From 9e6d9131ee004c06f0515a2957f51d38a7e9f6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Thu, 22 Apr 2021 16:43:30 +0800 Subject: [PATCH] android: fix fullscreen without virtual navigation --- .../java/pub/doric/plugin/KeyboardPlugin.java | 13 +++++++--- .../main/java/pub/doric/utils/DoricUtils.java | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/plugin/KeyboardPlugin.java b/doric-android/doric/src/main/java/pub/doric/plugin/KeyboardPlugin.java index cb4c967a..a3d3d847 100644 --- a/doric-android/doric/src/main/java/pub/doric/plugin/KeyboardPlugin.java +++ b/doric-android/doric/src/main/java/pub/doric/plugin/KeyboardPlugin.java @@ -9,6 +9,7 @@ import androidx.annotation.RequiresApi; import com.github.pengfeizhou.jscore.JSString; import com.github.pengfeizhou.jscore.JavaValue; import com.qmuiteam.qmui.util.QMUIKeyboardHelper; +import com.qmuiteam.qmui.util.QMUIStatusBarHelper; import org.json.JSONException; import org.json.JSONObject; @@ -50,7 +51,13 @@ public class KeyboardPlugin extends DoricJavaPlugin { activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int usableHeight = metrics.heightPixels; - final int virtualNavigationHeight = realHeight - usableHeight; + boolean navigationBarShow = DoricUtils.checkNavigationBarShow(activity, activity.getWindow()); + final int space; + if (navigationBarShow) { + space = realHeight - usableHeight; + } else { + space = QMUIStatusBarHelper.getStatusbarHeight(activity); + } QMUIKeyboardHelper.setVisibilityEventListener(activity, new QMUIKeyboardHelper.KeyboardVisibilityEventListener() { @Override @@ -66,9 +73,9 @@ public class KeyboardPlugin extends DoricJavaPlugin { data.put("oldBottomMargin", 0); data.put("bottomMargin", 0); data.put("oldHeight", keyboardHeight); - data.put("height", DoricUtils.px2dp(heightDiff - virtualNavigationHeight)); + data.put("height", DoricUtils.px2dp(heightDiff - space)); - keyboardHeight = DoricUtils.px2dp(heightDiff - virtualNavigationHeight); + keyboardHeight = DoricUtils.px2dp(heightDiff - space); callback.resolve(new JavaValue(data)); } catch (JSONException e) { diff --git a/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java b/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java index 5a365ea9..283b0734 100644 --- a/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java +++ b/doric-android/doric/src/main/java/pub/doric/utils/DoricUtils.java @@ -21,13 +21,18 @@ import android.content.ContextWrapper; import android.content.res.AssetManager; import android.content.res.Configuration; import android.content.res.Resources; +import android.graphics.Point; import android.graphics.Rect; +import android.os.Build; import android.util.DisplayMetrics; import android.util.Pair; import android.view.Display; +import android.view.View; +import android.view.Window; import android.view.WindowManager; import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSDecoder; @@ -329,4 +334,25 @@ public class DoricUtils { } return context; } + + + @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1) + public static boolean checkNavigationBarShow(@NonNull Context context, @NonNull Window window) { + boolean show; + Display display = window.getWindowManager().getDefaultDisplay(); + Point point = new Point(); + display.getRealSize(point); + + View decorView = window.getDecorView(); + Configuration conf = context.getResources().getConfiguration(); + if (Configuration.ORIENTATION_LANDSCAPE == conf.orientation) { + View contentView = decorView.findViewById(android.R.id.content); + show = (point.x != contentView.getWidth()); + } else { + Rect rect = new Rect(); + decorView.getWindowVisibleDisplayFrame(rect); + show = (rect.bottom != point.y); + } + return show; + } }