aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java130
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java11
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java2
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java5
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java38
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java21
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettings.java41
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java20
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsFragment.java39
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java2
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java26
-rw-r--r--java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java3
12 files changed, 193 insertions, 145 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index 322127a12..15f79f3de 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -136,12 +136,19 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
return;
}
// Announce the language name only when the language is changed.
- if (lastKeyboard == null || !lastKeyboard.mId.mSubtype.equals(keyboard.mId.mSubtype)) {
+ if (lastKeyboard == null || !keyboard.mId.mSubtype.equals(lastKeyboard.mId.mSubtype)) {
announceKeyboardLanguage(keyboard);
+ return;
}
// Announce the mode only when the mode is changed.
- if (lastKeyboardMode != keyboard.mId.mMode) {
+ if (keyboard.mId.mMode != lastKeyboardMode) {
announceKeyboardMode(keyboard);
+ return;
+ }
+ // Announce the keyboard type only when the type is changed.
+ if (keyboard.mId.mElementId != lastKeyboard.mId.mElementId) {
+ announceKeyboardType(keyboard, lastKeyboard);
+ return;
}
}
@@ -174,9 +181,8 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
* @param keyboard The new keyboard.
*/
private void announceKeyboardMode(final Keyboard keyboard) {
- final int mode = keyboard.mId.mMode;
final Context context = mView.getContext();
- final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(mode);
+ final int modeTextResId = KEYBOARD_MODE_RES_IDS.get(keyboard.mId.mMode);
if (modeTextResId == 0) {
return;
}
@@ -186,6 +192,50 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
/**
+ * Announces which type of keyboard is being displayed.
+ *
+ * @param keyboard The new keyboard.
+ * @param lastKeyboard The last keyboard.
+ */
+ private void announceKeyboardType(final Keyboard keyboard, final Keyboard lastKeyboard) {
+ final int lastElementId = lastKeyboard.mId.mElementId;
+ final int resId;
+ switch (keyboard.mId.mElementId) {
+ case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED:
+ case KeyboardId.ELEMENT_ALPHABET:
+ if (lastElementId == KeyboardId.ELEMENT_ALPHABET
+ || lastElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED) {
+ return;
+ }
+ resId = R.string.spoken_description_mode_alpha;
+ break;
+ case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
+ resId = R.string.spoken_description_shiftmode_on;
+ break;
+ case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
+ case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
+ resId = R.string.spoken_description_shiftmode_locked;
+ break;
+ case KeyboardId.ELEMENT_SYMBOLS:
+ resId = R.string.spoken_description_mode_symbol;
+ break;
+ case KeyboardId.ELEMENT_SYMBOLS_SHIFTED:
+ resId = R.string.spoken_description_mode_symbol_shift;
+ break;
+ case KeyboardId.ELEMENT_PHONE:
+ resId = R.string.spoken_description_mode_phone;
+ break;
+ case KeyboardId.ELEMENT_PHONE_SYMBOLS:
+ resId = R.string.spoken_description_mode_phone_shift;
+ break;
+ default:
+ return;
+ }
+ final String text = mView.getContext().getString(resId);
+ sendWindowStateChanged(text);
+ }
+
+ /**
* Announces that the keyboard has been hidden.
*/
private void announceKeyboardHidden() {
@@ -301,7 +351,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
/**
- * Simulates a key press by injecting touch event into the keyboard view.
+ * Simulates a key press by injecting touch an event into the keyboard view.
* This avoids the complexity of trackers and listeners within the keyboard.
*
* @param key The key to press.
@@ -318,7 +368,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
/**
- * Simulates a key release by injecting touch event into the keyboard view.
+ * Simulates a key release by injecting touch an event into the keyboard view.
* This avoids the complexity of trackers and listeners within the keyboard.
*
* @param key The key to release.
@@ -383,72 +433,4 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
return true;
}
-
- /**
- * Notifies the user of changes in the keyboard shift state.
- */
- public void notifyShiftState() {
- if (mView == null || mKeyboard == null) {
- return;
- }
-
- final KeyboardId keyboardId = mKeyboard.mId;
- final int elementId = keyboardId.mElementId;
- final Context context = mView.getContext();
- final CharSequence text;
-
- switch (elementId) {
- case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
- case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
- text = context.getText(R.string.spoken_description_shiftmode_locked);
- break;
- case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED:
- case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
- case KeyboardId.ELEMENT_SYMBOLS_SHIFTED:
- text = context.getText(R.string.spoken_description_shiftmode_on);
- break;
- default:
- text = context.getText(R.string.spoken_description_shiftmode_off);
- }
- AccessibilityUtils.getInstance().announceForAccessibility(mView, text);
- }
-
- /**
- * Notifies the user of changes in the keyboard symbols state.
- */
- public void notifySymbolsState() {
- if (mView == null || mKeyboard == null) {
- return;
- }
-
- final KeyboardId keyboardId = mKeyboard.mId;
- final int elementId = keyboardId.mElementId;
- final Context context = mView.getContext();
- final int resId;
-
- switch (elementId) {
- case KeyboardId.ELEMENT_ALPHABET:
- case KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED:
- case KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED:
- case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED:
- case KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED:
- resId = R.string.spoken_description_mode_alpha;
- break;
- case KeyboardId.ELEMENT_SYMBOLS:
- case KeyboardId.ELEMENT_SYMBOLS_SHIFTED:
- resId = R.string.spoken_description_mode_symbol;
- break;
- case KeyboardId.ELEMENT_PHONE:
- resId = R.string.spoken_description_mode_phone;
- break;
- case KeyboardId.ELEMENT_PHONE_SYMBOLS:
- resId = R.string.spoken_description_mode_phone_shift;
- break;
- default:
- return;
- }
-
- final String text = context.getString(resId);
- AccessibilityUtils.getInstance().announceForAccessibility(mView, text);
- }
}
diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
index a80c3fefe..18b3a6060 100644
--- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
+++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java
@@ -28,6 +28,12 @@ public final class InputMethodManagerCompatWrapper {
private static final Method METHOD_switchToNextInputMethod = CompatUtils.getMethod(
InputMethodManager.class, "switchToNextInputMethod", IBinder.class, Boolean.TYPE);
+ // Note that InputMethodManager.shouldOfferSwitchingToNextInputMethod() has been introduced
+ // in API level 19 (Build.VERSION_CODES.KITKAT).
+ private static final Method METHOD_shouldOfferSwitchingToNextInputMethod =
+ CompatUtils.getMethod(InputMethodManager.class,
+ "shouldOfferSwitchingToNextInputMethod", IBinder.class);
+
public final InputMethodManager mImm;
public InputMethodManagerCompatWrapper(final Context context) {
@@ -38,4 +44,9 @@ public final class InputMethodManagerCompatWrapper {
return (Boolean)CompatUtils.invoke(mImm, false /* defaultValue */,
METHOD_switchToNextInputMethod, token, onlyCurrentIme);
}
+
+ public boolean shouldOfferSwitchingToNextInputMethod(final IBinder token) {
+ return (Boolean)CompatUtils.invoke(mImm, false /* defaultValue */,
+ METHOD_shouldOfferSwitchingToNextInputMethod, token);
+ }
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index dcf7f7472..0e667bc1c 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -123,7 +123,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setOptions(
mSubtypeSwitcher.isShortcutImeEnabled(),
settingsValues.mShowsVoiceInputKey,
- settingsValues.isLanguageSwitchKeyEnabled());
+ mLatinIME.shouldShowLanguageSwitchKey());
mKeyboardLayoutSet = builder.build();
mCurrentSettingsValues = settingsValues;
try {
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 08f3c63a3..550db4a6c 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -511,12 +511,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
*/
private final void asyncReloadDictionary() {
if (mIsReloading.compareAndSet(false, true)) {
- mNeedsToReload = false;
asyncExecuteTaskWithWriteLock(new Runnable() {
@Override
public void run() {
try {
- if (!mDictFile.exists() || haveContentsChanged()) {
+ // TODO: Quit checking contents in ExpandableBinaryDictionary.
+ if (!mDictFile.exists() || (mNeedsToReload && haveContentsChanged())) {
// If the dictionary file does not exist or contents have been updated,
// generate a new one.
createNewDictionaryLocked();
@@ -524,6 +524,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// Otherwise, load the existing dictionary.
loadBinaryDictionaryLocked();
}
+ mNeedsToReload = false;
if (mBinaryDictionary != null && !(isValidDictionaryLocked()
// TODO: remove the check below
&& matchesExpectedBinaryDictFormatVersionForThisType(
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 27790d6c6..e5dcb12ae 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1230,7 +1230,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO: Revise the language switch key behavior to make it much smarter and more reasonable.
public void switchToNextSubtype() {
final IBinder token = getWindow().getWindow().getAttributes().token;
- if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) {
+ if (shouldSwitchToOtherInputMethods()) {
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
return;
}
@@ -1597,18 +1597,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onReleaseKey(final int primaryCode, final boolean withSliding) {
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding, getCurrentAutoCapsState(),
getCurrentRecapitalizeState());
-
- // If accessibility is on, ensure the user receives keyboard state updates.
- if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
- switch (primaryCode) {
- case Constants.CODE_SHIFT:
- AccessibleKeyboardViewProxy.getInstance().notifyShiftState();
- break;
- case Constants.CODE_SWITCH_ALPHA_SYMBOL:
- AccessibleKeyboardViewProxy.getInstance().notifySymbolsState();
- break;
- }
- }
}
private HardwareEventDecoder getHardwareKeyEventDecoder(final int deviceId) {
@@ -1800,4 +1788,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
p.println(settingsValues.dump());
// TODO: Dump all settings values
}
+
+ public boolean shouldSwitchToOtherInputMethods() {
+ // TODO: Revisit here to reorganize the settings. Probably we can/should use different
+ // strategy once the implementation of
+ // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
+ final boolean fallbackValue = mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList;
+ final IBinder token = getWindow().getWindow().getAttributes().token;
+ if (token == null) {
+ return fallbackValue;
+ }
+ return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
+ }
+
+ public boolean shouldShowLanguageSwitchKey() {
+ // TODO: Revisit here to reorganize the settings. Probably we can/should use different
+ // strategy once the implementation of
+ // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is defined well.
+ final boolean fallbackValue = mSettings.getCurrent().isLanguageSwitchKeyEnabled();
+ final IBinder token = getWindow().getWindow().getAttributes().token;
+ if (token == null) {
+ return fallbackValue;
+ }
+ return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index 630a03670..64cc562c8 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -20,6 +20,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
import android.content.Context;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -406,4 +407,24 @@ public final class RichInputMethodManager {
mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear();
mInputMethodInfoCache.clear();
}
+
+ public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder,
+ boolean defaultValue) {
+ // Use the default value instead on Jelly Bean MR2 and previous, where
+ // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available.
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ return defaultValue;
+ }
+ // Use the default value instead on KitKat as well, where
+ // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is still just a stub to
+ // return true always.
+ if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
+ // Make sure this is actually KitKat.
+ // TODO: Consider to remove this check once the *next* version becomes available.
+ if (Build.VERSION.CODENAME.equals("REL")) {
+ return defaultValue;
+ }
+ }
+ return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index 11d369282..c4c1234fc 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -55,6 +55,8 @@ public final class DebugSettings extends PreferenceFragment
private static final String PREF_DUMP_USER_DICT = "dump_user_dict";
private static final String PREF_DUMP_USER_HISTORY_DICT = "dump_user_history_dict";
private static final String PREF_DUMP_PERSONALIZATION_DICT = "dump_personalization_dict";
+ public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview";
+ public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
private static final boolean SHOW_STATISTICS_LOGGING = false;
@@ -110,6 +112,7 @@ public final class DebugSettings extends PreferenceFragment
findPreference(PREF_DUMP_PERSONALIZATION_DICT).setOnPreferenceClickListener(
dictDumpPrefClickListener);
final Resources res = getResources();
+ setupKeyLongpressTimeoutSettings(prefs, res);
setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_SHOW_UP_DURATION,
res.getInteger(R.integer.config_key_preview_show_up_duration));
setupKeyPreviewAnimationDuration(prefs, res, PREF_KEY_PREVIEW_DISMISS_DURATION,
@@ -200,6 +203,44 @@ public final class DebugSettings extends PreferenceFragment
}
}
+ private void setupKeyLongpressTimeoutSettings(final SharedPreferences sp,
+ final Resources res) {
+ final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
+ PREF_KEY_LONGPRESS_TIMEOUT);
+ if (pref == null) {
+ return;
+ }
+ pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
+ @Override
+ public void writeValue(final int value, final String key) {
+ sp.edit().putInt(key, value).apply();
+ }
+
+ @Override
+ public void writeDefaultValue(final String key) {
+ sp.edit().remove(key).apply();
+ }
+
+ @Override
+ public int readValue(final String key) {
+ return Settings.readKeyLongpressTimeout(sp, res);
+ }
+
+ @Override
+ public int readDefaultValue(final String key) {
+ return Settings.readDefaultKeyLongpressTimeout(res);
+ }
+
+ @Override
+ public String getValueText(final int value) {
+ return res.getString(R.string.abbreviation_unit_milliseconds, value);
+ }
+
+ @Override
+ public void feedbackValue(final int value) {}
+ });
+ }
+
private void setupKeyPreviewAnimationScale(final SharedPreferences sp, final Resources res,
final String prefKey, final float defaultValue) {
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 353b7463d..a3aae8cb3 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -72,8 +72,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction";
public static final String PREF_GESTURE_SETTINGS = "gesture_typing_settings";
public static final String PREF_GESTURE_INPUT = "gesture_input";
- public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview";
- public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout";
public static final String PREF_VIBRATION_DURATION_SETTINGS =
"pref_vibration_duration_settings";
public static final String PREF_KEYPRESS_SOUND_VOLUME =
@@ -196,7 +194,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// Accessed from the settings interface, hence public
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
final Resources res) {
- return prefs.getBoolean(Settings.PREF_SOUND_ON,
+ return prefs.getBoolean(PREF_SOUND_ON,
res.getBoolean(R.bool.config_default_sound_enabled));
}
@@ -216,7 +214,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static boolean readBlockPotentiallyOffensive(final SharedPreferences prefs,
final Resources res) {
- return prefs.getBoolean(Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,
+ return prefs.getBoolean(PREF_BLOCK_POTENTIALLY_OFFENSIVE,
res.getBoolean(R.bool.config_block_potentially_offensive));
}
@@ -227,12 +225,12 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static boolean readGestureInputEnabled(final SharedPreferences prefs,
final Resources res) {
return readFromBuildConfigIfGestureInputEnabled(res)
- && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true);
+ && prefs.getBoolean(PREF_GESTURE_INPUT, true);
}
public static boolean readPhraseGestureEnabled(final SharedPreferences prefs,
final Resources res) {
- return prefs.getBoolean(Settings.PREF_PHRASE_GESTURE_ENABLED,
+ return prefs.getBoolean(PREF_PHRASE_GESTURE_ENABLED,
res.getBoolean(R.bool.config_default_phrase_gesture_enabled));
}
@@ -278,7 +276,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static void writePrefAdditionalSubtypes(final SharedPreferences prefs,
final String prefSubtypes) {
- prefs.edit().putString(Settings.PREF_CUSTOM_INPUT_STYLES, prefSubtypes).apply();
+ prefs.edit().putString(PREF_CUSTOM_INPUT_STYLES, prefSubtypes).apply();
}
public static float readKeypressSoundVolume(final SharedPreferences prefs,
@@ -301,7 +299,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
public static int readKeyLongpressTimeout(final SharedPreferences prefs,
final Resources res) {
final int milliseconds = prefs.getInt(
- PREF_KEY_LONGPRESS_TIMEOUT, UNDEFINED_PREFERENCE_VALUE_INT);
+ DebugSettings.PREF_KEY_LONGPRESS_TIMEOUT, UNDEFINED_PREFERENCE_VALUE_INT);
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds
: readDefaultKeyLongpressTimeout(res);
}
@@ -354,18 +352,18 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
if (!enableSetupWizardByConfig) {
return false;
}
- if (!prefs.contains(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
+ if (!prefs.contains(PREF_SHOW_SETUP_WIZARD_ICON)) {
final ApplicationInfo appInfo = context.getApplicationInfo();
final boolean isApplicationInSystemImage =
(appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
// Default value
return !isApplicationInSystemImage;
}
- return prefs.getBoolean(Settings.PREF_SHOW_SETUP_WIZARD_ICON, false);
+ return prefs.getBoolean(PREF_SHOW_SETUP_WIZARD_ICON, false);
}
public static boolean isInternal(final SharedPreferences prefs) {
- return prefs.getBoolean(Settings.PREF_KEY_IS_INTERNAL, false);
+ return prefs.getBoolean(PREF_KEY_IS_INTERNAL, false);
}
public void writeLastUsedPersonalizationToken(byte[] token) {
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
index bb5547fc9..22cbd204c 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java
@@ -228,7 +228,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
AdditionalFeaturesSettingUtils.addAdditionalFeaturesPreferences(context, this);
- setupKeyLongpressTimeoutSettings(prefs, res);
setupKeypressVibrationDurationSettings(prefs, res);
setupKeypressSoundVolumeSettings(prefs, res);
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, res);
@@ -368,44 +367,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment
});
}
- private void setupKeyLongpressTimeoutSettings(final SharedPreferences sp,
- final Resources res) {
- final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
- Settings.PREF_KEY_LONGPRESS_TIMEOUT);
- if (pref == null) {
- return;
- }
- pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
- @Override
- public void writeValue(final int value, final String key) {
- sp.edit().putInt(key, value).apply();
- }
-
- @Override
- public void writeDefaultValue(final String key) {
- sp.edit().remove(key).apply();
- }
-
- @Override
- public int readValue(final String key) {
- return Settings.readKeyLongpressTimeout(sp, res);
- }
-
- @Override
- public int readDefaultValue(final String key) {
- return Settings.readDefaultKeyLongpressTimeout(res);
- }
-
- @Override
- public String getValueText(final int value) {
- return res.getString(R.string.abbreviation_unit_milliseconds, value);
- }
-
- @Override
- public void feedbackValue(final int value) {}
- });
- }
-
private void setupKeypressSoundVolumeSettings(final SharedPreferences sp, final Resources res) {
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(
Settings.PREF_KEYPRESS_SOUND_VOLUME);
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index d47a61ed1..dde50ccaf 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -119,7 +119,7 @@ public final class SettingsValues {
mSoundOn = Settings.readKeypressSoundEnabled(prefs, res);
mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res);
mSlidingKeyInputPreviewEnabled = prefs.getBoolean(
- Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
+ DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, true);
mShowsVoiceInputKey = needsToShowVoiceInputKey(prefs, res);
final String autoCorrectionThresholdRawValue = prefs.getString(
Settings.PREF_AUTO_CORRECTION_THRESHOLD,
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
index a104baa08..5a325ea82 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java
@@ -74,7 +74,13 @@ public final class MoreSuggestions extends Keyboard {
int rowStartIndex = fromIndex;
final int size = Math.min(suggestedWords.size(), SuggestedWords.MAX_SUGGESTIONS);
while (index < size) {
- final String word = suggestedWords.getLabel(index);
+ final String word;
+ if (isIndexSubjectToAutoCorrection(suggestedWords, index)) {
+ // INDEX_OF_AUTO_CORRECTION and INDEX_OF_TYPED_WORD got swapped.
+ word = suggestedWords.getLabel(SuggestedWords.INDEX_OF_TYPED_WORD);
+ } else {
+ word = suggestedWords.getLabel(index);
+ }
// TODO: Should take care of text x-scaling.
mWidths[index] = (int)(TypefaceUtils.getStringWidth(word, paint) + padding);
final int numColumn = index - rowStartIndex + 1;
@@ -172,6 +178,11 @@ public final class MoreSuggestions extends Keyboard {
}
}
+ private static boolean isIndexSubjectToAutoCorrection(final SuggestedWords suggestedWords,
+ final int index) {
+ return suggestedWords.mWillAutoCorrect && index == SuggestedWords.INDEX_OF_AUTO_CORRECTION;
+ }
+
public static final class Builder extends KeyboardBuilder<MoreSuggestionsParam> {
private final MoreSuggestionsView mPaneView;
private SuggestedWords mSuggestedWords;
@@ -189,7 +200,6 @@ public final class MoreSuggestions extends Keyboard {
final int xmlId = R.xml.kbd_suggestions_pane_template;
load(xmlId, parentKeyboard.mId);
mParams.mVerticalGap = mParams.mTopPadding = parentKeyboard.mVerticalGap / 2;
-
mPaneView.updateKeyboardGeometry(mParams.mDefaultRowHeight);
final int count = mParams.layout(suggestedWords, fromIndex, maxWidth, minWidth, maxRow,
mPaneView.newLabelPaint(null /* key */), mResources);
@@ -206,8 +216,16 @@ public final class MoreSuggestions extends Keyboard {
final int x = params.getX(index);
final int y = params.getY(index);
final int width = params.getWidth(index);
- final String word = mSuggestedWords.getLabel(index);
- final String info = mSuggestedWords.getDebugString(index);
+ final String word;
+ final String info;
+ if (isIndexSubjectToAutoCorrection(mSuggestedWords, index)) {
+ // INDEX_OF_AUTO_CORRECTION and INDEX_OF_TYPED_WORD got swapped.
+ word = mSuggestedWords.getLabel(SuggestedWords.INDEX_OF_TYPED_WORD);
+ info = mSuggestedWords.getDebugString(SuggestedWords.INDEX_OF_TYPED_WORD);
+ } else {
+ word = mSuggestedWords.getLabel(index);
+ info = mSuggestedWords.getDebugString(index);
+ }
final int indexInMoreSuggestions = index + SUGGESTION_CODE_BASE;
final Key key = new Key(word, KeyboardIconsSet.ICON_UNDEFINED,
indexInMoreSuggestions, null /* outputText */, info, 0 /* labelFlags */,
diff --git a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java
index a23b3ac79..bf38abc95 100644
--- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java
+++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java
@@ -16,6 +16,8 @@
package com.android.inputmethod.latin.utils;
+import com.android.inputmethod.annotations.UsedForTesting;
+
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -74,6 +76,7 @@ public class PrioritizedSerialExecutor {
* Enqueues the given task into the prioritized task queue.
* @param r the enqueued task
*/
+ @UsedForTesting
public void executePrioritized(final Runnable r) {
synchronized(mLock) {
if (!mIsShutdown) {