Skip to content

Commit

Permalink
Merge pull request #10442 from keymanapp/fix/android/landscape-kb-pic…
Browse files Browse the repository at this point in the history
…ker-osk

fix(android/engine): Fix OSK widths
  • Loading branch information
darcywong00 authored Jan 25, 2024
2 parents 4cd2cd4 + e2b8cf3 commit 811ea81
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions android/KMAPro/kMAPro/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -59,6 +60,7 @@
android:name=".SplashScreenActivity"
android:exported="true"
android:label="@string/app_name"
android:resizeableActivity="false"
android:theme="@style/AppTheme.BrandedLaunch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Configuration newConfig = this.getResources().getConfiguration();
if (newConfig != null && newConfig.orientation != lastOrientation) {
lastOrientation = newConfig.orientation;
// using KMManager.getOrientation() since getConfiguration().orientation is unreliable #10241
int newOrientation = KMManager.getOrientation(context);
if (newOrientation != lastOrientation) {
lastOrientation = newOrientation;
Configuration newConfig = this.getResources().getConfiguration();
KMManager.onConfigurationChanged(newConfig);
}
resizeTextView(textView.isKeyboardVisible());
Expand Down
1 change: 1 addition & 0 deletions android/KMEA/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<uses-permission android:name="android.permission.INTERNET" tools:node="remove" />

<application
android:resizeableActivity="false"
android:theme="@style/AppTheme" >

<!-- Have application handle initializing Sentry -->
Expand Down
18 changes: 14 additions & 4 deletions android/KMEA/app/src/main/java/com/keyman/engine/KMManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}

Expand Down

0 comments on commit 811ea81

Please sign in to comment.