Ver código fonte

修改H5页面部分横屏页面适配(部分手机从横屏返回竖屏页面会闪烁)

Pq 1 ano atrás
pai
commit
84c3632836

+ 33 - 0
student/src/main/java/com/cooleshow/student/ui/web/AccompanyActivity.java

@@ -4,6 +4,7 @@ import static com.cooleshow.base.common.WebConstants.WEB_URL;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.os.Handler;
 import android.text.TextUtils;
 import android.util.Log;
@@ -27,6 +28,7 @@ import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.service.PlayMusicService;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.utils.FileUtils;
+import com.cooleshow.base.utils.LOG;
 import com.cooleshow.base.utils.MyFileUtils;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.helper.WebParamsHelper;
@@ -82,6 +84,8 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
     private JSONObject baseJsonObject;
     private Intent intentOne;
 
+    private boolean isNeedResetScreenOrientation = true;
+
     @Override
     protected void initView() {
         camera = viewBinding.camera;
@@ -97,6 +101,10 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
             return;
         }
         int orientation = intent.getIntExtra("orientation", -1);
+        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);
+
         boolean isOpenLight = intent.getBooleanExtra("isOpenLight", false);
 
         if (isOpenLight) {
@@ -478,4 +486,29 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
         }
 
     }
+
+    @Override
+    public void finish() {
+        //为了适配华为mata40曲面屏,此页面是横屏,前一页面是竖屏,返回回去的时候会有UI闪动,所以这样处理
+        //观察发现横屏模式时候没有达到曲面最大效果(竖屏可以达到),猜测横屏模式就不是曲面模式了,这个时候回到前面(竖屏)页面,屏幕的最外层的容器可能会变化导致UI闪动
+        checkScreenOrientation();
+        super.finish();
+    }
+
+    @Override
+    public void onBackPressed() {
+        //为了适配华为mata40曲面屏,此页面是横屏,前一页面是竖屏,返回回去的时候会有UI闪动,所以这样处理
+        //观察发现横屏模式时候没有达到曲面最大效果(竖屏可以达到),猜测横屏模式就不是曲面模式了,这个时候回到前面(竖屏)页面,屏幕的最外层的容器可能会变化导致UI闪动
+        checkScreenOrientation();
+        super.onBackPressed();
+    }
+
+    private void checkScreenOrientation() {
+        LOG.i("isNeedResetScreenOrientation:" + isNeedResetScreenOrientation);
+        if (isNeedResetScreenOrientation) {
+            if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
+                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+            }
+        }
+    }
 }

+ 7 - 0
student/src/main/java/com/cooleshow/student/widgets/helper/JsInterfaceAccomPanyUtils.java

@@ -2,6 +2,7 @@ package com.cooleshow.student.widgets.helper;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.util.Log;
@@ -104,11 +105,13 @@ public class JsInterfaceAccomPanyUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = -1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                     } catch (Exception e) {
                     }
 
@@ -122,6 +125,7 @@ public class JsInterfaceAccomPanyUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
                 } else if ("openAccompanyWebView".equals(api)) {
                     JSONObject content = jsonObject.getJSONObject("content");
@@ -129,11 +133,13 @@ public class JsInterfaceAccomPanyUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = -1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation",ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                     } catch (Exception e) {
                     }
 
@@ -143,6 +149,7 @@ public class JsInterfaceAccomPanyUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
 
                 } else if ("startEvaluating".equals(api)) {

+ 7 - 0
student/src/main/java/com/cooleshow/student/widgets/helper/JsInterfaceUtils.java

@@ -4,6 +4,7 @@ import static com.cooleshow.base.common.WebConstants.WEB_URL;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.util.Log;
@@ -128,11 +129,13 @@ public class JsInterfaceUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = -1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                     } catch (Exception e) {
                     }
                     String path = RouterPath.WebCenter.ACTIVITY_HTML;
@@ -145,6 +148,7 @@ public class JsInterfaceUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
                 }
                 if ("openAccompanyWebView".equals(api)) {
@@ -153,11 +157,13 @@ public class JsInterfaceUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = 1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation",ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//当前页面的横竖屏,用于云教练页面页面关闭的时候判断
                     } catch (Exception e) {
                     }
                     ARouter.getInstance().build(RouterPath.WebCenter.ACTIVITY_ACCOMPANY_HTML)
@@ -166,6 +172,7 @@ public class JsInterfaceUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
 
                 }

+ 33 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/web/AccompanyActivity.java

@@ -2,6 +2,7 @@ package com.cooleshow.teacher.ui.web;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.net.Uri;
 import android.os.Handler;
 import android.text.TextUtils;
@@ -27,6 +28,7 @@ import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.service.PlayMusicService;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.utils.FileUtils;
+import com.cooleshow.base.utils.LOG;
 import com.cooleshow.base.utils.ToastUtil;
 import com.cooleshow.base.utils.helper.WebParamsHelper;
 import com.cooleshow.base.utils.helper.upload.UploadHelper;
@@ -82,6 +84,8 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
     private JSONObject baseJsonObject;
     private Intent intentOne;
 
+    private boolean isNeedResetScreenOrientation = true;
+
     @Override
     protected void initView() {
         camera = viewBinding.camera;
@@ -98,6 +102,10 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
         }
 
         int orientation = intent.getIntExtra("orientation", -1);
+        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);
+
         boolean isOpenLight = intent.getBooleanExtra("isOpenLight", false);
 
         if (isOpenLight) {
@@ -479,4 +487,29 @@ public class AccompanyActivity extends BaseMVPActivity<ActivityAccompanyBinding,
         }
 
     }
+
+    @Override
+    public void finish() {
+        //为了适配华为mata40曲面屏,此页面是横屏,前一页面是竖屏,返回回去的时候会有UI闪动,所以这样处理
+        //观察发现横屏模式时候没有达到曲面最大效果(竖屏可以达到),猜测横屏模式就不是曲面模式了,这个时候回到前面(竖屏)页面,屏幕的最外层的容器可能会变化导致UI闪动
+        checkScreenOrientation();
+        super.finish();
+    }
+
+    @Override
+    public void onBackPressed() {
+        //为了适配华为mata40曲面屏,此页面是横屏,前一页面是竖屏,返回回去的时候会有UI闪动,所以这样处理
+        //观察发现横屏模式时候没有达到曲面最大效果(竖屏可以达到),猜测横屏模式就不是曲面模式了,这个时候回到前面(竖屏)页面,屏幕的最外层的容器可能会变化导致UI闪动
+        checkScreenOrientation();
+        super.onBackPressed();
+    }
+
+    private void checkScreenOrientation() {
+        LOG.i("isNeedResetScreenOrientation:" + isNeedResetScreenOrientation);
+        if (isNeedResetScreenOrientation) {
+            if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
+                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+            }
+        }
+    }
 }

+ 7 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/helper/JsInterfaceAccomPanyUtils.java

@@ -2,6 +2,7 @@ package com.cooleshow.teacher.widgets.helper;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.view.Window;
@@ -100,11 +101,13 @@ public class JsInterfaceAccomPanyUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = -1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation",ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                     } catch (Exception e) {
                     }
 
@@ -118,6 +121,7 @@ public class JsInterfaceAccomPanyUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
                 } else if ("openAccompanyWebView".equals(api)) {
                     JSONObject content = jsonObject.getJSONObject("content");
@@ -125,11 +129,13 @@ public class JsInterfaceAccomPanyUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = -1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                     } catch (Exception e) {
                     }
 
@@ -139,6 +145,7 @@ public class JsInterfaceAccomPanyUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
 
                 } else if ("startEvaluating".equals(api)) {

+ 7 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/helper/JsInterfaceUtils.java

@@ -4,6 +4,7 @@ import static com.cooleshow.base.common.WebConstants.WEB_URL;
 
 import android.app.Activity;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.net.Uri;
 import android.text.TextUtils;
 import android.view.Window;
@@ -140,11 +141,13 @@ public class JsInterfaceUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = -1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                     } catch (Exception e) {
                     }
                     String path = RouterPath.WebCenter.ACTIVITY_HTML;
@@ -157,6 +160,7 @@ public class JsInterfaceUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
                     return;
                 }
@@ -166,11 +170,13 @@ public class JsInterfaceUtils extends Object {
                     boolean statusBarTextColor = false;
                     boolean isOpenLight = false;
                     int orientation = -1;
+                    int c_orientation = 1;
                     try {
                         isHideTitle = content.getBoolean("isHideTitle");
                         statusBarTextColor = content.getBoolean("statusBarTextColor");
                         isOpenLight = content.getBoolean("isOpenLight");
                         orientation = content.getInt("orientation");
+                        c_orientation = content.optInt("c_orientation",ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//当前页面的横竖屏,用于云教练页面页面关闭的时候判断
                     } catch (Exception e) {
                     }
                     ARouter.getInstance().build(RouterPath.WebCenter.ACTIVITY_ACCOMPANY_HTML)
@@ -179,6 +185,7 @@ public class JsInterfaceUtils extends Object {
                             .withBoolean("statusBarTextColor", statusBarTextColor)
                             .withBoolean("isOpenLight", isOpenLight)
                             .withInt("orientation", orientation)
+                            .withInt("c_orientation", c_orientation)
                             .navigation();
                     return;