Bladeren bron

0.0.48.beta24
- 当输入法处于弹出时,PopTip、PopNotification 启动时将不会再导致输入法关闭;
- PopTip、PopNotification 不会再获取任何焦点和触摸事件;
- 修复异常日志打印;

Kongzue 2 jaren geleden
bovenliggende
commit
c19fa3f89f

+ 4 - 4
DialogX/src/main/java/com/kongzue/dialogx/dialogs/BottomDialog.java

@@ -263,10 +263,10 @@ public class BottomDialog extends BaseDialog implements DialogXBaseBottomDialog
         public ImageView splitSelectPositive;
         public ImageView splitSelectOther;
 
-        private LinearLayout boxButton;
-        private TextView btnSelectNegative;
-        private TextView btnSelectOther;
-        private TextView btnSelectPositive;
+        public LinearLayout boxButton;
+        public TextView btnSelectNegative;
+        public TextView btnSelectOther;
+        public TextView btnSelectPositive;
 
         private List<View> blurViews;
 

+ 50 - 34
DialogX/src/main/java/com/kongzue/dialogx/interfaces/BaseDialog.java

@@ -129,7 +129,7 @@ public abstract class BaseDialog implements LifecycleOwner {
                     View boxRoot = baseDialog.getDialogView().findViewById(R.id.box_root);
                     if (boxRoot instanceof DialogXBaseRelativeLayout) {
                         if (((DialogXBaseRelativeLayout) boxRoot).isBaseFocusable()) {
-                            boxRoot.requestFocus();
+                            ((DialogXBaseRelativeLayout) boxRoot).requestFocusOnResume();
                             return;
                         }
                     }
@@ -139,7 +139,21 @@ public abstract class BaseDialog implements LifecycleOwner {
     }
 
     private static void requestDialogFocus() {
-        onActivityResume(getTopActivity());
+        if (runningDialogList != null) {
+            CopyOnWriteArrayList<BaseDialog> copyOnWriteList = new CopyOnWriteArrayList<>(runningDialogList);
+            for (int i = copyOnWriteList.size() - 1; i >= 0; i--) {
+                BaseDialog baseDialog = copyOnWriteList.get(i);
+                if (baseDialog.getOwnActivity() == getTopActivity() && baseDialog.isShow && baseDialog.getDialogView() != null) {
+                    View boxRoot = baseDialog.getDialogView().findViewById(R.id.box_root);
+                    if (boxRoot instanceof DialogXBaseRelativeLayout) {
+                        if (((DialogXBaseRelativeLayout) boxRoot).isBaseFocusable()) {
+                            boxRoot.requestFocus();
+                            return;
+                        }
+                    }
+                }
+            }
+        }
     }
 
     public abstract void restartDialog();
@@ -148,43 +162,43 @@ public abstract class BaseDialog implements LifecycleOwner {
         if (view == null) {
             return;
         }
-        final BaseDialog baseDialog = (BaseDialog) view.getTag();
-        if (baseDialog != null) {
-            if (baseDialog.isShow) {
-                if (baseDialog.getDialogView() != null) {
-                    baseDialog.getDialogView().setVisibility(View.VISIBLE);
+        final BaseDialog dialog = (BaseDialog) view.getTag();
+        if (dialog != null) {
+            if (dialog.isShow) {
+                if (dialog.getDialogView() != null) {
+                    dialog.getDialogView().setVisibility(View.VISIBLE);
                     return;
                 }
                 error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
                 return;
             }
-            baseDialog.dialogView = new WeakReference<>(view);
+            dialog.dialogView = new WeakReference<>(view);
 
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-                publicWindowInsets(baseDialog.getRootFrameLayout().getRootWindowInsets());
+                publicWindowInsets(dialog.getRootFrameLayout().getRootWindowInsets());
             }
 
-            log(baseDialog.dialogKey() + ".show");
+            log(dialog.dialogKey() + ".show");
 
-            addDialogToRunningList(baseDialog);
-            switch (baseDialog.dialogImplMode) {
+            addDialogToRunningList(dialog);
+            switch (dialog.dialogImplMode) {
                 case WINDOW:
-                    WindowUtil.show(baseDialog.getOwnActivity(), view, !(baseDialog instanceof NoTouchInterface));
+                    WindowUtil.show(dialog.getOwnActivity(), view, !(dialog instanceof NoTouchInterface));
                     break;
                 case DIALOG_FRAGMENT:
-                    DialogFragmentImpl dialogFragment = new DialogFragmentImpl(baseDialog, view);
-                    dialogFragment.show(getSupportFragmentManager(baseDialog.getOwnActivity()), "DialogX");
-                    baseDialog.ownDialogFragmentImpl = new WeakReference<>(dialogFragment);
+                    DialogFragmentImpl dialogFragment = new DialogFragmentImpl(dialog, view);
+                    dialogFragment.show(getSupportFragmentManager(dialog.getOwnActivity()), "DialogX");
+                    dialog.ownDialogFragmentImpl = new WeakReference<>(dialogFragment);
                     break;
                 case FLOATING_ACTIVITY:
                     if (waitRunDialogX == null) {
                         waitRunDialogX = new HashMap<>();
                     }
-                    waitRunDialogX.put(baseDialog.dialogKey(), new ActivityRunnable() {
+                    waitRunDialogX.put(dialog.dialogKey(), new ActivityRunnable() {
                         @Override
                         public void run(Activity activity) {
-                            baseDialog.floatingWindowActivity = new WeakReference<>((DialogXFloatingWindowActivity) activity);
-                            baseDialog.floatingWindowActivity.get().setFromActivity(baseDialog.getOwnActivity());
+                            dialog.floatingWindowActivity = new WeakReference<>((DialogXFloatingWindowActivity) activity);
+                            dialog.floatingWindowActivity.get().setFromActivity(dialog.getOwnActivity());
                             final FrameLayout activityRootView = getDecorView(activity);
                             if (activityRootView == null) {
                                 return;
@@ -192,7 +206,7 @@ public abstract class BaseDialog implements LifecycleOwner {
                             runOnMain(new Runnable() {
                                 @Override
                                 public void run() {
-                                    if (view.getParent() == baseDialog.getRootFrameLayout()) {
+                                    if (view.getParent() == dialog.getRootFrameLayout()) {
                                         error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
                                         return;
                                     }
@@ -205,38 +219,38 @@ public abstract class BaseDialog implements LifecycleOwner {
                         }
                     });
                     DialogXFloatingWindowActivity dialogXFloatingWindowActivity = DialogXFloatingWindowActivity.getDialogXFloatingWindowActivity();
-                    if (dialogXFloatingWindowActivity != null && dialogXFloatingWindowActivity.isSameFrom(baseDialog.getOwnActivity().hashCode())) {
-                        dialogXFloatingWindowActivity.showDialogX(baseDialog.dialogKey());
+                    if (dialogXFloatingWindowActivity != null && dialogXFloatingWindowActivity.isSameFrom(dialog.getOwnActivity().hashCode())) {
+                        dialogXFloatingWindowActivity.showDialogX(dialog.dialogKey());
                         return;
                     }
                     Intent intent = new Intent(getPrivateContext(), DialogXFloatingWindowActivity.class);
-                    if (baseDialog.getOwnActivity() == null) {
+                    if (dialog.getOwnActivity() == null) {
                         intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
                     }
-                    intent.putExtra("dialogXKey", baseDialog.dialogKey());
-                    intent.putExtra("fromActivityUiStatus", baseDialog.getOwnActivity() == null ? 0 : (getDecorView(baseDialog.getOwnActivity()) == null ? 0 : getDecorView(baseDialog.getOwnActivity()).getSystemUiVisibility()));
+                    intent.putExtra("dialogXKey", dialog.dialogKey());
+                    intent.putExtra("fromActivityUiStatus", dialog.getOwnActivity() == null ? 0 : (getDecorView(dialog.getOwnActivity()) == null ? 0 : getDecorView(dialog.getOwnActivity()).getSystemUiVisibility()));
                     intent.putExtra("from", getPrivateContext().hashCode());
                     getPrivateContext().startActivity(intent);
                     int version = Integer.valueOf(Build.VERSION.SDK_INT);
-                    if (version > 5 && baseDialog.getOwnActivity() != null) {
-                        baseDialog.getOwnActivity().overridePendingTransition(0, 0);
+                    if (version > 5 && dialog.getOwnActivity() != null) {
+                        dialog.getOwnActivity().overridePendingTransition(0, 0);
                     }
                     break;
                 default:
-                    if (baseDialog.getRootFrameLayout() == null) {
+                    if (dialog.getRootFrameLayout() == null) {
                         return;
                     }
                     runOnMain(new Runnable() {
                         @Override
                         public void run() {
-                            if (view.getParent() == baseDialog.getRootFrameLayout()) {
+                            if (view.getParent() == dialog.getRootFrameLayout()) {
                                 error(((BaseDialog) view.getTag()).dialogKey() + "已处于显示状态,请勿重复执行 show() 指令。");
                                 return;
                             }
                             if (view.getParent() != null) {
                                 ((ViewGroup) view.getParent()).removeView(view);
                             }
-                            baseDialog.getRootFrameLayout().addView(view);
+                            dialog.getRootFrameLayout().addView(view);
                         }
                     });
                     break;
@@ -680,10 +694,12 @@ public abstract class BaseDialog implements LifecycleOwner {
         }
 
         //Hide IME
-        View view = getOwnActivity().getCurrentFocus();
-        if (view != null) {
-            InputMethodManager imm = (InputMethodManager) getOwnActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
-            imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
+        if (!(this instanceof NoTouchInterface)) {
+            View view = getOwnActivity().getCurrentFocus();
+            if (view != null) {
+                InputMethodManager imm = (InputMethodManager) getOwnActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
+                imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
+            }
         }
     }
 

+ 0 - 1
DialogX/src/main/java/com/kongzue/dialogx/util/BottomDialogTouchEventInterceptor.java

@@ -63,7 +63,6 @@ public class BottomDialogTouchEventInterceptor {
             impl.bkg.setOnTouchListener(new View.OnTouchListener() {
                 @Override
                 public boolean onTouch(View v, MotionEvent event) {
-                    Log.e(">>>", "onTouch: ");
                     if (me.getDialogLifecycleCallback() instanceof BottomDialogSlideEventLifecycleCallback) {
                         if (((BottomDialogSlideEventLifecycleCallback) me.getDialogLifecycleCallback()).onSlideTouchEvent(me, v, event)) {
                             return true;

+ 44 - 8
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -28,11 +28,10 @@ import androidx.core.view.WindowInsetsCompat;
 
 import com.kongzue.dialogx.DialogX;
 import com.kongzue.dialogx.R;
-import com.kongzue.dialogx.dialogs.BottomDialog;
-import com.kongzue.dialogx.dialogs.FullScreenDialog;
 import com.kongzue.dialogx.interfaces.BaseDialog;
 import com.kongzue.dialogx.interfaces.DialogXBaseBottomDialog;
 import com.kongzue.dialogx.interfaces.DynamicWindowInsetsAnimationListener;
+import com.kongzue.dialogx.interfaces.NoTouchInterface;
 import com.kongzue.dialogx.interfaces.OnSafeInsetsChangeListener;
 
 import java.lang.ref.WeakReference;
@@ -52,6 +51,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
  */
 public class DialogXBaseRelativeLayout extends RelativeLayout {
 
+    private boolean debugMode = false;
+
     private OnSafeInsetsChangeListener onSafeInsetsChangeListener;
     private BaseDialog parentDialog;
     private boolean autoUnsafePlacePadding = true;
@@ -108,6 +109,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     @Override
     protected boolean fitSystemWindows(Rect insets) {
         if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW)) {
+            log("#fitSystemWindows paddingView: b=" + insets.bottom);
             paddingView(insets.left, insets.top, insets.right, insets.bottom);
         }
         return super.fitSystemWindows(insets);
@@ -118,6 +120,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
             if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW)) {
                 paddingView(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
+                log("#dispatchApplyWindowInsets paddingView: b=" + insets.getSystemWindowInsetBottom());
             }
         }
         return super.dispatchApplyWindowInsets(insets);
@@ -127,6 +130,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     public void paddingView(Insets insets) {
         if (insets != null) {
             paddingView(insets.left, insets.top, insets.right, insets.bottom);
+            log("#paddingView(insets) paddingView: b=" + insets.bottom);
         }
     }
 
@@ -148,6 +152,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
                 return;
             }
             paddingView(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
+            log("#paddingView(WindowInsets) paddingView: b=" + insets.getSystemWindowInsetBottom());
         }
     }
 
@@ -163,6 +168,9 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
+        if (parentDialog instanceof NoTouchInterface){
+            return super.onTouchEvent(event);
+        }
         InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
         return super.onTouchEvent(event);
@@ -180,7 +188,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
             }
             ViewCompat.requestApplyInsets(this);
 
-            if (parentDialog.getOwnActivity() == null) return;
+            if (parentDialog == null || parentDialog.getOwnActivity() == null) return;
 
             View decorView = (View) getParent();
             if (decorView != null) {
@@ -270,6 +278,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         decorView.getWindowVisibleDisplayFrame(rect);
         if (rect.left == 0 && rect.top == 0 && rect.right == 0 && rect.bottom == 0) return;
         paddingView(rect.left, rect.top, displayMetrics.widthPixels - rect.right, displayMetrics.heightPixels - rect.bottom);
+        log("#getWindowInsetsByDisplayMetrics paddingView: b=" + (displayMetrics.heightPixels - rect.bottom));
     }
 
     @Override
@@ -315,18 +324,39 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     @Override
     public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
+        if (parentDialog != null && parentDialog instanceof NoTouchInterface) {
+            return false;
+        }
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && getRootWindowInsets() != null && getRootWindowInsets().getStableInsets() != null) {
-                paddingView(getRootWindowInsets().getStableInsets());
-            }
             initDynamicSafeAreaListener();
         }
         if (direction == View.FOCUS_DOWN && requestFocusView != null && requestFocusView.get() != null) {
             return requestFocusView.get().requestFocus();
         }
+        View findFocusView = findFocus();
+        if (findFocusView != null) {
+            findFocusView.requestFocus();
+            return true;
+        }
         return super.requestFocus(direction, previouslyFocusedRect);
     }
 
+    public void requestFocusOnResume() {
+        log("#requestFocusOnResume");
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && getRootWindowInsets() != null && getRootWindowInsets().getStableInsets() != null) {
+            paddingView(getRootWindowInsets().getStableInsets());
+        }
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
+            initDynamicSafeAreaListener();
+        }
+        View findFocusView = findFocus();
+        if (findFocusView != null && findFocusView != this) {
+            findFocusView.requestFocus();
+            return;
+        }
+        requestFocus();
+    }
+
     public abstract static class OnLifecycleCallBack {
         public void onShow() {
         }
@@ -345,8 +375,8 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
             if (bkgLp.getRules()[ALIGN_PARENT_BOTTOM] == RelativeLayout.TRUE && isAutoUnsafePlacePadding()) {
                 bkgView.setNavBarHeight(bottom);
                 setPadding(extraPadding[0] + left, extraPadding[1] + top, extraPadding[2] + right, extraPadding[3]);
-                if (getParentDialog() instanceof DialogXBaseBottomDialog){
-                    if (((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf()){
+                if (getParentDialog() instanceof DialogXBaseBottomDialog) {
+                    if (((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf()) {
                         bkgView.setPadding(0, 0, 0, 0);
                         return;
                     }
@@ -491,4 +521,10 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     public int getUseAreaHeight() {
         return getHeight() - getRootPaddingBottom();
     }
+
+    protected void log(String s) {
+        if (debugMode) {
+            Log.e(">>>", s);
+        }
+    }
 }

+ 26 - 4
app/src/main/java/com/kongzue/dialogxdemo/activity/MainActivity.java

@@ -34,6 +34,7 @@ import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.AdapterView;
 import android.widget.EditText;
+import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.RadioButton;
@@ -43,6 +44,7 @@ import android.widget.TextView;
 import android.widget.Toast;
 
 import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
 import androidx.constraintlayout.widget.ConstraintLayout;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
@@ -92,6 +94,7 @@ import com.kongzue.dialogx.style.MaterialStyle;
 import com.kongzue.dialogx.util.InputInfo;
 import com.kongzue.dialogx.util.TextInfo;
 import com.kongzue.dialogx.util.views.ActivityScreenShotImageView;
+import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogxdemo.BuildConfig;
 import com.kongzue.dialogxdemo.R;
 import com.kongzue.dialogxdemo.custom.recycleview.CustomRecycleViewAdapter;
@@ -788,6 +791,19 @@ public class MainActivity extends BaseActivity {
             }
         });
 
+//        new Thread() {
+//            View fV;
+//            @Override
+//            public void run() {
+//                super.run();
+//                while (true) {
+//                    View view = getWindow().getDecorView().findFocus();
+//                    if (fV!=view)log("focusView=" + view);
+//                    fV = view;
+//                }
+//            }
+//        }.start();
+
         btnBottomReply.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -1042,7 +1058,7 @@ public class MainActivity extends BaseActivity {
                 //实现完全自定义动画效果
 //                        .setDialogXAnimImpl(new DialogXAnimInterface<CustomDialog>() {
 //                            @Override
-//                            public void doShowAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
+//                            public void doShowAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
 //                                Animation enterAnim;
 //
 //                                int enterAnimResId = com.kongzue.dialogx.R.anim.anim_dialogx_top_enter;
@@ -1059,14 +1075,17 @@ public class MainActivity extends BaseActivity {
 //                                bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
 //                                    @Override
 //                                    public void onAnimationUpdate(ValueAnimator animation) {
-//                                        animProgress.run((Float) animation.getAnimatedValue());
+//                                        if (customDialog.getDialogImpl() == null || customDialog.getDialogImpl().boxRoot == null) {
+//                                            return;
+//                                        }
+//                                        customDialog.getDialogImpl().boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
 //                                    }
 //                                });
 //                                bkgAlpha.start();
 //                            }
 //
 //                            @Override
-//                            public void doExitAnim(CustomDialog customDialog, ObjectRunnable<Float> animProgress) {
+//                            public void doExitAnim(CustomDialog customDialog, ViewGroup dialogBodyView) {
 //                                int exitAnimResIdTemp = com.kongzue.dialogx.R.anim.anim_dialogx_default_exit;
 //
 //                                Animation exitAnim = AnimationUtils.loadAnimation(me, exitAnimResIdTemp);
@@ -1077,7 +1096,10 @@ public class MainActivity extends BaseActivity {
 //                                bkgAlpha.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
 //                                    @Override
 //                                    public void onAnimationUpdate(ValueAnimator animation) {
-//                                        animProgress.run((Float) animation.getAnimatedValue());
+//                                        if (customDialog.getDialogImpl() == null || customDialog.getDialogImpl().boxRoot == null) {
+//                                            return;
+//                                        }
+//                                        customDialog.getDialogImpl().boxRoot.setBkgAlpha((Float) animation.getAnimatedValue());
 //                                    }
 //                                });
 //                                bkgAlpha.start();

+ 1 - 1
gradle.properties

@@ -19,6 +19,6 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.48.beta23
+BUILD_VERSION=0.0.48.beta24
 BUILD_VERSION_INT=47
 DIALOGX_STYLE_VERSION=5