You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Implement OS.get_window_safe_area() for Android
This commit is contained in:
@@ -37,12 +37,16 @@ import android.content.*;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Point;
|
||||
import android.media.*;
|
||||
import android.net.Uri;
|
||||
import android.os.*;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.Display;
|
||||
import android.view.DisplayCutout;
|
||||
import android.view.WindowInsets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -461,6 +465,28 @@ public class GodotIO {
|
||||
return (int)(metrics.density * 160f);
|
||||
}
|
||||
|
||||
public int[] screenGetUsableRect() {
|
||||
DisplayMetrics metrics = activity.getResources().getDisplayMetrics();
|
||||
Display display = activity.getWindowManager().getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getRealSize(size);
|
||||
|
||||
int result[] = { 0, 0, size.x, size.y };
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
WindowInsets insets = activity.getWindow().getDecorView().getRootWindowInsets();
|
||||
DisplayCutout cutout = insets.getDisplayCutout();
|
||||
if (cutout != null) {
|
||||
int insetLeft = cutout.getSafeInsetLeft();
|
||||
int insetTop = cutout.getSafeInsetTop();
|
||||
result[0] = insetLeft;
|
||||
result[1] = insetTop;
|
||||
result[2] -= insetLeft + cutout.getSafeInsetRight();
|
||||
result[3] -= insetTop + cutout.getSafeInsetBottom();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void showKeyboard(String p_existing_text, boolean p_multiline, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||
if (edit != null)
|
||||
edit.showKeyboard(p_existing_text, p_multiline, p_max_input_length, p_cursor_start, p_cursor_end);
|
||||
|
||||
Reference in New Issue
Block a user