1
0
Эх сурвалжийг харах

0.0.50.beta7
- 修复部分 API-21 设备上沉浸式不生效的问题;

Kongzue 1 жил өмнө
parent
commit
e9c35d7b82

+ 42 - 0
DialogX/src/main/java/com/kongzue/dialogx/util/views/FitSystemBarUtils.java

@@ -232,6 +232,48 @@ public class FitSystemBarUtils {
                                     parentView.removeOnLayoutChangeListener(rootViewLayoutChangeListener);
                                 }
                             });
+                        } else {
+                            View parentView = (View) view.getParent();
+                            ViewTreeObserver.OnPreDrawListener preDrawListener = new ViewTreeObserver.OnPreDrawListener() {
+                                @Override
+                                public boolean onPreDraw() {
+                                    // 获取状态栏高度
+                                    Rect insets = new Rect();
+                                    parentView.getWindowVisibleDisplayFrame(insets);
+                                    int statusBarHeight = insets.top;
+
+                                    // 获取导航栏高度
+                                    int navigationBarHeight = 0;
+                                    Resources resources = parentView.getResources();
+                                    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
+                                    if (resourceId > 0) {
+                                        navigationBarHeight = resources.getDimensionPixelSize(resourceId);
+                                    }
+
+                                    log("FitSystemBarUtils: below Android M use support mode: statusBarHeight=" + statusBarHeight + ", navigationBarHeight=" + navigationBarHeight);
+                                    int deviceOrientation = checkOrientationAndStatusBarSide();
+                                    log("    FitSystemBarUtils: deviceOrientation = " + deviceOrientation);
+                                    switch (deviceOrientation) {
+                                        case 1:
+                                        case -1:
+                                            initialPadding.end = navigationBarHeight;
+                                            initialPadding.start = 0;
+                                            break;
+                                        default:
+                                            initialPadding.top = statusBarHeight;
+                                            initialPadding.bottom = navigationBarHeight;
+                                            break;
+                                    }
+
+                                    applyCallBack(initialPadding);
+
+                                    parentView.getViewTreeObserver().removeOnPreDrawListener(this);
+
+                                    return true;
+                                }
+                            };
+                            parentView.getViewTreeObserver().addOnPreDrawListener(preDrawListener);
+
                         }
                     }
 

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

@@ -956,7 +956,7 @@ public class MainActivity extends BaseActivity {
         btnShowBreak.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                jump(MainActivity.class, new JumpParameter().put("showBreak", true).put("fromActivity", getInstanceKey()));
+                jump(TestMainActivity.class, new JumpParameter().put("showBreak", true).put("fromActivity", getInstanceKey()));
             }
         });
 

+ 53 - 49
app/src/main/java/com/kongzue/dialogxdemo/activity/TestMainActivity.java

@@ -25,6 +25,7 @@ import com.kongzue.dialogx.dialogs.CustomDialog;
 import com.kongzue.dialogx.dialogs.FullScreenDialog;
 import com.kongzue.dialogx.interfaces.DialogLifecycleCallback;
 import com.kongzue.dialogx.interfaces.OnBindView;
+import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 import com.kongzue.dialogxdemo.R;
 
 public class TestMainActivity extends AppCompatActivity {
@@ -34,60 +35,63 @@ public class TestMainActivity extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main_test);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-            getWindow().setStatusBarColor(ContextCompat.getColor(this,R.color.colorAccent));
+            getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorAccent));
         }
+
+        DialogXBaseRelativeLayout.debugMode = true;
         WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
         findViewById(R.id.btn_showDialog).setOnClickListener(view -> {
-//            BottomDialog.show("标题", "这里是对话框内容。")
-//                    .setCancelButton("取消", (dialog, v) -> false)
-//                    .setOkButton("确定", (dialog, v) -> false);
-
-            FullScreenDialog.show(new OnBindView<FullScreenDialog>(R.layout.layout_full_webview) {
-                private TextView btnClose;
-                private WebView webView;
-                @Override
-                public void onBind(final FullScreenDialog dialog, View v) {
-                    btnClose = v.findViewById(R.id.btn_close);
-                    webView = v.findViewById(R.id.webView);
-
-                    btnClose.setOnClickListener(new View.OnClickListener() {
-                        @Override
-                        public void onClick(View v) {
-                            dialog.dismiss();
-                        }
-                    });
-
-                    WebSettings webSettings = webView.getSettings();
-                    webSettings.setJavaScriptEnabled(true);
-                    webSettings.setLoadWithOverviewMode(true);
-                    webSettings.setUseWideViewPort(true);
-                    webSettings.setSupportZoom(false);
-                    webSettings.setAllowFileAccess(true);
-                    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
-                    webSettings.setLoadsImagesAutomatically(true);
-                    webSettings.setDefaultTextEncodingName("utf-8");
-
-                    webView.setWebViewClient(new WebViewClient() {
-                        @Override
-                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
-                            try {
-                                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
-                                startActivity(intent);
-                            } catch (ActivityNotFoundException e) {
-                                e.printStackTrace();
-                            }
-                            return true;
-                        }
 
-                        @Override
-                        public void onPageFinished(WebView view, String url) {
-                            super.onPageFinished(view, url);
-                        }
-                    });
+            BottomDialog.show("标题", "这里是对话框内容。")
+                    .setCancelButton("取消", (dialog, v) -> false)
+                    .setOkButton("确定", (dialog, v) -> false);
 
-                    webView.loadUrl("https://github.com/kongzue/DialogX");
-                }
-            });
+//            FullScreenDialog.show(new OnBindView<FullScreenDialog>(R.layout.layout_full_webview) {
+//                private TextView btnClose;
+//                private WebView webView;
+//                @Override
+//                public void onBind(final FullScreenDialog dialog, View v) {
+//                    btnClose = v.findViewById(R.id.btn_close);
+//                    webView = v.findViewById(R.id.webView);
+//
+//                    btnClose.setOnClickListener(new View.OnClickListener() {
+//                        @Override
+//                        public void onClick(View v) {
+//                            dialog.dismiss();
+//                        }
+//                    });
+//
+//                    WebSettings webSettings = webView.getSettings();
+//                    webSettings.setJavaScriptEnabled(true);
+//                    webSettings.setLoadWithOverviewMode(true);
+//                    webSettings.setUseWideViewPort(true);
+//                    webSettings.setSupportZoom(false);
+//                    webSettings.setAllowFileAccess(true);
+//                    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
+//                    webSettings.setLoadsImagesAutomatically(true);
+//                    webSettings.setDefaultTextEncodingName("utf-8");
+//
+//                    webView.setWebViewClient(new WebViewClient() {
+//                        @Override
+//                        public boolean shouldOverrideUrlLoading(WebView view, String url) {
+//                            try {
+//                                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+//                                startActivity(intent);
+//                            } catch (ActivityNotFoundException e) {
+//                                e.printStackTrace();
+//                            }
+//                            return true;
+//                        }
+//
+//                        @Override
+//                        public void onPageFinished(WebView view, String url) {
+//                            super.onPageFinished(view, url);
+//                        }
+//                    });
+//
+//                    webView.loadUrl("https://github.com/kongzue/DialogX");
+//                }
+//            });
         });
     }
 }