From 5cda6e5074eaeedcf1ed35ca0c725ef8da2a306c Mon Sep 17 00:00:00 2001 From: kongzue Date: Fri, 30 Jul 2021 11:41:50 +0800 Subject: [PATCH] 0.0.41.beta5 --- .idea/compiler.xml | 10 ++-- .idea/gradle.xml | 3 +- .idea/misc.xml | 12 ++++- .idea/runConfigurations.xml | 13 ----- .../kongzue/dialogx/dialogs/BottomDialog.java | 5 ++ .../kongzue/dialogx/dialogs/BottomMenu.java | 5 ++ .../kongzue/dialogx/dialogs/CustomDialog.java | 5 ++ .../dialogx/dialogs/FullScreenDialog.java | 5 ++ .../dialogx/dialogs/MessageDialog.java | 5 ++ .../com/kongzue/dialogx/dialogs/PopTip.java | 5 ++ .../kongzue/dialogx/dialogs/WaitDialog.java | 5 ++ .../dialogx/interfaces/BaseDialog.java | 35 +++++++++++- .../views/ActivityScreenShotImageView.java | 7 ++- .../com/kongzue/dialogxdemo/MainActivity.java | 40 ++++++++++++++ app/src/main/res/layout/activity_main.xml | 54 +++++++++++++++++++ gradle.properties | 2 +- 16 files changed, 185 insertions(+), 26 deletions(-) delete mode 100644 .idea/runConfigurations.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml index d5573aff..f55eb458 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,11 +2,11 @@ - - - - - + + + + + diff --git a/.idea/gradle.xml b/.idea/gradle.xml index dc418412..a7399c3a 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,7 +4,7 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index e45f247b..d1c833df 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,12 @@ + + + @@ -110,7 +117,7 @@ - + diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index e497da99..00000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java index ad2104b2..0c347521 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java @@ -955,4 +955,9 @@ public void hide() { getDialogView().setVisibility(View.GONE); } } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java index aad78f9e..3bc25c7d 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomMenu.java @@ -1060,4 +1060,9 @@ public BottomMenu setExitAnimDuration(long exitAnimDuration) { public SELECT_MODE getSelectMode() { return selectMode; } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java index 41984df9..62746229 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/CustomDialog.java @@ -495,4 +495,9 @@ public void hide() { getDialogView().setVisibility(View.GONE); } } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java index 08e91d44..bfcfc734 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/FullScreenDialog.java @@ -450,4 +450,9 @@ public void hide() { getDialogView().setVisibility(View.GONE); } } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java index afd45fb7..31134985 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java @@ -1071,4 +1071,9 @@ public MessageDialog setExitAnimResId(int exitResId) { customExitAnimResId = exitResId; return this; } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java index 5e303c07..b3f513e4 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java @@ -924,4 +924,9 @@ public PopTip setExitAnimResId(int exitResId) { this.exitAnimResId = exitResId; return this; } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/WaitDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/WaitDialog.java index 7ecbead5..6b2f7b30 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/dialogs/WaitDialog.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/dialogs/WaitDialog.java @@ -839,4 +839,9 @@ protected static void showWithInstance(boolean noInstance, Activity activity) { getInstanceNotNull(activity).refreshUI(); } } + + @Override + protected void shutdown() { + dismiss(); + } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java b/DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java index c4f1b2ff..a59339af 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java @@ -251,12 +251,19 @@ public static Context getContext() { return contextWeakReference.get(); } + /** + * 自动执行,不建议自行调用此方法 + * + * @hide + */ public static void cleanContext() { - contextWeakReference.clear(); + if (contextWeakReference != null) contextWeakReference.clear(); contextWeakReference = null; System.gc(); } + protected abstract void shutdown(); + protected boolean cancelable = true; protected OnBackPressedListener onBackPressedListener; protected boolean isShow; @@ -440,6 +447,18 @@ public Activity getActivity() { protected void cleanActivityContext() { if (ownActivity != null) ownActivity.clear(); + ownActivity = null; + } + + public static void cleanAll(){ + if (runningDialogList != null) { + CopyOnWriteArrayList copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList); + for (BaseDialog baseDialog : copyOnWriteList) { + if (baseDialog.isShow())baseDialog.shutdown(); + baseDialog.cleanActivityContext(); + runningDialogList.remove(baseDialog); + } + } } public static void recycleDialog(Activity activity) { @@ -464,6 +483,20 @@ public static void recycleDialog(Activity activity) { } } break; + default: + if (runningDialogList != null) { + CopyOnWriteArrayList copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList); + for (BaseDialog baseDialog : copyOnWriteList) { + if (baseDialog.getActivity() == activity) { + baseDialog.cleanActivityContext(); + runningDialogList.remove(baseDialog); + } + } + } + break; + } + if (activity == getContext()) { + cleanContext(); } } diff --git a/DialogX/src/main/java/com/kongzue/dialogx/util/views/ActivityScreenShotImageView.java b/DialogX/src/main/java/com/kongzue/dialogx/util/views/ActivityScreenShotImageView.java index 5b1f65da..d06bf9b1 100644 --- a/DialogX/src/main/java/com/kongzue/dialogx/util/views/ActivityScreenShotImageView.java +++ b/DialogX/src/main/java/com/kongzue/dialogx/util/views/ActivityScreenShotImageView.java @@ -87,7 +87,7 @@ protected void onDraw(Canvas canvas) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); - refreshImage(); + if (isAttachedToWindow()) refreshImage(); } private int screenWidth, screenHeight; @@ -104,16 +104,19 @@ private void doScreenshotActivityAndZoom() { if (BaseDialog.getRootFrameLayout() == null) return; final View view = BaseDialog.getRootFrameLayout().getChildAt(0); //先执行一次绘制,防止出现闪屏问题 - drawViewImage(view); + if (!inited) drawViewImage(view); view.post(new Runnable() { @Override public void run() { //当view渲染完成后再次通知刷新一下界面(当旋转屏幕执行时,很可能出现渲染延迟的问题) drawViewImage(view); + inited = true; } }); } + private boolean inited = false; + private void drawViewImage(View view) { view.destroyDrawingCache(); view.setDrawingCacheEnabled(true); diff --git a/app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java b/app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java index 8600ddab..5a1e895f 100644 --- a/app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java +++ b/app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java @@ -66,6 +66,10 @@ public class MainActivity extends BaseActivity { private ImageView btnShare; private TextView txtTitle; private LinearLayout boxBody; + private RadioGroup grpMode; + private RadioButton rdoModeView; + private RadioButton rdoModeWindow; + private RadioButton rdoModeDialogFragment; private RadioGroup grpStyle; private RadioButton rdoMaterial; private RadioButton rdoIos; @@ -107,6 +111,10 @@ public void initViews() { btnShare = findViewById(R.id.btn_share); txtTitle = findViewById(R.id.txt_title); boxBody = findViewById(R.id.box_body); + grpMode = findViewById(R.id.grp_mode); + rdoModeView = findViewById(R.id.rdo_mode_view); + rdoModeWindow = findViewById(R.id.rdo_mode_window); + rdoModeDialogFragment = findViewById(R.id.rdo_mode_dialogFragment); grpStyle = findViewById(R.id.grp_style); rdoMaterial = findViewById(R.id.rdo_material); rdoIos = findViewById(R.id.rdo_ios); @@ -172,6 +180,20 @@ public boolean onClick(BaseDialog baseDialog, View v) { }) .setCancelable(false); } + + switch (DialogX.implIMPLMode){ + case VIEW: + rdoModeView.setChecked(true); + break; + case WINDOW: + rdoModeWindow.setChecked(true); + break; + case DIALOG_FRAGMENT: + rdoModeDialogFragment.setChecked(true); + break; + } + + txtTitle.setText("Kongzue DialogX (" + BuildConfig.VERSION_NAME +")"); } //用于模拟进度提示 @@ -201,6 +223,24 @@ public boolean onClick(BaseDialog baseDialog, View v) { @Override public void setEvents() { + grpMode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + BaseDialog.cleanAll(); + switch (checkedId){ + case R.id.rdo_mode_view: + DialogX.implIMPLMode = DialogX.IMPL_MODE.VIEW; + break; + case R.id.rdo_mode_window: + DialogX.implIMPLMode = DialogX.IMPL_MODE.WINDOW; + break; + case R.id.rdo_mode_dialogFragment: + DialogX.implIMPLMode = DialogX.IMPL_MODE.DIALOG_FRAGMENT; + break; + } + } + }); + grpTheme.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d0109bc5..5fa230ac 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -112,6 +112,60 @@ android:paddingLeft="15dp" android:paddingRight="15dp"> + + + + + + + + + + + + + +