summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMing-Shin Lu <lumark@google.com>2022-01-13 02:35:54 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-01-13 02:35:54 +0000
commit36c1220335eca246104f498205dbcf62915fdecd (patch)
treeaed1df1aff1f55c18366e0493d9e940b28701ac6
parent68103a8646726bc0bbe9d97e744d2b72c96c79b4 (diff)
parent6c752d8eca0c74a1d9376fe38dba30f6038733ee (diff)
downloadLatinIME-36c1220335eca246104f498205dbcf62915fdecd.tar.gz
Using IME context to inflate layout from S_V2 am: 6c752d8eca
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/inputmethods/LatinIME/+/16613686 Change-Id: Id87eb67dbf2e4c8bc7060e5a8a524d30629f0571
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java56
1 files changed, 37 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index a99f0b48c..8ed3a59bf 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -16,8 +16,6 @@
package com.android.inputmethod.latin;
-import static android.view.Display.INVALID_DISPLAY;
-
import static com.android.inputmethod.latin.common.Constants.ImeOption.FORCE_ASCII;
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE;
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE_COMPAT;
@@ -46,6 +44,7 @@ import android.util.Log;
import android.util.PrintWriterPrinter;
import android.util.Printer;
import android.util.SparseArray;
+import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
@@ -56,12 +55,13 @@ import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
+import androidx.annotation.NonNull;
+
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.BuildCompatUtils;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils;
import com.android.inputmethod.compat.ViewOutlineProviderCompatUtils.InsetsUpdater;
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
@@ -170,7 +170,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Used for re-initialize keyboard layout after onConfigurationChange.
@Nullable private Context mDisplayContext;
- private int mCurDisplayId = INVALID_DISPLAY;
// Object for reacting to adding/removing a dictionary pack.
private final BroadcastReceiver mDictionaryPackInstallReceiver =
@@ -604,8 +603,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
AccessibilityUtils.init(this);
mStatsUtilsManager.onCreate(this /* context */, mDictionaryFacilitator);
final WindowManager wm = getSystemService(WindowManager.class);
- mDisplayContext = createDisplayContext(wm.getDefaultDisplay());
- mCurDisplayId = wm.getDefaultDisplay().getDisplayId();
+ mDisplayContext = getDisplayContext();
KeyboardSwitcher.init(this);
super.onCreate();
@@ -795,20 +793,40 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onInitializeInterface() {
- // TODO (b/133825283): Non-activity components Resources / DisplayMetrics update when
- // moving to external display.
- // An issue in Q that non-activity components Resources / DisplayMetrics in
- // Context doesn't well updated when moving to external display.
- // Currently we do a workaround is to check if IME is moving to new display, if so,
- // create new display context and re-init keyboard layout with this context.
- final WindowManager wm = getSystemService(WindowManager.class);
- final int newDisplayId = wm.getDefaultDisplay().getDisplayId();
- if (mCurDisplayId != newDisplayId || !mDisplayContext.getResources().getConfiguration()
- .equals(getResources().getConfiguration())) {
- mCurDisplayId = newDisplayId;
- mDisplayContext = createDisplayContext(wm.getDefaultDisplay());
- mKeyboardSwitcher.updateKeyboardTheme(mDisplayContext);
+ mDisplayContext = getDisplayContext();
+ mKeyboardSwitcher.updateKeyboardTheme(mDisplayContext);
+ }
+
+ /**
+ * Returns the context object whose resources are adjusted to match the metrics of the display.
+ *
+ * Note that before {@link android.os.Build.VERSION_CODES#KITKAT}, there is no way to support
+ * multi-display scenarios, so the context object will just return the IME context itself.
+ *
+ * With initiating multi-display APIs from {@link android.os.Build.VERSION_CODES#KITKAT}, the
+ * context object has to return with re-creating the display context according the metrics
+ * of the display in runtime.
+ *
+ * Starts from {@link android.os.Build.VERSION_CODES#S_V2}, the returning context object has
+ * became to IME context self since it ends up capable of updating its resources internally.
+ *
+ * @see android.content.Context#createDisplayContext(Display)
+ */
+ private @NonNull Context getDisplayContext() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+ // createDisplayContext is not available.
+ return this;
+ }
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2) {
+ // IME context sources is now managed by WindowProviderService from Android 12L.
+ return this;
}
+ // An issue in Q that non-activity components Resources / DisplayMetrics in
+ // Context doesn't well updated when the IME window moving to external display.
+ // Currently we do a workaround is to create new display context directly and re-init
+ // keyboard layout with this context.
+ final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
+ return createDisplayContext(wm.getDefaultDisplay());
}
@Override