From 338a8ac046bd105c129f3acc2e46b4550ee8cb0a Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 19 Jan 2024 07:40:07 +0700 Subject: [PATCH 1/6] fix(android/app): Apply resizeableActivity to entire app --- android/KMAPro/kMAPro/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/AndroidManifest.xml b/android/KMAPro/kMAPro/src/main/AndroidManifest.xml index fcaa99bed4b..bb392b850f9 100644 --- a/android/KMAPro/kMAPro/src/main/AndroidManifest.xml +++ b/android/KMAPro/kMAPro/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" + android:resizeableActivity="false" android:usesCleartextTraffic="true" android:theme="@style/AppTheme" android:supportsRtl="true"> @@ -71,7 +72,6 @@ android:exported="true" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize" android:label="@string/app_name" - android:resizeableActivity="false" android:launchMode="singleTask"> From 4785c6bf0101d3468a7278c6bec46e201c089ce1 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Mon, 22 Jan 2024 13:56:36 +0700 Subject: [PATCH 2/6] fix(android/engine): Try other settings to fix OSK width --- android/KMAPro/kMAPro/src/main/AndroidManifest.xml | 2 ++ android/KMEA/app/src/main/AndroidManifest.xml | 1 + .../KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java | 1 + 3 files changed, 4 insertions(+) diff --git a/android/KMAPro/kMAPro/src/main/AndroidManifest.xml b/android/KMAPro/kMAPro/src/main/AndroidManifest.xml index bb392b850f9..7a90ccc957c 100644 --- a/android/KMAPro/kMAPro/src/main/AndroidManifest.xml +++ b/android/KMAPro/kMAPro/src/main/AndroidManifest.xml @@ -60,6 +60,7 @@ android:name=".SplashScreenActivity" android:exported="true" android:label="@string/app_name" + android:resizeableActivity="false" android:theme="@style/AppTheme.BrandedLaunch"> @@ -72,6 +73,7 @@ android:exported="true" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize" android:label="@string/app_name" + android:resizeableActivity="false" android:launchMode="singleTask"> diff --git a/android/KMEA/app/src/main/AndroidManifest.xml b/android/KMEA/app/src/main/AndroidManifest.xml index c4522addc4a..304d715ee75 100644 --- a/android/KMEA/app/src/main/AndroidManifest.xml +++ b/android/KMEA/app/src/main/AndroidManifest.xml @@ -15,6 +15,7 @@ diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java index d17c3316971..ca2ad072165 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java @@ -186,6 +186,7 @@ public void initKMKeyboard(final Context context) { clearCache(true); getSettings().setJavaScriptEnabled(true); getSettings().setAllowFileAccess(true); + getSettings().setSupportMultipleWindows(false); // Normally, this would be true to prevent the WebView from accessing the network. // But this needs to false for sending embedded KMW crash reports to Sentry (keymanapp/keyman#3825) From 4718b5bb20103b8dd8fd3a4fd77f40f0c3587623 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 24 Jan 2024 12:53:38 +0700 Subject: [PATCH 3/6] refactor(android/engine): Refactor detection of device orientation --- .../kmapro/AdjustKeyboardHeightActivity.java | 8 ++------ .../com/tavultesoft/kmapro/MainActivity.java | 6 ++++-- .../main/java/com/keyman/engine/KMManager.java | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index a959bb1df63..a371adc1292 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -8,12 +8,9 @@ import android.content.res.Configuration; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; -import android.view.Display; import android.view.MotionEvent; -import android.view.Surface; import android.view.View; import android.view.ViewGroup; -import android.view.WindowManager; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; @@ -110,9 +107,8 @@ public boolean onTouch(View view, MotionEvent event) { break; case MotionEvent.ACTION_UP: // Save the currentHeight when the user releases - Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - int rotation = display.getRotation(); - String keyboardHeightKey = (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) ? + int orientation = KMManager.getOrientation(context);; + String keyboardHeightKey = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? KMManager.KMKey_KeyboardHeightLandscape : KMManager.KMKey_KeyboardHeightPortrait; editor.putInt(keyboardHeightKey, currentHeight); editor.commit(); diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java index 16899f7c2d9..d135513502d 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java @@ -267,9 +267,11 @@ protected void onResume() { // onConfigurationChanged() only triggers when device is rotated while app is in foreground // This handles when device is rotated while app is in background + // using KMManager.getOrientation() since getConfiguration().orientation is unreliable #10241 Configuration newConfig = this.getResources().getConfiguration(); - if (newConfig != null && newConfig.orientation != lastOrientation) { - lastOrientation = newConfig.orientation; + int newOrientation = KMManager.getOrientation(context); + if (newOrientation != lastOrientation) { + lastOrientation = newOrientation; KMManager.onConfigurationChanged(newConfig); } resizeTextView(textView.isKeyboardVisible()); diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java index c20dd6db59b..1d2593baf75 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java @@ -1998,6 +1998,17 @@ public static void removeKeyboardEventListener(OnKeyboardEventListener listener) KMKeyboard.removeOnKeyboardEventListener(listener); } + public static int getOrientation(Context context) { + Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + int rotation = display.getRotation(); + if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { + return Configuration.ORIENTATION_PORTRAIT; + } else if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { + return Configuration.ORIENTATION_LANDSCAPE; + } + return Configuration.ORIENTATION_UNDEFINED; + } + public static int getBannerHeight(Context context) { int bannerHeight = 0; if (InAppKeyboard != null && InAppKeyboard.getBanner() != BannerType.BLANK) { @@ -2012,11 +2023,10 @@ public static int getKeyboardHeight(Context context) { int defaultHeight = (int) context.getResources().getDimension(R.dimen.keyboard_height); SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); - Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - int rotation = display.getRotation(); - if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { + int orientation = getOrientation(context); + if (orientation == Configuration.ORIENTATION_PORTRAIT) { return prefs.getInt(KMManager.KMKey_KeyboardHeightPortrait, defaultHeight); - } else if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { + } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return prefs.getInt(KMManager.KMKey_KeyboardHeightLandscape, defaultHeight); } From 72bcb30545d8d31a373239561a02b70e9e63d732 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 24 Jan 2024 13:32:42 +0700 Subject: [PATCH 4/6] chore(android/engine): Revert KMKeyboard change --- android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java index ca2ad072165..d17c3316971 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/KMKeyboard.java @@ -186,7 +186,6 @@ public void initKMKeyboard(final Context context) { clearCache(true); getSettings().setJavaScriptEnabled(true); getSettings().setAllowFileAccess(true); - getSettings().setSupportMultipleWindows(false); // Normally, this would be true to prevent the WebView from accessing the network. // But this needs to false for sending embedded KMW crash reports to Sentry (keymanapp/keyman#3825) From 4cffe74900910ea9fa9cacc97958507431c0a09a Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Wed, 24 Jan 2024 14:02:28 +0700 Subject: [PATCH 5/6] chore(android/app): Move scope of newConfig --- .../src/main/java/com/tavultesoft/kmapro/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java index d135513502d..98baa169ab4 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java @@ -268,10 +268,10 @@ protected void onResume() { // onConfigurationChanged() only triggers when device is rotated while app is in foreground // This handles when device is rotated while app is in background // using KMManager.getOrientation() since getConfiguration().orientation is unreliable #10241 - Configuration newConfig = this.getResources().getConfiguration(); int newOrientation = KMManager.getOrientation(context); if (newOrientation != lastOrientation) { lastOrientation = newOrientation; + Configuration newConfig = this.getResources().getConfiguration(); KMManager.onConfigurationChanged(newConfig); } resizeTextView(textView.isKeyboardVisible()); From e2b8cf31b0370556335686f7a13535eb59a1a9e6 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Thu, 25 Jan 2024 11:05:56 +0700 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Marc Durdin --- .../com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java index a371adc1292..de4530fe3a4 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -107,7 +107,7 @@ public boolean onTouch(View view, MotionEvent event) { break; case MotionEvent.ACTION_UP: // Save the currentHeight when the user releases - int orientation = KMManager.getOrientation(context);; + int orientation = KMManager.getOrientation(context); String keyboardHeightKey = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? KMManager.KMKey_KeyboardHeightLandscape : KMManager.KMKey_KeyboardHeightPortrait; editor.putInt(keyboardHeightKey, currentHeight);