Commit 32434bc9c6e1d83dffc96b03d464b9a837b60d76

Authored by shixianjie
1 parent 0b06f873f3
Exists in master

全屏查看图片

... ... @@ -93,4 +93,6 @@ dependencies {
93 93 implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2'
94 94 implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.2'
95 95  
  96 + // 图片查看
  97 + implementation 'com.github.chrisbanes:PhotoView:2.0.0'
96 98 }
97 99 \ No newline at end of file
... ...
app/src/main/java/com/hjx/parent/HomeworkShareActivity.java
... ... @@ -19,6 +19,7 @@ import com.chad.library.adapter.base.BaseViewHolder;
19 19 import com.google.gson.Gson;
20 20 import com.gyf.immersionbar.ImmersionBar;
21 21 import com.hjx.parent.databinding.ActivityHomeworkShareBinding;
  22 +import com.hjx.parent.dialog.PhotoViewDialog;
22 23 import com.hjx.parent.rx.BaseRxActivity;
23 24 import com.prws.common.bean.ResponseResult;
24 25 import com.prws.common.bean.Student;
... ... @@ -220,6 +221,9 @@ public class HomeworkShareActivity extends BaseRxActivity<ActivityHomeworkShareB
220 221 if (url == null) {
221 222 return;
222 223 }
  224 + view.setOnClickListener(v -> {
  225 + new PhotoViewDialog(mContext).show(url);
  226 + });
223 227 Single.just(url)
224 228 .subscribeOn(Schedulers.io())
225 229 .map(u -> Glide.with(mContext).asBitmap().load(url).submit().get())
... ...
app/src/main/java/com/hjx/parent/dialog/PhotoViewDialog.java
... ... @@ -0,0 +1,59 @@
  1 +package com.hjx.parent.dialog;
  2 +
  3 +import android.content.Context;
  4 +import android.graphics.Color;
  5 +import android.view.View;
  6 +import android.view.WindowManager;
  7 +
  8 +import androidx.annotation.NonNull;
  9 +
  10 +import com.bumptech.glide.Glide;
  11 +import com.hjx.parent.databinding.DialogPhotoViewBinding;
  12 +
  13 +public class PhotoViewDialog extends BaseDialog<DialogPhotoViewBinding> {
  14 + public PhotoViewDialog(Context context) {
  15 + super(context);
  16 + }
  17 +
  18 + private String url;
  19 +
  20 + @Override
  21 + public void initView() {
  22 + setupWindow();
  23 + setCancelable(true);
  24 + binding.btnClose.setOnClickListener(v -> dismiss());
  25 + }
  26 +
  27 + private void setupWindow() {
  28 + // 在显示 Dialog 之前对窗口进行设置
  29 + getWindow().setFlags(
  30 + WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
  31 + WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
  32 +
  33 + // 设置状态栏背景透明
  34 + getWindow().setStatusBarColor(Color.TRANSPARENT);
  35 +
  36 + // 让内容延伸到状态栏区域,并保持状态栏和导航栏的显示
  37 + getWindow().getDecorView().setSystemUiVisibility(
  38 + View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  39 + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  40 +
  41 + }
  42 +
  43 + @Override
  44 + public void onDialogStart() {
  45 + super.onDialogStart();
  46 + Glide.with(getContext()).load(url).into(binding.photoView);
  47 + }
  48 +
  49 + public void show(String url) {
  50 + this.url = url;
  51 + super.show();
  52 + }
  53 +
  54 + @NonNull
  55 + @Override
  56 + public DialogPhotoViewBinding getBinding() {
  57 + return DialogPhotoViewBinding.inflate(getLayoutInflater());
  58 + }
  59 +}
... ...
app/src/main/res/layout/dialog_photo_view.xml
... ... @@ -0,0 +1,28 @@
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:orientation="vertical"
  6 + android:layout_width="match_parent"
  7 + android:layout_height="match_parent"
  8 + tools:background="#888"
  9 + tools:ignore="UseCompoundDrawables,HardcodedText,SmallSp,ContentDescription">
  10 +
  11 + <com.github.chrisbanes.photoview.PhotoView
  12 + android:id="@+id/photoView"
  13 + android:layout_width="match_parent"
  14 + android:layout_height="match_parent" />
  15 +
  16 + <ImageView
  17 + android:id="@+id/btnClose"
  18 + android:src="@drawable/svg_close_24"
  19 + android:padding="8dp"
  20 + android:background="@drawable/shape_circle"
  21 + android:backgroundTint="#88FFFFFF"
  22 + android:layout_gravity="end"
  23 + android:layout_marginTop="40dp"
  24 + android:layout_marginEnd="16dp"
  25 + android:layout_width="28dp"
  26 + android:layout_height="28dp"/>
  27 +
  28 +</FrameLayout>
0 29 \ No newline at end of file
... ...
app/src/main/res/values/styles.xml
... ... @@ -66,6 +66,12 @@
66 66 <item name="android:windowIsFloating">true</item>
67 67 </style>
68 68  
  69 + <style name="BaseDialog.FullScreen">
  70 + <item name="android:windowFullscreen">true</item>
  71 + <item name="android:windowIsTranslucent">true</item>
  72 + <item name="android:statusBarColor">@android:color/transparent</item>
  73 + </style>
  74 +
69 75 <style name="tv_StudentHomeworkFilter">
70 76 <item name="android:textSize">13sp</item>
71 77 <item name="android:textColor">@color/color_filter_state</item>
... ...