aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java20
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java20
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java7
-rw-r--r--java/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtils.java5
-rw-r--r--java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java39
5 files changed, 66 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 6d36af77a..0594c68cc 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -199,7 +199,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
latinIme.mSettings.getCurrent());
break;
case MSG_UPDATE_SHIFT_STATE:
- switcher.requestUpdatingShiftState();
+ switcher.requestUpdatingShiftState(latinIme.getCurrentAutoCapsState(),
+ latinIme.getCurrentRecapitalizeState());
break;
case MSG_SHOW_GESTURE_PREVIEW_AND_SUGGESTION_STRIP:
if (msg.arg1 == ARG1_NOT_GESTURE_INPUT) {
@@ -635,6 +636,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
super.onDestroy();
}
+ @UsedForTesting
+ public void recycle() {
+ mInputLogic.recycle();
+ }
+
@Override
public void onConfigurationChanged(final Configuration conf) {
// If orientation changed while predicting, commit the change
@@ -838,7 +844,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// we need to re-evaluate the shift state, but not the whole layout which would be
// disruptive.
// Space state must be updated before calling updateShiftState
- switcher.requestUpdatingShiftState();
+ switcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
+ getCurrentRecapitalizeState());
}
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
@@ -917,7 +924,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: find a better way to simulate actual execution.
if (isInputViewShown() &&
mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd)) {
- mKeyboardSwitcher.requestUpdatingShiftState();
+ mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
+ getCurrentRecapitalizeState());
}
mSubtypeState.currentSubtypeUsed();
@@ -1261,7 +1269,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: have the keyboard pass the correct key code when we need it.
final Event event = Event.createSoftwareTextEvent(rawText, Event.NOT_A_KEY_CODE);
mInputLogic.onTextInput(mSettings.getCurrent(), event, mHandler);
- mKeyboardSwitcher.requestUpdatingShiftState();
+ mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
+ getCurrentRecapitalizeState());
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT, getCurrentAutoCapsState());
}
@@ -1505,7 +1514,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mHandler.postUpdateShiftState();
break;
case InputTransaction.SHIFT_UPDATE_NOW:
- mKeyboardSwitcher.requestUpdatingShiftState();
+ mKeyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(),
+ getCurrentRecapitalizeState());
break;
default: // SHIFT_NO_UPDATE
}
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 7cf8c5e49..bf8467eb6 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -148,6 +148,17 @@ public final class InputLogic {
mInputLogicHandler.reset();
}
+ // Normally this class just gets out of scope after the process ends, but in unit tests, we
+ // create several instances of LatinIME in the same process, which results in several
+ // instances of InputLogic. This cleans up the associated handler so that tests don't leak
+ // handlers.
+ public void recycle() {
+ final InputLogicHandler inputLogicHandler = mInputLogicHandler;
+ mInputLogicHandler = InputLogicHandler.NULL_HANDLER;
+ inputLogicHandler.destroy();
+ mSuggest.mDictionaryFacilitator.closeDictionaries();
+ }
+
/**
* React to a string input.
*
@@ -537,7 +548,8 @@ public final class InputLogic {
// after typing some letters and a period, then gesturing; the keyboard is not in
// caps mode yet, but since a gesture is starting, it should go in caps mode,
// unless the user explictly said it should not.
- keyboardSwitcher.requestUpdatingShiftState();
+ keyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(settingsValues),
+ getCurrentRecapitalizeState());
}
}
mConnection.endBatchEdit();
@@ -579,7 +591,8 @@ public final class InputLogic {
promotePhantomSpace(settingsValues);
mConnection.commitText(commitParts[0], 0);
mSpaceState = SpaceState.PHANTOM;
- keyboardSwitcher.requestUpdatingShiftState();
+ keyboardSwitcher.requestUpdatingShiftState(
+ getCurrentAutoCapsState(settingsValues), getCurrentRecapitalizeState());
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
getActualCapsMode(settingsValues,
keyboardSwitcher.getKeyboardShiftMode()), commitParts[0]);
@@ -1819,7 +1832,8 @@ public final class InputLogic {
}
// Space state must be updated before calling updateShiftState
mSpaceState = SpaceState.PHANTOM;
- keyboardSwitcher.requestUpdatingShiftState();
+ keyboardSwitcher.requestUpdatingShiftState(getCurrentAutoCapsState(settingsValues),
+ getCurrentRecapitalizeState());
}
/**
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
index e3b8ab465..64bba681f 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
@@ -20,6 +20,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
+import com.android.inputmethod.compat.LooperCompatUtils;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.Suggest;
@@ -80,6 +81,12 @@ class InputLogicHandler implements Handler.Callback {
mNonUIThreadHandler.removeCallbacksAndMessages(null);
}
+ // In unit tests, we create several instances of LatinIME, which results in several instances
+ // of InputLogicHandler. To avoid these handlers lingering, we call this.
+ public void destroy() {
+ LooperCompatUtils.quitSafely(mNonUIThreadHandler.getLooper());
+ }
+
/**
* Handle a message.
* @see android.os.Handler.Callback#handleMessage(android.os.Message)
diff --git a/java/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtils.java b/java/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtils.java
index 89837c641..1ca895fdb 100644
--- a/java/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/SpacebarLanguageUtils.java
@@ -18,8 +18,6 @@ package com.android.inputmethod.latin.utils;
import android.view.inputmethod.InputMethodSubtype;
-import java.util.Locale;
-
public final class SpacebarLanguageUtils {
private SpacebarLanguageUtils() {
// Intentional empty constructor for utility class.
@@ -55,7 +53,6 @@ public final class SpacebarLanguageUtils {
if (SubtypeLocaleUtils.isNoLanguage(subtype)) {
return SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype);
}
- final Locale locale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
- return SubtypeLocaleUtils.getSubtypeLocaleDisplayName(locale.getLanguage());
+ return SubtypeLocaleUtils.getSubtypeLanguageDisplayName(subtype.getLocale());
}
}
diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
index 2452864d5..b37779bdc 100644
--- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
@@ -25,7 +25,7 @@ import android.os.Build;
import android.util.Log;
import android.view.inputmethod.InputMethodSubtype;
-import com.android.inputmethod.latin.DictionaryFactory;
+import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import java.util.Arrays;
@@ -33,10 +33,10 @@ import java.util.HashMap;
import java.util.Locale;
public final class SubtypeLocaleUtils {
- static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
- // This class must be located in the same package as LatinIME.java.
- private static final String RESOURCE_PACKAGE_NAME =
- DictionaryFactory.class.getPackage().getName();
+ private static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
+
+ // This reference class {@link Constants} must be located in the same package as LatinIME.java.
+ private static final String RESOURCE_PACKAGE_NAME = Constants.class.getPackage().getName();
// Special language code to represent "no language".
public static final String NO_LANGUAGE = "zz";
@@ -44,7 +44,8 @@ public final class SubtypeLocaleUtils {
public static final String EMOJI = "emoji";
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
- private static boolean sInitialized = false;
+ private static volatile boolean sInitialized = false;
+ private static final Object sInitializeLock = new Object();
private static Resources sResources;
private static String[] sPredefinedKeyboardLayoutSet;
// Keyboard layout to its display name map.
@@ -77,9 +78,16 @@ public final class SubtypeLocaleUtils {
}
// Note that this initialization method can be called multiple times.
- public static synchronized void init(final Context context) {
- if (sInitialized) return;
+ public static void init(final Context context) {
+ synchronized (sInitializeLock) {
+ if (sInitialized == false) {
+ initLocked(context);
+ sInitialized = true;
+ }
+ }
+ }
+ private static void initLocked(final Context context) {
final Resources res = context.getResources();
sResources = res;
@@ -122,8 +130,6 @@ public final class SubtypeLocaleUtils {
final String keyboardLayoutSet = keyboardLayoutSetMap[i + 1];
sLocaleAndExtraValueToKeyboardLayoutSetMap.put(key, keyboardLayoutSet);
}
-
- sInitialized = true;
}
public static String[] getPredefinedKeyboardLayoutSet() {
@@ -167,8 +173,18 @@ public final class SubtypeLocaleUtils {
return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale);
}
+ public static String getSubtypeLanguageDisplayName(final String localeString) {
+ final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
+ final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(localeString);
+ return getSubtypeLocaleDisplayNameInternal(locale.getLanguage(), displayLocale);
+ }
+
private static String getSubtypeLocaleDisplayNameInternal(final String localeString,
final Locale displayLocale) {
+ if (NO_LANGUAGE.equals(localeString)) {
+ // No language subtype should be displayed in system locale.
+ return sResources.getString(R.string.subtype_no_language);
+ }
final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
final String displayName;
if (exceptionalNameResId != null) {
@@ -179,9 +195,6 @@ public final class SubtypeLocaleUtils {
}
};
displayName = getExceptionalName.runInLocale(sResources, displayLocale);
- } else if (NO_LANGUAGE.equals(localeString)) {
- // No language subtype should be displayed in system locale.
- return sResources.getString(R.string.subtype_no_language);
} else {
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
displayName = locale.getDisplayName(displayLocale);