aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-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/ContactsBinaryDictionary.java13
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java128
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java26
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java12
-rw-r--r--java/src/com/android/inputmethod/latin/UserBinaryDictionary.java11
-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/spellcheck/AndroidSpellCheckerService.java2
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/SynchronouslyLoadedContactsBinaryDictionary.java (renamed from java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java)7
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/SynchronouslyLoadedUserBinaryDictionary.java (renamed from java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java)7
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java26
-rw-r--r--java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java33
16 files changed, 167 insertions, 213 deletions
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..0235fde38 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.shouldSwitchToOtherInputMethods());
mKeyboardLayoutSet = builder.build();
mCurrentSettingsValues = settingsValues;
try {
diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
index d5873d70f..88122792e 100644
--- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
@@ -77,15 +77,20 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
public ContactsBinaryDictionary(final Context context, final Locale locale,
final File dictFile) {
- super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_CONTACTS,
+ this(context, locale, dictFile, NAME);
+ }
+
+ protected ContactsBinaryDictionary(final Context context, final Locale locale,
+ final File dictFile, final String name) {
+ super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_CONTACTS,
dictFile);
mLocale = locale;
mUseFirstLastBigrams = useFirstLastBigramsForLocale(locale);
registerObserver(context);
// Load the current binary dictionary from internal storage. If no binary dictionary exists,
- // loadDictionary will start a new thread to generate one asynchronously.
- loadDictionary();
+ // reloadDictionaryIfRequired will start a new thread to generate one asynchronously.
+ reloadDictionaryIfRequired();
}
private synchronized void registerObserver(final Context context) {
@@ -95,7 +100,7 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
new ContentObserver(null) {
@Override
public void onChange(boolean self) {
- setRequiresReload(true);
+ setNeedsToReload();
}
});
}
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index 837fe4f1a..3eafcb245 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -27,7 +27,6 @@ import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.makedict.WordProperty;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.utils.AsyncResultHolder;
-import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CombinedFormatUtils;
import com.android.inputmethod.latin.utils.ExecutorUtils;
import com.android.inputmethod.latin.utils.FileUtils;
@@ -38,11 +37,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
/**
* Abstract base class for an expandable dictionary that can be created and updated dynamically
@@ -74,15 +71,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
private static final int DICTIONARY_FORMAT_VERSION = FormatSpec.VERSION4;
- /**
- * A static map of update controllers, each of which records the time of accesses to a single
- * binary dictionary file and tracks whether the file is regenerating. The key for this map is
- * the dictionary name and the value is the shared dictionary time recorder associated with
- * that dictionary name.
- */
- private static final ConcurrentHashMap<String, DictionaryUpdateController>
- sDictNameDictionaryUpdateControllerMap = CollectionUtils.newConcurrentHashMap();
-
/** The application context. */
protected final Context mContext;
@@ -105,21 +93,13 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/** Dictionary file */
private final File mDictFile;
- // TODO: remove, once dynamic operations is serialized
- /** Controls updating the shared binary dictionary file across multiple instances. */
- private final DictionaryUpdateController mDictNameDictionaryUpdateController;
+ private final AtomicBoolean mProcessingLargeTask;
+ private boolean mNeedsToReload;
- // TODO: remove, once dynamic operations is serialized
- /** Controls updating the local binary dictionary for this instance. */
- private final DictionaryUpdateController mPerInstanceDictionaryUpdateController =
- new DictionaryUpdateController();
/* A extension for a binary dictionary file. */
protected static final String DICT_FILE_EXTENSION = ".dict";
- private final AtomicReference<Runnable> mUnfinishedFlushingTask =
- new AtomicReference<Runnable>();
-
/**
* Abstract method for loading initial contents of a given dictionary.
*/
@@ -146,21 +126,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
/**
- * Gets the dictionary update controller for the given dictionary name.
- */
- private static DictionaryUpdateController getDictionaryUpdateController(
- final String dictName) {
- DictionaryUpdateController recorder = sDictNameDictionaryUpdateControllerMap.get(dictName);
- if (recorder == null) {
- synchronized(sDictNameDictionaryUpdateControllerMap) {
- recorder = new DictionaryUpdateController();
- sDictNameDictionaryUpdateControllerMap.put(dictName, recorder);
- }
- }
- return recorder;
- }
-
- /**
* Creates a new expandable binary dictionary.
*
* @param context The application context of the parent.
@@ -179,7 +144,8 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
mLocale = locale;
mDictFile = getDictFile(context, dictName, dictFile);
mBinaryDictionary = null;
- mDictNameDictionaryUpdateController = getDictionaryUpdateController(dictName);
+ mProcessingLargeTask = new AtomicBoolean();
+ mNeedsToReload = false;
}
public static File getDictFile(final Context context, final String dictName,
@@ -286,7 +252,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
try {
mBinaryDictionary.flushWithGC();
} finally {
- mDictNameDictionaryUpdateController.mProcessingLargeTask.set(false);
+ mProcessingLargeTask.set(false);
}
}
});
@@ -388,7 +354,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
callback.onFinished();
}
if (locked) {
- mDictNameDictionaryUpdateController.mProcessingLargeTask.set(false);
+ mProcessingLargeTask.set(false);
}
}
}
@@ -462,24 +428,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
/**
- * Load the current binary dictionary from internal storage in a background thread. If no binary
- * dictionary exists, this method will generate one.
- */
- protected void loadDictionary() {
- mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = System.currentTimeMillis();
- reloadDictionaryIfRequired();
- }
-
- /**
* Loads the current binary dictionary from internal storage. Assumes the dictionary file
* exists.
*/
private void loadBinaryDictionaryLocked() {
- if (DEBUG) {
- Log.d(TAG, "Loading binary dictionary: " + mDictName + " request="
- + mDictNameDictionaryUpdateController.mLastUpdateRequestTime + " update="
- + mDictNameDictionaryUpdateController.mLastUpdateTime);
- }
if (DBG_STRESS_TEST) {
// Test if this class does not cause problems when it takes long time to load binary
// dictionary.
@@ -505,11 +457,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* Create a new binary dictionary and load initial contents.
*/
private void createNewDictionaryLocked() {
- if (DEBUG) {
- Log.d(TAG, "Generating binary dictionary: " + mDictName + " request="
- + mDictNameDictionaryUpdateController.mLastUpdateRequestTime + " update="
- + mDictNameDictionaryUpdateController.mLastUpdateTime);
- }
removeBinaryDictionaryLocked();
createOnMemoryBinaryDictionaryLocked();
loadInitialContentsLocked();
@@ -529,20 +476,11 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
}
/**
- * Marks that the dictionary is out of date and requires a reload.
+ * Marks that the dictionary needs to be reloaded.
*
- * @param requiresRebuild Indicates that the source dictionary content has changed and a rebuild
- * of the binary file is required. If not true, the next reload process will only read
- * the current binary dictionary from file.
*/
- protected void setRequiresReload(final boolean requiresRebuild) {
- final long time = System.currentTimeMillis();
- mPerInstanceDictionaryUpdateController.mLastUpdateRequestTime = time;
- mDictNameDictionaryUpdateController.mLastUpdateRequestTime = time;
- if (DEBUG) {
- Log.d(TAG, "Reload request: " + mDictName + ": request=" + time + " update="
- + mDictNameDictionaryUpdateController.mLastUpdateTime);
- }
+ protected void setNeedsToReload() {
+ mNeedsToReload = true;
}
/**
@@ -559,18 +497,17 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* Returns whether a dictionary reload is required.
*/
private boolean isReloadRequired() {
- return mBinaryDictionary == null || mPerInstanceDictionaryUpdateController.isOutOfDate();
+ return mBinaryDictionary == null || mNeedsToReload;
}
private boolean processingLargeTask() {
- return mDictNameDictionaryUpdateController.mProcessingLargeTask.get();
+ return mProcessingLargeTask.get();
}
// Returns whether the dictionary is being used for a large task. If true, we should not use
// this dictionary for latency sensitive operations.
private boolean setProcessingLargeTaskIfNot() {
- return mDictNameDictionaryUpdateController.mProcessingLargeTask.compareAndSet(
- false /* expect */ , true /* update */);
+ return mProcessingLargeTask.compareAndSet(false /* expect */ , true /* update */);
}
/**
@@ -584,28 +521,17 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
@Override
public void run() {
try {
- final long time = System.currentTimeMillis();
- final boolean openedDictIsOutOfDate =
- mDictNameDictionaryUpdateController.isOutOfDate();
- if (!dictionaryFileExists()
- || (openedDictIsOutOfDate && haveContentsChanged())) {
+ if (!dictionaryFileExists() || haveContentsChanged()) {
// If the shared dictionary file does not exist or is out of date and
// contents have been updated, the first instance that acquires the lock
// will generate a new one
- mDictNameDictionaryUpdateController.mLastUpdateTime = time;
createNewDictionaryLocked();
- } else if (openedDictIsOutOfDate) {
- // If not, the reload request was unnecessary so revert
- // LastUpdateRequestTime to LastUpdateTime.
- mDictNameDictionaryUpdateController.mLastUpdateRequestTime =
- mDictNameDictionaryUpdateController.mLastUpdateTime;
- } else if (mBinaryDictionary == null ||
- mPerInstanceDictionaryUpdateController.mLastUpdateTime
- < mDictNameDictionaryUpdateController.mLastUpdateTime) {
+ } else if (mBinaryDictionary == null) {
// Otherwise, if the local dictionary is older than the shared dictionary,
// load the shared dictionary.
loadBinaryDictionaryLocked();
}
+ mNeedsToReload = false;
if (mBinaryDictionary != null && !(isValidDictionaryLocked()
// TODO: remove the check below
&& matchesExpectedBinaryDictFormatVersionForThisType(
@@ -613,12 +539,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
// Binary dictionary or its format version is not valid. Regenerate
// the dictionary file. writeBinaryDictionary will remove the
// existing files if appropriate.
- mDictNameDictionaryUpdateController.mLastUpdateTime = time;
createNewDictionaryLocked();
}
- mPerInstanceDictionaryUpdateController.mLastUpdateTime = time;
} finally {
- mDictNameDictionaryUpdateController.mProcessingLargeTask.set(false);
+ mProcessingLargeTask.set(false);
}
}
});
@@ -633,28 +557,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* Flush binary dictionary to dictionary file.
*/
public void asyncFlushBinaryDictionary() {
- final Runnable newTask = new Runnable() {
+ ExecutorUtils.getExecutor(mDictName).execute(new Runnable() {
@Override
public void run() {
flushDictionaryLocked();
}
- };
- final Runnable oldTask = mUnfinishedFlushingTask.getAndSet(newTask);
- ExecutorUtils.getExecutor(mDictName).replaceAndExecute(oldTask, newTask);
- }
-
- /**
- * For tracking whether the dictionary is out of date and the dictionary is used in a large
- * task. Can be shared across multiple dictionary instances that access the same filename.
- */
- private static class DictionaryUpdateController {
- public volatile long mLastUpdateTime = 0;
- public volatile long mLastUpdateRequestTime = 0;
- public volatile AtomicBoolean mProcessingLargeTask = new AtomicBoolean();
-
- public boolean isOutOfDate() {
- return (mLastUpdateRequestTime > mLastUpdateTime);
- }
+ });
}
// TODO: Implement BinaryDictionary.isInDictionary().
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index a77cedc48..f1b1b8db2 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1229,7 +1229,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;
}
@@ -1799,4 +1799,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..2b0be545e 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,15 @@ 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
+ // and on KitKat where the API is still just a stub to return true always.
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
+ return defaultValue;
+ }
+ return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
index 8838e27c4..9d9ce0138 100644
--- a/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserBinaryDictionary.java
@@ -86,7 +86,12 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
public UserBinaryDictionary(final Context context, final Locale locale,
final boolean alsoUseMoreRestrictiveLocales, final File dictFile) {
- super(context, getDictName(NAME, locale, dictFile), locale, Dictionary.TYPE_USER, dictFile);
+ this(context, locale, alsoUseMoreRestrictiveLocales, dictFile, NAME);
+ }
+
+ protected UserBinaryDictionary(final Context context, final Locale locale,
+ final boolean alsoUseMoreRestrictiveLocales, final File dictFile, final String name) {
+ super(context, getDictName(name, locale, dictFile), locale, Dictionary.TYPE_USER, dictFile);
if (null == locale) throw new NullPointerException(); // Catch the error earlier
final String localeStr = locale.toString();
if (SubtypeLocaleUtils.NO_LANGUAGE.equals(localeStr)) {
@@ -111,12 +116,12 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
// devices. On older versions of the platform, the hook above will be called instead.
@Override
public void onChange(final boolean self, final Uri uri) {
- setRequiresReload(true);
+ setNeedsToReload();
}
};
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
mEnabled = readIsEnabled();
- loadDictionary();
+ reloadDictionaryIfRequired();
}
@Override
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/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 6a52481b9..65ebcf5f1 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -33,8 +33,6 @@ import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryCollection;
import com.android.inputmethod.latin.DictionaryFactory;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.SynchronouslyLoadedContactsBinaryDictionary;
-import com.android.inputmethod.latin.SynchronouslyLoadedUserBinaryDictionary;
import com.android.inputmethod.latin.UserBinaryDictionary;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/spellcheck/SynchronouslyLoadedContactsBinaryDictionary.java
index c24ee4033..a694bf47d 100644
--- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/SynchronouslyLoadedContactsBinaryDictionary.java
@@ -14,21 +14,24 @@
* limitations under the License.
*/
-package com.android.inputmethod.latin;
+package com.android.inputmethod.latin.spellcheck;
import android.content.Context;
import com.android.inputmethod.keyboard.ProximityInfo;
+import com.android.inputmethod.latin.ContactsBinaryDictionary;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
+import com.android.inputmethod.latin.WordComposer;
import java.util.ArrayList;
import java.util.Locale;
public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryDictionary {
+ private static final String NAME = "spellcheck_contacts";
private final Object mLock = new Object();
public SynchronouslyLoadedContactsBinaryDictionary(final Context context, final Locale locale) {
- super(context, locale);
+ super(context, locale, null /* dictFile */, NAME);
}
@Override
diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/spellcheck/SynchronouslyLoadedUserBinaryDictionary.java
index 1d29d7ad0..1a6dd5818 100644
--- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/SynchronouslyLoadedUserBinaryDictionary.java
@@ -14,17 +14,20 @@
* limitations under the License.
*/
-package com.android.inputmethod.latin;
+package com.android.inputmethod.latin.spellcheck;
import android.content.Context;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
+import com.android.inputmethod.latin.UserBinaryDictionary;
+import com.android.inputmethod.latin.WordComposer;
import java.util.ArrayList;
import java.util.Locale;
public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDictionary {
+ private static final String NAME = "spellcheck_user";
private final Object mLock = new Object();
public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale) {
@@ -33,7 +36,7 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic
public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale,
final boolean alsoUseMoreRestrictiveLocales) {
- super(context, locale, alsoUseMoreRestrictiveLocales, null /* dictFile */);
+ super(context, locale, alsoUseMoreRestrictiveLocales, null /* dictFile */, NAME);
}
@Override
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 b10d08af3..a23b3ac79 100644
--- a/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java
+++ b/java/src/com/android/inputmethod/latin/utils/PrioritizedSerialExecutor.java
@@ -47,16 +47,6 @@ public class PrioritizedSerialExecutor {
}
/**
- * Clears all queued tasks.
- */
- public void clearAllTasks() {
- synchronized(mLock) {
- mTasks.clear();
- mPrioritizedTasks.clear();
- }
- }
-
- /**
* Enqueues the given task into the task queue.
* @param r the enqueued task
*/
@@ -120,33 +110,10 @@ public class PrioritizedSerialExecutor {
}
}
- public void remove(final Runnable r) {
- synchronized(mLock) {
- mTasks.remove(r);
- mPrioritizedTasks.remove(r);
- }
- }
-
- public void replaceAndExecute(final Runnable oldTask, final Runnable newTask) {
- synchronized(mLock) {
- if (oldTask != null) remove(oldTask);
- execute(newTask);
- }
- }
-
public void shutdown() {
synchronized(mLock) {
mIsShutdown = true;
mThreadPoolExecutor.shutdown();
}
}
-
- public boolean isTerminated() {
- synchronized(mLock) {
- if (!mIsShutdown) {
- return false;
- }
- return mPrioritizedTasks.isEmpty() && mTasks.isEmpty() && mActive == null;
- }
- }
}