summaryrefslogtreecommitdiff
path: root/platform/android/java/lib
diff options
context:
space:
mode:
authorYuri Sizov <11782833+YuriSizov@users.noreply.github.com>2023-03-27 20:14:47 +0200
committerGitHub <noreply@github.com>2023-03-27 20:14:47 +0200
commit19501f8eb19481b029f67ecf78e711d42f2fc431 (patch)
tree933ea3320b35bce6ba65ab1e1d1aa8ad662c90d4 /platform/android/java/lib
parentcacf49999e3fb37281d66cc591ca8bebc5712d4d (diff)
parent843f5adbc523ad2511322b4f09b5ce5a3fb9e225 (diff)
Merge pull request #75397 from YuriSizov/4.0-cherrypicks
Cherry-picks for the 4.0 branch (future 4.0.2) - 1st batch
Diffstat (limited to 'platform/android/java/lib')
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.java70
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt9
2 files changed, 70 insertions, 9 deletions
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
index a03da7292b..9b65a52b70 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
@@ -74,10 +74,14 @@ import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.Surface;
+import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
+import android.view.ViewTreeObserver;
import android.view.Window;
+import android.view.WindowInsets;
+import android.view.WindowInsetsAnimation;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
@@ -291,14 +295,64 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
editText.setView(mRenderView);
io.setEdit(editText);
- view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
- Point fullSize = new Point();
- activity.getWindowManager().getDefaultDisplay().getSize(fullSize);
- Rect gameSize = new Rect();
- mRenderView.getView().getWindowVisibleDisplayFrame(gameSize);
- final int keyboardHeight = fullSize.y - gameSize.bottom;
- GodotLib.setVirtualKeyboardHeight(keyboardHeight);
- });
+ // Listeners for keyboard height.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ // Report the height of virtual keyboard as it changes during the animation.
+ final View decorView = activity.getWindow().getDecorView();
+ decorView.setWindowInsetsAnimationCallback(new WindowInsetsAnimation.Callback(WindowInsetsAnimation.Callback.DISPATCH_MODE_STOP) {
+ int startBottom, endBottom;
+ @Override
+ public void onPrepare(@NonNull WindowInsetsAnimation animation) {
+ startBottom = decorView.getRootWindowInsets().getInsets(WindowInsets.Type.ime()).bottom;
+ }
+
+ @NonNull
+ @Override
+ public WindowInsetsAnimation.Bounds onStart(@NonNull WindowInsetsAnimation animation, @NonNull WindowInsetsAnimation.Bounds bounds) {
+ endBottom = decorView.getRootWindowInsets().getInsets(WindowInsets.Type.ime()).bottom;
+ return bounds;
+ }
+
+ @NonNull
+ @Override
+ public WindowInsets onProgress(@NonNull WindowInsets windowInsets, @NonNull List<WindowInsetsAnimation> list) {
+ // Find the IME animation.
+ WindowInsetsAnimation imeAnimation = null;
+ for (WindowInsetsAnimation animation : list) {
+ if ((animation.getTypeMask() & WindowInsets.Type.ime()) != 0) {
+ imeAnimation = animation;
+ break;
+ }
+ }
+ // Update keyboard height based on IME animation.
+ if (imeAnimation != null) {
+ float interpolatedFraction = imeAnimation.getInterpolatedFraction();
+ // Linear interpolation between start and end values.
+ float keyboardHeight = startBottom * (1.0f - interpolatedFraction) + endBottom * interpolatedFraction;
+ GodotLib.setVirtualKeyboardHeight((int)keyboardHeight);
+ }
+ return windowInsets;
+ }
+
+ @Override
+ public void onEnd(@NonNull WindowInsetsAnimation animation) {
+ }
+ });
+ } else {
+ // Infer the virtual keyboard height using visible area.
+ view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+ // Don't allocate a new Rect every time the callback is called.
+ final Rect visibleSize = new Rect();
+
+ @Override
+ public void onGlobalLayout() {
+ final SurfaceView view = mRenderView.getView();
+ view.getWindowVisibleDisplayFrame(visibleSize);
+ final int keyboardHeight = view.getHeight() - visibleSize.bottom;
+ GodotLib.setVirtualKeyboardHeight(keyboardHeight);
+ }
+ });
+ }
mRenderView.queueOnRenderThread(() -> {
for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt
index 833ab40af0..8ee3d5f48f 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt
+++ b/platform/android/java/lib/src/org/godotengine/godot/io/StorageScope.kt
@@ -76,6 +76,13 @@ internal enum class StorageScope {
return UNKNOWN
}
+ // If we have 'All Files Access' permission, we can access all directories without
+ // restriction.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
+ && Environment.isExternalStorageManager()) {
+ return APP
+ }
+
val canonicalPathFile = pathFile.canonicalPath
if (internalAppDir != null && canonicalPathFile.startsWith(internalAppDir)) {
@@ -90,7 +97,7 @@ internal enum class StorageScope {
return APP
}
- var rootDir: String? = System.getenv("ANDROID_ROOT")
+ val rootDir: String? = System.getenv("ANDROID_ROOT")
if (rootDir != null && canonicalPathFile.startsWith(rootDir)) {
return APP
}