浏览代码

增加浏览器适配部分曲面屏(华为mate40)返回页面时候UI闪动问题

Pq 1 年之前
父节点
当前提交
70da6b4233

+ 21 - 0
student/src/main/java/com/cooleshow/student/ui/web/HtmlActivity.java

@@ -54,6 +54,7 @@ import com.cooleshow.base.ui.activity.BaseActivity;
 import com.cooleshow.base.utils.AndroidBug5497Workaround;
 import com.cooleshow.base.utils.AppUtils;
 import com.cooleshow.base.utils.ClipboardUtils;
+import com.cooleshow.base.utils.LOG;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.MyFileUtils;
 import com.cooleshow.base.utils.PermissionUtils;
@@ -147,6 +148,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
     RelativeLayout rl_activity_html;
     LinearLayout ll_activity_html;
     private String mImageBase64;
+    private boolean isNeedResetScreenOrientation =true;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -223,6 +225,9 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             setRequestedOrientation(orientation);
 
         }
+        int c_orientation = intent.getIntExtra("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+        isNeedResetScreenOrientation = c_orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+        LOG.i("c_orientation:"+c_orientation+"--isNeedResetScreenOrientation:"+isNeedResetScreenOrientation);
 
         setStatusBarTextColor(intent.getBooleanExtra("statusBarTextColor", false));
         if (isHideTitle) {
@@ -985,6 +990,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
                     webView.goBack();
                 }
             } else {
+                checkScreenOrientation();
                 super.onBackPressed();
             }
         } else {
@@ -1457,6 +1463,21 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
             e.printStackTrace();
         }
     }
+
+    @Override
+    public void finish() {
+        checkScreenOrientation();
+        super.finish();
+    }
+
+    private void checkScreenOrientation() {
+        LOG.i("isNeedResetScreenOrientation:"+isNeedResetScreenOrientation);
+        if(isNeedResetScreenOrientation){
+            if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
+                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+            }
+        }
+    }
 }
 
 

+ 22 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/web/HtmlActivity.java

@@ -54,6 +54,7 @@ import com.cooleshow.base.ui.activity.BaseActivity;
 import com.cooleshow.base.utils.AppUtils;
 import com.cooleshow.base.utils.ClipboardUtils;
 import com.cooleshow.base.utils.FileUtils;
+import com.cooleshow.base.utils.LOG;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.PermissionUtils;
 import com.cooleshow.base.utils.ToastUtil;
@@ -148,6 +149,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
     RelativeLayout rl_activity_html;
     LinearLayout ll_activity_html;
     private String mImageBase64;
+    private boolean isNeedResetScreenOrientation =true;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -224,6 +226,10 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
 
         }
 
+        int c_orientation = intent.getIntExtra("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+        isNeedResetScreenOrientation = c_orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+        LOG.i("c_orientation:"+c_orientation+"--isNeedResetScreenOrientation:"+isNeedResetScreenOrientation);
+
         setStatusBarTextColor(intent.getBooleanExtra("statusBarTextColor", false));
         if (isHideTitle) {
             headerBbarView.setVisibility(View.GONE);
@@ -992,6 +998,7 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
                     webView.goBack();
                 }
             } else {
+                checkScreenOrientation();
                 super.onBackPressed();
             }
         } else {
@@ -1481,6 +1488,21 @@ public class HtmlActivity extends BaseActivity<ActivityHtml1Binding> implements
         }
     }
 
+
+    @Override
+    public void finish() {
+        checkScreenOrientation();
+        super.finish();
+    }
+
+    private void checkScreenOrientation() {
+        LOG.i("isNeedResetScreenOrientation:"+isNeedResetScreenOrientation);
+        if(isNeedResetScreenOrientation){
+            if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
+                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+            }
+        }
+    }
 }