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/BinaryDictionaryGetter.java14
-rw-r--r--java/src/com/android/inputmethod/latin/DictionaryFactory.java78
-rw-r--r--java/src/com/android/inputmethod/latin/InputAttributes.java8
-rw-r--r--java/src/com/android/inputmethod/latin/InputTypeUtils.java90
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java106
-rw-r--r--java/src/com/android/inputmethod/latin/LocaleUtils.java43
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java42
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java21
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java86
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeUtils.java37
-rw-r--r--java/src/com/android/inputmethod/latin/WhitelistDictionary.java14
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java19
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java16
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java4
14 files changed, 337 insertions, 241 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index 1c24cd11d..e4d839690 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -23,6 +23,8 @@ import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.util.Log;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
+
import java.io.File;
import java.util.ArrayList;
import java.util.Locale;
@@ -154,11 +156,13 @@ class BinaryDictionaryGetter {
*/
private static AssetFileAddress loadFallbackResource(final Context context,
final int fallbackResId, final Locale locale) {
- final Resources res = context.getResources();
- final Locale savedLocale = LocaleUtils.setSystemLocale(res, locale);
- final AssetFileDescriptor afd = res.openRawResourceFd(fallbackResId);
- LocaleUtils.setSystemLocale(res, savedLocale);
-
+ final RunInLocale<AssetFileDescriptor> job = new RunInLocale<AssetFileDescriptor>() {
+ @Override
+ protected AssetFileDescriptor job(Resources res) {
+ return res.openRawResourceFd(fallbackResId);
+ }
+ };
+ final AssetFileDescriptor afd = job.runInLocale(context.getResources(), locale);
if (afd == null) {
Log.e(TAG, "Found the resource but cannot read it. Is it compressed? resId="
+ fallbackResId);
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java
index 77c685c50..7be374db5 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java
@@ -21,6 +21,8 @@ import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.util.Log;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
+
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -30,7 +32,6 @@ import java.util.Locale;
* Factory for dictionary instances.
*/
public class DictionaryFactory {
-
private static String TAG = DictionaryFactory.class.getSimpleName();
/**
@@ -98,14 +99,13 @@ public class DictionaryFactory {
final int resId, final Locale locale) {
AssetFileDescriptor afd = null;
try {
- final Resources res = context.getResources();
- if (null != locale) {
- final Locale savedLocale = LocaleUtils.setSystemLocale(res, locale);
- afd = res.openRawResourceFd(resId);
- LocaleUtils.setSystemLocale(res, savedLocale);
- } else {
- afd = res.openRawResourceFd(resId);
- }
+ final RunInLocale<AssetFileDescriptor> job = new RunInLocale<AssetFileDescriptor>() {
+ @Override
+ protected AssetFileDescriptor job(Resources res) {
+ return res.openRawResourceFd(resId);
+ }
+ };
+ afd = job.runInLocale(context.getResources(), locale);
if (afd == null) {
Log.e(TAG, "Found the resource but it is compressed. resId=" + resId);
return null;
@@ -161,39 +161,41 @@ public class DictionaryFactory {
* @return whether a (non-placeholder) dictionary is available or not.
*/
public static boolean isDictionaryAvailable(Context context, Locale locale) {
- final Resources res = context.getResources();
- final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale);
-
- final int resourceId = getMainDictionaryResourceId(res);
- final AssetFileDescriptor afd = res.openRawResourceFd(resourceId);
- final boolean hasDictionary = isFullDictionary(afd);
- try {
- if (null != afd) afd.close();
- } catch (java.io.IOException e) {
- /* Um, what can we do here exactly? */
- }
-
- LocaleUtils.setSystemLocale(res, saveLocale);
- return hasDictionary;
+ final RunInLocale<Boolean> job = new RunInLocale<Boolean>() {
+ @Override
+ protected Boolean job(Resources res) {
+ final int resourceId = getMainDictionaryResourceId(res);
+ final AssetFileDescriptor afd = res.openRawResourceFd(resourceId);
+ final boolean hasDictionary = isFullDictionary(afd);
+ try {
+ if (null != afd) afd.close();
+ } catch (java.io.IOException e) {
+ /* Um, what can we do here exactly? */
+ }
+ return hasDictionary;
+ }
+ };
+ return job.runInLocale(context.getResources(), locale);
}
// TODO: Do not use the size of the dictionary as an unique dictionary ID.
public static Long getDictionaryId(final Context context, final Locale locale) {
- final Resources res = context.getResources();
- final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale);
-
- final int resourceId = getMainDictionaryResourceId(res);
- final AssetFileDescriptor afd = res.openRawResourceFd(resourceId);
- final Long size = (afd != null && afd.getLength() > PLACEHOLDER_LENGTH)
- ? afd.getLength()
- : null;
- try {
- if (null != afd) afd.close();
- } catch (java.io.IOException e) {
- }
-
- LocaleUtils.setSystemLocale(res, saveLocale);
- return size;
+ final RunInLocale<Long> job = new RunInLocale<Long>() {
+ @Override
+ protected Long job(Resources res) {
+ final int resourceId = getMainDictionaryResourceId(res);
+ final AssetFileDescriptor afd = res.openRawResourceFd(resourceId);
+ final Long size = (afd != null && afd.getLength() > PLACEHOLDER_LENGTH)
+ ? afd.getLength()
+ : null;
+ try {
+ if (null != afd) afd.close();
+ } catch (java.io.IOException e) {
+ }
+ return size;
+ }
+ };
+ return job.runInLocale(context.getResources(), locale);
}
// TODO: Find the Right Way to find out whether the resource is a placeholder or not.
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index 06c70c42c..a6ce04069 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -20,8 +20,6 @@ import android.text.InputType;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
-import com.android.inputmethod.compat.InputTypeCompatUtils;
-
/**
* Class to hold attributes of the input field.
*/
@@ -66,9 +64,9 @@ public class InputAttributes {
0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
// Make sure that passwords are not displayed in {@link SuggestionsView}.
- if (InputTypeCompatUtils.isPasswordInputType(inputType)
- || InputTypeCompatUtils.isVisiblePasswordInputType(inputType)
- || InputTypeCompatUtils.isEmailVariation(variation)
+ if (InputTypeUtils.isPasswordInputType(inputType)
+ || InputTypeUtils.isVisiblePasswordInputType(inputType)
+ || InputTypeUtils.isEmailVariation(variation)
|| InputType.TYPE_TEXT_VARIATION_URI == variation
|| InputType.TYPE_TEXT_VARIATION_FILTER == variation
|| flagNoSuggestions
diff --git a/java/src/com/android/inputmethod/latin/InputTypeUtils.java b/java/src/com/android/inputmethod/latin/InputTypeUtils.java
new file mode 100644
index 000000000..40c3b765e
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/InputTypeUtils.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin;
+
+import android.text.InputType;
+
+public class InputTypeUtils implements InputType {
+ private static final int WEB_TEXT_PASSWORD_INPUT_TYPE =
+ TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD;
+ private static final int WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE =
+ TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
+ private static final int NUMBER_PASSWORD_INPUT_TYPE =
+ TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD;
+ private static final int TEXT_PASSWORD_INPUT_TYPE =
+ TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD;
+ private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
+ TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+
+ private InputTypeUtils() {
+ // This utility class is not publicly instantiable.
+ }
+
+ private static boolean isWebEditTextInputType(int inputType) {
+ return inputType == (TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
+ }
+
+ private static boolean isWebPasswordInputType(int inputType) {
+ return WEB_TEXT_PASSWORD_INPUT_TYPE != 0
+ && inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
+ }
+
+ private static boolean isWebEmailAddressInputType(int inputType) {
+ return WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE != 0
+ && inputType == WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
+ }
+
+ private static boolean isNumberPasswordInputType(int inputType) {
+ return NUMBER_PASSWORD_INPUT_TYPE != 0
+ && inputType == NUMBER_PASSWORD_INPUT_TYPE;
+ }
+
+ private static boolean isTextPasswordInputType(int inputType) {
+ return inputType == TEXT_PASSWORD_INPUT_TYPE;
+ }
+
+ private static boolean isWebEmailAddressVariation(int variation) {
+ return variation == TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
+ }
+
+ public static boolean isEmailVariation(int variation) {
+ return variation == TYPE_TEXT_VARIATION_EMAIL_ADDRESS
+ || isWebEmailAddressVariation(variation);
+ }
+
+ public static boolean isWebInputType(int inputType) {
+ final int maskedInputType =
+ inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+ return isWebEditTextInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
+ || isWebEmailAddressInputType(maskedInputType);
+ }
+
+ // Please refer to TextView.isPasswordInputType
+ public static boolean isPasswordInputType(int inputType) {
+ final int maskedInputType =
+ inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+ return isTextPasswordInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
+ || isNumberPasswordInputType(maskedInputType);
+ }
+
+ // Please refer to TextView.isVisiblePasswordInputType
+ public static boolean isVisiblePasswordInputType(int inputType) {
+ final int maskedInputType =
+ inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
+ return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE;
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 69780d0fd..db57044e9 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -45,18 +45,18 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
+import android.view.Window;
+import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.compat.CompatUtils;
-import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener;
@@ -64,6 +64,7 @@ import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.LatinKeyboardView;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.suggestions.SuggestionsView;
@@ -75,7 +76,7 @@ import java.util.Locale;
/**
* Input method implementation for Qwerty'ish keyboard.
*/
-public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener,
+public class LatinIME extends InputMethodService implements KeyboardActionListener,
SuggestionsView.Listener {
private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean TRACE = false;
@@ -225,6 +226,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private boolean mIsAutoCorrectionIndicatorOn;
+ private AlertDialog mOptionsDialog;
+
public final UIHandler mHandler = new UIHandler(this);
public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> {
@@ -476,7 +479,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Has to be package-visible for unit tests
/* package */ void loadSettings() {
if (null == mPrefs) mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr());
+ final RunInLocale<SettingsValues> job = new RunInLocale<SettingsValues>() {
+ @Override
+ protected SettingsValues job(Resources res) {
+ return new SettingsValues(mPrefs, LatinIME.this);
+ }
+ };
+ mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getInputLocale());
mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues);
resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary());
}
@@ -485,33 +494,37 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final String localeStr = mSubtypeSwitcher.getInputLocaleStr();
final Locale keyboardLocale = mSubtypeSwitcher.getInputLocale();
- final Resources res = mResources;
- final Locale savedLocale = LocaleUtils.setSystemLocale(res, keyboardLocale);
- final ContactsDictionary oldContactsDictionary;
- if (mSuggest != null) {
- oldContactsDictionary = mSuggest.getContactsDictionary();
- mSuggest.close();
- } else {
- oldContactsDictionary = null;
- }
-
- int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(res);
- mSuggest = new Suggest(this, mainDicResId, keyboardLocale);
- if (mSettingsValues.mAutoCorrectEnabled) {
- mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
- }
+ final Context context = this;
+ final RunInLocale<Void> job = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ final ContactsDictionary oldContactsDictionary;
+ if (mSuggest != null) {
+ oldContactsDictionary = mSuggest.getContactsDictionary();
+ mSuggest.close();
+ } else {
+ oldContactsDictionary = null;
+ }
- mUserDictionary = new UserDictionary(this, localeStr);
- mSuggest.setUserDictionary(mUserDictionary);
- mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
+ int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(res);
+ mSuggest = new Suggest(context, mainDicResId, keyboardLocale);
+ if (mSettingsValues.mAutoCorrectEnabled) {
+ mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
+ }
- resetContactsDictionary(oldContactsDictionary);
+ mUserDictionary = new UserDictionary(context, localeStr);
+ mSuggest.setUserDictionary(mUserDictionary);
+ mIsUserDictionaryAvailable = mUserDictionary.isEnabled();
- mUserHistoryDictionary
- = new UserHistoryDictionary(this, localeStr, Suggest.DIC_USER_HISTORY);
- mSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
+ resetContactsDictionary(oldContactsDictionary);
- LocaleUtils.setSystemLocale(res, savedLocale);
+ mUserHistoryDictionary
+ = new UserHistoryDictionary(context, localeStr, Suggest.DIC_USER_HISTORY);
+ mSuggest.setUserHistoryDictionary(mUserHistoryDictionary);
+ return null;
+ }
+ };
+ job.runInLocale(mResources, keyboardLocale);
}
/**
@@ -627,6 +640,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mHandler.onFinishInput();
}
+ @Override
+ public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) {
+ SubtypeSwitcher.getInstance().updateSubtype(subtype);
+ }
+
private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
super.onStartInput(editorInfo, restarting);
}
@@ -968,7 +986,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final int touchHeight = inputView.getHeight() + extraHeight
// Extend touchable region below the keyboard.
+ EXTENDED_TOUCHABLE_REGION_HEIGHT;
- setTouchableRegionCompat(outInsets, 0, touchY, touchWidth, touchHeight);
+ outInsets.touchableInsets = InputMethodService.Insets.TOUCHABLE_INSETS_REGION;
+ outInsets.touchableRegion.set(0, touchY, touchWidth, touchHeight);
}
outInsets.contentTopInsets = touchY;
outInsets.visibleTopInsets = touchY;
@@ -1167,7 +1186,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return keyboard != null ? keyboard.mId.imeActionId() : EditorInfo.IME_ACTION_NONE;
}
- private void performeEditorAction(int actionId) {
+ private void performEditorAction(int actionId) {
final InputConnection ic = getCurrentInputConnection();
if (ic != null) {
ic.performEditorAction(actionId);
@@ -1178,7 +1197,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean includesOtherImes = mSettingsValues.mIncludesOtherImesInLanguageSwitchList;
final IBinder token = getWindow().getWindow().getAttributes().token;
if (mShouldSwitchToLastSubtype) {
- final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype();
+ final InputMethodSubtype lastSubtype = mImm.getLastInputMethodSubtype();
final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme(
this, lastSubtype);
if ((includesOtherImes || lastSubtypeBelongsToThisIme)
@@ -1258,13 +1277,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mSubtypeSwitcher.switchToShortcutIME();
break;
case Keyboard.CODE_ACTION_ENTER:
- performeEditorAction(getActionId(switcher.getKeyboard()));
+ performEditorAction(getActionId(switcher.getKeyboard()));
break;
case Keyboard.CODE_ACTION_NEXT:
- performeEditorAction(EditorInfo.IME_ACTION_NEXT);
+ performEditorAction(EditorInfo.IME_ACTION_NEXT);
break;
case Keyboard.CODE_ACTION_PREVIOUS:
- EditorInfoCompatUtils.performEditorActionPrevious(getCurrentInputConnection());
+ performEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
break;
case Keyboard.CODE_LANGUAGE_SWITCH:
handleLanguageSwitchKey();
@@ -2263,6 +2282,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
showOptionDialogInternal(builder.create());
}
+ private void showOptionDialogInternal(AlertDialog dialog) {
+ final IBinder windowToken = KeyboardSwitcher.getInstance().getKeyboardView()
+ .getWindowToken();
+ if (windowToken == null) return;
+
+ dialog.setCancelable(true);
+ dialog.setCanceledOnTouchOutside(true);
+
+ final Window window = dialog.getWindow();
+ final WindowManager.LayoutParams lp = window.getAttributes();
+ lp.token = windowToken;
+ lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
+ window.setAttributes(lp);
+ window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
+
+ mOptionsDialog = dialog;
+ dialog.show();
+ }
+
@Override
protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) {
super.dump(fd, fout, args);
diff --git a/java/src/com/android/inputmethod/latin/LocaleUtils.java b/java/src/com/android/inputmethod/latin/LocaleUtils.java
index cf60089c5..f19c59a6a 100644
--- a/java/src/com/android/inputmethod/latin/LocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/LocaleUtils.java
@@ -161,21 +161,36 @@ public class LocaleUtils {
return LOCALE_MATCH <= level;
}
- /**
- * Sets the system locale for this process.
- *
- * @param res the resources to use. Pass current resources.
- * @param newLocale the locale to change to.
- * @return the old locale.
- */
- public static synchronized Locale setSystemLocale(final Resources res, final Locale newLocale) {
- final Configuration conf = res.getConfiguration();
- final Locale oldLocale = conf.locale;
- if (newLocale != null && !newLocale.equals(oldLocale)) {
- conf.locale = newLocale;
- res.updateConfiguration(conf, res.getDisplayMetrics());
+ static final Object sLockForRunInLocale = new Object();
+
+ public abstract static class RunInLocale<T> {
+ protected abstract T job(Resources res);
+
+ /**
+ * Execute {@link #job(Resources)} method in specified system locale exclusively.
+ *
+ * @param res the resources to use. Pass current resources.
+ * @param newLocale the locale to change to
+ * @return the value returned from {@link #job(Resources)}.
+ */
+ public T runInLocale(final Resources res, final Locale newLocale) {
+ synchronized (sLockForRunInLocale) {
+ final Configuration conf = res.getConfiguration();
+ final Locale oldLocale = conf.locale;
+ try {
+ if (newLocale != null && !newLocale.equals(oldLocale)) {
+ conf.locale = newLocale;
+ res.updateConfiguration(conf, res.getDisplayMetrics());
+ }
+ return job(res);
+ } finally {
+ if (newLocale != null && !newLocale.equals(oldLocale)) {
+ conf.locale = oldLocale;
+ res.updateConfiguration(conf, res.getDisplayMetrics());
+ }
+ }
+ }
}
- return oldLocale;
}
private static final HashMap<String, Locale> sLocaleCache = new HashMap<String, Locale>();
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index fd61292df..7b98a7188 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -18,7 +18,6 @@ package com.android.inputmethod.latin;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Dialog;
import android.app.Fragment;
import android.app.backup.BackupManager;
import android.content.Context;
@@ -34,31 +33,20 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
-import android.text.TextUtils;
-import android.text.method.LinkMovementMethod;
-import android.util.Log;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
-import com.android.inputmethod.compat.CompatUtils;
-import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
-import com.android.inputmethod.latin.VibratorUtils;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethodcommon.InputMethodSettingsActivity;
-import java.util.Locale;
-
public class Settings extends InputMethodSettingsActivity
- implements SharedPreferences.OnSharedPreferenceChangeListener, OnPreferenceClickListener {
- private static final String TAG = Settings.class.getSimpleName();
-
+ implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false;
// In the same order as xml/prefs.xml
public static final String PREF_GENERAL_SETTINGS = "general_settings";
- public static final String PREF_SUBTYPES_SETTINGS = "subtype_settings";
public static final String PREF_AUTO_CAP = "auto_cap";
public static final String PREF_VIBRATE_ON = "vibrate_on";
public static final String PREF_SOUND_ON = "sound_on";
@@ -90,7 +78,6 @@ public class Settings extends InputMethodSettingsActivity
public static final String PREF_SELECTED_LANGUAGES = "selected_languages";
public static final String PREF_DEBUG_SETTINGS = "debug_settings";
- private PreferenceScreen mInputLanguageSelection;
private PreferenceScreen mKeypressVibrationDurationSettingsPref;
private PreferenceScreen mKeypressSoundVolumeSettingsPref;
private ListPreference mVoicePreference;
@@ -102,14 +89,10 @@ public class Settings extends InputMethodSettingsActivity
// Prediction: use bigrams to predict the next word when there is no input for it yet
private CheckBoxPreference mBigramPrediction;
private Preference mDebugSettingsPreference;
- private boolean mVoiceOn;
- private AlertDialog mDialog;
private TextView mKeypressVibrationDurationSettingsTextView;
private TextView mKeypressSoundVolumeSettingsTextView;
- private String mVoiceModeOff;
-
private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getResources().getString(
R.string.auto_correction_threshold_mode_index_off);
@@ -140,18 +123,12 @@ public class Settings extends InputMethodSettingsActivity
final Context context = getActivityInternal();
addPreferencesFromResource(R.xml.prefs);
- mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES_SETTINGS);
- mInputLanguageSelection.setOnPreferenceClickListener(this);
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_MODE);
mShowCorrectionSuggestionsPreference =
(ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
prefs.registerOnSharedPreferenceChangeListener(this);
- mVoiceModeOff = getString(R.string.voice_mode_off);
- mVoiceOn = !(prefs.getString(PREF_VOICE_MODE, mVoiceModeOff)
- .equals(mVoiceModeOff));
-
mAutoCorrectionThresholdPreference =
(ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD);
mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTION);
@@ -183,10 +160,6 @@ public class Settings extends InputMethodSettingsActivity
generalSettings.removePreference(findPreference(PREF_VIBRATE_ON));
}
- if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) {
- generalSettings.removePreference(findPreference(PREF_SUBTYPES_SETTINGS));
- }
-
final boolean showPopupOption = res.getBoolean(
R.bool.config_enable_show_popup_on_keypress_option);
if (!showPopupOption) {
@@ -318,25 +291,12 @@ public class Settings extends InputMethodSettingsActivity
!SettingsValues.isLanguageSwitchKeySupressed(prefs));
}
ensureConsistencyOfAutoCorrectionSettings();
- mVoiceOn = !(prefs.getString(PREF_VOICE_MODE, mVoiceModeOff)
- .equals(mVoiceModeOff));
updateVoiceModeSummary();
updateShowCorrectionSuggestionsSummary();
updateKeyPreviewPopupDelaySummary();
refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources());
}
- @Override
- public boolean onPreferenceClick(Preference pref) {
- if (pref == mInputLanguageSelection) {
- final String imeId = SubtypeUtils.getInputMethodId(
- getActivityInternal().getApplicationInfo().packageName);
- startActivity(CompatUtils.getInputLanguageSelectionIntent(imeId, 0));
- return true;
- }
- return false;
- }
-
private void updateShowCorrectionSuggestionsSummary() {
mShowCorrectionSuggestionsPreference.setSummary(
getResources().getStringArray(R.array.prefs_suggestion_visibilities)
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index f76cc7e44..103678403 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -22,15 +22,16 @@ import android.content.res.Resources;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
-import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
-import com.android.inputmethod.latin.VibratorUtils;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Locale;
+/**
+ * When you call the constructor of this class, you may want to change the current system locale by
+ * using {@link LocaleUtils.RunInLocale}.
+ */
public class SettingsValues {
private static final String TAG = SettingsValues.class.getSimpleName();
@@ -78,16 +79,8 @@ public class SettingsValues {
private final boolean mVoiceKeyEnabled;
private final boolean mVoiceKeyOnMain;
- public SettingsValues(final SharedPreferences prefs, final Context context,
- final String localeStr) {
+ public SettingsValues(final SharedPreferences prefs, final Context context) {
final Resources res = context.getResources();
- final Locale savedLocale;
- if (null != localeStr) {
- final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr);
- savedLocale = LocaleUtils.setSystemLocale(res, keyboardLocale);
- } else {
- savedLocale = null;
- }
// Get the resources
mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions);
@@ -152,8 +145,6 @@ public class SettingsValues {
mAutoCorrectionThresholdRawValue);
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
-
- LocaleUtils.setSystemLocale(res, savedLocale);
}
// Helper functions to create member values.
@@ -286,7 +277,7 @@ public class SettingsValues {
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
return shortcutImeEnabled && mVoiceKeyEnabled
- && !InputTypeCompatUtils.isPasswordInputType(inputType);
+ && !InputTypeUtils.isPasswordInputType(inputType);
}
public boolean isVoiceKeyOnMain() {
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index de2e8be3d..e35364420 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -29,14 +29,13 @@ import android.os.AsyncTask;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
-import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -47,7 +46,6 @@ public class SubtypeSwitcher {
public static final String KEYBOARD_MODE = "keyboard";
private static final char LOCALE_SEPARATOR = '_';
- private static final String VOICE_MODE = "voice";
private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY =
"requireNetworkConnectivity";
@@ -59,19 +57,19 @@ public class SubtypeSwitcher {
private /* final */ InputMethodManagerCompatWrapper mImm;
private /* final */ Resources mResources;
private /* final */ ConnectivityManager mConnectivityManager;
- private final ArrayList<InputMethodSubtypeCompatWrapper>
- mEnabledKeyboardSubtypesOfCurrentInputMethod =
- new ArrayList<InputMethodSubtypeCompatWrapper>();
+ private final ArrayList<InputMethodSubtype> mEnabledKeyboardSubtypesOfCurrentInputMethod =
+ new ArrayList<InputMethodSubtype>();
private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>();
/*-----------------------------------------------------------*/
// Variants which should be changed only by reload functions.
private boolean mNeedsToDisplayLanguage;
private boolean mIsSystemLanguageSameAsInputLanguage;
- private InputMethodInfoCompatWrapper mShortcutInputMethodInfo;
- private InputMethodSubtypeCompatWrapper mShortcutSubtype;
- private List<InputMethodSubtypeCompatWrapper> mAllEnabledSubtypesOfCurrentInputMethod;
- private InputMethodSubtypeCompatWrapper mCurrentSubtype;
+ private InputMethodInfo mShortcutInputMethodInfo;
+ private InputMethodSubtype mShortcutSubtype;
+ private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod;
+ // Note: This variable is always non-null after {@link #initialize(LatinIME)}.
+ private InputMethodSubtype mCurrentSubtype;
private Locale mSystemLocale;
private Locale mInputLocale;
private String mInputLocaleStr;
@@ -104,7 +102,7 @@ public class SubtypeSwitcher {
mSystemLocale = null;
mInputLocale = null;
mInputLocaleStr = null;
- mCurrentSubtype = null;
+ mCurrentSubtype = mImm.getCurrentInputMethodSubtype();
mAllEnabledSubtypesOfCurrentInputMethod = null;
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
@@ -134,7 +132,7 @@ public class SubtypeSwitcher {
null, true);
mEnabledLanguagesOfCurrentInputMethod.clear();
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
- for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) {
+ for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) {
final String locale = getSubtypeLocale(ims);
final String mode = ims.getMode();
mLocaleSplitter.setString(locale);
@@ -168,12 +166,12 @@ public class SubtypeSwitcher {
+ ", " + mShortcutSubtype.getMode())));
}
// TODO: Update an icon for shortcut IME
- final Map<InputMethodInfoCompatWrapper, List<InputMethodSubtypeCompatWrapper>> shortcuts =
+ final Map<InputMethodInfo, List<InputMethodSubtype>> shortcuts =
mImm.getShortcutInputMethodsAndSubtypes();
mShortcutInputMethodInfo = null;
mShortcutSubtype = null;
- for (InputMethodInfoCompatWrapper imi : shortcuts.keySet()) {
- List<InputMethodSubtypeCompatWrapper> subtypes = shortcuts.get(imi);
+ for (InputMethodInfo imi : shortcuts.keySet()) {
+ List<InputMethodSubtype> subtypes = shortcuts.get(imi);
// TODO: Returns the first found IMI for now. Should handle all shortcuts as
// appropriate.
mShortcutInputMethodInfo = imi;
@@ -191,27 +189,17 @@ public class SubtypeSwitcher {
}
}
- private static String getSubtypeLocale(InputMethodSubtypeCompatWrapper subtype) {
+ private static String getSubtypeLocale(InputMethodSubtype subtype) {
final String keyboardLocale = subtype.getExtraValueOf(
LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE);
return keyboardLocale != null ? keyboardLocale : subtype.getLocale();
}
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
- public void updateSubtype(InputMethodSubtypeCompatWrapper newSubtype) {
- final String newLocale;
- final String newMode;
+ public void updateSubtype(InputMethodSubtype newSubtype) {
+ final String newLocale = getSubtypeLocale(newSubtype);
+ final String newMode = newSubtype.getMode();
final String oldMode = getCurrentSubtypeMode();
- if (newSubtype == null) {
- // Normally, newSubtype shouldn't be null. But just in case newSubtype was null,
- // fallback to the default locale.
- Log.w(TAG, "Couldn't get the current subtype.");
- newLocale = "en_US";
- newMode = KEYBOARD_MODE;
- } else {
- newLocale = getSubtypeLocale(newSubtype);
- newMode = newSubtype.getMode();
- }
if (DBG) {
Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
+ ", from: " + mInputLocaleStr + ", " + oldMode);
@@ -286,12 +274,10 @@ public class SubtypeSwitcher {
}
final String imiId = mShortcutInputMethodInfo.getId();
- final InputMethodSubtypeCompatWrapper subtype = mShortcutSubtype;
- switchToTargetIME(imiId, subtype);
+ switchToTargetIME(imiId, mShortcutSubtype);
}
- private void switchToTargetIME(
- final String imiId, final InputMethodSubtypeCompatWrapper subtype) {
+ private void switchToTargetIME(final String imiId, final InputMethodSubtype subtype) {
final IBinder token = mService.getWindow().getWindow().getAttributes().token;
if (token == null) {
return;
@@ -302,17 +288,6 @@ public class SubtypeSwitcher {
mImm.setInputMethodAndSubtype(token, imiId, subtype);
return null;
}
-
- @Override
- protected void onPostExecute(Void result) {
- // Calls in this method need to be done in the same thread as the thread which
- // called switchToShortcutIME().
-
- // Notify an event that the current subtype was changed. This event will be
- // handled if "onCurrentInputMethodSubtypeChanged" can't be implemented
- // when the API level is 10 or previous.
- mService.notifyOnCurrentInputMethodSubtypeChanged(subtype);
- }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@@ -320,8 +295,7 @@ public class SubtypeSwitcher {
return getSubtypeIcon(mShortcutInputMethodInfo, mShortcutSubtype);
}
- private Drawable getSubtypeIcon(
- InputMethodInfoCompatWrapper imi, InputMethodSubtypeCompatWrapper subtype) {
+ private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
final PackageManager pm = mService.getPackageManager();
if (imi != null) {
final String imiPackageName = imi.getPackageName();
@@ -362,15 +336,9 @@ public class SubtypeSwitcher {
if (mShortcutSubtype == null) {
return true;
}
- // For compatibility, if the shortcut subtype is dummy, we assume the shortcut IME
- // (built-in voice dummy subtype) is available.
- if (!mShortcutSubtype.hasOriginalObject()) {
- return true;
- }
final boolean allowsImplicitlySelectedSubtypes = true;
- for (final InputMethodSubtypeCompatWrapper enabledSubtype :
- mImm.getEnabledInputMethodSubtypeList(
- mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
+ for (final InputMethodSubtype enabledSubtype : mImm.getEnabledInputMethodSubtypeList(
+ mShortcutInputMethodInfo, allowsImplicitlySelectedSubtypes)) {
if (enabledSubtype.equals(mShortcutSubtype)) {
return true;
}
@@ -462,20 +430,20 @@ public class SubtypeSwitcher {
public String getCurrentSubtypeExtraValue() {
// If null, return what an empty ExtraValue would return : the empty string.
- return null != mCurrentSubtype ? mCurrentSubtype.getExtraValue() : "";
+ return mCurrentSubtype.getExtraValue();
}
public boolean currentSubtypeContainsExtraValueKey(String key) {
// If null, return what an empty ExtraValue would return : false.
- return null != mCurrentSubtype ? mCurrentSubtype.containsExtraValueKey(key) : false;
+ return mCurrentSubtype.containsExtraValueKey(key);
}
public String getCurrentSubtypeExtraValueOf(String key) {
// If null, return what an empty ExtraValue would return : null.
- return null != mCurrentSubtype ? mCurrentSubtype.getExtraValueOf(key) : null;
+ return mCurrentSubtype.getExtraValueOf(key);
}
public String getCurrentSubtypeMode() {
- return null != mCurrentSubtype ? mCurrentSubtype.getMode() : KEYBOARD_MODE;
+ return mCurrentSubtype.getMode();
}
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
index cb2bcf43f..2c5d58200 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
@@ -17,10 +17,10 @@
package com.android.inputmethod.latin;
import android.content.Context;
+import android.view.inputmethod.InputMethodInfo;
+import android.view.inputmethod.InputMethodSubtype;
-import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper;
import java.util.Collections;
import java.util.List;
@@ -31,15 +31,13 @@ public class SubtypeUtils {
}
// TODO: Cache my InputMethodInfo and/or InputMethodSubtype list.
- public static boolean checkIfSubtypeBelongsToThisIme(Context context,
- InputMethodSubtypeCompatWrapper ims) {
+ public static boolean checkIfSubtypeBelongsToThisIme(Context context, InputMethodSubtype ims) {
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
if (imm == null) return false;
- final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName());
- final List<InputMethodSubtypeCompatWrapper> subtypes =
- imm.getEnabledInputMethodSubtypeList(myImi, true);
- for (final InputMethodSubtypeCompatWrapper subtype : subtypes) {
+ final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName());
+ final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(myImi, true);
+ for (final InputMethodSubtype subtype : subtypes) {
if (subtype.equals(ims)) {
return true;
}
@@ -52,29 +50,29 @@ public class SubtypeUtils {
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
if (imm == null) return false;
- final List<InputMethodInfoCompatWrapper> enabledImis = imm.getEnabledInputMethodList();
+ final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis);
}
public static boolean hasMultipleEnabledSubtypesInThisIme(Context context,
final boolean shouldIncludeAuxiliarySubtypes) {
- final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName());
- final List<InputMethodInfoCompatWrapper> imiList = Collections.singletonList(myImi);
+ final InputMethodInfo myImi = getInputMethodInfo(context.getPackageName());
+ final List<InputMethodInfo> imiList = Collections.singletonList(myImi);
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList);
}
private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes,
- List<InputMethodInfoCompatWrapper> imiList) {
+ List<InputMethodInfo> imiList) {
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
if (imm == null) return false;
// Number of the filtered IMEs
int filteredImisCount = 0;
- for (InputMethodInfoCompatWrapper imi : imiList) {
+ for (InputMethodInfo imi : imiList) {
// We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1) return true;
- final List<InputMethodSubtypeCompatWrapper> subtypes =
+ final List<InputMethodSubtype> subtypes =
imm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
@@ -83,7 +81,7 @@ public class SubtypeUtils {
}
int auxCount = 0;
- for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
+ for (InputMethodSubtype subtype : subtypes) {
if (subtype.isAuxiliary()) {
++auxCount;
}
@@ -102,13 +100,12 @@ public class SubtypeUtils {
if (filteredImisCount > 1) {
return true;
}
- final List<InputMethodSubtypeCompatWrapper> subtypes =
- imm.getEnabledInputMethodSubtypeList(null, true);
+ final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(null, true);
int keyboardCount = 0;
// imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's
// both explicitly and implicitly enabled input method subtype.
// (The current IME should be LatinIME.)
- for (InputMethodSubtypeCompatWrapper subtype : subtypes) {
+ for (InputMethodSubtype subtype : subtypes) {
if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) {
++keyboardCount;
}
@@ -120,13 +117,13 @@ public class SubtypeUtils {
return getInputMethodInfo(packageName).getId();
}
- public static InputMethodInfoCompatWrapper getInputMethodInfo(String packageName) {
+ public static InputMethodInfo getInputMethodInfo(String packageName) {
final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance();
if (imm == null) {
throw new RuntimeException("Input method manager not found");
}
- for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) {
+ for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
if (imi.getPackageName().equals(packageName))
return imi;
}
diff --git a/java/src/com/android/inputmethod/latin/WhitelistDictionary.java b/java/src/com/android/inputmethod/latin/WhitelistDictionary.java
index a90ef290b..7bb307662 100644
--- a/java/src/com/android/inputmethod/latin/WhitelistDictionary.java
+++ b/java/src/com/android/inputmethod/latin/WhitelistDictionary.java
@@ -22,6 +22,8 @@ import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
+import com.android.inputmethod.latin.LocaleUtils.RunInLocale;
+
import java.util.HashMap;
import java.util.Locale;
@@ -36,10 +38,14 @@ public class WhitelistDictionary extends ExpandableDictionary {
// TODO: Conform to the async load contact of ExpandableDictionary
public WhitelistDictionary(final Context context, final Locale locale) {
super(context, Suggest.DIC_WHITELIST);
- final Resources res = context.getResources();
- final Locale previousLocale = LocaleUtils.setSystemLocale(res, locale);
- initWordlist(res.getStringArray(R.array.wordlist_whitelist));
- LocaleUtils.setSystemLocale(res, previousLocale);
+ final RunInLocale<Void> job = new RunInLocale<Void>() {
+ @Override
+ protected Void job(Resources res) {
+ initWordlist(res.getStringArray(R.array.wordlist_whitelist));
+ return null;
+ }
+ };
+ job.runInLocale(context.getResources(), locale);
}
private void initWordlist(String[] wordlist) {
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index af7f863ee..010ea6813 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -26,6 +26,7 @@ import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
@@ -922,7 +923,14 @@ public class BinaryDictInputOutput {
if (version >= FIRST_VERSION_WITH_HEADER_SIZE) {
final int headerSizeOffset = index;
index += 4; // Size of the header size
- // TODO: Write out the header contents here.
+
+ // Write out the options.
+ for (final String key : dict.mOptions.mAttributes.keySet()) {
+ final String value = dict.mOptions.mAttributes.get(key);
+ index += CharEncoding.writeString(buffer, index, key);
+ index += CharEncoding.writeString(buffer, index, value);
+ }
+
// Write out the header size.
buffer[headerSizeOffset] = (byte) (0xFF & (index >> 24));
buffer[headerSizeOffset + 1] = (byte) (0xFF & (index >> 16));
@@ -1214,12 +1222,17 @@ public class BinaryDictInputOutput {
source.readUnsignedShort();
final long headerSize;
+ final HashMap<String, String> options = new HashMap<String, String>();
if (version < FIRST_VERSION_WITH_HEADER_SIZE) {
headerSize = source.getFilePointer();
} else {
headerSize = (source.readUnsignedByte() << 24) + (source.readUnsignedByte() << 16)
+ (source.readUnsignedByte() << 8) + source.readUnsignedByte();
- // read the header body
+ while (source.getFilePointer() < headerSize) {
+ final String key = CharEncoding.readString(source);
+ final String value = CharEncoding.readString(source);
+ options.put(key, value);
+ }
source.seek(headerSize);
}
@@ -1228,7 +1241,7 @@ public class BinaryDictInputOutput {
final Node root = readNode(source, headerSize, reverseNodeMapping, reverseGroupMapping);
FusionDictionary newDict = new FusionDictionary(root,
- new FusionDictionary.DictionaryOptions());
+ new FusionDictionary.DictionaryOptions(options));
if (null != dict) {
for (Word w : dict) {
newDict.add(w.mWord, w.mFrequency, w.mShortcutTargets, w.mBigrams);
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index d3ffb47ad..99b17048d 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.latin.makedict;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -250,6 +251,10 @@ public class FusionDictionary implements Iterable<Word> {
* There are no options at the moment, so this class is empty.
*/
public static class DictionaryOptions {
+ final HashMap<String, String> mAttributes;
+ public DictionaryOptions(final HashMap<String, String> attributes) {
+ mAttributes = attributes;
+ }
}
@@ -257,8 +262,13 @@ public class FusionDictionary implements Iterable<Word> {
public final Node mRoot;
public FusionDictionary() {
- mOptions = new DictionaryOptions();
mRoot = new Node();
+ mOptions = new DictionaryOptions(new HashMap<String, String>());
+ }
+
+ public FusionDictionary(final HashMap<String, String> attributes) {
+ mRoot = new Node();
+ mOptions = new DictionaryOptions(attributes);
}
public FusionDictionary(final Node root, final DictionaryOptions options) {
@@ -266,6 +276,10 @@ public class FusionDictionary implements Iterable<Word> {
mOptions = options;
}
+ public void addOptionAttribute(final String key, final String value) {
+ mOptions.mAttributes.put(key, value);
+ }
+
/**
* Helper method to convert a String to an int array.
*/
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index ca253543e..1ad37b933 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -52,11 +52,11 @@ import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
-import com.android.inputmethod.compat.FrameLayoutCompatUtils;
import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.keyboard.MoreKeysPanel;
import com.android.inputmethod.keyboard.PointerTracker;
+import com.android.inputmethod.keyboard.ViewLayoutUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@@ -416,7 +416,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
ViewGroup.LayoutParams.WRAP_CONTENT);
final int infoWidth = info.getMeasuredWidth();
final int y = info.getMeasuredHeight();
- FrameLayoutCompatUtils.placeViewAt(
+ ViewLayoutUtils.placeViewAt(
info, x - infoWidth, y, infoWidth, info.getMeasuredHeight());
}
}