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/AdditionalSubtype.java56
-rw-r--r--java/src/com/android/inputmethod/latin/DebugSettings.java13
-rw-r--r--java/src/com/android/inputmethod/latin/DebugSettingsActivity.java36
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java15
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java37
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsActivity.java36
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java18
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeLocale.java133
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java54
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeUtils.java15
10 files changed, 277 insertions, 136 deletions
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java
new file mode 100644
index 000000000..deb247860
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java
@@ -0,0 +1,56 @@
+/*
+ * 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.view.inputmethod.InputMethodSubtype;
+
+import java.util.HashMap;
+import java.util.Locale;
+
+public class AdditionalSubtype {
+ public static final String QWERTY = "qwerty";
+ public static final String QWERTZ = "qwertz";
+ public static final String AZERTY = "azerty";
+
+ private static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
+ private static final String SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype";
+
+ // Keyboard layout to subtype name resource id map.
+ private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap =
+ new HashMap<String, Integer>();
+
+ static {
+ sKeyboardLayoutToNameIdsMap.put(QWERTY, R.string.subtype_generic_qwerty);
+ sKeyboardLayoutToNameIdsMap.put(QWERTZ, R.string.subtype_generic_qwertz);
+ sKeyboardLayoutToNameIdsMap.put(AZERTY, R.string.subtype_generic_azerty);
+ }
+
+ public static boolean isAdditionalSubtype(InputMethodSubtype subtype) {
+ return subtype.containsExtraValueKey(SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE);
+ }
+
+ public static InputMethodSubtype createAddtionalSubtype(
+ Locale locale, String keyboardLayoutSet) {
+ final String extraValue = String.format(
+ "%s=%s,%s", LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET, keyboardLayoutSet,
+ SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE);
+ Integer nameId = sKeyboardLayoutToNameIdsMap.get(keyboardLayoutSet);
+ if (nameId == null) nameId = R.string.subtype_generic;
+ return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
+ locale.toString(), SUBTYPE_MODE_KEYBOARD, extraValue, false, false);
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/DebugSettings.java b/java/src/com/android/inputmethod/latin/DebugSettings.java
index 23d63b42a..af7649863 100644
--- a/java/src/com/android/inputmethod/latin/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/DebugSettings.java
@@ -16,18 +16,19 @@
package com.android.inputmethod.latin;
+import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Process;
import android.preference.CheckBoxPreference;
-import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
import android.util.Log;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
-public class DebugSettings extends PreferenceActivity
+public class DebugSettings extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String TAG = DebugSettings.class.getSimpleName();
@@ -38,7 +39,7 @@ public class DebugSettings extends PreferenceActivity
private CheckBoxPreference mDebugMode;
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_for_debug);
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
@@ -50,7 +51,7 @@ public class DebugSettings extends PreferenceActivity
}
@Override
- protected void onStop() {
+ public void onStop() {
super.onStop();
if (mServiceNeedsRestart) Process.killProcess(Process.myPid());
}
@@ -76,7 +77,9 @@ public class DebugSettings extends PreferenceActivity
boolean isDebugMode = mDebugMode.isChecked();
String version = "";
try {
- PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
+ final Context context = getActivity();
+ final String packageName = context.getPackageName();
+ PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
version = "Version " + info.versionName;
} catch (NameNotFoundException e) {
Log.e(TAG, "Could not find version info.");
diff --git a/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java b/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java
new file mode 100644
index 000000000..cde20606a
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/DebugSettingsActivity.java
@@ -0,0 +1,36 @@
+/*
+ * 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.content.Intent;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class DebugSettingsActivity extends PreferenceActivity {
+ @Override
+ public Intent getIntent() {
+ final Intent modIntent = new Intent(super.getIntent());
+ modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DebugSettings.class.getName());
+ return modIntent;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setTitle(R.string.english_ime_debug_settings);
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index b587568c9..336929229 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -439,6 +439,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
loadSettings();
+ mImm.setAdditionalInputMethodSubtypes(
+ SubtypeUtils.getInputMethodId(getPackageName()),
+ mSettingsValues.getPrefefinedAdditionalSubtypes());
+
// TODO: remove the following when it's not needed by updateCorrectionMode() any more
mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
updateCorrectionMode();
@@ -1899,7 +1903,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mSettingsValues.mEnableSuggestionSpanInsertion) {
final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
- this, bestWord, suggestedWords), 1);
+ this, bestWord, suggestedWords, mSubtypeSwitcher.isDictionaryAvailable()),
+ 1);
} else {
ic.commitText(bestWord, 1);
}
@@ -2225,15 +2230,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- protected void launchSettings() {
- launchSettingsClass(Settings.class);
+ private void launchSettings() {
+ launchSettingsClass(SettingsActivity.class);
}
public void launchDebugSettings() {
- launchSettingsClass(DebugSettings.class);
+ launchSettingsClass(DebugSettingsActivity.class);
}
- protected void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) {
+ private void launchSettingsClass(Class<? extends PreferenceActivity> settingsClass) {
handleClose();
Intent intent = new Intent();
intent.setClass(LatinIME.this, settingsClass);
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index 6bc049894..43e7e278f 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -16,9 +16,7 @@
package com.android.inputmethod.latin;
-import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Fragment;
import android.app.backup.BackupManager;
import android.content.Context;
import android.content.DialogInterface;
@@ -33,15 +31,16 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
+import android.view.LayoutInflater;
import android.view.View;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.android.inputmethod.latin.define.ProductionFlag;
-import com.android.inputmethodcommon.InputMethodSettingsActivity;
+import com.android.inputmethodcommon.InputMethodSettingsFragment;
-public class Settings extends InputMethodSettingsActivity
+public class Settings extends InputMethodSettingsFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false;
@@ -103,26 +102,16 @@ public class Settings extends InputMethodSettingsActivity
}
}
- public Activity getActivityInternal() {
- Object thisObject = (Object) this;
- if (thisObject instanceof Activity) {
- return (Activity) thisObject;
- } else if (thisObject instanceof Fragment) {
- return ((Fragment) thisObject).getActivity();
- } else {
- return null;
- }
- }
-
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
setSubtypeEnablerTitle(R.string.select_language);
+ addPreferencesFromResource(R.xml.prefs);
+
final Resources res = getResources();
- final Context context = getActivityInternal();
+ final Context context = getActivity();
- addPreferencesFromResource(R.xml.prefs);
mVoicePreference = (ListPreference) findPreference(PREF_VOICE_MODE);
mShowCorrectionSuggestionsPreference =
(ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING);
@@ -276,7 +265,7 @@ public class Settings extends InputMethodSettingsActivity
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
- (new BackupManager(getActivityInternal())).dataChanged();
+ (new BackupManager(getActivity())).dataChanged();
if (key.equals(PREF_POPUP_ON)) {
final ListPreference popupDismissDelay =
(ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY);
@@ -318,7 +307,7 @@ public class Settings extends InputMethodSettingsActivity
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
SharedPreferences sp, Resources res) {
if (mKeypressVibrationDurationSettingsPref != null) {
- final boolean hasVibrator = VibratorUtils.getInstance(this).hasVibrator();
+ final boolean hasVibrator = VibratorUtils.getInstance(getActivity()).hasVibrator();
final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON,
res.getBoolean(R.bool.config_default_vibration_enabled));
mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn);
@@ -342,7 +331,7 @@ public class Settings extends InputMethodSettingsActivity
private void showKeypressVibrationDurationSettingsDialog() {
final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
- final Activity context = getActivityInternal();
+ final Context context = getActivity();
final Resources res = context.getResources();
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.prefs_keypress_vibration_duration_settings);
@@ -361,7 +350,7 @@ public class Settings extends InputMethodSettingsActivity
dialog.dismiss();
}
});
- final View v = context.getLayoutInflater().inflate(
+ final View v = LayoutInflater.from(context).inflate(
R.layout.vibration_settings_dialog, null);
final int currentMs = SettingsValues.getCurrentVibrationDuration(
getPreferenceManager().getSharedPreferences(), getResources());
@@ -398,9 +387,9 @@ public class Settings extends InputMethodSettingsActivity
}
private void showKeypressSoundVolumeSettingDialog() {
- final AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ final Context context = getActivity();
+ final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final SharedPreferences sp = getPreferenceManager().getSharedPreferences();
- final Activity context = getActivityInternal();
final Resources res = context.getResources();
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.prefs_keypress_sound_volume_settings);
@@ -420,7 +409,7 @@ public class Settings extends InputMethodSettingsActivity
dialog.dismiss();
}
});
- final View v = context.getLayoutInflater().inflate(
+ final View v = LayoutInflater.from(context).inflate(
R.layout.sound_effect_volume_dialog, null);
final int currentVolumeInt =
(int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100);
diff --git a/java/src/com/android/inputmethod/latin/SettingsActivity.java b/java/src/com/android/inputmethod/latin/SettingsActivity.java
new file mode 100644
index 000000000..b85a936ad
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/SettingsActivity.java
@@ -0,0 +1,36 @@
+/*
+ * 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.content.Intent;
+import android.os.Bundle;
+import android.preference.PreferenceActivity;
+
+public class SettingsActivity extends PreferenceActivity {
+ @Override
+ public Intent getIntent() {
+ final Intent modIntent = new Intent(super.getIntent());
+ modIntent.putExtra(EXTRA_SHOW_FRAGMENT, Settings.class.getName());
+ return modIntent;
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setTitle(R.string.english_ime_settings);
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index 526acf128..8ff644fc5 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -21,12 +21,14 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
+import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
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
@@ -69,6 +71,7 @@ public class SettingsValues {
private final int mVibrationDurationSettingsRawValue;
@SuppressWarnings("unused") // TODO: Use this
private final float mKeypressSoundVolumeRawValue;
+ private final InputMethodSubtype[] mPredefinedAdditionalSubtypes;
// Deduced settings
public final int mKeypressVibrationDuration;
@@ -145,6 +148,16 @@ public class SettingsValues {
mAutoCorrectionThresholdRawValue);
mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
+
+ // Predefined additional subtypes
+ final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAddtionalSubtype(
+ Locale.GERMAN, AdditionalSubtype.QWERTY);
+ final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAddtionalSubtype(
+ Locale.FRENCH, AdditionalSubtype.QWERTZ);
+ mPredefinedAdditionalSubtypes = new InputMethodSubtype[] {
+ DE_QWERTY,
+ FR_QWERTZ,
+ };
}
// Helper functions to create member values.
@@ -304,6 +317,11 @@ public class SettingsValues {
return res.getBoolean(R.bool.config_use_fullscreen_mode);
}
+ // TODO: Should be able to add/remove/edit.
+ public InputMethodSubtype[] getPrefefinedAdditionalSubtypes() {
+ return mPredefinedAdditionalSubtypes;
+ }
+
// Accessed from the settings interface, hence public
public static float getCurrentKeypressSoundVolume(final SharedPreferences sp,
final Resources res) {
diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
index 2bc22a6f9..37da5e846 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java
@@ -18,20 +18,19 @@ package com.android.inputmethod.latin;
import android.content.Context;
import android.content.res.Resources;
+import android.view.inputmethod.InputMethodSubtype;
-
+import java.util.HashMap;
import java.util.Locale;
public class SubtypeLocale {
// Special language code to represent "no language".
- public static final String NO_LANGUAGE = "zz";
- // Special country code to represent "QWERTY".
- /* package for test */ static final String QWERTY = "QY";
-
- public static final Locale LOCALE_NO_LANGUAGE_QWERTY = new Locale(NO_LANGUAGE, QWERTY);
+ private static final String NO_LANGUAGE = "zz";
+ public static final Locale LOCALE_NO_LANGUAGE = new Locale(NO_LANGUAGE);
- private static String[] sExceptionKeys;
- private static String[] sExceptionValues;
+ // Exceptional locales to display name map.
+ private static final HashMap<String, String> sExceptionalDisplayNamesMap =
+ new HashMap<String, String>();
private SubtypeLocale() {
// Intentional empty constructor for utility class.
@@ -39,70 +38,82 @@ public class SubtypeLocale {
public static void init(Context context) {
final Resources res = context.getResources();
- sExceptionKeys = res.getStringArray(R.array.subtype_locale_exception_keys);
- sExceptionValues = res.getStringArray(R.array.subtype_locale_exception_values);
- }
-
- private static String lookupExceptionalLocale(String key) {
- for (int index = 0; index < sExceptionKeys.length; index++) {
- if (sExceptionKeys[index].equals(key)) {
- return sExceptionValues[index];
- }
+ final String[] locales = res.getStringArray(R.array.subtype_locale_exception_keys);
+ final String[] displayNames = res.getStringArray(R.array.subtype_locale_exception_values);
+ for (int i = 0; i < locales.length; i++) {
+ sExceptionalDisplayNamesMap.put(locales[i], displayNames[i]);
}
- return null;
}
- // Get Locale's full display name in its locale.
- // For example:
- // "fr_CH" is converted to "Français (Suisse)".
- // "de_QY" is converted to "Deutsche (QWERTY)". (Any locale that has country code "QY")
- // "zz_QY" is converted to "QWERTY". (The language code "zz" means "No language", thus just
- // ends up with the keyboard layout name.)
- public static String getFullDisplayName(Locale locale) {
- final String key;
- if (locale.getLanguage().equals(NO_LANGUAGE)) {
- key = locale.getCountry();
- } else if (locale.getCountry().equals(QWERTY)) {
- key = "*_" + QWERTY;
- } else {
- key = locale.toString();
+ // Get InputMethodSubtype's display name in its locale.
+ // isAdditionalSubtype (T=true, F=false)
+ // locale layout | Short Middle Full
+ // ------ ------ - ---- --------- -----------------
+ // en_US qwerty F En English English (US) exception
+ // en_GB qwerty F En English English (UK) exception
+ // fr azerty F Fr Français Français
+ // fr_CA qwerty F Fr Français Français (Canada)
+ // de qwertz F De Deutsch Deutsch
+ // zz qwerty F QWERTY QWERTY
+ // fr qwertz T Fr Français Français (QWERTZ)
+ // de qwerty T De Deutsch Deutsch (QWERTY)
+ // en azerty T En English English (AZERTY)
+ // zz azerty T AZERTY AZERTY
+
+ // Get InputMethodSubtype's full display name in its locale.
+ public static String getFullDisplayName(InputMethodSubtype subtype) {
+ final String value = sExceptionalDisplayNamesMap.get(subtype.getLocale());
+ if (value != null) {
+ return value;
}
- final String value = lookupExceptionalLocale(key);
- if (value == null) {
- return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
+
+ if (isNoLanguage(subtype)) {
+ return getKeyboardLayoutSetName(subtype).toUpperCase();
}
- if (value.indexOf("%s") >= 0) {
- final String languageName = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
- return String.format(value, languageName);
+
+ final Locale locale = getSubtypeLocale(subtype);
+ final String language = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
+ if (AdditionalSubtype.isAdditionalSubtype(subtype)) {
+ return String.format("%s (%s)",
+ language, getKeyboardLayoutSetName(subtype).toUpperCase());
}
- return value;
+ return StringUtils.toTitleCase(locale.getDisplayName(locale), locale);
}
- // Get Locale's middle display name in its locale.
- // For example:
- // "fr_CH" is converted to "Français".
- // "de_QY" is converted to "Deutsche". (Any locale that has country code "QY")
- // "zz_QY" is converted to "QWERTY". (The language code "zz" means "No language", thus just
- // ends up with the keyboard layout name.)
- public static String getMiddleDisplayName(Locale locale) {
- if (NO_LANGUAGE.equals(locale.getLanguage())) {
- return lookupExceptionalLocale(locale.getCountry());
- } else {
- return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
+ // Get InputMethodSubtype's middle display name in its locale.
+ public static String getMiddleDisplayName(InputMethodSubtype subtype) {
+ if (isNoLanguage(subtype)) {
+ return getKeyboardLayoutSetName(subtype).toUpperCase();
}
+ final Locale locale = getSubtypeLocale(subtype);
+ return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale);
}
- // Get Locale's short display name in its locale.
- // For example:
- // "fr_CH" is converted to "Fr".
- // "de_QY" is converted to "De". (Any locale that has country code "QY")
- // "zz_QY" is converter to "QY". (The language code "zz" means "No language", thus just ends
- // up with the keyboard layout name.)
- public static String getShortDisplayName(Locale locale) {
- if (NO_LANGUAGE.equals(locale.getLanguage())) {
- return locale.getCountry();
- } else {
- return StringUtils.toTitleCase(locale.getLanguage(), locale);
+ // Get InputMethodSubtype's short display name in its locale.
+ public static String getShortDisplayName(InputMethodSubtype subtype) {
+ if (isNoLanguage(subtype)) {
+ return "";
}
+ final Locale locale = getSubtypeLocale(subtype);
+ return StringUtils.toTitleCase(locale.getLanguage(), locale);
+ }
+
+ public static boolean isNoLanguage(InputMethodSubtype subtype) {
+ final String localeString = subtype.getLocale();
+ return localeString.equals(NO_LANGUAGE);
+ }
+
+ public static Locale getSubtypeLocale(InputMethodSubtype subtype) {
+ final String localeString = subtype.getLocale();
+ return LocaleUtils.constructLocaleFromString(localeString);
+ }
+
+ public static String getKeyboardLayoutSetName(InputMethodSubtype subtype) {
+ final String keyboardLayoutSet = subtype.getExtraValueOf(
+ LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET);
+ // TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is
+ // fixed.
+ if (keyboardLayoutSet == null) return AdditionalSubtype.QWERTY;
+ return keyboardLayoutSet;
}
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 6612c24cd..3bb3ab4ba 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -31,7 +31,6 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import java.util.ArrayList;
@@ -63,6 +62,7 @@ public class SubtypeSwitcher {
/*-----------------------------------------------------------*/
// Variants which should be changed only by reload functions.
private boolean mNeedsToDisplayLanguage;
+ private boolean mIsDictionaryAvailable;
private boolean mIsSystemLanguageSameAsInputLanguage;
private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype;
@@ -104,8 +104,8 @@ public class SubtypeSwitcher {
mInputLocaleStr = null;
mCurrentSubtype = mImm.getCurrentInputMethodSubtype();
mAllEnabledSubtypesOfCurrentInputMethod = null;
- mNoLanguageSubtype = SubtypeUtils.findSubtypeByKeyboardLayoutSetLocale(
- service, SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY);
+ mNoLanguageSubtype = SubtypeUtils.findSubtypeByLocaleAndKeyboardLayoutSet(
+ service, SubtypeLocale.LOCALE_NO_LANGUAGE, AdditionalSubtype.QWERTY);
final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
mIsNetworkConnected = (info != null && info.isConnected());
@@ -128,14 +128,14 @@ public class SubtypeSwitcher {
// Reload enabledSubtypes from the framework.
private void updateEnabledSubtypes() {
- final String currentMode = getCurrentSubtypeMode();
+ final String currentMode = mCurrentSubtype.getMode();
boolean foundCurrentSubtypeBecameDisabled = true;
mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList(
null, true);
mEnabledLanguagesOfCurrentInputMethod.clear();
mEnabledKeyboardSubtypesOfCurrentInputMethod.clear();
for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) {
- final String locale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(ims);
+ final String locale = ims.getLocale();
final String mode = ims.getMode();
mLocaleSplitter.setString(locale);
if (mLocaleSplitter.hasNext()) {
@@ -165,8 +165,7 @@ public class SubtypeSwitcher {
+ (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (
- KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
- + ", " + mShortcutSubtype.getMode())));
+ mShortcutSubtype.getLocale() + ", " + mShortcutSubtype.getMode())));
}
// TODO: Update an icon for shortcut IME
final Map<InputMethodInfo, List<InputMethodSubtype>> shortcuts =
@@ -188,16 +187,15 @@ public class SubtypeSwitcher {
+ (mShortcutInputMethodInfo == null
? "<null>" : mShortcutInputMethodInfo.getId()) + ", "
+ (mShortcutSubtype == null ? "<null>" : (
- KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype)
- + ", " + mShortcutSubtype.getMode())));
+ mShortcutSubtype.getLocale() + ", " + mShortcutSubtype.getMode())));
}
}
// Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
public void updateSubtype(InputMethodSubtype newSubtype) {
- final String newLocale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(newSubtype);
+ final String newLocale = newSubtype.getLocale();
final String newMode = newSubtype.getMode();
- final String oldMode = getCurrentSubtypeMode();
+ final String oldMode = mCurrentSubtype.getMode();
if (DBG) {
Log.w(TAG, "Update subtype to:" + newLocale + "," + newMode
+ ", from: " + mInputLocaleStr + ", " + oldMode);
@@ -217,7 +215,7 @@ public class SubtypeSwitcher {
}
mCurrentSubtype = newSubtype;
- if (isKeyboardMode()) {
+ if (KEYBOARD_MODE.equals(mCurrentSubtype.getMode())) {
if (modeChanged || languageChanged) {
updateShortcutIME();
mService.onRefreshKeyboard();
@@ -232,12 +230,10 @@ public class SubtypeSwitcher {
}
Log.w(TAG, "Unknown subtype mode: " + newMode + "," + version + ", " + packageName
+ ". IME is already changed to other IME.");
- if (newSubtype != null) {
- Log.w(TAG, "Subtype mode:" + newSubtype.getMode());
- Log.w(TAG, "Subtype locale:" + newSubtype.getLocale());
- Log.w(TAG, "Subtype extra value:" + newSubtype.getExtraValue());
- Log.w(TAG, "Subtype is auxiliary:" + newSubtype.isAuxiliary());
- }
+ Log.w(TAG, "Subtype mode:" + newSubtype.getMode());
+ Log.w(TAG, "Subtype locale:" + newSubtype.getLocale());
+ Log.w(TAG, "Subtype extra value:" + newSubtype.getExtraValue());
+ Log.w(TAG, "Subtype is auxiliary:" + newSubtype.isAuxiliary());
}
}
@@ -260,6 +256,7 @@ public class SubtypeSwitcher {
getInputLocale().getLanguage());
mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1
&& mIsSystemLanguageSameAsInputLanguage);
+ mIsDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(mService, mInputLocale);
}
////////////////////////////
@@ -280,10 +277,11 @@ public class SubtypeSwitcher {
if (token == null) {
return;
}
+ final InputMethodManagerCompatWrapper imm = mImm;
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
- mImm.setInputMethodAndSubtype(token, imiId, subtype);
+ imm.setInputMethodAndSubtype(token, imiId, subtype);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@@ -335,7 +333,7 @@ public class SubtypeSwitcher {
}
public boolean needsToDisplayLanguage(Locale keyboardLocale) {
- if (keyboardLocale.equals(SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY)) {
+ if (keyboardLocale.equals(SubtypeLocale.LOCALE_NO_LANGUAGE)) {
return true;
}
if (!keyboardLocale.equals(mInputLocale)) {
@@ -379,20 +377,8 @@ public class SubtypeSwitcher {
}
}
- // TODO: Remove this method
- private boolean isKeyboardMode() {
- return KEYBOARD_MODE.equals(getCurrentSubtypeMode());
- }
-
- // TODO: Remove this method
- private String getCurrentSubtypeMode() {
- return mCurrentSubtype.getMode();
- }
-
- // TODO: Remove this method
- public boolean currentSubtypeContainsExtraValueKey(String key) {
- // If null, return what an empty ExtraValue would return : false.
- return mCurrentSubtype.containsExtraValueKey(key);
+ public boolean isDictionaryAvailable() {
+ return mIsDictionaryAvailable;
}
public InputMethodSubtype getCurrentSubtype() {
diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
index a747c9ad7..4d0f1c262 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java
@@ -21,7 +21,6 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
-import com.android.inputmethod.keyboard.KeyboardLayoutSet;
import java.util.Collections;
import java.util.List;
@@ -125,24 +124,26 @@ public class SubtypeUtils {
throw new RuntimeException("Input method manager not found");
}
- for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
+ for (final InputMethodInfo imi : imm.getInputMethodList()) {
if (imi.getPackageName().equals(packageName))
return imi;
}
throw new RuntimeException("Can not find input method id for " + packageName);
}
- public static InputMethodSubtype findSubtypeByKeyboardLayoutSetLocale(
- Context context, Locale locale) {
+ public static InputMethodSubtype findSubtypeByLocaleAndKeyboardLayoutSet(
+ Context context, Locale locale, String keyoardLayoutSet) {
final String localeString = locale.toString();
- final InputMethodInfo imi = SubtypeUtils.getInputMethodInfo(context.getPackageName());
+ final InputMethodInfo imi = getInputMethodInfo(context.getPackageName());
final int count = imi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
- if (localeString.equals(KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(subtype))) {
+ final String layout = SubtypeLocale.getKeyboardLayoutSetName(subtype);
+ if (localeString.equals(subtype.getLocale()) && keyoardLayoutSet.equals(layout)) {
return subtype;
}
}
- throw new RuntimeException("Can not find subtype of locale " + localeString);
+ throw new RuntimeException("Can't find subtype for locale " + localeString
+ + " and keyboard layout " + keyoardLayoutSet);
}
}