android: fix fullscreen without virtual navigation

This commit is contained in:
王劲鹏 2021-04-22 16:43:30 +08:00 committed by osborn
parent c82fdf1a0d
commit 9e6d9131ee
2 changed files with 36 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import androidx.annotation.RequiresApi;
import com.github.pengfeizhou.jscore.JSString; import com.github.pengfeizhou.jscore.JSString;
import com.github.pengfeizhou.jscore.JavaValue; import com.github.pengfeizhou.jscore.JavaValue;
import com.qmuiteam.qmui.util.QMUIKeyboardHelper; import com.qmuiteam.qmui.util.QMUIKeyboardHelper;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -50,7 +51,13 @@ public class KeyboardPlugin extends DoricJavaPlugin {
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels; 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() { QMUIKeyboardHelper.setVisibilityEventListener(activity, new QMUIKeyboardHelper.KeyboardVisibilityEventListener() {
@Override @Override
@ -66,9 +73,9 @@ public class KeyboardPlugin extends DoricJavaPlugin {
data.put("oldBottomMargin", 0); data.put("oldBottomMargin", 0);
data.put("bottomMargin", 0); data.put("bottomMargin", 0);
data.put("oldHeight", keyboardHeight); 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)); callback.resolve(new JavaValue(data));
} catch (JSONException e) { } catch (JSONException e) {

View File

@ -21,13 +21,18 @@ import android.content.ContextWrapper;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Build;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Pair; import android.util.Pair;
import android.view.Display; import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import com.github.pengfeizhou.jscore.JSArray; import com.github.pengfeizhou.jscore.JSArray;
import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JSDecoder;
@ -329,4 +334,25 @@ public class DoricUtils {
} }
return context; 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;
}
} }