Browse Source

fix windowInsets bugs

kongzue 4 years ago
parent
commit
67fe5539ff

+ 3 - 12
.idea/codeStyles/Project.xml

@@ -3,18 +3,9 @@
     <JetCodeStyleSettings>
       <option name="PACKAGES_TO_USE_STAR_IMPORTS">
         <value>
-          <package name="java.util" alias="false" withSubpackages="false" />
-          <package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
-          <package name="io.ktor" alias="false" withSubpackages="true" />
-        </value>
-      </option>
-      <option name="PACKAGES_IMPORT_LAYOUT">
-        <value>
-          <package name="" alias="false" withSubpackages="true" />
-          <package name="java" alias="false" withSubpackages="true" />
-          <package name="javax" alias="false" withSubpackages="true" />
-          <package name="kotlin" alias="false" withSubpackages="true" />
-          <package name="" alias="true" withSubpackages="true" />
+          <package name="java.util" withSubpackages="false" static="false" />
+          <package name="kotlinx.android.synthetic" withSubpackages="true" static="false" />
+          <package name="io.ktor" withSubpackages="true" static="false" />
         </value>
       </option>
     </JetCodeStyleSettings>

+ 1 - 1
.idea/misc.xml

@@ -84,7 +84,7 @@
       <textMaps />
     </LinkMapSettings>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8 (2)" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 15 - 16
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -9,10 +9,13 @@ import android.util.Log;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.ViewParent;
 import android.view.WindowInsets;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.RelativeLayout;
 
+import androidx.core.view.ViewCompat;
+
 import com.kongzue.dialogx.R;
 import com.kongzue.dialogx.interfaces.OnBackPressedListener;
 
@@ -54,9 +57,14 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     private void init() {
         setFocusableInTouchMode(true);
         requestFocus();
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && getRootWindowInsets()!=null) {
-            onApplyWindowInsets(getRootWindowInsets());
+    }
+    
+    @Override
+    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            paddingView(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
         }
+        return super.dispatchApplyWindowInsets(insets);
     }
     
     @Override
@@ -80,6 +88,11 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     @Override
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
+        final ViewParent parent = getParent();
+    
+        ViewCompat.setFitsSystemWindows(this, ViewCompat.getFitsSystemWindows((View) parent));
+        ViewCompat.requestApplyInsets(this);
+        
         if (onLifecycleCallBack != null) {
             onLifecycleCallBack.onShow();
         }
@@ -123,20 +136,6 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         setPadding(left, top, right, bottom);
     }
     
-    @Override
-    protected boolean fitSystemWindows(Rect insets) {
-        paddingView(insets.left,insets.top,insets.right,insets.bottom);
-        return true;
-    }
-    
-    @Override
-    public WindowInsets onApplyWindowInsets(WindowInsets windowInsets) {
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-            paddingView(windowInsets.getSystemWindowInsetLeft(), windowInsets.getSystemWindowInsetTop(), windowInsets.getSystemWindowInsetRight(), windowInsets.getSystemWindowInsetBottom());
-        }
-        return super.onApplyWindowInsets(windowInsets);
-    }
-    
     public DialogXBaseRelativeLayout setOnBackPressedListener(OnBackPressedListener onBackPressedListener) {
         this.onBackPressedListener = onBackPressedListener;
         return this;

+ 1 - 1
README.md

@@ -7,7 +7,7 @@ DialogX 采用分离设计,默认自带 Material 主题,可选引入 IOS、K
 
 更低的耦合度,无论对话框是否正在显示,请肆意执行的 Activity 关闭逻辑,而无需担心引发 WindowLeaked 错误。
 
-目前开发进度:51% [========== · · · · · · · · · · ]
+目前开发进度:53% [========== · · · · · · · · · · ]
 
 # 开源协议
 ```

+ 1 - 1
app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java

@@ -30,7 +30,7 @@ import com.kongzue.dialogx.util.TextInfo;
 @Layout(R.layout.activity_main)
 @DarkStatusBarTheme(true)
 @DarkNavigationBarTheme(true)
-@NavigationBarBackgroundColorRes(R.color.empty)
+@NavigationBarBackgroundColorRes(R.color.colorNavbarBkg)
 public class MainActivity extends BaseActivity {
     
     private RelativeLayout boxTable;

+ 2 - 0
app/src/main/res/values/colors.xml

@@ -3,4 +3,6 @@
     <color name="colorPrimary">#6200EE</color>
     <color name="colorPrimaryDark">@color/white</color>
     <color name="colorAccent">#2196F3</color>
+
+    <color name="colorNavbarBkg">#01000000</color>
 </resources>