|
@@ -39,8 +39,6 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
|
|
|
/**
|
|
|
* @author: Kongzue
|
|
@@ -103,30 +101,88 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
setClipChildren(false);
|
|
|
setClipToPadding(false);
|
|
|
}
|
|
|
- }
|
|
|
+ //新增的 设置监听 OnApplyWindowInsetsListener
|
|
|
+ FitSystemBarUtils.attachView(this, new FitSystemBarUtils.CallBack() {
|
|
|
+ @Override
|
|
|
+ public boolean isEnable(FitSystemBarUtils.Orientation orientation) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- protected boolean fitSystemWindows(Rect insets) {
|
|
|
- if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW))) {
|
|
|
- log("#fitSystemWindows paddingView: b=" + insets.bottom);
|
|
|
- paddingView(insets.left, insets.top, insets.right, insets.bottom);
|
|
|
- }
|
|
|
- return super.fitSystemWindows(insets);
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public void unsafeRect(int start, int top, int end, int bottom) {
|
|
|
+ if (unsafePlace == null) {
|
|
|
+ unsafePlace = new Rect();
|
|
|
+ }
|
|
|
+ unsafePlace.left = start;
|
|
|
+ unsafePlace.top = top;
|
|
|
+ unsafePlace.right = end;
|
|
|
+ unsafePlace.bottom = bottom;
|
|
|
+
|
|
|
+ //做下判断,如果是底部对话框,则把paddingBottom设为0,改为推起子控件
|
|
|
+ MaxRelativeLayout bkgView = findViewById(R.id.bkg);
|
|
|
+ if (bkgView != null && bkgView.getLayoutParams() instanceof LayoutParams) {
|
|
|
+ LayoutParams bkgLp = (LayoutParams) bkgView.getLayoutParams();
|
|
|
+ if (bkgLp.getRules()[ALIGN_PARENT_BOTTOM] == RelativeLayout.TRUE && isAutoUnsafePlacePadding()) {
|
|
|
+ setPadding(extraPadding[0] + unsafePlace.left,
|
|
|
+ extraPadding[1] + unsafePlace.top,
|
|
|
+ extraPadding[2] + unsafePlace.right,
|
|
|
+ extraPadding[3]
|
|
|
+ );
|
|
|
+ bkgView.setNavBarHeight(bottom);
|
|
|
+ if (getParentDialog() instanceof DialogXBaseBottomDialog) {
|
|
|
+ if (((DialogXBaseBottomDialog) getParentDialog()).isBottomNonSafetyAreaBySelf()) {
|
|
|
+ bkgView.setPadding(0, 0, 0, 0);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unsafePlace.bottom = 0;
|
|
|
+ bkgView.setPadding(0, 0, 0, bottom);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
- if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW))) {
|
|
|
- paddingView(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
|
|
|
- log("#dispatchApplyWindowInsets paddingView: b=" + insets.getSystemWindowInsetBottom());
|
|
|
+ @Override
|
|
|
+ public int initialPadding(FitSystemBarUtils.Orientation orientation) {
|
|
|
+ switch (orientation) {
|
|
|
+ case Start:
|
|
|
+ return extraPadding[0];
|
|
|
+ case Top:
|
|
|
+ return extraPadding[1];
|
|
|
+ case End:
|
|
|
+ return extraPadding[2];
|
|
|
+ case Bottom:
|
|
|
+ return extraPadding[3];
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
}
|
|
|
- }
|
|
|
- return super.dispatchApplyWindowInsets(insets);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// protected boolean fitSystemWindows(Rect insets) {
|
|
|
+// if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW))) {
|
|
|
+// log("#fitSystemWindows paddingView: b=" + insets.bottom);
|
|
|
+// paddingView(insets.left, insets.top, insets.right, insets.bottom);
|
|
|
+// }
|
|
|
+// return super.fitSystemWindows(insets);
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+// if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW))) {
|
|
|
+// paddingView(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
|
|
|
+// log("#dispatchApplyWindowInsets paddingView: b=" + insets.getSystemWindowInsetBottom());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return super.dispatchApplyWindowInsets(insets);
|
|
|
+// }
|
|
|
+
|
|
|
+ public void paddingView(Insets insets) {
|
|
|
}
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.Q)
|
|
|
- public void paddingView(Insets insets) {
|
|
|
+ public void paddingViewOld(Insets insets) {
|
|
|
if (insets != null) {
|
|
|
paddingView(insets.left, insets.top, insets.right, insets.bottom);
|
|
|
log("#paddingView(insets) paddingView: b=" + insets.bottom);
|
|
@@ -134,6 +190,9 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
}
|
|
|
|
|
|
public void paddingView(WindowInsets insets) {
|
|
|
+ }
|
|
|
+
|
|
|
+ public void paddingViewOld(WindowInsets insets) {
|
|
|
if (!isAttachedToWindow()) {
|
|
|
getDynamicWindowInsetsAnimationListener(parentKey).remove(dynamicWindowInsetsAnimationListener);
|
|
|
return;
|
|
@@ -182,36 +241,36 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
protected void onAttachedToWindow() {
|
|
|
super.onAttachedToWindow();
|
|
|
if (!isInEditMode()) {
|
|
|
- final ViewParent parent = getParent();
|
|
|
- if (parent instanceof View) {
|
|
|
- ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));
|
|
|
- }
|
|
|
- ViewCompat.requestApplyInsets(this);
|
|
|
+// final ViewParent parent = getParent();
|
|
|
+// if (parent instanceof View) {
|
|
|
+// ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));
|
|
|
+// }
|
|
|
+// ViewCompat.requestApplyInsets(this);
|
|
|
|
|
|
if (getParentDialog() == null || getParentDialog().getOwnActivity() == null) return;
|
|
|
|
|
|
- View decorView = (View) getParent();
|
|
|
- if (decorView != null) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
- parentKey = Integer.toHexString(decorView.hashCode());
|
|
|
- getDynamicWindowInsetsAnimationListener(parentKey).add(dynamicWindowInsetsAnimationListener = new DynamicWindowInsetsAnimationListener() {
|
|
|
- @Override
|
|
|
- public void onChange(WindowInsets windowInsets) {
|
|
|
- paddingView(windowInsets);
|
|
|
- }
|
|
|
- });
|
|
|
- paddingWindowInsetsByDefault();
|
|
|
- initDynamicSafeAreaListener();
|
|
|
- } else {
|
|
|
- decorView.getViewTreeObserver().addOnGlobalLayoutListener(decorViewLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
- @Override
|
|
|
- public void onGlobalLayout() {
|
|
|
- paddingWindowInsetsByDefault();
|
|
|
- }
|
|
|
- });
|
|
|
- decorViewLayoutListener.onGlobalLayout();
|
|
|
- }
|
|
|
- }
|
|
|
+// View decorView = (View) getParent();
|
|
|
+// if (decorView != null) {
|
|
|
+// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
+// parentKey = Integer.toHexString(decorView.hashCode());
|
|
|
+// getDynamicWindowInsetsAnimationListener(parentKey).add(dynamicWindowInsetsAnimationListener = new DynamicWindowInsetsAnimationListener() {
|
|
|
+// @Override
|
|
|
+// public void onChange(WindowInsets windowInsets) {
|
|
|
+// paddingView(windowInsets);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// paddingWindowInsetsByDefault();
|
|
|
+// initDynamicSafeAreaListener();
|
|
|
+// } else {
|
|
|
+// decorView.getViewTreeObserver().addOnGlobalLayoutListener(decorViewLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
+// @Override
|
|
|
+// public void onGlobalLayout() {
|
|
|
+// paddingWindowInsetsByDefault();
|
|
|
+// }
|
|
|
+// });
|
|
|
+// decorViewLayoutListener.onGlobalLayout();
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
if (onLifecycleCallBack != null) {
|
|
|
onLifecycleCallBack.onShow();
|
|
@@ -238,8 +297,11 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
|
|
|
boolean useWindowInsetsAnimation = false;
|
|
|
|
|
|
+
|
|
|
+ private void initDynamicSafeAreaListener() {}
|
|
|
+
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
|
|
|
- private void initDynamicSafeAreaListener() {
|
|
|
+ private void initDynamicSafeAreaListenerOld() {
|
|
|
View decorView = (View) getParent();
|
|
|
if (decorView != null) {
|
|
|
try {
|
|
@@ -269,13 +331,15 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
|
|
|
private void paddingWindowInsetsByDefault() {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
- paddingView(getRootWindowInsets());
|
|
|
+// paddingView(getRootWindowInsets());
|
|
|
} else {
|
|
|
- getWindowInsetsByDisplayMetrics();
|
|
|
+// getWindowInsetsByDisplayMetrics();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void getWindowInsetsByDisplayMetrics() {
|
|
|
+ private void getWindowInsetsByDisplayMetrics() {}
|
|
|
+
|
|
|
+ private void getWindowInsetsByDisplayMetricsOld() {
|
|
|
if (getParentDialog() == null || getParentDialog().getOwnActivity() == null) return;
|
|
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
|
getParentDialog().getOwnActivity().getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
|
|
@@ -353,10 +417,10 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
public void requestFocusOnResume() {
|
|
|
log("#requestFocusOnResume");
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && getRootWindowInsets() != null && getRootWindowInsets().getStableInsets() != null) {
|
|
|
- paddingView(getRootWindowInsets().getStableInsets());
|
|
|
+// paddingView(getRootWindowInsets().getStableInsets());
|
|
|
}
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
|
|
|
- initDynamicSafeAreaListener();
|
|
|
+// initDynamicSafeAreaListener();
|
|
|
}
|
|
|
View findFocusView = findFocus();
|
|
|
if (findFocusView != null && findFocusView != this) {
|
|
@@ -375,7 +439,9 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
|
|
|
protected Rect unsafePlace = new Rect();
|
|
|
|
|
|
- private void paddingView(int left, int top, int right, int bottom) {
|
|
|
+ private void paddingView(int left, int top, int right, int bottom) {}
|
|
|
+
|
|
|
+ private void paddingViewOld(int left, int top, int right, int bottom) {
|
|
|
unsafePlace = new Rect(left, top, right, bottom);
|
|
|
if (onSafeInsetsChangeListener != null) onSafeInsetsChangeListener.onChange(unsafePlace);
|
|
|
MaxRelativeLayout bkgView = findViewById(R.id.bkg);
|
|
@@ -423,7 +489,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
|
|
|
public DialogXBaseRelativeLayout setAutoUnsafePlacePadding(boolean autoUnsafePlacePadding) {
|
|
|
this.autoUnsafePlacePadding = autoUnsafePlacePadding;
|
|
|
if (!autoUnsafePlacePadding) {
|
|
|
- setPadding(extraPadding[0], extraPadding[1], extraPadding[2], extraPadding[3]);
|
|
|
+// setPadding(extraPadding[0], extraPadding[1], extraPadding[2], extraPadding[3]);
|
|
|
}
|
|
|
return this;
|
|
|
}
|