Browse Source

增加H5交互api

Pq 1 year ago
parent
commit
cd26be4735

+ 30 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/helper/QMUIStatusBarHelper.java

@@ -459,6 +459,36 @@ public class QMUIStatusBarHelper {
         }
     }
 
+    public static void hideStatusBar(Activity activity) {
+        if (activity == null) return;
+        Window window = activity.getWindow();
+        if (window == null) return;
+        // 隐藏状态栏
+        window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        window.getDecorView().setSystemUiVisibility(
+                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                        | View.SYSTEM_UI_FLAG_FULLSCREEN);
+        WindowManager.LayoutParams lp = window.getAttributes();
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
+        }
+        window.setAttributes(lp);
+    }
+
+    public static void showStatusBar(Activity activity) {
+        if (activity == null) return;
+        Window window = activity.getWindow();
+        if (window == null) return;
+        window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+        WindowManager.LayoutParams lp = window.getAttributes();
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
+        }
+        window.setAttributes(lp);
+    }
+
     public static void setVirtualDensity(float density) {
         sVirtualDensity = density;
     }

+ 19 - 2
student/src/main/java/com/cooleshow/student/widgets/helper/JsInterfaceUtils.java

@@ -15,6 +15,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
 import com.cooleshow.base.common.WebApi;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.utils.LOG;
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
 import com.cooleshow.chatmodule.utils.helper.ChatHelper;
 import com.cooleshow.student.helper.EventHelper;
 import com.cooleshow.usercenter.constants.UserConstants;
@@ -54,10 +55,14 @@ public class JsInterfaceUtils extends Object {
             try {
                 JSONObject jsonObject = new JSONObject(message);
                 String api = jsonObject.getString("api");
-                LOG.i("api:"+api);
+                LOG.i("postMessage:" + jsonObject.toString());
                 if ("back".equals(api)) {
                     activity.finish();
                 }
+                if (TextUtils.equals("goBack", api)) {
+                    activity.finish();
+                    return;
+                }
                 if ("login".equals(api)) {
                     UserHelper.logout();
                     activity.finish();
@@ -67,7 +72,7 @@ public class JsInterfaceUtils extends Object {
                     if (null != contentBean) {
                         String userId = contentBean.optString("userId");
                         String name = contentBean.optString("name");
-                        ChatHelper.getInstance().goChat(userId,name);
+                        ChatHelper.getInstance().goChat(userId, name);
                     }
                 }
                 if (TextUtils.equals("chooseFile", api)) {
@@ -244,6 +249,18 @@ public class JsInterfaceUtils extends Object {
                     }
                 }
 
+                if ("setStatusBarVisibility".equalsIgnoreCase(api)) {
+                    //控制顶部状态显示隐藏
+                    JSONObject content = jsonObject.getJSONObject("content");
+                    int result = content.optInt("isVisibility", 1);//1显示 0隐藏
+                    if (result == 0) {
+                        QMUIStatusBarHelper.hideStatusBar(activity);
+                    } else {
+                        QMUIStatusBarHelper.showStatusBar(activity);
+                    }
+                    return;
+                }
+
                 if (TextUtils.equals(WebApi.SET_EVENT_TRACKING, api)) {
                     //事件埋点
                     JSONObject content = jsonObject.getJSONObject("content");

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

@@ -13,7 +13,9 @@ import android.webkit.JavascriptInterface;
 import com.alibaba.android.arouter.launcher.ARouter;
 import com.cooleshow.base.common.WebApi;
 import com.cooleshow.base.router.RouterPath;
+import com.cooleshow.base.utils.LOG;
 import com.cooleshow.base.utils.LogUtils;
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
 import com.cooleshow.chatmodule.utils.helper.ChatHelper;
 import com.cooleshow.teacher.helper.EventHelper;
 import com.cooleshow.usercenter.constants.UserConstants;
@@ -52,10 +54,15 @@ public class JsInterfaceUtils extends Object {
             try {
                 JSONObject jsonObject = new JSONObject(message);
                 String api = jsonObject.getString("api");
+                LOG.i("postMessage:"+jsonObject.toString());
                 if ("back".equals(api)) {
                     activity.finish();
                     return;
                 }
+                if (TextUtils.equals("goBack", api)) {
+                    activity.finish();
+                    return;
+                }
                 if ("login".equals(api)) {
                     UserHelper.logout();
                     activity.finish();
@@ -267,6 +274,18 @@ public class JsInterfaceUtils extends Object {
                     return;
                 }
 
+                if ("setStatusBarVisibility".equalsIgnoreCase(api)) {
+                    //控制顶部状态显示隐藏
+                    JSONObject content = jsonObject.getJSONObject("content");
+                    int result = content.optInt("isVisibility", 1);//1显示 0隐藏
+                    if (result == 0) {
+                        QMUIStatusBarHelper.hideStatusBar(activity);
+                    } else {
+                        QMUIStatusBarHelper.showStatusBar(activity);
+                    }
+                    return;
+                }
+
                 if (TextUtils.equals(WebApi.OPEN_PAGE_SUCCESS, api)) {
                     JSONObject content = jsonObject.getJSONObject("content");
                     if (content != null) {