From 7a16a061e622539e54d7d649dcb8d4965aea575a Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 8 Dec 2011 22:10:40 +0900 Subject: Extract Settings.Values to a new class This is pretty much automatic refactoring. Thanks Eclipse! Change-Id: I8ccd24d11878445c836347e9c487c91461eee9cd --- .../android/inputmethod/latin/SettingsValues.java | 244 +++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 java/src/com/android/inputmethod/latin/SettingsValues.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java new file mode 100644 index 000000000..4aa683abe --- /dev/null +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2011 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.Context; +import android.content.SharedPreferences; +import android.content.res.Resources; +import android.util.Log; +import android.view.inputmethod.EditorInfo; + +import com.android.inputmethod.compat.InputTypeCompatUtils; +import com.android.inputmethod.compat.VibratorCompatWrapper; + +import java.util.Arrays; +import java.util.Locale; + +public class SettingsValues { + private static final String TAG = SettingsValues.class.getSimpleName(); + + // From resources: + public final int mDelayUpdateOldSuggestions; + public final String mWordSeparators; + public final String mMagicSpaceStrippers; + public final String mMagicSpaceSwappers; + public final String mSuggestPuncs; + public final SuggestedWords mSuggestPuncList; + private final String mSymbolsExcludedFromWordSeparators; + public final CharSequence mHintToSaveText; + + // From preferences: + public final boolean mSoundOn; // Sound setting private to Latin IME (see mSilentModeOn) + public final boolean mVibrateOn; + public final boolean mKeyPreviewPopupOn; + public final int mKeyPreviewPopupDismissDelay; + public final boolean mAutoCap; + public final boolean mAutoCorrectEnabled; + public final double mAutoCorrectionThreshold; + // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary + public final boolean mBigramSuggestionEnabled; + // Prediction: use bigrams to predict the next word when there is no input for it yet + public final boolean mBigramPredictionEnabled; + public final boolean mUseContactsDict; + public final boolean mEnableSuggestionSpanInsertion; + + private final boolean mShowSettingsKey; + private final boolean mVoiceKeyEnabled; + private final boolean mVoiceKeyOnMain; + + public SettingsValues(final SharedPreferences prefs, final Context context, + final String localeStr) { + 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); + mMagicSpaceStrippers = res.getString(R.string.magic_space_stripping_symbols); + mMagicSpaceSwappers = res.getString(R.string.magic_space_swapping_symbols); + String wordSeparators = mMagicSpaceStrippers + mMagicSpaceSwappers + + res.getString(R.string.magic_space_promoting_symbols); + final String symbolsExcludedFromWordSeparators = + res.getString(R.string.symbols_excluded_from_word_separators); + for (int i = symbolsExcludedFromWordSeparators.length() - 1; i >= 0; --i) { + wordSeparators = wordSeparators.replace( + symbolsExcludedFromWordSeparators.substring(i, i + 1), ""); + } + mSymbolsExcludedFromWordSeparators = symbolsExcludedFromWordSeparators; + mWordSeparators = wordSeparators; + mSuggestPuncs = res.getString(R.string.suggested_punctuations); + // TODO: it would be nice not to recreate this each time we change the configuration + mSuggestPuncList = createSuggestPuncList(mSuggestPuncs); + mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); + + // Get the settings preferences + final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator(); + mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, + res.getBoolean(R.bool.config_default_vibration_enabled)); + mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, + res.getBoolean(R.bool.config_default_sound_enabled)); + mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res); + mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); + mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); + mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); + mBigramSuggestionEnabled = mAutoCorrectEnabled + && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); + mBigramPredictionEnabled = mBigramSuggestionEnabled + && isBigramPredictionEnabled(prefs, res); + mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); + mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); + mEnableSuggestionSpanInsertion = + prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true); + final boolean defaultShowSettingsKey = res.getBoolean( + R.bool.config_default_show_settings_key); + mShowSettingsKey = isShowSettingsKeyOption(res) + ? prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, defaultShowSettingsKey) + : defaultShowSettingsKey; + final String voiceModeMain = res.getString(R.string.voice_mode_main); + final String voiceModeOff = res.getString(R.string.voice_mode_off); + final String voiceMode = prefs.getString(Settings.PREF_VOICE_SETTINGS_KEY, voiceModeMain); + mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); + mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain); + + LocaleUtils.setSystemLocale(res, savedLocale); + } + + public boolean isSuggestedPunctuation(int code) { + return mSuggestPuncs.contains(String.valueOf((char)code)); + } + + public boolean isWordSeparator(int code) { + return mWordSeparators.contains(String.valueOf((char)code)); + } + + public boolean isSymbolExcludedFromWordSeparators(int code) { + return mSymbolsExcludedFromWordSeparators.contains(String.valueOf((char)code)); + } + + public boolean isMagicSpaceStripper(int code) { + return mMagicSpaceStrippers.contains(String.valueOf((char)code)); + } + + public boolean isMagicSpaceSwapper(int code) { + return mMagicSpaceSwappers.contains(String.valueOf((char)code)); + } + + private static boolean isAutoCorrectEnabled(SharedPreferences sp, Resources resources) { + final String currentAutoCorrectionSetting = sp.getString( + Settings.PREF_AUTO_CORRECTION_THRESHOLD, + resources.getString(R.string.auto_correction_threshold_mode_index_modest)); + final String autoCorrectionOff = resources.getString( + R.string.auto_correction_threshold_mode_index_off); + return !currentAutoCorrectionSetting.equals(autoCorrectionOff); + } + + // Public to access from KeyboardSwitcher. Should it have access to some + // process-global instance instead? + public static boolean isKeyPreviewPopupEnabled(SharedPreferences sp, Resources resources) { + final boolean showPopupOption = resources.getBoolean( + R.bool.config_enable_show_popup_on_keypress_option); + if (!showPopupOption) return resources.getBoolean(R.bool.config_default_popup_preview); + return sp.getBoolean(Settings.PREF_KEY_PREVIEW_POPUP_ON, + resources.getBoolean(R.bool.config_default_popup_preview)); + } + + // Likewise + public static int getKeyPreviewPopupDismissDelay(SharedPreferences sp, + Resources resources) { + return Integer.parseInt(sp.getString(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, + Integer.toString(resources.getInteger(R.integer.config_delay_after_preview)))); + } + + private static boolean isBigramSuggestionEnabled(SharedPreferences sp, Resources resources, + boolean autoCorrectEnabled) { + final boolean showBigramSuggestionsOption = resources.getBoolean( + R.bool.config_enable_bigram_suggestions_option); + if (!showBigramSuggestionsOption) { + return autoCorrectEnabled; + } + return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, resources.getBoolean( + R.bool.config_default_bigram_suggestions)); + } + + private static boolean isBigramPredictionEnabled(SharedPreferences sp, + Resources resources) { + return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, resources.getBoolean( + R.bool.config_default_bigram_prediction)); + } + + private static double getAutoCorrectionThreshold(SharedPreferences sp, + Resources resources) { + final String currentAutoCorrectionSetting = sp.getString( + Settings.PREF_AUTO_CORRECTION_THRESHOLD, + resources.getString(R.string.auto_correction_threshold_mode_index_modest)); + final String[] autoCorrectionThresholdValues = resources.getStringArray( + R.array.auto_correction_threshold_values); + // When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off. + double autoCorrectionThreshold = Double.MAX_VALUE; + try { + final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting); + if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) { + autoCorrectionThreshold = Double.parseDouble( + autoCorrectionThresholdValues[arrayIndex]); + } + } catch (NumberFormatException e) { + // Whenever the threshold settings are correct, never come here. + autoCorrectionThreshold = Double.MAX_VALUE; + Log.w(TAG, "Cannot load auto correction threshold setting." + + " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting + + ", autoCorrectionThresholdValues: " + + Arrays.toString(autoCorrectionThresholdValues)); + } + return autoCorrectionThreshold; + } + + private static SuggestedWords createSuggestPuncList(final String puncs) { + SuggestedWords.Builder builder = new SuggestedWords.Builder(); + if (puncs != null) { + for (int i = 0; i < puncs.length(); i++) { + builder.addWord(puncs.subSequence(i, i + 1)); + } + } + return builder.setIsPunctuationSuggestions().build(); + } + + public static boolean isShowSettingsKeyOption(final Resources resources) { + return resources.getBoolean(R.bool.config_enable_show_settings_key_option); + + } + + public boolean isSettingsKeyEnabled() { + return mShowSettingsKey; + } + + public boolean isVoiceKeyEnabled(EditorInfo editorInfo) { + final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); + final int inputType = (editorInfo != null) ? editorInfo.inputType : 0; + return shortcutImeEnabled && mVoiceKeyEnabled + && !InputTypeCompatUtils.isPasswordInputType(inputType); + } + + public boolean isVoiceKeyOnMain() { + return mVoiceKeyOnMain; + } +} \ No newline at end of file -- cgit v1.2.3-83-g751a From ed432962175a6f783428bbdcd7168d20097ec05d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 8 Dec 2011 22:14:54 +0900 Subject: Move settings method from Utils to SettingsValues Change-Id: I633378a41f63cd492b8c9345d550e07254df5e5a --- .../com/android/inputmethod/latin/LatinIME.java | 4 +-- .../com/android/inputmethod/latin/Settings.java | 10 +++--- .../android/inputmethod/latin/SettingsValues.java | 36 +++++++++++++++++++++- java/src/com/android/inputmethod/latin/Utils.java | 34 -------------------- 4 files changed, 42 insertions(+), 42 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 602de9203..4772334ce 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2323,7 +2323,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // update keypress sound volume private void updateSoundEffectVolume() { - mFxVolume = Utils.getCurrentKeypressSoundVolume(mPrefs, mResources); + mFxVolume = SettingsValues.getCurrentKeypressSoundVolume(mPrefs, mResources); } // update flags for silent mode @@ -2336,7 +2336,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void updateKeypressVibrationDuration() { - mKeypressVibrationDuration = Utils.getCurrentVibrationDuration(mPrefs, mResources); + mKeypressVibrationDuration = SettingsValues.getCurrentVibrationDuration(mPrefs, mResources); } private void playKeyClick(int primaryCode) { diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 27003280c..31c92e363 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -447,7 +447,7 @@ public class Settings extends InputMethodSettingsActivity SharedPreferences sp, Resources res) { if (mKeypressVibrationDurationSettingsPref != null) { mKeypressVibrationDurationSettingsPref.setSummary( - Utils.getCurrentVibrationDuration(sp, res) + SettingsValues.getCurrentVibrationDuration(sp, res) + res.getString(R.string.settings_ms)); } } @@ -475,7 +475,7 @@ public class Settings extends InputMethodSettingsActivity }); final View v = context.getLayoutInflater().inflate( R.layout.vibration_settings_dialog, null); - final int currentMs = Utils.getCurrentVibrationDuration( + final int currentMs = SettingsValues.getCurrentVibrationDuration( getPreferenceManager().getSharedPreferences(), getResources()); mKeypressVibrationDurationSettingsTextView = (TextView)v.findViewById(R.id.vibration_value); final SeekBar sb = (SeekBar)v.findViewById(R.id.vibration_settings); @@ -504,8 +504,8 @@ public class Settings extends InputMethodSettingsActivity private void updateKeypressSoundVolumeSummary(SharedPreferences sp, Resources res) { if (mKeypressSoundVolumeSettingsPref != null) { - mKeypressSoundVolumeSettingsPref.setSummary( - String.valueOf((int)(Utils.getCurrentKeypressSoundVolume(sp, res) * 100))); + mKeypressSoundVolumeSettingsPref.setSummary(String.valueOf( + (int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100))); } } @@ -534,7 +534,7 @@ public class Settings extends InputMethodSettingsActivity }); final View v = context.getLayoutInflater().inflate( R.layout.sound_effect_volume_dialog, null); - final int currentVolumeInt = (int)(Utils.getCurrentKeypressSoundVolume( + final int currentVolumeInt = (int)(SettingsValues.getCurrentKeypressSoundVolume( getPreferenceManager().getSharedPreferences(), getResources()) * 100); mKeypressSoundVolumeSettingsTextView = (TextView)v.findViewById(R.id.sound_effect_volume_value); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 4aa683abe..50fa69401 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -19,11 +19,13 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; +import android.os.Build; import android.util.Log; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethod.latin.R.array; import java.util.Arrays; import java.util.Locale; @@ -241,4 +243,36 @@ public class SettingsValues { public boolean isVoiceKeyOnMain() { return mVoiceKeyOnMain; } -} \ No newline at end of file + + public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) { + final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); + if (volume >= 0) { + return volume; + } + + final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes); + final String hardwarePrefix = Build.HARDWARE + ","; + for (final String element : volumePerHardwareList) { + if (element.startsWith(hardwarePrefix)) { + return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); + } + } + return -1.0f; + } + + public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) { + final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1); + if (ms >= 0) { + return ms; + } + final String[] durationPerHardwareList = res.getStringArray( + R.array.keypress_vibration_durations); + final String hardwarePrefix = Build.HARDWARE + ","; + for (final String element : durationPerHardwareList) { + if (element.startsWith(hardwarePrefix)) { + return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1)); + } + } + return -1; + } +} diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 3d0aa09f1..7f507fe02 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -17,11 +17,9 @@ package com.android.inputmethod.latin; import android.content.Context; -import android.content.SharedPreferences; import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.os.AsyncTask; -import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.Process; @@ -778,38 +776,6 @@ public class Utils { return s.toUpperCase(locale).charAt(0) + s.substring(1); } - public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) { - final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1); - if (ms >= 0) { - return ms; - } - final String[] durationPerHardwareList = res.getStringArray( - R.array.keypress_vibration_durations); - final String hardwarePrefix = Build.HARDWARE + ","; - for (final String element : durationPerHardwareList) { - if (element.startsWith(hardwarePrefix)) { - return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1)); - } - } - return -1; - } - - public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) { - final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); - if (volume >= 0) { - return volume; - } - - final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes); - final String hardwarePrefix = Build.HARDWARE + ","; - for (final String element : volumePerHardwareList) { - if (element.startsWith(hardwarePrefix)) { - return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); - } - } - return -1.0f; - } - public static boolean willAutoCorrect(SuggestedWords suggestions) { return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate && !suggestions.shouldBlockAutoCorrection(); -- cgit v1.2.3-83-g751a From c207e0a7dad0bdae054be47cafe878698f9401fc Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 8 Dec 2011 22:21:26 +0900 Subject: Move settings variables to the settings class Change-Id: Ifa7033a84b08ea626eb44cf6d04ba8e28c250bea --- java/src/com/android/inputmethod/latin/LatinIME.java | 19 +++---------------- java/src/com/android/inputmethod/latin/Settings.java | 4 ++-- .../com/android/inputmethod/latin/SettingsValues.java | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 21 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 985793ef3..de273b56f 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -221,11 +221,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private long mLastKeyTime; private AudioManager mAudioManager; - private float mFxVolume = -1.0f; // default volume private boolean mSilentModeOn; // System-wide current configuration private VibratorCompatWrapper mVibrator; - private long mKeypressVibrationDuration = -1; // TODO: Move this flag to VoiceProxy private boolean mConfigurationChanging; @@ -550,8 +548,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (null == mSubtypeSwitcher) mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSettingsValues = new SettingsValues(mPrefs, this, mSubtypeSwitcher.getInputLocaleStr()); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); - updateSoundEffectVolume(); - updateKeypressVibrationDuration(); } private void initSuggest() { @@ -2321,11 +2317,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } }; - // update keypress sound volume - private void updateSoundEffectVolume() { - mFxVolume = SettingsValues.getCurrentKeypressSoundVolume(mPrefs, mResources); - } - // update flags for silent mode private void updateRingerMode() { if (mAudioManager == null) { @@ -2335,10 +2326,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL); } - private void updateKeypressVibrationDuration() { - mKeypressVibrationDuration = SettingsValues.getCurrentVibrationDuration(mPrefs, mResources); - } - private void playKeyClick(int primaryCode) { // if mAudioManager is null, we don't have the ringer state yet // mAudioManager will be set by updateRingerMode @@ -2363,7 +2350,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar sound = AudioManager.FX_KEYPRESS_STANDARD; break; } - mAudioManager.playSoundEffect(sound, mFxVolume); + mAudioManager.playSoundEffect(sound, mSettingsValues.mFxVolume); } } @@ -2371,7 +2358,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (!mSettingsValues.mVibrateOn) { return; } - if (mKeypressVibrationDuration < 0) { + if (mSettingsValues.mKeypressVibrationDuration < 0) { // Go ahead with the system default LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) { @@ -2380,7 +2367,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); } } else if (mVibrator != null) { - mVibrator.vibrate(mKeypressVibrationDuration); + mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration); } } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 6558c3ca3..4166e6266 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -543,8 +543,8 @@ public class Settings extends InputMethodSettingsActivity }); final View v = context.getLayoutInflater().inflate( R.layout.sound_effect_volume_dialog, null); - final int currentVolumeInt = (int)(SettingsValues.getCurrentKeypressSoundVolume( - getPreferenceManager().getSharedPreferences(), getResources()) * 100); + final int currentVolumeInt = + (int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100); mKeypressSoundVolumeSettingsTextView = (TextView)v.findViewById(R.id.sound_effect_volume_value); final SeekBar sb = (SeekBar)v.findViewById(R.id.sound_effect_volume_bar); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 50fa69401..62cf4a38e 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -25,7 +25,6 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; -import com.android.inputmethod.latin.R.array; import java.util.Arrays; import java.util.Locale; @@ -62,6 +61,10 @@ public class SettingsValues { private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyOnMain; + // Deduced settings + public final int mKeypressVibrationDuration; + public final float mFxVolume; + public SettingsValues(final SharedPreferences prefs, final Context context, final String localeStr) { final Resources res = context.getResources(); @@ -122,6 +125,9 @@ public class SettingsValues { mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain); + mFxVolume = getCurrentKeypressSoundVolume(prefs, res); + mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); + LocaleUtils.setSystemLocale(res, savedLocale); } @@ -244,7 +250,9 @@ public class SettingsValues { return mVoiceKeyOnMain; } - public static float getCurrentKeypressSoundVolume(SharedPreferences sp, Resources res) { + // Accessed from the settings interface, hence public + public static float getCurrentKeypressSoundVolume(final SharedPreferences sp, + final Resources res) { final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); if (volume >= 0) { return volume; @@ -260,7 +268,9 @@ public class SettingsValues { return -1.0f; } - public static int getCurrentVibrationDuration(SharedPreferences sp, Resources res) { + // Likewise + public static int getCurrentVibrationDuration(final SharedPreferences sp, + final Resources res) { final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1); if (ms >= 0) { return ms; -- cgit v1.2.3-83-g751a From 837b109f278d9e3be9b12e87dff4b3e6bdc97def Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 16:41:05 +0900 Subject: Reorder members in SettingsValues. Reorder so that they match the order in the preference xml file. Also add TODOs for missing raw variables. Change-Id: I06332c131a624d6c359512d75c808f3f7313fa91 --- .../com/android/inputmethod/latin/Settings.java | 37 ++++++++++------------ .../android/inputmethod/latin/SettingsValues.java | 28 +++++++++------- 2 files changed, 33 insertions(+), 32 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 4166e6266..8a9e0532f 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -58,42 +58,37 @@ public class Settings extends InputMethodSettingsActivity public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false; + // In the same order as xml/prefs.xml public static final String PREF_GENERAL_SETTINGS_KEY = "general_settings"; + public static final String PREF_SUBTYPES = "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"; public static final String PREF_KEY_PREVIEW_POPUP_ON = "popup_on"; - public static final String PREF_AUTO_CAP = "auto_cap"; public static final String PREF_SHOW_SETTINGS_KEY = "show_settings_key"; public static final String PREF_VOICE_SETTINGS_KEY = "voice_mode"; - public static final String PREF_INPUT_LANGUAGE = "input_language"; - public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; - public static final String PREF_SUBTYPES = "subtype_settings"; - - public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key"; public static final String PREF_CORRECTION_SETTINGS_KEY = "correction_settings"; - public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting"; + public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key"; public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; - public static final String PREF_DEBUG_SETTINGS = "debug_settings"; - - public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; - public static final String PREF_BIGRAM_PREDICTIONS = "bigram_prediction"; - + public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting"; public static final String PREF_MISC_SETTINGS_KEY = "misc_settings"; - + public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; + public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; - public static final String PREF_KEY_USE_CONTACTS_DICT = - "pref_key_use_contacts_dict"; - public static final String PREF_KEY_ENABLE_SPAN_INSERT = - "enable_span_insert"; - - public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; - + public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; + public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; + public static final String PREF_BIGRAM_PREDICTIONS = "bigram_prediction"; + public static final String PREF_KEY_ENABLE_SPAN_INSERT = "enable_span_insert"; public static final String PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS = "pref_vibration_duration_settings"; - public static final String PREF_KEYPRESS_SOUND_VOLUME = "pref_keypress_sound_volume"; + + public static final String PREF_INPUT_LANGUAGE = "input_language"; + public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; + public static final String PREF_DEBUG_SETTINGS = "debug_settings"; + // Dialog ids private static final int VOICE_INPUT_CONFIRM_DIALOG = 0; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 62cf4a38e..9c956d2a3 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -42,28 +42,34 @@ public class SettingsValues { private final String mSymbolsExcludedFromWordSeparators; public final CharSequence mHintToSaveText; - // From preferences: - public final boolean mSoundOn; // Sound setting private to Latin IME (see mSilentModeOn) + // From preferences, in the same order as xml/prefs.xml: + public final boolean mAutoCap; public final boolean mVibrateOn; + public final boolean mSoundOn; public final boolean mKeyPreviewPopupOn; - public final int mKeyPreviewPopupDismissDelay; - public final boolean mAutoCap; - public final boolean mAutoCorrectEnabled; - public final double mAutoCorrectionThreshold; + private final boolean mShowSettingsKey; + // TODO: add a member for the raw "voice_mode" setting + // TODO: add a member for the raw "auto_correction_threshold" setting + // TODO: add a member for the raw "show_suggestions_setting" setting + // TODO: add a member for the raw "usability_study_mode" setting + // TODO: add a member for the raw "pref_key_preview_popup_dismiss_delay" setting + public final boolean mUseContactsDict; // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary public final boolean mBigramSuggestionEnabled; // Prediction: use bigrams to predict the next word when there is no input for it yet public final boolean mBigramPredictionEnabled; - public final boolean mUseContactsDict; public final boolean mEnableSuggestionSpanInsertion; - - private final boolean mShowSettingsKey; - private final boolean mVoiceKeyEnabled; - private final boolean mVoiceKeyOnMain; + // TODO: add a member for the raw "pref_vibration_duration_settings" setting + // TODO: add a member for the raw "pref_keypress_sound_volume" setting // Deduced settings public final int mKeypressVibrationDuration; public final float mFxVolume; + public final int mKeyPreviewPopupDismissDelay; + public final boolean mAutoCorrectEnabled; + public final double mAutoCorrectionThreshold; + private final boolean mVoiceKeyEnabled; + private final boolean mVoiceKeyOnMain; public SettingsValues(final SharedPreferences prefs, final Context context, final String localeStr) { -- cgit v1.2.3-83-g751a From ba93dda8cea74c903a01374b9e54a0fd467a4cf1 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 17:58:51 +0900 Subject: Match constant names to option names Change-Id: I7586fa342d7a39412d656890f7b525139c45ea4a --- .../com/android/inputmethod/latin/Settings.java | 48 +++++++++++----------- .../android/inputmethod/latin/SettingsValues.java | 8 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 8a9e0532f..2a7f1d955 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -59,28 +59,28 @@ public class Settings extends InputMethodSettingsActivity public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false; // In the same order as xml/prefs.xml - public static final String PREF_GENERAL_SETTINGS_KEY = "general_settings"; - public static final String PREF_SUBTYPES = "subtype_settings"; + 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"; - public static final String PREF_KEY_PREVIEW_POPUP_ON = "popup_on"; + public static final String PREF_POPUP_ON = "popup_on"; public static final String PREF_SHOW_SETTINGS_KEY = "show_settings_key"; - public static final String PREF_VOICE_SETTINGS_KEY = "voice_mode"; - public static final String PREF_CORRECTION_SETTINGS_KEY = "correction_settings"; + public static final String PREF_VOICE_MODE = "voice_mode"; + public static final String PREF_CORRECTION_SETTINGS = "correction_settings"; public static final String PREF_CONFIGURE_DICTIONARIES_KEY = "configure_dictionaries_key"; public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting"; - public static final String PREF_MISC_SETTINGS_KEY = "misc_settings"; + public static final String PREF_MISC_SETTINGS = "misc_settings"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; - public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; + public static final String PREF_BIGRAM_SUGGESTION = "bigram_suggestion"; public static final String PREF_BIGRAM_PREDICTIONS = "bigram_prediction"; public static final String PREF_KEY_ENABLE_SPAN_INSERT = "enable_span_insert"; - public static final String PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS = + public static final String PREF_VIBRATION_DURATION_SETTINGS = "pref_vibration_duration_settings"; public static final String PREF_KEYPRESS_SOUND_VOLUME = "pref_keypress_sound_volume"; @@ -144,9 +144,9 @@ public class Settings extends InputMethodSettingsActivity final Context context = getActivityInternal(); addPreferencesFromResource(R.xml.prefs); - mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES); + mInputLanguageSelection = (PreferenceScreen) findPreference(PREF_SUBTYPES_SETTINGS); mInputLanguageSelection.setOnPreferenceClickListener(this); - mVoicePreference = (ListPreference) findPreference(PREF_VOICE_SETTINGS_KEY); + mVoicePreference = (ListPreference) findPreference(PREF_VOICE_MODE); mShowSettingsKeyPreference = (CheckBoxPreference) findPreference(PREF_SHOW_SETTINGS_KEY); mShowCorrectionSuggestionsPreference = (ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING); @@ -154,12 +154,12 @@ public class Settings extends InputMethodSettingsActivity prefs.registerOnSharedPreferenceChangeListener(this); mVoiceModeOff = getString(R.string.voice_mode_off); - mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) + mVoiceOn = !(prefs.getString(PREF_VOICE_MODE, mVoiceModeOff) .equals(mVoiceModeOff)); mAutoCorrectionThresholdPreference = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD); - mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); + mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTION); mBigramPrediction = (CheckBoxPreference) findPreference(PREF_BIGRAM_PREDICTIONS); mDebugSettingsPreference = findPreference(PREF_DEBUG_SETTINGS); if (mDebugSettingsPreference != null) { @@ -172,11 +172,11 @@ public class Settings extends InputMethodSettingsActivity ensureConsistencyOfAutoCorrectionSettings(); final PreferenceGroup generalSettings = - (PreferenceGroup) findPreference(PREF_GENERAL_SETTINGS_KEY); + (PreferenceGroup) findPreference(PREF_GENERAL_SETTINGS); final PreferenceGroup textCorrectionGroup = - (PreferenceGroup) findPreference(PREF_CORRECTION_SETTINGS_KEY); + (PreferenceGroup) findPreference(PREF_CORRECTION_SETTINGS); final PreferenceGroup miscSettings = - (PreferenceGroup) findPreference(PREF_MISC_SETTINGS_KEY); + (PreferenceGroup) findPreference(PREF_MISC_SETTINGS); if (!SettingsValues.isShowSettingsKeyOption(res)) { generalSettings.removePreference(mShowSettingsKeyPreference); @@ -193,13 +193,13 @@ public class Settings extends InputMethodSettingsActivity } if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { - generalSettings.removePreference(findPreference(PREF_SUBTYPES)); + generalSettings.removePreference(findPreference(PREF_SUBTYPES_SETTINGS)); } final boolean showPopupOption = res.getBoolean( R.bool.config_enable_show_popup_on_keypress_option); if (!showPopupOption) { - generalSettings.removePreference(findPreference(PREF_KEY_PREVIEW_POPUP_ON)); + generalSettings.removePreference(findPreference(PREF_POPUP_ON)); } final boolean showBigramSuggestionsOption = res.getBoolean( @@ -256,7 +256,7 @@ public class Settings extends InputMethodSettingsActivity } mKeypressVibrationDurationSettingsPref = - (PreferenceScreen) findPreference(PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS); + (PreferenceScreen) findPreference(PREF_VIBRATION_DURATION_SETTINGS); if (mKeypressVibrationDurationSettingsPref != null) { mKeypressVibrationDurationSettingsPref.setOnPreferenceClickListener( new OnPreferenceClickListener() { @@ -312,20 +312,20 @@ public class Settings extends InputMethodSettingsActivity public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { (new BackupManager(getActivityInternal())).dataChanged(); // If turning on voice input, show dialog - if (key.equals(PREF_VOICE_SETTINGS_KEY) && !mVoiceOn) { - if (!prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) + if (key.equals(PREF_VOICE_MODE) && !mVoiceOn) { + if (!prefs.getString(PREF_VOICE_MODE, mVoiceModeOff) .equals(mVoiceModeOff)) { showVoiceConfirmation(); } - } else if (key.equals(PREF_KEY_PREVIEW_POPUP_ON)) { + } else if (key.equals(PREF_POPUP_ON)) { final ListPreference popupDismissDelay = (ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); if (null != popupDismissDelay) { - popupDismissDelay.setEnabled(prefs.getBoolean(PREF_KEY_PREVIEW_POPUP_ON, true)); + popupDismissDelay.setEnabled(prefs.getBoolean(PREF_POPUP_ON, true)); } } ensureConsistencyOfAutoCorrectionSettings(); - mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) + mVoiceOn = !(prefs.getString(PREF_VOICE_MODE, mVoiceModeOff) .equals(mVoiceModeOff)); updateVoiceModeSummary(); updateShowCorrectionSuggestionsSummary(); @@ -467,7 +467,7 @@ public class Settings extends InputMethodSettingsActivity public void onClick(DialogInterface dialog, int whichButton) { final int ms = Integer.valueOf( mKeypressVibrationDurationSettingsTextView.getText().toString()); - sp.edit().putInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, ms).apply(); + sp.edit().putInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, ms).apply(); updateKeypressVibrationDurationSettingsSummary(sp, res); } }); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 9c956d2a3..adb6b3a1c 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -127,7 +127,7 @@ public class SettingsValues { : defaultShowSettingsKey; final String voiceModeMain = res.getString(R.string.voice_mode_main); final String voiceModeOff = res.getString(R.string.voice_mode_off); - final String voiceMode = prefs.getString(Settings.PREF_VOICE_SETTINGS_KEY, voiceModeMain); + final String voiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain); mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain); @@ -172,7 +172,7 @@ public class SettingsValues { final boolean showPopupOption = resources.getBoolean( R.bool.config_enable_show_popup_on_keypress_option); if (!showPopupOption) return resources.getBoolean(R.bool.config_default_popup_preview); - return sp.getBoolean(Settings.PREF_KEY_PREVIEW_POPUP_ON, + return sp.getBoolean(Settings.PREF_POPUP_ON, resources.getBoolean(R.bool.config_default_popup_preview)); } @@ -190,7 +190,7 @@ public class SettingsValues { if (!showBigramSuggestionsOption) { return autoCorrectEnabled; } - return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, resources.getBoolean( + return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTION, resources.getBoolean( R.bool.config_default_bigram_suggestions)); } @@ -277,7 +277,7 @@ public class SettingsValues { // Likewise public static int getCurrentVibrationDuration(final SharedPreferences sp, final Resources res) { - final int ms = sp.getInt(Settings.PREF_KEYPRESS_VIBRATION_DURATION_SETTINGS, -1); + final int ms = sp.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); if (ms >= 0) { return ms; } -- cgit v1.2.3-83-g751a From bab1f045f4856e987f9d8b7b952f3765303528a7 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 18:19:30 +0900 Subject: Straighten out members extracted from resources. Change-Id: I9b9602ec5b379b44b0f0663d4f065dbcf88fd352 --- .../android/inputmethod/latin/SettingsValues.java | 52 ++++++++++++---------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index adb6b3a1c..36c295e17 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -34,12 +34,12 @@ public class SettingsValues { // From resources: public final int mDelayUpdateOldSuggestions; - public final String mWordSeparators; public final String mMagicSpaceStrippers; public final String mMagicSpaceSwappers; public final String mSuggestPuncs; public final SuggestedWords mSuggestPuncList; private final String mSymbolsExcludedFromWordSeparators; + public final String mWordSeparators; public final CharSequence mHintToSaveText; // From preferences, in the same order as xml/prefs.xml: @@ -83,23 +83,16 @@ public class SettingsValues { } // Get the resources - mDelayUpdateOldSuggestions = res.getInteger( - R.integer.config_delay_update_old_suggestions); + mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions); mMagicSpaceStrippers = res.getString(R.string.magic_space_stripping_symbols); mMagicSpaceSwappers = res.getString(R.string.magic_space_swapping_symbols); - String wordSeparators = mMagicSpaceStrippers + mMagicSpaceSwappers - + res.getString(R.string.magic_space_promoting_symbols); - final String symbolsExcludedFromWordSeparators = - res.getString(R.string.symbols_excluded_from_word_separators); - for (int i = symbolsExcludedFromWordSeparators.length() - 1; i >= 0; --i) { - wordSeparators = wordSeparators.replace( - symbolsExcludedFromWordSeparators.substring(i, i + 1), ""); - } - mSymbolsExcludedFromWordSeparators = symbolsExcludedFromWordSeparators; - mWordSeparators = wordSeparators; mSuggestPuncs = res.getString(R.string.suggested_punctuations); // TODO: it would be nice not to recreate this each time we change the configuration mSuggestPuncList = createSuggestPuncList(mSuggestPuncs); + mSymbolsExcludedFromWordSeparators = + res.getString(R.string.symbols_excluded_from_word_separators); + mWordSeparators = createWordSeparators(mMagicSpaceStrippers, mMagicSpaceSwappers, + mSymbolsExcludedFromWordSeparators, res); mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); // Get the settings preferences @@ -137,6 +130,29 @@ public class SettingsValues { LocaleUtils.setSystemLocale(res, savedLocale); } + // Helper functions to create member values. + private static SuggestedWords createSuggestPuncList(final String puncs) { + SuggestedWords.Builder builder = new SuggestedWords.Builder(); + if (puncs != null) { + for (int i = 0; i < puncs.length(); i++) { + builder.addWord(puncs.subSequence(i, i + 1)); + } + } + return builder.setIsPunctuationSuggestions().build(); + } + + private static String createWordSeparators(final String magicSpaceStrippers, + final String magicSpaceSwappers, final String symbolsExcludedFromWordSeparators, + final Resources res) { + String wordSeparators = magicSpaceStrippers + magicSpaceSwappers + + res.getString(R.string.magic_space_promoting_symbols); + for (int i = symbolsExcludedFromWordSeparators.length() - 1; i >= 0; --i) { + wordSeparators = wordSeparators.replace( + symbolsExcludedFromWordSeparators.substring(i, i + 1), ""); + } + return wordSeparators; + } + public boolean isSuggestedPunctuation(int code) { return mSuggestPuncs.contains(String.valueOf((char)code)); } @@ -226,16 +242,6 @@ public class SettingsValues { return autoCorrectionThreshold; } - private static SuggestedWords createSuggestPuncList(final String puncs) { - SuggestedWords.Builder builder = new SuggestedWords.Builder(); - if (puncs != null) { - for (int i = 0; i < puncs.length(); i++) { - builder.addWord(puncs.subSequence(i, i + 1)); - } - } - return builder.setIsPunctuationSuggestions().build(); - } - public static boolean isShowSettingsKeyOption(final Resources resources) { return resources.getBoolean(R.bool.config_enable_show_settings_key_option); -- cgit v1.2.3-83-g751a From c40b807ca420123d90cd9479a453051f975b7629 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 18:54:07 +0900 Subject: Straighten out prefs reading code Change-Id: Ibf9113a8ef07ac720100ee32d2e5ef321e8ddd98 --- .../com/android/inputmethod/latin/Settings.java | 2 +- .../android/inputmethod/latin/SettingsValues.java | 49 +++++++++++++--------- 2 files changed, 31 insertions(+), 20 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 2a7f1d955..ac4f705ea 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -178,7 +178,7 @@ public class Settings extends InputMethodSettingsActivity final PreferenceGroup miscSettings = (PreferenceGroup) findPreference(PREF_MISC_SETTINGS); - if (!SettingsValues.isShowSettingsKeyOption(res)) { + if (!SettingsValues.isShowSettingsKeyOptionEnabled(res)) { generalSettings.removePreference(mShowSettingsKeyPreference); } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 36c295e17..d23abfeb9 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -96,28 +96,24 @@ public class SettingsValues { mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); // Get the settings preferences - final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator(); - mVibrateOn = hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, - res.getBoolean(R.bool.config_default_vibration_enabled)); + mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); + mVibrateOn = isVibrateOn(context, prefs, res); mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, res.getBoolean(R.bool.config_default_sound_enabled)); mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res); - mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); - mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); + mShowSettingsKey = isSettingsKeyShown(prefs, res); + mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); mBigramPredictionEnabled = mBigramSuggestionEnabled && isBigramPredictionEnabled(prefs, res); - mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); - mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mEnableSuggestionSpanInsertion = - prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true); - final boolean defaultShowSettingsKey = res.getBoolean( - R.bool.config_default_show_settings_key); - mShowSettingsKey = isShowSettingsKeyOption(res) - ? prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, defaultShowSettingsKey) - : defaultShowSettingsKey; + prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true); + + // Compute other readable settings + mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); + mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); final String voiceModeMain = res.getString(R.string.voice_mode_main); final String voiceModeOff = res.getString(R.string.voice_mode_off); final String voiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain); @@ -153,6 +149,26 @@ public class SettingsValues { return wordSeparators; } + private static boolean isSettingsKeyShown(final SharedPreferences prefs, final Resources res) { + final boolean defaultShowSettingsKey = res.getBoolean( + R.bool.config_default_show_settings_key); + return isShowSettingsKeyOptionEnabled(res) + ? prefs.getBoolean(Settings.PREF_SHOW_SETTINGS_KEY, defaultShowSettingsKey) + : defaultShowSettingsKey; + } + + public static boolean isShowSettingsKeyOptionEnabled(final Resources resources) { + // TODO: Read this once and for all into a public final member + return resources.getBoolean(R.bool.config_enable_show_settings_key_option); + } + + private static boolean isVibrateOn(final Context context, final SharedPreferences prefs, + final Resources res) { + final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator(); + return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, + res.getBoolean(R.bool.config_default_vibration_enabled)); + } + public boolean isSuggestedPunctuation(int code) { return mSuggestPuncs.contains(String.valueOf((char)code)); } @@ -242,16 +258,11 @@ public class SettingsValues { return autoCorrectionThreshold; } - public static boolean isShowSettingsKeyOption(final Resources resources) { - return resources.getBoolean(R.bool.config_enable_show_settings_key_option); - - } - public boolean isSettingsKeyEnabled() { return mShowSettingsKey; } - public boolean isVoiceKeyEnabled(EditorInfo editorInfo) { + public boolean isVoiceKeyEnabled(final EditorInfo editorInfo) { final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); final int inputType = (editorInfo != null) ? editorInfo.inputType : 0; return shortcutImeEnabled && mVoiceKeyEnabled -- cgit v1.2.3-83-g751a From 12f10e1585f1e9e1875661b6dc171c8a44d7ceb7 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 18:58:24 +0900 Subject: Read options in the declaration order Change-Id: I1a7c4d0bcaedad6d4045c36c79280c23234db5b3 --- java/src/com/android/inputmethod/latin/SettingsValues.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d23abfeb9..e1c2be5cd 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -112,6 +112,8 @@ public class SettingsValues { prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true); // Compute other readable settings + mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); + mFxVolume = getCurrentKeypressSoundVolume(prefs, res); mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); final String voiceModeMain = res.getString(R.string.voice_mode_main); @@ -120,9 +122,6 @@ public class SettingsValues { mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain); - mFxVolume = getCurrentKeypressSoundVolume(prefs, res); - mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); - LocaleUtils.setSystemLocale(res, savedLocale); } -- cgit v1.2.3-83-g751a From 85b063f97ef98fc4162526d754adfb6f288b42ff Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 19:03:55 +0900 Subject: Resolve TODOs: add members to store raw settings Change-Id: I481eadb6a73faf239e24d05b7e220fcb01194fa4 --- .../android/inputmethod/latin/SettingsValues.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index e1c2be5cd..90d611ceb 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -48,8 +48,8 @@ public class SettingsValues { public final boolean mSoundOn; public final boolean mKeyPreviewPopupOn; private final boolean mShowSettingsKey; - // TODO: add a member for the raw "voice_mode" setting - // TODO: add a member for the raw "auto_correction_threshold" setting + private final String mVoiceMode; + private final String mAutoCorrectionThresholdRawValue; // TODO: add a member for the raw "show_suggestions_setting" setting // TODO: add a member for the raw "usability_study_mode" setting // TODO: add a member for the raw "pref_key_preview_popup_dismiss_delay" setting @@ -102,6 +102,11 @@ public class SettingsValues { res.getBoolean(R.bool.config_default_sound_enabled)); mKeyPreviewPopupOn = isKeyPreviewPopupEnabled(prefs, res); mShowSettingsKey = isSettingsKeyShown(prefs, res); + final String voiceModeMain = res.getString(R.string.voice_mode_main); + final String voiceModeOff = res.getString(R.string.voice_mode_off); + mVoiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain); + mAutoCorrectionThresholdRawValue = prefs.getString(Settings.PREF_AUTO_CORRECTION_THRESHOLD, + res.getString(R.string.auto_correction_threshold_mode_index_modest)); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); mBigramSuggestionEnabled = mAutoCorrectEnabled @@ -115,12 +120,10 @@ public class SettingsValues { mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); mFxVolume = getCurrentKeypressSoundVolume(prefs, res); mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); - mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res); - final String voiceModeMain = res.getString(R.string.voice_mode_main); - final String voiceModeOff = res.getString(R.string.voice_mode_off); - final String voiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain); - mVoiceKeyEnabled = voiceMode != null && !voiceMode.equals(voiceModeOff); - mVoiceKeyOnMain = voiceMode != null && voiceMode.equals(voiceModeMain); + mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res, + mAutoCorrectionThresholdRawValue); + mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); + mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); LocaleUtils.setSystemLocale(res, savedLocale); } @@ -214,8 +217,8 @@ public class SettingsValues { Integer.toString(resources.getInteger(R.integer.config_delay_after_preview)))); } - private static boolean isBigramSuggestionEnabled(SharedPreferences sp, Resources resources, - boolean autoCorrectEnabled) { + private static boolean isBigramSuggestionEnabled(final SharedPreferences sp, + final Resources resources, final boolean autoCorrectEnabled) { final boolean showBigramSuggestionsOption = resources.getBoolean( R.bool.config_enable_bigram_suggestions_option); if (!showBigramSuggestionsOption) { @@ -225,17 +228,14 @@ public class SettingsValues { R.bool.config_default_bigram_suggestions)); } - private static boolean isBigramPredictionEnabled(SharedPreferences sp, - Resources resources) { + private static boolean isBigramPredictionEnabled(final SharedPreferences sp, + final Resources resources) { return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, resources.getBoolean( R.bool.config_default_bigram_prediction)); } - private static double getAutoCorrectionThreshold(SharedPreferences sp, - Resources resources) { - final String currentAutoCorrectionSetting = sp.getString( - Settings.PREF_AUTO_CORRECTION_THRESHOLD, - resources.getString(R.string.auto_correction_threshold_mode_index_modest)); + private static double getAutoCorrectionThreshold(final SharedPreferences sp, + final Resources resources, final String currentAutoCorrectionSetting) { final String[] autoCorrectionThresholdValues = resources.getStringArray( R.array.auto_correction_threshold_values); // When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off. -- cgit v1.2.3-83-g751a From 0fe3611bee5095e7bd0fff2d0fdf8d5a13379132 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 20:16:57 +0900 Subject: Resolve TODOs: add some members to store prefs Change-Id: Idf09cb5d801e8008eb63cbb5138058faeb7db136 --- .../com/android/inputmethod/latin/LatinIME.java | 5 ++-- .../android/inputmethod/latin/SettingsValues.java | 27 +++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index de273b56f..b39e1543b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -144,6 +144,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar */ private static final String SCHEME_PACKAGE = "package"; + // TODO: migrate this to SettingsValues private int mSuggestionVisibility; private static final int SUGGESTION_VISIBILILTY_SHOW_VALUE = R.string.prefs_suggestion_visibility_show_value; @@ -2389,9 +2390,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) { - final String suggestionVisiblityStr = prefs.getString( - Settings.PREF_SHOW_SUGGESTIONS_SETTING, - res.getString(R.string.prefs_suggestion_visibility_default_value)); + final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting; for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { if (suggestionVisiblityStr.equals(res.getString(visibility))) { mSuggestionVisibility = visibility; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 90d611ceb..343427a38 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -50,9 +50,9 @@ public class SettingsValues { private final boolean mShowSettingsKey; private final String mVoiceMode; private final String mAutoCorrectionThresholdRawValue; - // TODO: add a member for the raw "show_suggestions_setting" setting - // TODO: add a member for the raw "usability_study_mode" setting - // TODO: add a member for the raw "pref_key_preview_popup_dismiss_delay" setting + public final String mShowSuggestionsSetting; + private final boolean mUsabilityStudyMode; + private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary public final boolean mBigramSuggestionEnabled; @@ -107,8 +107,14 @@ public class SettingsValues { mVoiceMode = prefs.getString(Settings.PREF_VOICE_MODE, voiceModeMain); mAutoCorrectionThresholdRawValue = prefs.getString(Settings.PREF_AUTO_CORRECTION_THRESHOLD, res.getString(R.string.auto_correction_threshold_mode_index_modest)); + mShowSuggestionsSetting = prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING, + res.getString(R.string.prefs_suggestion_visibility_default_value)); + mUsabilityStudyMode = getUsabilityStudyMode(prefs, res); + mKeyPreviewPopupDismissDelayRawValue = prefs.getString( + Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, + Integer.toString(res.getInteger(R.integer.config_delay_after_preview))); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); - mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res); + mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res, mAutoCorrectionThresholdRawValue); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); mBigramPredictionEnabled = mBigramSuggestionEnabled @@ -191,10 +197,8 @@ public class SettingsValues { return mMagicSpaceSwappers.contains(String.valueOf((char)code)); } - private static boolean isAutoCorrectEnabled(SharedPreferences sp, Resources resources) { - final String currentAutoCorrectionSetting = sp.getString( - Settings.PREF_AUTO_CORRECTION_THRESHOLD, - resources.getString(R.string.auto_correction_threshold_mode_index_modest)); + private static boolean isAutoCorrectEnabled(final SharedPreferences sp, + final Resources resources, final String currentAutoCorrectionSetting) { final String autoCorrectionOff = resources.getString( R.string.auto_correction_threshold_mode_index_off); return !currentAutoCorrectionSetting.equals(autoCorrectionOff); @@ -213,6 +217,7 @@ public class SettingsValues { // Likewise public static int getKeyPreviewPopupDismissDelay(SharedPreferences sp, Resources resources) { + // TODO: use mKeyPreviewPopupDismissDelayRawValue instead of reading it again here. return Integer.parseInt(sp.getString(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, Integer.toString(resources.getInteger(R.integer.config_delay_after_preview)))); } @@ -307,4 +312,10 @@ public class SettingsValues { } return -1; } + + // Likewise + public static boolean getUsabilityStudyMode(final SharedPreferences prefs, + final Resources res) { + return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true); + } } -- cgit v1.2.3-83-g751a From 74671cf6c5c2fbe7cee72c2cd74e55168e3306aa Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 9 Dec 2011 20:26:28 +0900 Subject: Resolve TODOs: add members to hold preferences Change-Id: I34f6c76bf9318e1fbe8eb5ffab6772a98ff824e0 --- java/src/com/android/inputmethod/latin/SettingsValues.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 343427a38..a3fe15dc6 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -59,8 +59,8 @@ public class SettingsValues { // Prediction: use bigrams to predict the next word when there is no input for it yet public final boolean mBigramPredictionEnabled; public final boolean mEnableSuggestionSpanInsertion; - // TODO: add a member for the raw "pref_vibration_duration_settings" setting - // TODO: add a member for the raw "pref_keypress_sound_volume" setting + private final int mVibrationDurationSettingsRawValue; + private final float mKeypressSoundVolumeRawValue; // Deduced settings public final int mKeypressVibrationDuration; @@ -120,7 +120,10 @@ public class SettingsValues { mBigramPredictionEnabled = mBigramSuggestionEnabled && isBigramPredictionEnabled(prefs, res); mEnableSuggestionSpanInsertion = - prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true); + prefs.getBoolean(Settings.PREF_KEY_ENABLE_SPAN_INSERT, true); + mVibrationDurationSettingsRawValue = + prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); + mKeypressSoundVolumeRawValue = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); // Compute other readable settings mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); @@ -280,6 +283,7 @@ public class SettingsValues { // Accessed from the settings interface, hence public public static float getCurrentKeypressSoundVolume(final SharedPreferences sp, final Resources res) { + // TODO: use mVibrationDurationSettingsRawValue instead of reading it again here final float volume = sp.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); if (volume >= 0) { return volume; @@ -298,6 +302,7 @@ public class SettingsValues { // Likewise public static int getCurrentVibrationDuration(final SharedPreferences sp, final Resources res) { + // TODO: use mKeypressVibrationDuration instead of reading it again here final int ms = sp.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); if (ms >= 0) { return ms; @@ -316,6 +321,7 @@ public class SettingsValues { // Likewise public static boolean getUsabilityStudyMode(final SharedPreferences prefs, final Resources res) { + // TODO: use mUsabilityStudyMode instead of reading it again here return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true); } } -- cgit v1.2.3-83-g751a From d567b230b055cb69186acf1ce0a1c4e1c7b61508 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 12 Dec 2011 19:52:17 +0900 Subject: Move a settings var to the settings class Change-Id: I1331ad6dec3a9d64a77e314f8a1f4c29282df31b --- java/src/com/android/inputmethod/latin/LatinIME.java | 3 +-- java/src/com/android/inputmethod/latin/SettingsValues.java | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 711afdfdd..d4aab409f 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1086,8 +1086,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public boolean onEvaluateFullscreenMode() { - return super.onEvaluateFullscreenMode() - && mResources.getBoolean(R.bool.config_use_fullscreen_mode); + return super.onEvaluateFullscreenMode() && mSettingsValues.mUseFullScreenMode; } @Override diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index a3fe15dc6..0ad1c1529 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -41,6 +41,7 @@ public class SettingsValues { private final String mSymbolsExcludedFromWordSeparators; public final String mWordSeparators; public final CharSequence mHintToSaveText; + public final boolean mUseFullScreenMode; // From preferences, in the same order as xml/prefs.xml: public final boolean mAutoCap; @@ -94,6 +95,7 @@ public class SettingsValues { mWordSeparators = createWordSeparators(mMagicSpaceStrippers, mMagicSpaceSwappers, mSymbolsExcludedFromWordSeparators, res); mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); + mUseFullScreenMode = res.getBoolean(R.bool.config_use_fullscreen_mode); // Get the settings preferences mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); -- cgit v1.2.3-83-g751a From 2ac5988f84b5c38d313951a3d7faddebf5f25e04 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 15 Dec 2011 19:32:11 +0900 Subject: Cleanup unused variables and parameters Change-Id: Iad756a7a775c93f3344c6962e7b3456ef8339490 --- .../accessibility/AccessibilityUtils.java | 13 ++++++------- .../AccessibleInputMethodServiceProxy.java | 9 +++------ .../accessibility/AccessibleKeyboardViewProxy.java | 16 +++++++--------- .../accessibility/FlickGestureDetector.java | 1 - .../accessibility/KeyCodeDescriptionMapper.java | 7 +++---- .../inputmethod/keyboard/LatinKeyboardView.java | 8 +++----- .../src/com/android/inputmethod/latin/LatinIME.java | 6 +++--- .../android/inputmethod/latin/SettingsValues.java | 21 ++++++++++++--------- .../android/inputmethod/latin/SuggestionsView.java | 7 ------- .../inputmethod/latin/UserUnigramDictionary.java | 6 +++--- 10 files changed, 40 insertions(+), 54 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java index 1836f27b3..9caed00c9 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.os.SystemClock; @@ -55,15 +54,15 @@ public class AccessibilityUtils { */ private static final boolean ENABLE_ACCESSIBILITY = true; - public static void init(InputMethodService inputMethod, SharedPreferences prefs) { + public static void init(InputMethodService inputMethod) { if (!ENABLE_ACCESSIBILITY) return; // These only need to be initialized if the kill switch is off. - sInstance.initInternal(inputMethod, prefs); - KeyCodeDescriptionMapper.init(inputMethod, prefs); - AccessibleInputMethodServiceProxy.init(inputMethod, prefs); - AccessibleKeyboardViewProxy.init(inputMethod, prefs); + sInstance.initInternal(inputMethod); + KeyCodeDescriptionMapper.init(); + AccessibleInputMethodServiceProxy.init(inputMethod); + AccessibleKeyboardViewProxy.init(inputMethod); } public static AccessibilityUtils getInstance() { @@ -74,7 +73,7 @@ public class AccessibilityUtils { // This class is not publicly instantiable. } - private void initInternal(Context context, SharedPreferences prefs) { + private void initInternal(Context context) { mContext = context; mAccessibilityManager = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java index 4ab9cb898..d834dd10b 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleInputMethodServiceProxy.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.os.Looper; @@ -82,8 +81,8 @@ public class AccessibleInputMethodServiceProxy implements AccessibleKeyboardActi } } - public static void init(InputMethodService inputMethod, SharedPreferences prefs) { - sInstance.initInternal(inputMethod, prefs); + public static void init(InputMethodService inputMethod) { + sInstance.initInternal(inputMethod); } public static AccessibleInputMethodServiceProxy getInstance() { @@ -94,7 +93,7 @@ public class AccessibleInputMethodServiceProxy implements AccessibleKeyboardActi // Not publicly instantiable. } - private void initInternal(InputMethodService inputMethod, SharedPreferences prefs) { + private void initInternal(InputMethodService inputMethod) { mInputMethod = inputMethod; mVibrator = (Vibrator) inputMethod.getSystemService(Context.VIBRATOR_SERVICE); mAudioManager = (AudioManager) inputMethod.getSystemService(Context.AUDIO_SERVICE); @@ -125,8 +124,6 @@ public class AccessibleInputMethodServiceProxy implements AccessibleKeyboardActi */ @Override public void onFlickGesture(int direction) { - final int keyEventCode; - switch (direction) { case FlickGestureDetector.FLICK_LEFT: sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT); diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 4cb2f20b9..9141daaee 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.Paint; import android.inputmethodservice.InputMethodService; @@ -43,8 +42,8 @@ public class AccessibleKeyboardViewProxy { private Key mLastHoverKey = null; - public static void init(InputMethodService inputMethod, SharedPreferences prefs) { - sInstance.initInternal(inputMethod, prefs); + public static void init(InputMethodService inputMethod) { + sInstance.initInternal(inputMethod); sInstance.mListener = AccessibleInputMethodServiceProxy.getInstance(); } @@ -60,7 +59,7 @@ public class AccessibleKeyboardViewProxy { // Not publicly instantiable. } - private void initInternal(InputMethodService inputMethod, SharedPreferences prefs) { + private void initInternal(InputMethodService inputMethod) { final Paint paint = new Paint(); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(14.0f); @@ -71,8 +70,7 @@ public class AccessibleKeyboardViewProxy { mGestureDetector = new KeyboardFlickGestureDetector(inputMethod); } - public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event, - PointerTracker tracker) { + public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (mView == null) { Log.e(TAG, "No keyboard view set!"); return false; @@ -132,9 +130,9 @@ public class AccessibleKeyboardViewProxy { final Key key = tracker.getKeyOn(x, y); if (key != mLastHoverKey) { - fireKeyHoverEvent(tracker, mLastHoverKey, false); + fireKeyHoverEvent(mLastHoverKey, false); mLastHoverKey = key; - fireKeyHoverEvent(tracker, mLastHoverKey, true); + fireKeyHoverEvent(mLastHoverKey, true); } return true; @@ -143,7 +141,7 @@ public class AccessibleKeyboardViewProxy { return false; } - private void fireKeyHoverEvent(PointerTracker tracker, Key key, boolean entering) { + private void fireKeyHoverEvent(Key key, boolean entering) { if (mListener == null) { Log.e(TAG, "No accessible keyboard action listener set!"); return; diff --git a/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java b/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java index 9d99e3131..db12f76ad 100644 --- a/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java +++ b/java/src/com/android/inputmethod/accessibility/FlickGestureDetector.java @@ -126,7 +126,6 @@ public abstract class FlickGestureDetector { } final float distanceSquare = calculateDistanceSquare(mCachedHoverEnter, event); - final long timeout = event.getEventTime() - mCachedHoverEnter.getEventTime(); switch (event.getAction()) { case MotionEventCompatUtils.ACTION_HOVER_MOVE: diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java index e01262c20..3d5ab05c3 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java +++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java @@ -17,7 +17,6 @@ package com.android.inputmethod.accessibility; import android.content.Context; -import android.content.SharedPreferences; import android.text.TextUtils; import com.android.inputmethod.keyboard.Key; @@ -45,8 +44,8 @@ public class KeyCodeDescriptionMapper { // Map of shift-locked key codes to spoken description resource IDs private final HashMap mShiftLockedKeyCodeMap; - public static void init(Context context, SharedPreferences prefs) { - sInstance.initInternal(context, prefs); + public static void init() { + sInstance.initInternal(); } public static KeyCodeDescriptionMapper getInstance() { @@ -60,7 +59,7 @@ public class KeyCodeDescriptionMapper { mShiftLockedKeyCodeMap = new HashMap(); } - private void initInternal(Context context, SharedPreferences prefs) { + private void initInternal() { // Manual label substitutions for key labels with no string resource mKeyLabelMap.put(":-)", R.string.spoken_description_smiley); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index e56f2ea84..7f2c6c501 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -206,7 +206,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke // Detected a double tap on shift key. If we are in the ignoring double tap // mode, it means we have already turned off caps lock in // {@link KeyboardSwitcher#onReleaseShift} . - onDoubleTapShiftKey(tracker, mKeyTimerHandler.isIgnoringDoubleTap()); + onDoubleTapShiftKey(mKeyTimerHandler.isIgnoringDoubleTap()); return true; } // Otherwise these events should not be handled as double tap. @@ -342,8 +342,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke return onLongPress(parentKey, tracker); } - private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker, - final boolean ignore) { + private void onDoubleTapShiftKey(final boolean ignore) { // When shift key is double tapped, the first tap is correctly processed as usual tap. And // the second tap is treated as this double tap event, so that we need not mark tracker // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue. @@ -633,9 +632,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - final PointerTracker tracker = getPointerTracker(0); return AccessibleKeyboardViewProxy.getInstance().dispatchPopulateAccessibilityEvent( - event, tracker) || super.dispatchPopulateAccessibilityEvent(event); + event) || super.dispatchPopulateAccessibilityEvent(event); } return super.dispatchPopulateAccessibilityEvent(event); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 98fea1b5b..943361c73 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -489,7 +489,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar InputMethodManagerCompatWrapper.init(this); SubtypeSwitcher.init(this); KeyboardSwitcher.init(this, prefs); - AccessibilityUtils.init(this, prefs); + AccessibilityUtils.init(this); super.onCreate(); @@ -758,7 +758,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar loadSettings(); updateCorrectionMode(); - updateSuggestionVisibility(mPrefs, mResources); + updateSuggestionVisibility(mResources); if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); @@ -2415,7 +2415,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode; } - private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) { + private void updateSuggestionVisibility(final Resources res) { final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting; for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { if (suggestionVisiblityStr.equals(res.getString(visibility))) { diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 0ad1c1529..651d90ca4 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -52,7 +52,9 @@ public class SettingsValues { private final String mVoiceMode; private final String mAutoCorrectionThresholdRawValue; public final String mShowSuggestionsSetting; + @SuppressWarnings("unused") // TODO: Use this private final boolean mUsabilityStudyMode; + @SuppressWarnings("unused") // TODO: Use this private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary @@ -60,7 +62,9 @@ public class SettingsValues { // Prediction: use bigrams to predict the next word when there is no input for it yet public final boolean mBigramPredictionEnabled; public final boolean mEnableSuggestionSpanInsertion; + @SuppressWarnings("unused") // TODO: Use this private final int mVibrationDurationSettingsRawValue; + @SuppressWarnings("unused") // TODO: Use this private final float mKeypressSoundVolumeRawValue; // Deduced settings @@ -111,12 +115,12 @@ public class SettingsValues { res.getString(R.string.auto_correction_threshold_mode_index_modest)); mShowSuggestionsSetting = prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING, res.getString(R.string.prefs_suggestion_visibility_default_value)); - mUsabilityStudyMode = getUsabilityStudyMode(prefs, res); + mUsabilityStudyMode = getUsabilityStudyMode(prefs); mKeyPreviewPopupDismissDelayRawValue = prefs.getString( Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, Integer.toString(res.getInteger(R.integer.config_delay_after_preview))); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); - mAutoCorrectEnabled = isAutoCorrectEnabled(prefs, res, mAutoCorrectionThresholdRawValue); + mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); mBigramPredictionEnabled = mBigramSuggestionEnabled @@ -131,7 +135,7 @@ public class SettingsValues { mKeypressVibrationDuration = getCurrentVibrationDuration(prefs, res); mFxVolume = getCurrentKeypressSoundVolume(prefs, res); mKeyPreviewPopupDismissDelay = getKeyPreviewPopupDismissDelay(prefs, res); - mAutoCorrectionThreshold = getAutoCorrectionThreshold(prefs, res, + mAutoCorrectionThreshold = getAutoCorrectionThreshold(res, mAutoCorrectionThresholdRawValue); mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); @@ -202,8 +206,8 @@ public class SettingsValues { return mMagicSpaceSwappers.contains(String.valueOf((char)code)); } - private static boolean isAutoCorrectEnabled(final SharedPreferences sp, - final Resources resources, final String currentAutoCorrectionSetting) { + private static boolean isAutoCorrectEnabled(final Resources resources, + final String currentAutoCorrectionSetting) { final String autoCorrectionOff = resources.getString( R.string.auto_correction_threshold_mode_index_off); return !currentAutoCorrectionSetting.equals(autoCorrectionOff); @@ -244,8 +248,8 @@ public class SettingsValues { R.bool.config_default_bigram_prediction)); } - private static double getAutoCorrectionThreshold(final SharedPreferences sp, - final Resources resources, final String currentAutoCorrectionSetting) { + private static double getAutoCorrectionThreshold(final Resources resources, + final String currentAutoCorrectionSetting) { final String[] autoCorrectionThresholdValues = resources.getStringArray( R.array.auto_correction_threshold_values); // When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off. @@ -321,8 +325,7 @@ public class SettingsValues { } // Likewise - public static boolean getUsabilityStudyMode(final SharedPreferences prefs, - final Resources res) { + public static boolean getUsabilityStudyMode(final SharedPreferences prefs) { // TODO: use mUsabilityStudyMode instead of reading it again here return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true); } diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 10f5ec9db..883bb57f0 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -100,8 +100,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, private static class UiHandler extends StaticInnerHandlerWrapper { private static final int MSG_HIDE_PREVIEW = 0; - private static final long DELAY_HIDE_PREVIEW = 1300; - public UiHandler(SuggestionsView outerInstance) { super(outerInstance); } @@ -116,11 +114,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } } - public void postHidePreview() { - cancelHidePreview(); - sendMessageDelayed(obtainMessage(MSG_HIDE_PREVIEW), DELAY_HIDE_PREVIEW); - } - public void cancelHidePreview() { removeMessages(MSG_HIDE_PREVIEW); } diff --git a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java index 6af20c754..a7f57ae46 100644 --- a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java @@ -172,7 +172,7 @@ public class UserUnigramDictionary extends ExpandableDictionary { // Nothing pending? Return if (mPendingWrites.isEmpty()) return; // Create a background thread to write the pending entries - new UpdateDbTask(getContext(), sOpenHelper, mPendingWrites, mLocale).execute(); + new UpdateDbTask(sOpenHelper, mPendingWrites, mLocale).execute(); // Create a new map for writing new entries into while the old one is written to db mPendingWrites = new HashMap(); } @@ -227,8 +227,8 @@ public class UserUnigramDictionary extends ExpandableDictionary { private final DatabaseHelper mDbHelper; private final String mLocale; - public UpdateDbTask(@SuppressWarnings("unused") Context context, DatabaseHelper openHelper, - HashMap pendingWrites, String locale) { + public UpdateDbTask(DatabaseHelper openHelper, HashMap pendingWrites, + String locale) { mMap = pendingWrites; mLocale = locale; mDbHelper = openHelper; -- cgit v1.2.3-83-g751a From 852630ba34195660f6c2401659dcdc951f2200a4 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 12 Jan 2012 12:00:01 +0900 Subject: Add a sanity check Check if any character is both a magic space swapper and a magic space stripper for the current language, and throw an exception if found. Since this is expensive, it's done only in debug mode. Change-Id: Ibd166db87c91495b76878ea0e4f420a62c7bb276 --- java/src/com/android/inputmethod/latin/SettingsValues.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 651d90ca4..83b27f7fe 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -91,6 +91,14 @@ public class SettingsValues { mDelayUpdateOldSuggestions = res.getInteger(R.integer.config_delay_update_old_suggestions); mMagicSpaceStrippers = res.getString(R.string.magic_space_stripping_symbols); mMagicSpaceSwappers = res.getString(R.string.magic_space_swapping_symbols); + if (LatinImeLogger.sDBG) { + for (int i = 0; i < mMagicSpaceStrippers.length(); ++i) { + if (isMagicSpaceSwapper(mMagicSpaceStrippers.codePointAt(i))) { + throw new RuntimeException("Char code " + mMagicSpaceStrippers.codePointAt(i) + + " is both a magic space swapper and stripper."); + } + } + } mSuggestPuncs = res.getString(R.string.suggested_punctuations); // TODO: it would be nice not to recreate this each time we change the configuration mSuggestPuncList = createSuggestPuncList(mSuggestPuncs); -- cgit v1.2.3-83-g751a From 9751a626ec9b2e771afa5b3757e8f8498a328683 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 16 Jan 2012 11:32:49 +0900 Subject: Don't cache resource value that depends on orientation Bug: 5794655 Change-Id: Ib324366c772e20bb54aba63c2f4540dc0f9de515 --- java/src/com/android/inputmethod/latin/LatinIME.java | 5 ++++- java/src/com/android/inputmethod/latin/SettingsValues.java | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 59de798d8..e60f55060 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1019,7 +1019,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public boolean onEvaluateFullscreenMode() { - return super.onEvaluateFullscreenMode() && mSettingsValues.mUseFullScreenMode; + // Reread resource value here, because this method is called by framework anytime as needed. + final boolean isFullscreenModeAllowed = + mSettingsValues.isFullscreenModeAllowed(getResources()); + return super.onEvaluateFullscreenMode() && isFullscreenModeAllowed; } @Override diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 83b27f7fe..0ae28d3fc 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -41,7 +41,6 @@ public class SettingsValues { private final String mSymbolsExcludedFromWordSeparators; public final String mWordSeparators; public final CharSequence mHintToSaveText; - public final boolean mUseFullScreenMode; // From preferences, in the same order as xml/prefs.xml: public final boolean mAutoCap; @@ -107,7 +106,6 @@ public class SettingsValues { mWordSeparators = createWordSeparators(mMagicSpaceStrippers, mMagicSpaceSwappers, mSymbolsExcludedFromWordSeparators, res); mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); - mUseFullScreenMode = res.getBoolean(R.bool.config_use_fullscreen_mode); // Get the settings preferences mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); @@ -294,6 +292,10 @@ public class SettingsValues { return mVoiceKeyOnMain; } + public boolean isFullscreenModeAllowed(Resources res) { + return res.getBoolean(R.bool.config_use_fullscreen_mode); + } + // Accessed from the settings interface, hence public public static float getCurrentKeypressSoundVolume(final SharedPreferences sp, final Resources res) { -- cgit v1.2.3-83-g751a From 160f01211d169d64102205e80e9ac8d46c7d674b Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 25 Jan 2012 20:14:39 +0900 Subject: Get rid of Resource reference from KeyboardView, LatinKeyboardView and PointerTracker This change introduces the following attributes. * KeyboardView - keyPreviewLingerTimeout * LatinKeboardView - keyHysteresisDistance - touchNoiseThresholdTime - touchNoiseThresholdDistance - slidingKeyInputEnable - keyRepeatStartTimeout - keyRepeatInterval - longPressKeyTimeout - longPressShiftKeyTimeout - longPressSpaceKeyTimeout - ignoreSpecialKeyTimeout - showMiniKeyboardAtTouchedPoint Change-Id: I25159a87289b12447e20031add173523070e9b03 --- java/res/values-sw600dp/config.xml | 9 ++- java/res/values-sw768dp/config.xml | 9 ++- java/res/values/attrs.xml | 24 +++++++ java/res/values/config.xml | 35 ++++++---- java/res/values/dimens.xml | 2 - java/res/values/styles.xml | 13 ++++ .../android/inputmethod/keyboard/KeyboardView.java | 49 ++----------- .../inputmethod/keyboard/LatinKeyboardView.java | 81 +++++++++++++++++----- .../inputmethod/keyboard/PointerTracker.java | 53 +++++--------- .../com/android/inputmethod/latin/Settings.java | 2 +- .../android/inputmethod/latin/SettingsValues.java | 5 +- 11 files changed, 162 insertions(+), 120 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values-sw600dp/config.xml b/java/res/values-sw600dp/config.xml index 1dd93121d..35da3009f 100644 --- a/java/res/values-sw600dp/config.xml +++ b/java/res/values-sw600dp/config.xml @@ -24,14 +24,11 @@ false false false - false false false true false - - true 1200 @@ -39,4 +36,10 @@ 5 5 + + false + + true diff --git a/java/res/values-sw768dp/config.xml b/java/res/values-sw768dp/config.xml index 06553a7c9..ddeadaf0f 100644 --- a/java/res/values-sw768dp/config.xml +++ b/java/res/values-sw768dp/config.xml @@ -24,19 +24,22 @@ false false false - false false false true false - - true 0 5 5 + + false + + true + + @@ -130,6 +132,28 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/res/values/config.xml b/java/res/values/config.xml index 5e6804364..32041df74 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -27,7 +27,6 @@ true true - true true true @@ -39,8 +38,6 @@ false false true - - false 1200 100 @@ -48,26 +45,38 @@ 100 50 50 - 0 - 70 0 100 - 400 - 50 32 16 + 1100 + + 5 + 5 + + 70 + + 0.05in + 40 + 2.0mm + true + 400 + 50 400 1200 @integer/config_long_press_key_timeout - 40 - 1100 700 - 2.0mm - - 5 - 5 + + false + diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index e46ff7718..95c4e5b8b 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -96,6 +96,4 @@ 27dip 3 36 - - 0.05in diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index c4e39e357..69637d75a 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -59,11 +59,24 @@ @dimen/key_preview_offset @dimen/key_preview_height @fraction/key_preview_text_ratio + @integer/config_key_preview_linger_timeout @layout/mini_keyboard @dimen/keyboard_vertical_correction #BB000000 2.75 0.5 + + @dimen/config_key_hysteresis_distance + @integer/config_touch_noise_threshold_time + @dimen/config_touch_noise_threshold_distance + @bool/config_sliding_key_input_enabled + @integer/config_key_repeat_start_timeout + @integer/config_key_repeat_interval + @integer/config_long_press_key_timeout + @integer/config_long_press_shift_key_timeout + @integer/config_long_press_space_key_timeout + @integer/config_ignore_special_key_timeout + @bool/config_show_mini_keyboard_at_touched_point diff --git a/java/res/values/keyboard-icons-ics.xml b/java/res/values/keyboard-icons-ics.xml index f68be5f1e..5fba0253d 100644 --- a/java/res/values/keyboard-icons-ics.xml +++ b/java/res/values/keyboard-icons-ics.xml @@ -33,5 +33,6 @@ @drawable/sym_keyboard_shift_locked_holo @drawable/sym_keyboard_voice_off_holo @drawable/sym_keyboard_feedback_tab + @drawable/sym_keyboard_language_switch diff --git a/java/res/values/keyboard-icons-white.xml b/java/res/values/keyboard-icons-white.xml index 35197a1c0..837b1a37a 100644 --- a/java/res/values/keyboard-icons-white.xml +++ b/java/res/values/keyboard-icons-white.xml @@ -31,5 +31,6 @@ @drawable/sym_keyboard_voice_off_holo @drawable/sym_keyboard_feedback_tab + @drawable/sym_keyboard_language_switch diff --git a/java/res/values/keycodes.xml b/java/res/values/keycodes.xml index 7f9e4bda4..d3d9b6324 100644 --- a/java/res/values/keycodes.xml +++ b/java/res/values/keycodes.xml @@ -32,5 +32,6 @@ -7 -8 -9 - -10 + -10 + -11 diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index d8a3a689e..f2c02d014 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -64,6 +64,13 @@ Options for experts + + Switch to other input methods + + Language switch key covers other input methods too + + Suppress language switch key + Key popup dismiss delay diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index 76eacb673..f153a7d96 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -117,10 +117,10 @@ latin:altCode="@integer/key_space" latin:parentStyle="f1MoreKeysStyle" /> + + - + + + + + + + + + + getEnabledInputMethodSubtypeList( InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) { if (!SUBTYPE_SUPPORTED) { @@ -221,6 +234,14 @@ public class InputMethodManagerCompatWrapper { return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToLastInputMethod, token); } + public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) { + if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) { + return true; + } + return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token, + onlyCurrentIme); + } + public List getEnabledInputMethodList() { if (mImm == null) return null; List imis = new ArrayList(); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index c6cdf7986..5660d1942 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -99,8 +99,9 @@ public class Keyboard { public static final int CODE_ACTION_ENTER = -7; public static final int CODE_ACTION_NEXT = -8; public static final int CODE_ACTION_PREVIOUS = -9; + public static final int CODE_LANGUAGE_SWITCH = -10; // Code value representing the code is not specified. - public static final int CODE_UNSPECIFIED = -10; + public static final int CODE_UNSPECIFIED = -11; public final KeyboardId mId; public final int mThemeId; @@ -1076,6 +1077,9 @@ public class Keyboard { R.styleable.Keyboard_Case_shortcutKeyEnabled, id.mShortcutKeyEnabled); final boolean hasShortcutKeyMatched = matchBoolean(a, R.styleable.Keyboard_Case_hasShortcutKey, id.mHasShortcutKey); + final boolean languageSwitchKeyEnabledMatched = matchBoolean(a, + R.styleable.Keyboard_Case_languageSwitchKeyEnabled, + id.mLanguageSwitchKeyEnabled); final boolean isMultiLineMatched = matchBoolean(a, R.styleable.Keyboard_Case_isMultiLine, id.isMultiLine()); final boolean imeActionMatched = matchInteger(a, @@ -1089,11 +1093,12 @@ public class Keyboard { final boolean selected = keyboardSetElementMatched && modeMatched && navigateNextMatched && navigatePreviousMatched && passwordInputMatched && clobberSettingsKeyMatched && shortcutKeyEnabledMatched - && hasShortcutKeyMatched && isMultiLineMatched && imeActionMatched - && localeCodeMatched && languageCodeMatched && countryCodeMatched; + && hasShortcutKeyMatched && languageSwitchKeyEnabledMatched + && isMultiLineMatched && imeActionMatched && localeCodeMatched + && languageCodeMatched && countryCodeMatched; if (DEBUG) { - startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, + startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE, textAttr(a.getString(R.styleable.Keyboard_Case_keyboardSetElement), "keyboardSetElement"), textAttr(a.getString(R.styleable.Keyboard_Case_mode), "mode"), @@ -1111,6 +1116,8 @@ public class Keyboard { "shortcutKeyEnabled"), booleanAttr(a, R.styleable.Keyboard_Case_hasShortcutKey, "hasShortcutKey"), + booleanAttr(a, R.styleable.Keyboard_Case_languageSwitchKeyEnabled, + "languageSwitchKeyEnabled"), booleanAttr(a, R.styleable.Keyboard_Case_isMultiLine, "isMultiLine"), textAttr(a.getString(R.styleable.Keyboard_Case_localeCode), diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index f5752962e..6703b9301 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -62,13 +62,14 @@ public class KeyboardId { public final boolean mClobberSettingsKey; public final boolean mShortcutKeyEnabled; public final boolean mHasShortcutKey; + public final boolean mLanguageSwitchKeyEnabled; public final String mCustomActionLabel; private final int mHashCode; public KeyboardId(int elementId, Locale locale, int orientation, int width, int mode, EditorInfo editorInfo, boolean clobberSettingsKey, boolean shortcutKeyEnabled, - boolean hasShortcutKey) { + boolean hasShortcutKey, boolean languageSwitchKeyEnabled) { this.mLocale = locale; this.mOrientation = orientation; this.mWidth = width; @@ -78,6 +79,7 @@ public class KeyboardId { this.mClobberSettingsKey = clobberSettingsKey; this.mShortcutKeyEnabled = shortcutKeyEnabled; this.mHasShortcutKey = hasShortcutKey; + this.mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled; this.mCustomActionLabel = (editorInfo.actionLabel != null) ? editorInfo.actionLabel.toString() : null; @@ -94,6 +96,7 @@ public class KeyboardId { id.mClobberSettingsKey, id.mShortcutKeyEnabled, id.mHasShortcutKey, + id.mLanguageSwitchKeyEnabled, id.isMultiLine(), id.imeAction(), id.mCustomActionLabel, @@ -114,6 +117,7 @@ public class KeyboardId { && other.mClobberSettingsKey == this.mClobberSettingsKey && other.mShortcutKeyEnabled == this.mShortcutKeyEnabled && other.mHasShortcutKey == this.mHasShortcutKey + && other.mLanguageSwitchKeyEnabled == this.mLanguageSwitchKeyEnabled && other.isMultiLine() == this.isMultiLine() && other.imeAction() == this.imeAction() && TextUtils.equals(other.mCustomActionLabel, this.mCustomActionLabel) @@ -172,7 +176,7 @@ public class KeyboardId { @Override public String toString() { - return String.format("[%s %s %s%d %s %s %s%s%s%s%s%s%s]", + return String.format("[%s %s %s%d %s %s %s%s%s%s%s%s%s%s]", elementIdToName(mElementId), mLocale, (mOrientation == 1 ? "port" : "land"), mWidth, @@ -184,6 +188,7 @@ public class KeyboardId { (passwordInput() ? " passwordInput" : ""), (mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""), (mHasShortcutKey ? " hasShortcutKey" : ""), + (mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""), (isMultiLine() ? "isMultiLine" : "") ); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index ee882edc0..731aaf7c5 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -101,6 +101,7 @@ public class KeyboardSet { boolean mVoiceKeyEnabled; boolean mVoiceKeyOnMain; boolean mNoSettingsKey; + boolean mLanguageSwitchKeyEnabled; Locale mLocale; int mOrientation; int mWidth; @@ -196,7 +197,7 @@ public class KeyboardSet { && (isSymbols != params.mVoiceKeyOnMain); return new KeyboardId(keyboardSetElementId, params.mLocale, params.mOrientation, params.mWidth, params.mMode, params.mEditorInfo, params.mNoSettingsKey, - params.mVoiceKeyEnabled, hasShortcutKey); + params.mVoiceKeyEnabled, hasShortcutKey, params.mLanguageSwitchKeyEnabled); } public static class Builder { @@ -239,7 +240,8 @@ public class KeyboardSet { return this; } - public Builder setOptions(boolean voiceKeyEnabled, boolean voiceKeyOnMain) { + public Builder setOptions(boolean voiceKeyEnabled, boolean voiceKeyOnMain, + boolean languageSwitchKeyEnabled) { @SuppressWarnings("deprecation") final boolean deprecatedNoMicrophone = Utils.inPrivateImeOptions( null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, mEditorInfo); @@ -248,6 +250,7 @@ public class KeyboardSet { || deprecatedNoMicrophone; mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone; mParams.mVoiceKeyOnMain = voiceKeyOnMain; + mParams.mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled; return this; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index e1c6f2604..ac8dd1b95 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -133,7 +133,8 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, LatinIME.SUBTYPE_EXTRA_VALUE_SUPPORT_TOUCH_POSITION_CORRECTION)); builder.setOptions( settingsValues.isVoiceKeyEnabled(editorInfo), - settingsValues.isVoiceKeyOnMain()); + settingsValues.isVoiceKeyOnMain(), + settingsValues.isLanguageSwitchKeyEnabled(mThemeContext)); mKeyboardSet = builder.build(); try { mState.onLoadKeyboard(mResources.getString(R.string.layout_switch_back_symbols)); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 78c371ff0..afc4932e9 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -489,7 +489,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke KeyboardSwitcher.getInstance().hapticAndAudioFeedback(primaryCode); return true; } - if (primaryCode == Keyboard.CODE_SPACE) { + if (primaryCode == Keyboard.CODE_SPACE || primaryCode == Keyboard.CODE_LANGUAGE_SWITCH) { // Long pressing the space key invokes IME switcher dialog. if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { tracker.onLongPressed(); @@ -782,6 +782,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke && Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { drawKeyPopupHint(key, canvas, paint, params); } + } else if (key.mCode == Keyboard.CODE_LANGUAGE_SWITCH) { + super.onDrawKeyTopVisuals(key, canvas, paint, params); + if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + drawKeyPopupHint(key, canvas, paint, params); + } } else { super.onDrawKeyTopVisuals(key, canvas, paint, params); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index 7c8fd1225..ca711ec7d 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -31,7 +31,7 @@ public class KeyboardIconsSet { // The value should be aligned with the enum value of Key.keyIcon. public static final int ICON_UNDEFINED = 0; - private static final int NUM_ICONS = 13; + private static final int NUM_ICONS = 14; private final Drawable[] mIcons = new Drawable[NUM_ICONS + 1]; @@ -57,6 +57,7 @@ public class KeyboardIconsSet { addIconIdMap(11, "shiftKeyShifted", R.styleable.Keyboard_iconShiftKeyShifted); addIconIdMap(12, "disabledShortcurKey", R.styleable.Keyboard_iconDisabledShortcutKey); addIconIdMap(13, "previewTabKey", R.styleable.Keyboard_iconPreviewTabKey); + addIconIdMap(14, "languageSwitchKey", R.styleable.Keyboard_iconLanguageSwitchKey); } private static void addIconIdMap(int iconId, String name, int attrId) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 2bcd947f1..cb22b4935 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -29,6 +29,7 @@ import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.net.ConnectivityManager; import android.os.Debug; +import android.os.IBinder; import android.os.Message; import android.os.SystemClock; import android.preference.PreferenceActivity; @@ -55,6 +56,7 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.compat.InputConnectionCompatUtils; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; +import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; @@ -196,6 +198,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private KeyboardSwitcher mKeyboardSwitcher; private SubtypeSwitcher mSubtypeSwitcher; private VoiceProxy mVoiceProxy; + private boolean mShouldSwitchToLastSubtype = true; private UserDictionary mUserDictionary; private UserBigramDictionary mUserBigramDictionary; @@ -1263,6 +1266,25 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } + private void handleLanguageSwitchKey() { + final boolean includesOtherImes = !mSettingsValues.mIncludesOtherImesInLanguageSwitchList; + final IBinder token = getWindow().getWindow().getAttributes().token; + if (mShouldSwitchToLastSubtype) { + final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype(); + final boolean lastSubtypeBelongsToThisIme = Utils.checkIfSubtypeBelongsToThisIme( + this, lastSubtype); + if ((includesOtherImes || lastSubtypeBelongsToThisIme) + && mImm.switchToLastInputMethod(token)) { + mShouldSwitchToLastSubtype = false; + } else { + mImm.switchToNextInputMethod(token, !includesOtherImes); + mShouldSwitchToLastSubtype = true; + } + } else { + mImm.switchToNextInputMethod(token, !includesOtherImes); + } + } + private void sendKeyCodePoint(int code) { // TODO: Remove this special handling of digit letters. // For backward compatibility. See {@link InputMethodService#sendKeyChar(char)}. @@ -1306,6 +1328,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar handleBackspace(spaceState); mDeleteCount++; mExpectingUpdateSelection = true; + mShouldSwitchToLastSubtype = true; LatinImeLogger.logOnDelete(); break; case Keyboard.CODE_SHIFT: @@ -1327,6 +1350,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_ACTION_PREVIOUS: EditorInfoCompatUtils.performEditorActionPrevious(getCurrentInputConnection()); break; + case Keyboard.CODE_LANGUAGE_SWITCH: + handleLanguageSwitchKey(); + break; default: mSpaceState = SPACE_STATE_NONE; if (mSettingsValues.isWordSeparator(primaryCode)) { @@ -1335,6 +1361,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar handleCharacter(primaryCode, x, y, spaceState); } mExpectingUpdateSelection = true; + mShouldSwitchToLastSubtype = true; break; } switcher.onCodeInput(primaryCode); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 3029057be..305cef22d 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -43,7 +43,6 @@ import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; import com.android.inputmethod.compat.CompatUtils; -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.deprecated.VoiceProxy; @@ -73,6 +72,10 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_MISC_SETTINGS = "misc_settings"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; + public static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = + "pref_suppress_language_switch_key"; + public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST = + "pref_include_other_imes_in_language_switch_list"; public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; @@ -204,6 +207,11 @@ public class Settings extends InputMethodSettingsActivity } } + final CheckBoxPreference includeOtherImesInLanguageSwitchList = + (CheckBoxPreference)findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST); + includeOtherImesInLanguageSwitchList.setEnabled( + !SettingsValues.isLanguageSwitchKeySupressed(prefs)); + mKeyPreviewPopupDismissDelay = (ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); final String[] entries = new String[] { @@ -316,6 +324,12 @@ public class Settings extends InputMethodSettingsActivity if (null != popupDismissDelay) { popupDismissDelay.setEnabled(prefs.getBoolean(PREF_POPUP_ON, true)); } + } else if (key.equals(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) { + final CheckBoxPreference includeOtherImesInLanguageSwicthList = + (CheckBoxPreference)findPreference( + PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST); + includeOtherImesInLanguageSwicthList.setEnabled( + !SettingsValues.isLanguageSwitchKeySupressed(prefs)); } ensureConsistencyOfAutoCorrectionSettings(); mVoiceOn = !(prefs.getString(PREF_VOICE_MODE, mVoiceModeOff) diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 6d65a74c8..69e45f619 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -23,11 +23,14 @@ import android.os.Build; import android.util.Log; import android.view.inputmethod.EditorInfo; +import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Locale; public class SettingsValues { @@ -55,6 +58,8 @@ public class SettingsValues { public final String mShowSuggestionsSetting; @SuppressWarnings("unused") // TODO: Use this private final boolean mUsabilityStudyMode; + public final boolean mIncludesOtherImesInLanguageSwitchList; + public final boolean mIsLanguageSwitchKeySuppressed; @SuppressWarnings("unused") // TODO: Use this private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; @@ -127,6 +132,9 @@ public class SettingsValues { mShowSuggestionsSetting = prefs.getString(Settings.PREF_SHOW_SUGGESTIONS_SETTING, res.getString(R.string.prefs_suggestion_visibility_default_value)); mUsabilityStudyMode = getUsabilityStudyMode(prefs); + mIncludesOtherImesInLanguageSwitchList = prefs.getBoolean( + Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false); + mIsLanguageSwitchKeySuppressed = isLanguageSwitchKeySupressed(prefs); mKeyPreviewPopupDismissDelayRawValue = prefs.getString( Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, Integer.toString(res.getInteger(R.integer.config_key_preview_linger_timeout))); @@ -309,6 +317,22 @@ public class SettingsValues { return mVoiceKeyOnMain; } + public static boolean isLanguageSwitchKeySupressed(SharedPreferences sp) { + return sp.getBoolean(Settings.PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, false); + } + + public boolean isLanguageSwitchKeyEnabled(Context context) { + if (mIsLanguageSwitchKeySuppressed) { + return false; + } + if (mIncludesOtherImesInLanguageSwitchList) { + return Utils.hasMultipleEnabledIMEsOrSubtypes(/* include aux subtypes */false); + } else { + return Utils.hasMultipleEnabledSubtypesInThisIme( + context, /* include aux subtypes */false); + } + } + public boolean isFullscreenModeAllowed(Resources res) { return res.getBoolean(R.bool.config_use_fullscreen_mode); } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 33d4b877e..a8679e07a 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -52,6 +52,7 @@ import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -117,16 +118,51 @@ public class Utils { } } + // TODO: Move InputMethodSubtype related utility methods to its own utility class. + // TODO: Cache my InputMethodInfo and/or InputMethodSubtype list. + public static boolean checkIfSubtypeBelongsToThisIme(Context context, + InputMethodSubtypeCompatWrapper ims) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( + context.getPackageName()); + final List subtypes = + imm.getEnabledInputMethodSubtypeList(myImi, true); + for (final InputMethodSubtypeCompatWrapper subtype : subtypes) { + if (subtype.equals(ims)) { + return true; + } + } + return false; + } + public static boolean hasMultipleEnabledIMEsOrSubtypes( final boolean shouldIncludeAuxiliarySubtypes) { final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); if (imm == null) return false; + final List enabledImis = imm.getEnabledInputMethodList(); + return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); + } + + public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( + context.getPackageName()); + final List imiList = Collections.singletonList(myImi); + return Utils.hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList); + } + + private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes, + List imiList) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; // Number of the filtered IMEs int filteredImisCount = 0; - for (InputMethodInfoCompatWrapper imi : enabledImis) { + for (InputMethodInfoCompatWrapper imi : imiList) { // We can return true immediately after we find two or more filtered IMEs. if (filteredImisCount > 1) return true; final List subtypes = @@ -564,6 +600,7 @@ public class Utils { } } + // TODO: Move this method to KeyboardSet class. public static int getKeyboardMode(EditorInfo editorInfo) { if (editorInfo == null) return KeyboardId.MODE_TEXT; -- cgit v1.2.3-83-g751a From cc8c8b99bd0463f5977dea82f5e2379ea1dd4e73 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 8 Mar 2012 17:07:02 +0900 Subject: Split Utils class to StringUtils, SubtypeUtils, and JniUtils Change-Id: I09e91675fe7d573dad8c933ad513b21d7e409144 --- .../compat/InputMethodManagerCompatWrapper.java | 7 +- .../android/inputmethod/deprecated/VoiceProxy.java | 6 +- .../languageswitcher/InputLanguageSelection.java | 24 +- .../deprecated/voice/RecognitionView.java | 10 +- java/src/com/android/inputmethod/keyboard/Key.java | 10 +- .../android/inputmethod/keyboard/KeyboardSet.java | 52 ++- .../android/inputmethod/keyboard/KeyboardView.java | 4 +- .../inputmethod/keyboard/LatinKeyboardView.java | 13 +- .../inputmethod/keyboard/MoreKeysKeyboard.java | 4 +- .../inputmethod/keyboard/ProximityInfo.java | 4 +- .../keyboard/internal/KeySpecParser.java | 12 +- .../inputmethod/latin/BinaryDictionary.java | 2 +- .../inputmethod/latin/DictionaryFactory.java | 14 +- .../com/android/inputmethod/latin/JniUtils.java | 41 +++ .../com/android/inputmethod/latin/LatinIME.java | 23 +- .../com/android/inputmethod/latin/Settings.java | 2 +- .../android/inputmethod/latin/SettingsValues.java | 4 +- .../com/android/inputmethod/latin/StringUtils.java | 198 ++++++++++ .../android/inputmethod/latin/SubtypeSwitcher.java | 2 +- .../android/inputmethod/latin/SubtypeUtils.java | 135 +++++++ .../src/com/android/inputmethod/latin/Suggest.java | 50 ++- java/src/com/android/inputmethod/latin/Utils.java | 398 +-------------------- .../spellcheck/AndroidSpellCheckerService.java | 10 +- 23 files changed, 551 insertions(+), 474 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/JniUtils.java create mode 100644 java/src/com/android/inputmethod/latin/StringUtils.java create mode 100644 java/src/com/android/inputmethod/latin/SubtypeUtils.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index 9dd0a599d..bf5f20158 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -32,7 +32,7 @@ import android.view.inputmethod.InputMethodManager; import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.SubtypeUtils; import java.lang.reflect.Method; import java.util.ArrayList; @@ -163,7 +163,7 @@ public class InputMethodManagerCompatWrapper { private InputMethodInfoCompatWrapper getLatinImeInputMethodInfo() { if (TextUtils.isEmpty(mLatinImePackageName)) return null; - return Utils.getInputMethodInfo(mLatinImePackageName); + return SubtypeUtils.getInputMethodInfo(mLatinImePackageName); } private static InputMethodSubtypeCompatWrapper getLastResortSubtype(String mode) { @@ -260,7 +260,8 @@ public class InputMethodManagerCompatWrapper { // The code below are based on {@link InputMethodManager#showInputMethodMenuInternal}. - final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo(mLatinImePackageName); + final InputMethodInfoCompatWrapper myImi = SubtypeUtils.getInputMethodInfo( + mLatinImePackageName); final List myImsList = getEnabledInputMethodSubtypeList( myImi, true); final InputMethodSubtypeCompatWrapper currentIms = getCurrentInputMethodSubtype(); diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index c1c6d31cd..87d1c118b 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -61,8 +61,8 @@ import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.Utils; import java.util.ArrayList; @@ -662,9 +662,9 @@ public class VoiceProxy implements VoiceInput.UiListener { private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo editorInfo) { @SuppressWarnings("deprecation") - final boolean noMic = Utils.inPrivateImeOptions(null, + final boolean noMic = StringUtils.inPrivateImeOptions(null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo) - || Utils.inPrivateImeOptions(mService.getPackageName(), + || StringUtils.inPrivateImeOptions(mService.getPackageName(), LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo); return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic && SpeechRecognizer.isRecognitionAvailable(mService); diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index e75e14861..421ee6529 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -16,16 +16,6 @@ package com.android.inputmethod.deprecated.languageswitcher; -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.keyboard.KeyboardSet; -import com.android.inputmethod.latin.DictionaryFactory; -import com.android.inputmethod.latin.LocaleUtils; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.Utils; - -import org.xmlpull.v1.XmlPullParserException; - import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Resources; @@ -37,6 +27,16 @@ import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.Pair; +import com.android.inputmethod.compat.SharedPreferencesCompat; +import com.android.inputmethod.keyboard.KeyboardSet; +import com.android.inputmethod.latin.DictionaryFactory; +import com.android.inputmethod.latin.LocaleUtils; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Settings; +import com.android.inputmethod.latin.StringUtils; + +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; import java.text.Collator; import java.util.ArrayList; @@ -237,12 +237,12 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new LocaleEntry(Utils.getFullDisplayName(l, false), l); + new LocaleEntry(StringUtils.getFullDisplayName(l, false), l); } else { if (s.equals("zz_ZZ")) { // ignore this locale } else { - final String displayName = Utils.getFullDisplayName(l, false); + final String displayName = StringUtils.getFullDisplayName(l, false); preprocess[finalSize++] = new LocaleEntry(displayName, l); } } diff --git a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java index 71d15dc3d..ff8b1abce 100644 --- a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java @@ -16,10 +16,6 @@ package com.android.inputmethod.deprecated.voice; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.Utils; - import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; @@ -39,6 +35,10 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StringUtils; +import com.android.inputmethod.latin.SubtypeSwitcher; + import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -222,7 +222,7 @@ public class RecognitionView { Locale locale = SubtypeSwitcher.getInstance().getInputLocale(); mLanguage.setVisibility(View.VISIBLE); - mLanguage.setText(Utils.getFullDisplayName(locale, true)); + mLanguage.setText(StringUtils.getFullDisplayName(locale, true)); mPopupLayout.setBackgroundDrawable(mListeningBorder); break; diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index f3923834b..6b4de184f 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -30,7 +30,7 @@ import com.android.inputmethod.keyboard.internal.KeyStyles; import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.XmlParseUtils; import org.xmlpull.v1.XmlPullParser; @@ -293,7 +293,7 @@ public class Key { // Choose the first letter of the label as primary code if not specified. if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText) && !TextUtils.isEmpty(mLabel)) { - if (Utils.codePointCount(mLabel) == 1) { + if (StringUtils.codePointCount(mLabel) == 1) { // Use the first letter of the hint label if shiftedLetterActivated flag is // specified. if (hasShiftedLetterHint() && isShiftedLetterActivated() @@ -309,7 +309,7 @@ public class Key { mCode = Keyboard.CODE_OUTPUT_TEXT; } } else if (code == Keyboard.CODE_UNSPECIFIED && outputText != null) { - if (Utils.codePointCount(outputText) == 1) { + if (StringUtils.codePointCount(outputText) == 1) { mCode = outputText.codePointAt(0); outputText = null; } else { @@ -336,7 +336,7 @@ public class Key { if (!Keyboard.isLetterCode(code) || preserveCase) return code; final String text = new String(new int[] { code } , 0, 1); final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id); - return Utils.codePointCount(casedText) == 1 + return StringUtils.codePointCount(casedText) == 1 ? casedText.codePointAt(0) : Keyboard.CODE_UNSPECIFIED; } @@ -484,7 +484,7 @@ public class Key { } public int selectTextSize(int letter, int largeLetter, int label, int hintLabel) { - if (Utils.codePointCount(mLabel) > 1 + if (StringUtils.codePointCount(mLabel) > 1 && (mLabelFlags & (LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO | LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO)) == 0) { return label; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 731aaf7c5..5ac6d03a8 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -21,16 +21,18 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; +import android.text.InputType; import android.util.Log; import android.util.Xml; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.EditorInfoCompatUtils; +import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.XmlParseUtils; import org.xmlpull.v1.XmlPullParser; @@ -215,9 +217,9 @@ public class KeyboardSet { mEditorInfo = editorInfo; final Params params = mParams; - params.mMode = Utils.getKeyboardMode(editorInfo); + params.mMode = getKeyboardMode(editorInfo); params.mEditorInfo = (editorInfo != null) ? editorInfo : EMPTY_EDITOR_INFO; - params.mNoSettingsKey = Utils.inPrivateImeOptions( + params.mNoSettingsKey = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, mEditorInfo); } @@ -230,7 +232,7 @@ public class KeyboardSet { // TODO: Use InputMethodSubtype object as argument. public Builder setSubtype(Locale inputLocale, boolean asciiCapable, boolean touchPositionCorrectionEnabled) { - final boolean deprecatedForceAscii = Utils.inPrivateImeOptions( + final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii( mParams.mEditorInfo.imeOptions) @@ -243,9 +245,9 @@ public class KeyboardSet { public Builder setOptions(boolean voiceKeyEnabled, boolean voiceKeyOnMain, boolean languageSwitchKeyEnabled) { @SuppressWarnings("deprecation") - final boolean deprecatedNoMicrophone = Utils.inPrivateImeOptions( + final boolean deprecatedNoMicrophone = StringUtils.inPrivateImeOptions( null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, mEditorInfo); - final boolean noMicrophone = Utils.inPrivateImeOptions( + final boolean noMicrophone = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_NO_MICROPHONE, mEditorInfo) || deprecatedNoMicrophone; mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone; @@ -337,6 +339,44 @@ public class KeyboardSet { a.recycle(); } } + + private static int getKeyboardMode(EditorInfo editorInfo) { + if (editorInfo == null) + return KeyboardId.MODE_TEXT; + + final int inputType = editorInfo.inputType; + final int variation = inputType & InputType.TYPE_MASK_VARIATION; + + switch (inputType & InputType.TYPE_MASK_CLASS) { + case InputType.TYPE_CLASS_NUMBER: + return KeyboardId.MODE_NUMBER; + case InputType.TYPE_CLASS_DATETIME: + switch (variation) { + case InputType.TYPE_DATETIME_VARIATION_DATE: + return KeyboardId.MODE_DATE; + case InputType.TYPE_DATETIME_VARIATION_TIME: + return KeyboardId.MODE_TIME; + default: // InputType.TYPE_DATETIME_VARIATION_NORMAL + return KeyboardId.MODE_DATETIME; + } + case InputType.TYPE_CLASS_PHONE: + return KeyboardId.MODE_PHONE; + case InputType.TYPE_CLASS_TEXT: + if (InputTypeCompatUtils.isEmailVariation(variation)) { + return KeyboardId.MODE_EMAIL; + } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { + return KeyboardId.MODE_URL; + } else if (variation == InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE) { + return KeyboardId.MODE_IM; + } else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) { + return KeyboardId.MODE_TEXT; + } else { + return KeyboardId.MODE_TEXT; + } + default: + return KeyboardId.MODE_TEXT; + } + } } public static String parseKeyboardLocale(Resources res, int resId) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 78e0ee230..decd73d45 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -41,7 +41,7 @@ import com.android.inputmethod.compat.FrameLayoutCompatUtils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import java.util.HashMap; @@ -853,7 +853,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { if (key.mLabel != null) { // TODO Should take care of temporaryShiftLabel here. previewText.setCompoundDrawables(null, null, null, null); - if (Utils.codePointCount(key.mLabel) > 1) { + if (StringUtils.codePointCount(key.mLabel) > 1) { previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mKeyLetterSize); previewText.setTypeface(Typeface.DEFAULT_BOLD); } else { diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index afc4932e9..0a0307500 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -46,6 +46,8 @@ import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.StringUtils; +import com.android.inputmethod.latin.SubtypeUtils; import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; @@ -779,12 +781,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke // Whether space key needs to show the "..." popup hint for special purposes if (mIsSpacebarTriggeringPopupByLongPress - && Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + && SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes( + true /* include aux subtypes */)) { drawKeyPopupHint(key, canvas, paint, params); } } else if (key.mCode == Keyboard.CODE_LANGUAGE_SWITCH) { super.onDrawKeyTopVisuals(key, canvas, paint, params); - if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { drawKeyPopupHint(key, canvas, paint, params); } } else { @@ -810,7 +813,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke paint.setTextAlign(Align.CENTER); paint.setTypeface(Typeface.DEFAULT); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = Utils.getFullDisplayName(locale, true); + String language = StringUtils.getFullDisplayName(locale, true); int textWidth = getTextWidth(paint, language, origTextSize); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(width / textWidth, 1.0f); @@ -822,7 +825,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final boolean useShortName; if (useMiddleName) { - language = Utils.getMiddleDisplayLanguage(locale); + language = StringUtils.getMiddleDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize); textSize = origTextSize * Math.min(width / textWidth, 1.0f); useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) @@ -832,7 +835,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } if (useShortName) { - language = Utils.getShortDisplayLanguage(locale); + language = StringUtils.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize); textSize = origTextSize * Math.min(width / textWidth, 1.0f); } diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java index 9f735cff7..904a81de4 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -22,7 +22,7 @@ import android.graphics.drawable.Drawable; import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; public class MoreKeysKeyboard extends Keyboard { private final int mDefaultKeyCoordX; @@ -301,7 +301,7 @@ public class MoreKeysKeyboard extends Keyboard { for (String moreKeySpec : parentKey.mMoreKeys) { final String label = KeySpecParser.getLabel(moreKeySpec); // If the label is single letter, minKeyWidth is enough to hold the label. - if (label != null && Utils.codePointCount(label) > 1) { + if (label != null && StringUtils.codePointCount(label) > 1) { if (paint == null) { paint = new Paint(); paint.setAntiAlias(true); diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index f96f71e8a..582509324 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -19,7 +19,7 @@ package com.android.inputmethod.keyboard; import android.graphics.Rect; import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.JniUtils; import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo; import java.util.Arrays; @@ -81,7 +81,7 @@ public class ProximityInfo { private long mNativeProximityInfo; static { - Utils.loadNativeLibrary(); + JniUtils.loadNativeLibrary(); } private native long setProximityInfoNative(int maxProximityCharsSize, int displayWidth, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index e3fea3dce..0aba813b2 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -22,7 +22,7 @@ import android.text.TextUtils; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import java.util.ArrayList; import java.util.Arrays; @@ -150,7 +150,7 @@ public class KeySpecParser { } final String outputText = getOutputTextInternal(moreKeySpec); if (outputText != null) { - if (Utils.codePointCount(outputText) == 1) { + if (StringUtils.codePointCount(outputText) == 1) { // If output text is one code point, it should be treated as a code. // See {@link #getCode(Resources, String)}. return null; @@ -165,7 +165,7 @@ public class KeySpecParser { throw new KeySpecParserError("Empty label: " + moreKeySpec); } // Code is automatically generated for one letter label. See {@link getCode()}. - return (Utils.codePointCount(label) == 1) ? null : label; + return (StringUtils.codePointCount(label) == 1) ? null : label; } public static int getCode(Resources res, String moreKeySpec) { @@ -184,14 +184,14 @@ public class KeySpecParser { if (outputText != null) { // If output text is one code point, it should be treated as a code. // See {@link #getOutputText(String)}. - if (Utils.codePointCount(outputText) == 1) { + if (StringUtils.codePointCount(outputText) == 1) { return outputText.codePointAt(0); } return Keyboard.CODE_OUTPUT_TEXT; } final String label = getLabel(moreKeySpec); // Code is automatically generated for one letter label. - if (Utils.codePointCount(label) == 1) { + if (StringUtils.codePointCount(label) == 1) { return label.codePointAt(0); } return Keyboard.CODE_OUTPUT_TEXT; @@ -393,7 +393,7 @@ public class KeySpecParser { if (size == 0) { return null; } - if (Utils.codePointCount(text) == 1) { + if (StringUtils.codePointCount(text) == 1) { return text.codePointAt(0) == COMMA ? null : new String[] { text }; } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 90ced6028..31ff4e7b4 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -104,7 +104,7 @@ public class BinaryDictionary extends Dictionary { } static { - Utils.loadNativeLibrary(); + JniUtils.loadNativeLibrary(); } private native long openNative(String sourceDir, long dictOffset, long dictSize, diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 1607f86a8..7a81f7bd5 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -164,7 +164,7 @@ public class DictionaryFactory { final Resources res = context.getResources(); final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale); - final int resourceId = Utils.getMainDictionaryResourceId(res); + final int resourceId = getMainDictionaryResourceId(res); final AssetFileDescriptor afd = res.openRawResourceFd(resourceId); final boolean hasDictionary = isFullDictionary(afd); try { @@ -182,7 +182,7 @@ public class DictionaryFactory { final Resources res = context.getResources(); final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale); - final int resourceId = Utils.getMainDictionaryResourceId(res); + final int resourceId = getMainDictionaryResourceId(res); final AssetFileDescriptor afd = res.openRawResourceFd(resourceId); final Long size = (afd != null && afd.getLength() > PLACEHOLDER_LENGTH) ? afd.getLength() @@ -209,4 +209,14 @@ public class DictionaryFactory { protected static boolean isFullDictionary(final AssetFileDescriptor afd) { return (afd != null && afd.getLength() > PLACEHOLDER_LENGTH); } + + /** + * Returns a main dictionary resource id + * @return main dictionary resource id + */ + public static int getMainDictionaryResourceId(Resources res) { + final String MAIN_DIC_NAME = "main"; + String packageName = LatinIME.class.getPackage().getName(); + return res.getIdentifier(MAIN_DIC_NAME, "raw", packageName); + } } diff --git a/java/src/com/android/inputmethod/latin/JniUtils.java b/java/src/com/android/inputmethod/latin/JniUtils.java new file mode 100644 index 000000000..4808b867a --- /dev/null +++ b/java/src/com/android/inputmethod/latin/JniUtils.java @@ -0,0 +1,41 @@ +/* + * 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.util.Log; + +import com.android.inputmethod.latin.define.JniLibName; + +public class JniUtils { + private static final String TAG = JniUtils.class.getSimpleName(); + + private JniUtils() { + // This utility class is not publicly instantiable. + } + + public static void loadNativeLibrary() { + try { + System.loadLibrary(JniLibName.JNI_LIB_NAME); + } catch (UnsatisfiedLinkError ule) { + Log.e(TAG, "Could not load native library " + JniLibName.JNI_LIB_NAME); + if (LatinImeLogger.sDBG) { + throw new RuntimeException( + "Could not load native library " + JniLibName.JNI_LIB_NAME); + } + } + } +} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 1858db949..c16a34fac 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -44,8 +44,8 @@ import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewParent; import android.view.ViewGroup.LayoutParams; +import android.view.ViewParent; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; @@ -576,7 +576,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar oldContactsDictionary = null; } - int mainDicResId = Utils.getMainDictionaryResourceId(res); + int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(res); mSuggest = new Suggest(this, mainDicResId, keyboardLocale); if (mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); @@ -636,7 +636,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar /* package private */ void resetSuggestMainDict() { final String localeStr = mSubtypeSwitcher.getInputLocaleStr(); final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr); - int mainDicResId = Utils.getMainDictionaryResourceId(mResources); + int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(mResources); mSuggest.resetMainDict(this, mainDicResId, keyboardLocale); } @@ -745,12 +745,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar + String.format("inputType=0x%08x imeOptions=0x%08x", editorInfo.inputType, editorInfo.imeOptions)); } - if (Utils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { + if (StringUtils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead"); } - if (Utils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { + if (StringUtils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); @@ -1207,7 +1207,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic == null) return false; final CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 - && Utils.canBeFollowedByPeriod(lastThree.charAt(0)) + && StringUtils.canBeFollowedByPeriod(lastThree.charAt(0)) && lastThree.charAt(1) == Keyboard.CODE_SPACE && lastThree.charAt(2) == Keyboard.CODE_SPACE && mHandler.isAcceptingDoubleSpaces()) { @@ -1247,7 +1247,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (isShowingOptionDialog()) return; if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { showSubtypeSelectorAndSettings(); - } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(false /* exclude aux subtypes */)) { + } else if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes( + false /* exclude aux subtypes */)) { showOptionsMenu(); } else { launchSettings(); @@ -1263,7 +1264,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (isShowingOptionDialog()) return false; switch (requestCode) { case CODE_SHOW_INPUT_METHOD_PICKER: - if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { mImm.showInputMethodPicker(); return true; } @@ -1295,7 +1296,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final IBinder token = getWindow().getWindow().getAttributes().token; if (mShouldSwitchToLastSubtype) { final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype(); - final boolean lastSubtypeBelongsToThisIme = Utils.checkIfSubtypeBelongsToThisIme( + final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme( this, lastSubtype); if ((includesOtherImes || lastSubtypeBelongsToThisIme) && mImm.switchToLastInputMethod(token)) { @@ -1884,7 +1885,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); } } - if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { + if (Suggest.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { builder.setShouldBlockAutoCorrectionBySafetyNet(); } showSuggestions(builder.build(), typedWord); @@ -2486,7 +2487,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar switch (position) { case 0: Intent intent = CompatUtils.getInputLanguageSelectionIntent( - Utils.getInputMethodId(getPackageName()), + SubtypeUtils.getInputMethodId(getPackageName()), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 305cef22d..72391f31e 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -343,7 +343,7 @@ public class Settings extends InputMethodSettingsActivity @Override public boolean onPreferenceClick(Preference pref) { if (pref == mInputLanguageSelection) { - final String imeId = Utils.getInputMethodId( + final String imeId = SubtypeUtils.getInputMethodId( getActivityInternal().getApplicationInfo().packageName); startActivity(CompatUtils.getInputLanguageSelectionIntent(imeId, 0)); return true; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 69e45f619..abd1dc692 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -326,9 +326,9 @@ public class SettingsValues { return false; } if (mIncludesOtherImesInLanguageSwitchList) { - return Utils.hasMultipleEnabledIMEsOrSubtypes(/* include aux subtypes */false); + return SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(/* include aux subtypes */false); } else { - return Utils.hasMultipleEnabledSubtypesInThisIme( + return SubtypeUtils.hasMultipleEnabledSubtypesInThisIme( context, /* include aux subtypes */false); } } diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java new file mode 100644 index 000000000..81c3b4edf --- /dev/null +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -0,0 +1,198 @@ +/* + * 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.TextUtils; +import android.view.inputmethod.EditorInfo; + +import com.android.inputmethod.keyboard.Keyboard; + +import java.util.ArrayList; +import java.util.Locale; + +public class StringUtils { + private StringUtils() { + // This utility class is not publicly instantiable. + } + + public static boolean canBeFollowedByPeriod(final int codePoint) { + // TODO: Check again whether there really ain't a better way to check this. + // TODO: This should probably be language-dependant... + return Character.isLetterOrDigit(codePoint) + || codePoint == Keyboard.CODE_SINGLE_QUOTE + || codePoint == Keyboard.CODE_DOUBLE_QUOTE + || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS + || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET + || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET + || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; + } + + public static int codePointCount(String text) { + if (TextUtils.isEmpty(text)) return 0; + return text.codePointCount(0, text.length()); + } + + public static boolean containsInCsv(String key, String csv) { + if (csv == null) + return false; + for (String option : csv.split(",")) { + if (option.equals(key)) + return true; + } + return false; + } + + public static boolean inPrivateImeOptions(String packageName, String key, + EditorInfo editorInfo) { + if (editorInfo == null) + return false; + return containsInCsv(packageName != null ? packageName + "." + key : key, + editorInfo.privateImeOptions); + } + + /** + * Returns true if a and b are equal ignoring the case of the character. + * @param a first character to check + * @param b second character to check + * @return {@code true} if a and b are equal, {@code false} otherwise. + */ + public static boolean equalsIgnoreCase(char a, char b) { + // Some language, such as Turkish, need testing both cases. + return a == b + || Character.toLowerCase(a) == Character.toLowerCase(b) + || Character.toUpperCase(a) == Character.toUpperCase(b); + } + + /** + * Returns true if a and b are equal ignoring the case of the characters, including if they are + * both null. + * @param a first CharSequence to check + * @param b second CharSequence to check + * @return {@code true} if a and b are equal, {@code false} otherwise. + */ + public static boolean equalsIgnoreCase(CharSequence a, CharSequence b) { + if (a == b) + return true; // including both a and b are null. + if (a == null || b == null) + return false; + final int length = a.length(); + if (length != b.length()) + return false; + for (int i = 0; i < length; i++) { + if (!equalsIgnoreCase(a.charAt(i), b.charAt(i))) + return false; + } + return true; + } + + /** + * Returns true if a and b are equal ignoring the case of the characters, including if a is null + * and b is zero length. + * @param a CharSequence to check + * @param b character array to check + * @param offset start offset of array b + * @param length length of characters in array b + * @return {@code true} if a and b are equal, {@code false} otherwise. + * @throws IndexOutOfBoundsException + * if {@code offset < 0 || length < 0 || offset + length > data.length}. + * @throws NullPointerException if {@code b == null}. + */ + public static boolean equalsIgnoreCase(CharSequence a, char[] b, int offset, int length) { + if (offset < 0 || length < 0 || length > b.length - offset) + throw new IndexOutOfBoundsException("array.length=" + b.length + " offset=" + offset + + " length=" + length); + if (a == null) + return length == 0; // including a is null and b is zero length. + if (a.length() != length) + return false; + for (int i = 0; i < length; i++) { + if (!equalsIgnoreCase(a.charAt(i), b[offset + i])) + return false; + } + return true; + } + + /** + * Remove duplicates from an array of strings. + * + * This method will always keep the first occurence of all strings at their position + * in the array, removing the subsequent ones. + */ + public static void removeDupes(final ArrayList suggestions) { + if (suggestions.size() < 2) return; + int i = 1; + // Don't cache suggestions.size(), since we may be removing items + while (i < suggestions.size()) { + final CharSequence cur = suggestions.get(i); + // Compare each suggestion with each previous suggestion + for (int j = 0; j < i; j++) { + CharSequence previous = suggestions.get(j); + if (TextUtils.equals(cur, previous)) { + removeFromSuggestions(suggestions, i); + i--; + break; + } + } + i++; + } + } + + private static void removeFromSuggestions(final ArrayList suggestions, + final int index) { + final CharSequence garbage = suggestions.remove(index); + if (garbage instanceof StringBuilder) { + StringBuilderPool.recycle((StringBuilder)garbage); + } + } + + public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { + if (returnsNameInThisLocale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } else { + return toTitleCase(locale.getDisplayName(), locale); + } + } + + public static String getDisplayLanguage(Locale locale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } + + public static String getMiddleDisplayLanguage(Locale locale) { + return toTitleCase((LocaleUtils.constructLocaleFromString( + locale.getLanguage()).getDisplayLanguage(locale)), locale); + } + + public static String getShortDisplayLanguage(Locale locale) { + return toTitleCase(locale.getLanguage(), locale); + } + + public static String toTitleCase(String s, Locale locale) { + if (s.length() <= 1) { + // TODO: is this really correct? Shouldn't this be s.toUpperCase()? + return s; + } + // TODO: fix the bugs below + // - This does not work for Greek, because it returns upper case instead of title case. + // - It does not work for Serbian, because it fails to account for the "lj" character, + // which should be "Lj" in title case and "LJ" in upper case. + // - It does not work for Dutch, because it fails to account for the "ij" digraph, which + // are two different characters but both should be capitalized as "IJ" as if they were + // a single letter. + // - It also does not work with unicode surrogate code points. + return s.toUpperCase(locale).charAt(0) + s.substring(1); + } +} diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index f5778167a..ffbbf9bb8 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -512,7 +512,7 @@ public class SubtypeSwitcher { } public String getInputLanguageName() { - return Utils.getDisplayLanguage(getInputLocale()); + return StringUtils.getDisplayLanguage(getInputLocale()); } ///////////////////////////// diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java new file mode 100644 index 000000000..cb2bcf43f --- /dev/null +++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java @@ -0,0 +1,135 @@ +/* + * 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.Context; + +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; + +public class SubtypeUtils { + private SubtypeUtils() { + // This utility class is not publicly instantiable. + } + + // TODO: Cache my InputMethodInfo and/or InputMethodSubtype list. + public static boolean checkIfSubtypeBelongsToThisIme(Context context, + InputMethodSubtypeCompatWrapper ims) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName()); + final List subtypes = + imm.getEnabledInputMethodSubtypeList(myImi, true); + for (final InputMethodSubtypeCompatWrapper subtype : subtypes) { + if (subtype.equals(ims)) { + return true; + } + } + return false; + } + + public static boolean hasMultipleEnabledIMEsOrSubtypes( + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + final List enabledImis = imm.getEnabledInputMethodList(); + return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); + } + + public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName()); + final List imiList = Collections.singletonList(myImi); + return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList); + } + + private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes, + List imiList) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + // Number of the filtered IMEs + int filteredImisCount = 0; + + for (InputMethodInfoCompatWrapper imi : imiList) { + // We can return true immediately after we find two or more filtered IMEs. + if (filteredImisCount > 1) return true; + final List subtypes = + imm.getEnabledInputMethodSubtypeList(imi, true); + // IMEs that have no subtypes should be counted. + if (subtypes.isEmpty()) { + ++filteredImisCount; + continue; + } + + int auxCount = 0; + for (InputMethodSubtypeCompatWrapper subtype : subtypes) { + if (subtype.isAuxiliary()) { + ++auxCount; + } + } + final int nonAuxCount = subtypes.size() - auxCount; + + // IMEs that have one or more non-auxiliary subtypes should be counted. + // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary + // subtypes should be counted as well. + if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { + ++filteredImisCount; + continue; + } + } + + if (filteredImisCount > 1) { + return true; + } + final List 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) { + if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) { + ++keyboardCount; + } + } + return keyboardCount > 1; + } + + public static String getInputMethodId(String packageName) { + return getInputMethodInfo(packageName).getId(); + } + + public static InputMethodInfoCompatWrapper 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()) { + if (imi.getPackageName().equals(packageName)) + return imi; + } + throw new RuntimeException("Can not find input method id for " + packageName); + } +} diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 298ead665..671fb905d 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -108,6 +108,8 @@ public class Suggest implements Dictionary.WordCallback { private boolean mIsAllUpperCase; private int mTrailingSingleQuotesCount; + private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4; + public Suggest(final Context context, final int dictionaryResId, final Locale locale) { initAsynchronously(context, dictionaryResId, locale); } @@ -383,7 +385,7 @@ public class Suggest implements Dictionary.WordCallback { if (typedWord != null) { mSuggestions.add(0, typedWord.toString()); } - Utils.removeDupes(mSuggestions); + StringUtils.removeDupes(mSuggestions); if (DBG) { double normalizedScore = mAutoCorrection.getNormalizedScore(); @@ -434,7 +436,7 @@ public class Suggest implements Dictionary.WordCallback { int pos = 0; // Check if it's the same word, only caps are different - if (Utils.equalsIgnoreCase(mConsideredWord, word, offset, length)) { + if (StringUtils.equalsIgnoreCase(mConsideredWord, word, offset, length)) { // TODO: remove this surrounding if clause and move this logic to // getSuggestedWordBuilder. if (suggestions.size() > 0) { @@ -443,7 +445,7 @@ public class Suggest implements Dictionary.WordCallback { // frequency to determine the insertion position. This does not ensure strictly // correct ordering, but ensures the top score is on top which is enough for // removing duplicates correctly. - if (Utils.equalsIgnoreCase(currentHighestWord, word, offset, length) + if (StringUtils.equalsIgnoreCase(currentHighestWord, word, offset, length) && score <= sortedScores[0]) { pos = 1; } @@ -558,4 +560,46 @@ public class Suggest implements Dictionary.WordCallback { } mMainDict = null; } + + // TODO: Resolve the inconsistencies between the native auto correction algorithms and + // this safety net + public static boolean shouldBlockAutoCorrectionBySafetyNet( + SuggestedWords.Builder suggestedWordsBuilder, Suggest suggest) { + // Safety net for auto correction. + // Actually if we hit this safety net, it's actually a bug. + if (suggestedWordsBuilder.size() <= 1 || suggestedWordsBuilder.isTypedWordValid()) { + return false; + } + // If user selected aggressive auto correction mode, there is no need to use the safety + // net. + if (suggest.isAggressiveAutoCorrectionMode()) { + return false; + } + final CharSequence typedWord = suggestedWordsBuilder.getWord(0); + // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH, + // we should not use net because relatively edit distance can be big. + if (typedWord.length() < Suggest.MINIMUM_SAFETY_NET_CHAR_LENGTH) { + return false; + } + final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1); + final int typedWordLength = typedWord.length(); + final int maxEditDistanceOfNativeDictionary = + (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; + final int distance = BinaryDictionary.editDistance( + typedWord.toString(), suggestionWord.toString()); + if (DBG) { + Log.d(TAG, "Autocorrected edit distance = " + distance + + ", " + maxEditDistanceOfNativeDictionary); + } + if (distance > maxEditDistanceOfNativeDictionary) { + if (DBG) { + Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); + Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " + + "Turning off auto-correction."); + } + return true; + } else { + return false; + } + } } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index a8679e07a..f8dd5ae42 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.AsyncTask; @@ -27,19 +26,9 @@ import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; import android.os.Process; -import android.text.InputType; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; -import android.view.inputmethod.EditorInfo; - -import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; -import com.android.inputmethod.compat.InputTypeCompatUtils; -import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.KeyboardId; -import com.android.inputmethod.latin.define.JniLibName; import java.io.BufferedReader; import java.io.File; @@ -51,20 +40,11 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; -import java.util.List; -import java.util.Locale; public class Utils { - private static final String TAG = Utils.class.getSimpleName(); - private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4; - private static boolean DBG = LatinImeLogger.sDBG; - private static boolean DBG_EDIT_DISTANCE = false; - private Utils() { - // Intentional empty constructor for utility class. + // This utility class is not publicly instantiable. } /** @@ -118,166 +98,6 @@ public class Utils { } } - // TODO: Move InputMethodSubtype related utility methods to its own utility class. - // TODO: Cache my InputMethodInfo and/or InputMethodSubtype list. - public static boolean checkIfSubtypeBelongsToThisIme(Context context, - InputMethodSubtypeCompatWrapper ims) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) return false; - - final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( - context.getPackageName()); - final List subtypes = - imm.getEnabledInputMethodSubtypeList(myImi, true); - for (final InputMethodSubtypeCompatWrapper subtype : subtypes) { - if (subtype.equals(ims)) { - return true; - } - } - return false; - } - - public static boolean hasMultipleEnabledIMEsOrSubtypes( - final boolean shouldIncludeAuxiliarySubtypes) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) return false; - - final List enabledImis = imm.getEnabledInputMethodList(); - return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); - } - - public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, - final boolean shouldIncludeAuxiliarySubtypes) { - final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( - context.getPackageName()); - final List imiList = Collections.singletonList(myImi); - return Utils.hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList); - } - - private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes, - List imiList) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) return false; - - // Number of the filtered IMEs - int filteredImisCount = 0; - - for (InputMethodInfoCompatWrapper imi : imiList) { - // We can return true immediately after we find two or more filtered IMEs. - if (filteredImisCount > 1) return true; - final List subtypes = - imm.getEnabledInputMethodSubtypeList(imi, true); - // IMEs that have no subtypes should be counted. - if (subtypes.isEmpty()) { - ++filteredImisCount; - continue; - } - - int auxCount = 0; - for (InputMethodSubtypeCompatWrapper subtype : subtypes) { - if (subtype.isAuxiliary()) { - ++auxCount; - } - } - final int nonAuxCount = subtypes.size() - auxCount; - - // IMEs that have one or more non-auxiliary subtypes should be counted. - // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary - // subtypes should be counted as well. - if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { - ++filteredImisCount; - continue; - } - } - - if (filteredImisCount > 1) { - return true; - } - final List 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) { - if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) { - ++keyboardCount; - } - } - return keyboardCount > 1; - } - - public static String getInputMethodId(String packageName) { - return getInputMethodInfo(packageName).getId(); - } - - public static InputMethodInfoCompatWrapper 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()) { - if (imi.getPackageName().equals(packageName)) - return imi; - } - throw new RuntimeException("Can not find input method id for " + packageName); - } - - // TODO: Resolve the inconsistencies between the native auto correction algorithms and - // this safety net - public static boolean shouldBlockAutoCorrectionBySafetyNet( - SuggestedWords.Builder suggestedWordsBuilder, Suggest suggest) { - // Safety net for auto correction. - // Actually if we hit this safety net, it's actually a bug. - if (suggestedWordsBuilder.size() <= 1 || suggestedWordsBuilder.isTypedWordValid()) { - return false; - } - // If user selected aggressive auto correction mode, there is no need to use the safety - // net. - if (suggest.isAggressiveAutoCorrectionMode()) { - return false; - } - final CharSequence typedWord = suggestedWordsBuilder.getWord(0); - // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH, - // we should not use net because relatively edit distance can be big. - if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) { - return false; - } - final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1); - final int typedWordLength = typedWord.length(); - final int maxEditDistanceOfNativeDictionary = - (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; - final int distance = BinaryDictionary.editDistance( - typedWord.toString(), suggestionWord.toString()); - if (DBG) { - Log.d(TAG, "Autocorrected edit distance = " + distance - + ", " + maxEditDistanceOfNativeDictionary); - } - if (distance > maxEditDistanceOfNativeDictionary) { - if (DBG) { - Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); - Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " - + "Turning off auto-correction."); - } - return true; - } else { - return false; - } - } - - public static boolean canBeFollowedByPeriod(final int codePoint) { - // TODO: Check again whether there really ain't a better way to check this. - // TODO: This should probably be language-dependant... - return Character.isLetterOrDigit(codePoint) - || codePoint == Keyboard.CODE_SINGLE_QUOTE - || codePoint == Keyboard.CODE_DOUBLE_QUOTE - || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS - || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET - || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET - || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; - } - /* package */ static class RingCharBuffer { private static RingCharBuffer sRingCharBuffer = new RingCharBuffer(); private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC'; @@ -600,147 +420,6 @@ public class Utils { } } - // TODO: Move this method to KeyboardSet class. - public static int getKeyboardMode(EditorInfo editorInfo) { - if (editorInfo == null) - return KeyboardId.MODE_TEXT; - - final int inputType = editorInfo.inputType; - final int variation = inputType & InputType.TYPE_MASK_VARIATION; - - switch (inputType & InputType.TYPE_MASK_CLASS) { - case InputType.TYPE_CLASS_NUMBER: - return KeyboardId.MODE_NUMBER; - case InputType.TYPE_CLASS_DATETIME: - switch (variation) { - case InputType.TYPE_DATETIME_VARIATION_DATE: - return KeyboardId.MODE_DATE; - case InputType.TYPE_DATETIME_VARIATION_TIME: - return KeyboardId.MODE_TIME; - default: // InputType.TYPE_DATETIME_VARIATION_NORMAL - return KeyboardId.MODE_DATETIME; - } - case InputType.TYPE_CLASS_PHONE: - return KeyboardId.MODE_PHONE; - case InputType.TYPE_CLASS_TEXT: - if (InputTypeCompatUtils.isEmailVariation(variation)) { - return KeyboardId.MODE_EMAIL; - } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { - return KeyboardId.MODE_URL; - } else if (variation == InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE) { - return KeyboardId.MODE_IM; - } else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) { - return KeyboardId.MODE_TEXT; - } else { - return KeyboardId.MODE_TEXT; - } - default: - return KeyboardId.MODE_TEXT; - } - } - - public static boolean containsInCsv(String key, String csv) { - if (csv == null) - return false; - for (String option : csv.split(",")) { - if (option.equals(key)) - return true; - } - return false; - } - - public static boolean inPrivateImeOptions(String packageName, String key, - EditorInfo editorInfo) { - if (editorInfo == null) - return false; - return containsInCsv(packageName != null ? packageName + "." + key : key, - editorInfo.privateImeOptions); - } - - /** - * Returns a main dictionary resource id - * @return main dictionary resource id - */ - public static int getMainDictionaryResourceId(Resources res) { - final String MAIN_DIC_NAME = "main"; - String packageName = LatinIME.class.getPackage().getName(); - return res.getIdentifier(MAIN_DIC_NAME, "raw", packageName); - } - - public static void loadNativeLibrary() { - try { - System.loadLibrary(JniLibName.JNI_LIB_NAME); - } catch (UnsatisfiedLinkError ule) { - Log.e(TAG, "Could not load native library " + JniLibName.JNI_LIB_NAME); - if (LatinImeLogger.sDBG) { - throw new RuntimeException( - "Could not load native library " + JniLibName.JNI_LIB_NAME); - } - } - } - - /** - * Returns true if a and b are equal ignoring the case of the character. - * @param a first character to check - * @param b second character to check - * @return {@code true} if a and b are equal, {@code false} otherwise. - */ - public static boolean equalsIgnoreCase(char a, char b) { - // Some language, such as Turkish, need testing both cases. - return a == b - || Character.toLowerCase(a) == Character.toLowerCase(b) - || Character.toUpperCase(a) == Character.toUpperCase(b); - } - - /** - * Returns true if a and b are equal ignoring the case of the characters, including if they are - * both null. - * @param a first CharSequence to check - * @param b second CharSequence to check - * @return {@code true} if a and b are equal, {@code false} otherwise. - */ - public static boolean equalsIgnoreCase(CharSequence a, CharSequence b) { - if (a == b) - return true; // including both a and b are null. - if (a == null || b == null) - return false; - final int length = a.length(); - if (length != b.length()) - return false; - for (int i = 0; i < length; i++) { - if (!equalsIgnoreCase(a.charAt(i), b.charAt(i))) - return false; - } - return true; - } - - /** - * Returns true if a and b are equal ignoring the case of the characters, including if a is null - * and b is zero length. - * @param a CharSequence to check - * @param b character array to check - * @param offset start offset of array b - * @param length length of characters in array b - * @return {@code true} if a and b are equal, {@code false} otherwise. - * @throws IndexOutOfBoundsException - * if {@code offset < 0 || length < 0 || offset + length > data.length}. - * @throws NullPointerException if {@code b == null}. - */ - public static boolean equalsIgnoreCase(CharSequence a, char[] b, int offset, int length) { - if (offset < 0 || length < 0 || length > b.length - offset) - throw new IndexOutOfBoundsException("array.length=" + b.length + " offset=" + offset - + " length=" + length); - if (a == null) - return length == 0; // including a is null and b is zero length. - if (a.length() != length) - return false; - for (int i = 0; i < length; i++) { - if (!equalsIgnoreCase(a.charAt(i), b[offset + i])) - return false; - } - return true; - } - public static float getDipScale(Context context) { final float scale = context.getResources().getDisplayMetrics().density; return scale; @@ -751,76 +430,6 @@ public class Utils { return (int) (dip * scale + 0.5); } - /** - * Remove duplicates from an array of strings. - * - * This method will always keep the first occurence of all strings at their position - * in the array, removing the subsequent ones. - */ - public static void removeDupes(final ArrayList suggestions) { - if (suggestions.size() < 2) return; - int i = 1; - // Don't cache suggestions.size(), since we may be removing items - while (i < suggestions.size()) { - final CharSequence cur = suggestions.get(i); - // Compare each suggestion with each previous suggestion - for (int j = 0; j < i; j++) { - CharSequence previous = suggestions.get(j); - if (TextUtils.equals(cur, previous)) { - removeFromSuggestions(suggestions, i); - i--; - break; - } - } - i++; - } - } - - private static void removeFromSuggestions(final ArrayList suggestions, - final int index) { - final CharSequence garbage = suggestions.remove(index); - if (garbage instanceof StringBuilder) { - StringBuilderPool.recycle((StringBuilder)garbage); - } - } - - public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { - if (returnsNameInThisLocale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } else { - return toTitleCase(locale.getDisplayName(), locale); - } - } - - public static String getDisplayLanguage(Locale locale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } - - public static String getMiddleDisplayLanguage(Locale locale) { - return toTitleCase((LocaleUtils.constructLocaleFromString( - locale.getLanguage()).getDisplayLanguage(locale)), locale); - } - - public static String getShortDisplayLanguage(Locale locale) { - return toTitleCase(locale.getLanguage(), locale); - } - - public static String toTitleCase(String s, Locale locale) { - if (s.length() <= 1) { - // TODO: is this really correct? Shouldn't this be s.toUpperCase()? - return s; - } - // TODO: fix the bugs below - // - This does not work for Greek, because it returns upper case instead of title case. - // - It does not work for Serbian, because it fails to account for the "lj" character, - // which should be "Lj" in title case and "LJ" in upper case. - // - It does not work for Dutch, because it fails to account for the "ij" digraph, which - // are two different characters but both should be capitalized as "IJ" as if they were - // a single letter. - // - It also does not work with unicode surrogate code points. - return s.toUpperCase(locale).charAt(0) + s.substring(1); - } - public static class Stats { public static void onNonSeparator(final char code, final int x, final int y) { @@ -845,9 +454,4 @@ public class Utils { LatinImeLogger.logOnAutoCorrectionCancelled(); } } - - public static int codePointCount(String text) { - if (TextUtils.isEmpty(text)) return 0; - return text.codePointCount(0, text.length()); - } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 755c75b2e..35a5c0f52 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -37,9 +37,9 @@ import com.android.inputmethod.latin.DictionaryFactory; import com.android.inputmethod.latin.Flag; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.SynchronouslyLoadedContactsDictionary; import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary; -import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.WhitelistDictionary; import com.android.inputmethod.latin.WordComposer; @@ -47,11 +47,11 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.TreeMap; -import java.util.HashSet; /** * Service for spell checking, using LatinIME's dictionaries and mechanisms. @@ -316,7 +316,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService } } Collections.reverse(mSuggestions); - Utils.removeDupes(mSuggestions); + StringUtils.removeDupes(mSuggestions); if (CAPITALIZE_ALL == capitalizeType) { for (int i = 0; i < mSuggestions.size(); ++i) { // get(i) returns a CharSequence which is actually a String so .toString() @@ -326,7 +326,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService } else if (CAPITALIZE_FIRST == capitalizeType) { for (int i = 0; i < mSuggestions.size(); ++i) { // Likewise - mSuggestions.set(i, Utils.toTitleCase(mSuggestions.get(i).toString(), + mSuggestions.set(i, StringUtils.toTitleCase(mSuggestions.get(i).toString(), locale)); } } @@ -396,7 +396,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService final ProximityInfo proximityInfo = ProximityInfo.createSpellCheckerProximityInfo( SpellCheckerProximityInfo.getProximityForScript(script)); final Resources resources = getResources(); - final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources); + final int fallbackResourceId = DictionaryFactory.getMainDictionaryResourceId(resources); final DictionaryCollection dictionaryCollection = DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId, USE_FULL_EDIT_DISTANCE_FLAG_ARRAY); -- cgit v1.2.3-83-g751a From ca0e04868891c461a3e6f30bf15d209d622c8349 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 12 Mar 2012 19:48:32 +0900 Subject: Kill methods with side-effects Change-Id: I42baeec68eb2540e7d8f8538ae2dceeef5594391 --- .../android/inputmethod/latin/SettingsValues.java | 21 ++++++++++++++------- .../android/inputmethod/latin/SuggestedWords.java | 11 ----------- 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index abd1dc692..1f4909f73 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,6 +28,7 @@ import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -174,28 +175,34 @@ public class SettingsValues { } private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + final ArrayList puncList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { - builder.addWord(KeySpecParser.getLabel(puncSpec)); + puncList.add(KeySpecParser.getLabel(puncSpec)); } } - return builder.setIsPunctuationSuggestions().build(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder() + .addWords(puncList, null) + .setIsPunctuationSuggestions(); + return builder.build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + final ArrayList puncOutputTextList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { final String outputText = KeySpecParser.getOutputText(puncSpec); if (outputText != null) { - builder.addWord(outputText); + puncOutputTextList.add(outputText); } else { - builder.addWord(KeySpecParser.getLabel(puncSpec)); + puncOutputTextList.add(KeySpecParser.getLabel(puncSpec)); } } } - return builder.setIsPunctuationSuggestions().build(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder() + .addWords(puncOutputTextList, null) + .setIsPunctuationSuggestions(); + return builder.build(); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 4a51e796d..a603fd8ec 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -104,17 +104,6 @@ public class SuggestedWords { return this; } - public Builder addWord(CharSequence word) { - return addWord(word, null, false); - } - - public Builder addWord(CharSequence word, CharSequence debugString, - boolean isPreviousSuggestedWord) { - SuggestedWordInfo info = new SuggestedWordInfo(word, debugString, - isPreviousSuggestedWord); - return addWord(word, info); - } - /* package for tests */ Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) { if (!TextUtils.isEmpty(suggestedWordInfo.mWord)) { -- cgit v1.2.3-83-g751a From b26af7eae7747853c1818b3b97f5d1d94b3105ee Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 12 Mar 2012 19:42:29 -0700 Subject: Revert "Kill methods with side-effects" This reverts commit ca0e04868891c461a3e6f30bf15d209d622c8349 --- .../android/inputmethod/latin/SettingsValues.java | 21 +++++++-------------- .../android/inputmethod/latin/SuggestedWords.java | 11 +++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 1f4909f73..abd1dc692 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,7 +28,6 @@ import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -175,34 +174,28 @@ public class SettingsValues { } private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final ArrayList puncList = new ArrayList(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder(); if (puncs != null) { for (final String puncSpec : puncs) { - puncList.add(KeySpecParser.getLabel(puncSpec)); + builder.addWord(KeySpecParser.getLabel(puncSpec)); } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncList, null) - .setIsPunctuationSuggestions(); - return builder.build(); + return builder.setIsPunctuationSuggestions().build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final ArrayList puncOutputTextList = new ArrayList(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder(); if (puncs != null) { for (final String puncSpec : puncs) { final String outputText = KeySpecParser.getOutputText(puncSpec); if (outputText != null) { - puncOutputTextList.add(outputText); + builder.addWord(outputText); } else { - puncOutputTextList.add(KeySpecParser.getLabel(puncSpec)); + builder.addWord(KeySpecParser.getLabel(puncSpec)); } } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncOutputTextList, null) - .setIsPunctuationSuggestions(); - return builder.build(); + return builder.setIsPunctuationSuggestions().build(); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index a603fd8ec..4a51e796d 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -104,6 +104,17 @@ public class SuggestedWords { return this; } + public Builder addWord(CharSequence word) { + return addWord(word, null, false); + } + + public Builder addWord(CharSequence word, CharSequence debugString, + boolean isPreviousSuggestedWord) { + SuggestedWordInfo info = new SuggestedWordInfo(word, debugString, + isPreviousSuggestedWord); + return addWord(word, info); + } + /* package for tests */ Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) { if (!TextUtils.isEmpty(suggestedWordInfo.mWord)) { -- cgit v1.2.3-83-g751a From 7c9bff96f0bbc237c9e4cbe86a409b93555cf33a Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 14:18:30 +0900 Subject: Kill methods with side-effects, take 2 ...working this time Change-Id: I80e377e6250d3817f1e067a551bca2a557740764 --- .../android/inputmethod/latin/SettingsValues.java | 21 ++++++++++++++------- .../android/inputmethod/latin/SuggestedWords.java | 15 ++------------- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index abd1dc692..1f4909f73 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,6 +28,7 @@ import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -174,28 +175,34 @@ public class SettingsValues { } private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + final ArrayList puncList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { - builder.addWord(KeySpecParser.getLabel(puncSpec)); + puncList.add(KeySpecParser.getLabel(puncSpec)); } } - return builder.setIsPunctuationSuggestions().build(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder() + .addWords(puncList, null) + .setIsPunctuationSuggestions(); + return builder.build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final SuggestedWords.Builder builder = new SuggestedWords.Builder(); + final ArrayList puncOutputTextList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { final String outputText = KeySpecParser.getOutputText(puncSpec); if (outputText != null) { - builder.addWord(outputText); + puncOutputTextList.add(outputText); } else { - builder.addWord(KeySpecParser.getLabel(puncSpec)); + puncOutputTextList.add(KeySpecParser.getLabel(puncSpec)); } } } - return builder.setIsPunctuationSuggestions().build(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder() + .addWords(puncOutputTextList, null) + .setIsPunctuationSuggestions(); + return builder.build(); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 4a51e796d..9959292cb 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -104,17 +104,6 @@ public class SuggestedWords { return this; } - public Builder addWord(CharSequence word) { - return addWord(word, null, false); - } - - public Builder addWord(CharSequence word, CharSequence debugString, - boolean isPreviousSuggestedWord) { - SuggestedWordInfo info = new SuggestedWordInfo(word, debugString, - isPreviousSuggestedWord); - return addWord(word, info); - } - /* package for tests */ Builder addWord(CharSequence word, SuggestedWordInfo suggestedWordInfo) { if (!TextUtils.isEmpty(suggestedWordInfo.mWord)) { @@ -169,14 +158,14 @@ public class SuggestedWords { SuggestedWords previousSuggestions) { mSuggestedWordInfoList.clear(); final HashSet alreadySeen = new HashSet(); - addWord(typedWord, null, false); + addWord(typedWord, new SuggestedWordInfo(typedWord, null, false)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { final String prevWord = previousSuggestions.getWord(pos).toString(); // Filter out duplicate suggestion. if (!alreadySeen.contains(prevWord)) { - addWord(prevWord, null, true); + addWord(prevWord, new SuggestedWordInfo(prevWord, null, true)); alreadySeen.add(prevWord); } } -- cgit v1.2.3-83-g751a From d0d4074392a844602d068b17733fe16b1af94d86 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 15:05:44 +0900 Subject: Remove a useless parameter. Change-Id: I7625bf17158c207ad7e8cd496bef825704173c4c --- .../com/android/inputmethod/latin/LatinIME.java | 4 +-- .../android/inputmethod/latin/SettingsValues.java | 18 +++++++---- .../src/com/android/inputmethod/latin/Suggest.java | 8 +++-- .../android/inputmethod/latin/SuggestedWords.java | 37 +++++++++++++--------- 4 files changed, 40 insertions(+), 27 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 22d1a4025..dc5bd2efc 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -922,11 +922,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - final List applicationSuggestedWords = + final List applicationSuggestedWords = SuggestedWords.Builder.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(applicationSuggestedWords, null) + .addWords(applicationSuggestedWords) .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 1f4909f73..7e7702002 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -175,32 +175,36 @@ public class SettingsValues { } private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final ArrayList puncList = new ArrayList(); + final ArrayList puncList = + new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { - puncList.add(KeySpecParser.getLabel(puncSpec)); + puncList.add(new SuggestedWords.SuggestedWordInfo( + KeySpecParser.getLabel(puncSpec))); } } final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncList, null) + .addWords(puncList) .setIsPunctuationSuggestions(); return builder.build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final ArrayList puncOutputTextList = new ArrayList(); + final ArrayList puncOutputTextList = + new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { final String outputText = KeySpecParser.getOutputText(puncSpec); if (outputText != null) { - puncOutputTextList.add(outputText); + puncOutputTextList.add(new SuggestedWords.SuggestedWordInfo(outputText)); } else { - puncOutputTextList.add(KeySpecParser.getLabel(puncSpec)); + puncOutputTextList.add(new SuggestedWords.SuggestedWordInfo( + KeySpecParser.getLabel(puncSpec))); } } } final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncOutputTextList, null) + .addWords(puncOutputTextList) .setIsPunctuationSuggestions(); return builder.build(); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index f17c1d95a..e04a4e8d1 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -291,7 +291,8 @@ public class Suggest implements Dictionary.WordCallback { StringUtils.removeDupes(mSuggestions); - return new SuggestedWords.Builder().addWords(mSuggestions, null) + return new SuggestedWords.Builder() + .addWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) .setAllowsToBeAutoCorrected(false) .setHasAutoCorrection(false); } @@ -445,11 +446,12 @@ public class Suggest implements Dictionary.WordCallback { scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i), "--", false)); } - builder = new SuggestedWords.Builder().addWords(mSuggestions, scoreInfoList) + builder = new SuggestedWords.Builder().addWords(scoreInfoList) .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected) .setHasAutoCorrection(hasAutoCorrection); } else { - builder = new SuggestedWords.Builder().addWords(mSuggestions, null) + builder = new SuggestedWords.Builder() + .addWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected) .setHasAutoCorrection(hasAutoCorrection); } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 9959292cb..7dd85f65b 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -87,19 +87,17 @@ public class SuggestedWords { // Nothing to do here. } - public Builder addWords(List words, - List suggestedWordInfoList) { - final int N = words.size(); + // TODO: the following method is a wrapper to satisfy tests. Update tests and remove it. + public Builder addWords(final List words, + final List suggestedWordInfoList) { + return addWords(suggestedWordInfoList); + } + + public Builder addWords(List suggestedWordInfoList) { + final int N = suggestedWordInfoList.size(); for (int i = 0; i < N; ++i) { - final CharSequence word = words.get(i); - SuggestedWordInfo suggestedWordInfo = null; - if (suggestedWordInfoList != null) { - suggestedWordInfo = suggestedWordInfoList.get(i); - } - if (suggestedWordInfo == null) { - suggestedWordInfo = new SuggestedWordInfo(word); - } - addWord(word, suggestedWordInfo); + SuggestedWordInfo suggestedWordInfo = suggestedWordInfoList.get(i); + addWord(suggestedWordInfo.mWord, suggestedWordInfo); } return this; } @@ -113,11 +111,20 @@ public class SuggestedWords { return this; } - public static List getFromApplicationSpecifiedCompletions( + public static List getFromCharSequenceList( + final List wordList) { + final ArrayList result = new ArrayList(); + for (CharSequence word : wordList) { + if (null != word) result.add(new SuggestedWordInfo(word, null, false)); + } + return result; + } + + public static List getFromApplicationSpecifiedCompletions( final CompletionInfo[] infos) { - final ArrayList result = new ArrayList(); + final ArrayList result = new ArrayList(); for (CompletionInfo info : infos) { - if (null != info) result.add(info.getText()); + if (null != info) result.add(new SuggestedWordInfo(info.getText(), null, false)); } return result; } -- cgit v1.2.3-83-g751a From 674ffcdf9361b3c90cc39daf02f3217fb6d870de Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 16:36:21 +0900 Subject: Make an add into a set. This method now only sets words, so it should be named set. The functionality is identical since there are no more places where the list is reused. This will also allow to make the list final in an upcoming change. Change-Id: I25b0c7d7f13c3fa5d89806f01f48f1026769603f --- java/src/com/android/inputmethod/latin/LatinIME.java | 4 ++-- java/src/com/android/inputmethod/latin/SettingsValues.java | 4 ++-- java/src/com/android/inputmethod/latin/Suggest.java | 6 +++--- java/src/com/android/inputmethod/latin/SuggestedWords.java | 11 ++++++----- 4 files changed, 13 insertions(+), 12 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 39cbfa7a0..a7985c37d 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -927,7 +927,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar SuggestedWords.Builder.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(applicationSuggestedWords) + .setWords(applicationSuggestedWords) .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application @@ -1787,7 +1787,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar SuggestedWords.Builder.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); final SuggestedWords.Builder obsoleteSuggestionsBuilder = new SuggestedWords.Builder() - .addWords(typedWordAndPreviousSuggestions) + .setWords(typedWordAndPreviousSuggestions) .setTypedWordValid(false) .setHasMinimalSuggestion(false); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 7e7702002..9abea66b2 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -184,7 +184,7 @@ public class SettingsValues { } } final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncList) + .setWords(puncList) .setIsPunctuationSuggestions(); return builder.build(); } @@ -204,7 +204,7 @@ public class SettingsValues { } } final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .addWords(puncOutputTextList) + .setWords(puncOutputTextList) .setIsPunctuationSuggestions(); return builder.build(); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 487e91b0e..a5c70eca9 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -270,7 +270,7 @@ public class Suggest implements Dictionary.WordCallback { StringUtils.removeDupes(mSuggestions); return new SuggestedWords.Builder() - .addWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) + .setWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) .setAllowsToBeAutoCorrected(false) .setHasAutoCorrection(false); } @@ -424,12 +424,12 @@ public class Suggest implements Dictionary.WordCallback { scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i), "--", false)); } - builder = new SuggestedWords.Builder().addWords(scoreInfoList) + builder = new SuggestedWords.Builder().setWords(scoreInfoList) .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected) .setHasAutoCorrection(hasAutoCorrection); } else { builder = new SuggestedWords.Builder() - .addWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) + .setWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected) .setHasAutoCorrection(hasAutoCorrection); } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 9a7ea6b6a..5d0fc20b2 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -87,12 +87,13 @@ public class SuggestedWords { // Nothing to do here. } + // TODO: compatibility for tests. Remove this once tests are okay. public Builder addWords(List suggestedWordInfoList) { - final int N = suggestedWordInfoList.size(); - for (int i = 0; i < N; ++i) { - SuggestedWordInfo suggestedWordInfo = suggestedWordInfoList.get(i); - addWord(suggestedWordInfo.mWord, suggestedWordInfo); - } + return setWords(suggestedWordInfoList); + } + + public Builder setWords(List suggestedWordInfoList) { + mSuggestedWordInfoList = suggestedWordInfoList; return this; } -- cgit v1.2.3-83-g751a From c60fea852d0eaaed7f212dbab0af500d07188c69 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 19:26:52 +0900 Subject: Make the suggested word list final in Builder. Change-Id: I2ddfab00dc8c141fc989a051f16eb2b3571b7e86 --- java/src/com/android/inputmethod/latin/LatinIME.java | 7 +++---- java/src/com/android/inputmethod/latin/SettingsValues.java | 6 ++---- java/src/com/android/inputmethod/latin/Suggest.java | 10 +++++----- java/src/com/android/inputmethod/latin/SuggestedWords.java | 11 ++--------- 4 files changed, 12 insertions(+), 22 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a7985c37d..bd502a030 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -926,8 +926,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final List applicationSuggestedWords = SuggestedWords.Builder.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); - SuggestedWords.Builder builder = new SuggestedWords.Builder() - .setWords(applicationSuggestedWords) + SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords) .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application @@ -1786,8 +1785,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final ArrayList typedWordAndPreviousSuggestions = SuggestedWords.Builder.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); - final SuggestedWords.Builder obsoleteSuggestionsBuilder = new SuggestedWords.Builder() - .setWords(typedWordAndPreviousSuggestions) + final SuggestedWords.Builder obsoleteSuggestionsBuilder = + new SuggestedWords.Builder(typedWordAndPreviousSuggestions) .setTypedWordValid(false) .setHasMinimalSuggestion(false); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 9abea66b2..591f9f5a7 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -183,8 +183,7 @@ public class SettingsValues { KeySpecParser.getLabel(puncSpec))); } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .setWords(puncList) + final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncList) .setIsPunctuationSuggestions(); return builder.build(); } @@ -203,8 +202,7 @@ public class SettingsValues { } } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder() - .setWords(puncOutputTextList) + final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncOutputTextList) .setIsPunctuationSuggestions(); return builder.build(); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 3015d75ce..40e9ef8e7 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -269,8 +269,8 @@ public class Suggest implements Dictionary.WordCallback { StringUtils.removeDupes(mSuggestions); - return new SuggestedWords.Builder() - .setWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) + return new SuggestedWords.Builder( + SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) .setAllowsToBeAutoCorrected(false); } @@ -423,11 +423,11 @@ public class Suggest implements Dictionary.WordCallback { scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i), "--", false)); } - builder = new SuggestedWords.Builder().setWords(scoreInfoList) + builder = new SuggestedWords.Builder(scoreInfoList) .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected); } else { - builder = new SuggestedWords.Builder() - .setWords(SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) + builder = new SuggestedWords.Builder( + SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected); } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index a9699af52..676563e1d 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -16,7 +16,6 @@ package com.android.inputmethod.latin; -import android.text.TextUtils; import android.view.inputmethod.CompletionInfo; import java.util.ArrayList; @@ -79,16 +78,10 @@ public class SuggestedWords { private boolean mIsPunctuationSuggestions; private boolean mShouldBlockAutoCorrectionBySafetyNet; private boolean mAllowsToBeAutoCorrected; - private List mSuggestedWordInfoList = - new ArrayList(); + private final List mSuggestedWordInfoList; - public Builder() { - // Nothing to do here. - } - - public Builder setWords(List suggestedWordInfoList) { + public Builder(final List suggestedWordInfoList) { mSuggestedWordInfoList = suggestedWordInfoList; - return this; } public static List getFromCharSequenceList( -- cgit v1.2.3-83-g751a From b5eeb724fc98bb7169683539027d9ba54ffb8b14 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 19:40:24 +0900 Subject: Make some more Builder attributes final. Change-Id: I3132b7fe4ee97c566736bfc21c3783cfc79fc7ff --- java/src/com/android/inputmethod/latin/LatinIME.java | 12 ++++++++---- .../android/inputmethod/latin/SettingsValues.java | 10 ++++++---- java/src/com/android/inputmethod/latin/Suggest.java | 14 ++++++++------ .../android/inputmethod/latin/SuggestedWords.java | 20 +++++++------------- 4 files changed, 29 insertions(+), 27 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index bd502a030..2bbda7848 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -926,7 +926,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final List applicationSuggestedWords = SuggestedWords.Builder.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); - SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords) + SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords, + false /* allowsToBeAutoCorrected */, + false /* isPunctuationSuggestions */) .setTypedWordValid(false) .setHasMinimalSuggestion(false); // When in fullscreen mode, show completions generated by the application @@ -1786,9 +1788,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar SuggestedWords.Builder.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); final SuggestedWords.Builder obsoleteSuggestionsBuilder = - new SuggestedWords.Builder(typedWordAndPreviousSuggestions) - .setTypedWordValid(false) - .setHasMinimalSuggestion(false); + new SuggestedWords.Builder(typedWordAndPreviousSuggestions, + false /* allowsToBeAutoCorrected */, + false /* isPunctuationSuggestions */) + .setTypedWordValid(false) + .setHasMinimalSuggestion(false); showSuggestions(obsoleteSuggestionsBuilder.build(), typedWord); } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 591f9f5a7..c5198b337 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -183,8 +183,9 @@ public class SettingsValues { KeySpecParser.getLabel(puncSpec))); } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncList) - .setIsPunctuationSuggestions(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncList, + false /* allowsToBeAutoCorrected */, + true /* isPunctuationSuggestions */); return builder.build(); } @@ -202,8 +203,9 @@ public class SettingsValues { } } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncOutputTextList) - .setIsPunctuationSuggestions(); + final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncOutputTextList, + false /* allowsToBeAutoCorrected */, + true /* isPunctuationSuggestions */); return builder.build(); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 40e9ef8e7..fd813c9a2 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -270,8 +270,9 @@ public class Suggest implements Dictionary.WordCallback { StringUtils.removeDupes(mSuggestions); return new SuggestedWords.Builder( - SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) - .setAllowsToBeAutoCorrected(false); + SuggestedWords.Builder.getFromCharSequenceList(mSuggestions), + false /* allowsToBeAutoCorrected */, + false /* isPunctuationSuggestions */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -423,12 +424,13 @@ public class Suggest implements Dictionary.WordCallback { scoreInfoList.add(new SuggestedWords.SuggestedWordInfo(mSuggestions.get(i), "--", false)); } - builder = new SuggestedWords.Builder(scoreInfoList) - .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected); + builder = new SuggestedWords.Builder(scoreInfoList, allowsToBeAutoCorrected, + false /* isPunctuationSuggestions */); } else { builder = new SuggestedWords.Builder( - SuggestedWords.Builder.getFromCharSequenceList(mSuggestions)) - .setAllowsToBeAutoCorrected(allowsToBeAutoCorrected); + SuggestedWords.Builder.getFromCharSequenceList(mSuggestions), + allowsToBeAutoCorrected, + false /* isPunctuationSuggestions */); } boolean autoCorrectionAvailable = hasAutoCorrection; diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 676563e1d..d41f84798 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -75,13 +75,17 @@ public class SuggestedWords { public static class Builder { private boolean mTypedWordValid; private boolean mHasMinimalSuggestion; - private boolean mIsPunctuationSuggestions; + private final boolean mIsPunctuationSuggestions; private boolean mShouldBlockAutoCorrectionBySafetyNet; - private boolean mAllowsToBeAutoCorrected; + private final boolean mAllowsToBeAutoCorrected; private final List mSuggestedWordInfoList; - public Builder(final List suggestedWordInfoList) { + public Builder(final List suggestedWordInfoList, + final boolean allowsToBeAutoCorrected, + final boolean isPunctuationSuggestions) { mSuggestedWordInfoList = suggestedWordInfoList; + mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; + mIsPunctuationSuggestions = isPunctuationSuggestions; } public static List getFromCharSequenceList( @@ -112,21 +116,11 @@ public class SuggestedWords { return this; } - public Builder setIsPunctuationSuggestions() { - mIsPunctuationSuggestions = true; - return this; - } - public Builder setShouldBlockAutoCorrectionBySafetyNet() { mShouldBlockAutoCorrectionBySafetyNet = true; return this; } - public Builder setAllowsToBeAutoCorrected(final boolean allowsToBeAutoCorrected) { - mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; - return this; - } - // Should get rid of the first one (what the user typed previously) from suggestions // and replace it with what the user currently typed. public static ArrayList getTypedWordAndPreviousSuggestions( -- cgit v1.2.3-83-g751a From 2e2519ee914d4bf9462950553840557a4c19faed Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 20:05:00 +0900 Subject: Make still more members of the Builder final. Change-Id: Ic455f97247da5e40d4939555ab639ecffef36e2d --- java/src/com/android/inputmethod/latin/LatinIME.java | 13 ++++++------- .../com/android/inputmethod/latin/SettingsValues.java | 4 ++++ java/src/com/android/inputmethod/latin/Suggest.java | 9 ++++++--- .../com/android/inputmethod/latin/SuggestedWords.java | 18 ++++++------------ 4 files changed, 22 insertions(+), 22 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 2bbda7848..f41972e8b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -927,10 +927,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar SuggestedWords.Builder.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords, + false /* typedWordValid */, + false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */) - .setTypedWordValid(false) - .setHasMinimalSuggestion(false); + false /* isPunctuationSuggestions */); // When in fullscreen mode, show completions generated by the application final SuggestedWords words = builder.build(); final boolean isAutoCorrection = false; @@ -1789,11 +1789,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar typedWord, previousSuggestions); final SuggestedWords.Builder obsoleteSuggestionsBuilder = new SuggestedWords.Builder(typedWordAndPreviousSuggestions, + false /* typedWordValid */, + false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */) - .setTypedWordValid(false) - .setHasMinimalSuggestion(false); - + false /* isPunctuationSuggestions */); showSuggestions(obsoleteSuggestionsBuilder.build(), typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index c5198b337..0a4aea140 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -184,6 +184,8 @@ public class SettingsValues { } } final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncList, + false /* typedWordValid */, + false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */); return builder.build(); @@ -204,6 +206,8 @@ public class SettingsValues { } } final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncOutputTextList, + false /* typedWordValid */, + false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */); return builder.build(); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 28cbc9789..28d3b4437 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -271,6 +271,8 @@ public class Suggest implements Dictionary.WordCallback { return new SuggestedWords.Builder( SuggestedWords.Builder.getFromCharSequenceList(mSuggestions), + false /* typedWordValid */, + false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */); } @@ -435,10 +437,11 @@ public class Suggest implements Dictionary.WordCallback { } // Don't auto-correct words with multiple capital letter autoCorrectionAvailable &= !wordComposer.isMostlyCaps(); - builder = new SuggestedWords.Builder(scoreInfoList, allowsToBeAutoCorrected, + builder = new SuggestedWords.Builder(scoreInfoList, + !allowsToBeAutoCorrected /* typedWordValid */, + autoCorrectionAvailable /* hasMinimalSuggestion */, + allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */); - builder.setTypedWordValid(!allowsToBeAutoCorrected).setHasMinimalSuggestion( - autoCorrectionAvailable); if (allowsToBeAutoCorrected && builder.size() > 1 && mAutoCorrectionThreshold > 0 && Suggest.shouldBlockAutoCorrectionBySafetyNet(typedWord, builder.getWord(1))) { builder.setShouldBlockAutoCorrectionBySafetyNet(); diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index f62e99cac..144e67482 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -73,17 +73,21 @@ public class SuggestedWords { } public static class Builder { - private boolean mTypedWordValid; - private boolean mHasMinimalSuggestion; + private final boolean mTypedWordValid; + private final boolean mHasMinimalSuggestion; private final boolean mIsPunctuationSuggestions; private boolean mShouldBlockAutoCorrectionBySafetyNet; private final boolean mAllowsToBeAutoCorrected; private final List mSuggestedWordInfoList; public Builder(final List suggestedWordInfoList, + final boolean typedWordValid, + final boolean hasMinimalSuggestion, final boolean allowsToBeAutoCorrected, final boolean isPunctuationSuggestions) { mSuggestedWordInfoList = suggestedWordInfoList; + mTypedWordValid = typedWordValid; + mHasMinimalSuggestion = hasMinimalSuggestion; mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; mIsPunctuationSuggestions = isPunctuationSuggestions; } @@ -106,16 +110,6 @@ public class SuggestedWords { return result; } - public Builder setTypedWordValid(boolean typedWordValid) { - mTypedWordValid = typedWordValid; - return this; - } - - public Builder setHasMinimalSuggestion(boolean hasMinimalSuggestion) { - mHasMinimalSuggestion = hasMinimalSuggestion; - return this; - } - public Builder setShouldBlockAutoCorrectionBySafetyNet() { mShouldBlockAutoCorrectionBySafetyNet = true; return this; -- cgit v1.2.3-83-g751a From e3afb7d19276676d28ca018e5f156892e137a96e Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 20:33:13 +0900 Subject: Make the Builder fully immutable at last Change-Id: Ie399ca7a9e76ccab44a92bc378d11f92392fed2c --- java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++++-- java/src/com/android/inputmethod/latin/SettingsValues.java | 6 ++++-- java/src/com/android/inputmethod/latin/Suggest.java | 9 ++++----- java/src/com/android/inputmethod/latin/SuggestedWords.java | 11 ++++------- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index def639dce..ec408792c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -930,7 +930,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* shouldBlockAutoCorrectionBySafetyNet */); // When in fullscreen mode, show completions generated by the application final SuggestedWords words = builder.build(); final boolean isAutoCorrection = false; @@ -1794,7 +1795,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* shouldBlockAutoCorrectionBySafetyNet */); showSuggestions(obsoleteSuggestionsBuilder.build(), typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 0a4aea140..7ae95326b 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -187,7 +187,8 @@ public class SettingsValues { false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */); + true /* isPunctuationSuggestions */, + false /* shouldBlockAutoCorrectionBySafetyNet */); return builder.build(); } @@ -209,7 +210,8 @@ public class SettingsValues { false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */); + true /* isPunctuationSuggestions */, + false /* shouldBlockAutoCorrectionBySafetyNet */); return builder.build(); } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 4dee4f3b4..b02c9738e 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -274,7 +274,8 @@ public class Suggest implements Dictionary.WordCallback { false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* shouldBlockAutoCorrectionBySafetyNet */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -449,10 +450,8 @@ public class Suggest implements Dictionary.WordCallback { !allowsToBeAutoCorrected /* typedWordValid */, autoCorrectionAvailable /* hasMinimalSuggestion */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); - if (shouldBlockAutoCorrectionBySatefyNet) { - builder.setShouldBlockAutoCorrectionBySafetyNet(); - } + false /* isPunctuationSuggestions */, + shouldBlockAutoCorrectionBySatefyNet); return builder; } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index bc89941a1..03ff5de7b 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -80,7 +80,7 @@ public class SuggestedWords { private final boolean mTypedWordValid; private final boolean mHasMinimalSuggestion; private final boolean mIsPunctuationSuggestions; - private boolean mShouldBlockAutoCorrectionBySafetyNet; + private final boolean mShouldBlockAutoCorrectionBySafetyNet; private final boolean mAllowsToBeAutoCorrected; private final List mSuggestedWordInfoList; @@ -88,12 +88,14 @@ public class SuggestedWords { final boolean typedWordValid, final boolean hasMinimalSuggestion, final boolean allowsToBeAutoCorrected, - final boolean isPunctuationSuggestions) { + final boolean isPunctuationSuggestions, + final boolean shouldBlockAutoCorrectionBySafetyNet) { mSuggestedWordInfoList = suggestedWordInfoList; mTypedWordValid = typedWordValid; mHasMinimalSuggestion = hasMinimalSuggestion; mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; mIsPunctuationSuggestions = isPunctuationSuggestions; + mShouldBlockAutoCorrectionBySafetyNet = shouldBlockAutoCorrectionBySafetyNet; } public static ArrayList getFromCharSequenceList( @@ -114,11 +116,6 @@ public class SuggestedWords { return result; } - public Builder setShouldBlockAutoCorrectionBySafetyNet() { - mShouldBlockAutoCorrectionBySafetyNet = true; - return this; - } - // Should get rid of the first one (what the user typed previously) from suggestions // and replace it with what the user currently typed. public static ArrayList getTypedWordAndPreviousSuggestions( -- cgit v1.2.3-83-g751a From 7d55c891afdf7e74e505acac998a95a9ca7a9ec2 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 14 Mar 2012 15:22:57 +0900 Subject: Make the Builder private Change-Id: I2184084f4b7729c4324f8291d548bd4c4c2872a1 --- .../src/com/android/inputmethod/latin/LatinIME.java | 12 ++++++------ .../android/inputmethod/latin/SettingsValues.java | 6 ++---- java/src/com/android/inputmethod/latin/Suggest.java | 8 ++++---- .../android/inputmethod/latin/SuggestedWords.java | 21 ++++++++++++++++++--- 4 files changed, 30 insertions(+), 17 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d0f94bb6a..62ba8d952 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -926,16 +926,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final List applicationSuggestedWords = SuggestedWords.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); - SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords, + final SuggestedWords suggestedWords = SuggestedWords.getSuggestedWords( + applicationSuggestedWords, false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); // When in fullscreen mode, show completions generated by the application - final SuggestedWords words = builder.build(); final boolean isAutoCorrection = false; - setSuggestions(words, isAutoCorrection); + setSuggestions(suggestedWords, isAutoCorrection); setAutoCorrectionIndicator(isAutoCorrection); // TODO: is this the right thing to do? What should we auto-correct to in // this case? This says to keep whatever the user typed. @@ -1789,14 +1789,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final ArrayList typedWordAndPreviousSuggestions = SuggestedWords.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); - final SuggestedWords.Builder obsoleteSuggestionsBuilder = - new SuggestedWords.Builder(typedWordAndPreviousSuggestions, + final SuggestedWords obsoleteSuggestedWords = + SuggestedWords.getSuggestedWords(typedWordAndPreviousSuggestions, false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); - showSuggestions(obsoleteSuggestionsBuilder.build(), typedWord); + showSuggestions(obsoleteSuggestedWords, typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 7ae95326b..df0e1696b 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -183,13 +183,12 @@ public class SettingsValues { KeySpecParser.getLabel(puncSpec))); } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncList, + return SuggestedWords.getSuggestedWords(puncList, false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); - return builder.build(); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { @@ -206,13 +205,12 @@ public class SettingsValues { } } } - final SuggestedWords.Builder builder = new SuggestedWords.Builder(puncOutputTextList, + return SuggestedWords.getSuggestedWords(puncOutputTextList, false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); - return builder.build(); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 236a34164..fea1b83bb 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -269,13 +269,13 @@ public class Suggest implements Dictionary.WordCallback { StringUtils.removeDupes(mSuggestions); - return new SuggestedWords.Builder( + return SuggestedWords.getSuggestedWords( SuggestedWords.getFromCharSequenceList(mSuggestions), false /* typedWordValid */, false /* hasMinimalSuggestion */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, - false /* shouldBlockAutoCorrectionBySafetyNet */).build(); + false /* shouldBlockAutoCorrectionBySafetyNet */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -445,12 +445,12 @@ public class Suggest implements Dictionary.WordCallback { } else { shouldBlockAutoCorrectionBySatefyNet = false; } - return new SuggestedWords.Builder(scoreInfoList, + return SuggestedWords.getSuggestedWords(scoreInfoList, !allowsToBeAutoCorrected /* typedWordValid */, autoCorrectionAvailable /* hasMinimalSuggestion */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, - shouldBlockAutoCorrectionBySatefyNet).build(); + shouldBlockAutoCorrectionBySatefyNet); } @Override diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 5fae06f73..758b81e94 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -33,7 +33,7 @@ public class SuggestedWords { public final boolean mAllowsToBeAutoCorrected; private final List mSuggestedWordInfoList; - SuggestedWords(final boolean typedWordValid, + private SuggestedWords(final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean isPunctuationSuggestions, final boolean shouldBlockAutoCorrectionBySafetyNet, @@ -76,7 +76,7 @@ public class SuggestedWords { + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions; } - public static class Builder { + private static class Builder { private final boolean mTypedWordValid; private final boolean mHasMinimalSuggestion; private final boolean mIsPunctuationSuggestions; @@ -84,7 +84,7 @@ public class SuggestedWords { private final boolean mAllowsToBeAutoCorrected; private final List mSuggestedWordInfoList; - public Builder(final List suggestedWordInfoList, + private Builder(final List suggestedWordInfoList, final boolean typedWordValid, final boolean hasMinimalSuggestion, final boolean allowsToBeAutoCorrected, @@ -105,6 +105,21 @@ public class SuggestedWords { } } + public static SuggestedWords getSuggestedWords( + final List suggestedWordInfoList, + final boolean typedWordValid, + final boolean hasMinimalSuggestion, + final boolean allowsToBeAutoCorrected, + final boolean isPunctuationSuggestions, + final boolean shouldBlockAutoCorrectionBySafetyNet) { + return new Builder(suggestedWordInfoList, + typedWordValid, + hasMinimalSuggestion, + allowsToBeAutoCorrected, + isPunctuationSuggestions, + shouldBlockAutoCorrectionBySafetyNet).build(); + } + public static ArrayList getFromCharSequenceList( final List wordList) { final ArrayList result = new ArrayList(); -- cgit v1.2.3-83-g751a From bdf6d1b18b3cebdde5f39d10066ead34be161baf Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 14 Mar 2012 15:59:04 +0900 Subject: Remove a useless method Change-Id: I208dd2e725e37c2fb3cd51fe48194679e5912f6b --- java/src/com/android/inputmethod/latin/LatinIME.java | 8 ++++---- .../com/android/inputmethod/latin/SettingsValues.java | 8 ++++---- java/src/com/android/inputmethod/latin/Suggest.java | 9 ++++----- .../com/android/inputmethod/latin/SuggestedWords.java | 17 +---------------- 4 files changed, 13 insertions(+), 29 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 62ba8d952..6570f7a2f 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -926,10 +926,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final List applicationSuggestedWords = SuggestedWords.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); - final SuggestedWords suggestedWords = SuggestedWords.getSuggestedWords( + final SuggestedWords suggestedWords = new SuggestedWords( applicationSuggestedWords, false /* typedWordValid */, - false /* hasMinimalSuggestion */, + false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); @@ -1790,9 +1790,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar SuggestedWords.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); final SuggestedWords obsoleteSuggestedWords = - SuggestedWords.getSuggestedWords(typedWordAndPreviousSuggestions, + new SuggestedWords(typedWordAndPreviousSuggestions, false /* typedWordValid */, - false /* hasMinimalSuggestion */, + false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index df0e1696b..d88047c32 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -183,9 +183,9 @@ public class SettingsValues { KeySpecParser.getLabel(puncSpec))); } } - return SuggestedWords.getSuggestedWords(puncList, + return new SuggestedWords(puncList, false /* typedWordValid */, - false /* hasMinimalSuggestion */, + false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); @@ -205,9 +205,9 @@ public class SettingsValues { } } } - return SuggestedWords.getSuggestedWords(puncOutputTextList, + return new SuggestedWords(puncOutputTextList, false /* typedWordValid */, - false /* hasMinimalSuggestion */, + false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index fea1b83bb..7ac00a34e 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -269,10 +269,9 @@ public class Suggest implements Dictionary.WordCallback { StringUtils.removeDupes(mSuggestions); - return SuggestedWords.getSuggestedWords( - SuggestedWords.getFromCharSequenceList(mSuggestions), + return new SuggestedWords(SuggestedWords.getFromCharSequenceList(mSuggestions), false /* typedWordValid */, - false /* hasMinimalSuggestion */, + false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* shouldBlockAutoCorrectionBySafetyNet */); @@ -445,9 +444,9 @@ public class Suggest implements Dictionary.WordCallback { } else { shouldBlockAutoCorrectionBySatefyNet = false; } - return SuggestedWords.getSuggestedWords(scoreInfoList, + return new SuggestedWords(scoreInfoList, !allowsToBeAutoCorrected /* typedWordValid */, - autoCorrectionAvailable /* hasMinimalSuggestion */, + autoCorrectionAvailable /* hasAutoCorrectionCandidate */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, shouldBlockAutoCorrectionBySatefyNet); diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 60b55f58e..7ce1049d7 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -33,7 +33,7 @@ public class SuggestedWords { public final boolean mAllowsToBeAutoCorrected; private final List mSuggestedWordInfoList; - private SuggestedWords(final List suggestedWordInfoList, + public SuggestedWords(final List suggestedWordInfoList, final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, @@ -76,21 +76,6 @@ public class SuggestedWords { + " mIsPunctuationSuggestions=" + mIsPunctuationSuggestions; } - public static SuggestedWords getSuggestedWords( - final List suggestedWordInfoList, - final boolean typedWordValid, - final boolean hasMinimalSuggestion, - final boolean allowsToBeAutoCorrected, - final boolean isPunctuationSuggestions, - final boolean shouldBlockAutoCorrectionBySafetyNet) { - return new SuggestedWords(suggestedWordInfoList, - typedWordValid, - hasMinimalSuggestion, - allowsToBeAutoCorrected, - isPunctuationSuggestions, - shouldBlockAutoCorrectionBySafetyNet); - } - public static ArrayList getFromCharSequenceList( final List wordList) { final ArrayList result = new ArrayList(); -- cgit v1.2.3-83-g751a From f985efe39c98d03125884b140d7c64bb28914018 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 14 Mar 2012 18:12:12 +0900 Subject: Remove a useless parameter Change-Id: I03005240238fb004c20b2df0d836796e2e8b307f --- java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++---- java/src/com/android/inputmethod/latin/SettingsValues.java | 6 ++---- java/src/com/android/inputmethod/latin/Suggest.java | 9 ++++----- java/src/com/android/inputmethod/latin/SuggestedWords.java | 8 +++----- 4 files changed, 11 insertions(+), 18 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6570f7a2f..9f5931de9 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -931,8 +931,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */, - false /* shouldBlockAutoCorrectionBySafetyNet */); + false /* isPunctuationSuggestions */); // When in fullscreen mode, show completions generated by the application final boolean isAutoCorrection = false; setSuggestions(suggestedWords, isAutoCorrection); @@ -1794,8 +1793,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */, - false /* shouldBlockAutoCorrectionBySafetyNet */); + false /* isPunctuationSuggestions */); showSuggestions(obsoleteSuggestedWords, typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d88047c32..d12b9c428 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -187,8 +187,7 @@ public class SettingsValues { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */, - false /* shouldBlockAutoCorrectionBySafetyNet */); + true /* isPunctuationSuggestions */); } private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { @@ -209,8 +208,7 @@ public class SettingsValues { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */, - false /* shouldBlockAutoCorrectionBySafetyNet */); + true /* isPunctuationSuggestions */); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 7ac00a34e..b93626caa 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -273,8 +273,7 @@ public class Suggest implements Dictionary.WordCallback { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */, - false /* shouldBlockAutoCorrectionBySafetyNet */); + false /* isPunctuationSuggestions */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -446,10 +445,10 @@ public class Suggest implements Dictionary.WordCallback { } return new SuggestedWords(scoreInfoList, !allowsToBeAutoCorrected /* typedWordValid */, - autoCorrectionAvailable /* hasAutoCorrectionCandidate */, + autoCorrectionAvailable & !shouldBlockAutoCorrectionBySatefyNet + /* hasAutoCorrectionCandidate */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */, - shouldBlockAutoCorrectionBySatefyNet); + false /* isPunctuationSuggestions */); } @Override diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 7ce1049d7..201e0f410 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -25,7 +25,7 @@ import java.util.List; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - Collections.emptyList(), false, false, false, false, false); + Collections.emptyList(), false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; @@ -37,12 +37,10 @@ public class SuggestedWords { final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, - final boolean isPunctuationSuggestions, - final boolean shouldBlockAutoCorrectionBySafetyNet) { + final boolean isPunctuationSuggestions) { mSuggestedWordInfoList = suggestedWordInfoList; mTypedWordValid = typedWordValid; - mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate - && !shouldBlockAutoCorrectionBySafetyNet; + mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; mIsPunctuationSuggestions = isPunctuationSuggestions; } -- cgit v1.2.3-83-g751a From 5f9593593ebaa32e17d5f26918a0efef87f0a83b Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 15 Mar 2012 12:47:05 +0900 Subject: Remove useless stuff Change-Id: I43dae30774c40a9d6e7396f8fa73ed4b82a7c777 --- .../android/inputmethod/latin/SettingsValues.java | 35 ---------------------- 1 file changed, 35 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d12b9c428..be9c5cf4c 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -42,9 +42,7 @@ public class SettingsValues { public final String mWeakSpaceStrippers; public final String mWeakSpaceSwappers; private final String mPhantomSpacePromotingSymbols; - private final String mSuggestPuncs; public final SuggestedWords mSuggestPuncList; - public final SuggestedWords mSuggestPuncOutputTextList; private final String mSymbolsExcludedFromWordSeparators; public final String mWordSeparators; public final CharSequence mHintToSaveText; @@ -110,9 +108,7 @@ public class SettingsValues { } final String[] suggestPuncsSpec = KeySpecParser.parseCsvString( res.getString(R.string.suggested_punctuations), res, R.string.english_ime_name); - mSuggestPuncs = createSuggestPuncs(suggestPuncsSpec); mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec); - mSuggestPuncOutputTextList = createSuggestPuncOutputTextList(suggestPuncsSpec); mSymbolsExcludedFromWordSeparators = res.getString(R.string.symbols_excluded_from_word_separators); mWordSeparators = createWordSeparators(mWeakSpaceStrippers, mWeakSpaceSwappers, @@ -164,16 +160,6 @@ public class SettingsValues { } // Helper functions to create member values. - private static String createSuggestPuncs(final String[] puncs) { - final StringBuilder sb = new StringBuilder(); - if (puncs != null) { - for (final String puncSpec : puncs) { - sb.append(KeySpecParser.getLabel(puncSpec)); - } - } - return sb.toString(); - } - private static SuggestedWords createSuggestPuncList(final String[] puncs) { final ArrayList puncList = new ArrayList(); @@ -190,27 +176,6 @@ public class SettingsValues { true /* isPunctuationSuggestions */); } - private static SuggestedWords createSuggestPuncOutputTextList(final String[] puncs) { - final ArrayList puncOutputTextList = - new ArrayList(); - if (puncs != null) { - for (final String puncSpec : puncs) { - final String outputText = KeySpecParser.getOutputText(puncSpec); - if (outputText != null) { - puncOutputTextList.add(new SuggestedWords.SuggestedWordInfo(outputText)); - } else { - puncOutputTextList.add(new SuggestedWords.SuggestedWordInfo( - KeySpecParser.getLabel(puncSpec))); - } - } - } - return new SuggestedWords(puncOutputTextList, - false /* typedWordValid */, - false /* hasAutoCorrectionCandidate */, - false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */); - } - private static String createWordSeparators(final String weakSpaceStrippers, final String weakSpaceSwappers, final String symbolsExcludedFromWordSeparators, final Resources res) { -- cgit v1.2.3-83-g751a From 03a35170751a635332c00bf6c272a0127a255cf6 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 15 Mar 2012 13:12:08 +0900 Subject: Add info for obsolete suggestions in SuggestedWords Change-Id: I9684c7b08244b34853ce8a99b6e9d885389f6687 --- java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++++-- java/src/com/android/inputmethod/latin/SettingsValues.java | 3 ++- java/src/com/android/inputmethod/latin/Suggest.java | 6 ++++-- java/src/com/android/inputmethod/latin/SuggestedWords.java | 7 +++++-- 4 files changed, 15 insertions(+), 7 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 9f5931de9..42dd766fa 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -931,7 +931,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); // When in fullscreen mode, show completions generated by the application final boolean isAutoCorrection = false; setSuggestions(suggestedWords, isAutoCorrection); @@ -1793,7 +1794,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + true /* isObsoleteSuggestions */); showSuggestions(obsoleteSuggestedWords, typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index be9c5cf4c..4346a3671 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -173,7 +173,8 @@ public class SettingsValues { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - true /* isPunctuationSuggestions */); + true /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index c0ec4f614..79a819d1e 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -274,7 +274,8 @@ public class Suggest implements Dictionary.WordCallback { false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -413,7 +414,8 @@ public class Suggest implements Dictionary.WordCallback { !allowsToBeAutoCorrected /* typedWordValid */, autoCorrectionAvailable /* hasAutoCorrectionCandidate */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */); + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */); } // This assumes the scores[] array is at least as long as suggestions.size() - 1. diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 6b231f81c..3c5e65f16 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -27,24 +27,27 @@ import java.util.List; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - Collections.emptyList(), false, false, false, false); + Collections.emptyList(), false, false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; public final boolean mAllowsToBeAutoCorrected; + public final boolean mIsObsoleteSuggestions; private final List mSuggestedWordInfoList; public SuggestedWords(final List suggestedWordInfoList, final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, - final boolean isPunctuationSuggestions) { + final boolean isPunctuationSuggestions, + final boolean isObsoleteSuggestions) { mSuggestedWordInfoList = suggestedWordInfoList; mTypedWordValid = typedWordValid; mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; mIsPunctuationSuggestions = isPunctuationSuggestions; + mIsObsoleteSuggestions = isObsoleteSuggestions; } public int size() { -- cgit v1.2.3-83-g751a From 660776e09b9a3b321074a94721d901a035ca1b9f Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Sat, 17 Mar 2012 00:50:51 +0900 Subject: Small performance improvement by removing interface accesses. Change-Id: I6d91f3b086470b79306dbe2874db9748b9e0eb5f --- .../src/com/android/inputmethod/keyboard/KeyboardSet.java | 5 ++--- .../src/com/android/inputmethod/latin/AutoCorrection.java | 14 +++++++------- .../android/inputmethod/latin/BinaryDictionaryGetter.java | 5 ++--- .../android/inputmethod/latin/DictionaryCollection.java | 3 +-- .../com/android/inputmethod/latin/DictionaryFactory.java | 6 +++--- java/src/com/android/inputmethod/latin/LatinIME.java | 3 +-- .../src/com/android/inputmethod/latin/LatinImeLogger.java | 2 -- .../src/com/android/inputmethod/latin/SettingsValues.java | 2 -- java/src/com/android/inputmethod/latin/Suggest.java | 15 +++++++-------- .../src/com/android/inputmethod/latin/SuggestedWords.java | 12 +++++------- java/src/com/android/inputmethod/latin/XmlParseUtils.java | 4 ++++ .../inputmethod/latin/suggestions/SuggestionsView.java | 9 ++++----- 12 files changed, 36 insertions(+), 44 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 680ff0d25..52096c843 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.lang.ref.SoftReference; import java.util.HashMap; import java.util.Locale; -import java.util.Map; /** * This class represents a set of keyboards. Each of them represents a different keyboard @@ -75,7 +74,7 @@ public class KeyboardSet { } public static class KeysCache { - private final Map mMap; + private final HashMap mMap; public KeysCache() { mMap = new HashMap(); @@ -108,7 +107,7 @@ public class KeyboardSet { int mOrientation; int mWidth; // KeyboardSet element id to keyboard layout XML id map. - final Map mKeyboardSetElementIdToXmlIdMap = + final HashMap mKeyboardSetElementIdToXmlIdMap = new HashMap(); Params() {} } diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index 9c35f8f6f..ef88f9906 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -20,7 +20,7 @@ import android.text.TextUtils; import android.util.Log; import java.util.ArrayList; -import java.util.Map; +import java.util.HashMap; public class AutoCorrection { private static final boolean DBG = LatinImeLogger.sDBG; @@ -30,7 +30,7 @@ public class AutoCorrection { // Purely static class: can't instantiate. } - public static CharSequence computeAutoCorrectionWord(Map dictionaries, + public static CharSequence computeAutoCorrectionWord(HashMap dictionaries, WordComposer wordComposer, ArrayList suggestions, int[] sortedScores, CharSequence consideredWord, double autoCorrectionThreshold, CharSequence whitelistedWord) { @@ -47,7 +47,7 @@ public class AutoCorrection { } public static boolean isValidWord( - Map dictionaries, CharSequence word, boolean ignoreCase) { + HashMap dictionaries, CharSequence word, boolean ignoreCase) { if (TextUtils.isEmpty(word)) { return false; } @@ -72,7 +72,7 @@ public class AutoCorrection { } public static boolean allowsToBeAutoCorrected( - Map dictionaries, CharSequence word, boolean ignoreCase) { + HashMap dictionaries, CharSequence word, boolean ignoreCase) { final WhitelistDictionary whitelistDictionary = (WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST); // If "word" is in the whitelist dictionary, it should not be auto corrected. @@ -87,9 +87,9 @@ public class AutoCorrection { return whiteListedWord != null; } - private static boolean hasAutoCorrectionForConsideredWord(Map dictionaries, - WordComposer wordComposer, ArrayList suggestions, - CharSequence consideredWord) { + private static boolean hasAutoCorrectionForConsideredWord( + HashMap dictionaries, WordComposer wordComposer, + ArrayList suggestions, CharSequence consideredWord) { if (TextUtils.isEmpty(consideredWord)) return false; return wordComposer.size() > 1 && suggestions.size() > 0 && !allowsToBeAutoCorrected(dictionaries, consideredWord, false); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 79441c557..1c24cd11d 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -25,7 +25,6 @@ import android.util.Log; import java.io.File; import java.util.ArrayList; -import java.util.List; import java.util.Locale; /** @@ -264,9 +263,9 @@ class BinaryDictionaryGetter { * - Gets a file name from the fallback resource passed as an argument. * If that fails: * - Returns null. - * @return The address of a valid file, or null. + * @return The list of addresses of valid dictionary files, or null. */ - public static List getDictionaryFiles(final Locale locale, + public static ArrayList getDictionaryFiles(final Locale locale, final Context context, final int fallbackResId) { // cacheWordListsFromContentProvider returns the list of files it copied to local diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index c19a5a718..5de770a4a 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -22,7 +22,6 @@ import android.util.Log; import java.util.Collection; import java.util.Collections; -import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; /** @@ -30,7 +29,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class DictionaryCollection extends Dictionary { private final String TAG = DictionaryCollection.class.getSimpleName(); - protected final List mDictionaries; + protected final CopyOnWriteArrayList mDictionaries; public DictionaryCollection() { mDictionaries = new CopyOnWriteArrayList(); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 7a81f7bd5..77c685c50 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -22,8 +22,8 @@ import android.content.res.Resources; import android.util.Log; import java.io.File; +import java.util.ArrayList; import java.util.LinkedList; -import java.util.List; import java.util.Locale; /** @@ -52,8 +52,8 @@ public class DictionaryFactory { return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale)); } - final List dictList = new LinkedList(); - final List assetFileList = + final LinkedList dictList = new LinkedList(); + final ArrayList assetFileList = BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId); if (null != assetFileList) { for (final AssetFileAddress f : assetFileList) { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 234a501de..d5cd35db6 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -73,7 +73,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.List; import java.util.Locale; /** @@ -919,7 +918,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - final List applicationSuggestedWords = + final ArrayList applicationSuggestedWords = SuggestedWords.getFromApplicationSpecifiedCompletions( applicationSpecifiedCompletions); final SuggestedWords suggestedWords = new SuggestedWords( diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index 5390ee39e..683dafa86 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -22,8 +22,6 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.keyboard.Keyboard; -import java.util.List; - public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener { public static boolean sDBG = false; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 4346a3671..020b57caf 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -30,8 +30,6 @@ import com.android.inputmethod.keyboard.internal.KeySpecParser; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.List; import java.util.Locale; public class SettingsValues { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 69754d769..08f0e425b 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -30,15 +30,12 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Locale; -import java.util.Map; -import java.util.Set; /** * This class loads a dictionary and provides a list of suggestions for a given sequence of * characters. This includes corrections and completions. */ public class Suggest implements Dictionary.WordCallback { - public static final String TAG = Suggest.class.getSimpleName(); public static final int APPROX_MAX_WORD_LENGTH = 32; @@ -87,8 +84,10 @@ public class Suggest implements Dictionary.WordCallback { private Dictionary mMainDict; private ContactsDictionary mContactsDict; private WhitelistDictionary mWhiteListDictionary; - private final Map mUnigramDictionaries = new HashMap(); - private final Map mBigramDictionaries = new HashMap(); + private final HashMap mUnigramDictionaries = + new HashMap(); + private final HashMap mBigramDictionaries = + new HashMap(); private int mPrefMaxSuggestions = 18; @@ -142,7 +141,7 @@ public class Suggest implements Dictionary.WordCallback { initWhitelistAndAutocorrectAndPool(context, locale); } - private static void addOrReplaceDictionary(Map dictionaries, String key, + private static void addOrReplaceDictionary(HashMap dictionaries, String key, Dictionary dict) { final Dictionary oldDict = (dict == null) ? dictionaries.remove(key) @@ -177,7 +176,7 @@ public class Suggest implements Dictionary.WordCallback { return mContactsDict; } - public Map getUnigramDictionaries() { + public HashMap getUnigramDictionaries() { return mUnigramDictionaries; } @@ -563,7 +562,7 @@ public class Suggest implements Dictionary.WordCallback { } public void close() { - final Set dictionaries = new HashSet(); + final HashSet dictionaries = new HashSet(); dictionaries.addAll(mUnigramDictionaries.values()); dictionaries.addAll(mBigramDictionaries.values()); for (final Dictionary dictionary : dictionaries) { diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index b63bc6c29..ef8e58e0c 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -21,22 +21,20 @@ import android.view.inputmethod.CompletionInfo; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; -import java.util.List; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - Collections.emptyList(), false, false, false, false, false); + new ArrayList(0), false, false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; public final boolean mAllowsToBeAutoCorrected; public final boolean mIsObsoleteSuggestions; - private final List mSuggestedWordInfoList; + private final ArrayList mSuggestedWordInfoList; - public SuggestedWords(final List suggestedWordInfoList, + public SuggestedWords(final ArrayList suggestedWordInfoList, final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, @@ -82,7 +80,7 @@ public class SuggestedWords { } public static ArrayList getFromCharSequenceList( - final List wordList) { + final ArrayList wordList) { final ArrayList result = new ArrayList(); for (CharSequence word : wordList) { if (null != word) result.add(new SuggestedWordInfo(word)); @@ -90,7 +88,7 @@ public class SuggestedWords { return result; } - public static List getFromApplicationSpecifiedCompletions( + public static ArrayList getFromApplicationSpecifiedCompletions( final CompletionInfo[] infos) { final ArrayList result = new ArrayList(); for (CompletionInfo info : infos) { diff --git a/java/src/com/android/inputmethod/latin/XmlParseUtils.java b/java/src/com/android/inputmethod/latin/XmlParseUtils.java index e14c71cb5..481cdfa47 100644 --- a/java/src/com/android/inputmethod/latin/XmlParseUtils.java +++ b/java/src/com/android/inputmethod/latin/XmlParseUtils.java @@ -24,6 +24,10 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; public class XmlParseUtils { + private XmlParseUtils() { + // This utility class is not publicly instantiable. + } + @SuppressWarnings("serial") public static class ParseException extends XmlPullParserException { public ParseException(String msg, XmlPullParser parser) { diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index d3c3afb73..286bf0aea 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -66,7 +66,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.Utils; import java.util.ArrayList; -import java.util.List; public class SuggestionsView extends RelativeLayout implements OnClickListener, OnLongClickListener { @@ -144,9 +143,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, public final float mMinMoreSuggestionsWidth; public final int mMoreSuggestionsBottomGap; - private final List mWords; - private final List mDividers; - private final List mInfos; + private final ArrayList mWords; + private final ArrayList mDividers; + private final ArrayList mInfos; private final int mColorValidTypedWord; private final int mColorTypedWord; @@ -174,7 +173,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, private final TextView mHintToSaveView; public SuggestionsViewParams(Context context, AttributeSet attrs, int defStyle, - List words, List dividers, List infos) { + ArrayList words, ArrayList dividers, ArrayList infos) { mWords = words; mDividers = dividers; mInfos = infos; -- cgit v1.2.3-83-g751a From 728d1c884e99e1fd25aa253b5ad30dbdb046ad5f Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 19 Mar 2012 14:47:38 +0900 Subject: Cleanup proximity related code Bug: 4343280 Change-Id: I57c0f9e20d9d8911009ea97057251a7f7a81512f --- java/res/values-en/additional-proximitychars.xml | 62 ------- java/res/values/additional-proximitychars.xml | 23 --- .../android/inputmethod/keyboard/KeyDetector.java | 185 +-------------------- .../com/android/inputmethod/keyboard/Keyboard.java | 36 +--- .../inputmethod/keyboard/LatinKeyboardView.java | 1 - .../inputmethod/keyboard/MoreKeysDetector.java | 28 ---- .../inputmethod/keyboard/ProximityInfo.java | 35 +--- .../android/inputmethod/latin/InputAttributes.java | 1 + .../android/inputmethod/latin/SettingsValues.java | 1 - .../android/inputmethod/latin/WordComposer.java | 9 +- .../latin/suggestions/MoreSuggestions.java | 3 - .../latin/suggestions/SuggestionsView.java | 1 - 12 files changed, 13 insertions(+), 372 deletions(-) delete mode 100644 java/res/values-en/additional-proximitychars.xml delete mode 100644 java/res/values/additional-proximitychars.xml (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values-en/additional-proximitychars.xml b/java/res/values-en/additional-proximitychars.xml deleted file mode 100644 index a5ff4a979..000000000 --- a/java/res/values-en/additional-proximitychars.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - a - e - i - o - u - - - e - a - i - o - u - - - i - a - e - o - u - - - o - a - e - i - u - - - u - a - e - i - o - - - - diff --git a/java/res/values/additional-proximitychars.xml b/java/res/values/additional-proximitychars.xml deleted file mode 100644 index 03d10d5d8..000000000 --- a/java/res/values/additional-proximitychars.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/java/src/com/android/inputmethod/keyboard/KeyDetector.java b/java/src/com/android/inputmethod/keyboard/KeyDetector.java index c2ad56d9f..13e909c7e 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyDetector.java +++ b/java/src/com/android/inputmethod/keyboard/KeyDetector.java @@ -16,17 +16,9 @@ package com.android.inputmethod.keyboard; -import android.util.Log; - -import java.util.Arrays; -import java.util.List; public class KeyDetector { - private static final String TAG = KeyDetector.class.getSimpleName(); - private static final boolean DEBUG = false; - public static final int NOT_A_CODE = -1; - private static final int ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE = 2; private final int mKeyHysteresisDistanceSquared; @@ -34,12 +26,6 @@ public class KeyDetector { private int mCorrectionX; private int mCorrectionY; private boolean mProximityCorrectOn; - private int mProximityThresholdSquare; - - // working area - private static final int MAX_NEARBY_KEYS = 12; - private final int[] mDistances = new int[MAX_NEARBY_KEYS]; - private final Key[] mNeighborKeys = new Key[MAX_NEARBY_KEYS]; /** * This class handles key detection. @@ -57,8 +43,6 @@ public class KeyDetector { mCorrectionX = (int)correctionX; mCorrectionY = (int)correctionY; mKeyboard = keyboard; - final int threshold = keyboard.mMostCommonKeyWidth; - mProximityThresholdSquare = threshold * threshold; } public int getKeyHysteresisDistanceSquared() { @@ -87,168 +71,10 @@ public class KeyDetector { return mProximityCorrectOn; } - public void setProximityThreshold(int threshold) { - mProximityThresholdSquare = threshold * threshold; - } - public boolean alwaysAllowsSlidingInput() { return false; } - /** - * Computes maximum size of the array that can contain all nearby key codes returned by - * {@link #getNearbyCodes}. - * - * @return Returns maximum size of the array that can contain all nearby key codes returned - * by {@link #getNearbyCodes}. - */ - protected int getMaxNearbyKeys() { - return MAX_NEARBY_KEYS; - } - - /** - * Allocates array that can hold all key codes returned by {@link #getNearbyCodes} - * method. The maximum size of the array should be computed by {@link #getMaxNearbyKeys}. - * - * @return Allocates and returns an array that can hold all key codes returned by - * {@link #getNearbyCodes} method. All elements in the returned array are - * initialized by {@link #NOT_A_CODE} value. - */ - public int[] newCodeArray() { - int[] codes = new int[getMaxNearbyKeys()]; - Arrays.fill(codes, NOT_A_CODE); - return codes; - } - - private void initializeNearbyKeys() { - Arrays.fill(mDistances, Integer.MAX_VALUE); - Arrays.fill(mNeighborKeys, null); - } - - /** - * Insert the key into nearby keys buffer and sort nearby keys by ascending order of distance. - * If the distance of two keys are the same, the key which the point is on should be considered - * as a closer one. - * - * @param key the key to be inserted into the nearby keys buffer. - * @param distance distance between the key's edge and user touched point. - * @param isOnKey true if the point is on the key. - * @return order of the key in the nearby buffer, 0 if it is the nearest key. - */ - private int sortNearbyKeys(Key key, int distance, boolean isOnKey) { - final int[] distances = mDistances; - final Key[] neighborKeys = mNeighborKeys; - for (int insertPos = 0; insertPos < distances.length; insertPos++) { - final int comparingDistance = distances[insertPos]; - if (distance < comparingDistance || (distance == comparingDistance && isOnKey)) { - final int nextPos = insertPos + 1; - if (nextPos < distances.length) { - System.arraycopy(distances, insertPos, distances, nextPos, - distances.length - nextPos); - System.arraycopy(neighborKeys, insertPos, neighborKeys, nextPos, - neighborKeys.length - nextPos); - } - distances[insertPos] = distance; - neighborKeys[insertPos] = key; - return insertPos; - } - } - return distances.length; - } - - private void getNearbyKeyCodes(final int primaryCode, final int[] allCodes) { - final Key[] neighborKeys = mNeighborKeys; - final int maxCodesSize = allCodes.length; - - // allCodes[0] should always have the key code even if it is a non-letter key. - if (neighborKeys[0] == null) { - allCodes[0] = NOT_A_CODE; - return; - } - - int numCodes = 0; - for (int j = 0; j < neighborKeys.length && numCodes < maxCodesSize; j++) { - final Key key = neighborKeys[j]; - if (key == null) - break; - final int code = key.mCode; - // filter out a non-letter key from nearby keys - if (code < Keyboard.CODE_SPACE) - continue; - allCodes[numCodes++] = code; - } - if (maxCodesSize <= numCodes) { - return; - } - - final int code = (primaryCode == NOT_A_CODE) ? allCodes[0] : primaryCode; - if (code == NOT_A_CODE) { - return; - } - final List additionalChars = mKeyboard.getAdditionalProximityChars().get(code); - if (additionalChars == null || additionalChars.size() == 0) { - return; - } - int currentCodesSize = numCodes; - allCodes[numCodes++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE; - if (maxCodesSize <= numCodes) { - return; - } - // TODO: This is O(N^2). Assuming additionalChars.size() is up to 4 or 5. - for (int i = 0; i < additionalChars.size(); ++i) { - final int additionalChar = additionalChars.get(i); - boolean contains = false; - for (int j = 0; j < currentCodesSize; ++j) { - if (additionalChar == allCodes[j]) { - contains = true; - break; - } - } - if (!contains) { - allCodes[numCodes++] = additionalChar; - if (maxCodesSize <= numCodes) { - return; - } - } - } - } - - /** - * Finds all possible nearby key codes around a touch event point and returns the nearest key. - * The algorithm to determine the nearby keys depends on the threshold set by - * {@link #setProximityThreshold(int)} and the mode set by - * {@link #setProximityCorrectionEnabled(boolean)}. - * - * @param x The x-coordinate of a touch point - * @param y The y-coordinate of a touch point - * @param allCodes All nearby key codes except functional key are returned in this array - */ - // TODO: Move this method to native code. - public void getNearbyCodes(int x, int y, final int[] allCodes) { - final int touchX = getTouchX(x); - final int touchY = getTouchY(y); - - initializeNearbyKeys(); - Key primaryKey = null; - for (final Key key : mKeyboard.getNearestKeys(touchX, touchY)) { - final boolean isOnKey = key.isOnKey(touchX, touchY); - final int distance = key.squaredDistanceToEdge(touchX, touchY); - if (isOnKey || (mProximityCorrectOn && distance < mProximityThresholdSquare)) { - final int insertedPosition = sortNearbyKeys(key, distance, isOnKey); - if (insertedPosition == 0 && isOnKey) { - primaryKey = key; - } - } - } - - getNearbyKeyCodes(primaryKey != null ? primaryKey.mCode : NOT_A_CODE, allCodes); - if (DEBUG) { - Log.d(TAG, "x=" + x + " y=" + y - + " primary=" + printableCode(primaryKey) - + " codes=" + printableCodes(allCodes)); - } - } - /** * Detect the key whose hitbox the touch point is in. * @@ -284,14 +110,9 @@ public class KeyDetector { boolean addDelimiter = false; for (final int code : codes) { if (code == NOT_A_CODE) break; - if (code == ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE) { - sb.append(" | "); - addDelimiter = false; - } else { - if (addDelimiter) sb.append(", "); - sb.append(Keyboard.printableCode(code)); - addDelimiter = true; - } + if (addDelimiter) sb.append(", "); + sb.append(Keyboard.printableCode(code)); + addDelimiter = true; } return "[" + sb + "]"; } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 973f64b4d..2b1cc43cd 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -20,7 +20,6 @@ import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; -import android.text.TextUtils; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; @@ -42,8 +41,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; -import java.util.List; -import java.util.Map; /** * Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard @@ -133,8 +130,6 @@ public class Keyboard { private final ProximityInfo mProximityInfo; - private final Map> mAdditionalProximityChars; - public Keyboard(Params params) { mId = params.mId; mThemeId = params.mThemeId; @@ -153,12 +148,10 @@ public class Keyboard { mAltCodeKeysWhileTyping = params.mAltCodeKeysWhileTyping.toArray( new Key[params.mAltCodeKeysWhileTyping.size()]); mIconsSet = params.mIconsSet; - mAdditionalProximityChars = params.mAdditionalProximityChars; mProximityInfo = new ProximityInfo(params.mId.mLocale.toString(), params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight, - mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrection, - params.mAdditionalProximityChars); + mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrection); } public ProximityInfo getProximityInfo() { @@ -230,9 +223,6 @@ public class Keyboard { public final ArrayList mShiftKeys = new ArrayList(); public final ArrayList mAltCodeKeysWhileTyping = new ArrayList(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); - // TODO: Should be in Key instead of Keyboard.Params? - public final Map> mAdditionalProximityChars = - new HashMap>(); public KeyboardSet.KeysCache mKeysCache; @@ -368,10 +358,6 @@ public class Keyboard { return mProximityInfo.getNearestKeys(adjustedX, adjustedY); } - public Map> getAdditionalProximityChars() { - return mAdditionalProximityChars; - } - public static String printableCode(int code) { switch (code) { case CODE_SHIFT: return "shift"; @@ -630,7 +616,6 @@ public class Keyboard { mParams = params; setTouchPositionCorrectionData(context, params); - setAdditionalProximityChars(context, params); params.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width); params.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height); @@ -653,25 +638,6 @@ public class Keyboard { params.mTouchPositionCorrection.load(data); } - private static void setAdditionalProximityChars(Context context, Params params) { - final String[] additionalChars = - context.getResources().getStringArray(R.array.additional_proximitychars); - int currentPrimaryIndex = 0; - for (int i = 0; i < additionalChars.length; ++i) { - final String additionalChar = additionalChars[i]; - if (TextUtils.isEmpty(additionalChar)) { - currentPrimaryIndex = 0; - } else if (currentPrimaryIndex == 0) { - currentPrimaryIndex = additionalChar.charAt(0); - params.mAdditionalProximityChars.put( - currentPrimaryIndex, new ArrayList()); - } else if (currentPrimaryIndex != 0) { - final int c = additionalChar.charAt(0); - params.mAdditionalProximityChars.get(currentPrimaryIndex).add(c); - } - } - } - public void setAutoGenerate(KeyboardSet.KeysCache keysCache) { mParams.mKeysCache = keysCache; } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 343842552..b869059e4 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -480,7 +480,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke super.setKeyboard(keyboard); mKeyDetector.setKeyboard( keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); - mKeyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth); PointerTracker.setKeyDetector(mKeyDetector); mTouchScreenRegulator.setKeyboard(keyboard); mMoreKeysPanelCache.clear(); diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java b/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java index 6c8d02016..cd4e3001e 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysDetector.java @@ -32,34 +32,6 @@ public class MoreKeysDetector extends KeyDetector { return true; } - @Override - protected int getMaxNearbyKeys() { - // No nearby key will be returned. - return 1; - } - - @Override - public void getNearbyCodes(int x, int y, final int[] allCodes) { - final int touchX = getTouchX(x); - final int touchY = getTouchY(y); - - Key nearestKey = null; - int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare; - for (final Key key : getKeyboard().mKeys) { - final int dist = key.squaredDistanceToEdge(touchX, touchY); - if (dist < nearestDist) { - nearestKey = key; - nearestDist = dist; - } - } - - if (nearestKey != null) { - allCodes[0] = nearestKey.mCode; - } else { - allCodes[0] = NOT_A_CODE; - } - } - @Override public Key detectHitKey(int x, int y) { final int touchX = getTouchX(x); diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index 61d75e278..442413c0c 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -24,10 +24,7 @@ import com.android.inputmethod.latin.JniUtils; import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.List; -import java.util.Map; public class ProximityInfo { public static final int MAX_PROXIMITY_CHARS_SIZE = 16; @@ -50,8 +47,7 @@ public class ProximityInfo { ProximityInfo(String localeStr, int gridWidth, int gridHeight, int minWidth, int height, int mostCommonKeyWidth, int mostCommonKeyHeight, final Key[] keys, - TouchPositionCorrection touchPositionCorrection, - Map> additionalProximityChars) { + TouchPositionCorrection touchPositionCorrection) { if (TextUtils.isEmpty(localeStr)) { mLocaleStr = ""; } else { @@ -72,12 +68,11 @@ public class ProximityInfo { return; } computeNearestNeighbors( - mostCommonKeyWidth, keys, touchPositionCorrection, additionalProximityChars); + mostCommonKeyWidth, keys, touchPositionCorrection); } public static ProximityInfo createDummyProximityInfo() { - return new ProximityInfo("", 1, 1, 1, 1, 1, 1, EMPTY_KEY_ARRAY, null, - Collections.> emptyMap()); + return new ProximityInfo("", 1, 1, 1, 1, 1, 1, EMPTY_KEY_ARRAY, null); } public static ProximityInfo createSpellCheckerProximityInfo(final int[] proximity) { @@ -184,8 +179,7 @@ public class ProximityInfo { } private void computeNearestNeighbors(int defaultWidth, final Key[] keys, - TouchPositionCorrection touchPositionCorrection, - Map> additionalProximityChars) { + TouchPositionCorrection touchPositionCorrection) { final HashMap keyCodeMap = new HashMap(); for (final Key key : keys) { keyCodeMap.put(key.mCode, key); @@ -207,27 +201,6 @@ public class ProximityInfo { neighborKeys[count++] = key; } } - int currentCodesSize = count; - for (int i = 0; i < currentCodesSize; ++i) { - final int c = neighborKeys[i].mCode; - final List additionalChars = additionalProximityChars.get(c); - if (additionalChars == null || additionalChars.size() == 0) { - continue; - } - for (int j = 0; j < additionalChars.size(); ++j) { - final int additionalChar = additionalChars.get(j); - boolean contains = false; - for (int k = 0; k < count; ++k) { - if(additionalChar == neighborKeys[k].mCode) { - contains = true; - break; - } - } - if (!contains) { - neighborKeys[count++] = keyCodeMap.get(additionalChar); - } - } - } mGridNeighbors[(y / mCellHeight) * mGridWidth + (x / mCellWidth)] = Arrays.copyOfRange(neighborKeys, 0, count); } diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java index f7afed2a5..06c70c42c 100644 --- a/java/src/com/android/inputmethod/latin/InputAttributes.java +++ b/java/src/com/android/inputmethod/latin/InputAttributes.java @@ -95,6 +95,7 @@ public class InputAttributes { } } + @SuppressWarnings("unused") private void dumpFlags(final int inputType) { Log.i(TAG, "Input class:"); final int inputClass = inputType & InputType.TYPE_MASK_CLASS; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 020b57caf..9fc047b75 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -23,7 +23,6 @@ import android.os.Build; import android.util.Log; import android.view.inputmethod.EditorInfo; -import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 251063ec4..9f23f174f 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -141,6 +141,7 @@ public class WordComposer { keyY = y; } else { final Key key = keyDetector.detectHitKey(x, y); + // TODO: Pass an integer instead of an integer array codes = new int[] { key != null ? key.mCode : NOT_A_CODE }; keyX = keyDetector.getTouchX(x); keyY = keyDetector.getTouchY(y); @@ -202,9 +203,8 @@ public class WordComposer { if (key.mCode == codePoint) { final int x = key.mX + key.mWidth / 2; final int y = key.mY + key.mHeight / 2; - final int[] codes = keyDetector.newCodeArray(); - keyDetector.getNearbyCodes(x, y, codes); - add(codePoint, codes, x, y); + // TODO: Pass an integer instead of an integer array + add(codePoint, new int[] { key.mCode }, x, y); return; } } @@ -216,7 +216,7 @@ public class WordComposer { * Set the currently composing word to the one passed as an argument. * This will register NOT_A_COORDINATE for X and Ys, and use the passed keyboard for proximity. */ - public void setComposingWord(final CharSequence word, final Keyboard keyboard, + private void setComposingWord(final CharSequence word, final Keyboard keyboard, final KeyDetector keyDetector) { reset(); final int length = word.length(); @@ -233,7 +233,6 @@ public class WordComposer { final KeyDetector keyDetector = new KeyDetector(0); keyDetector.setKeyboard(keyboard, 0, 0); keyDetector.setProximityCorrectionEnabled(true); - keyDetector.setProximityThreshold(keyboard.mMostCommonKeyWidth); setComposingWord(word, keyboard, keyDetector); } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index c9c88fd23..3a17f1f64 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -25,7 +25,6 @@ import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; -import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.Utils; @@ -38,8 +37,6 @@ public class MoreSuggestions extends Keyboard { } public static class Builder extends Keyboard.Builder { - private static final boolean DBG = LatinImeLogger.sDBG; - private final MoreSuggestionsView mPaneView; private SuggestedWords mSuggestions; private int mFromPos; diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index 286bf0aea..06fda44fa 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -62,7 +62,6 @@ import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; import com.android.inputmethod.latin.Suggest; import com.android.inputmethod.latin.SuggestedWords; -import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.Utils; import java.util.ArrayList; -- cgit v1.2.3-83-g751a From 624f1bab39357eb716dfc7ec6b723da3f926f5a2 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 21 Mar 2012 15:33:55 +0900 Subject: Refactor to memorize device dependent override parameters Change-Id: I79482a8ef3846525669979a30dec183ea18138b5 --- .../sudden-jumping-touch-event-device-list.xml | 8 ++++---- .../keyboard/SuddenJumpingTouchEventHandler.java | 16 +++------------ .../android/inputmethod/latin/SettingsValues.java | 23 +++++----------------- java/src/com/android/inputmethod/latin/Utils.java | 22 +++++++++++++++++++++ 4 files changed, 34 insertions(+), 35 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values/sudden-jumping-touch-event-device-list.xml b/java/res/values/sudden-jumping-touch-event-device-list.xml index ba828a758..543992a81 100644 --- a/java/res/values/sudden-jumping-touch-event-device-list.xml +++ b/java/res/values/sudden-jumping-touch-event-device-list.xml @@ -19,9 +19,9 @@ --> - - mahimahi - - sholes + + mahimahi,true + sholes,true diff --git a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java index 62a9259f9..347383f95 100644 --- a/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java +++ b/java/src/com/android/inputmethod/keyboard/SuddenJumpingTouchEventHandler.java @@ -17,12 +17,12 @@ package com.android.inputmethod.keyboard; import android.content.Context; -import android.os.Build; import android.util.Log; import android.view.MotionEvent; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Utils; public class SuddenJumpingTouchEventHandler { private static final String TAG = SuddenJumpingTouchEventHandler.class.getSimpleName(); @@ -49,18 +49,8 @@ public class SuddenJumpingTouchEventHandler { public SuddenJumpingTouchEventHandler(Context context, ProcessMotionEvent view) { mView = view; - final String[] deviceList = context.getResources().getStringArray( - R.array.sudden_jumping_touch_event_device_list); - mNeedsSuddenJumpingHack = needsSuddenJumpingHack(Build.HARDWARE, deviceList); - } - - private static boolean needsSuddenJumpingHack(String deviceName, String[] deviceList) { - for (String device : deviceList) { - if (device.equalsIgnoreCase(deviceName)) { - return true; - } - } - return false; + mNeedsSuddenJumpingHack = Boolean.parseBoolean(Utils.getDeviceOverrideValue( + context.getResources(), R.array.sudden_jumping_touch_event_device_list, "false")); } public void setKeyboard(Keyboard newKeyboard) { diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 9fc047b75..c1335fdfe 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; -import android.os.Build; import android.util.Log; import android.view.inputmethod.EditorInfo; @@ -322,14 +321,8 @@ public class SettingsValues { return volume; } - final String[] volumePerHardwareList = res.getStringArray(R.array.keypress_volumes); - final String hardwarePrefix = Build.HARDWARE + ","; - for (final String element : volumePerHardwareList) { - if (element.startsWith(hardwarePrefix)) { - return Float.parseFloat(element.substring(element.lastIndexOf(',') + 1)); - } - } - return -1.0f; + return Float.parseFloat( + Utils.getDeviceOverrideValue(res, R.array.keypress_volumes, "-1.0f")); } // Likewise @@ -340,15 +333,9 @@ public class SettingsValues { if (ms >= 0) { return ms; } - final String[] durationPerHardwareList = res.getStringArray( - R.array.keypress_vibration_durations); - final String hardwarePrefix = Build.HARDWARE + ","; - for (final String element : durationPerHardwareList) { - if (element.startsWith(hardwarePrefix)) { - return (int)Long.parseLong(element.substring(element.lastIndexOf(',') + 1)); - } - } - return -1; + + return Integer.parseInt( + Utils.getDeviceOverrideValue(res, R.array.keypress_vibration_durations, "-1")); } // Likewise diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index a7de47c58..a914ff76e 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -19,9 +19,11 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; @@ -43,6 +45,7 @@ import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; public class Utils { private Utils() { @@ -465,4 +468,23 @@ public class Utils { if (TextUtils.isEmpty(info)) return null; return info; } + + private static final String HARDWARE_PREFIX = Build.HARDWARE + ","; + private static final HashMap sDeviceOverrideValueMap = + new HashMap(); + + public static String getDeviceOverrideValue(Resources res, int overrideResId, String defValue) { + final Integer key = overrideResId; + if (!sDeviceOverrideValueMap.containsKey(key)) { + String overrideValue = defValue; + for (final String element : res.getStringArray(overrideResId)) { + if (element.startsWith(HARDWARE_PREFIX)) { + overrideValue = element.substring(HARDWARE_PREFIX.length()); + break; + } + } + sDeviceOverrideValueMap.put(key, overrideValue); + } + return sDeviceOverrideValueMap.get(key); + } } -- cgit v1.2.3-83-g751a From 376eb52450ffdc3d4580b405fc049144395c407f Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 30 Mar 2012 18:47:24 +0900 Subject: Move VibratorCompatWrapper to VibratorUtils. bug: 6129704 Change-Id: Ib63f1ed2d610e27e14957cf8805ef884cae6adf6 --- .../inputmethod/compat/VibratorCompatWrapper.java | 51 ---------------------- .../latin/AudioAndHapticFeedbackManager.java | 10 ++--- .../com/android/inputmethod/latin/Settings.java | 8 ++-- .../android/inputmethod/latin/SettingsValues.java | 4 +- .../android/inputmethod/latin/VibratorUtils.java | 50 +++++++++++++++++++++ 5 files changed, 61 insertions(+), 62 deletions(-) delete mode 100644 java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java create mode 100644 java/src/com/android/inputmethod/latin/VibratorUtils.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java deleted file mode 100644 index 2fb8b8710..000000000 --- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011 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.compat; - -import android.content.Context; -import android.os.Vibrator; - -import java.lang.reflect.Method; - -public class VibratorCompatWrapper { - private static final Method METHOD_hasVibrator = CompatUtils.getMethod(Vibrator.class, - "hasVibrator"); - - private static final VibratorCompatWrapper sInstance = new VibratorCompatWrapper(); - private Vibrator mVibrator; - - private VibratorCompatWrapper() { - } - - public static VibratorCompatWrapper getInstance(Context context) { - if (sInstance.mVibrator == null) { - sInstance.mVibrator = - (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - } - return sInstance; - } - - public boolean hasVibrator() { - if (mVibrator == null) - return false; - return (Boolean) CompatUtils.invoke(mVibrator, true, METHOD_hasVibrator); - } - - public void vibrate(long milliseconds) { - mVibrator.vibrate(milliseconds); - } -} diff --git a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java index 9c5ccc76b..55664d411 100644 --- a/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java +++ b/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java @@ -21,8 +21,8 @@ import android.media.AudioManager; import android.view.HapticFeedbackConstants; import android.view.View; -import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.latin.VibratorUtils; /** * This class gathers audio feedback and haptic feedback functions. @@ -33,13 +33,13 @@ import com.android.inputmethod.keyboard.Keyboard; public class AudioAndHapticFeedbackManager { final private SettingsValues mSettingsValues; final private AudioManager mAudioManager; - final private VibratorCompatWrapper mVibrator; + final private VibratorUtils mVibratorUtils; private boolean mSoundOn; public AudioAndHapticFeedbackManager(final LatinIME latinIme, final SettingsValues settingsValues) { mSettingsValues = settingsValues; - mVibrator = VibratorCompatWrapper.getInstance(latinIme); + mVibratorUtils = VibratorUtils.getInstance(latinIme); mAudioManager = (AudioManager) latinIme.getSystemService(Context.AUDIO_SERVICE); mSoundOn = reevaluateIfSoundIsOn(); } @@ -93,8 +93,8 @@ public class AudioAndHapticFeedbackManager { HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); } - } else if (mVibrator != null) { - mVibrator.vibrate(mSettingsValues.mKeypressVibrationDuration); + } else if (mVibratorUtils != null) { + mVibratorUtils.vibrate(mSettingsValues.mKeypressVibrationDuration); } } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 650dcdc68..fd61292df 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -44,7 +44,7 @@ import android.widget.TextView; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; -import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethod.latin.VibratorUtils; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethodcommon.InputMethodSettingsActivity; @@ -179,7 +179,7 @@ public class Settings extends InputMethodSettingsActivity generalSettings.removePreference(mVoicePreference); } - if (!VibratorCompatWrapper.getInstance(context).hasVibrator()) { + if (!VibratorUtils.getInstance(context).hasVibrator()) { generalSettings.removePreference(findPreference(PREF_VIBRATE_ON)); } @@ -358,7 +358,7 @@ public class Settings extends InputMethodSettingsActivity private void refreshEnablingsOfKeypressSoundAndVibrationSettings( SharedPreferences sp, Resources res) { if (mKeypressVibrationDurationSettingsPref != null) { - final boolean hasVibrator = VibratorCompatWrapper.getInstance(this).hasVibrator(); + final boolean hasVibrator = VibratorUtils.getInstance(this).hasVibrator(); final boolean vibrateOn = hasVibrator && sp.getBoolean(Settings.PREF_VIBRATE_ON, res.getBoolean(R.bool.config_default_vibration_enabled)); mKeypressVibrationDurationSettingsPref.setEnabled(vibrateOn); @@ -421,7 +421,7 @@ public class Settings extends InputMethodSettingsActivity @Override public void onStopTrackingTouch(SeekBar arg0) { final int tempMs = arg0.getProgress(); - VibratorCompatWrapper.getInstance(context).vibrate(tempMs); + VibratorUtils.getInstance(context).vibrate(tempMs); } }); sb.setProgress(currentMs); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index c1335fdfe..0ad685bdb 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -23,8 +23,8 @@ import android.util.Log; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.InputTypeCompatUtils; -import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.keyboard.internal.KeySpecParser; +import com.android.inputmethod.latin.VibratorUtils; import java.util.ArrayList; import java.util.Arrays; @@ -187,7 +187,7 @@ public class SettingsValues { private static boolean isVibrateOn(final Context context, final SharedPreferences prefs, final Resources res) { - final boolean hasVibrator = VibratorCompatWrapper.getInstance(context).hasVibrator(); + final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator(); return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, res.getBoolean(R.bool.config_default_vibration_enabled)); } diff --git a/java/src/com/android/inputmethod/latin/VibratorUtils.java b/java/src/com/android/inputmethod/latin/VibratorUtils.java new file mode 100644 index 000000000..33ffdd9c9 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/VibratorUtils.java @@ -0,0 +1,50 @@ +/* + * 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.Context; +import android.os.Vibrator; + +public class VibratorUtils { + private static final VibratorUtils sInstance = new VibratorUtils(); + private Vibrator mVibrator; + + private VibratorUtils() { + // This utility class is not publicly instantiable. + } + + public static VibratorUtils getInstance(Context context) { + if (sInstance.mVibrator == null) { + sInstance.mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); + } + return sInstance; + } + + public boolean hasVibrator() { + if (mVibrator == null) { + return false; + } + return mVibrator.hasVibrator(); + } + + public void vibrate(long milliseconds) { + if (mVibrator == null) { + return; + } + mVibrator.vibrate(milliseconds); + } +} -- cgit v1.2.3-83-g751a From 7e518d8b8358c96b94b900f0917cdc5fd8190ce1 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 2 Apr 2012 16:33:24 +0900 Subject: Combine candidate words and scores Bug: 5240798 Change-Id: Ie56c1c2cfd7f365e771fee88c1ed15012448feed --- .../android/inputmethod/latin/AutoCorrection.java | 24 +++-- .../com/android/inputmethod/latin/LatinIME.java | 2 - .../android/inputmethod/latin/SettingsValues.java | 3 +- .../src/com/android/inputmethod/latin/Suggest.java | 109 ++++++++++----------- .../android/inputmethod/latin/SuggestedWords.java | 75 +++++++++----- 5 files changed, 119 insertions(+), 94 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index ef88f9906..38444a10c 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; + import android.text.TextUtils; import android.util.Log; @@ -30,8 +32,9 @@ public class AutoCorrection { // Purely static class: can't instantiate. } - public static CharSequence computeAutoCorrectionWord(HashMap dictionaries, - WordComposer wordComposer, ArrayList suggestions, int[] sortedScores, + public static CharSequence computeAutoCorrectionWord( + HashMap dictionaries, + WordComposer wordComposer, ArrayList suggestions, CharSequence consideredWord, double autoCorrectionThreshold, CharSequence whitelistedWord) { if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) { @@ -40,8 +43,8 @@ public class AutoCorrection { dictionaries, wordComposer, suggestions, consideredWord)) { return consideredWord; } else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, - sortedScores, consideredWord, autoCorrectionThreshold)) { - return suggestions.get(0); + consideredWord, autoCorrectionThreshold)) { + return suggestions.get(0).mWord; } return null; } @@ -89,22 +92,23 @@ public class AutoCorrection { private static boolean hasAutoCorrectionForConsideredWord( HashMap dictionaries, WordComposer wordComposer, - ArrayList suggestions, CharSequence consideredWord) { + ArrayList suggestions, CharSequence consideredWord) { if (TextUtils.isEmpty(consideredWord)) return false; return wordComposer.size() > 1 && suggestions.size() > 0 && !allowsToBeAutoCorrected(dictionaries, consideredWord, false); } private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer, - ArrayList suggestions, int[] sortedScores, + ArrayList suggestions, CharSequence consideredWord, double autoCorrectionThreshold) { - if (wordComposer.size() > 1 && suggestions.size() > 0 && sortedScores.length > 0) { - final CharSequence autoCorrectionSuggestion = suggestions.get(0); - final int autoCorrectionSuggestionScore = sortedScores[0]; + if (wordComposer.size() > 1 && suggestions.size() > 0) { + final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0); + //final int autoCorrectionSuggestionScore = sortedScores[0]; + final int autoCorrectionSuggestionScore = autoCorrectionSuggestion.mScore; // TODO: when the normalized score of the first suggestion is nearly equals to // the normalized score of the second suggestion, behave less aggressive. final double normalizedScore = BinaryDictionary.calcNormalizedScore( - consideredWord.toString(), autoCorrectionSuggestion.toString(), + consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(), autoCorrectionSuggestionScore); if (DBG) { Log.d(TAG, "Normalized " + consideredWord + "," + autoCorrectionSuggestion + "," diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 363494b7d..69780d0fd 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -48,7 +48,6 @@ import android.view.ViewParent; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.ExtractedText; import android.view.inputmethod.InputConnection; import com.android.inputmethod.accessibility.AccessibilityUtils; @@ -58,7 +57,6 @@ 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.InputTypeCompatUtils; import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 0ad685bdb..f76cc7e44 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -24,6 +24,7 @@ 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; @@ -162,7 +163,7 @@ public class SettingsValues { if (puncs != null) { for (final String puncSpec : puncs) { puncList.add(new SuggestedWords.SuggestedWordInfo( - KeySpecParser.getLabel(puncSpec))); + KeySpecParser.getLabel(puncSpec), SuggestedWordInfo.MAX_SCORE)); } } return new SuggestedWords(puncList, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 9ae2506f4..b31f3019c 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -26,7 +26,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Locale; @@ -93,11 +92,9 @@ public class Suggest implements Dictionary.WordCallback { private static final int PREF_MAX_BIGRAMS = 60; private double mAutoCorrectionThreshold; - private int[] mScores = new int[mPrefMaxSuggestions]; - private int[] mBigramScores = new int[PREF_MAX_BIGRAMS]; - private ArrayList mSuggestions = new ArrayList(); - private ArrayList mBigramSuggestions = new ArrayList(); + private ArrayList mSuggestions = new ArrayList(); + private ArrayList mBigramSuggestions = new ArrayList(); private CharSequence mConsideredWord; // TODO: Remove these member variables by passing more context to addWord() callback method @@ -230,10 +227,8 @@ public class Suggest implements Dictionary.WordCallback { return sb; } - protected void addBigramToSuggestions(CharSequence bigram) { - final StringBuilder sb = new StringBuilder(getApproxMaxWordLength()); - sb.append(bigram); - mSuggestions.add(sb); + protected void addBigramToSuggestions(SuggestedWordInfo bigram) { + mSuggestions.add(bigram); } private static final WordComposer sEmptyWordComposer = new WordComposer(); @@ -242,15 +237,13 @@ public class Suggest implements Dictionary.WordCallback { mIsFirstCharCapitalized = false; mIsAllUpperCase = false; mTrailingSingleQuotesCount = 0; - mSuggestions = new ArrayList(mPrefMaxSuggestions); - Arrays.fill(mScores, 0); + mSuggestions = new ArrayList(mPrefMaxSuggestions); // Treating USER_TYPED as UNIGRAM suggestion for logging now. LatinImeLogger.onAddSuggestedWord("", Suggest.DIC_USER_TYPED, Dictionary.UNIGRAM); mConsideredWord = ""; - Arrays.fill(mBigramScores, 0); - mBigramSuggestions = new ArrayList(PREF_MAX_BIGRAMS); + mBigramSuggestions = new ArrayList(PREF_MAX_BIGRAMS); CharSequence lowerPrevWord = prevWordForBigram.toString().toLowerCase(); if (mMainDict != null && mMainDict.isValidWord(lowerPrevWord)) { @@ -265,9 +258,9 @@ public class Suggest implements Dictionary.WordCallback { addBigramToSuggestions(mBigramSuggestions.get(i)); } - StringUtils.removeDupes(mSuggestions); + SuggestedWordInfo.removeDups(mSuggestions); - return new SuggestedWords(SuggestedWords.getFromCharSequenceList(mSuggestions), + return new SuggestedWords(mSuggestions, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, @@ -283,8 +276,7 @@ public class Suggest implements Dictionary.WordCallback { mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); mIsAllUpperCase = wordComposer.isAllUpperCase(); mTrailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount(); - mSuggestions = new ArrayList(mPrefMaxSuggestions); - Arrays.fill(mScores, 0); + mSuggestions = new ArrayList(mPrefMaxSuggestions); final String typedWord = wordComposer.getTypedWord(); final String consideredWord = mTrailingSingleQuotesCount > 0 @@ -296,8 +288,7 @@ public class Suggest implements Dictionary.WordCallback { if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL_BIGRAM)) { // At first character typed, search only the bigrams - Arrays.fill(mBigramScores, 0); - mBigramSuggestions = new ArrayList(PREF_MAX_BIGRAMS); + mBigramSuggestions = new ArrayList(PREF_MAX_BIGRAMS); if (!TextUtils.isEmpty(prevWordForBigram)) { CharSequence lowerPrevWord = prevWordForBigram.toString().toLowerCase(); @@ -317,12 +308,14 @@ public class Suggest implements Dictionary.WordCallback { // Word entered: return only bigrams that match the first char of the typed word final char currentChar = consideredWord.charAt(0); // TODO: Must pay attention to locale when changing case. + // TODO: Use codepoint instead of char final char currentCharUpper = Character.toUpperCase(currentChar); int count = 0; final int bigramSuggestionSize = mBigramSuggestions.size(); for (int i = 0; i < bigramSuggestionSize; i++) { - final CharSequence bigramSuggestion = mBigramSuggestions.get(i); - final char bigramSuggestionFirstChar = bigramSuggestion.charAt(0); + final SuggestedWordInfo bigramSuggestion = mBigramSuggestions.get(i); + final char bigramSuggestionFirstChar = + (char)bigramSuggestion.codePointAt(0); if (bigramSuggestionFirstChar == currentChar || bigramSuggestionFirstChar == currentCharUpper) { addBigramToSuggestions(bigramSuggestion); @@ -359,7 +352,7 @@ public class Suggest implements Dictionary.WordCallback { if (CORRECTION_FULL == correctionMode || CORRECTION_FULL_BIGRAM == correctionMode) { final CharSequence autoCorrection = AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer, - mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, + mSuggestions, consideredWord, mAutoCorrectionThreshold, whitelistedWord); hasAutoCorrection = (null != autoCorrection); } else { @@ -372,20 +365,22 @@ public class Suggest implements Dictionary.WordCallback { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); } - mSuggestions.add(0, sb.toString()); + mSuggestions.add(0, new SuggestedWordInfo( + sb.toString(), SuggestedWordInfo.MAX_SCORE)); } else { - mSuggestions.add(0, whitelistedWord); + mSuggestions.add(0, new SuggestedWordInfo( + whitelistedWord, SuggestedWordInfo.MAX_SCORE)); } } - mSuggestions.add(0, typedWord); - StringUtils.removeDupes(mSuggestions); + mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE)); + SuggestedWordInfo.removeDups(mSuggestions); final ArrayList suggestionsList; if (DBG) { - suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, mSuggestions, mScores); + suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, mSuggestions); } else { - suggestionsList = SuggestedWords.getFromCharSequenceList(mSuggestions); + suggestionsList = mSuggestions; } // TODO: Change this scheme - a boolean is not enough. A whitelisted word may be "valid" @@ -415,50 +410,45 @@ public class Suggest implements Dictionary.WordCallback { false /* isObsoleteSuggestions */); } - // This assumes the scores[] array is at least as long as suggestions.size() - 1. private static ArrayList getSuggestionsInfoListWithDebugInfo( - final String typedWord, final ArrayList suggestions, final int[] scores) { - // TODO: this doesn't take into account the fact that removing dupes from mSuggestions - // may have made mScores[] and mSuggestions out of sync. - final CharSequence autoCorrectionSuggestion = suggestions.get(0); + final String typedWord, final ArrayList suggestions) { + final SuggestedWordInfo typedWordInfo = suggestions.get(0); + typedWordInfo.setDebugString("+"); double normalizedScore = BinaryDictionary.calcNormalizedScore( - typedWord, autoCorrectionSuggestion.toString(), scores[0]); + typedWord, typedWordInfo.toString(), typedWordInfo.mScore); final int suggestionsSize = suggestions.size(); final ArrayList suggestionsList = new ArrayList(suggestionsSize); - suggestionsList.add(new SuggestedWordInfo(autoCorrectionSuggestion, "+")); + suggestionsList.add(typedWordInfo); // Note: i here is the index in mScores[], but the index in mSuggestions is one more // than i because we added the typed word to mSuggestions without touching mScores. - for (int i = 0; i < scores.length && i < suggestionsSize - 1; ++i) { + for (int i = 0; i < suggestionsSize - 1; ++i) { + final SuggestedWordInfo cur = suggestions.get(i + 1); final String scoreInfoString; if (normalizedScore > 0) { - scoreInfoString = String.format("%d (%4.2f)", scores[i], normalizedScore); + scoreInfoString = String.format("%d (%4.2f)", cur.mScore, normalizedScore); normalizedScore = 0.0; } else { - scoreInfoString = Integer.toString(scores[i]); + scoreInfoString = Integer.toString(cur.mScore); } - suggestionsList.add(new SuggestedWordInfo(suggestions.get(i + 1), scoreInfoString)); - } - for (int i = scores.length; i < suggestionsSize; ++i) { - suggestionsList.add(new SuggestedWordInfo(suggestions.get(i), "--")); + cur.setDebugString(scoreInfoString); + suggestionsList.add(cur); } return suggestionsList; } + // TODO: Use codepoint instead of char @Override public boolean addWord(final char[] word, final int offset, final int length, int score, final int dicTypeId, final int dataType) { int dataTypeForLog = dataType; - final ArrayList suggestions; - final int[] sortedScores; + final ArrayList suggestions; final int prefMaxSuggestions; if (dataType == Dictionary.BIGRAM) { suggestions = mBigramSuggestions; - sortedScores = mBigramScores; prefMaxSuggestions = PREF_MAX_BIGRAMS; } else { suggestions = mSuggestions; - sortedScores = mScores; prefMaxSuggestions = mPrefMaxSuggestions; } @@ -469,13 +459,13 @@ public class Suggest implements Dictionary.WordCallback { // TODO: remove this surrounding if clause and move this logic to // getSuggestedWordBuilder. if (suggestions.size() > 0) { - final String currentHighestWord = suggestions.get(0).toString(); + final SuggestedWordInfo currentHighestWord = suggestions.get(0); // If the current highest word is also equal to typed word, we need to compare // frequency to determine the insertion position. This does not ensure strictly // correct ordering, but ensures the top score is on top which is enough for // removing duplicates correctly. - if (StringUtils.equalsIgnoreCase(currentHighestWord, word, offset, length) - && score <= sortedScores[0]) { + if (StringUtils.equalsIgnoreCase(currentHighestWord.mWord, word, offset, length) + && score <= currentHighestWord.mScore) { pos = 1; } } @@ -486,7 +476,7 @@ public class Suggest implements Dictionary.WordCallback { if(bigramSuggestion >= 0) { dataTypeForLog = Dictionary.BIGRAM; // turn freq from bigram into multiplier specified above - double multiplier = (((double) mBigramScores[bigramSuggestion]) + double multiplier = (((double) mBigramSuggestions.get(bigramSuggestion).mScore) / MAXIMUM_BIGRAM_FREQUENCY) * (BIGRAM_MULTIPLIER_MAX - BIGRAM_MULTIPLIER_MIN) + BIGRAM_MULTIPLIER_MIN; @@ -500,10 +490,12 @@ public class Suggest implements Dictionary.WordCallback { } // Check the last one's score and bail - if (sortedScores[prefMaxSuggestions - 1] >= score) return true; - while (pos < prefMaxSuggestions) { - if (sortedScores[pos] < score - || (sortedScores[pos] == score && length < suggestions.get(pos).length())) { + if (suggestions.size() >= prefMaxSuggestions + && suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true; + while (pos < suggestions.size()) { + final int curScore = suggestions.get(pos).mScore; + if (curScore < score + || (curScore == score && length < suggestions.get(pos).codePointCount())) { break; } pos++; @@ -513,8 +505,6 @@ public class Suggest implements Dictionary.WordCallback { return true; } - System.arraycopy(sortedScores, pos, sortedScores, pos + 1, prefMaxSuggestions - pos - 1); - sortedScores[pos] = score; final StringBuilder sb = new StringBuilder(getApproxMaxWordLength()); // TODO: Must pay attention to locale when changing case. if (mIsAllUpperCase) { @@ -530,7 +520,7 @@ public class Suggest implements Dictionary.WordCallback { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); } - suggestions.add(pos, sb); + suggestions.add(pos, new SuggestedWordInfo(sb, score)); if (suggestions.size() > prefMaxSuggestions) { suggestions.remove(prefMaxSuggestions); } else { @@ -539,15 +529,16 @@ public class Suggest implements Dictionary.WordCallback { return true; } + // TODO: Use codepoint instead of char private int searchBigramSuggestion(final char[] word, final int offset, final int length) { // TODO This is almost O(n^2). Might need fix. // search whether the word appeared in bigram data int bigramSuggestSize = mBigramSuggestions.size(); for (int i = 0; i < bigramSuggestSize; i++) { - if (mBigramSuggestions.get(i).length() == length) { + if (mBigramSuggestions.get(i).codePointCount() == length) { boolean chk = true; for (int j = 0; j < length; j++) { - if (mBigramSuggestions.get(i).charAt(j) != word[offset+j]) { + if (mBigramSuggestions.get(i).codePointAt(j) != word[offset+j]) { chk = false; break; } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index ef8e58e0c..0c0ce182f 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -56,6 +56,10 @@ public class SuggestedWords { return mSuggestedWordInfoList.get(pos).mWord; } + public SuggestedWordInfo getWordInfo(int pos) { + return mSuggestedWordInfoList.get(pos); + } + public SuggestedWordInfo getInfo(int pos) { return mSuggestedWordInfoList.get(pos); } @@ -79,20 +83,12 @@ public class SuggestedWords { + " words=" + Arrays.toString(mSuggestedWordInfoList.toArray()); } - public static ArrayList getFromCharSequenceList( - final ArrayList wordList) { - final ArrayList result = new ArrayList(); - for (CharSequence word : wordList) { - if (null != word) result.add(new SuggestedWordInfo(word)); - } - return result; - } - public static ArrayList getFromApplicationSpecifiedCompletions( final CompletionInfo[] infos) { final ArrayList result = new ArrayList(); for (CompletionInfo info : infos) { - if (null != info) result.add(new SuggestedWordInfo(info.getText())); + if (null != info) result.add(new SuggestedWordInfo(info.getText(), + SuggestedWordInfo.MAX_SCORE)); } return result; } @@ -103,14 +99,15 @@ public class SuggestedWords { final CharSequence typedWord, final SuggestedWords previousSuggestions) { final ArrayList suggestionsList = new ArrayList(); final HashSet alreadySeen = new HashSet(); - suggestionsList.add(new SuggestedWordInfo(typedWord)); + suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { - final String prevWord = previousSuggestions.getWord(pos).toString(); + final SuggestedWordInfo prevWordInfo = previousSuggestions.getWordInfo(pos); + final String prevWord = prevWordInfo.mWord.toString(); // Filter out duplicate suggestion. if (!alreadySeen.contains(prevWord)) { - suggestionsList.add(new SuggestedWordInfo(prevWord)); + suggestionsList.add(prevWordInfo); alreadySeen.add(prevWord); } } @@ -118,30 +115,64 @@ public class SuggestedWords { } public static class SuggestedWordInfo { + public static final int MAX_SCORE = Integer.MAX_VALUE; + private final String mWordStr; public final CharSequence mWord; - private final String mDebugString; + public final int mScore; + public final int mCodePointCount; + private String mDebugString = ""; - public SuggestedWordInfo(final CharSequence word) { + public SuggestedWordInfo(final CharSequence word, final int score) { + mWordStr = word.toString(); mWord = word; - mDebugString = ""; + mScore = score; + mCodePointCount = mWordStr.codePointCount(0, mWordStr.length()); } - public SuggestedWordInfo(final CharSequence word, final String debugString) { - mWord = word; - if (null == debugString) throw new NullPointerException(""); - mDebugString = debugString; + + public void setDebugString(String str) { + if (null == str) throw new NullPointerException("Debug info is null"); + mDebugString = str; } public String getDebugString() { return mDebugString; } + public int codePointCount() { + return mCodePointCount; + } + + public int codePointAt(int i) { + return mWordStr.codePointAt(i); + } + @Override public String toString() { if (TextUtils.isEmpty(mDebugString)) { - return mWord.toString(); + return mWordStr; } else { - return mWord.toString() + " (" + mDebugString.toString() + ")"; + return mWordStr + " (" + mDebugString.toString() + ")"; + } + } + + // TODO: Consolidate this method and StringUtils.removeDupes() in the future. + public static void removeDups(ArrayList candidates) { + if (candidates.size() <= 1) { + return; + } + int i = 1; + while(i < candidates.size()) { + final SuggestedWordInfo cur = candidates.get(i); + for (int j = 0; j < i; ++j) { + final SuggestedWordInfo previous = candidates.get(j); + if (TextUtils.equals(cur.mWord, previous.mWord)) { + candidates.remove(cur.mScore < previous.mScore ? i : j); + --i; + break; + } + } + ++i; } } } -- cgit v1.2.3-83-g751a From be55086fd9218bc03ee0ccac1052d96b40d8a979 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 2 Apr 2012 22:43:38 +0900 Subject: Cleanup InputTypeCompatUtils to InputTypeUtils Bug: 6129704 Change-Id: I45e19e456ef7c6e61fe877ea544fef1b9f896e95 --- .../accessibility/AccessibilityUtils.java | 4 +- .../inputmethod/compat/InputTypeCompatUtils.java | 118 --------------------- .../android/inputmethod/keyboard/KeyboardId.java | 6 +- .../android/inputmethod/keyboard/KeyboardSet.java | 4 +- .../android/inputmethod/latin/InputAttributes.java | 8 +- .../android/inputmethod/latin/InputTypeUtils.java | 90 ++++++++++++++++ .../android/inputmethod/latin/SettingsValues.java | 4 +- 7 files changed, 101 insertions(+), 133 deletions(-) delete mode 100644 java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java create mode 100644 java/src/com/android/inputmethod/latin/InputTypeUtils.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java index af10e75bf..667b109cb 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java @@ -28,8 +28,8 @@ import android.view.accessibility.AccessibilityManager; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.AudioManagerCompatWrapper; -import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.SettingsSecureCompatUtils; +import com.android.inputmethod.latin.InputTypeUtils; import com.android.inputmethod.latin.R; public class AccessibilityUtils { @@ -132,7 +132,7 @@ public class AccessibilityUtils { return false; // Don't speak if the IME is connected to a password field. - return InputTypeCompatUtils.isPasswordInputType(editorInfo.inputType); + return InputTypeUtils.isPasswordInputType(editorInfo.inputType); } /** diff --git a/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java b/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java deleted file mode 100644 index 6c2f0f799..000000000 --- a/java/src/com/android/inputmethod/compat/InputTypeCompatUtils.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2011 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.compat; - -import android.text.InputType; - -import java.lang.reflect.Field; - -public class InputTypeCompatUtils { - private static final Field FIELD_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS = - CompatUtils.getField(InputType.class, "TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS"); - private static final Field FIELD_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD = CompatUtils - .getField(InputType.class, "TYPE_TEXT_VARIATION_WEB_PASSWORD"); - private static final Field FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD = CompatUtils - .getField(InputType.class, "TYPE_NUMBER_VARIATION_PASSWORD"); - private static final Integer OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS = - (Integer) CompatUtils.getFieldValue(null, null, - FIELD_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS); - private static final Integer OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD = - (Integer) CompatUtils.getFieldValue(null, null, - FIELD_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD); - private static final Integer OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD = - (Integer) CompatUtils.getFieldValue(null, null, - FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD); - private static final int WEB_TEXT_PASSWORD_INPUT_TYPE; - private static final int WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE; - private static final int NUMBER_PASSWORD_INPUT_TYPE; - private static final int TEXT_PASSWORD_INPUT_TYPE = - InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; - private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE = - InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; - - static { - WEB_TEXT_PASSWORD_INPUT_TYPE = - OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD != null - ? InputType.TYPE_CLASS_TEXT | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD - : 0; - WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE = - OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != null - ? InputType.TYPE_CLASS_TEXT - | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS - : 0; - NUMBER_PASSWORD_INPUT_TYPE = - OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD != null - ? InputType.TYPE_CLASS_NUMBER | OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD - : 0; - } - - private static boolean isWebEditTextInputType(int inputType) { - return inputType == (InputType.TYPE_CLASS_TEXT - | InputType.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 OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != null - && variation == OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS; - } - - public static boolean isEmailVariation(int variation) { - return variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS - || isWebEmailAddressVariation(variation); - } - - public static boolean isWebInputType(int inputType) { - final int maskedInputType = - inputType & (InputType.TYPE_MASK_CLASS | InputType.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 & (InputType.TYPE_MASK_CLASS | InputType.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 & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION); - return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index eef065f52..e35081867 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -21,7 +21,7 @@ import android.text.TextUtils; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.EditorInfoCompatUtils; -import com.android.inputmethod.compat.InputTypeCompatUtils; +import com.android.inputmethod.latin.InputTypeUtils; import java.util.Arrays; import java.util.Locale; @@ -140,8 +140,8 @@ public class KeyboardId { public boolean passwordInput() { final int inputType = mEditorInfo.inputType; - return InputTypeCompatUtils.isPasswordInputType(inputType) - || InputTypeCompatUtils.isVisiblePasswordInputType(inputType); + return InputTypeUtils.isPasswordInputType(inputType) + || InputTypeUtils.isVisiblePasswordInputType(inputType); } public boolean isMultiLine() { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 4d0f00380..62cb41b9e 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -27,8 +27,8 @@ import android.util.Xml; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.EditorInfoCompatUtils; -import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams; +import com.android.inputmethod.latin.InputTypeUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LocaleUtils; @@ -379,7 +379,7 @@ public class KeyboardSet { case InputType.TYPE_CLASS_PHONE: return KeyboardId.MODE_PHONE; case InputType.TYPE_CLASS_TEXT: - if (InputTypeCompatUtils.isEmailVariation(variation)) { + if (InputTypeUtils.isEmailVariation(variation)) { return KeyboardId.MODE_EMAIL; } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { return KeyboardId.MODE_URL; 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/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index f76cc7e44..d46160f0d 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -22,10 +22,8 @@ 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; @@ -286,7 +284,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() { -- cgit v1.2.3-83-g751a From 16c6f355700ee5cdaa029f4a25b8b3d40718e6ab Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 3 Apr 2012 14:28:56 +0900 Subject: Add RunInLocale class to guard locale switching Bug: 6128216 Change-Id: I8d9c75c773c3de886183b291ada7a3836295839b --- .../android/inputmethod/keyboard/KeyboardSet.java | 62 +++++++++-------- .../inputmethod/latin/BinaryDictionaryGetter.java | 14 ++-- .../inputmethod/latin/DictionaryFactory.java | 78 +++++++++++----------- .../com/android/inputmethod/latin/LatinIME.java | 59 +++++++++------- .../com/android/inputmethod/latin/LocaleUtils.java | 43 ++++++++---- .../android/inputmethod/latin/SettingsValues.java | 18 ++--- .../inputmethod/latin/WhitelistDictionary.java | 14 ++-- 7 files changed, 163 insertions(+), 125 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 4d0f00380..0f3ae2f07 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -31,7 +31,7 @@ import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.LocaleUtils; +import com.android.inputmethod.latin.LocaleUtils.RunInLocale; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.XmlParseUtils; @@ -66,6 +66,7 @@ public class KeyboardSet { public static class KeyboardSetException extends RuntimeException { public final KeyboardId mKeyboardId; + public KeyboardSetException(Throwable cause, KeyboardId keyboardId) { super(cause); mKeyboardId = keyboardId; @@ -161,26 +162,29 @@ public class KeyboardSet { } } - private Keyboard getKeyboard(Context context, ElementParams elementParams, KeyboardId id) { - final Resources res = context.getResources(); + private Keyboard getKeyboard(Context context, ElementParams elementParams, + final KeyboardId id) { final SoftReference ref = sKeyboardCache.get(id); Keyboard keyboard = (ref == null) ? null : ref.get(); if (keyboard == null) { - final Locale savedLocale = LocaleUtils.setSystemLocale(res, id.mLocale); - try { - final Keyboard.Builder builder = - new Keyboard.Builder(context, new Keyboard.Params()); - if (id.isAlphabetKeyboard()) { - builder.setAutoGenerate(sKeysCache); - } - builder.load(elementParams.mKeyboardXmlId, id); - builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled); - builder.setProximityCharsCorrectionEnabled( - elementParams.mProximityCharsCorrectionEnabled); - keyboard = builder.build(); - } finally { - LocaleUtils.setSystemLocale(res, savedLocale); + final Keyboard.Builder builder = + new Keyboard.Builder(mContext, new Keyboard.Params()); + if (id.isAlphabetKeyboard()) { + builder.setAutoGenerate(sKeysCache); } + final int keyboardXmlId = elementParams.mKeyboardXmlId; + final RunInLocale job = new RunInLocale() { + @Override + protected Void job(Resources res) { + builder.load(keyboardXmlId, id); + return null; + } + }; + job.runInLocale(context.getResources(), id.mLocale); + builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled); + builder.setProximityCharsCorrectionEnabled( + elementParams.mProximityCharsCorrectionEnabled); + keyboard = builder.build(); sKeyboardCache.put(id, new SoftReference(keyboard)); if (DEBUG_CACHE) { @@ -271,16 +275,20 @@ public class KeyboardSet { if (mParams.mLocale == null) throw new RuntimeException("KeyboardSet subtype is not specified"); - final Locale savedLocale = LocaleUtils.setSystemLocale(mResources, mParams.mLocale); - try { - parseKeyboardSet(mResources, R.xml.keyboard_set); - } catch (Exception e) { - throw new RuntimeException(e.getMessage() + " in " - + mResources.getResourceName(R.xml.keyboard_set) - + " of locale " + mParams.mLocale); - } finally { - LocaleUtils.setSystemLocale(mResources, savedLocale); - } + final RunInLocale job = new RunInLocale() { + @Override + protected Void job(Resources res) { + try { + parseKeyboardSet(res, R.xml.keyboard_set); + } catch (Exception e) { + throw new RuntimeException(e.getMessage() + " in " + + res.getResourceName(R.xml.keyboard_set) + + " of locale " + mParams.mLocale); + } + return null; + } + }; + job.runInLocale(mResources, mParams.mLocale); return new KeyboardSet(mContext, mParams); } 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 job = new RunInLocale() { + @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 job = new RunInLocale() { + @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 job = new RunInLocale() { + @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 job = new RunInLocale() { + @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/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 177f5e629..1eb9c8d02 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -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; @@ -478,7 +479,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // 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 job = new RunInLocale() { + @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()); } @@ -487,33 +494,37 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen 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 job = new RunInLocale() { + @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); } /** 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 { + 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 sLocaleCache = new HashMap(); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index f76cc7e44..f2abb9c20 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -25,12 +25,14 @@ 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 +80,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 +146,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. 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 job = new RunInLocale() { + @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) { -- cgit v1.2.3-83-g751a From 80f2ccc236272be5897b2b0ba4ad302c8bbcc97d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Apr 2012 20:49:37 +0900 Subject: Update the names and default values of bigram options. Bug: 6293595 Change-Id: I9978a1127c64b7a26a5ccf6f777366f7c4e214db --- java/res/values/config.xml | 10 +++++----- java/res/values/strings.xml | 14 +++++++------- java/res/xml/prefs.xml | 8 ++++---- java/src/com/android/inputmethod/latin/Settings.java | 6 +++--- java/src/com/android/inputmethod/latin/SettingsValues.java | 6 +++--- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values/config.xml b/java/res/values/config.xml index f0b12e92b..133bb0a06 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -22,17 +22,17 @@ false true true - true + true true true - - true - - false + true false true 100 diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index a22c68cb8..28acd0fcc 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -118,13 +118,13 @@ Very aggressive - - Bigram suggestions - - Use previous word to improve suggestion - - Bigram prediction - + + Next word suggestions + + Use previous word to improve suggestions + + Next word prediction + Use previous word also for prediction diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index c5c647aac..ab5d44b24 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -111,18 +111,18 @@ android:persistent="true" android:defaultValue="true" /> + android:defaultValue="true" /> Date: Thu, 5 Apr 2012 14:59:55 +0900 Subject: Generate KeyboardLabelsSet from donottranslate-more-keys.xml This change introduces makelabel tool that reads all languages' donottranslate-more-keys and generate KeyboardLabelsSet.java source file. The makelabel command must be invoked prior to compile LatinIME. Change-Id: I7515c7919c535e30f9c80a37bdc831d0f682cd43 --- java/res/values-ar/donottranslate-more-keys.xml | 144 -- java/res/values-be/donottranslate-more-keys.xml | 31 - java/res/values-ca/donottranslate-more-keys.xml | 73 - java/res/values-cs/donottranslate-more-keys.xml | 87 - java/res/values-da/donottranslate-more-keys.xml | 71 - java/res/values-de/donottranslate-more-keys.xml | 54 - java/res/values-en/donottranslate-more-keys.xml | 63 - java/res/values-es/donottranslate-more-keys.xml | 73 - java/res/values-et/donottranslate-more-keys.xml | 114 - java/res/values-fa/donottranslate-more-keys.xml | 146 -- java/res/values-fi/donottranslate-more-keys.xml | 56 - java/res/values-fr/donottranslate-more-keys.xml | 68 - java/res/values-hi/donottranslate-more-keys.xml | 51 - java/res/values-hr/donottranslate-more-keys.xml | 38 - java/res/values-hu/donottranslate-more-keys.xml | 62 - java/res/values-is/donottranslate-more-keys.xml | 73 - java/res/values-it/donottranslate-more-keys.xml | 62 - java/res/values-iw/donottranslate-more-keys.xml | 53 - java/res/values-ky/donottranslate-more-keys.xml | 37 - java/res/values-lt/donottranslate-more-keys.xml | 107 - java/res/values-lv/donottranslate-more-keys.xml | 106 - java/res/values-mk/donottranslate-more-keys.xml | 47 - java/res/values-nb/donottranslate-more-keys.xml | 60 - java/res/values-nl/donottranslate-more-keys.xml | 66 - java/res/values-pl/donottranslate-more-keys.xml | 65 - java/res/values-pt/donottranslate-more-keys.xml | 65 - java/res/values-rm/donottranslate-more-keys.xml | 29 - java/res/values-ro/donottranslate-more-keys.xml | 45 - java/res/values-ru/donottranslate-more-keys.xml | 33 - java/res/values-sk/donottranslate-more-keys.xml | 107 - java/res/values-sl/donottranslate-more-keys.xml | 30 - java/res/values-sr/donottranslate-more-keys.xml | 47 - java/res/values-sv/donottranslate-more-keys.xml | 54 - java/res/values-tr/donottranslate-more-keys.xml | 57 - java/res/values-uk/donottranslate-more-keys.xml | 33 - java/res/values-vi/donottranslate-more-keys.xml | 95 - java/res/values-zz/donottranslate-more-keys.xml | 139 -- java/res/values/donottranslate-more-keys.xml | 187 -- java/res/values/donottranslate.xml | 18 - java/res/xml-sw600dp/key_shortcut.xml | 2 +- java/res/xml-sw600dp/key_styles_common.xml | 16 +- java/res/xml-sw600dp/keys_apostrophe_dash.xml | 12 +- java/res/xml-sw600dp/keys_comma_period.xml | 10 +- java/res/xml-sw600dp/rowkeys_symbols2.xml | 8 +- java/res/xml-sw600dp/rowkeys_symbols3.xml | 12 +- java/res/xml-sw600dp/rowkeys_symbols_shift1.xml | 2 +- java/res/xml-sw600dp/rows_number_normal.xml | 2 +- java/res/xml-sw600dp/rows_symbols4.xml | 2 +- java/res/xml-sw768dp/key_styles_common.xml | 20 +- java/res/xml-sw768dp/keys_apostrophe_dash.xml | 12 +- java/res/xml-sw768dp/rows_number_normal.xml | 2 +- java/res/xml-sw768dp/rows_symbols4.xml | 2 +- java/res/xml/key_azerty_quote.xml | 2 +- java/res/xml/key_styles_common.xml | 18 +- java/res/xml/key_styles_currency.xml | 6 +- java/res/xml/key_styles_currency_dollar.xml | 2 +- java/res/xml/key_styles_currency_euro.xml | 2 +- java/res/xml/key_styles_enter.xml | 20 +- java/res/xml/key_styles_number.xml | 8 +- java/res/xml/keys_less_greater.xml | 4 +- java/res/xml/keys_parentheses.xml | 4 +- java/res/xml/row_qwerty4.xml | 4 +- java/res/xml/rowkeys_azerty1.xml | 18 +- java/res/xml/rowkeys_azerty2.xml | 14 +- java/res/xml/rowkeys_azerty3.xml | 8 +- java/res/xml/rowkeys_east_slavic1.xml | 10 +- java/res/xml/rowkeys_east_slavic2.xml | 6 +- java/res/xml/rowkeys_east_slavic3.xml | 4 +- java/res/xml/rowkeys_nordic1.xml | 2 +- java/res/xml/rowkeys_nordic2.xml | 8 +- java/res/xml/rowkeys_qwerty1.xml | 16 +- java/res/xml/rowkeys_qwerty2.xml | 16 +- java/res/xml/rowkeys_qwerty3.xml | 8 +- java/res/xml/rowkeys_qwertz1.xml | 16 +- java/res/xml/rowkeys_qwertz3.xml | 8 +- java/res/xml/rowkeys_south_slavic1.xml | 6 +- java/res/xml/rowkeys_south_slavic2.xml | 2 +- java/res/xml/rowkeys_south_slavic3.xml | 4 +- java/res/xml/rowkeys_symbols1.xml | 60 +- java/res/xml/rowkeys_symbols2.xml | 10 +- java/res/xml/rowkeys_symbols3.xml | 12 +- java/res/xml/rowkeys_symbols_shift1.xml | 2 +- java/res/xml/rows_number_normal.xml | 2 +- java/res/xml/rows_symbols4.xml | 4 +- java/src/com/android/inputmethod/keyboard/Key.java | 10 +- .../com/android/inputmethod/keyboard/Keyboard.java | 16 +- .../inputmethod/keyboard/KeyboardLayoutSet.java | 9 +- .../keyboard/internal/KeySpecParser.java | 50 +- .../inputmethod/keyboard/internal/KeyStyles.java | 80 +- .../keyboard/internal/KeyboardLabelsSet.java | 2477 ++++++++++++++++++++ .../android/inputmethod/latin/SettingsValues.java | 2 +- tests/res/values/donottranslate.xml | 6 +- .../keyboard/internal/KeySpecParserCsvTests.java | 134 +- .../keyboard/internal/KeySpecParserTests.java | 88 +- tools/makelabel/Android.mk | 26 + tools/makelabel/etc/Android.mk | 21 + tools/makelabel/etc/makelabel | 63 + tools/makelabel/etc/manifest.txt | 1 + .../keyboard/internal/KeyboardLabelsSet.tmpl | 117 + .../res/values-ar/donottranslate-more-keys.xml | 144 ++ .../res/values-be/donottranslate-more-keys.xml | 31 + .../res/values-ca/donottranslate-more-keys.xml | 73 + .../res/values-cs/donottranslate-more-keys.xml | 87 + .../res/values-da/donottranslate-more-keys.xml | 71 + .../res/values-de/donottranslate-more-keys.xml | 54 + .../res/values-en/donottranslate-more-keys.xml | 63 + .../res/values-es/donottranslate-more-keys.xml | 73 + .../res/values-et/donottranslate-more-keys.xml | 114 + .../res/values-fa/donottranslate-more-keys.xml | 146 ++ .../res/values-fi/donottranslate-more-keys.xml | 56 + .../res/values-fr/donottranslate-more-keys.xml | 68 + .../res/values-hi/donottranslate-more-keys.xml | 51 + .../res/values-hr/donottranslate-more-keys.xml | 38 + .../res/values-hu/donottranslate-more-keys.xml | 62 + .../res/values-is/donottranslate-more-keys.xml | 73 + .../res/values-it/donottranslate-more-keys.xml | 62 + .../res/values-iw/donottranslate-more-keys.xml | 53 + .../res/values-ky/donottranslate-more-keys.xml | 37 + .../res/values-lt/donottranslate-more-keys.xml | 107 + .../res/values-lv/donottranslate-more-keys.xml | 106 + .../res/values-mk/donottranslate-more-keys.xml | 47 + .../res/values-nb/donottranslate-more-keys.xml | 60 + .../res/values-nl/donottranslate-more-keys.xml | 66 + .../res/values-pl/donottranslate-more-keys.xml | 65 + .../res/values-pt/donottranslate-more-keys.xml | 65 + .../res/values-rm/donottranslate-more-keys.xml | 29 + .../res/values-ro/donottranslate-more-keys.xml | 45 + .../res/values-ru/donottranslate-more-keys.xml | 33 + .../res/values-sk/donottranslate-more-keys.xml | 107 + .../res/values-sl/donottranslate-more-keys.xml | 30 + .../res/values-sr/donottranslate-more-keys.xml | 47 + .../res/values-sv/donottranslate-more-keys.xml | 54 + .../res/values-tr/donottranslate-more-keys.xml | 57 + .../res/values-uk/donottranslate-more-keys.xml | 33 + .../res/values-vi/donottranslate-more-keys.xml | 95 + .../res/values-zz/donottranslate-more-keys.xml | 139 ++ .../res/values/donottranslate-more-keys.xml | 203 ++ .../latin/makelabel/ArrayInitializerFormatter.java | 89 + .../inputmethod/latin/makelabel/JarUtils.java | 86 + .../inputmethod/latin/makelabel/LabelMaker.java | 65 + .../latin/makelabel/MoreKeysResources.java | 258 ++ .../latin/makelabel/StringResource.java | 29 + .../latin/makelabel/StringResourceMap.java | 128 + 143 files changed, 6521 insertions(+), 3132 deletions(-) delete mode 100644 java/res/values-ar/donottranslate-more-keys.xml delete mode 100644 java/res/values-be/donottranslate-more-keys.xml delete mode 100644 java/res/values-ca/donottranslate-more-keys.xml delete mode 100644 java/res/values-cs/donottranslate-more-keys.xml delete mode 100644 java/res/values-da/donottranslate-more-keys.xml delete mode 100644 java/res/values-de/donottranslate-more-keys.xml delete mode 100644 java/res/values-en/donottranslate-more-keys.xml delete mode 100644 java/res/values-es/donottranslate-more-keys.xml delete mode 100644 java/res/values-et/donottranslate-more-keys.xml delete mode 100644 java/res/values-fa/donottranslate-more-keys.xml delete mode 100644 java/res/values-fi/donottranslate-more-keys.xml delete mode 100644 java/res/values-fr/donottranslate-more-keys.xml delete mode 100644 java/res/values-hi/donottranslate-more-keys.xml delete mode 100644 java/res/values-hr/donottranslate-more-keys.xml delete mode 100644 java/res/values-hu/donottranslate-more-keys.xml delete mode 100644 java/res/values-is/donottranslate-more-keys.xml delete mode 100644 java/res/values-it/donottranslate-more-keys.xml delete mode 100644 java/res/values-iw/donottranslate-more-keys.xml delete mode 100644 java/res/values-ky/donottranslate-more-keys.xml delete mode 100644 java/res/values-lt/donottranslate-more-keys.xml delete mode 100644 java/res/values-lv/donottranslate-more-keys.xml delete mode 100644 java/res/values-mk/donottranslate-more-keys.xml delete mode 100644 java/res/values-nb/donottranslate-more-keys.xml delete mode 100644 java/res/values-nl/donottranslate-more-keys.xml delete mode 100644 java/res/values-pl/donottranslate-more-keys.xml delete mode 100644 java/res/values-pt/donottranslate-more-keys.xml delete mode 100644 java/res/values-rm/donottranslate-more-keys.xml delete mode 100644 java/res/values-ro/donottranslate-more-keys.xml delete mode 100644 java/res/values-ru/donottranslate-more-keys.xml delete mode 100644 java/res/values-sk/donottranslate-more-keys.xml delete mode 100644 java/res/values-sl/donottranslate-more-keys.xml delete mode 100644 java/res/values-sr/donottranslate-more-keys.xml delete mode 100644 java/res/values-sv/donottranslate-more-keys.xml delete mode 100644 java/res/values-tr/donottranslate-more-keys.xml delete mode 100644 java/res/values-uk/donottranslate-more-keys.xml delete mode 100644 java/res/values-vi/donottranslate-more-keys.xml delete mode 100644 java/res/values-zz/donottranslate-more-keys.xml delete mode 100644 java/res/values/donottranslate-more-keys.xml create mode 100644 java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java create mode 100644 tools/makelabel/Android.mk create mode 100644 tools/makelabel/etc/Android.mk create mode 100755 tools/makelabel/etc/makelabel create mode 100644 tools/makelabel/etc/manifest.txt create mode 100644 tools/makelabel/res/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.tmpl create mode 100644 tools/makelabel/res/values-ar/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-be/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-ca/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-cs/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-da/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-de/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-en/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-es/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-et/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-fa/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-fi/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-fr/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-hi/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-hr/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-hu/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-is/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-it/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-iw/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-ky/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-lt/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-lv/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-mk/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-nb/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-nl/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-pl/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-pt/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-rm/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-ro/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-ru/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-sk/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-sl/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-sr/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-sv/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-tr/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-uk/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-vi/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values-zz/donottranslate-more-keys.xml create mode 100644 tools/makelabel/res/values/donottranslate-more-keys.xml create mode 100644 tools/makelabel/src/com/android/inputmethod/latin/makelabel/ArrayInitializerFormatter.java create mode 100644 tools/makelabel/src/com/android/inputmethod/latin/makelabel/JarUtils.java create mode 100644 tools/makelabel/src/com/android/inputmethod/latin/makelabel/LabelMaker.java create mode 100644 tools/makelabel/src/com/android/inputmethod/latin/makelabel/MoreKeysResources.java create mode 100644 tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResource.java create mode 100644 tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResourceMap.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values-ar/donottranslate-more-keys.xml b/java/res/values-ar/donottranslate-more-keys.xml deleted file mode 100644 index 402e17160..000000000 --- a/java/res/values-ar/donottranslate-more-keys.xml +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - - "!fixedColumnOrder!8,\",\',-,:,!,؟,،,؛,ِ,َ,ٍ,ً,ٖ,ٰ,ٕ,ٔ,ُ,ٌ,ّ,ْ,ٓ,ـــ|ـ,/" - ً - - ١ - - ٢ - - ٣ - - ٤ - - ٥ - - ٦ - - ٧ - - ٨ - - ٩ - - ٠ - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - - 0,٫,٬ - - ، - "\\," - ؟ - ؛ - - ٪ - \? - ; - - %,‰ - - ، - "." - ؟ - ً - "؟,؛,!,:,-,/,\',\"" - - - - - "ّ,ْ,ٌ,ٓ,ُ,ِ,َ,ً,ـــ|ـ,ٍ,ٔ,ٖ,ٕ,ٰ" - - - - ★,٭ - - - - - !fixedColumnOrder!4,﴾|﴿,<|>,{|},[|] - !fixedColumnOrder!4,﴿|﴾,>|<,}|{,]|[ - - !fixedColumnOrder!3,‹|›,≤|≥,«|» - !fixedColumnOrder!3,›|‹,≥|≤,»|« - - - !fixedColumnOrder!4,“,”,«|»,»|« - - - !fixedColumnOrder!4,“,”,«|»,»|«,‘,’,‚,‛ - diff --git a/java/res/values-be/donottranslate-more-keys.xml b/java/res/values-be/donottranslate-more-keys.xml deleted file mode 100644 index 835553a1f..000000000 --- a/java/res/values-be/donottranslate-more-keys.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - ў - - ы - - і - - ъ - - ъ - diff --git a/java/res/values-ca/donottranslate-more-keys.xml b/java/res/values-ca/donottranslate-more-keys.xml deleted file mode 100644 index baa23bf9c..000000000 --- a/java/res/values-ca/donottranslate-more-keys.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - à,á,ä,â,ã,å,ą,æ,ā,ª - - è,é,ë,ê,ę,ė,ē - - í,ï,ì,î,į,ī - - ò,ó,ö,ô,õ,ø,œ,ō,º - - ú,ü,ù,û,ū - - ñ,ń - - ç,ć,č - - ŀ,ł - diff --git a/java/res/values-cs/donottranslate-more-keys.xml b/java/res/values-cs/donottranslate-more-keys.xml deleted file mode 100644 index 9af6794df..000000000 --- a/java/res/values-cs/donottranslate-more-keys.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - - á,à,â,ä,æ,ã,å,ā - - é,ě,è,ê,ë,ę,ė,ē - - í,î,ï,ì,į,ī - - ó,ö,ô,ò,õ,œ,ø,ō - - ú,ů,û,ü,ù,ū - - š,ß,ś - - ň,ñ,ń - - č,ç,ć - - ý,ÿ - - ď - - ř - - ť - - ž,ź,ż - diff --git a/java/res/values-da/donottranslate-more-keys.xml b/java/res/values-da/donottranslate-more-keys.xml deleted file mode 100644 index acc0c534d..000000000 --- a/java/res/values-da/donottranslate-more-keys.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - á,ä,à,â,ã,ā - - é,ë - - í,ï - - ó,ô,ò,õ,œ,ō - - ú,ü,û,ù,ū - - ß,ś,š - - ñ,ń - - ý,ÿ - - ð - - ł - - å - - æ - - ø - - ä - - ö - diff --git a/java/res/values-de/donottranslate-more-keys.xml b/java/res/values-de/donottranslate-more-keys.xml deleted file mode 100644 index 562e574eb..000000000 --- a/java/res/values-de/donottranslate-more-keys.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - ä,â,à,á,æ,ã,å,ā - - ė - - ö,ô,ò,ó,õ,œ,ø,ō - - ü,û,ù,ú,ū - - ß,ś,š - - ñ,ń - diff --git a/java/res/values-en/donottranslate-more-keys.xml b/java/res/values-en/donottranslate-more-keys.xml deleted file mode 100644 index 6e43e86d7..000000000 --- a/java/res/values-en/donottranslate-more-keys.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - à,á,â,ä,æ,ã,å,ā - - è,é,ê,ë,ă - - î,ï,í,ī,ì - - ô,ö,ò,ó,œ,øō,õ - - û,ü,ù,ú,ū - - ß - - ñ - - ç - diff --git a/java/res/values-es/donottranslate-more-keys.xml b/java/res/values-es/donottranslate-more-keys.xml deleted file mode 100644 index f56b1d54f..000000000 --- a/java/res/values-es/donottranslate-more-keys.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - á,à,ä,â,ã,å,ą,æ,ā,ª - - é,è,ë,ê,ę,ė,ē - - í,ï,ì,î,į,ī - - ó,ò,ö,ô,õ,ø,œ,ō,º - - ú,ü,ù,û,ū - - ñ,ń - - ç,ć,č - - "!fixedColumnOrder!7,#,-,¡,!,¿,\\,,\?,\\%,+,;,:,/,(,),\@,&,\",\'" - diff --git a/java/res/values-et/donottranslate-more-keys.xml b/java/res/values-et/donottranslate-more-keys.xml deleted file mode 100644 index 69cf654a6..000000000 --- a/java/res/values-et/donottranslate-more-keys.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - - ä,ā,à,á,â,ã,å,æ,ą - - ē,è,ė,é,ê,ë,ę,ě - - ī,ì,į,í,î,ï,ı - - ö,õ,ò,ó,ô,œ,ő,ø - - ü,ū,ų,ù,ú,û,ů,ű - - š,ß,ś,ş - - ņ,ñ,ń,ń - - č,ç,ć - - ý,ÿ - - ď - - ŗ,ř,ŕ - - ţ,ť - - ž,ż,ź - - ķ - - ļ,ł,ĺ,ľ - - ģ,ğ - - ü - - ö - - ä - - õ - diff --git a/java/res/values-fa/donottranslate-more-keys.xml b/java/res/values-fa/donottranslate-more-keys.xml deleted file mode 100644 index 1da1c1889..000000000 --- a/java/res/values-fa/donottranslate-more-keys.xml +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - - "!fixedColumnOrder!8,\",\',-,:,!,؟,،,؛,ِ,َ,ٍ,ً,ٖ,ٰ,ٕ,ٔ,ُ,ٌ,ّ,ْ,ٓ,ـــ|ـ,/" - ً - - ۱ - - ۲ - - ۳ - - ۴ - - ۵ - - ۶ - - ۷ - - ۸ - - ۹ - - ۰ - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - - 0,٫,٬ - - ، - "\\," - ؟ - ؛ - - ٪ - \? - ; - - %,‰ - - "،" - "!" - "!,\\," - "؟" - "؟,\?" - ً - "؟,؛,!,:,-,/,\',\"" - - - - - "ّ,ْ,ٌ,ٓ,ُ,ِ,َ,ً,ـــ|ـ,ٍ,ٔ,ٖ,ٕ,_,ٰ" - - - - ★,٭ - - - - - !fixedColumnOrder!4,﴾|﴿,<|>,{|},[|] - !fixedColumnOrder!4,﴿|﴾,>|<,}|{,]|[ - - !fixedColumnOrder!3,‹|›,≤|≥,«|» - !fixedColumnOrder!3,›|‹,≥|≤,»|« - - - !fixedColumnOrder!4,“,”,«|»,»|« - - - !fixedColumnOrder!4,“,”,«|»,»|«,‘,’,‚,‛ - diff --git a/java/res/values-fi/donottranslate-more-keys.xml b/java/res/values-fi/donottranslate-more-keys.xml deleted file mode 100644 index 25b785845..000000000 --- a/java/res/values-fi/donottranslate-more-keys.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - - æ,à,á,â,ã,ā - - ø,ô,ò,ó,õ,œ,ō - - ü - - š,ß,ś - - ž,ź,ż - - å - - ö - - ä - - ø - - æ - diff --git a/java/res/values-fr/donottranslate-more-keys.xml b/java/res/values-fr/donottranslate-more-keys.xml deleted file mode 100644 index 7b11a183d..000000000 --- a/java/res/values-fr/donottranslate-more-keys.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - à,â,%,æ,á,ä,ã,å,ā,ª - - é,è,ê,ë,%,ę,ė,ē - - î,%,ï,ì,í,į,ī - - ô,œ,%,ö,ò,ó,õ,ø,ō,º - - ù,û,%,ü,ú,ū - - ç,ć,č - - %,ÿ - diff --git a/java/res/values-hi/donottranslate-more-keys.xml b/java/res/values-hi/donottranslate-more-keys.xml deleted file mode 100644 index 19bcb9dda..000000000 --- a/java/res/values-hi/donottranslate-more-keys.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 0 - diff --git a/java/res/values-hr/donottranslate-more-keys.xml b/java/res/values-hr/donottranslate-more-keys.xml deleted file mode 100644 index 9b4005d0d..000000000 --- a/java/res/values-hr/donottranslate-more-keys.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - š,ś,ß - - ñ,ń - - ž,ź,ż - - č,ć,ç - - đ - diff --git a/java/res/values-hu/donottranslate-more-keys.xml b/java/res/values-hu/donottranslate-more-keys.xml deleted file mode 100644 index 48259104b..000000000 --- a/java/res/values-hu/donottranslate-more-keys.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - á,à,â,ä,æ,ã,å,ā - - é,è,ê,ë,ę,ė,ē - - í,î,ï,ì,į,ī - - ó,ö,ő,ô,ò,õ,œ,ø,ō - - ú,ü,ű,û,ù,ū - diff --git a/java/res/values-is/donottranslate-more-keys.xml b/java/res/values-is/donottranslate-more-keys.xml deleted file mode 100644 index 284aae930..000000000 --- a/java/res/values-is/donottranslate-more-keys.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - á,ä,æ,å,à,â,ã,ā - - é,ë,è,ê,ę,ė,ē - - í,ï,î,ì,į,ī - - ó,ö,ô,ò,õ,œ,ø,ō - - ú,ü,û,ù,ū - - ý,ÿ - - ð - - þ - - ð - - æ - - þ - diff --git a/java/res/values-it/donottranslate-more-keys.xml b/java/res/values-it/donottranslate-more-keys.xml deleted file mode 100644 index 17dd03108..000000000 --- a/java/res/values-it/donottranslate-more-keys.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - à,á,â,ä,æ,ã,å,ā,ª - - è,é,ê,ë,ę,ė,ē - - ì,í,î,ï,į,ī - - ò,ó,ô,ö,õ,œ,ø,ō,º - - ù,ú,û,ü,ū - diff --git a/java/res/values-iw/donottranslate-more-keys.xml b/java/res/values-iw/donottranslate-more-keys.xml deleted file mode 100644 index ad209edde..000000000 --- a/java/res/values-iw/donottranslate-more-keys.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - ±,﬩ - - !fixedColumnOrder!3,<|>,{|},[|] - !fixedColumnOrder!3,>|<,}|{,]|[ - - !fixedColumnOrder!3,‹|›,≤|≥,«|» - !fixedColumnOrder!3,›|‹,≥|≤,»|« - - - !fixedColumnOrder!4,“,”,«|»,»|« - - - !fixedColumnOrder!4,“,”,«|»,»|«,‘,’,‚,‛ - diff --git a/java/res/values-ky/donottranslate-more-keys.xml b/java/res/values-ky/donottranslate-more-keys.xml deleted file mode 100644 index fd90248b2..000000000 --- a/java/res/values-ky/donottranslate-more-keys.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - щ - - ы - - и - - ү - - ң - - ъ - - ө - - ъ - diff --git a/java/res/values-lt/donottranslate-more-keys.xml b/java/res/values-lt/donottranslate-more-keys.xml deleted file mode 100644 index 1491d954e..000000000 --- a/java/res/values-lt/donottranslate-more-keys.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - ą,ä,ā,à,á,â,ã,å,æ - - ė,ę,ē,è,é,ê,ë,ě - - į,ī,ì,í,î,ï,ı - - ö,õ,ò,ó,ô,œ,ő,ø - - ū,ų,ü,ū,ù,ú,û,ů,ű - - š,ß,ś,ş - - ņ,ñ,ń,ń - - č,ç,ć - - ý,ÿ - - ď - - ŗ,ř,ŕ - - ţ,ť - - ž,ż,ź - - ķ - - ļ,ł,ĺ,ľ - - ģ,ğ - diff --git a/java/res/values-lv/donottranslate-more-keys.xml b/java/res/values-lv/donottranslate-more-keys.xml deleted file mode 100644 index d0a44480a..000000000 --- a/java/res/values-lv/donottranslate-more-keys.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - ā,à,á,â,ã,ä,å,æ,ą - - ē,ė,è,é,ê,ë,ę,ě - - ī,į,ì,í,î,ï,ı - - ò,ó,ô,õ,ö,œ,ő,ø - - ū,ų,ù,ú,û,ü,ů,ű - - š,ß,ś,ş - - ņ,ñ,ń,ń - - č,ç,ć - - ý,ÿ - - ď - - ŗ,ř,ŕ - - ţ,ť - - ž,ż,ź - - ķ - - ļ,ł,ĺ,ľ - - ģ,ğ - diff --git a/java/res/values-mk/donottranslate-more-keys.xml b/java/res/values-mk/donottranslate-more-keys.xml deleted file mode 100644 index d0cccf61b..000000000 --- a/java/res/values-mk/donottranslate-more-keys.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - ѕ - - ќ - - з - - ѓ - - ѐ - - ѝ - - - - !fixedColumnOrder!5,„,“,”,«,» - - - !fixedColumnOrder!5,„,“,”,«,»,‘,’,‚,‛ - diff --git a/java/res/values-nb/donottranslate-more-keys.xml b/java/res/values-nb/donottranslate-more-keys.xml deleted file mode 100644 index 49e6d5faf..000000000 --- a/java/res/values-nb/donottranslate-more-keys.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - à,ä,á,â,ã,ā - - é,è,ê,ë,ę,ė,ē - - ô,ò,ó,ö,õ,œ,ō - - ü,û,ù,ú,ū - - å - - ø - - æ - - ö - - ä - diff --git a/java/res/values-nl/donottranslate-more-keys.xml b/java/res/values-nl/donottranslate-more-keys.xml deleted file mode 100644 index 73768aff2..000000000 --- a/java/res/values-nl/donottranslate-more-keys.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - á,ä,â,à,æ,ã,å,ā - - é,ë,ê,è,ę,ė,ē - - í,ï,ì,î,į,ī,ij - - ó,ö,ô,ò,õ,œ,ø,ō - - ú,ü,û,ù,ū - - ñ,ń - - ij - diff --git a/java/res/values-pl/donottranslate-more-keys.xml b/java/res/values-pl/donottranslate-more-keys.xml deleted file mode 100644 index 0f8a59bd6..000000000 --- a/java/res/values-pl/donottranslate-more-keys.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - ą,á,à,â,ä,æ,ã,å,ā - - ę,è,é,ê,ë,ė,ē - - ó,ö,ô,ò,õ,œ,ø,ō - - ś,ß,š - - ń,ñ - - ć,ç,č - - ż,ź,ž - - ł - diff --git a/java/res/values-pt/donottranslate-more-keys.xml b/java/res/values-pt/donottranslate-more-keys.xml deleted file mode 100644 index 0c9065f27..000000000 --- a/java/res/values-pt/donottranslate-more-keys.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - á,ã,à,â,ä,å,æ,ª - - é,ê,è,ę,ė,ē,ë - - í,î,ì,ï,į,ī - - ó,õ,ô,ò,ö,œ,ø,ō,º - - ú,ü,ù,û,ū - - ç,č,ć - diff --git a/java/res/values-rm/donottranslate-more-keys.xml b/java/res/values-rm/donottranslate-more-keys.xml deleted file mode 100644 index aa0d7f817..000000000 --- a/java/res/values-rm/donottranslate-more-keys.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - ò,ó,ö,ô,õ,œ,ø - diff --git a/java/res/values-ro/donottranslate-more-keys.xml b/java/res/values-ro/donottranslate-more-keys.xml deleted file mode 100644 index 44613cf85..000000000 --- a/java/res/values-ro/donottranslate-more-keys.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - â,ã,ă,à,á,ä,æ,å,ā - - î,ï,ì,í,į,ī - - ș,ß,ś,š - - ț - diff --git a/java/res/values-ru/donottranslate-more-keys.xml b/java/res/values-ru/donottranslate-more-keys.xml deleted file mode 100644 index 0bb57074c..000000000 --- a/java/res/values-ru/donottranslate-more-keys.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - щ - - ы - - и - - ё - - ъ - - ъ - diff --git a/java/res/values-sk/donottranslate-more-keys.xml b/java/res/values-sk/donottranslate-more-keys.xml deleted file mode 100644 index f6e1e8d72..000000000 --- a/java/res/values-sk/donottranslate-more-keys.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - á,ä,ā,à,â,ã,å,æ,ą - - é,ě,ē,ė,è,ê,ë,ę - - í,ī,į,ì,î,ï,ı - - ô,ó,ö,ò,õ,œ,ő,ø - - ú,ů,ü,ū,ų,ù,û,ű - - š,ß,ś,ş - - ň,ņ,ñ,ń,ń - - č,ç,ć - - ý,ÿ - - ď - - ŕ,ř,ŗ - - ť,ţ - - ž,ż,ź - - ķ - - ľ,ĺ,ļ,ł - - ģ,ğ - diff --git a/java/res/values-sl/donottranslate-more-keys.xml b/java/res/values-sl/donottranslate-more-keys.xml deleted file mode 100644 index ccff2ac29..000000000 --- a/java/res/values-sl/donottranslate-more-keys.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - š - - č,ć - - đ - - ž - diff --git a/java/res/values-sr/donottranslate-more-keys.xml b/java/res/values-sr/donottranslate-more-keys.xml deleted file mode 100644 index e85d3d7a2..000000000 --- a/java/res/values-sr/donottranslate-more-keys.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - з - - ћ - - ѕ - - ђ - - ѐ - - ѝ - - - - !fixedColumnOrder!5,„,“,”,«,» - - - !fixedColumnOrder!5,„,“,”,«,»,‘,’,‚,‛ - diff --git a/java/res/values-sv/donottranslate-more-keys.xml b/java/res/values-sv/donottranslate-more-keys.xml deleted file mode 100644 index d479191f4..000000000 --- a/java/res/values-sv/donottranslate-more-keys.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - é,è,ê,ë,ę - - œ,ô,ò,ó,õ,ō - - ü,û,ù,ú,ū - - ß,ś,š - - å - - ö - - ä - - ø - - æ - diff --git a/java/res/values-tr/donottranslate-more-keys.xml b/java/res/values-tr/donottranslate-more-keys.xml deleted file mode 100644 index 1161811d4..000000000 --- a/java/res/values-tr/donottranslate-more-keys.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - â - - ı,î,ï,ì,í,į,ī - - ö,ô,œ,ò,ó,õ,ø,ō - - ü,û,ù,ú,ū - - ş,ß,ś,š - - ğ - - ç,ć,č - diff --git a/java/res/values-uk/donottranslate-more-keys.xml b/java/res/values-uk/donottranslate-more-keys.xml deleted file mode 100644 index 32397049a..000000000 --- a/java/res/values-uk/donottranslate-more-keys.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - щ - - і - - и - - ъ - - ї - - ъ - diff --git a/java/res/values-vi/donottranslate-more-keys.xml b/java/res/values-vi/donottranslate-more-keys.xml deleted file mode 100644 index 6ef1c6bc5..000000000 --- a/java/res/values-vi/donottranslate-more-keys.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - à,á,ả,ã,ạ,ă,ằ,ắ,ẳ,ẵ,ặ,â,ầ,ấ,ẩ,ẫ,ậ - - è,é,ẻ,ẽ,ẹ,ê,ề,ế,ể,ễ,ệ - - ì,í,ỉ,ĩ,ị - - ò,ó,ỏ,õ,ọ,ô,ồ,ố,ổ,ỗ,ộ,ơ,ờ,ớ,ở,ỡ,ợ - - ù,ú,ủ,ũ,ụ,ư,ừ,ứ,ử,ữ,ự - - ỳ,ý,ỷ,ỹ,ỵ - - đ - diff --git a/java/res/values-zz/donottranslate-more-keys.xml b/java/res/values-zz/donottranslate-more-keys.xml deleted file mode 100644 index eb984a469..000000000 --- a/java/res/values-zz/donottranslate-more-keys.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - - - à,á,â,ã,ä,å,æ,ã,å,ā,ă,ą,ª - - è,é,ê,ë,ē,ĕ,ė,ę,ě - - ì,í,î,ï,ĩ,ī,ĭ,į,ı,ij - - ò,ó,ô,õ,ö,ø,ō,ŏ,ő,œ,º - - ù,ú,û,ü,ũ,ū,ŭ,ů,ű,ų - - ß,ś,ŝ,ş,š,ſ - - ñ,ń,ņ,ň,ʼn,ŋ - - ç,ć,ĉ,ċ,č - - ý,ŷ,ÿ,ij - - ď,đ,ð - - ŕ,ŗ,ř - - þ,ţ,ť,ŧ - - ź,ż,ž - - ķ,ĸ - - ĺ,ļ,ľ,ŀ,ł - - ĝ,ğ,ġ,ģ - - ĥ - - ĵ - - ŵ - diff --git a/java/res/values/donottranslate-more-keys.xml b/java/res/values/donottranslate-more-keys.xml deleted file mode 100644 index 14c278af9..000000000 --- a/java/res/values/donottranslate-more-keys.xml +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ¢,£,€,¥,₱ - ¢,£,$,¥,₱ - ¢,$,€,¥,₱ - ¢,$,€,£,¥,₱ - "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ " - "!fixedColumnOrder!8,\",\',#,-,:,!,\\,,\?,\@,&,\\%,+,;,/,(,)" - - ".com" - - "!hasLabels!,.net,.org,.gov,.edu" - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 0 - - - - - - - - - - - - ¹,½,⅓,¼,⅛ - - ²,⅔ - - ³,¾,⅜ - - - - - - - - - - - ⁿ,∅ - !fixedColumnOrder!2,!hasLabels!,\@string/label_time_am,\@string/label_time_pm - !icon/settingsKey|!code/key_settings - , - - !hasLabels!,\@string/label_next_key|!code/key_action_next - !hasLabels!,\@string/label_previous_key|!code/key_action_previous - \? - ; - % - - ¿ - - - - , - ! - ! - \? - \? - \' - - - \" - _ - \" - _ - - ♪,♥,♠,♦,♣ - - †,‡,★ - - ± - - !fixedColumnOrder!3,<,{,[ - !fixedColumnOrder!3,>,},] - - !fixedColumnOrder!3,‹,≤,« - !fixedColumnOrder!3,›,≥,» - !fixedColumnOrder!4,‘,’,‚,‛ - - - !fixedColumnOrder!4,“,”,«,» - - - !fixedColumnOrder!4,“,”,«,»,‘,’,‚,‛ - diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index 9c8bd3cd4..bfe42327c 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -45,24 +45,6 @@ - - = \\ < - - ~ \\ { - - - Tab - - 123 - - - *# - - "AM" - - "PM" - 0 diff --git a/java/res/xml-sw600dp/key_shortcut.xml b/java/res/xml-sw600dp/key_shortcut.xml index d4c45ad22..2114c67bd 100644 --- a/java/res/xml-sw600dp/key_shortcut.xml +++ b/java/res/xml-sw600dp/key_shortcut.xml @@ -29,7 +29,7 @@ + latin:moreKeys="!label/more_keys_for_smiley" /> + latin:keyOutputText="!label/keylabel_for_popular_domain" + latin:moreKeys="!label/more_keys_for_popular_domain" /> diff --git a/java/res/xml-sw600dp/keys_apostrophe_dash.xml b/java/res/xml-sw600dp/keys_apostrophe_dash.xml index a53c1e4ab..faaae50c9 100644 --- a/java/res/xml-sw600dp/keys_apostrophe_dash.xml +++ b/java/res/xml-sw600dp/keys_apostrophe_dash.xml @@ -39,9 +39,9 @@ @@ -54,9 +54,9 @@ diff --git a/java/res/xml-sw600dp/keys_comma_period.xml b/java/res/xml-sw600dp/keys_comma_period.xml index f5f307be6..4a83cc817 100644 --- a/java/res/xml-sw600dp/keys_comma_period.xml +++ b/java/res/xml-sw600dp/keys_comma_period.xml @@ -32,14 +32,14 @@ diff --git a/java/res/xml-sw600dp/rowkeys_symbols2.xml b/java/res/xml-sw600dp/rowkeys_symbols2.xml index e0121a35c..fd774168f 100644 --- a/java/res/xml-sw600dp/rowkeys_symbols2.xml +++ b/java/res/xml-sw600dp/rowkeys_symbols2.xml @@ -26,13 +26,13 @@ + latin:keyLabel="!label/keylabel_for_symbols_percent" + latin:moreKeys="!label/more_keys_for_symbols_percent" /> + latin:moreKeys="!label/more_keys_for_star" /> + latin:moreKeys="!label/more_keys_for_plus" /> diff --git a/java/res/xml-sw600dp/rowkeys_symbols3.xml b/java/res/xml-sw600dp/rowkeys_symbols3.xml index 9293352cf..536ac05a2 100644 --- a/java/res/xml-sw600dp/rowkeys_symbols3.xml +++ b/java/res/xml-sw600dp/rowkeys_symbols3.xml @@ -41,11 +41,11 @@ + latin:keyLabel="!label/keylabel_for_symbols_semicolon" + latin:moreKeys="!label/more_keys_for_symbols_semicolon" /> + latin:keyLabel="!label/keylabel_for_comma" + latin:moreKeys="!label/more_keys_for_comma" /> @@ -53,6 +53,6 @@ latin:keyLabel="!" latin:moreKeys="¡" /> + latin:keyLabel="!label/keylabel_for_symbols_question" + latin:moreKeys="!label/more_keys_for_symbols_question" /> diff --git a/java/res/xml-sw600dp/rowkeys_symbols_shift1.xml b/java/res/xml-sw600dp/rowkeys_symbols_shift1.xml index 356ee2f0e..914a4499b 100644 --- a/java/res/xml-sw600dp/rowkeys_symbols_shift1.xml +++ b/java/res/xml-sw600dp/rowkeys_symbols_shift1.xml @@ -30,7 +30,7 @@ + latin:moreKeys="!label/more_keys_for_bullet" /> diff --git a/java/res/xml-sw600dp/rows_number_normal.xml b/java/res/xml-sw600dp/rows_number_normal.xml index be5776b20..00fda2899 100644 --- a/java/res/xml-sw600dp/rows_number_normal.xml +++ b/java/res/xml-sw600dp/rows_number_normal.xml @@ -70,7 +70,7 @@ diff --git a/java/res/xml-sw600dp/rows_symbols4.xml b/java/res/xml-sw600dp/rows_symbols4.xml index bfc9b2cf6..afa2652ea 100644 --- a/java/res/xml-sw600dp/rows_symbols4.xml +++ b/java/res/xml-sw600dp/rows_symbols4.xml @@ -37,7 +37,7 @@ latin:keyWidth="39.750%p" /> + latin:moreKeys="!label/more_keys_for_tablet_double_quote" /> + latin:moreKeys="!label/more_keys_for_smiley" /> @@ -122,7 +122,7 @@ @@ -130,35 +130,35 @@ + latin:keyOutputText="!label/keylabel_for_popular_domain" + latin:moreKeys="!label/more_keys_for_popular_domain" /> diff --git a/java/res/xml-sw768dp/keys_apostrophe_dash.xml b/java/res/xml-sw768dp/keys_apostrophe_dash.xml index a53c1e4ab..faaae50c9 100644 --- a/java/res/xml-sw768dp/keys_apostrophe_dash.xml +++ b/java/res/xml-sw768dp/keys_apostrophe_dash.xml @@ -39,9 +39,9 @@ @@ -54,9 +54,9 @@ diff --git a/java/res/xml-sw768dp/rows_number_normal.xml b/java/res/xml-sw768dp/rows_number_normal.xml index 2eeb6c9d4..f868cbb8b 100644 --- a/java/res/xml-sw768dp/rows_number_normal.xml +++ b/java/res/xml-sw768dp/rows_number_normal.xml @@ -72,7 +72,7 @@ diff --git a/java/res/xml-sw768dp/rows_symbols4.xml b/java/res/xml-sw768dp/rows_symbols4.xml index 19b36d690..dd1647b95 100644 --- a/java/res/xml-sw768dp/rows_symbols4.xml +++ b/java/res/xml-sw768dp/rows_symbols4.xml @@ -37,7 +37,7 @@ latin:keyWidth="37.500%p" /> + latin:moreKeys="!label/more_keys_for_tablet_double_quote" /> diff --git a/java/res/xml/key_azerty_quote.xml b/java/res/xml/key_azerty_quote.xml index 966ae6f21..b8c51d30f 100644 --- a/java/res/xml/key_azerty_quote.xml +++ b/java/res/xml/key_azerty_quote.xml @@ -31,7 +31,7 @@ + latin:moreKeys="!label/more_keys_for_single_quote" /> diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index b0b87a810..ec011d08b 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -35,7 +35,7 @@ @@ -98,7 +98,7 @@ latin:keyLabel=":-)" latin:keyOutputText=":-) " latin:keyLabelFlags="hasPopupHint" - latin:moreKeys="@string/more_keys_for_smiley" + latin:moreKeys="!label/more_keys_for_smiley" latin:backgroundType="functional" /> @@ -158,7 +158,7 @@ latin:styleName="toSymbolKeyStyle" latin:code="!code/key_switch_alpha_symbol" latin:keyIcon="iconShortcutForLabel" - latin:keyLabel="@string/label_to_symbol_with_microphone_key" + latin:keyLabel="!label/label_to_symbol_with_microphone_key" latin:keyLabelFlags="withIconRight|preserveCase" latin:keyActionFlags="noKeyPreview" latin:backgroundType="functional" /> @@ -167,7 +167,7 @@ @@ -176,29 +176,29 @@ diff --git a/java/res/xml/key_styles_currency.xml b/java/res/xml/key_styles_currency.xml index bd1d959e4..6057d5bd7 100644 --- a/java/res/xml/key_styles_currency.xml +++ b/java/res/xml/key_styles_currency.xml @@ -86,7 +86,7 @@ + latin:moreKeys="!label/more_keys_for_currency_general" /> @@ -112,7 +112,7 @@ + latin:moreKeys="!label/more_keys_for_currency_general" /> @@ -138,7 +138,7 @@ + latin:moreKeys="!label/more_keys_for_currency_pound" /> diff --git a/java/res/xml/key_styles_currency_dollar.xml b/java/res/xml/key_styles_currency_dollar.xml index 8dd849879..704970a56 100644 --- a/java/res/xml/key_styles_currency_dollar.xml +++ b/java/res/xml/key_styles_currency_dollar.xml @@ -26,7 +26,7 @@ + latin:moreKeys="!label/more_keys_for_currency_dollar" /> diff --git a/java/res/xml/key_styles_currency_euro.xml b/java/res/xml/key_styles_currency_euro.xml index 0573e0991..074d4c0c2 100644 --- a/java/res/xml/key_styles_currency_euro.xml +++ b/java/res/xml/key_styles_currency_euro.xml @@ -26,7 +26,7 @@ + latin:moreKeys="!abel/more_keys_for_currency_euro" /> diff --git a/java/res/xml/key_styles_enter.xml b/java/res/xml/key_styles_enter.xml index 49759c470..04bd80d9e 100644 --- a/java/res/xml/key_styles_enter.xml +++ b/java/res/xml/key_styles_enter.xml @@ -30,7 +30,7 @@ + latin:moreKeys="!label/action_previous_as_more_key" /> + latin:moreKeys="!label/action_next_as_more_key" /> + latin:moreKeys="!fixedColumnOrder!2,!needsDividers!,!label/action_previous_as_more_key,!label/action_next_as_more_key" /> + latin:moreKeys="!label/action_next_as_more_key" /> + latin:moreKeys="!label/action_previous_as_more_key" /> @@ -119,7 +119,7 @@ > + latin:moreKeys="!label/more_keys_for_less_than" /> + latin:moreKeys="!label/more_keys_for_greater_than" /> diff --git a/java/res/xml/keys_parentheses.xml b/java/res/xml/keys_parentheses.xml index 502a84ede..17d72859c 100644 --- a/java/res/xml/keys_parentheses.xml +++ b/java/res/xml/keys_parentheses.xml @@ -24,9 +24,9 @@ + latin:moreKeys="!label/more_keys_for_left_parenthesis" /> + latin:moreKeys="!label/more_keys_for_right_parenthesis" /> diff --git a/java/res/xml/row_qwerty4.xml b/java/res/xml/row_qwerty4.xml index b2b47e9b5..c08518079 100644 --- a/java/res/xml/row_qwerty4.xml +++ b/java/res/xml/row_qwerty4.xml @@ -51,9 +51,9 @@ diff --git a/java/res/xml/rowkeys_azerty1.xml b/java/res/xml/rowkeys_azerty1.xml index 99834321f..50a0162de 100644 --- a/java/res/xml/rowkeys_azerty1.xml +++ b/java/res/xml/rowkeys_azerty1.xml @@ -25,47 +25,47 @@ latin:keyLabel="a" latin:keyHintLabel="1" latin:additionalMoreKeys="1" - latin:moreKeys="@string/more_keys_for_a" /> + latin:moreKeys="!label/more_keys_for_a" /> + latin:moreKeys="!label/more_keys_for_z" /> + latin:moreKeys="!label/more_keys_for_e" /> + latin:moreKeys="!label/more_keys_for_r" /> + latin:moreKeys="!label/more_keys_for_t" /> + latin:moreKeys="!label/more_keys_for_y" /> + latin:moreKeys="!label/more_keys_for_u" /> + latin:moreKeys="!label/more_keys_for_i" /> + latin:moreKeys="!label/more_keys_for_o" /> + latin:moreKeys="!label/more_keys_for_s" /> + latin:moreKeys="!label/more_keys_for_d" /> + latin:moreKeys="!label/more_keys_for_g" /> + latin:moreKeys="!label/more_keys_for_h" /> + latin:moreKeys="!label/more_keys_for_j" /> + latin:moreKeys="!label/more_keys_for_k" /> + latin:moreKeys="!label/more_keys_for_l" /> diff --git a/java/res/xml/rowkeys_azerty3.xml b/java/res/xml/rowkeys_azerty3.xml index b81c3c5a1..35e9b195f 100644 --- a/java/res/xml/rowkeys_azerty3.xml +++ b/java/res/xml/rowkeys_azerty3.xml @@ -23,20 +23,20 @@ > + latin:moreKeys="!label/more_keys_for_w" /> + latin:moreKeys="!label/more_keys_for_c" /> + latin:moreKeys="!label/more_keys_for_v" /> + latin:moreKeys="!label/more_keys_for_n" /> diff --git a/java/res/xml/rowkeys_east_slavic1.xml b/java/res/xml/rowkeys_east_slavic1.xml index 04c6ef6ab..dd83c0250 100644 --- a/java/res/xml/rowkeys_east_slavic1.xml +++ b/java/res/xml/rowkeys_east_slavic1.xml @@ -36,7 +36,7 @@ latin:keyLabel="у" latin:keyHintLabel="3" latin:additionalMoreKeys="3" - latin:moreKeys="@string/more_keys_for_cyrillic_u" /> + latin:moreKeys="!label/more_keys_for_cyrillic_u" /> + latin:moreKeys="!label/more_keys_for_cyrillic_ye" /> + latin:moreKeys="!label/more_keys_for_cyrillic_en" /> @@ -76,5 +76,5 @@ + latin:moreKeys="!label/more_keys_for_cyrillic_ha" /> diff --git a/java/res/xml/rowkeys_east_slavic2.xml b/java/res/xml/rowkeys_east_slavic2.xml index 57b037367..75d7d939d 100644 --- a/java/res/xml/rowkeys_east_slavic2.xml +++ b/java/res/xml/rowkeys_east_slavic2.xml @@ -25,8 +25,8 @@ + latin:keyLabel="!label/keylabel_for_east_slavic_row2_1" + latin:moreKeys="!label/more_keys_for_east_slavic_row2_1" /> @@ -42,7 +42,7 @@ + latin:moreKeys="!label/more_keys_for_cyrillic_o" /> diff --git a/java/res/xml/rowkeys_east_slavic3.xml b/java/res/xml/rowkeys_east_slavic3.xml index b0f7aed7b..a05e92d44 100644 --- a/java/res/xml/rowkeys_east_slavic3.xml +++ b/java/res/xml/rowkeys_east_slavic3.xml @@ -34,14 +34,14 @@ + latin:keyLabel="!label/keylabel_for_east_slavic_row3_5" /> + latin:moreKeys="!label/more_keys_for_cyrillic_soft_sign" /> diff --git a/java/res/xml/rowkeys_nordic1.xml b/java/res/xml/rowkeys_nordic1.xml index 056895f1f..ff29369d7 100644 --- a/java/res/xml/rowkeys_nordic1.xml +++ b/java/res/xml/rowkeys_nordic1.xml @@ -24,5 +24,5 @@ + latin:keyLabel="!label/keylabel_for_nordic_row1_11" /> diff --git a/java/res/xml/rowkeys_nordic2.xml b/java/res/xml/rowkeys_nordic2.xml index 0033ea1bb..52bb2f18f 100644 --- a/java/res/xml/rowkeys_nordic2.xml +++ b/java/res/xml/rowkeys_nordic2.xml @@ -24,9 +24,9 @@ + latin:keyLabel="!label/keylabel_for_nordic_row2_10" + latin:moreKeys="!label/more_keys_for_nordic_row2_10" /> + latin:keyLabel="!label/keylabel_for_nordic_row2_11" + latin:moreKeys="!label/more_keys_for_nordic_row2_11" /> diff --git a/java/res/xml/rowkeys_qwerty1.xml b/java/res/xml/rowkeys_qwerty1.xml index 19067a70c..8fb60db74 100644 --- a/java/res/xml/rowkeys_qwerty1.xml +++ b/java/res/xml/rowkeys_qwerty1.xml @@ -29,42 +29,42 @@ latin:keyLabel="w" latin:keyHintLabel="2" latin:additionalMoreKeys="2" - latin:moreKeys="@string/more_keys_for_w" /> + latin:moreKeys="!label/more_keys_for_w" /> + latin:moreKeys="!label/more_keys_for_e" /> + latin:moreKeys="!label/more_keys_for_r" /> + latin:moreKeys="!label/more_keys_for_t" /> + latin:moreKeys="!label/more_keys_for_y" /> + latin:moreKeys="!label/more_keys_for_u" /> + latin:moreKeys="!label/more_keys_for_i" /> + latin:moreKeys="!label/more_keys_for_o" /> + latin:moreKeys="!label/more_keys_for_a" /> + latin:moreKeys="!label/more_keys_for_s" /> + latin:moreKeys="!label/more_keys_for_d" /> + latin:moreKeys="!label/more_keys_for_g" /> + latin:moreKeys="!label/more_keys_for_h" /> + latin:moreKeys="!label/more_keys_for_j" /> + latin:moreKeys="!label/more_keys_for_k" /> + latin:moreKeys="!label/more_keys_for_l" /> diff --git a/java/res/xml/rowkeys_qwerty3.xml b/java/res/xml/rowkeys_qwerty3.xml index 932ea6f65..afe43f6e4 100644 --- a/java/res/xml/rowkeys_qwerty3.xml +++ b/java/res/xml/rowkeys_qwerty3.xml @@ -23,20 +23,20 @@ > + latin:moreKeys="!label/more_keys_for_z" /> + latin:moreKeys="!label/more_keys_for_c" /> + latin:moreKeys="!label/more_keys_for_v" /> + latin:moreKeys="!label/more_keys_for_n" /> diff --git a/java/res/xml/rowkeys_qwertz1.xml b/java/res/xml/rowkeys_qwertz1.xml index 3e11a7ab4..12788968a 100644 --- a/java/res/xml/rowkeys_qwertz1.xml +++ b/java/res/xml/rowkeys_qwertz1.xml @@ -29,42 +29,42 @@ latin:keyLabel="w" latin:keyHintLabel="2" latin:additionalMoreKeys="2" - latin:moreKeys="@string/more_keys_for_w" /> + latin:moreKeys="!label/more_keys_for_w" /> + latin:moreKeys="!label/more_keys_for_e" /> + latin:moreKeys="!label/more_keys_for_r" /> + latin:moreKeys="!label/more_keys_for_t" /> + latin:moreKeys="!label/more_keys_for_z" /> + latin:moreKeys="!label/more_keys_for_u" /> + latin:moreKeys="!label/more_keys_for_i" /> + latin:moreKeys="!label/more_keys_for_o" /> + latin:moreKeys="!label/more_keys_for_y" /> + latin:moreKeys="!label/more_keys_for_c" /> + latin:moreKeys="!label/more_keys_for_v" /> + latin:moreKeys="!label/more_keys_for_n" /> diff --git a/java/res/xml/rowkeys_south_slavic1.xml b/java/res/xml/rowkeys_south_slavic1.xml index e3cb89c67..7c9a3bc92 100644 --- a/java/res/xml/rowkeys_south_slavic1.xml +++ b/java/res/xml/rowkeys_south_slavic1.xml @@ -36,7 +36,7 @@ latin:keyLabel="е" latin:keyHintLabel="3" latin:additionalMoreKeys="3" - latin:moreKeys="@string/more_keys_for_cyrillic_ie" /> + latin:moreKeys="!label/more_keys_for_cyrillic_ie" /> @@ -61,7 +61,7 @@ latin:keyLabel="и" latin:keyHintLabel="8" latin:additionalMoreKeys="8" - latin:moreKeys="@string/more_keys_for_cyrillic_i" /> + latin:moreKeys="!label/more_keys_for_cyrillic_i" /> + latin:keyLabel="!label/keylabel_for_south_slavic_row2_11" /> diff --git a/java/res/xml/rowkeys_south_slavic3.xml b/java/res/xml/rowkeys_south_slavic3.xml index 97ff51ee1..d668ddf39 100644 --- a/java/res/xml/rowkeys_south_slavic3.xml +++ b/java/res/xml/rowkeys_south_slavic3.xml @@ -22,7 +22,7 @@ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" > + latin:keyLabel="!label/keylabel_for_south_slavic_row3_1" /> @@ -42,7 +42,7 @@ + latin:keyLabel="!label/keylabel_for_south_slavic_row3_8" /> diff --git a/java/res/xml/rowkeys_symbols1.xml b/java/res/xml/rowkeys_symbols1.xml index f6d6243d1..f9f8bb16c 100644 --- a/java/res/xml/rowkeys_symbols1.xml +++ b/java/res/xml/rowkeys_symbols1.xml @@ -22,43 +22,43 @@ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" > + latin:keyLabel="!label/keylabel_for_symbols_1" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_1" + latin:moreKeys="!label/more_keys_for_symbols_1" /> + latin:keyLabel="!label/keylabel_for_symbols_2" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_2" + latin:moreKeys="!label/more_keys_for_symbols_2" /> + latin:keyLabel="!label/keylabel_for_symbols_3" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_3" + latin:moreKeys="!label/more_keys_for_symbols_3" /> + latin:keyLabel="!label/keylabel_for_symbols_4" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_4" + latin:moreKeys="!label/more_keys_for_symbols_4" /> + latin:keyLabel="!label/keylabel_for_symbols_5" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_5" + latin:moreKeys="!label/more_keys_for_symbols_5" /> + latin:keyLabel="!label/keylabel_for_symbols_6" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_6" + latin:moreKeys="!label/more_keys_for_symbols_6" /> + latin:keyLabel="!label/keylabel_for_symbols_7" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_7" + latin:moreKeys="!label/more_keys_for_symbols_7" /> + latin:keyLabel="!label/keylabel_for_symbols_8" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_8" + latin:moreKeys="!label/more_keys_for_symbols_8" /> + latin:keyLabel="!label/keylabel_for_symbols_9" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_9" + latin:moreKeys="!label/more_keys_for_symbols_9" /> + latin:keyLabel="!label/keylabel_for_symbols_0" + latin:additionalMoreKeys="!label/additional_more_keys_for_symbols_0" + latin:moreKeys="!label/more_keys_for_symbols_0" /> diff --git a/java/res/xml/rowkeys_symbols2.xml b/java/res/xml/rowkeys_symbols2.xml index 1092421d8..47865a989 100644 --- a/java/res/xml/rowkeys_symbols2.xml +++ b/java/res/xml/rowkeys_symbols2.xml @@ -28,21 +28,21 @@ + latin:keyLabel="!label/keylabel_for_symbols_percent" + latin:moreKeys="!label/more_keys_for_symbols_percent" /> + latin:moreKeys="!label/more_keys_for_star" /> + U+2014: "—" EM DASH --> + latin:moreKeys="!label/more_keys_for_plus" /> diff --git a/java/res/xml/rowkeys_symbols3.xml b/java/res/xml/rowkeys_symbols3.xml index 1a484d416..4cef6b255 100644 --- a/java/res/xml/rowkeys_symbols3.xml +++ b/java/res/xml/rowkeys_symbols3.xml @@ -31,20 +31,20 @@ latin:moreKeys="¡" /> + latin:moreKeys="!label/more_keys_for_double_quote" /> + latin:moreKeys="!label/more_keys_for_single_quote" /> + latin:keyLabel="!label/keylabel_for_symbols_semicolon" + latin:moreKeys="!label/more_keys_for_symbols_semicolon" /> + latin:keyLabel="!label/keylabel_for_symbols_question" + latin:moreKeys="!label/more_keys_for_symbols_question" /> + latin:moreKeys="!label/more_keys_for_bullet" /> diff --git a/java/res/xml/rows_number_normal.xml b/java/res/xml/rows_number_normal.xml index 6f9429cd8..7015bb2d6 100644 --- a/java/res/xml/rows_number_normal.xml +++ b/java/res/xml/rows_number_normal.xml @@ -61,7 +61,7 @@ diff --git a/java/res/xml/rows_symbols4.xml b/java/res/xml/rows_symbols4.xml index 3e26650e8..de7e043e8 100644 --- a/java/res/xml/rows_symbols4.xml +++ b/java/res/xml/rows_symbols4.xml @@ -37,9 +37,9 @@ diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index fbb13c25f..254d2d618 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -189,11 +189,11 @@ public class Key { * @param row the row that this key belongs to. row's x-coordinate will be the right edge of * this key. * @param parser the XML parser containing the attributes for this key - * @param keyStyles active key styles set * @throws XmlPullParserException */ public Key(Resources res, Keyboard.Params params, Keyboard.Builder.Row row, - XmlPullParser parser, KeyStyles keyStyles) throws XmlPullParserException { + XmlPullParser parser) throws XmlPullParserException { + final KeyStyles keyStyles = params.mKeyStyles; final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap; final int keyHeight = row.mRowHeight; mVerticalGap = params.mVerticalGap; @@ -210,7 +210,7 @@ public class Key { throw new XmlParseUtils.ParseException( "Unknown key style: " + styleName, parser); } else { - style = KeyStyles.getEmptyKeyStyle(); + style = keyStyles.getEmptyKeyStyle(); } final float keyXPos = row.getKeyX(keyAttr); @@ -709,8 +709,8 @@ public class Key { public static class Spacer extends Key { public Spacer(Resources res, Keyboard.Params params, Keyboard.Builder.Row row, - XmlPullParser parser, KeyStyles keyStyles) throws XmlPullParserException { - super(res, params, row, parser, keyStyles); + XmlPullParser parser) throws XmlPullParserException { + super(res, params, row, parser); } /** diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 36a988bb6..4018d65d4 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -30,6 +30,7 @@ import android.view.InflateException; import com.android.inputmethod.keyboard.internal.KeyStyles; import com.android.inputmethod.keyboard.internal.KeyboardCodesSet; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; +import com.android.inputmethod.keyboard.internal.KeyboardLabelsSet; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.Utils; @@ -240,6 +241,8 @@ public class Keyboard { public final ArrayList mAltCodeKeysWhileTyping = new ArrayList(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); public final KeyboardCodesSet mCodesSet = new KeyboardCodesSet(); + public final KeyboardLabelsSet mLabelsSet = new KeyboardLabelsSet(); + public final KeyStyles mKeyStyles = new KeyStyles(mLabelsSet); public KeyboardLayoutSet.KeysCache mKeysCache; @@ -500,7 +503,6 @@ public class Keyboard { private boolean mLeftEdge; private boolean mTopEdge; private Key mRightEdgeKey = null; - private final KeyStyles mKeyStyles = new KeyStyles(); /** * Container for keys in the keyboard. All keys in a row are at the same Y-coordinate. @@ -777,7 +779,10 @@ public class Keyboard { params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0); params.mIconsSet.loadIcons(keyboardAttr); - params.mCodesSet.setLanguage(params.mId.mLocale.getLanguage()); + final String language = params.mId.mLocale.getLanguage(); + params.mCodesSet.setLanguage(language); + params.mLabelsSet.setLanguage(language); + params.mLabelsSet.loadStringResources(mContext); final int resourceId = keyboardAttr.getResourceId( R.styleable.Keyboard_touchPositionCorrectionData, 0); @@ -887,7 +892,7 @@ public class Keyboard { XmlParseUtils.checkEndTag(TAG_KEY, parser); if (DEBUG) startEndTag("<%s /> skipped", TAG_KEY); } else { - final Key key = new Key(mResources, mParams, row, parser, mKeyStyles); + final Key key = new Key(mResources, mParams, row, parser); if (DEBUG) { startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"), key, @@ -904,8 +909,7 @@ public class Keyboard { XmlParseUtils.checkEndTag(TAG_SPACER, parser); if (DEBUG) startEndTag("<%s /> skipped", TAG_SPACER); } else { - final Key.Spacer spacer = new Key.Spacer( - mResources, mParams, row, parser, mKeyStyles); + final Key.Spacer spacer = new Key.Spacer(mResources, mParams, row, parser); if (DEBUG) startEndTag("<%s />", TAG_SPACER); XmlParseUtils.checkEndTag(TAG_SPACER, parser); endKey(spacer); @@ -1210,7 +1214,7 @@ public class Keyboard { skip ? " skipped" : ""); } if (!skip) - mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser); + mParams.mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser); } finally { keyStyleAttr.recycle(); keyAttrs.recycle(); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index 51cd90549..c8ec3a4dd 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -65,9 +65,7 @@ public class KeyboardLayoutSet { private static final String DEFAULT_KEYBOARD_LAYOUT_SET = "qwerty"; private static final char KEYBOARD_LAYOUT_SET_LOCALE_DELIMITER = ':'; - private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "xml/keyboard_layout_set_"; - private static final int DEFAULT_KEYBOARD_LAYOUT_SET_RESOURCE_ID = - R.xml.keyboard_layout_set_qwerty; + private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "keyboard_layout_set_"; private final Context mContext; private final Params mParams; @@ -319,9 +317,10 @@ public class KeyboardLayoutSet { throw new RuntimeException("Screen geometry is not specified"); if (mParams.mLocale == null) throw new RuntimeException("KeyboardLayoutSet subtype is not specified"); + final String packageName = mResources.getResourcePackageName( + R.xml.keyboard_layout_set_qwerty); final String keyboardLayoutSetName = mParams.mKeyboardLayoutSetName; - final int xmlId = KeySpecParser.getResourceId( - mResources, keyboardLayoutSetName, DEFAULT_KEYBOARD_LAYOUT_SET_RESOURCE_ID); + final int xmlId = mResources.getIdentifier(keyboardLayoutSetName, "xml", packageName); final RunInLocale job = new RunInLocale() { @Override protected Void job(Resources res) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index 288fb4556..2981a8e5c 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -16,7 +16,6 @@ package com.android.inputmethod.keyboard.internal; -import android.content.res.Resources; import android.text.TextUtils; import com.android.inputmethod.keyboard.Keyboard; @@ -27,18 +26,20 @@ import java.util.ArrayList; import java.util.Arrays; /** - * String parser of moreKeys attribute of Key. - * The string is comma separated texts each of which represents one "more key". - * - String resource can be embedded into specification @string/name. This is done before parsing - * comma. + * The string parser of more keys specification. + * The specification is comma separated texts each of which represents one "more key". + * The specification might have label or string resource reference in it. These references are + * expanded before parsing comma. + * - Label reference should be a string representation of label (!label/label_name) + * - String resource reference should be a string representation of resource (!label/resource_name) * Each "more key" specification is one of the following: * - Label optionally followed by keyOutputText or code (keyLabel|keyOutputText). * - Icon followed by keyOutputText or code (!icon/icon_name|!code/code_name) * - Icon should be a string representation of icon (!icon/icon_name). - * - Code should be a code point presented by hexadecimal string prefixed with "0x". - * Or a string representation of code (!code/code_name). + * - Code should be a code point presented by hexadecimal string prefixed with "0x", or a string + * representation of code (!code/code_name). * Special character, comma ',' backslash '\', and bar '|' can be escaped by '\' character. - * Note that the character '@' and '\' are also parsed by XML parser and CSV parser as well. + * Note that the '\' is also parsed by XML parser and CSV parser as well. * See {@link KeyboardIconsSet} about icon_name. */ public class KeySpecParser { @@ -49,10 +50,8 @@ public class KeySpecParser { // Constants for parsing. private static int COMMA = ','; private static final char ESCAPE_CHAR = '\\'; - private static final char PREFIX_AT = '@'; - private static final char SUFFIX_SLASH = '/'; - private static final String PREFIX_STRING = PREFIX_AT + "string" + SUFFIX_SLASH; private static final char LABEL_END = '|'; + private static final String PREFIX_LABEL = "!label/"; private static final String PREFIX_ICON = "!icon/"; private static final String PREFIX_CODE = "!code/"; private static final String PREFIX_HEX = "0x"; @@ -341,17 +340,7 @@ public class KeySpecParser { } } - public static int getResourceId(Resources res, String name, int packageNameResId) { - String packageName = res.getResourcePackageName(packageNameResId); - int resId = res.getIdentifier(name, null, packageName); - if (resId == 0) { - throw new RuntimeException("Unknown resource: " + name); - } - return resId; - } - - private static String resolveStringResource(String rawText, Resources res, - int packageNameResId) { + public static String resolveLabelReference(String rawText, KeyboardLabelsSet labelsSet) { int level = 0; String text = rawText; StringBuilder sb; @@ -362,21 +351,20 @@ public class KeySpecParser { } final int size = text.length(); - if (size < PREFIX_STRING.length()) { + if (size < PREFIX_LABEL.length()) { return text; } sb = null; for (int pos = 0; pos < size; pos++) { final char c = text.charAt(pos); - if (c == PREFIX_AT && text.startsWith(PREFIX_STRING, pos)) { + if (text.startsWith(PREFIX_LABEL, pos) && labelsSet != null) { if (sb == null) { sb = new StringBuilder(text.substring(0, pos)); } - final int end = searchResourceNameEnd(text, pos + PREFIX_STRING.length()); - final String resName = text.substring(pos + 1, end); - final int resId = getResourceId(res, resName, packageNameResId); - sb.append(res.getString(resId)); + final int end = searchLabelNameEnd(text, pos + PREFIX_LABEL.length()); + final String name = text.substring(pos + PREFIX_LABEL.length(), end); + sb.append(labelsSet.getLabel(name)); pos = end - 1; } else if (c == ESCAPE_CHAR) { if (sb != null) { @@ -397,7 +385,7 @@ public class KeySpecParser { return text; } - private static int searchResourceNameEnd(String text, int start) { + private static int searchLabelNameEnd(String text, int start) { final int size = text.length(); for (int pos = start; pos < size; pos++) { final char c = text.charAt(pos); @@ -410,8 +398,8 @@ public class KeySpecParser { return size; } - public static String[] parseCsvString(String rawText, Resources res, int packageNameResId) { - final String text = resolveStringResource(rawText, res, packageNameResId); + public static String[] parseCsvString(String rawText, KeyboardLabelsSet labelsSet) { + final String text = resolveLabelReference(rawText, labelsSet); final int size = text.length(); if (size == 0) { return null; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 405b7ad05..8e0b21607 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -34,24 +34,55 @@ public class KeyStyles { private final HashMap mStyles = new HashMap(); - private static final KeyStyle EMPTY_KEY_STYLE = new EmptyKeyStyle(); - public interface KeyStyle { - public String[] getStringArray(TypedArray a, int index); - public String getString(TypedArray a, int index); - public int getInt(TypedArray a, int index, int defaultValue); - public int getFlag(TypedArray a, int index); + private final KeyboardLabelsSet mLabelsSet; + private final KeyStyle mEmptyKeyStyle; + + public KeyStyles(KeyboardLabelsSet labelsSet) { + mLabelsSet = labelsSet; + mEmptyKeyStyle = new EmptyKeyStyle(labelsSet); + } + + public static abstract class KeyStyle { + protected final KeyboardLabelsSet mLabelsSet; + + public KeyStyle(KeyboardLabelsSet labelsSet) { + mLabelsSet = labelsSet; + } + + public abstract String[] getStringArray(TypedArray a, int index); + public abstract String getString(TypedArray a, int index); + public abstract int getInt(TypedArray a, int index, int defaultValue); + public abstract int getFlag(TypedArray a, int index); + + protected String parseString(TypedArray a, int index) { + if (a.hasValue(index)) { + return KeySpecParser.resolveLabelReference(a.getString(index), mLabelsSet); + } + return null; + } + + protected String[] parseStringArray(TypedArray a, int index) { + if (a.hasValue(index)) { + return KeySpecParser.parseCsvString(a.getString(index), mLabelsSet); + } + return null; + } } - static class EmptyKeyStyle implements KeyStyle { + private static class EmptyKeyStyle extends KeyStyle { + public EmptyKeyStyle(KeyboardLabelsSet labelsSet) { + super(labelsSet); + } + @Override public String[] getStringArray(TypedArray a, int index) { - return KeyStyles.parseStringArray(a, index); + return parseStringArray(a, index); } @Override public String getString(TypedArray a, int index) { - return a.getString(index); + return parseString(a, index); } @Override @@ -65,9 +96,13 @@ public class KeyStyles { } } - static class DeclaredKeyStyle implements KeyStyle { + private static class DeclaredKeyStyle extends KeyStyle { private final HashMap mStyleAttributes = new HashMap(); + public DeclaredKeyStyle(KeyboardLabelsSet labelsSet) { + super(labelsSet); + } + @Override public String[] getStringArray(TypedArray a, int index) { if (a.hasValue(index)) { @@ -79,7 +114,7 @@ public class KeyStyles { @Override public String getString(TypedArray a, int index) { if (a.hasValue(index)) { - return a.getString(index); + return parseString(a, index); } return (String)mStyleAttributes.get(index); } @@ -120,7 +155,7 @@ public class KeyStyles { private void readString(TypedArray a, int index) { if (a.hasValue(index)) { - mStyleAttributes.put(index, a.getString(index)); + mStyleAttributes.put(index, parseString(a, index)); } } @@ -131,16 +166,15 @@ public class KeyStyles { } private void readFlag(TypedArray a, int index) { - final Integer value = (Integer)mStyleAttributes.get(index); if (a.hasValue(index)) { + final Integer value = (Integer)mStyleAttributes.get(index); mStyleAttributes.put(index, a.getInt(index, 0) | (value != null ? value : 0)); } } private void readStringArray(TypedArray a, int index) { - final String[] value = parseStringArray(a, index); - if (value != null) { - mStyleAttributes.put(index, value); + if (a.hasValue(index)) { + mStyleAttributes.put(index, parseStringArray(a, index)); } } @@ -149,14 +183,6 @@ public class KeyStyles { } } - static String[] parseStringArray(TypedArray a, int index) { - if (a.hasValue(index)) { - return KeySpecParser.parseCsvString( - a.getString(index), a.getResources(), R.string.english_ime_name); - } - return null; - } - public void parseKeyStyleAttributes(TypedArray keyStyleAttr, TypedArray keyAttrs, XmlPullParser parser) throws XmlPullParserException { final String styleName = keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName); @@ -169,7 +195,7 @@ public class KeyStyles { } } - final DeclaredKeyStyle style = new DeclaredKeyStyle(); + final DeclaredKeyStyle style = new DeclaredKeyStyle(mLabelsSet); if (keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_parentStyle)) { final String parentStyle = keyStyleAttr.getString( R.styleable.Keyboard_KeyStyle_parentStyle); @@ -188,7 +214,7 @@ public class KeyStyles { return mStyles.get(styleName); } - public static KeyStyle getEmptyKeyStyle() { - return EMPTY_KEY_STYLE; + public KeyStyle getEmptyKeyStyle() { + return mEmptyKeyStyle; } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java new file mode 100644 index 000000000..a46f3bf1b --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java @@ -0,0 +1,2477 @@ +/* + * 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.keyboard.internal; + +import android.content.Context; +import android.content.res.Resources; + +import com.android.inputmethod.latin.R; + +import java.util.HashMap; + +/** + * !!!!! DO NOT EDIT THIS FILE !!!!! + * This file is generated by tools/makelabel. + */ +public final class KeyboardLabelsSet { + // Language to labels map. + private static final HashMap sLocaleToLabelsMap = + new HashMap(); + private static final HashMap sNameToIdMap = new HashMap(); + + private String[] mLabels; + // Resource name to label map. + private HashMap mResourceNameToLabelsMap = new HashMap(); + + public void setLanguage(final String language) { + mLabels = sLocaleToLabelsMap.get(language); + if (mLabels == null) { + mLabels = LANGUAGE_DEFAULT; + } + } + + public void loadStringResources(Context context) { + loadStringResourcesInternal(context, RESOURCE_NAMES, R.string.english_ime_name); + } + + /* package for test */ + void loadStringResourcesInternal(Context context, final String[] resourceNames, + int referenceId) { + final Resources res = context.getResources(); + final String packageName = res.getResourcePackageName(referenceId); + for (final String resName : resourceNames) { + final int resId = res.getIdentifier(resName, "string", packageName); + mResourceNameToLabelsMap.put(resName, res.getString(resId)); + } + } + + public String getLabel(final String name) { + if (mResourceNameToLabelsMap.containsKey(name)) { + return mResourceNameToLabelsMap.get(name); + } + final Integer id = sNameToIdMap.get(name); + if (id == null) throw new RuntimeException("Unknown label: " + name); + final String label = (id < mLabels.length) ? mLabels[id] : null; + return (label == null) ? LANGUAGE_DEFAULT[id] : label; + } + + private static final String[] RESOURCE_NAMES = { + // These labels' name should be aligned with the @string/ in values/strings.xml. + // Labels for action. + "label_go_key", + // "label_search_key", + "label_send_key", + "label_next_key", + "label_done_key", + "label_previous_key", + // Other labels. + "label_to_alpha_key", + "label_to_symbol_key", + "label_to_symbol_with_microphone_key", + "label_pause_key", + "label_wait_key", + }; + + private static final String[] NAMES = { + /* 0 */ "more_keys_for_a", + /* 1 */ "more_keys_for_e", + /* 2 */ "more_keys_for_i", + /* 3 */ "more_keys_for_o", + /* 4 */ "more_keys_for_u", + /* 5 */ "more_keys_for_s", + /* 6 */ "more_keys_for_n", + /* 7 */ "more_keys_for_c", + /* 8 */ "more_keys_for_y", + /* 9 */ "more_keys_for_d", + /* 10 */ "more_keys_for_r", + /* 11 */ "more_keys_for_t", + /* 12 */ "more_keys_for_z", + /* 13 */ "more_keys_for_k", + /* 14 */ "more_keys_for_l", + /* 15 */ "more_keys_for_g", + /* 16 */ "more_keys_for_v", + /* 17 */ "more_keys_for_h", + /* 18 */ "more_keys_for_j", + /* 19 */ "more_keys_for_w", + /* 20 */ "keylabel_for_nordic_row1_11", + /* 21 */ "keylabel_for_nordic_row2_10", + /* 22 */ "keylabel_for_nordic_row2_11", + /* 23 */ "more_keys_for_nordic_row2_10", + /* 24 */ "more_keys_for_nordic_row2_11", + /* 25 */ "keylabel_for_east_slavic_row1_9", + /* 26 */ "keylabel_for_east_slavic_row2_1", + /* 27 */ "keylabel_for_east_slavic_row3_5", + /* 28 */ "more_keys_for_cyrillic_u", + /* 29 */ "more_keys_for_cyrillic_ye", + /* 30 */ "more_keys_for_cyrillic_en", + /* 31 */ "more_keys_for_cyrillic_ha", + /* 32 */ "more_keys_for_east_slavic_row2_1", + /* 33 */ "more_keys_for_cyrillic_o", + /* 34 */ "more_keys_for_cyrillic_soft_sign", + /* 35 */ "keylabel_for_south_slavic_row1_6", + /* 36 */ "keylabel_for_south_slavic_row2_11", + /* 37 */ "keylabel_for_south_slavic_row3_1", + /* 38 */ "keylabel_for_south_slavic_row3_8", + /* 39 */ "more_keys_for_cyrillic_ie", + /* 40 */ "more_keys_for_cyrillic_i", + /* 41 */ "more_keys_for_single_quote", + /* 42 */ "more_keys_for_double_quote", + /* 43 */ "more_keys_for_tablet_double_quote", + /* 44 */ "more_keys_for_currency_dollar", + /* 45 */ "more_keys_for_currency_euro", + /* 46 */ "more_keys_for_currency_pound", + /* 47 */ "more_keys_for_currency_general", + /* 48 */ "more_keys_for_smiley", + /* 49 */ "more_keys_for_punctuation", + /* 50 */ "keyhintlabel_for_punctuation", + /* 51 */ "keylabel_for_popular_domain", + /* 52 */ "more_keys_for_popular_domain", + /* 53 */ "keylabel_for_symbols_1", + /* 54 */ "keylabel_for_symbols_2", + /* 55 */ "keylabel_for_symbols_3", + /* 56 */ "keylabel_for_symbols_4", + /* 57 */ "keylabel_for_symbols_5", + /* 58 */ "keylabel_for_symbols_6", + /* 59 */ "keylabel_for_symbols_7", + /* 60 */ "keylabel_for_symbols_8", + /* 61 */ "keylabel_for_symbols_9", + /* 62 */ "keylabel_for_symbols_0", + /* 63 */ "additional_more_keys_for_symbols_1", + /* 64 */ "additional_more_keys_for_symbols_2", + /* 65 */ "additional_more_keys_for_symbols_3", + /* 66 */ "additional_more_keys_for_symbols_4", + /* 67 */ "additional_more_keys_for_symbols_5", + /* 68 */ "additional_more_keys_for_symbols_6", + /* 69 */ "additional_more_keys_for_symbols_7", + /* 70 */ "additional_more_keys_for_symbols_8", + /* 71 */ "additional_more_keys_for_symbols_9", + /* 72 */ "additional_more_keys_for_symbols_0", + /* 73 */ "more_keys_for_symbols_1", + /* 74 */ "more_keys_for_symbols_2", + /* 75 */ "more_keys_for_symbols_3", + /* 76 */ "more_keys_for_symbols_4", + /* 77 */ "more_keys_for_symbols_5", + /* 78 */ "more_keys_for_symbols_6", + /* 79 */ "more_keys_for_symbols_7", + /* 80 */ "more_keys_for_symbols_8", + /* 81 */ "more_keys_for_symbols_9", + /* 82 */ "more_keys_for_symbols_0", + /* 83 */ "more_keys_for_am_pm", + /* 84 */ "settings_as_more_key", + /* 85 */ "keylabel_for_comma", + /* 86 */ "more_keys_for_comma", + /* 87 */ "action_next_as_more_key", + /* 88 */ "action_previous_as_more_key", + /* 89 */ "keylabel_for_symbols_question", + /* 90 */ "keylabel_for_symbols_semicolon", + /* 91 */ "keylabel_for_symbols_percent", + /* 92 */ "more_keys_for_symbols_question", + /* 93 */ "more_keys_for_symbols_semicolon", + /* 94 */ "more_keys_for_symbols_percent", + /* 95 */ "keylabel_for_tablet_comma", + /* 96 */ "keyhintlabel_for_tablet_comma", + /* 97 */ "more_keys_for_tablet_comma", + /* 98 */ "keyhintlabel_for_tablet_period", + /* 99 */ "more_keys_for_tablet_period", + /* 100 */ "keylabel_for_apostrophe", + /* 101 */ "keylabel_for_dash", + /* 102 */ "keyhintlabel_for_apostrophe", + /* 103 */ "keyhintlabel_for_dash", + /* 104 */ "more_keys_for_apostrophe", + /* 105 */ "more_keys_for_dash", + /* 106 */ "more_keys_for_bullet", + /* 107 */ "more_keys_for_star", + /* 108 */ "more_keys_for_plus", + /* 109 */ "more_keys_for_left_parenthesis", + /* 110 */ "more_keys_for_right_parenthesis", + /* 111 */ "more_keys_for_less_than", + /* 112 */ "more_keys_for_greater_than", + /* 113 */ "label_to_more_symbol_key", + /* 114 */ "label_to_more_symbol_for_tablet_key", + /* 115 */ "label_tab_key", + /* 116 */ "label_to_phone_numeric_key", + /* 117 */ "label_to_phone_symbols_key", + /* 118 */ "label_time_am", + /* 119 */ "label_time_pm", + }; + + private static final String EMPTY = ""; + + /* Default labels */ + private static final String[] LANGUAGE_DEFAULT = { + /* 0~ */ + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + EMPTY, EMPTY, + /* ~40 */ + /* 41 */ "!fixedColumnOrder!4,\u2018,\u2019,\u201A,\u201B", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK. !fixedColumnOrder!6,“,”,„,‟,«,» + /* 42 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB,\u00BB", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK. !fixedColumnOrder!6,“,”,„,‟,«,»,‘,’,‚,‛ + /* 43 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB,\u00BB,\u2018,\u2019,\u201A,\u201B", + // U+00A2: "¢" CENT SIGN + // U+00A3: "£" POUND SIGN + // U+20AC: "€" EURO SIGN + // U+00A5: "¥" YEN SIGN + // U+20B1: "₱" PESO SIGN + /* 44 */ "\u00A2,\u00A3,\u20AC,\u00A5,\u20B1", + /* 45 */ "\u00A2,\u00A3,$,\u00A5,\u20B1", + /* 46 */ "\u00A2,$,\u20AC,\u00A5,\u20B1", + /* 47 */ "\u00A2,$,\u20AC,\u00A3,\u00A5,\u20B1", + /* 48 */ "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ ", + /* 49 */ "!fixedColumnOrder!8,\",\',#,-,:,!,\\,,?,@,&,\\%,+,;,/,(,)", + /* 50 */ EMPTY, + /* 51 */ ".com", + // popular web domains for the locale - most popular, displayed on the keyboard + /* 52 */ "!hasLabels!,.net,.org,.gov,.edu", + /* 53 */ "1", + /* 54 */ "2", + /* 55 */ "3", + /* 56 */ "4", + /* 57 */ "5", + /* 58 */ "6", + /* 59 */ "7", + /* 60 */ "8", + /* 61 */ "9", + /* 62 */ "0", + /* 63~ */ + EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, + /* ~72 */ + // U+00B9: "¹" SUPERSCRIPT ONE + // U+00BD: "½" VULGAR FRACTION ONE HALF + // U+2153: "⅓" VULGAR FRACTION ONE THIRD + // U+00BC: "¼" VULGAR FRACTION ONE QUARTER + // U+215B: "⅛" VULGAR FRACTION ONE EIGHTH + /* 73 */ "\u00B9,\u00BD,\u2153,\u00BC,\u215B", + // U+00B2: "²" SUPERSCRIPT TWO + // U+2154: "⅔" VULGAR FRACTION TWO THIRDS + /* 74 */ "\u00B2,\u2154", + // U+00B3: "³" SUPERSCRIPT THREE + // U+00BE: "¾" VULGAR FRACTION THREE QUARTERS + // U+215C: "⅜" VULGAR FRACTION THREE EIGHTHS + /* 75 */ "\u00B3,\u00BE,\u215C", + // U+2074: "⁴" SUPERSCRIPT FOUR + /* 76 */ "\u2074", + // U+215D: "⅝" VULGAR FRACTION FIVE EIGHTHS + /* 77 */ "\u215D", + /* 78 */ EMPTY, + // U+215E: "⅞" VULGAR FRACTION SEVEN EIGHTHS + /* 79 */ "\u215E", + /* 80 */ EMPTY, + /* 81 */ EMPTY, + // U+207F: "ⁿ" SUPERSCRIPT LATIN SMALL LETTER N + // U+2205: "∅" EMPTY SET + /* 82 */ "\u207F,\u2205", + /* 83 */ "!fixedColumnOrder!2,!hasLabels!,!label/label_time_am,!label/label_time_pm", + /* 84 */ "!icon/settingsKey|!code/key_settings", + /* 85 */ ",", + /* 86 */ EMPTY, + /* 87 */ "!hasLabels!,!label/label_next_key|!code/key_action_next", + /* 88 */ "!hasLabels!,!label/label_previous_key|!code/key_action_previous", + /* 89 */ "?", + /* 90 */ ";", + /* 91 */ "%", + // U+00BF: "¿" INVERTED QUESTION MARK + /* 92 */ "\u00BF", + /* 93 */ EMPTY, + // U+2030: "‰" PER MILLE SIGN + /* 94 */ "\u2030", + /* 95 */ ",", + /* 96 */ "!", + /* 97 */ "!", + /* 98 */ "?", + /* 99 */ "?", + /* 100 */ "\'", + /* 101 */ "-", + /* 102 */ "\"", + /* 103 */ "_", + /* 104 */ "\"", + /* 105 */ "_", + // U+266A: "♪" EIGHTH NOTE + // U+2665: "♥" BLACK HEART SUIT + // U+2660: "♠" BLACK SPADE SUIT + // U+2666: "♦" BLACK DIAMOND SUIT + // U+2663: "♣" BLACK CLUB SUIT + /* 106 */ "\u266A,\u2665,\u2660,\u2666,\u2663", + // U+2020: "†" DAGGER + // U+2021: "‡" DOUBLE DAGGER + // U+2605: "★" BLACK STAR + /* 107 */ "\u2020,\u2021,\u2605", + // U+00B1: "±" PLUS-MINUS SIGN + /* 108 */ "\u00B1", + // The all letters need to be mirrored are found at + // http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt + /* 109 */ "!fixedColumnOrder!3,<,{,[", + /* 110 */ "!fixedColumnOrder!3,>,},]", + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // The following characters don't need BIDI mirroring. + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + // U+201B: "‛" SINGLE HIGH-REVERSED-9 QUOTATION MARK + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + // U+201F: "‟" DOUBLE HIGH-REVERSED-9 QUOTATION MARK + /* 111 */ "!fixedColumnOrder!3,\u2039,\u2264,\u00AB", + /* 112 */ "!fixedColumnOrder!3,\u203A,\u2265,\u00BB", + // Label for "switch to more symbol" modifier key. Must be short to fit on key! + /* 113 */ "= \\ <", + // Label for "switch to more symbol" modifier key on tablets. Must be short to fit on key! + /* 114 */ "~ \\ {", + // Label for "Tab" key. Must be short to fit on key! + /* 115 */ "Tab", + // Label for "switch to phone numeric" key. Must be short to fit on key! + /* 116 */ "123", + // Label for "switch to phone symbols" key. Must be short to fit on key! U+FF0A: "*" FULLWIDTH ASTERISK + // U+FF03: "#" FULLWIDTH NUMBER SIGN + /* 117 */ "\uFF0A\uFF03", + // Key label for "ante meridiem" + /* 118 */ "AM", + // Key label for "post meridiem" + /* 119 */ "PM", + }; + + /* Language ar: Arabic */ + private static final String[] LANGUAGE_ar = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + /* ~41 */ + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK “,”,„,‟,«|»,»|« + /* 42 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB|\u00BB,\u00BB|\u00AB", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK !fixedColumnOrder!6,“,”,„,‟,«|»,»|«;,‘,’,‚,‛ + /* 43 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB|\u00BB,\u00BB|\u00AB,\u2018,\u2019,\u201A,\u201B", + /* 44~ */ + null, null, null, null, null, + /* ~48 */ + // U+061F: "؟" ARABIC QUESTION MARK + // U+060C: "،" ARABIC COMMA + // U+061B: "؛" ARABIC SEMICOLON U+0650: "ِ" ARABIC KASRA + // U+064E: "َ" ARABIC FATHA + // U+064D: "ٍ" ARABIC KASRATAN + // U+064B: "ً" ARABIC FATHATAN + // U+0656: "ٖ" ARABIC SUBSCRIPT ALEF + // U+0670: "ٰ" ARABIC LETTER SUPERSCRIPT ALEF + // U+0655: "ٕ" ARABIC HAMZA BELOW + // U+0654: "ٔ" ARABIC HAMZA ABOVE U+064F: "ُ" ARABIC DAMMA + // U+064C: "ٌ" ARABIC DAMMATAN + // U+0651: "ّ" ARABIC SHADDA + // U+0652: "ْ" ARABIC SUKUN + // U+0653: "ٓ" ARABIC MADDAH ABOVE + // U+0640: "ـ" ARABIC TATWEEL In order to make Tatweel easily distinguishable from other punctuations, we use consecutive Tatweels only for its displayed label. + /* 49 */ "!fixedColumnOrder!8,\",\',-,:,!,\u061F,\u060C,\u061B,\u0650,\u064E,\u064D,\u064B,\u0656,\u0670,\u0655,\u0654,\u064F,\u064C,\u0651,\u0652,\u0653,\u0640\u0640\u0640|\u0640,/", + /* 50 */ "\u064B", + /* 51 */ null, + /* 52 */ null, + // U+0661: "١" ARABIC-INDIC DIGIT ONE + /* 53 */ "\u0661", + // U+0662: "٢" ARABIC-INDIC DIGIT TWO + /* 54 */ "\u0662", + // U+0663: "٣" ARABIC-INDIC DIGIT THREE + /* 55 */ "\u0663", + // U+0664: "٤" ARABIC-INDIC DIGIT FOUR + /* 56 */ "\u0664", + // U+0665: "٥" ARABIC-INDIC DIGIT FIVE + /* 57 */ "\u0665", + // U+0666: "٦" ARABIC-INDIC DIGIT SIX + /* 58 */ "\u0666", + // U+0667: "٧" ARABIC-INDIC DIGIT SEVEN + /* 59 */ "\u0667", + // U+0668: "٨" ARABIC-INDIC DIGIT EIGHT + /* 60 */ "\u0668", + // U+0669: "٩" ARABIC-INDIC DIGIT NINE + /* 61 */ "\u0669", + // U+0660: "٠" ARABIC-INDIC DIGIT ZERO + /* 62 */ "\u0660", + /* 63 */ "1", + /* 64 */ "2", + /* 65 */ "3", + /* 66 */ "4", + /* 67 */ "5", + /* 68 */ "6", + /* 69 */ "7", + /* 70 */ "8", + /* 71 */ "9", + // U+066B: "٫" ARABIC DECIMAL SEPARATOR + // U+066C: "٬" ARABIC THOUSANDS SEPARATOR + /* 72 */ "0,\u066B,\u066C", + /* 73~ */ + null, null, null, null, null, null, null, null, null, null, null, null, + /* ~84 */ + // U+060C: "،" ARABIC COMMA + /* 85 */ "\u060C", + /* 86 */ "\\,", + /* 87 */ null, + /* 88 */ null, + /* 89 */ "\u061F", + /* 90 */ "\u061B", + // U+066A: "٪" ARABIC PERCENT SIGN + /* 91 */ "\u066A", + /* 92 */ "?", + /* 93 */ ";", + // U+2030: "‰" PER MILLE SIGN + /* 94 */ "%,\u2030", + /* 95~ */ + null, null, null, null, null, + /* ~99 */ + // U+060C: "،" ARABIC COMMA + // U+061B: "؛" ARABIC SEMICOLON + // U+061F: "؟" ARABIC QUESTION MARK + /* 100 */ "\u060C", + /* 101 */ ".", + /* 102 */ "\u061F", + /* 103 */ "\u064B", + /* 104 */ "\u061F,\u061B,!,:,-,/,\',\"", + // U+0651: "ّ" ARABIC SHADDA + // U+0652: "ْ" ARABIC SUKUN + // U+064C: "ٌ" ARABIC DAMMATAN + // U+0653: "ٓ" ARABIC MADDAH ABOVE + // U+064F: "ُ" ARABIC DAMMA U+0650: "ِ" ARABIC KASRA + // U+064E: "َ" ARABIC FATHA + // U+064B: "ً" ARABIC FATHATAN + // U+0640: "ـ" ARABIC TATWEEL + // U+064D: "ٍ" ARABIC KASRATAN U+0670: "ٰ" ARABIC LETTER SUPERSCRIPT ALEF + // U+0656: "ٖ" ARABIC SUBSCRIPT ALEF + // U+0654: "ٔ" ARABIC HAMZA ABOVE + // U+0655: "ٕ" ARABIC HAMZA BELOW In order to make Tatweel easily distinguishable from other punctuations, we use consecutive Tatweels only for its displayed label. + /* 105 */ "\u0651,\u0652,\u064C,\u0653,\u064F,\u0650,\u064E,\u064B,\u0640\u0640\u0640|\u0640,\u064D,\u0654,\u0656,\u0655,\u0670", + // U+266A: "♪" EIGHTH NOTE + /* 106 */ "\u266A", + // U+2605: "★" BLACK STAR + // U+066D: "٭" ARABIC FIVE POINTED STAR + /* 107 */ "\u2605,\u066D", + /* 108 */ null, + // The all letters need to be mirrored are found at + // http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt U+FD3E: "﴾" ORNATE LEFT PARENTHESIS + // U+FD3F: "﴿" ORNATE RIGHT PARENTHESIS TODO: DroidSansArabic lacks the glyph of U+FD3E ORNATE LEFT PARENTHESIS TODO: DroidSansArabic lacks the glyph of U+FD3F ORNATE RIGHT PARENTHESIS + /* 109 */ "!fixedColumnOrder!4,\uFD3E|\uFD3F,<|>,{|},[|]", + /* 110 */ "!fixedColumnOrder!4,\uFD3F|\uFD3E,>|<,}|{,]|[", + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // The following characters don't need BIDI mirroring. + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + // U+201B: "‛" SINGLE HIGH-REVERSED-9 QUOTATION MARK + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + // U+201F: "‟" DOUBLE HIGH-REVERSED-9 QUOTATION MARK + /* 111 */ "!fixedColumnOrder!3,\u2039|\u203A,\u2264|\u2265,\u00AB|\u00BB", + /* 112 */ "!fixedColumnOrder!3,\u203A|\u2039,\u2265|\u2264,\u00BB|\u00AB", + }; + + /* Language be: Belarusian */ + private static final String[] LANGUAGE_be = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, + /* ~24 */ + // U+045E: "ў" CYRILLIC SMALL LETTER SHORT U + /* 25 */ "\u045E", + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + /* 26 */ "\u044B", + // U+0456: "і" CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I + /* 27 */ "\u0456", + /* 28~ */ + null, null, null, + /* ~30 */ + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 31 */ "\u044A", + /* 32 */ null, + /* 33 */ null, + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 34 */ "\u044A", + }; + + /* Language ca: Catalan */ + private static final String[] LANGUAGE_ca = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E0,\u00E1,\u00E4,\u00E2,\u00E3,\u00E5,\u0105,\u00E6,\u0101,\u00AA", + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E8,\u00E9,\u00EB,\u00EA,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EF,\u00EC,\u00EE,\u012F,\u012B", + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F2,\u00F3,\u00F6,\u00F4,\u00F5,\u00F8,\u0153,\u014D,\u00BA", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00F9,\u00FB,\u016B", + /* 5 */ null, + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u00E7,\u0107,\u010D", + /* 8~ */ + null, null, null, null, null, null, + /* ~13 */ + // U+0140: "ŀ" LATIN SMALL LETTER L WITH MIDDLE DOT + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + /* 14 */ "\u0140,\u0142", + }; + + /* Language cs: Czech */ + private static final String[] LANGUAGE_cs = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E1,\u00E0,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u011B,\u00E8,\u00EA,\u00EB,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EE,\u00EF,\u00EC,\u012F,\u012B", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F3,\u00F6,\u00F4,\u00F2,\u00F5,\u0153,\u00F8,\u014D", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u016F,\u00FB,\u00FC,\u00F9,\u016B", + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + /* 5 */ "\u0161,\u00DF,\u015B", + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u0148,\u00F1,\u0144", + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u010D,\u00E7,\u0107", + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + /* 9 */ "\u010F", + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + /* 10 */ "\u0159", + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + /* 11 */ "\u0165", + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + /* 12 */ "\u017E,\u017A,\u017C", + }; + + /* Language da: Danish */ + private static final String[] LANGUAGE_da = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E1,\u00E4,\u00E0,\u00E2,\u00E3,\u0101", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + /* 1 */ "\u00E9,\u00EB", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + /* 2 */ "\u00ED,\u00EF", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F3,\u00F4,\u00F2,\u00F5,\u0153,\u014D", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00FB,\u00F9,\u016B", + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u00DF,\u015B,\u0161", + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + /* 7 */ null, + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+00F0: "ð" LATIN SMALL LETTER ETH + /* 9 */ "\u00F0", + /* 10~ */ + null, null, null, null, + /* ~13 */ + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + /* 14 */ "\u0142", + /* 15~ */ + null, null, null, null, null, + /* ~19 */ + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + /* 20 */ "\u00E5", + // U+00E6: "æ" LATIN SMALL LETTER AE + /* 21 */ "\u00E6", + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 22 */ "\u00F8", + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + /* 23 */ "\u00E4", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + /* 24 */ "\u00F6", + }; + + /* Language de: German */ + private static final String[] LANGUAGE_de = { + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E4,\u00E2,\u00E0,\u00E1,\u00E6,\u00E3,\u00E5,\u0101", + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + /* 1 */ "\u0117", + /* 2 */ null, + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F6,\u00F4,\u00F2,\u00F3,\u00F5,\u0153,\u00F8,\u014D", + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FC,\u00FB,\u00F9,\u00FA,\u016B", + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u00DF,\u015B,\u0161", + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + }; + + /* Language en: English */ + private static final String[] LANGUAGE_en = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E0,\u00E1,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E8,\u00E9,\u00EA,\u00EB,\u0103", + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + /* 2 */ "\u00EE,\u00EF,\u00ED,\u012B,\u00EC", + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + /* 3 */ "\u00F4,\u00F6,\u00F2,\u00F3,\u0153,\u00F8\u014D,\u00F5", + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FB,\u00FC,\u00F9,\u00FA,\u016B", + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + /* 5 */ "\u00DF", + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + /* 6 */ "\u00F1", + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + /* 7 */ "\u00E7", + }; + + /* Language es: Spanish */ + private static final String[] LANGUAGE_es = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E1,\u00E0,\u00E4,\u00E2,\u00E3,\u00E5,\u0105,\u00E6,\u0101,\u00AA", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00E8,\u00EB,\u00EA,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EF,\u00EC,\u00EE,\u012F,\u012B", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F3,\u00F2,\u00F6,\u00F4,\u00F5,\u00F8,\u0153,\u014D,\u00BA", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00F9,\u00FB,\u016B", + /* 5 */ null, + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u00E7,\u0107,\u010D", + /* 8~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, + /* ~48 */ + // U+00A1: "¡" INVERTED EXCLAMATION MARK + // U+00BF: "¿" INVERTED QUESTION MARK + /* 49 */ "!fixedColumnOrder!7,#,-,\u00A1,!,\u00BF,\\,,?,\\%,+,;,:,/,(,),@,&,\",\'", + }; + + /* Language et: Estonian */ + private static final String[] LANGUAGE_et = { + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + /* 0 */ "\u00E4,\u0101,\u00E0,\u00E1,\u00E2,\u00E3,\u00E5,\u00E6,\u0105", + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + /* 1 */ "\u0113,\u00E8,\u0117,\u00E9,\u00EA,\u00EB,\u0119,\u011B", + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + /* 2 */ "\u012B,\u00EC,\u012F,\u00ED,\u00EE,\u00EF,\u0131", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 3 */ "\u00F6,\u00F5,\u00F2,\u00F3,\u00F4,\u0153,\u0151,\u00F8", + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + /* 4 */ "\u00FC,\u016B,\u0173,\u00F9,\u00FA,\u00FB,\u016F,\u0171", + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + /* 5 */ "\u0161,\u00DF,\u015B,\u015F", + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u0146,\u00F1,\u0144,\u0144", + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u010D,\u00E7,\u0107", + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + /* 9 */ "\u010F", + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + /* 10 */ "\u0157,\u0159,\u0155", + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + /* 11 */ "\u0163,\u0165", + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + /* 12 */ "\u017E,\u017C,\u017A", + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + /* 13 */ "\u0137", + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + /* 14 */ "\u013C,\u0142,\u013A,\u013E", + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + /* 15 */ "\u0123,\u011F", + /* 16~ */ + null, null, null, null, + /* ~19 */ + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + /* 20 */ "\u00FC", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + /* 21 */ "\u00F6", + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + /* 22 */ "\u00E4", + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + /* 23 */ "\u00F5", + }; + + /* Language fa: Persian */ + private static final String[] LANGUAGE_fa = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + /* ~41 */ + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK “,”,„,‟,«|»,»|« + /* 42 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB|\u00BB,\u00BB|\u00AB", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK !fixedColumnOrder!6,“,”,„,‟,«|»,»|«;,‘,’,‚,‛ + /* 43 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB|\u00BB,\u00BB|\u00AB,\u2018,\u2019,\u201A,\u201B", + /* 44~ */ + null, null, null, null, null, + /* ~48 */ + // U+061F: "؟" ARABIC QUESTION MARK + // U+060C: "،" ARABIC COMMA + // U+061B: "؛" ARABIC SEMICOLON U+0650: "ِ" ARABIC KASRA + // U+064E: "َ" ARABIC FATHA + // U+064D: "ٍ" ARABIC KASRATAN + // U+064B: "ً" ARABIC FATHATAN + // U+0656: "ٖ" ARABIC SUBSCRIPT ALEF + // U+0670: "ٰ" ARABIC LETTER SUPERSCRIPT ALEF + // U+0655: "ٕ" ARABIC HAMZA BELOW + // U+0654: "ٔ" ARABIC HAMZA ABOVE U+064F: "ُ" ARABIC DAMMA + // U+064C: "ٌ" ARABIC DAMMATAN + // U+0651: "ّ" ARABIC SHADDA + // U+0652: "ْ" ARABIC SUKUN + // U+0653: "ٓ" ARABIC MADDAH ABOVE + // U+0640: "ـ" ARABIC TATWEEL In order to make Tatweel easily distinguishable from other punctuations, we use consecutive Tatweels only for its displayed label. + /* 49 */ "!fixedColumnOrder!8,\",\',-,:,!,\u061F,\u060C,\u061B,\u0650,\u064E,\u064D,\u064B,\u0656,\u0670,\u0655,\u0654,\u064F,\u064C,\u0651,\u0652,\u0653,\u0640\u0640\u0640|\u0640,/", + /* 50 */ "\u064B", + /* 51 */ null, + /* 52 */ null, + // U+06F1: "۱" EXTENDED ARABIC-INDIC DIGIT ONE + /* 53 */ "\u06F1", + // U+06F2: "۲" EXTENDED ARABIC-INDIC DIGIT TWO + /* 54 */ "\u06F2", + // U+06F3: "۳" EXTENDED ARABIC-INDIC DIGIT THREE + /* 55 */ "\u06F3", + // U+06F4: "۴" EXTENDED ARABIC-INDIC DIGIT FOUR + /* 56 */ "\u06F4", + // U+06F5: "۵" EXTENDED ARABIC-INDIC DIGIT FIVE + /* 57 */ "\u06F5", + // U+06F6: "۶" EXTENDED ARABIC-INDIC DIGIT SIX + /* 58 */ "\u06F6", + // U+06F7: "۷" EXTENDED ARABIC-INDIC DIGIT SEVEN + /* 59 */ "\u06F7", + // U+06F8: "۸" EXTENDED ARABIC-INDIC DIGIT EIGHT + /* 60 */ "\u06F8", + // U+06F9: "۹" EXTENDED ARABIC-INDIC DIGIT NINE + /* 61 */ "\u06F9", + // U+06F0: "۰" EXTENDED ARABIC-INDIC DIGIT ZERO + /* 62 */ "\u06F0", + /* 63 */ "1", + /* 64 */ "2", + /* 65 */ "3", + /* 66 */ "4", + /* 67 */ "5", + /* 68 */ "6", + /* 69 */ "7", + /* 70 */ "8", + /* 71 */ "9", + // U+066B: "٫" ARABIC DECIMAL SEPARATOR + // U+066C: "٬" ARABIC THOUSANDS SEPARATOR + /* 72 */ "0,\u066B,\u066C", + /* 73~ */ + null, null, null, null, null, null, null, null, null, null, null, null, + /* ~84 */ + // U+060C: "،" ARABIC COMMA + /* 85 */ "\u060C", + /* 86 */ "\\,", + /* 87 */ null, + /* 88 */ null, + /* 89 */ "\u061F", + /* 90 */ "\u061B", + // U+066A: "٪" ARABIC PERCENT SIGN + /* 91 */ "\u066A", + /* 92 */ "?", + /* 93 */ ";", + // U+2030: "‰" PER MILLE SIGN + /* 94 */ "%,\u2030", + // U+060C: "،" ARABIC COMMA + // U+061B: "؛" ARABIC SEMICOLON + // U+061F: "؟" ARABIC QUESTION MARK + /* 95 */ "\u060C", + /* 96 */ "!", + /* 97 */ "!,\\,", + /* 98 */ "\u061F", + /* 99 */ "\u061F,?", + /* 100~ */ + null, null, null, + /* ~102 */ + /* 103 */ "\u064B", + /* 104 */ "\u061F,\u061B,!,:,-,/,\',\"", + // U+0651: "ّ" ARABIC SHADDA + // U+0652: "ْ" ARABIC SUKUN + // U+064C: "ٌ" ARABIC DAMMATAN + // U+0653: "ٓ" ARABIC MADDAH ABOVE + // U+064F: "ُ" ARABIC DAMMA U+0650: "ِ" ARABIC KASRA + // U+064E: "َ" ARABIC FATHA + // U+064B: "ً" ARABIC FATHATAN + // U+0640: "ـ" ARABIC TATWEEL + // U+064D: "ٍ" ARABIC KASRATAN U+0670: "ٰ" ARABIC LETTER SUPERSCRIPT ALEF + // U+0656: "ٖ" ARABIC SUBSCRIPT ALEF + // U+0654: "ٔ" ARABIC HAMZA ABOVE + // U+0655: "ٕ" ARABIC HAMZA BELOW In order to make Tatweel easily distinguishable from other punctuations, we use consecutive Tatweels only for its displayed label. + /* 105 */ "\u0651,\u0652,\u064C,\u0653,\u064F,\u0650,\u064E,\u064B,\u0640\u0640\u0640|\u0640,\u064D,\u0654,\u0656,\u0655,_,\u0670", + // U+266A: "♪" EIGHTH NOTE + /* 106 */ "\u266A", + // U+2605: "★" BLACK STAR + // U+066D: "٭" ARABIC FIVE POINTED STAR + /* 107 */ "\u2605,\u066D", + /* 108 */ null, + // The all letters need to be mirrored are found at + // http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt U+FD3E: "﴾" ORNATE LEFT PARENTHESIS + // U+FD3F: "﴿" ORNATE RIGHT PARENTHESIS TODO: DroidSansArabic lacks the glyph of U+FD3E ORNATE LEFT PARENTHESIS TODO: DroidSansArabic lacks the glyph of U+FD3F ORNATE RIGHT PARENTHESIS + /* 109 */ "!fixedColumnOrder!4,\uFD3E|\uFD3F,<|>,{|},[|]", + /* 110 */ "!fixedColumnOrder!4,\uFD3F|\uFD3E,>|<,}|{,]|[", + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // The following characters don't need BIDI mirroring. + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + // U+201B: "‛" SINGLE HIGH-REVERSED-9 QUOTATION MARK + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + // U+201F: "‟" DOUBLE HIGH-REVERSED-9 QUOTATION MARK + /* 111 */ "!fixedColumnOrder!3,\u2039|\u203A,\u2264|\u2265,\u00AB|\u00BB", + /* 112 */ "!fixedColumnOrder!3,\u203A|\u2039,\u2265|\u2264,\u00BB|\u00AB", + }; + + /* Language fi: Finnish */ + private static final String[] LANGUAGE_fi = { + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E6,\u00E0,\u00E1,\u00E2,\u00E3,\u0101", + /* 1 */ null, + /* 2 */ null, + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F8,\u00F4,\u00F2,\u00F3,\u00F5,\u0153,\u014D", + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + /* 4 */ "\u00FC", + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + /* 5 */ "\u0161,\u00DF,\u015B", + /* 6~ */ + null, null, null, null, null, null, + /* ~11 */ + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + /* 12 */ "\u017E,\u017A,\u017C", + /* 13~ */ + null, null, null, null, null, null, null, + /* ~19 */ + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + /* 20 */ "\u00E5", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + /* 21 */ "\u00F6", + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + /* 22 */ "\u00E4", + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 23 */ "\u00F8", + // U+00E6: "æ" LATIN SMALL LETTER AE + /* 24 */ "\u00E6", + }; + + /* Language fr: French */ + private static final String[] LANGUAGE_fr = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E0,\u00E2,%,\u00E6,\u00E1,\u00E4,\u00E3,\u00E5,\u0101,\u00AA", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00E8,\u00EA,\u00EB,%,\u0119,\u0117,\u0113", + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00EE,%,\u00EF,\u00EC,\u00ED,\u012F,\u012B", + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F4,\u0153,%,\u00F6,\u00F2,\u00F3,\u00F5,\u00F8,\u014D,\u00BA", + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00F9,\u00FB,%,\u00FC,\u00FA,\u016B", + /* 5 */ null, + /* 6 */ null, + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u00E7,\u0107,\u010D", + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "%,\u00FF", + }; + + /* Language hi: Hindi */ + private static final String[] LANGUAGE_hi = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, + /* ~52 */ + // U+0967: "१" DEVANAGARI DIGIT ONE + /* 53 */ "\u0967", + // U+0968: "२" DEVANAGARI DIGIT TWO + /* 54 */ "\u0968", + // U+0969: "३" DEVANAGARI DIGIT THREE + /* 55 */ "\u0969", + // U+096A: "४" DEVANAGARI DIGIT FOUR + /* 56 */ "\u096A", + // U+096B: "५" DEVANAGARI DIGIT FIVE + /* 57 */ "\u096B", + // U+096C: "६" DEVANAGARI DIGIT SIX + /* 58 */ "\u096C", + // U+096D: "७" DEVANAGARI DIGIT SEVEN + /* 59 */ "\u096D", + // U+096E: "८" DEVANAGARI DIGIT EIGHT + /* 60 */ "\u096E", + // U+096F: "९" DEVANAGARI DIGIT NINE + /* 61 */ "\u096F", + // U+0966: "०" DEVANAGARI DIGIT ZERO + /* 62 */ "\u0966", + /* 63 */ "1", + /* 64 */ "2", + /* 65 */ "3", + /* 66 */ "4", + /* 67 */ "5", + /* 68 */ "6", + /* 69 */ "7", + /* 70 */ "8", + /* 71 */ "9", + /* 72 */ "0", + }; + + /* Language hr: Croatian */ + private static final String[] LANGUAGE_hr = { + /* 0~ */ + null, null, null, null, null, + /* ~4 */ + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + /* 5 */ "\u0161,\u015B,\u00DF", + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + /* 7 */ "\u010D,\u0107,\u00E7", + /* 8 */ null, + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + /* 9 */ "\u0111", + /* 10 */ null, + /* 11 */ null, + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + /* 12 */ "\u017E,\u017A,\u017C", + }; + + /* Language hu: Hungarian */ + private static final String[] LANGUAGE_hu = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E1,\u00E0,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00E8,\u00EA,\u00EB,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EE,\u00EF,\u00EC,\u012F,\u012B", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F3,\u00F6,\u0151,\u00F4,\u00F2,\u00F5,\u0153,\u00F8,\u014D", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u0171,\u00FB,\u00F9,\u016B", + }; + + /* Language is: Icelandic */ + private static final String[] LANGUAGE_is = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E1,\u00E4,\u00E6,\u00E5,\u00E0,\u00E2,\u00E3,\u0101", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00EB,\u00E8,\u00EA,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EF,\u00EE,\u00EC,\u012F,\u012B", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F3,\u00F6,\u00F4,\u00F2,\u00F5,\u0153,\u00F8,\u014D", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00FB,\u00F9,\u016B", + /* 5~ */ + null, null, null, + /* ~7 */ + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+00F0: "ð" LATIN SMALL LETTER ETH + /* 9 */ "\u00F0", + /* 10 */ null, + // U+00FE: "þ" LATIN SMALL LETTER THORN + /* 11 */ "\u00FE", + /* 12~ */ + null, null, null, null, null, null, null, null, + /* ~19 */ + // U+00F0: "ð" LATIN SMALL LETTER ETH + /* 20 */ "\u00F0", + // U+00E6: "æ" LATIN SMALL LETTER AE + /* 21 */ "\u00E6", + // U+00FE: "þ" LATIN SMALL LETTER THORN + /* 22 */ "\u00FE", + }; + + /* Language it: Italian */ + private static final String[] LANGUAGE_it = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E0,\u00E1,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101,\u00AA", + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E8,\u00E9,\u00EA,\u00EB,\u0119,\u0117,\u0113", + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00EC,\u00ED,\u00EE,\u00EF,\u012F,\u012B", + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F2,\u00F3,\u00F4,\u00F6,\u00F5,\u0153,\u00F8,\u014D,\u00BA", + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00F9,\u00FA,\u00FB,\u00FC,\u016B", + }; + + /* Language iw: Hebrew */ + private static final String[] LANGUAGE_iw = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, + /* ~41 */ + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK “,”,„,‟,«|»,»|« + /* 42 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB|\u00BB,\u00BB|\u00AB", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK !fixedColumnOrder!6,“,”,„,‟,«|»,»|«;,‘,’,‚,‛ + /* 43 */ "!fixedColumnOrder!4,\u201C,\u201D,\u00AB|\u00BB,\u00BB|\u00AB,\u2018,\u2019,\u201A,\u201B", + /* 44~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, + /* ~106 */ + // U+2605: "★" BLACK STAR + /* 107 */ "\u2605", + // U+00B1: "±" PLUS-MINUS SIGN + // U+FB29: "﬩" HEBREW LETTER ALTERNATIVE PLUS SIGN + /* 108 */ "\u00B1,\uFB29", + // The all letters need to be mirrored are found at + // http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt + /* 109 */ "!fixedColumnOrder!3,<|>,{|},[|]", + /* 110 */ "!fixedColumnOrder!3,>|<,}|{,]|[", + // U+2264: "≤" LESS-THAN OR EQUAL TO + // U+2265: "≥" GREATER-THAN EQUAL TO + // U+00AB: "«" LEFT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+00BB: "»" RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK + // U+2039: "‹" SINGLE LEFT-POINTING ANGLE QUOTATION MARK + // U+203A: "›" SINGLE RIGHT-POINTING ANGLE QUOTATION MARK + // The following characters don't need BIDI mirroring. + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + // U+201B: "‛" SINGLE HIGH-REVERSED-9 QUOTATION MARK + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + // U+201F: "‟" DOUBLE HIGH-REVERSED-9 QUOTATION MARK + /* 111 */ "!fixedColumnOrder!3,\u2039|\u203A,\u2264|\u2265,\u00AB|\u00BB", + /* 112 */ "!fixedColumnOrder!3,\u203A|\u2039,\u2265|\u2264,\u00BB|\u00AB", + }; + + /* Language ky: Kirghiz */ + private static final String[] LANGUAGE_ky = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, + /* ~24 */ + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + /* 25 */ "\u0449", + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + /* 26 */ "\u044B", + // U+0438: "и" CYRILLIC SMALL LETTER I + /* 27 */ "\u0438", + // U+04AF: "ү" CYRILLIC SMALL LETTER STRAIGHT U + /* 28 */ "\u04AF", + /* 29 */ null, + // U+04A3: "ң" CYRILLIC SMALL LETTER EN WITH DESCENDER + /* 30 */ "\u04A3", + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 31 */ "\u044A", + /* 32 */ null, + // U+04E9: "ө" CYRILLIC SMALL LETTER BARRED O + /* 33 */ "\u04E9", + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 34 */ "\u044A", + }; + + /* Language lt: Lithuanian */ + private static final String[] LANGUAGE_lt = { + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + /* 0 */ "\u0105,\u00E4,\u0101,\u00E0,\u00E1,\u00E2,\u00E3,\u00E5,\u00E6", + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + /* 1 */ "\u0117,\u0119,\u0113,\u00E8,\u00E9,\u00EA,\u00EB,\u011B", + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + /* 2 */ "\u012F,\u012B,\u00EC,\u00ED,\u00EE,\u00EF,\u0131", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 3 */ "\u00F6,\u00F5,\u00F2,\u00F3,\u00F4,\u0153,\u0151,\u00F8", + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + /* 4 */ "\u016B,\u0173,\u00FC,\u016B,\u00F9,\u00FA,\u00FB,\u016F,\u0171", + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + /* 5 */ "\u0161,\u00DF,\u015B,\u015F", + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u0146,\u00F1,\u0144,\u0144", + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u010D,\u00E7,\u0107", + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + /* 9 */ "\u010F", + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + /* 10 */ "\u0157,\u0159,\u0155", + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + /* 11 */ "\u0163,\u0165", + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + /* 12 */ "\u017E,\u017C,\u017A", + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + /* 13 */ "\u0137", + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + /* 14 */ "\u013C,\u0142,\u013A,\u013E", + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + /* 15 */ "\u0123,\u011F", + }; + + /* Language lv: Latvian */ + private static final String[] LANGUAGE_lv = { + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + /* 0 */ "\u0101,\u00E0,\u00E1,\u00E2,\u00E3,\u00E4,\u00E5,\u00E6,\u0105", + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + /* 1 */ "\u0113,\u0117,\u00E8,\u00E9,\u00EA,\u00EB,\u0119,\u011B", + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + /* 2 */ "\u012B,\u012F,\u00EC,\u00ED,\u00EE,\u00EF,\u0131", + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 3 */ "\u00F2,\u00F3,\u00F4,\u00F5,\u00F6,\u0153,\u0151,\u00F8", + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + /* 4 */ "\u016B,\u0173,\u00F9,\u00FA,\u00FB,\u00FC,\u016F,\u0171", + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + /* 5 */ "\u0161,\u00DF,\u015B,\u015F", + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u0146,\u00F1,\u0144,\u0144", + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u010D,\u00E7,\u0107", + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + /* 9 */ "\u010F", + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + /* 10 */ "\u0157,\u0159,\u0155", + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + /* 11 */ "\u0163,\u0165", + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + /* 12 */ "\u017E,\u017C,\u017A", + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + /* 13 */ "\u0137", + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + /* 14 */ "\u013C,\u0142,\u013A,\u013E", + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + /* 15 */ "\u0123,\u011F", + }; + + /* Language mk: Macedonian */ + private static final String[] LANGUAGE_mk = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, + /* ~34 */ + // U+0455: "ѕ" CYRILLIC SMALL LETTER DZE + /* 35 */ "\u0455", + // U+045C: "ќ" CYRILLIC SMALL LETTER KJE + /* 36 */ "\u045C", + // U+0437: "з" CYRILLIC SMALL LETTER ZE + /* 37 */ "\u0437", + // U+0453: "ѓ" CYRILLIC SMALL LETTER GJE + /* 38 */ "\u0453", + // U+0450: "ѐ" CYRILLIC SMALL LETTER IE WITH GRAVE + /* 39 */ "\u0450", + // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE + /* 40 */ "\u045D", + /* 41 */ null, + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + // U+201B: "‛" SINGLE HIGH-REVERSED-9 QUOTATION MARK + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + // U+201F: "‟" DOUBLE HIGH-REVERSED-9 QUOTATION MARK TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK. !fixedColumnOrder!6,„,“,”,‟,«,» + /* 42 */ "!fixedColumnOrder!5,\u201E,\u201C,\u201D,\u00AB,\u00BB", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK. !fixedColumnOrder!6,“,”,„,‟,«,»,‘,’,‚,‛ + /* 43 */ "!fixedColumnOrder!5,\u201E,\u201C,\u201D,\u00AB,\u00BB,\u2018,\u2019,\u201A,\u201B", + }; + + /* Language nb: Norwegian Bokmål */ + private static final String[] LANGUAGE_nb = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E0,\u00E4,\u00E1,\u00E2,\u00E3,\u0101", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00E8,\u00EA,\u00EB,\u0119,\u0117,\u0113", + /* 2 */ null, + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F4,\u00F2,\u00F3,\u00F6,\u00F5,\u0153,\u014D", + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FC,\u00FB,\u00F9,\u00FA,\u016B", + /* 5~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* ~19 */ + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + /* 20 */ "\u00E5", + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 21 */ "\u00F8", + // U+00E6: "æ" LATIN SMALL LETTER AE + /* 22 */ "\u00E6", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + /* 23 */ "\u00F6", + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + /* 24 */ "\u00E4", + }; + + /* Language nl: Dutch */ + private static final String[] LANGUAGE_nl = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E1,\u00E4,\u00E2,\u00E0,\u00E6,\u00E3,\u00E5,\u0101", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u00E9,\u00EB,\u00EA,\u00E8,\u0119,\u0117,\u0113", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+0133: "ij" LATIN SMALL LIGATURE IJ + /* 2 */ "\u00ED,\u00EF,\u00EC,\u00EE,\u012F,\u012B,\u0133", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F3,\u00F6,\u00F4,\u00F2,\u00F5,\u0153,\u00F8,\u014D", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00FB,\u00F9,\u016B", + /* 5 */ null, + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u00F1,\u0144", + /* 7 */ null, + // U+0133: "ij" LATIN SMALL LIGATURE IJ + /* 8 */ "\u0133", + }; + + /* Language pl: Polish */ + private static final String[] LANGUAGE_pl = { + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u0105,\u00E1,\u00E0,\u00E2,\u00E4,\u00E6,\u00E3,\u00E5,\u0101", + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + /* 1 */ "\u0119,\u00E8,\u00E9,\u00EA,\u00EB,\u0117,\u0113", + /* 2 */ null, + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F3,\u00F6,\u00F4,\u00F2,\u00F5,\u0153,\u00F8,\u014D", + /* 4 */ null, + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u015B,\u00DF,\u0161", + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + /* 6 */ "\u0144,\u00F1", + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u0107,\u00E7,\u010D", + /* 8~ */ + null, null, null, null, + /* ~11 */ + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + /* 12 */ "\u017C,\u017A,\u017E", + /* 13 */ null, + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + /* 14 */ "\u0142", + }; + + /* Language pt: Portuguese */ + private static final String[] LANGUAGE_pt = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E1,\u00E3,\u00E0,\u00E2,\u00E4,\u00E5,\u00E6,\u00AA", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + /* 1 */ "\u00E9,\u00EA,\u00E8,\u0119,\u0117,\u0113,\u00EB", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00ED,\u00EE,\u00EC,\u00EF,\u012F,\u012B", + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F3,\u00F5,\u00F4,\u00F2,\u00F6,\u0153,\u00F8,\u014D,\u00BA", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FA,\u00FC,\u00F9,\u00FB,\u016B", + /* 5 */ null, + /* 6 */ null, + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u00E7,\u010D,\u0107", + }; + + /* Language rm: Raeto-Romance */ + private static final String[] LANGUAGE_rm = { + /* 0~ */ + null, null, null, + /* ~2 */ + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 3 */ "\u00F2,\u00F3,\u00F6,\u00F4,\u00F5,\u0153,\u00F8", + }; + + /* Language ro: Romanian */ + private static final String[] LANGUAGE_ro = { + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + /* 0 */ "\u00E2,\u00E3,\u0103,\u00E0,\u00E1,\u00E4,\u00E6,\u00E5,\u0101", + /* 1 */ null, + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u00EE,\u00EF,\u00EC,\u00ED,\u012F,\u012B", + /* 3 */ null, + /* 4 */ null, + // U+0219: "ș" LATIN SMALL LETTER S WITH COMMA BELOW + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u0219,\u00DF,\u015B,\u0161", + /* 6~ */ + null, null, null, null, null, + /* ~10 */ + // U+021B: "ț" LATIN SMALL LETTER T WITH COMMA BELOW + /* 11 */ "\u021B", + }; + + /* Language ru: Russian */ + private static final String[] LANGUAGE_ru = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, + /* ~24 */ + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + /* 25 */ "\u0449", + // U+044B: "ы" CYRILLIC SMALL LETTER YERU + /* 26 */ "\u044B", + // U+0438: "и" CYRILLIC SMALL LETTER I + /* 27 */ "\u0438", + /* 28 */ null, + // U+0451: "ё" CYRILLIC SMALL LETTER IO + /* 29 */ "\u0451", + /* 30 */ null, + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 31 */ "\u044A", + /* 32 */ null, + /* 33 */ null, + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 34 */ "\u044A", + }; + + /* Language sk: Slovak */ + private static final String[] LANGUAGE_sk = { + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + /* 0 */ "\u00E1,\u00E4,\u0101,\u00E0,\u00E2,\u00E3,\u00E5,\u00E6,\u0105", + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + /* 1 */ "\u00E9,\u011B,\u0113,\u0117,\u00E8,\u00EA,\u00EB,\u0119", + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + /* 2 */ "\u00ED,\u012B,\u012F,\u00EC,\u00EE,\u00EF,\u0131", + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 3 */ "\u00F4,\u00F3,\u00F6,\u00F2,\u00F5,\u0153,\u0151,\u00F8", + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + /* 4 */ "\u00FA,\u016F,\u00FC,\u016B,\u0173,\u00F9,\u00FB,\u0171", + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + /* 5 */ "\u0161,\u00DF,\u015B,\u015F", + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + /* 6 */ "\u0148,\u0146,\u00F1,\u0144,\u0144", + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u010D,\u00E7,\u0107", + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + /* 8 */ "\u00FD,\u00FF", + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + /* 9 */ "\u010F", + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + /* 10 */ "\u0155,\u0159,\u0157", + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + /* 11 */ "\u0165,\u0163", + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + /* 12 */ "\u017E,\u017C,\u017A", + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + /* 13 */ "\u0137", + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + /* 14 */ "\u013E,\u013A,\u013C,\u0142", + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + /* 15 */ "\u0123,\u011F", + }; + + /* Language sl: Slovenian */ + private static final String[] LANGUAGE_sl = { + /* 0~ */ + null, null, null, null, null, + /* ~4 */ + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u0161", + /* 6 */ null, + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + /* 7 */ "\u010D,\u0107", + /* 8 */ null, + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + /* 9 */ "\u0111", + /* 10 */ null, + /* 11 */ null, + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + /* 12 */ "\u017E", + }; + + /* Language sr: Serbian */ + private static final String[] LANGUAGE_sr = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, + /* ~34 */ + // U+0437: "з" CYRILLIC SMALL LETTER ZE + /* 35 */ "\u0437", + // U+045B: "ћ" CYRILLIC SMALL LETTER TSHE + /* 36 */ "\u045B", + // U+0455: "ѕ" CYRILLIC SMALL LETTER DZE + /* 37 */ "\u0455", + // U+0452: "ђ" CYRILLIC SMALL LETTER DJE + /* 38 */ "\u0452", + // U+0450: "ѐ" CYRILLIC SMALL LETTER IE WITH GRAVE + /* 39 */ "\u0450", + // U+045D: "ѝ" CYRILLIC SMALL LETTER I WITH GRAVE + /* 40 */ "\u045D", + /* 41 */ null, + // U+2018: "‘" LEFT SINGLE QUOTATION MARK + // U+2019: "’" RIGHT SINGLE QUOTATION MARK + // U+201A: "‚" SINGLE LOW-9 QUOTATION MARK + // U+201B: "‛" SINGLE HIGH-REVERSED-9 QUOTATION MARK + // U+201C: "“" LEFT DOUBLE QUOTATION MARK + // U+201D: "”" RIGHT DOUBLE QUOTATION MARK + // U+201E: "„" DOUBLE LOW-9 QUOTATION MARK + // U+201F: "‟" DOUBLE HIGH-REVERSED-9 QUOTATION MARK TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK. !fixedColumnOrder!6,„,“,”,‟,«,» + /* 42 */ "!fixedColumnOrder!5,\u201E,\u201C,\u201D,\u00AB,\u00BB", + // TODO: Neither DroidSans nor Roboto have the glyph for U+201F DOUBLE HIGH-REVERSED-9 QUOTATION MARK. !fixedColumnOrder!6,“,”,„,‟,«,»,‘,’,‚,‛ + /* 43 */ "!fixedColumnOrder!5,\u201E,\u201C,\u201D,\u00AB,\u00BB,\u2018,\u2019,\u201A,\u201B", + }; + + /* Language sv: Swedish */ + private static final String[] LANGUAGE_sv = { + /* 0 */ null, + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + /* 1 */ "\u00E9,\u00E8,\u00EA,\u00EB,\u0119", + /* 2 */ null, + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u0153,\u00F4,\u00F2,\u00F3,\u00F5,\u014D", + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FC,\u00FB,\u00F9,\u00FA,\u016B", + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u00DF,\u015B,\u0161", + /* 6~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, + /* ~19 */ + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + /* 20 */ "\u00E5", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + /* 21 */ "\u00F6", + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + /* 22 */ "\u00E4", + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + /* 23 */ "\u00F8", + // U+00E6: "æ" LATIN SMALL LETTER AE + /* 24 */ "\u00E6", + }; + + /* Language tr: Turkish */ + private static final String[] LANGUAGE_tr = { + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + /* 0 */ "\u00E2", + /* 1 */ null, + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + /* 2 */ "\u0131,\u00EE,\u00EF,\u00EC,\u00ED,\u012F,\u012B", + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + /* 3 */ "\u00F6,\u00F4,\u0153,\u00F2,\u00F3,\u00F5,\u00F8,\u014D", + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + /* 4 */ "\u00FC,\u00FB,\u00F9,\u00FA,\u016B", + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + /* 5 */ "\u015F,\u00DF,\u015B,\u0161", + /* 6 */ null, + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u00E7,\u0107,\u010D", + /* 8~ */ + null, null, null, null, null, null, null, + /* ~14 */ + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + /* 15 */ "\u011F", + }; + + /* Language uk: Ukrainian */ + private static final String[] LANGUAGE_uk = { + /* 0~ */ + null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null, null, null, null, null, null, null, + /* ~24 */ + // U+0449: "щ" CYRILLIC SMALL LETTER SHCHA + /* 25 */ "\u0449", + // U+0456: "і" CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I + /* 26 */ "\u0456", + // U+0438: "и" CYRILLIC SMALL LETTER I + /* 27 */ "\u0438", + /* 28~ */ + null, null, null, + /* ~30 */ + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 31 */ "\u044A", + // U+0457: "ї" CYRILLIC SMALL LETTER YI + /* 32 */ "\u0457", + /* 33 */ null, + // U+044A: "ъ" CYRILLIC SMALL LETTER HARD SIGN + /* 34 */ "\u044A", + }; + + /* Language vi: Vietnamese */ + private static final String[] LANGUAGE_vi = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+1EA3: "ả" LATIN SMALL LETTER A WITH HOOK ABOVE + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+1EA1: "ạ" LATIN SMALL LETTER A WITH DOT BELOW + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+1EB1: "ằ" LATIN SMALL LETTER A WITH BREVE AND GRAVE + // U+1EAF: "ắ" LATIN SMALL LETTER A WITH BREVE AND ACUTE + // U+1EB3: "ẳ" LATIN SMALL LETTER A WITH BREVE AND HOOK ABOVE + // U+1EB5: "ẵ" LATIN SMALL LETTER A WITH BREVE AND TILDE + // U+1EB7: "ặ" LATIN SMALL LETTER A WITH BREVE AND DOT BELOW + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+1EA7: "ầ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND GRAVE + // U+1EA5: "ấ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND ACUTE + // U+1EA9: "ẩ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND HOOK ABOVE + // U+1EAB: "ẫ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND TILDE + // U+1EAD: "ậ" LATIN SMALL LETTER A WITH CIRCUMFLEX AND DOT BELOW + /* 0 */ "\u00E0,\u00E1,\u1EA3,\u00E3,\u1EA1,\u0103,\u1EB1,\u1EAF,\u1EB3,\u1EB5,\u1EB7,\u00E2,\u1EA7,\u1EA5,\u1EA9,\u1EAB,\u1EAD", + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+1EBB: "ẻ" LATIN SMALL LETTER E WITH HOOK ABOVE + // U+1EBD: "ẽ" LATIN SMALL LETTER E WITH TILDE + // U+1EB9: "ẹ" LATIN SMALL LETTER E WITH DOT BELOW + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+1EC1: "ề" LATIN SMALL LETTER E WITH CIRCUMFLEX AND GRAVE + // U+1EBF: "ế" LATIN SMALL LETTER E WITH CIRCUMFLEX AND ACUTE + // U+1EC3: "ể" LATIN SMALL LETTER E WITH CIRCUMFLEX AND HOOK ABOVE + // U+1EC5: "ễ" LATIN SMALL LETTER E WITH CIRCUMFLEX AND TILDE + // U+1EC7: "ệ" LATIN SMALL LETTER E WITH CIRCUMFLEX AND DOT BELOW + /* 1 */ "\u00E8,\u00E9,\u1EBB,\u1EBD,\u1EB9,\u00EA,\u1EC1,\u1EBF,\u1EC3,\u1EC5,\u1EC7", + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+1EC9: "ỉ" LATIN SMALL LETTER I WITH HOOK ABOVE + // U+0129: "ĩ" LATIN SMALL LETTER I WITH TILDE + // U+1ECB: "ị" LATIN SMALL LETTER I WITH DOT BELOW + /* 2 */ "\u00EC,\u00ED,\u1EC9,\u0129,\u1ECB", + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+1ECF: "ỏ" LATIN SMALL LETTER O WITH HOOK ABOVE + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+1ECD: "ọ" LATIN SMALL LETTER O WITH DOT BELOW + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+1ED3: "ồ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND GRAVE + // U+1ED1: "ố" LATIN SMALL LETTER O WITH CIRCUMFLEX AND ACUTE + // U+1ED5: "ổ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND HOOK ABOVE + // U+1ED7: "ỗ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND TILDE + // U+1ED9: "ộ" LATIN SMALL LETTER O WITH CIRCUMFLEX AND DOT BELOW + // U+01A1: "ơ" LATIN SMALL LETTER O WITH HORN + // U+1EDD: "ờ" LATIN SMALL LETTER O WITH HORN AND GRAVE + // U+1EDB: "ớ" LATIN SMALL LETTER O WITH HORN AND ACUTE + // U+1EDF: "ở" LATIN SMALL LETTER O WITH HORN AND HOOK ABOVE + // U+1EE1: "ỡ" LATIN SMALL LETTER O WITH HORN AND TILDE + // U+1EE3: "ợ" LATIN SMALL LETTER O WITH HORN AND DOT BELOW + /* 3 */ "\u00F2,\u00F3,\u1ECF,\u00F5,\u1ECD,\u00F4,\u1ED3,\u1ED1,\u1ED5,\u1ED7,\u1ED9,\u01A1,\u1EDD,\u1EDB,\u1EDF,\u1EE1,\u1EE3", + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+1EE7: "ủ" LATIN SMALL LETTER U WITH HOOK ABOVE + // U+0169: "ũ" LATIN SMALL LETTER U WITH TILDE + // U+1EE5: "ụ" LATIN SMALL LETTER U WITH DOT BELOW + // U+01B0: "ư" LATIN SMALL LETTER U WITH HORN + // U+1EEB: "ừ" LATIN SMALL LETTER U WITH HORN AND GRAVE + // U+1EE9: "ứ" LATIN SMALL LETTER U WITH HORN AND ACUTE + // U+1EED: "ử" LATIN SMALL LETTER U WITH HORN AND HOOK ABOVE + // U+1EEF: "ữ" LATIN SMALL LETTER U WITH HORN AND TILDE + // U+1EF1: "ự" LATIN SMALL LETTER U WITH HORN AND DOT BELOW + /* 4 */ "\u00F9,\u00FA,\u1EE7,\u0169,\u1EE5,\u01B0,\u1EEB,\u1EE9,\u1EED,\u1EEF,\u1EF1", + /* 5~ */ + null, null, null, + /* ~7 */ + // U+1EF3: "ỳ" LATIN SMALL LETTER Y WITH GRAVE + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+1EF7: "ỷ" LATIN SMALL LETTER Y WITH HOOK ABOVE + // U+1EF9: "ỹ" LATIN SMALL LETTER Y WITH TILDE + // U+1EF5: "ỵ" LATIN SMALL LETTER Y WITH DOT BELOW + /* 8 */ "\u1EF3,\u00FD,\u1EF7,\u1EF9,\u1EF5", + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + /* 9 */ "\u0111", + }; + + /* Language zz: No language */ + private static final String[] LANGUAGE_zz = { + // U+00E0: "à" LATIN SMALL LETTER A WITH GRAVE + // U+00E1: "á" LATIN SMALL LETTER A WITH ACUTE + // U+00E2: "â" LATIN SMALL LETTER A WITH CIRCUMFLEX + // U+00E3: "ã" LATIN SMALL LETTER A WITH TILDE + // U+00E4: "ä" LATIN SMALL LETTER A WITH DIAERESIS + // U+00E5: "å" LATIN SMALL LETTER A WITH RING ABOVE + // U+00E6: "æ" LATIN SMALL LETTER AE + // U+0101: "ā" LATIN SMALL LETTER A WITH MACRON + // U+0103: "ă" LATIN SMALL LETTER A WITH BREVE + // U+0105: "ą" LATIN SMALL LETTER A WITH OGONEK + // U+00AA: "ª" FEMININE ORDINAL INDICATOR + /* 0 */ "\u00E0,\u00E1,\u00E2,\u00E3,\u00E4,\u00E5,\u00E6,\u00E3,\u00E5,\u0101,\u0103,\u0105,\u00AA", + // U+00E8: "è" LATIN SMALL LETTER E WITH GRAVE + // U+00E9: "é" LATIN SMALL LETTER E WITH ACUTE + // U+00EA: "ê" LATIN SMALL LETTER E WITH CIRCUMFLEX + // U+00EB: "ë" LATIN SMALL LETTER E WITH DIAERESIS + // U+0113: "ē" LATIN SMALL LETTER E WITH MACRON + // U+0115: "ĕ" LATIN SMALL LETTER E WITH BREVE + // U+0117: "ė" LATIN SMALL LETTER E WITH DOT ABOVE + // U+0119: "ę" LATIN SMALL LETTER E WITH OGONEK + // U+011B: "ě" LATIN SMALL LETTER E WITH CARON + /* 1 */ "\u00E8,\u00E9,\u00EA,\u00EB,\u0113,\u0115,\u0117,\u0119,\u011B", + // U+00EC: "ì" LATIN SMALL LETTER I WITH GRAVE + // U+00ED: "í" LATIN SMALL LETTER I WITH ACUTE + // U+00EE: "î" LATIN SMALL LETTER I WITH CIRCUMFLEX + // U+00EF: "ï" LATIN SMALL LETTER I WITH DIAERESIS + // U+0129: "ĩ" LATIN SMALL LETTER I WITH TILDE + // U+012B: "ī" LATIN SMALL LETTER I WITH MACRON + // U+012D: "ĭ" LATIN SMALL LETTER I WITH BREVE + // U+012F: "į" LATIN SMALL LETTER I WITH OGONEK + // U+0131: "ı" LATIN SMALL LETTER DOTLESS I + // U+0133: "ij" LATIN SMALL LIGATURE IJ + /* 2 */ "\u00EC,\u00ED,\u00EE,\u00EF,\u0129,\u012B,\u012D,\u012F,\u0131,\u0133", + // U+00F2: "ò" LATIN SMALL LETTER O WITH GRAVE + // U+00F3: "ó" LATIN SMALL LETTER O WITH ACUTE + // U+00F4: "ô" LATIN SMALL LETTER O WITH CIRCUMFLEX + // U+00F5: "õ" LATIN SMALL LETTER O WITH TILDE + // U+00F6: "ö" LATIN SMALL LETTER O WITH DIAERESIS + // U+00F8: "ø" LATIN SMALL LETTER O WITH STROKE + // U+014D: "ō" LATIN SMALL LETTER O WITH MACRON + // U+014F: "ŏ" LATIN SMALL LETTER O WITH BREVE + // U+0151: "ő" LATIN SMALL LETTER O WITH DOUBLE ACUTE + // U+0153: "œ" LATIN SMALL LIGATURE OE + // U+00BA: "º" MASCULINE ORDINAL INDICATOR + /* 3 */ "\u00F2,\u00F3,\u00F4,\u00F5,\u00F6,\u00F8,\u014D,\u014F,\u0151,\u0153,\u00BA", + // U+00F9: "ù" LATIN SMALL LETTER U WITH GRAVE + // U+00FA: "ú" LATIN SMALL LETTER U WITH ACUTE + // U+00FB: "û" LATIN SMALL LETTER U WITH CIRCUMFLEX + // U+00FC: "ü" LATIN SMALL LETTER U WITH DIAERESIS + // U+0169: "ũ" LATIN SMALL LETTER U WITH TILDE + // U+016B: "ū" LATIN SMALL LETTER U WITH MACRON + // U+016D: "ŭ" LATIN SMALL LETTER U WITH BREVE + // U+016F: "ů" LATIN SMALL LETTER U WITH RING ABOVE + // U+0171: "ű" LATIN SMALL LETTER U WITH DOUBLE ACUTE + // U+0173: "ų" LATIN SMALL LETTER U WITH OGONEK + /* 4 */ "\u00F9,\u00FA,\u00FB,\u00FC,\u0169,\u016B,\u016D,\u016F,\u0171,\u0173", + // U+00DF: "ß" LATIN SMALL LETTER SHARP S + // U+015B: "ś" LATIN SMALL LETTER S WITH ACUTE + // U+015D: "ŝ" LATIN SMALL LETTER S WITH CIRCUMFLEX + // U+015F: "ş" LATIN SMALL LETTER S WITH CEDILLA + // U+0161: "š" LATIN SMALL LETTER S WITH CARON + // U+017F: "ſ" LATIN SMALL LETTER LONG S + /* 5 */ "\u00DF,\u015B,\u015D,\u015F,\u0161,\u017F", + // U+00F1: "ñ" LATIN SMALL LETTER N WITH TILDE + // U+0144: "ń" LATIN SMALL LETTER N WITH ACUTE + // U+0146: "ņ" LATIN SMALL LETTER N WITH CEDILLA + // U+0148: "ň" LATIN SMALL LETTER N WITH CARON + // U+0149: "ʼn" LATIN SMALL LETTER N PRECEDED BY APOSTROPHE + // U+014B: "ŋ" LATIN SMALL LETTER ENG + /* 6 */ "\u00F1,\u0144,\u0146,\u0148,\u0149,\u014B", + // U+00E7: "ç" LATIN SMALL LETTER C WITH CEDILLA + // U+0107: "ć" LATIN SMALL LETTER C WITH ACUTE + // U+0109: "ĉ" LATIN SMALL LETTER C WITH CIRCUMFLEX + // U+010B: "ċ" LATIN SMALL LETTER C WITH DOT ABOVE + // U+010D: "č" LATIN SMALL LETTER C WITH CARON + /* 7 */ "\u00E7,\u0107,\u0109,\u010B,\u010D", + // U+00FD: "ý" LATIN SMALL LETTER Y WITH ACUTE + // U+0177: "ŷ" LATIN SMALL LETTER Y WITH CIRCUMFLEX + // U+00FF: "ÿ" LATIN SMALL LETTER Y WITH DIAERESIS + // U+0133: "ij" LATIN SMALL LIGATURE IJ + /* 8 */ "\u00FD,\u0177,\u00FF,\u0133", + // U+010F: "ď" LATIN SMALL LETTER D WITH CARON + // U+0111: "đ" LATIN SMALL LETTER D WITH STROKE + // U+00F0: "ð" LATIN SMALL LETTER ETH + /* 9 */ "\u010F,\u0111,\u00F0", + // U+0155: "ŕ" LATIN SMALL LETTER R WITH ACUTE + // U+0157: "ŗ" LATIN SMALL LETTER R WITH CEDILLA + // U+0159: "ř" LATIN SMALL LETTER R WITH CARON + /* 10 */ "\u0155,\u0157,\u0159", + // U+00FE: "þ" LATIN SMALL LETTER THORN + // U+0163: "ţ" LATIN SMALL LETTER T WITH CEDILLA + // U+0165: "ť" LATIN SMALL LETTER T WITH CARON + // U+0167: "ŧ" LATIN SMALL LETTER T WITH STROKE + /* 11 */ "\u00FE,\u0163,\u0165,\u0167", + // U+017A: "ź" LATIN SMALL LETTER Z WITH ACUTE + // U+017C: "ż" LATIN SMALL LETTER Z WITH DOT ABOVE + // U+017E: "ž" LATIN SMALL LETTER Z WITH CARON + /* 12 */ "\u017A,\u017C,\u017E", + // U+0137: "ķ" LATIN SMALL LETTER K WITH CEDILLA + // U+0138: "ĸ" LATIN SMALL LETTER KRA + /* 13 */ "\u0137,\u0138", + // U+013A: "ĺ" LATIN SMALL LETTER L WITH ACUTE + // U+013C: "ļ" LATIN SMALL LETTER L WITH CEDILLA + // U+013E: "ľ" LATIN SMALL LETTER L WITH CARON + // U+0140: "ŀ" LATIN SMALL LETTER L WITH MIDDLE DOT + // U+0142: "ł" LATIN SMALL LETTER L WITH STROKE + /* 14 */ "\u013A,\u013C,\u013E,\u0140,\u0142", + // U+011D: "ĝ" LATIN SMALL LETTER G WITH CIRCUMFLEX + // U+011F: "ğ" LATIN SMALL LETTER G WITH BREVE + // U+0121: "ġ" LATIN SMALL LETTER G WITH DOT ABOVE + // U+0123: "ģ" LATIN SMALL LETTER G WITH CEDILLA + /* 15 */ "\u011D,\u011F,\u0121,\u0123", + /* 16 */ null, + // U+0125: "ĥ" LATIN SMALL LETTER H WITH CIRCUMFLEX + /* 17 */ "\u0125", + // U+0135: "ĵ" LATIN SMALL LETTER J WITH CIRCUMFLEX + /* 18 */ "\u0135", + // U+0175: "ŵ" LATIN SMALL LETTER W WITH CIRCUMFLEX + /* 19 */ "\u0175", + }; + + private static final Object[] LANGUAGES_AND_LABELS = { + "DEFAULT", LANGUAGE_DEFAULT, /* default */ + "ar", LANGUAGE_ar, /* Arabic */ + "be", LANGUAGE_be, /* Belarusian */ + "ca", LANGUAGE_ca, /* Catalan */ + "cs", LANGUAGE_cs, /* Czech */ + "da", LANGUAGE_da, /* Danish */ + "de", LANGUAGE_de, /* German */ + "en", LANGUAGE_en, /* English */ + "es", LANGUAGE_es, /* Spanish */ + "et", LANGUAGE_et, /* Estonian */ + "fa", LANGUAGE_fa, /* Persian */ + "fi", LANGUAGE_fi, /* Finnish */ + "fr", LANGUAGE_fr, /* French */ + "hi", LANGUAGE_hi, /* Hindi */ + "hr", LANGUAGE_hr, /* Croatian */ + "hu", LANGUAGE_hu, /* Hungarian */ + "is", LANGUAGE_is, /* Icelandic */ + "it", LANGUAGE_it, /* Italian */ + "iw", LANGUAGE_iw, /* Hebrew */ + "ky", LANGUAGE_ky, /* Kirghiz */ + "lt", LANGUAGE_lt, /* Lithuanian */ + "lv", LANGUAGE_lv, /* Latvian */ + "mk", LANGUAGE_mk, /* Macedonian */ + "nb", LANGUAGE_nb, /* Norwegian Bokmål */ + "nl", LANGUAGE_nl, /* Dutch */ + "pl", LANGUAGE_pl, /* Polish */ + "pt", LANGUAGE_pt, /* Portuguese */ + "rm", LANGUAGE_rm, /* Raeto-Romance */ + "ro", LANGUAGE_ro, /* Romanian */ + "ru", LANGUAGE_ru, /* Russian */ + "sk", LANGUAGE_sk, /* Slovak */ + "sl", LANGUAGE_sl, /* Slovenian */ + "sr", LANGUAGE_sr, /* Serbian */ + "sv", LANGUAGE_sv, /* Swedish */ + "tr", LANGUAGE_tr, /* Turkish */ + "uk", LANGUAGE_uk, /* Ukrainian */ + "vi", LANGUAGE_vi, /* Vietnamese */ + "zz", LANGUAGE_zz, /* No language */ + }; + + static { + int id = 0; + for (final String name : NAMES) { + sNameToIdMap.put(name, id++); + } + + for (int i = 0; i < LANGUAGES_AND_LABELS.length; i += 2) { + final String language = (String)LANGUAGES_AND_LABELS[i]; + final String[] labels = (String[])LANGUAGES_AND_LABELS[i + 1]; + sLocaleToLabelsMap.put(language, labels); + } + } +} diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 49ab7f9d7..526acf128 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -97,7 +97,7 @@ public class SettingsValues { } } final String[] suggestPuncsSpec = KeySpecParser.parseCsvString( - res.getString(R.string.suggested_punctuations), res, R.string.english_ime_name); + res.getString(R.string.suggested_punctuations), null); mSuggestPuncList = createSuggestPuncList(suggestPuncsSpec); mSymbolsExcludedFromWordSeparators = res.getString(R.string.symbols_excluded_from_word_separators); diff --git a/tests/res/values/donottranslate.xml b/tests/res/values/donottranslate.xml index 1ca4451d4..42181ed92 100644 --- a/tests/res/values/donottranslate.xml +++ b/tests/res/values/donottranslate.xml @@ -50,7 +50,7 @@ " \\abc , d\\ef , gh\\i " "ab\\\\,d\\\\\\,,g\\,i" " ab\\\\ , d\\\\\\, , g\\,i " - @string/multiple_chars - x,@string/multiple_chars,y - infinite,@string/infinite_indirection,loop + !label/multiple_chars + x,!label/multiple_chars,y + infinite,!label/infinite_indirection,loop diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java index e090031e4..000623bc0 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserCsvTests.java @@ -16,22 +16,37 @@ package com.android.inputmethod.keyboard.internal; -import android.content.res.Resources; import android.test.AndroidTestCase; import android.text.TextUtils; -import com.android.inputmethod.latin.tests.R; - +import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Locale; public class KeySpecParserCsvTests extends AndroidTestCase { - private Resources mTestResources; + private final KeyboardLabelsSet mLabelsSet = new KeyboardLabelsSet(); @Override protected void setUp() throws Exception { super.setUp(); - mTestResources = getTestContext().getResources(); + mLabelsSet.setLanguage(Locale.ENGLISH.getLanguage()); + final String[] testResourceNames = getAllResourceIdNames( + com.android.inputmethod.latin.tests.R.string.class); + mLabelsSet.loadStringResourcesInternal(getTestContext(), + testResourceNames, + com.android.inputmethod.latin.tests.R.string.empty_string); + } + + private static String[] getAllResourceIdNames(final Class resourceIdClass) { + final ArrayList names = new ArrayList(); + for (final Field field : resourceIdClass.getFields()) { + if (field.getType() == Integer.TYPE) { + names.add(field.getName()); + } + } + return names.toArray(new String[names.size()]); } private static String format(String message, Object expected, Object actual) { @@ -39,8 +54,7 @@ public class KeySpecParserCsvTests extends AndroidTestCase { } private void assertTextArray(String message, String value, String ... expected) { - final String actual[] = KeySpecParser.parseCsvString(value, mTestResources, - R.string.empty_string); + final String actual[] = KeySpecParser.parseCsvString(value, mLabelsSet); if (expected.length == 0) { assertNull(message + ": expected=null actual=" + Arrays.toString(actual), actual); @@ -104,10 +118,10 @@ public class KeySpecParserCsvTests extends AndroidTestCase { "ab" + SURROGATE1 + "cd", "ab" + SURROGATE1 + "cd"); - assertTextArray("Incomplete resource reference 1", "string", "string"); - assertTextArray("Incomplete resource reference 2", "@string", "@string"); - assertTextArray("Incomplete resource reference 3", "string/", "string/"); - assertTextArray("Incomplete resource reference 4", "@" + SURROGATE2, "@" + SURROGATE2); + assertTextArray("Incomplete resource reference 1", "label", "label"); + assertTextArray("Incomplete resource reference 2", "!label", "!label"); + assertTextArray("Incomplete resource reference 3", "label/", "label/"); + assertTextArray("Incomplete resource reference 4", "!" + SURROGATE2, "!" + SURROGATE2); } public void testParseCsvTextSingleEscaped() { @@ -138,9 +152,9 @@ public class KeySpecParserCsvTests extends AndroidTestCase { assertTextArray("Escaped surrogate with escape", PAIR1 + "\\\\" + PAIR2, PAIR1 + "\\\\" + PAIR2); - assertTextArray("Escaped @string", "\\@string", "\\@string"); - assertTextArray("Escaped @string/", "\\@string/", "\\@string/"); - assertTextArray("Escaped @string/", "\\@string/empty_string", "\\@string/empty_string"); + assertTextArray("Escaped !label", "\\!label", "\\!label"); + assertTextArray("Escaped !label/", "\\!label/", "\\!label/"); + assertTextArray("Escaped !label/", "\\!label/empty_string", "\\!label/empty_string"); } public void testParseCsvTextMulti() { @@ -171,133 +185,133 @@ public class KeySpecParserCsvTests extends AndroidTestCase { assertTextArray("Multiple labels with comma and escape surrounded by spaces", " ab\\\\ , d\\\\\\, , g\\,i ", " ab\\\\ ", " d\\\\\\, ", " g\\,i "); - assertTextArray("Multiple escaped @string", "\\@,\\@string/empty_string", - "\\@", "\\@string/empty_string"); + assertTextArray("Multiple escaped !label", "\\!,\\!label/empty_string", + "\\!", "\\!label/empty_string"); } public void testParseCsvResourceError() { - assertError("Incomplete resource name", "@string/", "@string/"); - assertError("Non existing resource", "@string/non_existing"); + assertError("Incomplete resource name", "!label/", "!label/"); + assertError("Non existing resource", "!label/non_existing"); } public void testParseCsvResourceZero() { assertTextArray("Empty string", - "@string/empty_string"); + "!label/empty_string"); } public void testParseCsvResourceSingle() { assertTextArray("Single char", - "@string/single_char", "a"); + "!label/single_char", "a"); assertTextArray("Space", - "@string/space", " "); + "!label/space", " "); assertTextArray("Single label", - "@string/single_label", "abc"); + "!label/single_label", "abc"); assertTextArray("Spaces", - "@string/spaces", " "); + "!label/spaces", " "); assertTextArray("Spaces in label", - "@string/spaces_in_label", "a b c"); + "!label/spaces_in_label", "a b c"); assertTextArray("Spaces at beginning of label", - "@string/spaces_at_beginning_of_label", " abc"); + "!label/spaces_at_beginning_of_label", " abc"); assertTextArray("Spaces at end of label", - "@string/spaces_at_end_of_label", "abc "); + "!label/spaces_at_end_of_label", "abc "); assertTextArray("label surrounded by spaces", - "@string/label_surrounded_by_spaces", " abc "); + "!label/label_surrounded_by_spaces", " abc "); assertTextArray("Escape and single char", - "\\\\@string/single_char", "\\\\a"); + "\\\\!label/single_char", "\\\\a"); } public void testParseCsvResourceSingleEscaped() { assertTextArray("Escaped char", - "@string/escaped_char", "\\a"); + "!label/escaped_char", "\\a"); assertTextArray("Escaped comma", - "@string/escaped_comma", "\\,"); + "!label/escaped_comma", "\\,"); assertTextArray("Escaped comma escape", - "@string/escaped_comma_escape", "a\\,\\"); + "!label/escaped_comma_escape", "a\\,\\"); assertTextArray("Escaped escape", - "@string/escaped_escape", "\\\\"); + "!label/escaped_escape", "\\\\"); assertTextArray("Escaped label", - "@string/escaped_label", "a\\bc"); + "!label/escaped_label", "a\\bc"); assertTextArray("Escaped label at beginning", - "@string/escaped_label_at_beginning", "\\abc"); + "!label/escaped_label_at_beginning", "\\abc"); assertTextArray("Escaped label at end", - "@string/escaped_label_at_end", "abc\\"); + "!label/escaped_label_at_end", "abc\\"); assertTextArray("Escaped label with comma", - "@string/escaped_label_with_comma", "a\\,c"); + "!label/escaped_label_with_comma", "a\\,c"); assertTextArray("Escaped label with comma at beginning", - "@string/escaped_label_with_comma_at_beginning", "\\,bc"); + "!label/escaped_label_with_comma_at_beginning", "\\,bc"); assertTextArray("Escaped label with comma at end", - "@string/escaped_label_with_comma_at_end", "ab\\,"); + "!label/escaped_label_with_comma_at_end", "ab\\,"); assertTextArray("Escaped label with successive", - "@string/escaped_label_with_successive", "\\,\\\\bc"); + "!label/escaped_label_with_successive", "\\,\\\\bc"); assertTextArray("Escaped label with escape", - "@string/escaped_label_with_escape", "a\\\\c"); + "!label/escaped_label_with_escape", "a\\\\c"); } public void testParseCsvResourceMulti() { assertTextArray("Multiple chars", - "@string/multiple_chars", "a", "b", "c"); + "!label/multiple_chars", "a", "b", "c"); assertTextArray("Multiple chars surrounded by spaces", - "@string/multiple_chars_surrounded_by_spaces", + "!label/multiple_chars_surrounded_by_spaces", " a ", " b ", " c "); assertTextArray("Multiple labels", - "@string/multiple_labels", "abc", "def", "ghi"); + "!label/multiple_labels", "abc", "def", "ghi"); assertTextArray("Multiple labels surrounded by spaces", - "@string/multiple_labels_surrounded_by_spaces", " abc ", " def ", " ghi "); + "!label/multiple_labels_surrounded_by_spaces", " abc ", " def ", " ghi "); } public void testParseCsvResourcetMultiEscaped() { assertTextArray("Multiple chars with comma", - "@string/multiple_chars_with_comma", + "!label/multiple_chars_with_comma", "a", "\\,", "c"); assertTextArray("Multiple chars with comma surrounded by spaces", - "@string/multiple_chars_with_comma_surrounded_by_spaces", + "!label/multiple_chars_with_comma_surrounded_by_spaces", " a ", " \\, ", " c "); assertTextArray("Multiple labels with escape", - "@string/multiple_labels_with_escape", + "!label/multiple_labels_with_escape", "\\abc", "d\\ef", "gh\\i"); assertTextArray("Multiple labels with escape surrounded by spaces", - "@string/multiple_labels_with_escape_surrounded_by_spaces", + "!label/multiple_labels_with_escape_surrounded_by_spaces", " \\abc ", " d\\ef ", " gh\\i "); assertTextArray("Multiple labels with comma and escape", - "@string/multiple_labels_with_comma_and_escape", + "!label/multiple_labels_with_comma_and_escape", "ab\\\\", "d\\\\\\,", "g\\,i"); assertTextArray("Multiple labels with comma and escape surrounded by spaces", - "@string/multiple_labels_with_comma_and_escape_surrounded_by_spaces", + "!label/multiple_labels_with_comma_and_escape_surrounded_by_spaces", " ab\\\\ ", " d\\\\\\, ", " g\\,i "); } public void testParseMultipleResources() { assertTextArray("Literals and resources", - "1,@string/multiple_chars,z", "1", "a", "b", "c", "z"); + "1,!label/multiple_chars,z", "1", "a", "b", "c", "z"); assertTextArray("Literals and resources and escape at end", - "\\1,@string/multiple_chars,z\\", "\\1", "a", "b", "c", "z\\"); + "\\1,!label/multiple_chars,z\\", "\\1", "a", "b", "c", "z\\"); assertTextArray("Multiple single resource chars and labels", - "@string/single_char,@string/single_label,@string/escaped_comma", + "!label/single_char,!label/single_label,!label/escaped_comma", "a", "abc", "\\,"); assertTextArray("Multiple single resource chars and labels 2", - "@string/single_char,@string/single_label,@string/escaped_comma_escape", + "!label/single_char,!label/single_label,!label/escaped_comma_escape", "a", "abc", "a\\,\\"); assertTextArray("Multiple multiple resource chars and labels", - "@string/multiple_chars,@string/multiple_labels,@string/multiple_chars_with_comma", + "!label/multiple_chars,!label/multiple_labels,!label/multiple_chars_with_comma", "a", "b", "c", "abc", "def", "ghi", "a", "\\,", "c"); assertTextArray("Concatenated resources", - "@string/multiple_chars@string/multiple_labels@string/multiple_chars_with_comma", + "!label/multiple_chars!label/multiple_labels!label/multiple_chars_with_comma", "a", "b", "cabc", "def", "ghia", "\\,", "c"); assertTextArray("Concatenated resource and literal", - "abc@string/multiple_labels", + "abc!label/multiple_labels", "abcabc", "def", "ghi"); } public void testParseIndirectReference() { assertTextArray("Indirect", - "@string/indirect_string", "a", "b", "c"); + "!label/indirect_string", "a", "b", "c"); assertTextArray("Indirect with literal", - "1,@string/indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2"); + "1,!label/indirect_string_with_literal,2", "1", "x", "a", "b", "c", "y", "2"); } public void testParseInfiniteIndirectReference() { assertError("Infinite indirection", - "1,@string/infinite_indirection,2", "1", "infinite", "", "loop", "2"); + "1,!label/infinite_indirection,2", "1", "infinite", "", "loop", "2"); } } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java index 980b1e4d5..e4879ad2a 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeySpecParserTests.java @@ -97,10 +97,10 @@ public class KeySpecParserTests extends AndroidTestCase { "a", null, ICON_UNDEFINED, 'a'); assertParser("Single escaped surrogate", "\\" + PAIR2, PAIR2, null, ICON_UNDEFINED, CODE2); - assertParser("Single at", "@", - "@", null, ICON_UNDEFINED, '@'); - assertParser("Single escaped at", "\\@", - "@", null, ICON_UNDEFINED, '@'); + assertParser("Single bang", "!", + "!", null, ICON_UNDEFINED, '!'); + assertParser("Single escaped bang", "\\!", + "!", null, ICON_UNDEFINED, '!'); assertParser("Single output text letter", "a|a", "a", null, ICON_UNDEFINED, 'a'); assertParser("Single surrogate pair outputText", "G Clef|" + PAIR1, @@ -120,14 +120,14 @@ public class KeySpecParserTests extends AndroidTestCase { "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Single letter with escaped comma outputText", "a|a\\,b", "a", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Single letter with outputText starts with at", "a|@bc", - "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Single letter with surrogate outputText starts with at", "a|@" + SURROGATE2, - "a", "@" + SURROGATE2, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Single letter with outputText contains at", "a|a@c", - "a", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Single letter with escaped at outputText", "a|\\@bc", - "a", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Single letter with outputText starts with bang", "a|!bc", + "a", "!bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Single letter with surrogate outputText starts with bang", "a|!" + SURROGATE2, + "a", "!" + SURROGATE2, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Single letter with outputText contains bang", "a|a!c", + "a", "a!c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Single letter with escaped bang outputText", "a|\\!bc", + "a", "!bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Single escaped escape with single outputText", "\\\\|\\\\", "\\", null, ICON_UNDEFINED, '\\'); assertParser("Single escaped bar with single outputText", "\\||\\|", @@ -152,14 +152,14 @@ public class KeySpecParserTests extends AndroidTestCase { "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Label with escaped comma", "a\\,c", "a,c", "a,c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label starts with at", "@bc", - "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Surrogate label starts with at", "@" + SURROGATE1, - "@" + SURROGATE1, "@" + SURROGATE1, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label contains at", "a@c", - "a@c", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label with escaped at", "\\@bc", - "@bc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label starts with bang", "!bc", + "!bc", "!bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Surrogate label starts with bang", "!" + SURROGATE1, + "!" + SURROGATE1, "!" + SURROGATE1, ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label contains bang", "a!c", + "a!c", "a!c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label with escaped bang", "\\!bc", + "!bc", "!bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Label with escaped letter", "\\abc", "abc", "abc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Label with outputText", "abc|def", @@ -174,22 +174,22 @@ public class KeySpecParserTests extends AndroidTestCase { "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Escaped escape label with outputText", "a\\\\|def", "a\\", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label starts with at and outputText", "@bc|def", - "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label contains at label and outputText", "a@c|def", - "a@c", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Escaped at label with outputText", "\\@bc|def", - "@bc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label starts with bang and outputText", "!bc|def", + "!bc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label contains bang label and outputText", "a!c|def", + "a!c", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Escaped bang label with outputText", "\\!bc|def", + "!bc", "def", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Label with comma outputText", "abc|a,b", "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Label with escaped comma outputText", "abc|a\\,b", "abc", "a,b", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label with outputText starts with at", "abc|@bc", - "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label with outputText contains at", "abc|a@c", - "abc", "a@c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label with escaped at outputText", "abc|\\@bc", - "abc", "@bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label with outputText starts with bang", "abc|!bc", + "abc", "!bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label with outputText contains bang", "abc|a!c", + "abc", "a!c", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label with escaped bang outputText", "abc|\\!bc", + "abc", "!bc", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Label with escaped bar outputText", "abc|d\\|f", "abc", "d|f", ICON_UNDEFINED, Keyboard.CODE_OUTPUT_TEXT); assertParser("Escaped bar label with escaped bar outputText", "a\\|c|d\\|f", @@ -203,18 +203,18 @@ public class KeySpecParserTests extends AndroidTestCase { public void testIconAndCode() { assertParser("Icon with outputText", ICON_SETTINGS + "|abc", null, "abc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Icon with outputText starts with at", ICON_SETTINGS + "|@bc", - null, "@bc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Icon with outputText contains at", ICON_SETTINGS + "|a@c", - null, "a@c", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Icon with escaped at outputText", ICON_SETTINGS + "|\\@bc", - null, "@bc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); - assertParser("Label starts with at and code", "@bc|" + CODE_SETTINGS, - "@bc", null, ICON_UNDEFINED, mCodeSettings); - assertParser("Label contains at and code", "a@c|" + CODE_SETTINGS, - "a@c", null, ICON_UNDEFINED, mCodeSettings); - assertParser("Escaped at label with code", "\\@bc|" + CODE_SETTINGS, - "@bc", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Icon with outputText starts with bang", ICON_SETTINGS + "|!bc", + null, "!bc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Icon with outputText contains bang", ICON_SETTINGS + "|a!c", + null, "a!c", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Icon with escaped bang outputText", ICON_SETTINGS + "|\\!bc", + null, "!bc", mSettingsIconId, Keyboard.CODE_OUTPUT_TEXT); + assertParser("Label starts with bang and code", "!bc|" + CODE_SETTINGS, + "!bc", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Label contains bang and code", "a!c|" + CODE_SETTINGS, + "a!c", null, ICON_UNDEFINED, mCodeSettings); + assertParser("Escaped bang label with code", "\\!bc|" + CODE_SETTINGS, + "!bc", null, ICON_UNDEFINED, mCodeSettings); assertParser("Icon with code", ICON_SETTINGS + "|" + CODE_SETTINGS, null, null, mSettingsIconId, mCodeSettings); } diff --git a/tools/makelabel/Android.mk b/tools/makelabel/Android.mk new file mode 100644 index 000000000..9fa865084 --- /dev/null +++ b/tools/makelabel/Android.mk @@ -0,0 +1,26 @@ +# +# 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. + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES += $(call all-java-files-under,src) +LOCAL_JAR_MANIFEST := etc/manifest.txt +LOCAL_JAVA_RESOURCE_DIRS := res +LOCAL_MODULE_TAGS := eng +LOCAL_MODULE := makelabel + +include $(BUILD_HOST_JAVA_LIBRARY) +include $(LOCAL_PATH)/etc/Android.mk diff --git a/tools/makelabel/etc/Android.mk b/tools/makelabel/etc/Android.mk new file mode 100644 index 000000000..2d2e9a6ed --- /dev/null +++ b/tools/makelabel/etc/Android.mk @@ -0,0 +1,21 @@ +# 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. + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := eng + +LOCAL_PREBUILT_EXECUTABLES := makelabel +include $(BUILD_HOST_PREBUILT) diff --git a/tools/makelabel/etc/makelabel b/tools/makelabel/etc/makelabel new file mode 100755 index 000000000..44a05b612 --- /dev/null +++ b/tools/makelabel/etc/makelabel @@ -0,0 +1,63 @@ +#!/bin/sh +# Copyright 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. + +# Set up prog to be the path of this script, including following symlinks, +# and set up progdir to be the fully-qualified pathname of its directory. +prog="$0" +while [ -h "${prog}" ]; do + newProg=`/bin/ls -ld "${prog}"` + newProg=`expr "${newProg}" : ".* -> \(.*\)$"` + if expr "x${newProg}" : 'x/' >/dev/null; then + prog="${newProg}" + else + progdir=`dirname "${prog}"` + prog="${progdir}/${newProg}" + fi +done +oldwd=`pwd` +progdir=`dirname "${prog}"` +cd "${progdir}" +progdir=`pwd` +prog="${progdir}"/`basename "${prog}"` +cd "${oldwd}" + +jarfile=makelabel.jar +frameworkdir="$progdir" +if [ ! -r "$frameworkdir/$jarfile" ] +then + frameworkdir=`dirname "$progdir"`/tools/lib + libdir=`dirname "$progdir"`/tools/lib +fi +if [ ! -r "$frameworkdir/$jarfile" ] +then + frameworkdir=`dirname "$progdir"`/framework + libdir=`dirname "$progdir"`/lib +fi +if [ ! -r "$frameworkdir/$jarfile" ] +then + echo `basename "$prog"`": can't find $jarfile" + exit 1 +fi + +if [ "$OSTYPE" = "cygwin" ] ; then + jarpath=`cygpath -w "$frameworkdir/$jarfile"` + progdir=`cygpath -w "$progdir"` +else + jarpath="$frameworkdir/$jarfile" +fi + +# need to use "java.ext.dirs" because "-jar" causes classpath to be ignored +# might need more memory, e.g. -Xmx128M +exec java -ea -jar "$jarpath" "$@" diff --git a/tools/makelabel/etc/manifest.txt b/tools/makelabel/etc/manifest.txt new file mode 100644 index 000000000..18bf0be09 --- /dev/null +++ b/tools/makelabel/etc/manifest.txt @@ -0,0 +1 @@ +Main-Class: com.android.inputmethod.latin.makelabel.LabelMaker diff --git a/tools/makelabel/res/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.tmpl b/tools/makelabel/res/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.tmpl new file mode 100644 index 000000000..0e887e494 --- /dev/null +++ b/tools/makelabel/res/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.tmpl @@ -0,0 +1,117 @@ +/* + * 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.keyboard.internal; + +import android.content.Context; +import android.content.res.Resources; + +import com.android.inputmethod.latin.R; + +import java.util.HashMap; + +/** + * !!!!! DO NOT EDIT THIS FILE !!!!! + * This file is generated by tools/makelabel. + */ +public final class KeyboardLabelsSet { + // Language to labels map. + private static final HashMap sLocaleToLabelsMap = + new HashMap(); + private static final HashMap sNameToIdMap = new HashMap(); + + private String[] mLabels; + // Resource name to label map. + private HashMap mResourceNameToLabelsMap = new HashMap(); + + public void setLanguage(final String language) { + mLabels = sLocaleToLabelsMap.get(language); + if (mLabels == null) { + mLabels = LANGUAGE_DEFAULT; + } + } + + public void loadStringResources(Context context) { + loadStringResourcesInternal(context, RESOURCE_NAMES, R.string.english_ime_name); + } + + /* package for test */ + void loadStringResourcesInternal(Context context, final String[] resourceNames, + int referenceId) { + final Resources res = context.getResources(); + final String packageName = res.getResourcePackageName(referenceId); + for (final String resName : resourceNames) { + final int resId = res.getIdentifier(resName, "string", packageName); + mResourceNameToLabelsMap.put(resName, res.getString(resId)); + } + } + + public String getLabel(final String name) { + if (mResourceNameToLabelsMap.containsKey(name)) { + return mResourceNameToLabelsMap.get(name); + } + final Integer id = sNameToIdMap.get(name); + if (id == null) throw new RuntimeException("Unknown label: " + name); + final String label = (id < mLabels.length) ? mLabels[id] : null; + return (label == null) ? LANGUAGE_DEFAULT[id] : label; + } + + private static final String[] RESOURCE_NAMES = { + // These labels' name should be aligned with the @string/ in values/strings.xml. + // Labels for action. + "label_go_key", + // "label_search_key", + "label_send_key", + "label_next_key", + "label_done_key", + "label_previous_key", + // Other labels. + "label_to_alpha_key", + "label_to_symbol_key", + "label_to_symbol_with_microphone_key", + "label_pause_key", + "label_wait_key", + }; + + private static final String[] NAMES = { + /* @NAMES@ */ + }; + + private static final String EMPTY = ""; + + /* Default labels */ + private static final String[] LANGUAGE_DEFAULT = { + /* @DEFAULT_LABELS@ */ + }; + + /* @LABELS@ */ + private static final Object[] LANGUAGES_AND_LABELS = { + /* @LANGUAGES_AND_LABELS@ */ + }; + + static { + int id = 0; + for (final String name : NAMES) { + sNameToIdMap.put(name, id++); + } + + for (int i = 0; i < LANGUAGES_AND_LABELS.length; i += 2) { + final String language = (String)LANGUAGES_AND_LABELS[i]; + final String[] labels = (String[])LANGUAGES_AND_LABELS[i + 1]; + sLocaleToLabelsMap.put(language, labels); + } + } +} diff --git a/tools/makelabel/res/values-ar/donottranslate-more-keys.xml b/tools/makelabel/res/values-ar/donottranslate-more-keys.xml new file mode 100644 index 000000000..402e17160 --- /dev/null +++ b/tools/makelabel/res/values-ar/donottranslate-more-keys.xml @@ -0,0 +1,144 @@ + + + + + + + + "!fixedColumnOrder!8,\",\',-,:,!,؟,،,؛,ِ,َ,ٍ,ً,ٖ,ٰ,ٕ,ٔ,ُ,ٌ,ّ,ْ,ٓ,ـــ|ـ,/" + ً + + ١ + + ٢ + + ٣ + + ٤ + + ٥ + + ٦ + + ٧ + + ٨ + + ٩ + + ٠ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + + 0,٫,٬ + + ، + "\\," + ؟ + ؛ + + ٪ + \? + ; + + %,‰ + + ، + "." + ؟ + ً + "؟,؛,!,:,-,/,\',\"" + + + + + "ّ,ْ,ٌ,ٓ,ُ,ِ,َ,ً,ـــ|ـ,ٍ,ٔ,ٖ,ٕ,ٰ" + + + + ★,٭ + + + + + !fixedColumnOrder!4,﴾|﴿,<|>,{|},[|] + !fixedColumnOrder!4,﴿|﴾,>|<,}|{,]|[ + + !fixedColumnOrder!3,‹|›,≤|≥,«|» + !fixedColumnOrder!3,›|‹,≥|≤,»|« + + + !fixedColumnOrder!4,“,”,«|»,»|« + + + !fixedColumnOrder!4,“,”,«|»,»|«,‘,’,‚,‛ + diff --git a/tools/makelabel/res/values-be/donottranslate-more-keys.xml b/tools/makelabel/res/values-be/donottranslate-more-keys.xml new file mode 100644 index 000000000..835553a1f --- /dev/null +++ b/tools/makelabel/res/values-be/donottranslate-more-keys.xml @@ -0,0 +1,31 @@ + + + + + ў + + ы + + і + + ъ + + ъ + diff --git a/tools/makelabel/res/values-ca/donottranslate-more-keys.xml b/tools/makelabel/res/values-ca/donottranslate-more-keys.xml new file mode 100644 index 000000000..baa23bf9c --- /dev/null +++ b/tools/makelabel/res/values-ca/donottranslate-more-keys.xml @@ -0,0 +1,73 @@ + + + + + à,á,ä,â,ã,å,ą,æ,ā,ª + + è,é,ë,ê,ę,ė,ē + + í,ï,ì,î,į,ī + + ò,ó,ö,ô,õ,ø,œ,ō,º + + ú,ü,ù,û,ū + + ñ,ń + + ç,ć,č + + ŀ,ł + diff --git a/tools/makelabel/res/values-cs/donottranslate-more-keys.xml b/tools/makelabel/res/values-cs/donottranslate-more-keys.xml new file mode 100644 index 000000000..9af6794df --- /dev/null +++ b/tools/makelabel/res/values-cs/donottranslate-more-keys.xml @@ -0,0 +1,87 @@ + + + + + á,à,â,ä,æ,ã,å,ā + + é,ě,è,ê,ë,ę,ė,ē + + í,î,ï,ì,į,ī + + ó,ö,ô,ò,õ,œ,ø,ō + + ú,ů,û,ü,ù,ū + + š,ß,ś + + ň,ñ,ń + + č,ç,ć + + ý,ÿ + + ď + + ř + + ť + + ž,ź,ż + diff --git a/tools/makelabel/res/values-da/donottranslate-more-keys.xml b/tools/makelabel/res/values-da/donottranslate-more-keys.xml new file mode 100644 index 000000000..acc0c534d --- /dev/null +++ b/tools/makelabel/res/values-da/donottranslate-more-keys.xml @@ -0,0 +1,71 @@ + + + + + á,ä,à,â,ã,ā + + é,ë + + í,ï + + ó,ô,ò,õ,œ,ō + + ú,ü,û,ù,ū + + ß,ś,š + + ñ,ń + + ý,ÿ + + ð + + ł + + å + + æ + + ø + + ä + + ö + diff --git a/tools/makelabel/res/values-de/donottranslate-more-keys.xml b/tools/makelabel/res/values-de/donottranslate-more-keys.xml new file mode 100644 index 000000000..562e574eb --- /dev/null +++ b/tools/makelabel/res/values-de/donottranslate-more-keys.xml @@ -0,0 +1,54 @@ + + + + + ä,â,à,á,æ,ã,å,ā + + ė + + ö,ô,ò,ó,õ,œ,ø,ō + + ü,û,ù,ú,ū + + ß,ś,š + + ñ,ń + diff --git a/tools/makelabel/res/values-en/donottranslate-more-keys.xml b/tools/makelabel/res/values-en/donottranslate-more-keys.xml new file mode 100644 index 000000000..6e43e86d7 --- /dev/null +++ b/tools/makelabel/res/values-en/donottranslate-more-keys.xml @@ -0,0 +1,63 @@ + + + + + à,á,â,ä,æ,ã,å,ā + + è,é,ê,ë,ă + + î,ï,í,ī,ì + + ô,ö,ò,ó,œ,øō,õ + + û,ü,ù,ú,ū + + ß + + ñ + + ç + diff --git a/tools/makelabel/res/values-es/donottranslate-more-keys.xml b/tools/makelabel/res/values-es/donottranslate-more-keys.xml new file mode 100644 index 000000000..f56b1d54f --- /dev/null +++ b/tools/makelabel/res/values-es/donottranslate-more-keys.xml @@ -0,0 +1,73 @@ + + + + + á,à,ä,â,ã,å,ą,æ,ā,ª + + é,è,ë,ê,ę,ė,ē + + í,ï,ì,î,į,ī + + ó,ò,ö,ô,õ,ø,œ,ō,º + + ú,ü,ù,û,ū + + ñ,ń + + ç,ć,č + + "!fixedColumnOrder!7,#,-,¡,!,¿,\\,,\?,\\%,+,;,:,/,(,),\@,&,\",\'" + diff --git a/tools/makelabel/res/values-et/donottranslate-more-keys.xml b/tools/makelabel/res/values-et/donottranslate-more-keys.xml new file mode 100644 index 000000000..69cf654a6 --- /dev/null +++ b/tools/makelabel/res/values-et/donottranslate-more-keys.xml @@ -0,0 +1,114 @@ + + + + + ä,ā,à,á,â,ã,å,æ,ą + + ē,è,ė,é,ê,ë,ę,ě + + ī,ì,į,í,î,ï,ı + + ö,õ,ò,ó,ô,œ,ő,ø + + ü,ū,ų,ù,ú,û,ů,ű + + š,ß,ś,ş + + ņ,ñ,ń,ń + + č,ç,ć + + ý,ÿ + + ď + + ŗ,ř,ŕ + + ţ,ť + + ž,ż,ź + + ķ + + ļ,ł,ĺ,ľ + + ģ,ğ + + ü + + ö + + ä + + õ + diff --git a/tools/makelabel/res/values-fa/donottranslate-more-keys.xml b/tools/makelabel/res/values-fa/donottranslate-more-keys.xml new file mode 100644 index 000000000..1da1c1889 --- /dev/null +++ b/tools/makelabel/res/values-fa/donottranslate-more-keys.xml @@ -0,0 +1,146 @@ + + + + + + + + "!fixedColumnOrder!8,\",\',-,:,!,؟,،,؛,ِ,َ,ٍ,ً,ٖ,ٰ,ٕ,ٔ,ُ,ٌ,ّ,ْ,ٓ,ـــ|ـ,/" + ً + + ۱ + + ۲ + + ۳ + + ۴ + + ۵ + + ۶ + + ۷ + + ۸ + + ۹ + + ۰ + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + + 0,٫,٬ + + ، + "\\," + ؟ + ؛ + + ٪ + \? + ; + + %,‰ + + "،" + "!" + "!,\\," + "؟" + "؟,\?" + ً + "؟,؛,!,:,-,/,\',\"" + + + + + "ّ,ْ,ٌ,ٓ,ُ,ِ,َ,ً,ـــ|ـ,ٍ,ٔ,ٖ,ٕ,_,ٰ" + + + + ★,٭ + + + + + !fixedColumnOrder!4,﴾|﴿,<|>,{|},[|] + !fixedColumnOrder!4,﴿|﴾,>|<,}|{,]|[ + + !fixedColumnOrder!3,‹|›,≤|≥,«|» + !fixedColumnOrder!3,›|‹,≥|≤,»|« + + + !fixedColumnOrder!4,“,”,«|»,»|« + + + !fixedColumnOrder!4,“,”,«|»,»|«,‘,’,‚,‛ + diff --git a/tools/makelabel/res/values-fi/donottranslate-more-keys.xml b/tools/makelabel/res/values-fi/donottranslate-more-keys.xml new file mode 100644 index 000000000..25b785845 --- /dev/null +++ b/tools/makelabel/res/values-fi/donottranslate-more-keys.xml @@ -0,0 +1,56 @@ + + + + + æ,à,á,â,ã,ā + + ø,ô,ò,ó,õ,œ,ō + + ü + + š,ß,ś + + ž,ź,ż + + å + + ö + + ä + + ø + + æ + diff --git a/tools/makelabel/res/values-fr/donottranslate-more-keys.xml b/tools/makelabel/res/values-fr/donottranslate-more-keys.xml new file mode 100644 index 000000000..7b11a183d --- /dev/null +++ b/tools/makelabel/res/values-fr/donottranslate-more-keys.xml @@ -0,0 +1,68 @@ + + + + + à,â,%,æ,á,ä,ã,å,ā,ª + + é,è,ê,ë,%,ę,ė,ē + + î,%,ï,ì,í,į,ī + + ô,œ,%,ö,ò,ó,õ,ø,ō,º + + ù,û,%,ü,ú,ū + + ç,ć,č + + %,ÿ + diff --git a/tools/makelabel/res/values-hi/donottranslate-more-keys.xml b/tools/makelabel/res/values-hi/donottranslate-more-keys.xml new file mode 100644 index 000000000..19bcb9dda --- /dev/null +++ b/tools/makelabel/res/values-hi/donottranslate-more-keys.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + diff --git a/tools/makelabel/res/values-hr/donottranslate-more-keys.xml b/tools/makelabel/res/values-hr/donottranslate-more-keys.xml new file mode 100644 index 000000000..9b4005d0d --- /dev/null +++ b/tools/makelabel/res/values-hr/donottranslate-more-keys.xml @@ -0,0 +1,38 @@ + + + + + š,ś,ß + + ñ,ń + + ž,ź,ż + + č,ć,ç + + đ + diff --git a/tools/makelabel/res/values-hu/donottranslate-more-keys.xml b/tools/makelabel/res/values-hu/donottranslate-more-keys.xml new file mode 100644 index 000000000..48259104b --- /dev/null +++ b/tools/makelabel/res/values-hu/donottranslate-more-keys.xml @@ -0,0 +1,62 @@ + + + + + á,à,â,ä,æ,ã,å,ā + + é,è,ê,ë,ę,ė,ē + + í,î,ï,ì,į,ī + + ó,ö,ő,ô,ò,õ,œ,ø,ō + + ú,ü,ű,û,ù,ū + diff --git a/tools/makelabel/res/values-is/donottranslate-more-keys.xml b/tools/makelabel/res/values-is/donottranslate-more-keys.xml new file mode 100644 index 000000000..284aae930 --- /dev/null +++ b/tools/makelabel/res/values-is/donottranslate-more-keys.xml @@ -0,0 +1,73 @@ + + + + + á,ä,æ,å,à,â,ã,ā + + é,ë,è,ê,ę,ė,ē + + í,ï,î,ì,į,ī + + ó,ö,ô,ò,õ,œ,ø,ō + + ú,ü,û,ù,ū + + ý,ÿ + + ð + + þ + + ð + + æ + + þ + diff --git a/tools/makelabel/res/values-it/donottranslate-more-keys.xml b/tools/makelabel/res/values-it/donottranslate-more-keys.xml new file mode 100644 index 000000000..17dd03108 --- /dev/null +++ b/tools/makelabel/res/values-it/donottranslate-more-keys.xml @@ -0,0 +1,62 @@ + + + + + à,á,â,ä,æ,ã,å,ā,ª + + è,é,ê,ë,ę,ė,ē + + ì,í,î,ï,į,ī + + ò,ó,ô,ö,õ,œ,ø,ō,º + + ù,ú,û,ü,ū + diff --git a/tools/makelabel/res/values-iw/donottranslate-more-keys.xml b/tools/makelabel/res/values-iw/donottranslate-more-keys.xml new file mode 100644 index 000000000..ad209edde --- /dev/null +++ b/tools/makelabel/res/values-iw/donottranslate-more-keys.xml @@ -0,0 +1,53 @@ + + + + + + + ±,﬩ + + !fixedColumnOrder!3,<|>,{|},[|] + !fixedColumnOrder!3,>|<,}|{,]|[ + + !fixedColumnOrder!3,‹|›,≤|≥,«|» + !fixedColumnOrder!3,›|‹,≥|≤,»|« + + + !fixedColumnOrder!4,“,”,«|»,»|« + + + !fixedColumnOrder!4,“,”,«|»,»|«,‘,’,‚,‛ + diff --git a/tools/makelabel/res/values-ky/donottranslate-more-keys.xml b/tools/makelabel/res/values-ky/donottranslate-more-keys.xml new file mode 100644 index 000000000..fd90248b2 --- /dev/null +++ b/tools/makelabel/res/values-ky/donottranslate-more-keys.xml @@ -0,0 +1,37 @@ + + + + + щ + + ы + + и + + ү + + ң + + ъ + + ө + + ъ + diff --git a/tools/makelabel/res/values-lt/donottranslate-more-keys.xml b/tools/makelabel/res/values-lt/donottranslate-more-keys.xml new file mode 100644 index 000000000..1491d954e --- /dev/null +++ b/tools/makelabel/res/values-lt/donottranslate-more-keys.xml @@ -0,0 +1,107 @@ + + + + + ą,ä,ā,à,á,â,ã,å,æ + + ė,ę,ē,è,é,ê,ë,ě + + į,ī,ì,í,î,ï,ı + + ö,õ,ò,ó,ô,œ,ő,ø + + ū,ų,ü,ū,ù,ú,û,ů,ű + + š,ß,ś,ş + + ņ,ñ,ń,ń + + č,ç,ć + + ý,ÿ + + ď + + ŗ,ř,ŕ + + ţ,ť + + ž,ż,ź + + ķ + + ļ,ł,ĺ,ľ + + ģ,ğ + diff --git a/tools/makelabel/res/values-lv/donottranslate-more-keys.xml b/tools/makelabel/res/values-lv/donottranslate-more-keys.xml new file mode 100644 index 000000000..d0a44480a --- /dev/null +++ b/tools/makelabel/res/values-lv/donottranslate-more-keys.xml @@ -0,0 +1,106 @@ + + + + + ā,à,á,â,ã,ä,å,æ,ą + + ē,ė,è,é,ê,ë,ę,ě + + ī,į,ì,í,î,ï,ı + + ò,ó,ô,õ,ö,œ,ő,ø + + ū,ų,ù,ú,û,ü,ů,ű + + š,ß,ś,ş + + ņ,ñ,ń,ń + + č,ç,ć + + ý,ÿ + + ď + + ŗ,ř,ŕ + + ţ,ť + + ž,ż,ź + + ķ + + ļ,ł,ĺ,ľ + + ģ,ğ + diff --git a/tools/makelabel/res/values-mk/donottranslate-more-keys.xml b/tools/makelabel/res/values-mk/donottranslate-more-keys.xml new file mode 100644 index 000000000..d0cccf61b --- /dev/null +++ b/tools/makelabel/res/values-mk/donottranslate-more-keys.xml @@ -0,0 +1,47 @@ + + + + + ѕ + + ќ + + з + + ѓ + + ѐ + + ѝ + + + + !fixedColumnOrder!5,„,“,”,«,» + + + !fixedColumnOrder!5,„,“,”,«,»,‘,’,‚,‛ + diff --git a/tools/makelabel/res/values-nb/donottranslate-more-keys.xml b/tools/makelabel/res/values-nb/donottranslate-more-keys.xml new file mode 100644 index 000000000..49e6d5faf --- /dev/null +++ b/tools/makelabel/res/values-nb/donottranslate-more-keys.xml @@ -0,0 +1,60 @@ + + + + + à,ä,á,â,ã,ā + + é,è,ê,ë,ę,ė,ē + + ô,ò,ó,ö,õ,œ,ō + + ü,û,ù,ú,ū + + å + + ø + + æ + + ö + + ä + diff --git a/tools/makelabel/res/values-nl/donottranslate-more-keys.xml b/tools/makelabel/res/values-nl/donottranslate-more-keys.xml new file mode 100644 index 000000000..73768aff2 --- /dev/null +++ b/tools/makelabel/res/values-nl/donottranslate-more-keys.xml @@ -0,0 +1,66 @@ + + + + + á,ä,â,à,æ,ã,å,ā + + é,ë,ê,è,ę,ė,ē + + í,ï,ì,î,į,ī,ij + + ó,ö,ô,ò,õ,œ,ø,ō + + ú,ü,û,ù,ū + + ñ,ń + + ij + diff --git a/tools/makelabel/res/values-pl/donottranslate-more-keys.xml b/tools/makelabel/res/values-pl/donottranslate-more-keys.xml new file mode 100644 index 000000000..0f8a59bd6 --- /dev/null +++ b/tools/makelabel/res/values-pl/donottranslate-more-keys.xml @@ -0,0 +1,65 @@ + + + + + ą,á,à,â,ä,æ,ã,å,ā + + ę,è,é,ê,ë,ė,ē + + ó,ö,ô,ò,õ,œ,ø,ō + + ś,ß,š + + ń,ñ + + ć,ç,č + + ż,ź,ž + + ł + diff --git a/tools/makelabel/res/values-pt/donottranslate-more-keys.xml b/tools/makelabel/res/values-pt/donottranslate-more-keys.xml new file mode 100644 index 000000000..0c9065f27 --- /dev/null +++ b/tools/makelabel/res/values-pt/donottranslate-more-keys.xml @@ -0,0 +1,65 @@ + + + + + á,ã,à,â,ä,å,æ,ª + + é,ê,è,ę,ė,ē,ë + + í,î,ì,ï,į,ī + + ó,õ,ô,ò,ö,œ,ø,ō,º + + ú,ü,ù,û,ū + + ç,č,ć + diff --git a/tools/makelabel/res/values-rm/donottranslate-more-keys.xml b/tools/makelabel/res/values-rm/donottranslate-more-keys.xml new file mode 100644 index 000000000..aa0d7f817 --- /dev/null +++ b/tools/makelabel/res/values-rm/donottranslate-more-keys.xml @@ -0,0 +1,29 @@ + + + + + ò,ó,ö,ô,õ,œ,ø + diff --git a/tools/makelabel/res/values-ro/donottranslate-more-keys.xml b/tools/makelabel/res/values-ro/donottranslate-more-keys.xml new file mode 100644 index 000000000..44613cf85 --- /dev/null +++ b/tools/makelabel/res/values-ro/donottranslate-more-keys.xml @@ -0,0 +1,45 @@ + + + + + â,ã,ă,à,á,ä,æ,å,ā + + î,ï,ì,í,į,ī + + ș,ß,ś,š + + ț + diff --git a/tools/makelabel/res/values-ru/donottranslate-more-keys.xml b/tools/makelabel/res/values-ru/donottranslate-more-keys.xml new file mode 100644 index 000000000..0bb57074c --- /dev/null +++ b/tools/makelabel/res/values-ru/donottranslate-more-keys.xml @@ -0,0 +1,33 @@ + + + + + щ + + ы + + и + + ё + + ъ + + ъ + diff --git a/tools/makelabel/res/values-sk/donottranslate-more-keys.xml b/tools/makelabel/res/values-sk/donottranslate-more-keys.xml new file mode 100644 index 000000000..f6e1e8d72 --- /dev/null +++ b/tools/makelabel/res/values-sk/donottranslate-more-keys.xml @@ -0,0 +1,107 @@ + + + + + á,ä,ā,à,â,ã,å,æ,ą + + é,ě,ē,ė,è,ê,ë,ę + + í,ī,į,ì,î,ï,ı + + ô,ó,ö,ò,õ,œ,ő,ø + + ú,ů,ü,ū,ų,ù,û,ű + + š,ß,ś,ş + + ň,ņ,ñ,ń,ń + + č,ç,ć + + ý,ÿ + + ď + + ŕ,ř,ŗ + + ť,ţ + + ž,ż,ź + + ķ + + ľ,ĺ,ļ,ł + + ģ,ğ + diff --git a/tools/makelabel/res/values-sl/donottranslate-more-keys.xml b/tools/makelabel/res/values-sl/donottranslate-more-keys.xml new file mode 100644 index 000000000..ccff2ac29 --- /dev/null +++ b/tools/makelabel/res/values-sl/donottranslate-more-keys.xml @@ -0,0 +1,30 @@ + + + + + š + + č,ć + + đ + + ž + diff --git a/tools/makelabel/res/values-sr/donottranslate-more-keys.xml b/tools/makelabel/res/values-sr/donottranslate-more-keys.xml new file mode 100644 index 000000000..e85d3d7a2 --- /dev/null +++ b/tools/makelabel/res/values-sr/donottranslate-more-keys.xml @@ -0,0 +1,47 @@ + + + + + з + + ћ + + ѕ + + ђ + + ѐ + + ѝ + + + + !fixedColumnOrder!5,„,“,”,«,» + + + !fixedColumnOrder!5,„,“,”,«,»,‘,’,‚,‛ + diff --git a/tools/makelabel/res/values-sv/donottranslate-more-keys.xml b/tools/makelabel/res/values-sv/donottranslate-more-keys.xml new file mode 100644 index 000000000..d479191f4 --- /dev/null +++ b/tools/makelabel/res/values-sv/donottranslate-more-keys.xml @@ -0,0 +1,54 @@ + + + + + é,è,ê,ë,ę + + œ,ô,ò,ó,õ,ō + + ü,û,ù,ú,ū + + ß,ś,š + + å + + ö + + ä + + ø + + æ + diff --git a/tools/makelabel/res/values-tr/donottranslate-more-keys.xml b/tools/makelabel/res/values-tr/donottranslate-more-keys.xml new file mode 100644 index 000000000..1161811d4 --- /dev/null +++ b/tools/makelabel/res/values-tr/donottranslate-more-keys.xml @@ -0,0 +1,57 @@ + + + + + â + + ı,î,ï,ì,í,į,ī + + ö,ô,œ,ò,ó,õ,ø,ō + + ü,û,ù,ú,ū + + ş,ß,ś,š + + ğ + + ç,ć,č + diff --git a/tools/makelabel/res/values-uk/donottranslate-more-keys.xml b/tools/makelabel/res/values-uk/donottranslate-more-keys.xml new file mode 100644 index 000000000..32397049a --- /dev/null +++ b/tools/makelabel/res/values-uk/donottranslate-more-keys.xml @@ -0,0 +1,33 @@ + + + + + щ + + і + + и + + ъ + + ї + + ъ + diff --git a/tools/makelabel/res/values-vi/donottranslate-more-keys.xml b/tools/makelabel/res/values-vi/donottranslate-more-keys.xml new file mode 100644 index 000000000..6ef1c6bc5 --- /dev/null +++ b/tools/makelabel/res/values-vi/donottranslate-more-keys.xml @@ -0,0 +1,95 @@ + + + + + à,á,ả,ã,ạ,ă,ằ,ắ,ẳ,ẵ,ặ,â,ầ,ấ,ẩ,ẫ,ậ + + è,é,ẻ,ẽ,ẹ,ê,ề,ế,ể,ễ,ệ + + ì,í,ỉ,ĩ,ị + + ò,ó,ỏ,õ,ọ,ô,ồ,ố,ổ,ỗ,ộ,ơ,ờ,ớ,ở,ỡ,ợ + + ù,ú,ủ,ũ,ụ,ư,ừ,ứ,ử,ữ,ự + + ỳ,ý,ỷ,ỹ,ỵ + + đ + diff --git a/tools/makelabel/res/values-zz/donottranslate-more-keys.xml b/tools/makelabel/res/values-zz/donottranslate-more-keys.xml new file mode 100644 index 000000000..eb984a469 --- /dev/null +++ b/tools/makelabel/res/values-zz/donottranslate-more-keys.xml @@ -0,0 +1,139 @@ + + + + + à,á,â,ã,ä,å,æ,ã,å,ā,ă,ą,ª + + è,é,ê,ë,ē,ĕ,ė,ę,ě + + ì,í,î,ï,ĩ,ī,ĭ,į,ı,ij + + ò,ó,ô,õ,ö,ø,ō,ŏ,ő,œ,º + + ù,ú,û,ü,ũ,ū,ŭ,ů,ű,ų + + ß,ś,ŝ,ş,š,ſ + + ñ,ń,ņ,ň,ʼn,ŋ + + ç,ć,ĉ,ċ,č + + ý,ŷ,ÿ,ij + + ď,đ,ð + + ŕ,ŗ,ř + + þ,ţ,ť,ŧ + + ź,ż,ž + + ķ,ĸ + + ĺ,ļ,ľ,ŀ,ł + + ĝ,ğ,ġ,ģ + + ĥ + + ĵ + + ŵ + diff --git a/tools/makelabel/res/values/donottranslate-more-keys.xml b/tools/makelabel/res/values/donottranslate-more-keys.xml new file mode 100644 index 000000000..7878757f7 --- /dev/null +++ b/tools/makelabel/res/values/donottranslate-more-keys.xml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + !fixedColumnOrder!4,‘,’,‚,‛ + + + !fixedColumnOrder!4,“,”,«,» + + + !fixedColumnOrder!4,“,”,«,»,‘,’,‚,‛ + + ¢,£,€,¥,₱ + ¢,£,$,¥,₱ + ¢,$,€,¥,₱ + ¢,$,€,£,¥,₱ + "!fixedColumnOrder!5,!hasLabels!,=-O|=-O ,:-P|:-P ,;-)|;-) ,:-(|:-( ,:-)|:-) ,:-!|:-! ,:-$|:-$ ,B-)|B-) ,:O|:O ,:-*|:-* ,:-D|:-D ,:\'(|:\'( ,:-\\\\|:-\\\\ ,O:-)|O:-) ,:-[|:-[ " + "!fixedColumnOrder!8,\",\',#,-,:,!,\\,,\?,\@,&,\\%,+,;,/,(,)" + + ".com" + + "!hasLabels!,.net,.org,.gov,.edu" + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 0 + + + + + + + + + + + + ¹,½,⅓,¼,⅛ + + ²,⅔ + + ³,¾,⅜ + + + + + + + + + + + ⁿ,∅ + !fixedColumnOrder!2,!hasLabels!,\@string/label_time_am,\@string/label_time_pm + !icon/settingsKey|!code/key_settings + , + + !hasLabels!,\@string/label_next_key|!code/key_action_next + !hasLabels!,\@string/label_previous_key|!code/key_action_previous + \? + ; + % + + ¿ + + + + , + ! + ! + \? + \? + \' + - + \" + _ + \" + _ + + ♪,♥,♠,♦,♣ + + †,‡,★ + + ± + + !fixedColumnOrder!3,<,{,[ + !fixedColumnOrder!3,>,},] + + !fixedColumnOrder!3,‹,≤,« + !fixedColumnOrder!3,›,≥,» + + = \\ < + + ~ \\ { + + Tab + + 123 + + + *# + + "AM" + + "PM" + diff --git a/tools/makelabel/src/com/android/inputmethod/latin/makelabel/ArrayInitializerFormatter.java b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/ArrayInitializerFormatter.java new file mode 100644 index 000000000..0cf2991b0 --- /dev/null +++ b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/ArrayInitializerFormatter.java @@ -0,0 +1,89 @@ +/* + * 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.makelabel; + +import java.io.PrintStream; + +public class ArrayInitializerFormatter { + private final PrintStream mOut; + private final int mMaxWidth; + private final String mIndent; + + private int mCurrentIndex = 0; + private String mFixedElement; + private final StringBuilder mBuffer = new StringBuilder(); + private int mBufferedLen; + private int mBufferedIndex = Integer.MIN_VALUE; + + public ArrayInitializerFormatter(PrintStream out, int width, String indent) { + mOut = out; + mMaxWidth = width - indent.length(); + mIndent = indent; + } + + public void flush() { + if (mBuffer.length() == 0) { + return; + } + final int lastIndex = mCurrentIndex - 1; + if (mBufferedIndex == lastIndex) { + mOut.format("%s/* %d */ %s\n", mIndent, mBufferedIndex, mBuffer); + } else if (mBufferedIndex == lastIndex - 1) { + final String[] elements = mBuffer.toString().split(" "); + mOut.format("%s/* %d */ %s\n" + + "%s/* %d */ %s\n", + mIndent, mBufferedIndex, elements[0], + mIndent, lastIndex, elements[1]); + } else { + mOut.format("%s/* %d~ */\n" + + "%s%s\n" + + "%s/* ~%d */\n", mIndent, mBufferedIndex, + mIndent, mBuffer, + mIndent, lastIndex); + } + mBuffer.setLength(0); + mBufferedLen = 0; + } + + public void outCommentLines(String lines) { + flush(); + mOut.print(lines); + mFixedElement = null; + } + + public void outElement(String element) { + if (!element.equals(mFixedElement)) { + flush(); + mBufferedIndex = mCurrentIndex; + } + final int nextLen = mBufferedLen + " ".length() + element.length(); + if (mBufferedLen != 0 && nextLen < mMaxWidth) { + mBuffer.append(' '); + mBuffer.append(element); + mBufferedLen = nextLen; + } else { + if (mBufferedLen != 0) { + mBuffer.append('\n'); + mBuffer.append(mIndent); + } + mBuffer.append(element); + mBufferedLen = element.length(); + } + mCurrentIndex++; + mFixedElement = element; + } +} diff --git a/tools/makelabel/src/com/android/inputmethod/latin/makelabel/JarUtils.java b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/JarUtils.java new file mode 100644 index 000000000..b24b2ca30 --- /dev/null +++ b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/JarUtils.java @@ -0,0 +1,86 @@ +/* + * 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.makelabel; + +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +public class JarUtils { + private static final String MANIFEST = "META-INF/MANIFEST.MF"; + + private JarUtils() { + // This utility class is not publicly instantiable. + } + + public static JarFile getJarFile(final ClassLoader loader) { + final URL resUrl = loader.getResource(MANIFEST); + if (!resUrl.getProtocol().equals("jar")) { + throw new RuntimeException("Should run as jar"); + } + final String path = resUrl.getPath(); + if (!path.startsWith("file:")) { + throw new RuntimeException("Unknown jar path: " + path); + } + final String jarPath = path.substring("file:".length(), path.indexOf('!')); + try { + return new JarFile(URLDecoder.decode(jarPath, "UTF-8")); + } catch (UnsupportedEncodingException e) { + } catch (IOException e) { + } + return null; + } + + public static InputStream openResource(final String name) { + return JarUtils.class.getResourceAsStream("/" + name); + } + + public interface JarFilter { + public boolean accept(String dirName, String name); + } + + public static ArrayList getNameListing(final JarFile jar, final JarFilter filter) { + final ArrayList result = new ArrayList(); + final Enumeration entries = jar.entries(); + while (entries.hasMoreElements()) { + final JarEntry entry = entries.nextElement(); + final String path = entry.getName(); + final int pos = path.lastIndexOf('/'); + final String dirName = (pos >= 0) ? path.substring(0, pos) : ""; + final String name = (pos >= 0) ? path.substring(pos + 1) : path; + if (filter.accept(dirName, name)) { + result.add(path); + } + } + return result; + } + + public static ArrayList getNameListing(final JarFile jar, final String filterName) { + return getNameListing(jar, new JarFilter() { + @Override + public boolean accept(final String dirName, final String name) { + return name.equals(filterName); + } + }); + } +} diff --git a/tools/makelabel/src/com/android/inputmethod/latin/makelabel/LabelMaker.java b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/LabelMaker.java new file mode 100644 index 000000000..e02f80283 --- /dev/null +++ b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/LabelMaker.java @@ -0,0 +1,65 @@ +/* + * 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.makelabel; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.NoSuchElementException; +import java.util.jar.JarFile; + +public class LabelMaker { + static class Options { + private static final String OPTION_JAVA = "-java"; + + public final String mJava; + + public static void usage(String message) { + if (message != null) { + System.err.println(message); + } + System.err.println("usage: makelabel " + OPTION_JAVA + " "); + System.exit(1); + } + + public Options(final String[] argsArray) { + final LinkedList args = new LinkedList(Arrays.asList(argsArray)); + String arg = null; + String java = null; + try { + while (!args.isEmpty()) { + arg = args.removeFirst(); + if (arg.equals(OPTION_JAVA)) { + java = args.removeFirst(); + } else { + usage("Unknown option: " + arg); + } + } + } catch (NoSuchElementException e) { + usage("Option " + arg + " needs argument"); + } + + mJava = java; + } + } + + public static void main(final String[] args) { + final Options options = new Options(args); + final JarFile jar = JarUtils.getJarFile(LabelMaker.class.getClassLoader()); + final MoreKeysResources resources = new MoreKeysResources(jar); + resources.writeToJava(options.mJava); + } +} diff --git a/tools/makelabel/src/com/android/inputmethod/latin/makelabel/MoreKeysResources.java b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/MoreKeysResources.java new file mode 100644 index 000000000..1dfb8533f --- /dev/null +++ b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/MoreKeysResources.java @@ -0,0 +1,258 @@ +/* + * 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.makelabel; + +import java.io.Closeable; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Locale; +import java.util.jar.JarFile; + +public class MoreKeysResources { + private static final String LABEL_RESOURCE_NAME = "donottranslate-more-keys.xml"; + + private static final String JAVA_TEMPLATE = "KeyboardLabelsSet.tmpl"; + private static final String MARK_NAMES = "@NAMES@"; + private static final String MARK_DEFAULT_LABELS = "@DEFAULT_LABELS@"; + private static final String MARK_LABELS = "@LABELS@"; + private static final String MARK_LANGUAGES_AND_LABELS = "@LANGUAGES_AND_LABELS@"; + private static final String DEFAUT_LANGUAGE_NAME = "DEFAULT"; + private static final String ARRAY_NAME_FOR_LANGUAGE = "LANGUAGE_%s"; + private static final String EMPTY_STRING_VAR = "EMPTY"; + + private static final String NO_LANGUAGE_CODE = "zz"; + private static final String NO_LANGUAGE_DISPLAY_NAME = "No language"; + + private final JarFile mJar; + // Language to string resources map. + private final HashMap mResourcesMap = + new HashMap(); + // Name to id map. + private final HashMap mNameToIdMap = new HashMap(); + + public MoreKeysResources(final JarFile jar) { + mJar = jar; + final ArrayList resources = JarUtils.getNameListing(jar, LABEL_RESOURCE_NAME); + for (final String name : resources) { + final String dirName = name.substring(0, name.lastIndexOf('/')); + final int pos = dirName.lastIndexOf('/'); + final String parentName = (pos >= 0) ? dirName.substring(pos + 1) : dirName; + final String language = getLanguageFromResDir(parentName); + final InputStream stream = JarUtils.openResource(name); + try { + mResourcesMap.put(language, new StringResourceMap(stream)); + } finally { + close(stream); + } + } + } + + private static String getLanguageFromResDir(final String dirName) { + final int languagePos = dirName.indexOf('-'); + if (languagePos < 0) { + // Default resource. + return DEFAUT_LANGUAGE_NAME; + } + final String language = dirName.substring(languagePos + 1); + final int countryPos = language.indexOf("-r"); + if (countryPos < 0) { + return language; + } + return language.replace("-r", "_"); + } + + public void writeToJava(final String outDir) { + final ArrayList list = JarUtils.getNameListing(mJar, JAVA_TEMPLATE); + if (list.isEmpty()) + throw new RuntimeException("Can't find java template " + JAVA_TEMPLATE); + if (list.size() > 1) + throw new RuntimeException("Found multiple java template " + JAVA_TEMPLATE); + final String template = list.get(0); + final String javaPackage = template.substring(0, template.lastIndexOf('/')); + PrintStream ps = null; + LineNumberReader lnr = null; + try { + if (outDir == null) { + ps = System.out; + } else { + final File outPackage = new File(outDir, javaPackage); + final File outputFile = new File(outPackage, + JAVA_TEMPLATE.replace(".tmpl", ".java")); + outPackage.mkdirs(); + ps = new PrintStream(outputFile); + } + lnr = new LineNumberReader(new InputStreamReader(JarUtils.openResource(template))); + inflateTemplate(lnr, ps); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + close(lnr); + close(ps); + } + } + + private void inflateTemplate(final LineNumberReader in, final PrintStream out) + throws IOException { + String line; + while ((line = in.readLine()) != null) { + if (line.contains(MARK_NAMES)) { + dumpNames(out); + } else if (line.contains(MARK_DEFAULT_LABELS)) { + dumpDefaultLabels(out); + } else if (line.contains(MARK_LABELS)) { + dumpLabels(out); + } else if (line.contains(MARK_LANGUAGES_AND_LABELS)) { + dumpLanguageMap(out); + } else { + out.println(line); + } + } + } + + private void dumpNames(final PrintStream out) { + final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME); + int id = 0; + for (final StringResource res : defaultResMap.getResources()) { + out.format(" /* %2d */ \"%s\",\n", id, res.mName); + mNameToIdMap.put(res.mName, id); + id++; + } + } + + private void dumpDefaultLabels(final PrintStream out) { + final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME); + dumpLabelsInternal(out, defaultResMap, defaultResMap); + } + + private void dumpLabels(final PrintStream out) { + final StringResourceMap defaultResMap = mResourcesMap.get(DEFAUT_LANGUAGE_NAME); + final ArrayList allLanguages = new ArrayList(); + allLanguages.addAll(mResourcesMap.keySet()); + Collections.sort(allLanguages); + for (final String language : allLanguages) { + if (language.equals(DEFAUT_LANGUAGE_NAME)) { + continue; + } + out.format(" /* Language %s: %s */\n", language, getLanguageDisplayName(language)); + out.format(" private static final String[] " + ARRAY_NAME_FOR_LANGUAGE + " = {\n", + language); + final StringResourceMap resMap = mResourcesMap.get(language); + dumpLabelsInternal(out, resMap, defaultResMap); + out.format(" };\n\n"); + } + } + + private void dumpLanguageMap(final PrintStream out) { + final ArrayList allLanguages = new ArrayList(); + allLanguages.addAll(mResourcesMap.keySet()); + Collections.sort(allLanguages); + for (final String language : allLanguages) { + out.format(" \"%s\", " + ARRAY_NAME_FOR_LANGUAGE + ", /* %s */\n", + language, language, getLanguageDisplayName(language)); + } + } + + private static String getLanguageDisplayName(final String language) { + if (language.equals(NO_LANGUAGE_CODE)) { + return NO_LANGUAGE_DISPLAY_NAME; + } else { + return new Locale(language).getDisplayLanguage(); + } + } + + private static void dumpLabelsInternal(final PrintStream out, final StringResourceMap resMap, + final StringResourceMap defaultResMap) { + final ArrayInitializerFormatter formatter = + new ArrayInitializerFormatter(out, 100, " "); + boolean successiveNull = false; + for (final StringResource defaultRes : defaultResMap.getResources()) { + if (resMap.contains(defaultRes.mName)) { + final StringResource res = resMap.get(defaultRes.mName); + if (res.mComment != null) { + formatter.outCommentLines(addPrefix(" // ", res. mComment)); + } + final String escaped = escapeNonAscii(res.mValue); + if (escaped.length() == 0) { + formatter.outElement(EMPTY_STRING_VAR + ","); + } else { + formatter.outElement(String.format("\"%s\",", escaped)); + } + successiveNull = false; + } else { + formatter.outElement("null,"); + successiveNull = true; + } + } + if (!successiveNull) { + formatter.flush(); + } + } + + private static String addPrefix(final String prefix, final String lines) { + final StringBuilder sb = new StringBuilder(); + for (final String line : lines.split("\n")) { + sb.append(prefix + line.trim() + "\n"); + } + return sb.toString(); + } + + private static String escapeNonAscii(final String text) { + final StringBuilder sb = new StringBuilder(); + final int length = text.length(); + for (int i = 0; i < length; i++) { + final char c = text.charAt(i); + if (c >= ' ' && c < 0x7f) { + sb.append(c); + } else { + sb.append(String.format("\\u%04X", (int)c)); + } + } + return replaceIncompatibleEscape(sb.toString()); + } + + private static String replaceIncompatibleEscape(final String text) { + String t = text; + t = replaceAll(t, "\\?", "?"); + t = replaceAll(t, "\\@", "@"); + t = replaceAll(t, "@string/", "!label/"); + return t; + } + + private static String replaceAll(final String text, final String target, final String replace) { + String t = text; + while (t.indexOf(target) >= 0) { + t = t.replace(target, replace); + } + return t; + } + + private static void close(Closeable stream) { + try { + if (stream != null) { + stream.close(); + } + } catch (IOException e) { + } + } +} diff --git a/tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResource.java b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResource.java new file mode 100644 index 000000000..793483ce1 --- /dev/null +++ b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResource.java @@ -0,0 +1,29 @@ +/* + * 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.makelabel; + +public class StringResource { + public final String mName; + public final String mValue; + public final String mComment; + + public StringResource(final String name, final String value, final String comment) { + mName = name; + mValue = value; + mComment = comment; + } +} diff --git a/tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResourceMap.java b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResourceMap.java new file mode 100644 index 000000000..afb1aa7ac --- /dev/null +++ b/tools/makelabel/src/com/android/inputmethod/latin/makelabel/StringResourceMap.java @@ -0,0 +1,128 @@ +/* + * 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.makelabel; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.ext.DefaultHandler2; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +public class StringResourceMap { + // String resource list. + private final List mResources; + // Name to string resource map. + private final Map mResourcesMap; + + public StringResourceMap(final InputStream is) { + final StringResourceHandler handler = new StringResourceHandler(); + final SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + try { + final SAXParser parser = factory.newSAXParser(); + // In order to get comment tag. + parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); + parser.parse(is, handler); + } catch (ParserConfigurationException e) { + } catch (SAXException e) { + throw new RuntimeException(e.getMessage()); + } catch (IOException e) { + } + + mResources = Collections.unmodifiableList(handler.mResources); + final HashMap map = new HashMap(); + for (final StringResource res : mResources) { + map.put(res.mName, res); + } + mResourcesMap = map; + } + + public List getResources() { + return mResources; + } + + public boolean contains(final String name) { + return mResourcesMap.containsKey(name); + } + + public StringResource get(final String name) { + return mResourcesMap.get(name); + } + + static class StringResourceHandler extends DefaultHandler2 { + private static final String TAG_RESOURCES = "resources"; + private static final String TAG_STRING = "string"; + private static final String ATTR_NAME = "name"; + + final ArrayList mResources = new ArrayList(); + + private String mName; + private final StringBuilder mValue = new StringBuilder(); + private final StringBuilder mComment = new StringBuilder(); + + private void init() { + mName = null; + mComment.setLength(0); + } + + @Override + public void comment(char[] ch, int start, int length) { + mComment.append(ch, start, length); + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attr) { + if (TAG_RESOURCES.equals(localName)) { + init(); + } else if (TAG_STRING.equals(localName)) { + mName = attr.getValue(ATTR_NAME); + mValue.setLength(0); + } + } + + @Override + public void characters(char[] ch, int start, int length) { + mValue.append(ch, start, length); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + if (TAG_STRING.equals(localName)) { + if (mName == null) + throw new SAXException(TAG_STRING + " doesn't have name"); + final String comment = mComment.length() > 0 ? mComment.toString() : null; + String value = mValue.toString(); + if (value.startsWith("\"") && value.endsWith("\"")) { + // Trim surroundings double quote. + value = value.substring(1, value.length() - 1); + } + mResources.add(new StringResource(mName, value, comment)); + init(); + } + } + } +} -- cgit v1.2.3-83-g751a From f6972561fcb45310f18230ce217f0c6bb57e7eee Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 11 Apr 2012 18:21:10 +0900 Subject: Utilize InputMethodSubtype and additional subtype * Remove de_QY and fr_CH from supported subtypes * Add de-qwerty and fr-qwertz predefined additional subtypes instead. Change-Id: I49e8ba0299529302f2b91b4d018b07304cdd6897 --- java/res/values/donottranslate.xml | 10 +- java/res/xml/method.xml | 18 +-- .../compat/InputMethodManagerCompatWrapper.java | 4 + .../com/android/inputmethod/keyboard/Keyboard.java | 2 +- .../android/inputmethod/keyboard/KeyboardId.java | 18 ++- .../inputmethod/keyboard/KeyboardLayoutSet.java | 11 +- .../inputmethod/keyboard/LatinKeyboardView.java | 18 +-- .../inputmethod/latin/AdditionalSubtype.java | 56 +++++++ .../com/android/inputmethod/latin/LatinIME.java | 4 + .../android/inputmethod/latin/SettingsValues.java | 18 +++ .../android/inputmethod/latin/SubtypeLocale.java | 145 ++++++++---------- .../android/inputmethod/latin/SubtypeSwitcher.java | 14 +- .../android/inputmethod/latin/SubtypeUtils.java | 3 +- .../inputmethod/latin/SubtypeLocaleTests.java | 167 ++++++++++++++------- 14 files changed, 296 insertions(+), 192 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/AdditionalSubtype.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index bfe42327c..892c72aec 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -134,24 +134,24 @@ 5 - + en_US en_GB - *_QY - QY English (US) English (UK) - @string/subtype_generic_qwerty - QWERTY %s %s (QWERTY) + + %s (QWERTZ) + + %s (AZERTY) com.google.android.inputmethod.latin.dictionarypack diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml index ba4534351..ca0b24e19 100644 --- a/java/res/xml/method.xml +++ b/java/res/xml/method.xml @@ -28,7 +28,6 @@ cs: Czech/qwertz da: Danish/nordic de: German/qwertz - de_QY: German (QWERTY)/qwerty el: Greek/greek en_US: English United States/qwerty en_GB: English Great Britain/qwerty @@ -38,7 +37,6 @@ fi: Finnish/nordic fr: French/azerty fr_CA: French Canada/qwerty - fr_CH: French Switzerland/qwertz hi: Hindi/hindi hr: Croatian/qwertz hu: Hungarian/qwertz @@ -64,7 +62,7 @@ tr: Turkish/qwerty uk: Ukrainian/east_slavic vi: Vietnamese/qwerty - zz_QY: QWERTY/qwerty + zz: QWERTY/qwerty --> + + + de:qwerty,fr:qwertz + diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java index 5e42ad6c5..b24f06472 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java @@ -52,4 +52,20 @@ public class AdditionalSubtype { return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard, localeString, SUBTYPE_MODE_KEYBOARD, extraValue, false, false); } + + private static final String LOCALE_AND_LAYOUT_SEPARATOR = ":"; + private static final String SUBTYPE_SEPARATOR = ","; + + public static InputMethodSubtype[] createAdditionalSubtypesArray(String csvSubtypes) { + final String[] subtypeSpecs = csvSubtypes.split(SUBTYPE_SEPARATOR); + final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[subtypeSpecs.length]; + for (int i = 0; i < subtypeSpecs.length; i++) { + final String elems[] = subtypeSpecs[i].split(LOCALE_AND_LAYOUT_SEPARATOR); + final String localeString = elems[0]; + final String keyboardLayoutSetName = elems[1]; + subtypesArray[i] = AdditionalSubtype.createAdditionalSubtype( + localeString, keyboardLayoutSetName); + } + return subtypesArray; + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index aea6add56..682901cbc 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -441,8 +441,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadSettings(); - ImfUtils.setAdditionalInputMethodSubtypes( - this, mSettingsValues.getPrefefinedAdditionalSubtypes()); + ImfUtils.setAdditionalInputMethodSubtypes(this, mSettingsValues.getAdditionalSubtypes()); // TODO: remove the following when it's not needed by updateCorrectionMode() any more mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 43e7e278f..29825df7d 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -62,6 +62,7 @@ public class Settings extends InputMethodSettingsFragment "pref_suppress_language_switch_key"; public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST = "pref_include_other_imes_in_language_switch_list"; + public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles"; public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 539ac5963..c160555f0 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -71,7 +71,7 @@ public class SettingsValues { private final int mVibrationDurationSettingsRawValue; @SuppressWarnings("unused") // TODO: Use this private final float mKeypressSoundVolumeRawValue; - private final InputMethodSubtype[] mPredefinedAdditionalSubtypes; + private final InputMethodSubtype[] mAdditionalSubtypes; // Deduced settings public final int mKeypressVibrationDuration; @@ -149,15 +149,8 @@ public class SettingsValues { mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); - // Predefined additional subtypes - final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype( - Locale.GERMAN.toString(), AdditionalSubtype.QWERTY); - final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype( - Locale.FRENCH.toString(), AdditionalSubtype.QWERTZ); - mPredefinedAdditionalSubtypes = new InputMethodSubtype[] { - DE_QWERTY, - FR_QWERTZ, - }; + mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( + getCsvAdditionalSubtypes(prefs, res)); } // Helper functions to create member values. @@ -318,9 +311,14 @@ 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; + public InputMethodSubtype[] getAdditionalSubtypes() { + return mAdditionalSubtypes; + } + + public static String getCsvAdditionalSubtypes(final SharedPreferences prefs, + final Resources res) { + final String csvPredefinedSubtypes = res.getString(R.string.predefined_subtypes, ""); + return prefs.getString(Settings.PREF_CUSTOM_INPUT_STYLES, csvPredefinedSubtypes); } // Accessed from the settings interface, hence public -- cgit v1.2.3-83-g751a From 344af156744c6866090fb70f151efd66668c1e20 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 19 Apr 2012 16:39:25 +0900 Subject: Change predefined additional subtype format in preference This change also refactor StringUtils class Change-Id: Ie0b4d169b21c260bf238d6fcc9ab0ee8bfd6b508 --- java/res/values/predefined-subtypes.xml | 4 +- .../inputmethod/keyboard/KeyboardLayoutSet.java | 10 +-- .../inputmethod/latin/AdditionalSubtype.java | 33 ++++---- .../android/inputmethod/latin/InputAttributes.java | 8 ++ .../com/android/inputmethod/latin/LatinIME.java | 20 ++++- .../android/inputmethod/latin/SettingsValues.java | 8 +- .../com/android/inputmethod/latin/StringUtils.java | 50 ++++++------ .../inputmethod/latin/StringUtilsTests.java | 91 ++++++++++++++++++++++ .../inputmethod/latin/SubtypeLocaleTests.java | 8 +- 9 files changed, 174 insertions(+), 58 deletions(-) create mode 100644 tests/src/com/android/inputmethod/latin/StringUtilsTests.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/values/predefined-subtypes.xml b/java/res/values/predefined-subtypes.xml index e67fee53f..602f53eac 100644 --- a/java/res/values/predefined-subtypes.xml +++ b/java/res/values/predefined-subtypes.xml @@ -18,6 +18,6 @@ */ --> - - de:qwerty,fr:qwertz + + de:qwerty:AsciiCapable;fr:qwertz:AsciiCapable diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index 35209e0ad..07f71ee17 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -29,11 +29,11 @@ import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.keyboard.KeyboardLayoutSet.Params.ElementParams; +import com.android.inputmethod.latin.InputAttributes; import com.android.inputmethod.latin.InputTypeUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.XmlParseUtils; @@ -229,7 +229,7 @@ public class KeyboardLayoutSet { params.mMode = getKeyboardMode(editorInfo); params.mEditorInfo = (editorInfo != null) ? editorInfo : EMPTY_EDITOR_INFO; - params.mNoSettingsKey = StringUtils.inPrivateImeOptions( + params.mNoSettingsKey = InputAttributes.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, mEditorInfo); } @@ -242,7 +242,7 @@ public class KeyboardLayoutSet { public Builder setSubtype(InputMethodSubtype subtype) { final boolean asciiCapable = subtype.containsExtraValueKey( LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); - final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions( + final boolean deprecatedForceAscii = InputAttributes.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii( mParams.mEditorInfo.imeOptions) @@ -259,9 +259,9 @@ public class KeyboardLayoutSet { public Builder setOptions(boolean voiceKeyEnabled, boolean voiceKeyOnMain, boolean languageSwitchKeyEnabled) { @SuppressWarnings("deprecation") - final boolean deprecatedNoMicrophone = StringUtils.inPrivateImeOptions( + final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions( null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, mEditorInfo); - final boolean noMicrophone = StringUtils.inPrivateImeOptions( + final boolean noMicrophone = InputAttributes.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_NO_MICROPHONE, mEditorInfo) || deprecatedNoMicrophone; mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone; diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java index b24f06472..323f74ab9 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtype.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtype.java @@ -43,28 +43,35 @@ public class AdditionalSubtype { } public static InputMethodSubtype createAdditionalSubtype( - String localeString, 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); + String localeString, String keyboardLayoutSetName, String extraValue) { + final String layoutExtraValue = LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET + "=" + + keyboardLayoutSetName; + final String filteredExtraValue = StringUtils.appendToCsvIfNotExists( + SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE, + StringUtils.removeFromCsvIfExists(layoutExtraValue, extraValue)); + Integer nameId = sKeyboardLayoutToNameIdsMap.get(keyboardLayoutSetName); if (nameId == null) nameId = R.string.subtype_generic; return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard, - localeString, SUBTYPE_MODE_KEYBOARD, extraValue, false, false); + localeString, SUBTYPE_MODE_KEYBOARD, filteredExtraValue, false, false); } private static final String LOCALE_AND_LAYOUT_SEPARATOR = ":"; - private static final String SUBTYPE_SEPARATOR = ","; + private static final String PREF_SUBTYPE_SEPARATOR = ";"; - public static InputMethodSubtype[] createAdditionalSubtypesArray(String csvSubtypes) { - final String[] subtypeSpecs = csvSubtypes.split(SUBTYPE_SEPARATOR); - final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[subtypeSpecs.length]; - for (int i = 0; i < subtypeSpecs.length; i++) { - final String elems[] = subtypeSpecs[i].split(LOCALE_AND_LAYOUT_SEPARATOR); + public static InputMethodSubtype[] createAdditionalSubtypesArray(String prefSubtypes) { + final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR); + final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[prefSubtypeArray.length]; + for (int i = 0; i < prefSubtypeArray.length; i++) { + final String prefSubtype = prefSubtypeArray[i]; + final String elems[] = prefSubtype.split(LOCALE_AND_LAYOUT_SEPARATOR); + if (elems.length < 2 || elems.length > 3) { + throw new RuntimeException("Unknown subtype found in preference: " + prefSubtype); + } final String localeString = elems[0]; final String keyboardLayoutSetName = elems[1]; + final String extraValue = (elems.length == 3) ? elems[2] : null; subtypesArray[i] = AdditionalSubtype.createAdditionalSubtype( - localeString, keyboardLayoutSetName); + localeString, keyboardLayoutSetName, extraValue); } return subtypesArray; } diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java index a6ce04069..9c32f947c 100644 --- a/java/src/com/android/inputmethod/latin/InputAttributes.java +++ b/java/src/com/android/inputmethod/latin/InputAttributes.java @@ -162,4 +162,12 @@ public class InputAttributes { + "\n mIsSettingsSuggestionStripOn = " + mIsSettingsSuggestionStripOn + "\n mApplicationSpecifiedCompletionOn = " + mApplicationSpecifiedCompletionOn; } + + public static boolean inPrivateImeOptions(String packageName, String key, + EditorInfo editorInfo) { + if (editorInfo == null) return false; + final String findingKey = (packageName != null) ? packageName + "." + key + : key; + return StringUtils.containsInCsv(findingKey, editorInfo.privateImeOptions); + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 682901cbc..9cfde8b77 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -669,12 +669,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onStartInputViewInternal(editorInfo); } - if (StringUtils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { + if (InputAttributes.inPrivateImeOptions( + null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead"); } - if (StringUtils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { + if (InputAttributes.inPrivateImeOptions( + getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); @@ -1077,7 +1079,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ic == null) return false; final CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 - && StringUtils.canBeFollowedByPeriod(lastThree.charAt(0)) + && canBeFollowedByPeriod(lastThree.charAt(0)) && lastThree.charAt(1) == Keyboard.CODE_SPACE && lastThree.charAt(2) == Keyboard.CODE_SPACE && mHandler.isAcceptingDoubleSpaces()) { @@ -1093,6 +1095,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return false; } + private static boolean canBeFollowedByPeriod(final int codePoint) { + // TODO: Check again whether there really ain't a better way to check this. + // TODO: This should probably be language-dependant... + return Character.isLetterOrDigit(codePoint) + || codePoint == Keyboard.CODE_SINGLE_QUOTE + || codePoint == Keyboard.CODE_DOUBLE_QUOTE + || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS + || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET + || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET + || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; + } + // "ic" may be null private static void removeTrailingSpaceWhileInBatchEdit(final InputConnection ic) { if (ic == null) return; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index c160555f0..b83cec462 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -150,7 +150,7 @@ public class SettingsValues { mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( - getCsvAdditionalSubtypes(prefs, res)); + getPrefAdditionalSubtypes(prefs, res)); } // Helper functions to create member values. @@ -315,10 +315,10 @@ public class SettingsValues { return mAdditionalSubtypes; } - public static String getCsvAdditionalSubtypes(final SharedPreferences prefs, + public static String getPrefAdditionalSubtypes(final SharedPreferences prefs, final Resources res) { - final String csvPredefinedSubtypes = res.getString(R.string.predefined_subtypes, ""); - return prefs.getString(Settings.PREF_CUSTOM_INPUT_STYLES, csvPredefinedSubtypes); + final String prefSubtypes = res.getString(R.string.predefined_subtypes, ""); + return prefs.getString(Settings.PREF_CUSTOM_INPUT_STYLES, prefSubtypes); } // Accessed from the settings interface, hence public diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java index a599933d8..160581cbe 100644 --- a/java/src/com/android/inputmethod/latin/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -17,9 +17,6 @@ package com.android.inputmethod.latin; import android.text.TextUtils; -import android.view.inputmethod.EditorInfo; - -import com.android.inputmethod.keyboard.Keyboard; import java.util.ArrayList; import java.util.Locale; @@ -29,39 +26,38 @@ public class StringUtils { // This utility class is not publicly instantiable. } - public static boolean canBeFollowedByPeriod(final int codePoint) { - // TODO: Check again whether there really ain't a better way to check this. - // TODO: This should probably be language-dependant... - return Character.isLetterOrDigit(codePoint) - || codePoint == Keyboard.CODE_SINGLE_QUOTE - || codePoint == Keyboard.CODE_DOUBLE_QUOTE - || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS - || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET - || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET - || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; - } - public static int codePointCount(String text) { if (TextUtils.isEmpty(text)) return 0; return text.codePointCount(0, text.length()); } - private static boolean containsInCsv(String key, String csv) { - if (csv == null) - return false; - for (String option : csv.split(",")) { - if (option.equals(key)) - return true; + public static boolean containsInArray(String key, String[] array) { + for (final String element : array) { + if (key.equals(element)) return true; } return false; } - public static boolean inPrivateImeOptions(String packageName, String key, - EditorInfo editorInfo) { - if (editorInfo == null) - return false; - return containsInCsv(packageName != null ? packageName + "." + key : key, - editorInfo.privateImeOptions); + public static boolean containsInCsv(String key, String csv) { + if (TextUtils.isEmpty(csv)) return false; + return containsInArray(key, csv.split(",")); + } + + public static String appendToCsvIfNotExists(String key, String csv) { + if (TextUtils.isEmpty(csv)) return key; + if (containsInCsv(key, csv)) return csv; + return csv + "," + key; + } + + public static String removeFromCsvIfExists(String key, String csv) { + if (TextUtils.isEmpty(csv)) return ""; + final String[] elements = csv.split(","); + if (!containsInArray(key, elements)) return csv; + final ArrayList result = new ArrayList(elements.length - 1); + for (final String element : elements) { + if (!key.equals(element)) result.add(element); + } + return TextUtils.join(",", result); } /** diff --git a/tests/src/com/android/inputmethod/latin/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java new file mode 100644 index 000000000..8a5a82246 --- /dev/null +++ b/tests/src/com/android/inputmethod/latin/StringUtilsTests.java @@ -0,0 +1,91 @@ +/* + * 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.test.AndroidTestCase; + +public class StringUtilsTests extends AndroidTestCase { + public void testContainsInArray() { + assertFalse("empty array", StringUtils.containsInArray("key", new String[0])); + assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] { + "key1" + })); + assertFalse("not in 2 elements", StringUtils.containsInArray("key", new String[] { + "key1", "key2" + })); + + assertTrue("in 1 element", StringUtils.containsInArray("key", new String[] { + "key" + })); + assertTrue("in 2 elements", StringUtils.containsInArray("key", new String[] { + "key1", "key" + })); + } + + public void testContainsInCsv() { + assertFalse("null", StringUtils.containsInCsv("key", null)); + assertFalse("empty", StringUtils.containsInCsv("key", "")); + assertFalse("not in 1 element", StringUtils.containsInCsv("key", "key1")); + assertFalse("not in 2 elements", StringUtils.containsInCsv("key", "key1,key2")); + + assertTrue("in 1 element", StringUtils.containsInCsv("key", "key")); + assertTrue("in 2 elements", StringUtils.containsInCsv("key", "key1,key")); + } + + public void testAppendToCsvIfNotExists() { + assertEquals("null", "key", StringUtils.appendToCsvIfNotExists("key", null)); + assertEquals("empty", "key", StringUtils.appendToCsvIfNotExists("key", "")); + + assertEquals("not in 1 element", "key1,key", + StringUtils.appendToCsvIfNotExists("key", "key1")); + assertEquals("not in 2 elements", "key1,key2,key", + StringUtils.appendToCsvIfNotExists("key", "key1,key2")); + + assertEquals("in 1 element", "key", + StringUtils.appendToCsvIfNotExists("key", "key")); + assertEquals("in 2 elements at position 1", "key,key2", + StringUtils.appendToCsvIfNotExists("key", "key,key2")); + assertEquals("in 2 elements at position 2", "key1,key", + StringUtils.appendToCsvIfNotExists("key", "key1,key")); + assertEquals("in 3 elements at position 2", "key1,key,key3", + StringUtils.appendToCsvIfNotExists("key", "key1,key,key3")); + } + + public void testRemoveFromCsvIfExists() { + assertEquals("null", "", StringUtils.removeFromCsvIfExists("key", null)); + assertEquals("empty", "", StringUtils.removeFromCsvIfExists("key", "")); + + assertEquals("not in 1 element", "key1", + StringUtils.removeFromCsvIfExists("key", "key1")); + assertEquals("not in 2 elements", "key1,key2", + StringUtils.removeFromCsvIfExists("key", "key1,key2")); + + assertEquals("in 1 element", "", + StringUtils.removeFromCsvIfExists("key", "key")); + assertEquals("in 2 elements at position 1", "key2", + StringUtils.removeFromCsvIfExists("key", "key,key2")); + assertEquals("in 2 elements at position 2", "key1", + StringUtils.removeFromCsvIfExists("key", "key1,key")); + assertEquals("in 3 elements at position 2", "key1,key3", + StringUtils.removeFromCsvIfExists("key", "key1,key,key3")); + + assertEquals("in 3 elements at position 1,2,3", "", + StringUtils.removeFromCsvIfExists("key", "key,key,key")); + assertEquals("in 5 elements at position 2,4", "key1,key3,key5", + StringUtils.removeFromCsvIfExists("key", "key1,key,key3,key,key5")); + } +} diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java index 12711c137..971fbc21b 100644 --- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java @@ -165,13 +165,13 @@ public class SubtypeLocaleTests extends AndroidTestCase { public void testAdditionalSubtype() { final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype( - Locale.GERMAN.toString(), AdditionalSubtype.QWERTY); + Locale.GERMAN.toString(), AdditionalSubtype.QWERTY, null); final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype( - Locale.FRENCH.toString(), AdditionalSubtype.QWERTZ); + Locale.FRENCH.toString(), AdditionalSubtype.QWERTZ, null); final InputMethodSubtype EN_AZERTY = AdditionalSubtype.createAdditionalSubtype( - Locale.ENGLISH.toString(), AdditionalSubtype.AZERTY); + Locale.ENGLISH.toString(), AdditionalSubtype.AZERTY, null); final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype( - SubtypeLocale.NO_LANGUAGE, AdditionalSubtype.AZERTY); + SubtypeLocale.NO_LANGUAGE, AdditionalSubtype.AZERTY, null); assertTrue(AdditionalSubtype.isAdditionalSubtype(FR_QWERTZ)); assertTrue(AdditionalSubtype.isAdditionalSubtype(DE_QWERTY)); -- cgit v1.2.3-83-g751a From c27fe6253c1d8b3ad3c2f891a48ec5c54d77a3f1 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 13 Apr 2012 16:41:24 +0900 Subject: Add custom subtype settings Bug: 4460018 Change-Id: I4919d79516dcf574be2761bbaf9adcdc381b2ddc --- java/res/layout/additional_subtype_dialog.xml | 56 +++ java/res/values/strings.xml | 17 + java/res/xml/additional_subtype_settings.xml | 19 + java/res/xml/prefs.xml | 4 + .../inputmethod/latin/AdditionalSubtype.java | 55 ++- .../latin/AdditionalSubtypeSettings.java | 438 +++++++++++++++++++++ .../com/android/inputmethod/latin/Settings.java | 17 + .../inputmethod/latin/SettingsActivity.java | 12 +- .../android/inputmethod/latin/SettingsValues.java | 2 - .../android/inputmethod/latin/SubtypeLocale.java | 29 +- .../inputmethod/latin/SubtypeLocaleTests.java | 39 +- 11 files changed, 640 insertions(+), 48 deletions(-) create mode 100644 java/res/layout/additional_subtype_dialog.xml create mode 100644 java/res/xml/additional_subtype_settings.xml create mode 100644 java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/layout/additional_subtype_dialog.xml b/java/res/layout/additional_subtype_dialog.xml new file mode 100644 index 000000000..f97c006d6 --- /dev/null +++ b/java/res/layout/additional_subtype_dialog.xml @@ -0,0 +1,56 @@ + + + + + + + + + diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 28acd0fcc..93bd26867 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -252,9 +252,26 @@ English (UK) English (US) + + No language No language (QWERTY) + + Custom input styles + + Add style + + Add + + Remove + + Save + + Language + + Layout + Usability study mode diff --git a/java/res/xml/additional_subtype_settings.xml b/java/res/xml/additional_subtype_settings.xml new file mode 100644 index 000000000..ad280c146 --- /dev/null +++ b/java/res/xml/additional_subtype_settings.xml @@ -0,0 +1,19 @@ + + + + + + diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index ab5d44b24..3598a685e 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -100,6 +100,10 @@ android:summary="@string/include_other_imes_in_language_switch_list_summary" android:persistent="true" android:defaultValue="false" /> + 3) { - throw new RuntimeException("Unknown subtype found in preference: " + prefSubtype); - } - final String localeString = elems[0]; - final String keyboardLayoutSetName = elems[1]; - final String extraValue = (elems.length == 3) ? elems[2] : null; - subtypesArray[i] = AdditionalSubtype.createAdditionalSubtype( - localeString, keyboardLayoutSetName, extraValue); + subtypesArray[i] = createAdditionalSubtype(prefSubtypeArray[i]); } return subtypesArray; } diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java new file mode 100644 index 000000000..6ff8aa2f5 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java @@ -0,0 +1,438 @@ +/** + * 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.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import android.preference.DialogPreference; +import android.preference.Preference; +import android.preference.PreferenceFragment; +import android.preference.PreferenceGroup; +import android.preference.PreferenceScreen; +import android.util.Pair; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodInfo; +import android.view.inputmethod.InputMethodSubtype; +import android.widget.ArrayAdapter; +import android.widget.Spinner; +import android.widget.SpinnerAdapter; + +import java.util.Locale; +import java.util.TreeSet; + +public class AdditionalSubtypeSettings extends PreferenceFragment { + private SharedPreferences mPrefs; + private SubtypeLocaleAdapter mSubtypeLocaleAdapter; + private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter; + + private PreferenceGroup mSubtypePrefGroup; + + private static final int MENU_ADD_SUBTYPE = Menu.FIRST; + + static class SubtypeLocaleItem extends Pair + implements Comparable { + public SubtypeLocaleItem(String localeString, String displayName) { + super(localeString, displayName); + } + + public SubtypeLocaleItem(String localeString) { + this(localeString, getDisplayName(localeString)); + } + + @Override + public String toString() { + return second; + } + + @Override + public int compareTo(SubtypeLocaleItem o) { + return first.compareTo(o.first); + } + + private static String getDisplayName(String localeString) { + final Locale locale = LocaleUtils.constructLocaleFromString(localeString); + return StringUtils.toTitleCase(locale.getDisplayName(locale), locale); + } + } + + static class SubtypeLocaleAdapter extends ArrayAdapter { + public SubtypeLocaleAdapter(Context context) { + super(context, android.R.layout.simple_spinner_item); + setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + final TreeSet items = new TreeSet(); + final InputMethodInfo imi = ImfUtils.getInputMethodInfoOfThisIme(context); + final int count = imi.getSubtypeCount(); + for (int i = 0; i < count; i++) { + final InputMethodSubtype subtype = imi.getSubtypeAt(i); + if (subtype.containsExtraValueKey(LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE)) { + items.add(createItem(context, subtype.getLocale())); + } + } + // TODO: Should filter out already existing combinations of locale and layout. + addAll(items); + } + + public static SubtypeLocaleItem createItem(Context context, String localeString) { + if (localeString.equals(SubtypeLocale.NO_LANGUAGE)) { + final String displayName = context.getString(R.string.subtype_no_language); + return new SubtypeLocaleItem(localeString, displayName); + } else { + return new SubtypeLocaleItem(localeString); + } + } + } + + static class KeyboardLayoutSetItem extends Pair { + public KeyboardLayoutSetItem(String keyboardLayoutSetName) { + super(keyboardLayoutSetName, getDisplayName(keyboardLayoutSetName)); + } + + @Override + public String toString() { + return second; + } + + private static String getDisplayName(String keyboardLayoutSetName) { + return keyboardLayoutSetName.toUpperCase(); + } + } + + static class KeyboardLayoutSetAdapter extends ArrayAdapter { + public KeyboardLayoutSetAdapter(Context context) { + super(context, android.R.layout.simple_spinner_item); + setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + + // TODO: Should filter out already existing combinations of locale and layout. + for (final String layout : AdditionalSubtype.PREDEFINED_KEYBOARD_LAYOUT_SET) { + add(new KeyboardLayoutSetItem(layout)); + } + } + } + + private interface SubtypeDialogProxy { + public void onRemovePressed(SubtypePreference subtypePref); + public SubtypeLocaleAdapter getSubtypeLocaleAdapter(); + public KeyboardLayoutSetAdapter getKeyboardLayoutSetAdapter(); + } + + static class SubtypePreference extends DialogPreference { + private InputMethodSubtype mSubtype; + + private final SubtypeDialogProxy mProxy; + private Spinner mSubtypeLocaleSpinner; + private Spinner mKeyboardLayoutSetSpinner; + + public SubtypePreference(Context context, InputMethodSubtype subtype, + SubtypeDialogProxy proxy) { + super(context, null); + setPersistent(false); + mProxy = proxy; + setSubtype(subtype); + } + + public void show() { + showDialog(null); + } + + public InputMethodSubtype getSubtype() { + return mSubtype; + } + + public void setSubtype(InputMethodSubtype subtype) { + mSubtype = subtype; + if (subtype == null) { + setTitle(null); + setDialogTitle(R.string.add_style); + } else { + final String displayName = SubtypeLocale.getFullDisplayName(subtype); + setTitle(displayName); + setDialogTitle(displayName); + } + } + + @Override + protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { + final Context context = builder.getContext(); + final View v = LayoutInflater.from(context).inflate( + R.layout.additional_subtype_dialog, null); + builder.setView(v); + mSubtypeLocaleSpinner = (Spinner) v.findViewById(R.id.subtype_locale_spinner); + mSubtypeLocaleSpinner.setAdapter(mProxy.getSubtypeLocaleAdapter()); + mKeyboardLayoutSetSpinner = (Spinner) v.findViewById(R.id.keyboard_layout_set_spinner); + mKeyboardLayoutSetSpinner.setAdapter(mProxy.getKeyboardLayoutSetAdapter()); + + if (mSubtype == null) { + builder.setPositiveButton(R.string.add, this) + .setNegativeButton(android.R.string.cancel, this); + } else { + builder.setPositiveButton(R.string.save, this) + .setNeutralButton(android.R.string.cancel, this) + .setNegativeButton(R.string.remove, this); + final SubtypeLocaleItem localeItem = SubtypeLocaleAdapter.createItem( + context, mSubtype.getLocale()); + final KeyboardLayoutSetItem layoutItem = new KeyboardLayoutSetItem( + SubtypeLocale.getKeyboardLayoutSetName(mSubtype)); + setSpinnerPosition(mSubtypeLocaleSpinner, localeItem); + setSpinnerPosition(mKeyboardLayoutSetSpinner, layoutItem); + } + } + + private static void setSpinnerPosition(Spinner spinner, Object itemToSelect) { + final SpinnerAdapter adapter = spinner.getAdapter(); + final int count = adapter.getCount(); + for (int i = 0; i < count; i++) { + final Object item = spinner.getItemAtPosition(i); + if (item.equals(itemToSelect)) { + spinner.setSelection(i); + return; + } + } + } + + @Override + public void onClick(DialogInterface dialog, int which) { + super.onClick(dialog, which); + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + final SubtypeLocaleItem locale = + (SubtypeLocaleItem) mSubtypeLocaleSpinner.getSelectedItem(); + final KeyboardLayoutSetItem layout = + (KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem(); + final InputMethodSubtype subtype = AdditionalSubtype.createAdditionalSubtype( + locale.first, layout.first, LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); + setSubtype(subtype); + notifyChanged(); + break; + case DialogInterface.BUTTON_NEUTRAL: + // Nothing to do + break; + case DialogInterface.BUTTON_NEGATIVE: + mProxy.onRemovePressed(this); + break; + } + } + + @Override + protected Parcelable onSaveInstanceState() { + final SavedState myState = new SavedState(super.onSaveInstanceState()); + myState.mSubtype = mSubtype; + return myState; + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + if (state instanceof SavedState) { + final SavedState myState = (SavedState) state; + super.onRestoreInstanceState(state); + setSubtype(myState.mSubtype); + } else { + super.onRestoreInstanceState(state); + } + } + + static class SavedState extends Preference.BaseSavedState { + InputMethodSubtype mSubtype; + private static final byte VALID = 1; + private static final byte INVALID = 0; + + public SavedState(Parcelable superState) { + super(superState); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + if (mSubtype != null) { + dest.writeByte(VALID); + mSubtype.writeToParcel(dest, 0); + } else { + dest.writeByte(INVALID); + } + } + + public SavedState(Parcel source) { + super(source); + if (source.readByte() == VALID) { + mSubtype = source.readParcelable(null); + } else { + mSubtype = null; + } + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public SavedState createFromParcel(Parcel source) { + return new SavedState(source); + } + + @Override + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; + } + } + + public AdditionalSubtypeSettings() { + // Empty constructor for fragment generation. + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.additional_subtype_settings); + setHasOptionsMenu(true); + mSubtypePrefGroup = getPreferenceScreen(); + + mPrefs = getPreferenceManager().getSharedPreferences(); + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + final Context context = getActivity(); + mSubtypeLocaleAdapter = new SubtypeLocaleAdapter(context); + mKeyboardLayoutSetAdapter = new KeyboardLayoutSetAdapter(context); + + // TODO: Restore editing dialog if any. + } + + private final SubtypeDialogProxy mSubtypeProxy = new SubtypeDialogProxy() { + @Override + public void onRemovePressed(SubtypePreference subtypePref) { + final PreferenceGroup group = mSubtypePrefGroup; + if (group != null) { + group.removePreference(subtypePref); + } + } + + @Override + public SubtypeLocaleAdapter getSubtypeLocaleAdapter() { + return mSubtypeLocaleAdapter; + } + + @Override + public KeyboardLayoutSetAdapter getKeyboardLayoutSetAdapter() { + return mKeyboardLayoutSetAdapter; + } + }; + + private void setPrefSubtypes(String prefSubtypes, Context context) { + final PreferenceGroup group = mSubtypePrefGroup; + group.removeAll(); + final String[] prefSubtypeArray = prefSubtypes.split( + AdditionalSubtype.PREF_SUBTYPE_SEPARATOR); + for (final String prefSubtype : prefSubtypeArray) { + final InputMethodSubtype subtype = + AdditionalSubtype.createAdditionalSubtype(prefSubtype); + final SubtypePreference pref = new SubtypePreference( + context, subtype, mSubtypeProxy); + group.addPreference(pref); + } + } + + private String getPrefSubtypes() { + final StringBuilder sb = new StringBuilder(); + final int count = mSubtypePrefGroup.getPreferenceCount(); + for (int i = 0; i < count; i++) { + final Preference pref = mSubtypePrefGroup.getPreference(i); + if (pref instanceof SubtypePreference) { + final InputMethodSubtype subtype = ((SubtypePreference)pref).getSubtype(); + if (sb.length() > 0) { + sb.append(AdditionalSubtype.PREF_SUBTYPE_SEPARATOR); + } + sb.append(AdditionalSubtype.getPrefSubtype(subtype)); + } + } + return sb.toString(); + } + + @Override + public void onResume() { + super.onResume(); + + final String prefSubtypes = + SettingsValues.getPrefAdditionalSubtypes(mPrefs, getResources()); + setPrefSubtypes(prefSubtypes, getActivity()); + } + + @Override + public void onPause() { + super.onPause(); + final String oldSubtypes = SettingsValues.getPrefAdditionalSubtypes(mPrefs, getResources()); + final String prefSubtypes = getPrefSubtypes(); + if (prefSubtypes.equals(oldSubtypes)) { + return; + } + + final SharedPreferences.Editor editor = mPrefs.edit(); + try { + editor.putString(Settings.PREF_CUSTOM_INPUT_STYLES, prefSubtypes); + } finally { + editor.apply(); + } + final InputMethodSubtype[] subtypes = + AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes); + ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + // TODO: save editing dialog state. + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen prefScreen, Preference pref) { + if (pref instanceof SubtypePreference) { + return true; + } + return super.onPreferenceTreeClick(prefScreen, pref); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + final MenuItem addSubtypeMenu = menu.add(0, MENU_ADD_SUBTYPE, 0, R.string.add_style); + addSubtypeMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + final int itemId = item.getItemId(); + if (itemId == MENU_ADD_SUBTYPE) { + final SubtypePreference subtypePref = new SubtypePreference( + getActivity(), null, mSubtypeProxy); + mSubtypePrefGroup.addPreference(subtypePref); + subtypePref.show(); + return true; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 29825df7d..13264f7e8 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -33,6 +33,7 @@ import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.view.LayoutInflater; import android.view.View; +import android.view.inputmethod.InputMethodSubtype; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; import android.widget.TextView; @@ -255,6 +256,7 @@ public class Settings extends InputMethodSettingsFragment } updateShowCorrectionSuggestionsSummary(); updateKeyPreviewPopupDelaySummary(); + updateCustomInputStylesSummary(); } @Override @@ -294,6 +296,21 @@ public class Settings extends InputMethodSettingsFragment mShowCorrectionSuggestionsPreference.getValue())]); } + private void updateCustomInputStylesSummary() { + final PreferenceScreen customInputStyles = + (PreferenceScreen)findPreference(PREF_CUSTOM_INPUT_STYLES); + final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); + final String prefSubtype = SettingsValues.getPrefAdditionalSubtypes(prefs, getResources()); + final InputMethodSubtype[] subtypes = + AdditionalSubtype.createAdditionalSubtypesArray(prefSubtype); + final StringBuilder styles = new StringBuilder(); + for (final InputMethodSubtype subtype : subtypes) { + if (styles.length() > 0) styles.append(", "); + styles.append(SubtypeLocale.getFullDisplayName(subtype)); + } + customInputStyles.setSummary(styles); + } + private void updateKeyPreviewPopupDelaySummary() { final ListPreference lp = mKeyPreviewPopupDismissDelay; lp.setSummary(lp.getEntries()[lp.findIndexOfValue(lp.getValue())]); diff --git a/java/src/com/android/inputmethod/latin/SettingsActivity.java b/java/src/com/android/inputmethod/latin/SettingsActivity.java index 556701364..68f8582fc 100644 --- a/java/src/com/android/inputmethod/latin/SettingsActivity.java +++ b/java/src/com/android/inputmethod/latin/SettingsActivity.java @@ -20,11 +20,15 @@ import android.content.Intent; import android.preference.PreferenceActivity; public class SettingsActivity extends PreferenceActivity { + private static final String DEFAULT_FRAGMENT = Settings.class.getName(); + @Override public Intent getIntent() { - final Intent modIntent = new Intent(super.getIntent()); - modIntent.putExtra(EXTRA_SHOW_FRAGMENT, Settings.class.getName()); - modIntent.putExtra(EXTRA_NO_HEADERS, true); - return modIntent; + final Intent intent = super.getIntent(); + if (!intent.hasExtra(EXTRA_SHOW_FRAGMENT)) { + intent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT); + } + intent.putExtra(EXTRA_NO_HEADERS, true); + return intent; } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index b83cec462..5f9e1bc76 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,7 +28,6 @@ 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 @@ -148,7 +147,6 @@ public class SettingsValues { mAutoCorrectionThresholdRawValue); mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); - mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( getPrefAdditionalSubtypes(prefs, res)); } diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index 37f46fc79..787e86a79 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.Locale; public class SubtypeLocale { + private static final String TAG = SubtypeLocale.class.getSimpleName(); + // Special language code to represent "no language". public static final String NO_LANGUAGE = "zz"; @@ -56,26 +58,29 @@ public class SubtypeLocale { // 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) + // en_US azerty T En English English (US) (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; - } - if (isNoLanguage(subtype)) { return getKeyboardLayoutSetDisplayName(subtype); } + final String exceptionalValue = sExceptionalDisplayNamesMap.get(subtype.getLocale()); + final Locale locale = getSubtypeLocale(subtype); - final String language = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); if (AdditionalSubtype.isAdditionalSubtype(subtype)) { - return String.format("%s (%s)", - language, getKeyboardLayoutSetDisplayName(subtype)); + final String language = (exceptionalValue != null) ? exceptionalValue + : StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); + final String layout = getKeyboardLayoutSetDisplayName(subtype); + return String.format("%s (%s)", language, layout); } + + if (exceptionalValue != null) { + return exceptionalValue; + } + return StringUtils.toTitleCase(locale.getDisplayName(locale), locale); } @@ -116,7 +121,11 @@ public class SubtypeLocale { LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET); // TODO: Remove this null check when InputMethodManager.getCurrentInputMethodSubtype is // fixed. - if (keyboardLayoutSet == null) return AdditionalSubtype.QWERTY; + if (keyboardLayoutSet == null) { + android.util.Log.w(TAG, "KeyboardLayoutSet not found, use QWERTY: " + + getFullDisplayName(subtype) + " extraValue=" + subtype.getExtraValue()); + return AdditionalSubtype.QWERTY; + } return keyboardLayoutSet; } } diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java index 971fbc21b..b29477057 100644 --- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java +++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java @@ -110,6 +110,7 @@ public class SubtypeLocaleTests extends AndroidTestCase { // zz qwerty F QWERTY QWERTY // fr qwertz T Fr Français Français (QWERTZ) // de qwerty T De Deutsch Deutsch (QWERTY) + // en_US azerty T En English English (US) (AZERTY) // zz azerty T AZERTY AZERTY public void testSampleSubtypes() { @@ -168,29 +169,33 @@ public class SubtypeLocaleTests extends AndroidTestCase { Locale.GERMAN.toString(), AdditionalSubtype.QWERTY, null); final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype( Locale.FRENCH.toString(), AdditionalSubtype.QWERTZ, null); - final InputMethodSubtype EN_AZERTY = AdditionalSubtype.createAdditionalSubtype( - Locale.ENGLISH.toString(), AdditionalSubtype.AZERTY, null); + final InputMethodSubtype US_AZERTY = AdditionalSubtype.createAdditionalSubtype( + Locale.US.toString(), AdditionalSubtype.AZERTY, null); final InputMethodSubtype ZZ_AZERTY = AdditionalSubtype.createAdditionalSubtype( SubtypeLocale.NO_LANGUAGE, AdditionalSubtype.AZERTY, null); assertTrue(AdditionalSubtype.isAdditionalSubtype(FR_QWERTZ)); assertTrue(AdditionalSubtype.isAdditionalSubtype(DE_QWERTY)); - assertTrue(AdditionalSubtype.isAdditionalSubtype(EN_AZERTY)); + assertTrue(AdditionalSubtype.isAdditionalSubtype(US_AZERTY)); assertTrue(AdditionalSubtype.isAdditionalSubtype(ZZ_AZERTY)); - assertEquals("fr qwertz", "Français (QWERTZ)", SubtypeLocale.getFullDisplayName(FR_QWERTZ)); - assertEquals("de qwerty", "Deutsch (QWERTY)", SubtypeLocale.getFullDisplayName(DE_QWERTY)); - assertEquals("en azerty", "English (AZERTY)", SubtypeLocale.getFullDisplayName(EN_AZERTY)); - assertEquals("zz azerty", "AZERTY", SubtypeLocale.getFullDisplayName(ZZ_AZERTY)); - - assertEquals("fr qwertz", "Français", SubtypeLocale.getMiddleDisplayName(FR_QWERTZ)); - assertEquals("de qwerty", "Deutsch", SubtypeLocale.getMiddleDisplayName(DE_QWERTY)); - assertEquals("en azerty", "English", SubtypeLocale.getMiddleDisplayName(EN_AZERTY)); - assertEquals("zz azerty", "AZERTY", SubtypeLocale.getMiddleDisplayName(ZZ_AZERTY)); - - assertEquals("fr qwertz", "Fr", SubtypeLocale.getShortDisplayName(FR_QWERTZ)); - assertEquals("de qwerty", "De", SubtypeLocale.getShortDisplayName(DE_QWERTY)); - assertEquals("en azerty", "En", SubtypeLocale.getShortDisplayName(EN_AZERTY)); - assertEquals("zz azerty", "", SubtypeLocale.getShortDisplayName(ZZ_AZERTY)); + assertEquals("fr qwertz", "Français (QWERTZ)", + SubtypeLocale.getFullDisplayName(FR_QWERTZ)); + assertEquals("de qwerty", "Deutsch (QWERTY)", + SubtypeLocale.getFullDisplayName(DE_QWERTY)); + assertEquals("en_US azerty", "English (US) (AZERTY)", + SubtypeLocale.getFullDisplayName(US_AZERTY)); + assertEquals("zz azerty", "AZERTY", + SubtypeLocale.getFullDisplayName(ZZ_AZERTY)); + + assertEquals("fr qwertz", "Français", SubtypeLocale.getMiddleDisplayName(FR_QWERTZ)); + assertEquals("de qwerty", "Deutsch", SubtypeLocale.getMiddleDisplayName(DE_QWERTY)); + assertEquals("en_US azerty", "English", SubtypeLocale.getMiddleDisplayName(US_AZERTY)); + assertEquals("zz azerty", "AZERTY", SubtypeLocale.getMiddleDisplayName(ZZ_AZERTY)); + + assertEquals("fr qwertz", "Fr", SubtypeLocale.getShortDisplayName(FR_QWERTZ)); + assertEquals("de qwerty", "De", SubtypeLocale.getShortDisplayName(DE_QWERTY)); + assertEquals("en_US azerty", "En", SubtypeLocale.getShortDisplayName(US_AZERTY)); + assertEquals("zz azerty", "", SubtypeLocale.getShortDisplayName(ZZ_AZERTY)); } } -- cgit v1.2.3-83-g751a From 0142b997bf18f5d07e83b3fd403f0b3ea4736040 Mon Sep 17 00:00:00 2001 From: satok Date: Mon, 14 May 2012 14:42:40 +0900 Subject: Do not set "SuggestionSpan"s for suggestions from the next word predicition Bug: 6294817 Change-Id: I5010eafa5ba7e947743706adf7e722f4f0cfb415 --- .../com/android/inputmethod/compat/SuggestionSpanUtils.java | 1 + java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++++-- java/src/com/android/inputmethod/latin/SettingsValues.java | 3 ++- java/src/com/android/inputmethod/latin/Suggest.java | 10 +++++----- java/src/com/android/inputmethod/latin/SuggestedWords.java | 7 +++++-- 5 files changed, 17 insertions(+), 10 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 25afef1e6..a0f48d24c 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -108,6 +108,7 @@ public class SuggestionSpanUtils { if (!dictionaryAvailable || TextUtils.isEmpty(pickedWord) || CONSTRUCTOR_SuggestionSpan == null || suggestedWords == null || suggestedWords.size() == 0 + || suggestedWords.mIsPrediction || suggestedWords.mIsPunctuationSuggestions || OBJ_SUGGESTIONS_MAX_SIZE == null) { return pickedWord; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 011b512e8..fb119da02 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -877,7 +877,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, - false /* isObsoleteSuggestions */); + false /* isObsoleteSuggestions */, + false /* isPrediction */); // When in fullscreen mode, show completions generated by the application final boolean isAutoCorrection = false; setSuggestions(suggestedWords, isAutoCorrection); @@ -1772,7 +1773,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, - true /* isObsoleteSuggestions */); + true /* isObsoleteSuggestions */, + false /* isPrediction */); showSuggestions(obsoleteSuggestedWords, typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 5f9e1bc76..55b896f5a 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -166,7 +166,8 @@ public class SettingsValues { false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */, - false /* isObsoleteSuggestions */); + false /* isObsoleteSuggestions */, + false /* isPrediction */); } private static String createWordSeparators(final String weakSpaceStrippers, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 112bde6a3..845df81f6 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -253,13 +253,12 @@ public class Suggest implements Dictionary.WordCallback { SuggestedWordInfo.removeDups(mSuggestions); return new SuggestedWords(mSuggestions, - // TODO: Just assuming the suggestions that came from the bigram prediction are - // valid now. Need to assign a correct value for typedWordValid. - true /* typedWordValid */, + false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, - false /* isObsoleteSuggestions */); + false /* isObsoleteSuggestions */, + true /* isPrediction */); } // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder @@ -396,7 +395,8 @@ public class Suggest implements Dictionary.WordCallback { autoCorrectionAvailable /* hasAutoCorrectionCandidate */, allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, - false /* isObsoleteSuggestions */); + false /* isObsoleteSuggestions */, + false /* isPrediction */); } /** diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 91110d888..497fd3bfa 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -25,13 +25,14 @@ import java.util.HashSet; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - new ArrayList(0), false, false, false, false, false); + new ArrayList(0), false, false, false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; public final boolean mAllowsToBeAutoCorrected; public final boolean mIsObsoleteSuggestions; + public final boolean mIsPrediction; private final ArrayList mSuggestedWordInfoList; public SuggestedWords(final ArrayList suggestedWordInfoList, @@ -39,13 +40,15 @@ public class SuggestedWords { final boolean hasAutoCorrectionCandidate, final boolean allowsToBeAutoCorrected, final boolean isPunctuationSuggestions, - final boolean isObsoleteSuggestions) { + final boolean isObsoleteSuggestions, + final boolean isPrediction) { mSuggestedWordInfoList = suggestedWordInfoList; mTypedWordValid = typedWordValid; mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mAllowsToBeAutoCorrected = allowsToBeAutoCorrected; mIsPunctuationSuggestions = isPunctuationSuggestions; mIsObsoleteSuggestions = isObsoleteSuggestions; + mIsPrediction = isPrediction; } public int size() { -- cgit v1.2.3-83-g751a From 0028ed3627ff4f37a62a80f3b2c857e373cd5090 Mon Sep 17 00:00:00 2001 From: satok Date: Wed, 16 May 2012 20:42:12 +0900 Subject: Use "float" instead of "double" Change-Id: I93ed4d88ede4058f081dd8d634b00dfff4e96d07 --- .../inputmethod/keyboard/ProximityInfo.java | 3 ++- .../android/inputmethod/latin/AutoCorrection.java | 6 +++--- .../inputmethod/latin/BinaryDictionary.java | 4 ++-- .../android/inputmethod/latin/SettingsValues.java | 10 +++++----- .../src/com/android/inputmethod/latin/Suggest.java | 6 +++--- .../spellcheck/AndroidSpellCheckerService.java | 22 +++++++++++----------- ..._android_inputmethod_latin_BinaryDictionary.cpp | 6 +++--- native/jni/src/correction.cpp | 10 +++++----- native/jni/src/correction.h | 2 +- native/jni/src/defines.h | 10 +++++----- native/jni/src/unigram_dictionary.cpp | 10 +++++----- native/jni/src/words_priority_queue.h | 8 ++++---- 12 files changed, 49 insertions(+), 48 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index 90394ce5e..5ea28abe2 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard; import android.graphics.Rect; import android.text.TextUtils; +import android.util.FloatMath; import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection; import com.android.inputmethod.latin.JniUtils; @@ -147,7 +148,7 @@ public class ProximityInfo { final float radius = touchPositionCorrection.mRadii[row]; sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth; sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight; - sweetSpotRadii[i] = radius * (float) Math.sqrt( + sweetSpotRadii[i] = radius * FloatMath.sqrt( hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight); } } diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index 38444a10c..da1936aef 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -35,7 +35,7 @@ public class AutoCorrection { public static CharSequence computeAutoCorrectionWord( HashMap dictionaries, WordComposer wordComposer, ArrayList suggestions, - CharSequence consideredWord, double autoCorrectionThreshold, + CharSequence consideredWord, float autoCorrectionThreshold, CharSequence whitelistedWord) { if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) { return whitelistedWord; @@ -100,14 +100,14 @@ public class AutoCorrection { private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer, ArrayList suggestions, - CharSequence consideredWord, double autoCorrectionThreshold) { + CharSequence consideredWord, float autoCorrectionThreshold) { if (wordComposer.size() > 1 && suggestions.size() > 0) { final SuggestedWordInfo autoCorrectionSuggestion = suggestions.get(0); //final int autoCorrectionSuggestionScore = sortedScores[0]; final int autoCorrectionSuggestionScore = autoCorrectionSuggestion.mScore; // TODO: when the normalized score of the first suggestion is nearly equals to // the normalized score of the second suggestion, behave less aggressive. - final double normalizedScore = BinaryDictionary.calcNormalizedScore( + final float normalizedScore = BinaryDictionary.calcNormalizedScore( consideredWord.toString(), autoCorrectionSuggestion.mWord.toString(), autoCorrectionSuggestionScore); if (DBG) { diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index cc20f4294..e18aee6ff 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -92,7 +92,7 @@ public class BinaryDictionary extends Dictionary { private native int getBigramsNative(long dict, int[] prevWord, int prevWordLength, int[] inputCodes, int inputCodesLength, char[] outputChars, int[] scores, int maxWordLength, int maxBigrams); - private static native double calcNormalizedScoreNative( + private static native float calcNormalizedScoreNative( char[] before, int beforeLength, char[] after, int afterLength, int score); private static native int editDistanceNative( char[] before, int beforeLength, char[] after, int afterLength); @@ -189,7 +189,7 @@ public class BinaryDictionary extends Dictionary { prevWordCodePointArray, mUseFullEditDistance, outputChars, scores); } - public static double calcNormalizedScore(String before, String after, int score) { + public static float calcNormalizedScore(String before, String after, int score) { return calcNormalizedScoreNative(before.toCharArray(), before.length(), after.toCharArray(), after.length(), score); } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 55b896f5a..932920a60 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -77,7 +77,7 @@ public class SettingsValues { public final float mFxVolume; public final int mKeyPreviewPopupDismissDelay; public final boolean mAutoCorrectEnabled; - public final double mAutoCorrectionThreshold; + public final float mAutoCorrectionThreshold; private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyOnMain; @@ -255,21 +255,21 @@ public class SettingsValues { R.bool.config_default_next_word_prediction)); } - private static double getAutoCorrectionThreshold(final Resources resources, + private static float getAutoCorrectionThreshold(final Resources resources, final String currentAutoCorrectionSetting) { final String[] autoCorrectionThresholdValues = resources.getStringArray( R.array.auto_correction_threshold_values); // When autoCorrectionThreshold is greater than 1.0, it's like auto correction is off. - double autoCorrectionThreshold = Double.MAX_VALUE; + float autoCorrectionThreshold = Float.MAX_VALUE; try { final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting); if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) { - autoCorrectionThreshold = Double.parseDouble( + autoCorrectionThreshold = Float.parseFloat( autoCorrectionThresholdValues[arrayIndex]); } } catch (NumberFormatException e) { // Whenever the threshold settings are correct, never come here. - autoCorrectionThreshold = Double.MAX_VALUE; + autoCorrectionThreshold = Float.MAX_VALUE; Log.w(TAG, "Cannot load auto correction threshold setting." + " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting + ", autoCorrectionThresholdValues: " diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index d7cd0575b..9e478fab4 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -77,7 +77,7 @@ public class Suggest implements Dictionary.WordCallback { private static final int PREF_MAX_BIGRAMS = 60; - private double mAutoCorrectionThreshold; + private float mAutoCorrectionThreshold; private ArrayList mSuggestions = new ArrayList(); private ArrayList mBigramSuggestions = new ArrayList(); @@ -185,7 +185,7 @@ public class Suggest implements Dictionary.WordCallback { userHistoryDictionary); } - public void setAutoCorrectionThreshold(double threshold) { + public void setAutoCorrectionThreshold(float threshold) { mAutoCorrectionThreshold = threshold; } @@ -416,7 +416,7 @@ public class Suggest implements Dictionary.WordCallback { // than i because we added the typed word to mSuggestions without touching mScores. for (int i = 0; i < suggestionsSize - 1; ++i) { final SuggestedWordInfo cur = suggestions.get(i + 1); - final double normalizedScore = BinaryDictionary.calcNormalizedScore( + final float normalizedScore = BinaryDictionary.calcNormalizedScore( typedWord, cur.toString(), cur.mScore); final String scoreInfoString; if (normalizedScore > 0) { diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 0c9f9fb27..d7c8e3850 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -79,9 +79,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService private Dictionary mContactsDictionary; // The threshold for a candidate to be offered as a suggestion. - private double mSuggestionThreshold; + private float mSuggestionThreshold; // The threshold for a suggestion to be considered "recommended". - private double mRecommendedThreshold; + private float mRecommendedThreshold; // Whether to use the contacts dictionary private boolean mUseContactsDictionary; private final Object mUseContactsLock = new Object(); @@ -113,9 +113,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService @Override public void onCreate() { super.onCreate(); mSuggestionThreshold = - Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value)); + Float.parseFloat(getString(R.string.spellchecker_suggestion_threshold_value)); mRecommendedThreshold = - Double.parseDouble(getString(R.string.spellchecker_recommended_threshold_value)); + Float.parseFloat(getString(R.string.spellchecker_recommended_threshold_value)); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY); @@ -207,8 +207,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService private final ArrayList mSuggestions; private final int[] mScores; private final String mOriginalText; - private final double mSuggestionThreshold; - private final double mRecommendedThreshold; + private final float mSuggestionThreshold; + private final float mRecommendedThreshold; private final int mMaxLength; private int mLength = 0; @@ -217,8 +217,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService private String mBestSuggestion = null; private int mBestScore = Integer.MIN_VALUE; // As small as possible - SuggestionsGatherer(final String originalText, final double suggestionThreshold, - final double recommendedThreshold, final int maxLength) { + SuggestionsGatherer(final String originalText, final float suggestionThreshold, + final float recommendedThreshold, final int maxLength) { mOriginalText = originalText; mSuggestionThreshold = suggestionThreshold; mRecommendedThreshold = recommendedThreshold; @@ -261,7 +261,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService // Compute the normalized score and skip this word if it's normalized score does not // make the threshold. final String wordString = new String(word, wordOffset, wordLength); - final double normalizedScore = + final float normalizedScore = BinaryDictionary.calcNormalizedScore(mOriginalText, wordString, score); if (normalizedScore < mSuggestionThreshold) { if (DBG) Log.i(TAG, wordString + " does not make the score threshold"); @@ -295,7 +295,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService hasRecommendedSuggestions = false; } else { gatheredSuggestions = EMPTY_STRING_ARRAY; - final double normalizedScore = BinaryDictionary.calcNormalizedScore( + final float normalizedScore = BinaryDictionary.calcNormalizedScore( mOriginalText, mBestSuggestion, mBestScore); hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold); } @@ -329,7 +329,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService final int bestScore = mScores[mLength - 1]; final CharSequence bestSuggestion = mSuggestions.get(0); - final double normalizedScore = + final float normalizedScore = BinaryDictionary.calcNormalizedScore( mOriginalText, bestSuggestion.toString(), bestScore); hasRecommendedSuggestions = (normalizedScore > mRecommendedThreshold); diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp index b8f4ec77a..0fe4564fb 100644 --- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp +++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp @@ -196,11 +196,11 @@ static jboolean latinime_BinaryDictionary_isValidBigram(JNIEnv *env, jobject obj return result; } -static jdouble latinime_BinaryDictionary_calcNormalizedScore(JNIEnv *env, jobject object, +static jfloat latinime_BinaryDictionary_calcNormalizedScore(JNIEnv *env, jobject object, jcharArray before, jint beforeLength, jcharArray after, jint afterLength, jint score) { jchar *beforeChars = env->GetCharArrayElements(before, 0); jchar *afterChars = env->GetCharArrayElements(after, 0); - jdouble result = Correction::RankingAlgorithm::calcNormalizedScore((unsigned short*)beforeChars, + jfloat result = Correction::RankingAlgorithm::calcNormalizedScore((unsigned short*)beforeChars, beforeLength, (unsigned short*)afterChars, afterLength, score); env->ReleaseCharArrayElements(after, afterChars, JNI_ABORT); env->ReleaseCharArrayElements(before, beforeChars, JNI_ABORT); @@ -255,7 +255,7 @@ static JNINativeMethod sMethods[] = { {"isValidWordNative", "(J[II)Z", (void*)latinime_BinaryDictionary_isValidWord}, {"isValidBigramNative", "(J[I[I)Z", (void*)latinime_BinaryDictionary_isValidBigram}, {"getBigramsNative", "(J[II[II[C[III)I", (void*)latinime_BinaryDictionary_getBigrams}, - {"calcNormalizedScoreNative", "([CI[CII)D", + {"calcNormalizedScoreNative", "([CI[CII)F", (void*)latinime_BinaryDictionary_calcNormalizedScore}, {"editDistanceNative", "([CI[CI)I", (void*)latinime_BinaryDictionary_editDistance} }; diff --git a/native/jni/src/correction.cpp b/native/jni/src/correction.cpp index a1f812909..5ae34cd02 100644 --- a/native/jni/src/correction.cpp +++ b/native/jni/src/correction.cpp @@ -1113,7 +1113,7 @@ int Correction::RankingAlgorithm::editDistance(const unsigned short* before, // So, we can normalize original score by dividing pow(2, min(b.l(),a.l())) * 255 * 2. /* static */ -double Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* before, +float Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* before, const int beforeLength, const unsigned short* after, const int afterLength, const int score) { if (0 == beforeLength || 0 == afterLength) { @@ -1131,14 +1131,14 @@ double Correction::RankingAlgorithm::calcNormalizedScore(const unsigned short* b return 0; } - const double maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE - * pow((double)TYPED_LETTER_MULTIPLIER, - (double)min(beforeLength, afterLength - spaceCount)) * FULL_WORD_MULTIPLIER; + const float maxScore = score >= S_INT_MAX ? S_INT_MAX : MAX_INITIAL_SCORE + * pow((float)TYPED_LETTER_MULTIPLIER, + (float)min(beforeLength, afterLength - spaceCount)) * FULL_WORD_MULTIPLIER; // add a weight based on edit distance. // distance <= max(afterLength, beforeLength) == afterLength, // so, 0 <= distance / afterLength <= 1 - const double weight = 1.0 - (double) distance / afterLength; + const float weight = 1.0 - (float) distance / afterLength; return (score / maxScore) * weight; } diff --git a/native/jni/src/correction.h b/native/jni/src/correction.h index 1b4e4bf4e..1ac4b8782 100644 --- a/native/jni/src/correction.h +++ b/native/jni/src/correction.h @@ -162,7 +162,7 @@ class Correction { static int calcFreqForSplitMultipleWords(const int *freqArray, const int *wordLengthArray, const int wordCount, const Correction* correction, const bool isSpaceProximity, const unsigned short *word); - static double calcNormalizedScore(const unsigned short* before, const int beforeLength, + static float calcNormalizedScore(const unsigned short* before, const int beforeLength, const unsigned short* after, const int afterLength, const int score); static int editDistance(const unsigned short* before, const int beforeLength, const unsigned short* after, const int afterLength); diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h index cb3dbb115..c6ad66abe 100644 --- a/native/jni/src/defines.h +++ b/native/jni/src/defines.h @@ -46,8 +46,8 @@ static inline void dumpWord(const unsigned short* word, const int length) { #include #define PROF_BUF_SIZE 100 -static double profile_buf[PROF_BUF_SIZE]; -static double profile_old[PROF_BUF_SIZE]; +static float profile_buf[PROF_BUF_SIZE]; +static float profile_old[PROF_BUF_SIZE]; static unsigned int profile_counter[PROF_BUF_SIZE]; #define PROF_RESET prof_reset() @@ -74,8 +74,8 @@ static inline void prof_out(void) { AKLOGI("Error: You must call PROF_OPEN before PROF_CLOSE."); } AKLOGI("Total time is %6.3f ms.", - profile_buf[PROF_BUF_SIZE - 1] * 1000 / (double)CLOCKS_PER_SEC); - double all = 0; + profile_buf[PROF_BUF_SIZE - 1] * 1000 / (float)CLOCKS_PER_SEC); + float all = 0; for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) { all += profile_buf[i]; } @@ -84,7 +84,7 @@ static inline void prof_out(void) { if (profile_buf[i] != 0) { AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.", i, (profile_buf[i] * 100 / all), - profile_buf[i] * 1000 / (double)CLOCKS_PER_SEC, profile_counter[i]); + profile_buf[i] * 1000 / (float)CLOCKS_PER_SEC, profile_counter[i]); } } } diff --git a/native/jni/src/unigram_dictionary.cpp b/native/jni/src/unigram_dictionary.cpp index 43fe892be..ee8c49703 100644 --- a/native/jni/src/unigram_dictionary.cpp +++ b/native/jni/src/unigram_dictionary.cpp @@ -202,7 +202,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, PROF_START(20); if (DEBUG_DICT) { - double ns = queuePool->getMasterQueue()->getHighestNormalizedScore( + float ns = queuePool->getMasterQueue()->getHighestNormalizedScore( proximityInfo->getPrimaryInputWord(), codesSize, 0, 0, 0); ns += 0; AKLOGI("Max normalized score = %f", ns); @@ -212,7 +212,7 @@ int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, proximityInfo->getPrimaryInputWord(), codesSize, frequencies, outWords); if (DEBUG_DICT) { - double ns = queuePool->getMasterQueue()->getHighestNormalizedScore( + float ns = queuePool->getMasterQueue()->getHighestNormalizedScore( proximityInfo->getPrimaryInputWord(), codesSize, 0, 0, 0); ns += 0; AKLOGI("Returning %d words", suggestedWordsCount); @@ -255,7 +255,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo, bool hasAutoCorrectionCandidate = false; WordsPriorityQueue* masterQueue = queuePool->getMasterQueue(); if (masterQueue->size() > 0) { - double nsForMaster = masterQueue->getHighestNormalizedScore( + float nsForMaster = masterQueue->getHighestNormalizedScore( proximityInfo->getPrimaryInputWord(), inputLength, 0, 0, 0); hasAutoCorrectionCandidate = (nsForMaster > START_TWO_WORDS_CORRECTION_THRESHOLD); } @@ -284,7 +284,7 @@ void UnigramDictionary::getWordSuggestions(ProximityInfo *proximityInfo, const int score = sw->mScore; const unsigned short* word = sw->mWord; const int wordLength = sw->mWordLength; - double ns = Correction::RankingAlgorithm::calcNormalizedScore( + float ns = Correction::RankingAlgorithm::calcNormalizedScore( proximityInfo->getPrimaryInputWord(), i, word, wordLength, score); ns += 0; AKLOGI("--- TOP SUB WORDS for %d --- %d %f [%d]", i, score, ns, @@ -452,7 +452,7 @@ bool UnigramDictionary::getSubStringSuggestion( return false; } int score = 0; - const double ns = queue->getHighestNormalizedScore( + const float ns = queue->getHighestNormalizedScore( proximityInfo->getPrimaryInputWord(), inputWordLength, &tempOutputWord, &score, &nextWordLength); if (DEBUG_DICT) { diff --git a/native/jni/src/words_priority_queue.h b/native/jni/src/words_priority_queue.h index 1387267a0..7629251d6 100644 --- a/native/jni/src/words_priority_queue.h +++ b/native/jni/src/words_priority_queue.h @@ -112,13 +112,13 @@ class WordsPriorityQueue { if (size >= 2) { SuggestedWord* nsMaxSw = 0; unsigned int maxIndex = 0; - double maxNs = 0; + float maxNs = 0; for (unsigned int i = 0; i < size; ++i) { SuggestedWord* tempSw = swBuffer[i]; if (!tempSw) { continue; } - const double tempNs = getNormalizedScore(tempSw, before, beforeLength, 0, 0, 0); + const float tempNs = getNormalizedScore(tempSw, before, beforeLength, 0, 0, 0); if (tempNs >= maxNs) { maxNs = tempNs; maxIndex = i; @@ -172,7 +172,7 @@ class WordsPriorityQueue { DUMP_WORD(mHighestSuggestedWord->mWord, mHighestSuggestedWord->mWordLength); } - double getHighestNormalizedScore(const unsigned short* before, const int beforeLength, + float getHighestNormalizedScore(const unsigned short* before, const int beforeLength, unsigned short** outWord, int *outScore, int *outLength) { if (!mHighestSuggestedWord) { return 0.0; @@ -199,7 +199,7 @@ class WordsPriorityQueue { return 0; } - static double getNormalizedScore(SuggestedWord* sw, const unsigned short* before, + static float getNormalizedScore(SuggestedWord* sw, const unsigned short* before, const int beforeLength, unsigned short** outWord, int *outScore, int *outLength) { const int score = sw->mScore; unsigned short* word = sw->mWord; -- cgit v1.2.3-83-g751a From fd53b8cc2b78acd7e33f4dc39cfc2faaea92f0f8 Mon Sep 17 00:00:00 2001 From: satok Date: Fri, 18 May 2012 21:28:09 +0900 Subject: Forget user history Bug: 4192129 Change-Id: Ic98398e5383093a1c24373849eadc48fc4d3626f --- .../inputmethod/latin/ContactsDictionary.java | 2 +- .../inputmethod/latin/ExpandableDictionary.java | 136 ++++++++++++++----- .../com/android/inputmethod/latin/LatinIME.java | 3 +- .../com/android/inputmethod/latin/Settings.java | 3 +- .../android/inputmethod/latin/SettingsValues.java | 21 +++ .../inputmethod/latin/UserHistoryDictionary.java | 148 +++++++++++++-------- .../latin/UserHistoryForgettingCurveUtils.java | 82 +++++++++++- java/src/com/android/inputmethod/latin/Utils.java | 38 ++++++ 8 files changed, 333 insertions(+), 100 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/ContactsDictionary.java b/java/src/com/android/inputmethod/latin/ContactsDictionary.java index c9b8d6eb1..cbfbd0ec8 100644 --- a/java/src/com/android/inputmethod/latin/ContactsDictionary.java +++ b/java/src/com/android/inputmethod/latin/ContactsDictionary.java @@ -159,7 +159,7 @@ public class ContactsDictionary extends ExpandableDictionary { super.addWord(word, null /* shortcut */, FREQUENCY_FOR_CONTACTS); if (!TextUtils.isEmpty(prevWord)) { - super.setBigram(prevWord, word, + super.setBigramAndGetFrequency(prevWord, word, FREQUENCY_FOR_CONTACTS_BIGRAM); } prevWord = word; diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index 6c457afd2..358cd4d4d 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -21,6 +21,7 @@ import android.content.Context; import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.ProximityInfo; +import com.android.inputmethod.latin.UserHistoryForgettingCurveUtils.ForgettingCurveParams; import java.util.ArrayList; import java.util.LinkedList; @@ -80,31 +81,73 @@ public class ExpandableDictionary extends Dictionary { } } - private static class NextWord { - public final Node mWord; - private int mFrequency; + protected interface NextWord { + public Node getWordNode(); + public int getFrequency(); + /** FcValue is a bit set */ + public int getFcValue(); + public int notifyTypedAgainAndGetFrequency(); + } - public NextWord(Node word, int frequency) { + private static class NextStaticWord implements NextWord { + public final Node mWord; + private final int mFrequency; + public NextStaticWord(Node word, int frequency) { mWord = word; mFrequency = frequency; } + @Override + public Node getWordNode() { + return mWord; + } + + @Override public int getFrequency() { return mFrequency; } - public int setFrequency(int freq) { - mFrequency = freq; + @Override + public int getFcValue() { return mFrequency; } - public int addFrequency(int add) { - mFrequency += add; - if (mFrequency > BIGRAM_MAX_FREQUENCY) mFrequency = BIGRAM_MAX_FREQUENCY; + @Override + public int notifyTypedAgainAndGetFrequency() { return mFrequency; } } + private static class NextHistoryWord implements NextWord { + public final Node mWord; + public final ForgettingCurveParams mFcp; + + public NextHistoryWord(Node word, ForgettingCurveParams fcp) { + mWord = word; + mFcp = fcp; + } + + @Override + public Node getWordNode() { + return mWord; + } + + @Override + public int getFrequency() { + return mFcp.getFrequency(); + } + + @Override + public int getFcValue() { + return mFcp.getFc(); + } + + @Override + public int notifyTypedAgainAndGetFrequency() { + return mFcp.notifyTypedAgainAndGetFrequency(); + } + } + private NodeArray mRoots; private int[][] mCodes; @@ -183,7 +226,7 @@ public class ExpandableDictionary extends Dictionary { childNode.mShortcutOnly = isShortcutOnly; children.add(childNode); } - if (wordLength == depth + 1) { + if (wordLength == depth + 1 && shortcutTarget != null) { // Terminate this word childNode.mTerminal = true; if (isShortcutOnly) { @@ -221,7 +264,7 @@ public class ExpandableDictionary extends Dictionary { protected final void getWordsInner(final WordComposer codes, final CharSequence prevWordForBigrams, final WordCallback callback, - @SuppressWarnings("unused") final ProximityInfo proximityInfo) { + final ProximityInfo proximityInfo) { mInputLength = codes.size(); if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; final int[] xCoordinates = codes.getXCoordinates(); @@ -265,13 +308,13 @@ public class ExpandableDictionary extends Dictionary { // Refer to addOrSetBigram() about word1.toLowerCase() final Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null); final Node secondWord = searchWord(mRoots, word2, 0, null); - LinkedList bigram = firstWord.mNGrams; + LinkedList bigrams = firstWord.mNGrams; NextWord bigramNode = null; - if (bigram == null || bigram.size() == 0) { + if (bigrams == null || bigrams.size() == 0) { return false; } else { - for (NextWord nw : bigram) { - if (nw.mWord == secondWord) { + for (NextWord nw : bigrams) { + if (nw.getWordNode() == secondWord) { bigramNode = nw; break; } @@ -280,7 +323,7 @@ public class ExpandableDictionary extends Dictionary { if (bigramNode == null) { return false; } - return bigram.remove(bigramNode); + return bigrams.remove(bigramNode); } /** @@ -292,6 +335,23 @@ public class ExpandableDictionary extends Dictionary { return (node == null) ? -1 : node.mFrequency; } + protected NextWord getBigramWord(String word1, String word2) { + // Refer to addOrSetBigram() about word1.toLowerCase() + final Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null); + final Node secondWord = searchWord(mRoots, word2, 0, null); + LinkedList bigrams = firstWord.mNGrams; + if (bigrams == null || bigrams.size() == 0) { + return null; + } else { + for (NextWord nw : bigrams) { + if (nw.getWordNode() == secondWord) { + return nw; + } + } + } + return null; + } + private static int computeSkippedWordFinalFreq(int freq, int snr, int inputLength) { // The computation itself makes sense for >= 2, but the == 2 case returns 0 // anyway so we may as well test against 3 instead and return the constant @@ -445,43 +505,45 @@ public class ExpandableDictionary extends Dictionary { } } - protected int setBigram(String word1, String word2, int frequency) { - return addOrSetBigram(word1, word2, frequency, false); + public int setBigramAndGetFrequency(String word1, String word2, int frequency) { + return setBigramAndGetFrequency(word1, word2, frequency, null /* unused */); } - protected int addBigram(String word1, String word2, int frequency) { - return addOrSetBigram(word1, word2, frequency, true); + public int setBigramAndGetFrequency(String word1, String word2, ForgettingCurveParams fcp) { + return setBigramAndGetFrequency(word1, word2, 0 /* unused */, fcp); } /** * Adds bigrams to the in-memory trie structure that is being used to retrieve any word * @param frequency frequency for this bigram * @param addFrequency if true, it adds to current frequency, else it overwrites the old value - * @return returns the final frequency + * @return returns the final bigram frequency */ - private int addOrSetBigram(String word1, String word2, int frequency, boolean addFrequency) { + private int setBigramAndGetFrequency( + String word1, String word2, int frequency, ForgettingCurveParams fcp) { // We don't want results to be different according to case of the looked up left hand side // word. We do want however to return the correct case for the right hand side. // So we want to squash the case of the left hand side, and preserve that of the right // hand side word. Node firstWord = searchWord(mRoots, word1.toLowerCase(), 0, null); Node secondWord = searchWord(mRoots, word2, 0, null); - LinkedList bigram = firstWord.mNGrams; - if (bigram == null || bigram.size() == 0) { + LinkedList bigrams = firstWord.mNGrams; + if (bigrams == null || bigrams.size() == 0) { firstWord.mNGrams = new LinkedList(); - bigram = firstWord.mNGrams; + bigrams = firstWord.mNGrams; } else { - for (NextWord nw : bigram) { - if (nw.mWord == secondWord) { - if (addFrequency) { - return nw.addFrequency(frequency); - } else { - return nw.setFrequency(frequency); - } + for (NextWord nw : bigrams) { + if (nw.getWordNode() == secondWord) { + return nw.notifyTypedAgainAndGetFrequency(); } } } - firstWord.mNGrams.add(new NextWord(secondWord, frequency)); + if (fcp != null) { + // history + firstWord.mNGrams.add(new NextHistoryWord(secondWord, fcp)); + } else { + firstWord.mNGrams.add(new NextStaticWord(secondWord, frequency)); + } return frequency; } @@ -580,7 +642,7 @@ public class ExpandableDictionary extends Dictionary { Node node; int freq; for (NextWord nextWord : terminalNodes) { - node = nextWord.mWord; + node = nextWord.getWordNode(); freq = nextWord.getFrequency(); int index = BinaryDictionary.MAX_WORD_LENGTH; do { @@ -589,8 +651,10 @@ public class ExpandableDictionary extends Dictionary { node = node.mParent; } while (node != null); - callback.addWord(mLookedUpString, index, BinaryDictionary.MAX_WORD_LENGTH - index, - freq, mDicTypeId, Dictionary.BIGRAM); + if (freq >= 0) { + callback.addWord(mLookedUpString, index, BinaryDictionary.MAX_WORD_LENGTH - index, + freq, mDicTypeId, Dictionary.BIGRAM); + } } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c58549497..e9117e29a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -494,7 +494,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen resetContactsDictionary(oldContactsDictionary); mUserHistoryDictionary = new UserHistoryDictionary( - this, localeStr, Suggest.DIC_USER_HISTORY); + this, localeStr, Suggest.DIC_USER_HISTORY, mPrefs); mSuggest.setUserHistoryDictionary(mUserHistoryDictionary); } @@ -745,7 +745,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); - if (mUserHistoryDictionary != null) mUserHistoryDictionary.flushPendingWrites(); } private void onFinishInputViewInternal(boolean finishingInput) { diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 74c4aea0c..08f3e8456 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -58,6 +58,8 @@ public class Settings extends InputMethodSettingsFragment public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting"; public static final String PREF_MISC_SETTINGS = "misc_settings"; public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; + public static final String PREF_LAST_USER_DICTIONARY_WRITE_TIME = + "last_user_dictionary_write_time"; public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings"; public static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = "pref_suppress_language_switch_key"; @@ -244,7 +246,6 @@ public class Settings extends InputMethodSettingsFragment refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, res); } - @SuppressWarnings("unused") @Override public void onResume() { super.onResume(); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 932920a60..4aae6a85e 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -28,6 +28,8 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; /** * When you call the constructor of this class, you may want to change the current system locale by @@ -351,4 +353,23 @@ public class SettingsValues { // TODO: use mUsabilityStudyMode instead of reading it again here return prefs.getBoolean(Settings.PREF_USABILITY_STUDY_MODE, true); } + + public static long getLastUserHistoryWriteTime( + final SharedPreferences prefs, final String locale) { + final String str = prefs.getString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, ""); + final HashMap map = Utils.localeAndTimeStrToHashMap(str); + if (map.containsKey(locale)) { + return map.get(locale); + } + return 0; + } + + public static void setLastUserHistoryWriteTime( + final SharedPreferences prefs, final String locale) { + final String oldStr = prefs.getString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, ""); + final HashMap map = Utils.localeAndTimeStrToHashMap(oldStr); + map.put(locale, System.currentTimeMillis()); + final String newStr = Utils.localeAndTimeHashMapToStr(map); + prefs.edit().putString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, newStr).apply(); + } } diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java index efafacc8a..fa3d1be11 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.ContentValues; import android.content.Context; +import android.content.SharedPreferences; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; @@ -26,6 +27,8 @@ import android.os.AsyncTask; import android.provider.BaseColumns; import android.util.Log; +import com.android.inputmethod.latin.UserHistoryForgettingCurveUtils.ForgettingCurveParams; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -40,9 +43,6 @@ public class UserHistoryDictionary extends ExpandableDictionary { /** Any pair being typed or picked */ private static final int FREQUENCY_FOR_TYPED = 2; - /** Maximum frequency for all pairs */ - private static final int FREQUENCY_MAX = 127; - /** Maximum number of pairs. Pruning will start when databases goes above this number. */ private static int sMaxHistoryBigrams = 10000; @@ -81,6 +81,7 @@ public class UserHistoryDictionary extends ExpandableDictionary { private HashSet mPendingWrites = new HashSet(); private final Object mPendingWritesLock = new Object(); private static volatile boolean sUpdatingDB = false; + private final SharedPreferences mPrefs; private final static HashMap sDictProjectionMap; @@ -101,12 +102,10 @@ public class UserHistoryDictionary extends ExpandableDictionary { private static class Bigram { public final String mWord1; public final String mWord2; - public final int mFrequency; - Bigram(String word1, String word2, int frequency) { + Bigram(String word1, String word2) { this.mWord1 = word1; this.mWord2 = word2; - this.mFrequency = frequency; } @Override @@ -137,7 +136,8 @@ public class UserHistoryDictionary extends ExpandableDictionary { sDeleteHistoryBigrams = deleteHistoryBigram; } - public UserHistoryDictionary(final Context context, final String locale, final int dicTypeId) { + public UserHistoryDictionary(final Context context, final String locale, final int dicTypeId, + SharedPreferences sp) { super(context, dicTypeId); mLocale = locale; if (sOpenHelper == null) { @@ -146,11 +146,13 @@ public class UserHistoryDictionary extends ExpandableDictionary { if (mLocale != null && mLocale.length() > 1) { loadDictionary(); } + mPrefs = sp; } @Override public void close() { flushPendingWrites(); + SettingsValues.setLastUserHistoryWriteTime(mPrefs, mLocale); // Don't close the database as locale changes will require it to be reopened anyway // Also, the database is written to somewhat frequently, so it needs to be kept alive // throughout the life of the process. @@ -176,25 +178,20 @@ public class UserHistoryDictionary extends ExpandableDictionary { * The second word may not be null (a NullPointerException would be thrown). */ public int addToUserHistory(final String word1, String word2) { - super.addWord(word2, null /* shortcut */, FREQUENCY_FOR_TYPED); + super.addWord(word2, null /* the "shortcut" parameter is null */, FREQUENCY_FOR_TYPED); // Do not insert a word as a bigram of itself if (word2.equals(word1)) { return 0; } - - int freq; + final int freq; if (null == word1) { freq = FREQUENCY_FOR_TYPED; } else { - freq = super.addBigram(word1, word2, FREQUENCY_FOR_TYPED); + freq = super.setBigramAndGetFrequency(word1, word2, new ForgettingCurveParams()); } - if (freq > FREQUENCY_MAX) freq = FREQUENCY_MAX; synchronized (mPendingWritesLock) { - if (freq == FREQUENCY_FOR_TYPED || mPendingWrites.isEmpty()) { - mPendingWrites.add(new Bigram(word1, word2, freq)); - } else { - Bigram bi = new Bigram(word1, word2, freq); - mPendingWrites.remove(bi); + final Bigram bi = new Bigram(word1, word2); + if (!mPendingWrites.contains(bi)) { mPendingWrites.add(bi); } } @@ -203,7 +200,7 @@ public class UserHistoryDictionary extends ExpandableDictionary { } public boolean cancelAddingUserHistory(String word1, String word2) { - final Bigram bi = new Bigram(word1, word2, 0); + final Bigram bi = new Bigram(word1, word2); if (mPendingWrites.contains(bi)) { mPendingWrites.remove(bi); return super.removeBigram(word1, word2); @@ -214,12 +211,12 @@ public class UserHistoryDictionary extends ExpandableDictionary { /** * Schedules a background thread to write any pending words to the database. */ - public void flushPendingWrites() { + private void flushPendingWrites() { synchronized (mPendingWritesLock) { // Nothing pending? Return if (mPendingWrites.isEmpty()) return; // Create a background thread to write the pending entries - new UpdateDbTask(sOpenHelper, mPendingWrites, mLocale).execute(); + new UpdateDbTask(sOpenHelper, mPendingWrites, mLocale, this).execute(); // Create a new map for writing new entries into while the old one is written to db mPendingWrites = new HashSet(); } @@ -240,25 +237,30 @@ public class UserHistoryDictionary extends ExpandableDictionary { @Override public void loadDictionaryAsync() { + final long last = SettingsValues.getLastUserHistoryWriteTime(mPrefs, mLocale); + final long now = System.currentTimeMillis(); // Load the words that correspond to the current input locale final Cursor cursor = query(MAIN_COLUMN_LOCALE + "=?", new String[] { mLocale }); if (null == cursor) return; try { if (cursor.moveToFirst()) { - int word1Index = cursor.getColumnIndex(MAIN_COLUMN_WORD1); - int word2Index = cursor.getColumnIndex(MAIN_COLUMN_WORD2); - int frequencyIndex = cursor.getColumnIndex(FREQ_COLUMN_FREQUENCY); + final int word1Index = cursor.getColumnIndex(MAIN_COLUMN_WORD1); + final int word2Index = cursor.getColumnIndex(MAIN_COLUMN_WORD2); + final int frequencyIndex = cursor.getColumnIndex(FREQ_COLUMN_FREQUENCY); while (!cursor.isAfterLast()) { - String word1 = cursor.getString(word1Index); - String word2 = cursor.getString(word2Index); - int frequency = cursor.getInt(frequencyIndex); + final String word1 = cursor.getString(word1Index); + final String word2 = cursor.getString(word2Index); + final int frequency = cursor.getInt(frequencyIndex); // Safeguard against adding really long words. Stack may overflow due // to recursive lookup if (null == word1) { super.addWord(word2, null /* shortcut */, frequency); } else if (word1.length() < BinaryDictionary.MAX_WORD_LENGTH && word2.length() < BinaryDictionary.MAX_WORD_LENGTH) { - super.setBigram(word1, word2, frequency); + super.setBigramAndGetFrequency( + word1, word2, new ForgettingCurveParams(frequency, now, last)); + // TODO: optimize + mPendingWrites.add(new Bigram(word1, word2)); } cursor.moveToNext(); } @@ -340,12 +342,14 @@ public class UserHistoryDictionary extends ExpandableDictionary { private final HashSet mMap; private final DatabaseHelper mDbHelper; private final String mLocale; + private final UserHistoryDictionary mUserHistoryDictionary; public UpdateDbTask(DatabaseHelper openHelper, HashSet pendingWrites, - String locale) { + String locale, UserHistoryDictionary dict) { mMap = pendingWrites; mLocale = locale; mDbHelper = openHelper; + mUserHistoryDictionary = dict; } /** Prune any old data if the database is getting too big. */ @@ -357,7 +361,8 @@ public class UserHistoryDictionary extends ExpandableDictionary { int totalRowCount = c.getCount(); // prune out old data if we have too much data if (totalRowCount > sMaxHistoryBigrams) { - int numDeleteRows = (totalRowCount - sMaxHistoryBigrams) + sDeleteHistoryBigrams; + int numDeleteRows = (totalRowCount - sMaxHistoryBigrams) + + sDeleteHistoryBigrams; int pairIdColumnId = c.getColumnIndex(FREQ_COLUMN_PAIR_ID); c.moveToFirst(); int count = 0; @@ -397,43 +402,70 @@ public class UserHistoryDictionary extends ExpandableDictionary { } db.execSQL("PRAGMA foreign_keys = ON;"); // Write all the entries to the db - Iterator iterator = mMap.iterator(); + final Iterator iterator = mMap.iterator(); while (iterator.hasNext()) { // TODO: this process of making a text search for each pair each time // is terribly inefficient. Optimize this. - Bigram bi = iterator.next(); + final Bigram bi = iterator.next(); // find pair id - final Cursor c; - if (null != bi.mWord1) { - c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, - MAIN_COLUMN_WORD1 + "=? AND " + MAIN_COLUMN_WORD2 + "=? AND " - + MAIN_COLUMN_LOCALE + "=?", - new String[] { bi.mWord1, bi.mWord2, mLocale }, null, null, null); - } else { - c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, - MAIN_COLUMN_WORD1 + " IS NULL AND " + MAIN_COLUMN_WORD2 + "=? AND " - + MAIN_COLUMN_LOCALE + "=?", - new String[] { bi.mWord2, mLocale }, null, null, null); - } + Cursor c = null; + try { + if (null != bi.mWord1) { + c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, + MAIN_COLUMN_WORD1 + "=? AND " + MAIN_COLUMN_WORD2 + "=? AND " + + MAIN_COLUMN_LOCALE + "=?", + new String[] { bi.mWord1, bi.mWord2, mLocale }, null, null, + null); + } else { + c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, + MAIN_COLUMN_WORD1 + " IS NULL AND " + MAIN_COLUMN_WORD2 + "=? AND " + + MAIN_COLUMN_LOCALE + "=?", + new String[] { bi.mWord2, mLocale }, null, null, null); + } - int pairId; - if (c.moveToFirst()) { - // existing pair - pairId = c.getInt(c.getColumnIndex(MAIN_COLUMN_ID)); - db.delete(FREQ_TABLE_NAME, FREQ_COLUMN_PAIR_ID + "=?", - new String[] { Integer.toString(pairId) }); - } else { - // new pair - Long pairIdLong = db.insert(MAIN_TABLE_NAME, null, - getContentValues(bi.mWord1, bi.mWord2, mLocale)); - pairId = pairIdLong.intValue(); + final int pairId; + if (c.moveToFirst()) { + // existing pair + pairId = c.getInt(c.getColumnIndex(MAIN_COLUMN_ID)); + db.delete(FREQ_TABLE_NAME, FREQ_COLUMN_PAIR_ID + "=?", + new String[] { Integer.toString(pairId) }); + } else { + // new pair + Long pairIdLong = db.insert(MAIN_TABLE_NAME, null, + getContentValues(bi.mWord1, bi.mWord2, mLocale)); + pairId = pairIdLong.intValue(); + } + // insert new frequency + final int freq; + if (bi.mWord1 == null) { + freq = FREQUENCY_FOR_TYPED; + } else { + final NextWord nw = mUserHistoryDictionary.getBigramWord( + bi.mWord1, bi.mWord2); + if (nw != null) { + final int tempFreq = nw.getFcValue(); + // TODO: Check whether the word is valid or not + if (UserHistoryForgettingCurveUtils.needsToSave( + (byte)tempFreq, false)) { + freq = tempFreq; + } else { + freq = -1; + } + } else { + freq = -1; + } + } + if (freq > 0) { + db.insert(FREQ_TABLE_NAME, null, getFrequencyContentValues(pairId, freq)); + } + } finally { + if (c != null) { + c.close(); + } } - c.close(); - - // insert new frequency - db.insert(FREQ_TABLE_NAME, null, getFrequencyContentValues(pairId, bi.mFrequency)); } + checkPruneData(db); sUpdatingDB = false; diff --git a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java index eb3881726..f30fee23e 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java @@ -16,14 +16,78 @@ package com.android.inputmethod.latin; +import android.text.format.DateUtils; +import android.util.Log; + public class UserHistoryForgettingCurveUtils { + private static final String TAG = UserHistoryForgettingCurveUtils.class.getSimpleName(); + private static final boolean DEBUG = false; private static final int FC_FREQ_MAX = 127; /* package */ static final int COUNT_MAX = 3; private static final int FC_LEVEL_MAX = 3; /* package */ static final int ELAPSED_TIME_MAX = 15; private static final int ELAPSED_TIME_INTERVAL_HOURS = 6; + private static final long ELAPSED_TIME_INTERVAL_MILLIS = ELAPSED_TIME_INTERVAL_HOURS + * DateUtils.HOUR_IN_MILLIS; private static final int HALF_LIFE_HOURS = 48; + private UserHistoryForgettingCurveUtils() { + // This utility class is not publicly instantiable. + } + + public static class ForgettingCurveParams { + private byte mFc; + long mLastTouchedTime = 0; + + private void updateLastTouchedTime() { + mLastTouchedTime = System.currentTimeMillis(); + } + + public ForgettingCurveParams() { + // TODO: Check whether this word is valid or not + this(System.currentTimeMillis()); + } + + private ForgettingCurveParams(long now) { + this((int)pushCount((byte)0, false), now, now); + } + + public ForgettingCurveParams(int fc, long now, long last) { + mFc = (byte)fc; + mLastTouchedTime = last; + updateElapsedTime(now); + } + + public byte getFc() { + updateElapsedTime(System.currentTimeMillis()); + return mFc; + } + + public int getFrequency() { + updateElapsedTime(System.currentTimeMillis()); + return UserHistoryForgettingCurveUtils.fcToFreq(mFc); + } + + public int notifyTypedAgainAndGetFrequency() { + updateLastTouchedTime(); + // TODO: Check whether this word is valid or not + mFc = pushCount(mFc, false); + return UserHistoryForgettingCurveUtils.fcToFreq(mFc); + } + + private void updateElapsedTime(long now) { + final int elapsedTimeCount = + (int)((now - mLastTouchedTime) / ELAPSED_TIME_INTERVAL_MILLIS); + if (elapsedTimeCount <= 0) { + return; + } + for (int i = 0; i < elapsedTimeCount; ++i) { + mLastTouchedTime += ELAPSED_TIME_INTERVAL_MILLIS; + mFc = pushElapsedTime(mFc); + } + } + } + /* package */ static int fcToElapsedTime(byte fc) { return fc & 0x0F; } @@ -38,8 +102,8 @@ public class UserHistoryForgettingCurveUtils { private static int calcFreq(int elapsedTime, int count, int level) { if (level <= 0) { - // Reserved words, just return 0 - return 0; + // Reserved words, just return -1 + return -1; } if (count == COUNT_MAX) { // Temporary promote because it's frequently typed recently @@ -87,12 +151,26 @@ public class UserHistoryForgettingCurveUtils { // Upgrade level ++level; count = 0; + if (DEBUG) { + Log.d(TAG, "Upgrade level."); + } } else { ++count; } return calcFc(0, count, level); } + // TODO: isValid should be false for a word whose frequency is 0, + // or that is not in the dictionary. + public static boolean needsToSave(byte fc, boolean isValid) { + int level = fcToLevel(fc); + if (isValid && level == 0) { + return false; + } + final int elapsedTime = fcToElapsedTime(fc); + return (elapsedTime < ELAPSED_TIME_MAX - 1 || level > 0); + } + private static class MathUtils { public static final int[][] SCORE_TABLE = new int[FC_LEVEL_MAX][ELAPSED_TIME_MAX + 1]; static { diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 036ff74b8..91996674b 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -44,8 +44,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; +import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.Map; public class Utils { private Utils() { @@ -484,4 +486,40 @@ public class Utils { } return sDeviceOverrideValueMap.get(key); } + + private static final HashMap EMPTY_LT_HASH_MAP = new HashMap(); + private static final String LOCALE_AND_TIME_STR_SEPARATER = ","; + public static HashMap localeAndTimeStrToHashMap(String str) { + if (TextUtils.isEmpty(str)) { + return EMPTY_LT_HASH_MAP; + } + final String[] ss = str.split(LOCALE_AND_TIME_STR_SEPARATER); + final int N = ss.length; + if (N < 2 || N % 2 != 0) { + return EMPTY_LT_HASH_MAP; + } + final HashMap retval = new HashMap(); + for (int i = 0; i < N / 2; ++i) { + final String localeStr = ss[i]; + final long time = Long.valueOf(ss[i + 1]); + retval.put(localeStr, time); + } + return retval; + } + + public static String localeAndTimeHashMapToStr(HashMap map) { + if (map == null || map.isEmpty()) { + return ""; + } + final StringBuilder builder = new StringBuilder(); + for (String localeStr : map.keySet()) { + if (builder.length() > 0) { + builder.append(LOCALE_AND_TIME_STR_SEPARATER); + } + final Long time = map.get(localeStr); + builder.append(localeStr).append(LOCALE_AND_TIME_STR_SEPARATER); + builder.append(String.valueOf(time)); + } + return builder.toString(); + } } -- cgit v1.2.3-83-g751a From 7214617622fce8f3fea6620e782c16336260a2a3 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 16:00:02 +0900 Subject: Remove a slew of Eclipse warnings. Change-Id: I03236386aea13fbd4fb8eaeee18e0008aa136502 --- java/src/com/android/inputmethod/keyboard/KeyboardView.java | 1 + java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java | 2 -- java/src/com/android/inputmethod/latin/ExpandableDictionary.java | 4 +++- java/src/com/android/inputmethod/latin/LatinIME.java | 1 + java/src/com/android/inputmethod/latin/ResearchLogger.java | 4 ++-- java/src/com/android/inputmethod/latin/SettingsValues.java | 1 - java/src/com/android/inputmethod/latin/UserHistoryDictionary.java | 2 +- .../android/inputmethod/latin/UserHistoryForgettingCurveUtils.java | 4 ++-- java/src/com/android/inputmethod/latin/Utils.java | 2 -- .../com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 51a0f537f..18e01fb49 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -873,6 +873,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacer, 0, 0)); } + @SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16 @Override public void showKeyPreview(PointerTracker tracker) { if (!mShowKeyPreviewPopup) return; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index 5aa9a0887..4ab6832c3 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -21,8 +21,6 @@ import android.util.Log; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.Constants; -import com.android.inputmethod.latin.ResearchLogger; -import com.android.inputmethod.latin.define.ProductionFlag; /** * Keyboard state machine. diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index 34a92fd30..4a5471c85 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -514,8 +514,10 @@ public class ExpandableDictionary extends Dictionary { /** * Adds bigrams to the in-memory trie structure that is being used to retrieve any word + * @param word1 the first word of this bigram + * @param word2 the second word of this bigram * @param frequency frequency for this bigram - * @param addFrequency if true, it adds to current frequency, else it overwrites the old value + * @param fcp an instance of ForgettingCurveParams to use for decay policy * @return returns the final bigram frequency */ private int setBigramAndGetFrequency( diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index ae9e197a1..f5025e54a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -747,6 +747,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } + @Override public void onTargetApplicationKnown(final ApplicationInfo info) { mTargetApplicationInfo = info; } diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index bb003f766..a7e7738d8 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -101,13 +101,13 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private static class NullOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public void write(byte[] buffer, int offset, int count) throws IOException { + public void write(byte[] buffer, int offset, int count) { // nop } /** {@inheritDoc} */ @Override - public void write(byte[] buffer) throws IOException { + public void write(byte[] buffer) { // nop } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 4aae6a85e..dfe207cf2 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -29,7 +29,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Map; /** * When you call the constructor of this class, you may want to change the current system locale by diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java index 9c54e0b81..10f92d29e 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java @@ -440,7 +440,7 @@ public class UserHistoryDictionary extends ExpandableDictionary { if (nw != null) { final ForgettingCurveParams fcp = nw.getFcParams(); final byte prevFc = word1Bigrams.get(word2); - final byte fc = (byte)fcp.getFc(); + final byte fc = fcp.getFc(); final boolean isValid = fcp.isValid(); if (prevFc > 0 && prevFc == fc) { // No need to update since we found no changes for this entry. diff --git a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java index e5516dc62..3ae1bd336 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java @@ -50,7 +50,7 @@ public class UserHistoryForgettingCurveUtils { } private ForgettingCurveParams(long now, boolean isValid) { - this((int)pushCount((byte)0, isValid), now, now, isValid); + this(pushCount((byte)0, isValid), now, now, isValid); } /** This constructor is called when the user history bigram dictionary is being restored. */ @@ -201,7 +201,7 @@ public class UserHistoryForgettingCurveUtils { for (int i = 0; i < FC_LEVEL_MAX; ++i) { final double initialFreq; if (i >= 2) { - initialFreq = (double)FC_FREQ_MAX; + initialFreq = FC_FREQ_MAX; } else if (i == 1) { initialFreq = (double)FC_FREQ_MAX / 2; } else if (i == 0) { diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 4178955bc..903b5a357 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -44,10 +44,8 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; -import java.util.Collections; import java.util.Date; import java.util.HashMap; -import java.util.Map; public class Utils { private Utils() { diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java index 89c59f809..0c5d41a5c 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java @@ -788,7 +788,7 @@ public class BinaryDictInputOutput { // which is the best approximation. This is how we get the most precise result with // only four bits. final double stepSize = - (double)(MAX_TERMINAL_FREQUENCY - unigramFrequency) / (1.5 + MAX_BIGRAM_FREQUENCY); + (MAX_TERMINAL_FREQUENCY - unigramFrequency) / (1.5 + MAX_BIGRAM_FREQUENCY); final double firstStepStart = 1 + unigramFrequency + (stepSize / 2.0); final int discretizedFrequency = (int)((bigramFrequency - firstStepStart) / stepSize); // If the bigram freq is less than half-a-step higher than the unigram freq, we get -1 -- cgit v1.2.3-83-g751a From 4b9e6ee6fb408e2793e9ead5de2d6b45270d1f0d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 21:10:35 +0900 Subject: Move the correction mode to SettingsValue and make it final At last this guy is final, at last Change-Id: I76911f8d47493f8a1719f75fc7e949be5d7da1a2 --- .../com/android/inputmethod/latin/LatinIME.java | 30 ++++++++-------------- .../android/inputmethod/latin/SettingsValues.java | 12 ++++++++- 2 files changed, 21 insertions(+), 21 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f2e3098a0..339c68b55 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -163,8 +163,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private WordComposer mWordComposer = new WordComposer(); private RichInputConnection mConnection = new RichInputConnection(); - private int mCorrectionMode; - // Keep track of the last selection range to decide if we need to show word alternatives private static final int NOT_A_CURSOR_POSITION = -1; private int mLastSelectionStart = NOT_A_CURSOR_POSITION; @@ -448,11 +446,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final RunInLocale job = new RunInLocale() { @Override protected SettingsValues job(Resources res) { - return new SettingsValues(mPrefs, LatinIME.this); + return new SettingsValues(mPrefs, mInputAttributes, LatinIME.this); } }; mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale()); - updateCorrectionMode(); mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } @@ -1092,7 +1089,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private boolean maybeDoubleSpace() { - if (mCorrectionMode == Suggest.CORRECTION_NONE) return false; + if (mSettingsValues.mCorrectionMode == Suggest.CORRECTION_NONE) return false; final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 && canBeFollowedByPeriod(lastThree.charAt(0)) @@ -1644,8 +1641,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public boolean isSuggestionsRequested() { + // TODO: move this method to mSettingsValues return mInputAttributes.mIsSettingsSuggestionStripOn - && (mCorrectionMode > 0 || isShowingSuggestionsStrip()); + && (mSettingsValues.mCorrectionMode > 0 || isShowingSuggestionsStrip()); } public boolean isShowingPunctuationList() { @@ -1738,7 +1736,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final CharSequence typedWord = mWordComposer.getTypedWord(); // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, - prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCorrectionMode); + prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), + mSettingsValues.mCorrectionMode); // Basically, we update the suggestion strip only when suggestion count > 1. However, // there is an exception: We update the suggestion strip whenever typed word's length @@ -1962,7 +1961,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } final SuggestedWords suggestedWords; - if (mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) { + if (mSettingsValues.mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) { final CharSequence prevWord = mConnection.getThisWord(mSettingsValues.mWordSeparators); if (!TextUtils.isEmpty(prevWord)) { suggestedWords = mSuggest.getBigramPredictions(prevWord); @@ -1994,8 +1993,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be // adding words in situations where the user or application really didn't // want corrections enabled or learned. - if (!(mCorrectionMode == Suggest.CORRECTION_FULL - || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) { + if (!(mSettingsValues.mCorrectionMode == Suggest.CORRECTION_FULL + || mSettingsValues.mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) { return null; } @@ -2260,15 +2259,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } }; - private void updateCorrectionMode() { - // TODO: cleanup messy flags - final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled - && !mInputAttributes.mInputTypeNoAutoCorrect; - mCorrectionMode = shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; - mCorrectionMode = (mSettingsValues.mBigramSuggestionEnabled && shouldAutoCorrect) - ? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode; - } - private void updateSuggestionVisibility(final Resources res) { final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting; for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { @@ -2356,7 +2346,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; p.println(" Keyboard mode = " + keyboardMode); p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn); - p.println(" mCorrectionMode=" + mCorrectionMode); + p.println(" mCorrectionMode=" + mSettingsValues.mCorrectionMode); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled); p.println(" mSoundOn=" + mSettingsValues.mSoundOn); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index dfe207cf2..0f522f20f 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -79,10 +79,12 @@ public class SettingsValues { public final int mKeyPreviewPopupDismissDelay; public final boolean mAutoCorrectEnabled; public final float mAutoCorrectionThreshold; + public final int mCorrectionMode; private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyOnMain; - public SettingsValues(final SharedPreferences prefs, final Context context) { + public SettingsValues(final SharedPreferences prefs, final InputAttributes inputAttributes, + final Context context) { final Resources res = context.getResources(); // Get the resources @@ -150,6 +152,7 @@ public class SettingsValues { mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( getPrefAdditionalSubtypes(prefs, res)); + mCorrectionMode = createCorrectionMode(inputAttributes); } // Helper functions to create member values. @@ -183,6 +186,13 @@ public class SettingsValues { return wordSeparators; } + private int createCorrectionMode(final InputAttributes inputAttributes) { + final boolean shouldAutoCorrect = mAutoCorrectEnabled + && !inputAttributes.mInputTypeNoAutoCorrect; + if (mBigramSuggestionEnabled && shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM; + return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; + } + private static boolean isVibrateOn(final Context context, final SharedPreferences prefs, final Resources res) { final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator(); -- cgit v1.2.3-83-g751a From 01e3b014bb97e649ff4cf5a58ce8285f7d800cc8 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 21:15:33 +0900 Subject: Accept a null input attributes for reading settings. Change-Id: I11a8e1aca3541c35d2b39b27716687fcd8ff3dc6 --- java/src/com/android/inputmethod/latin/LatinIME.java | 2 -- java/src/com/android/inputmethod/latin/SettingsValues.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 339c68b55..5b7d6584e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -400,8 +400,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final Resources res = getResources(); mResources = res; - // TODO: remove the following when it's not needed by updateCorrectionMode() any more - mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); loadSettings(); ImfUtils.setAdditionalInputMethodSubtypes(this, mSettingsValues.getAdditionalSubtypes()); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 0f522f20f..fb3c03963 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -188,7 +188,7 @@ public class SettingsValues { private int createCorrectionMode(final InputAttributes inputAttributes) { final boolean shouldAutoCorrect = mAutoCorrectEnabled - && !inputAttributes.mInputTypeNoAutoCorrect; + && (null == inputAttributes || !inputAttributes.mInputTypeNoAutoCorrect); if (mBigramSuggestionEnabled && shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM; return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; } -- cgit v1.2.3-83-g751a From d2736972598eda61a8e40a3d5b26156136e78d66 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 21:26:25 +0900 Subject: Move suggestion strip visibility to SettingsValues Change-Id: If34112c69acd5122d87554043d87d8f4dbdf5d15 --- .../com/android/inputmethod/latin/LatinIME.java | 30 +------------------- .../android/inputmethod/latin/SettingsValues.java | 32 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 29 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5b7d6584e..22445a4c6 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -102,21 +102,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ private static final String SCHEME_PACKAGE = "package"; - // TODO: migrate this to SettingsValues - private int mSuggestionVisibility; - private static final int SUGGESTION_VISIBILITY_SHOW_VALUE - = R.string.prefs_suggestion_visibility_show_value; - private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE - = R.string.prefs_suggestion_visibility_show_only_portrait_value; - private static final int SUGGESTION_VISIBILITY_HIDE_VALUE - = R.string.prefs_suggestion_visibility_hide_value; - - private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] { - SUGGESTION_VISIBILITY_SHOW_VALUE, - SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE, - SUGGESTION_VISIBILITY_HIDE_VALUE - }; - private static final int SPACE_STATE_NONE = 0; // Double space: the state where the user pressed space twice quickly, which LatinIME // resolved as period-space. Undoing this converts the period to a space. @@ -694,7 +679,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSpaceState = SPACE_STATE_NONE; loadSettings(); - updateSuggestionVisibility(mResources); if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); @@ -1650,9 +1634,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public boolean isShowingSuggestionsStrip() { - return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE) - || (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE - && mDisplayOrientation == Configuration.ORIENTATION_PORTRAIT); + return mSettingsValues.isSuggestionStripVisibleInOrientation(mDisplayOrientation); } public boolean isSuggestionsStripVisible() { @@ -2257,16 +2239,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } }; - private void updateSuggestionVisibility(final Resources res) { - final String suggestionVisiblityStr = mSettingsValues.mShowSuggestionsSetting; - for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { - if (suggestionVisiblityStr.equals(res.getString(visibility))) { - mSuggestionVisibility = visibility; - break; - } - } - } - private void launchSettings() { launchSettingsClass(SettingsActivity.class); } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index fb3c03963..9985d2fb1 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.content.res.Resources; import android.util.Log; import android.view.inputmethod.EditorInfo; @@ -37,6 +38,19 @@ import java.util.HashMap; public class SettingsValues { private static final String TAG = SettingsValues.class.getSimpleName(); + private static final int SUGGESTION_VISIBILITY_SHOW_VALUE + = R.string.prefs_suggestion_visibility_show_value; + private static final int SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE + = R.string.prefs_suggestion_visibility_show_only_portrait_value; + private static final int SUGGESTION_VISIBILITY_HIDE_VALUE + = R.string.prefs_suggestion_visibility_hide_value; + + private static final int[] SUGGESTION_VISIBILITY_VALUE_ARRAY = new int[] { + SUGGESTION_VISIBILITY_SHOW_VALUE, + SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE, + SUGGESTION_VISIBILITY_HIDE_VALUE + }; + // From resources: public final int mDelayUpdateOldSuggestions; public final String mWeakSpaceStrippers; @@ -80,6 +94,7 @@ public class SettingsValues { public final boolean mAutoCorrectEnabled; public final float mAutoCorrectionThreshold; public final int mCorrectionMode; + public final int mSuggestionVisibility; private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyOnMain; @@ -153,6 +168,7 @@ public class SettingsValues { mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( getPrefAdditionalSubtypes(prefs, res)); mCorrectionMode = createCorrectionMode(inputAttributes); + mSuggestionVisibility = createSuggestionVisibility(res); } // Helper functions to create member values. @@ -193,6 +209,16 @@ public class SettingsValues { return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; } + private int createSuggestionVisibility(final Resources res) { + final String suggestionVisiblityStr = mShowSuggestionsSetting; + for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { + if (suggestionVisiblityStr.equals(res.getString(visibility))) { + return visibility; + } + } + throw new RuntimeException("Bug: visibility string is not configured correctly"); + } + private static boolean isVibrateOn(final Context context, final SharedPreferences prefs, final Resources res) { final boolean hasVibrator = VibratorUtils.getInstance(context).hasVibrator(); @@ -200,6 +226,12 @@ public class SettingsValues { res.getBoolean(R.bool.config_default_vibration_enabled)); } + public boolean isSuggestionStripVisibleInOrientation(final int orientation) { + return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE) + || (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE + && orientation == Configuration.ORIENTATION_PORTRAIT); + } + public boolean isWordSeparator(int code) { return mWordSeparators.contains(String.valueOf((char)code)); } -- cgit v1.2.3-83-g751a From 2010aad741bc1a7266913bcb8b8348d6e401c95b Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 21:56:44 +0900 Subject: Move two methods in a more appropriate place Change-Id: I512b04e23490413a44b1ca0517102fe2d9138df3 --- .../com/android/inputmethod/latin/LatinIME.java | 33 ++-------------------- .../inputmethod/latin/RichInputConnection.java | 26 +++++++++++++++++ .../android/inputmethod/latin/SettingsValues.java | 5 ++++ 3 files changed, 33 insertions(+), 31 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index da091dd05..94e0ac836 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1401,7 +1401,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } } else if (SPACE_STATE_SWAP_PUNCTUATION == spaceState) { - if (revertSwapPunctuation()) { + if (mConnection.revertSwapPunctuation()) { // Likewise return; } @@ -1975,10 +1975,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be // adding words in situations where the user or application really didn't // want corrections enabled or learned. - if (!(mCurrentSettings.mCorrectionMode == Suggest.CORRECTION_FULL - || mCurrentSettings.mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM)) { - return null; - } + if (!mCurrentSettings.isCorrectionOn()) return null; if (mUserHistoryDictionary != null) { final CharSequence prevWord @@ -2075,32 +2072,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.postUpdateSuggestions(); } - private boolean revertSwapPunctuation() { - // Here we test whether we indeed have a space and something else before us. This should not - // be needed, but it's there just in case something went wrong. - final CharSequence textBeforeCursor = mConnection.getTextBeforeCursor(2, 0); - // NOTE: This does not work with surrogate pairs. Hopefully when the keyboard is able to - // enter surrogate pairs this code will have been removed. - if (TextUtils.isEmpty(textBeforeCursor) - || (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1))) { - // We may only come here if the application is changing the text while we are typing. - // This is quite a broken case, but not logically impossible, so we shouldn't crash, - // but some debugging log may be in order. - Log.d(TAG, "Tried to revert a swap of punctuation but we didn't " - + "find a space just before the cursor."); - return false; - } - mConnection.deleteSurroundingText(2, 0); - if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_deleteSurroundingText(2); - } - mConnection.commitText(" " + textBeforeCursor.subSequence(0, 1), 1); - if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_revertSwapPunctuation(); - } - return true; - } - public boolean isWordSeparator(int code) { return mCurrentSettings.isWordSeparator(code); } diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index 5ca4a84b9..227990acc 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -393,4 +393,30 @@ public class RichInputConnection { } return true; } + + public boolean revertSwapPunctuation() { + // Here we test whether we indeed have a space and something else before us. This should not + // be needed, but it's there just in case something went wrong. + final CharSequence textBeforeCursor = getTextBeforeCursor(2, 0); + // NOTE: This does not work with surrogate pairs. Hopefully when the keyboard is able to + // enter surrogate pairs this code will have been removed. + if (TextUtils.isEmpty(textBeforeCursor) + || (Keyboard.CODE_SPACE != textBeforeCursor.charAt(1))) { + // We may only come here if the application is changing the text while we are typing. + // This is quite a broken case, but not logically impossible, so we shouldn't crash, + // but some debugging log may be in order. + Log.d(TAG, "Tried to revert a swap of punctuation but we didn't " + + "find a space just before the cursor."); + return false; + } + deleteSurroundingText(2, 0); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_deleteSurroundingText(2); + } + commitText(" " + textBeforeCursor.subSequence(0, 1), 1); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_revertSwapPunctuation(); + } + return true; + } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 9985d2fb1..10094b5ad 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -226,6 +226,11 @@ public class SettingsValues { res.getBoolean(R.bool.config_default_vibration_enabled)); } + public boolean isCorrectionOn() { + return mCorrectionMode == Suggest.CORRECTION_FULL + || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM; + } + public boolean isSuggestionStripVisibleInOrientation(final int orientation) { return (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_VALUE) || (mSuggestionVisibility == SUGGESTION_VISIBILITY_SHOW_ONLY_PORTRAIT_VALUE -- cgit v1.2.3-83-g751a From 140adf204bdf68e25a760b371516e23f6ac51cf2 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 8 Jun 2012 22:09:20 +0900 Subject: Consolidate auto-correction settings. For some reason, there were several ways, not exactly identical, to get this setting. The ones that used mAutoCorrectionEnabled would kick in when the input field was specifying no correction, so it would be a little strange (although harmless in the practice because the settings set in this way would not get used later, because the correct test would be done at that time). Also perform a very small refactoring Change-Id: Ica9f32b238d98009ae1852d3c1e940398f5d341c --- java/src/com/android/inputmethod/latin/LatinIME.java | 18 +++++++----------- .../com/android/inputmethod/latin/SettingsValues.java | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 94e0ac836..4670bedb4 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -449,7 +449,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen oldContactsDictionary = null; } mSuggest = new Suggest(this, subtypeLocale); - if (mCurrentSettings.mAutoCorrectEnabled) { + if (mCurrentSettings.isCorrectionOn()) { mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); } @@ -680,7 +680,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadSettings(); - if (mSuggest != null && mCurrentSettings.mAutoCorrectEnabled) { + if (mSuggest != null && mCurrentSettings.isCorrectionOn()) { mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); } @@ -1553,8 +1553,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // not to auto correct, but accept the typed word. For instance, // in Italian dov' should not be expanded to dove' because the elision // requires the last vowel to be removed. - final boolean shouldAutoCorrect = mCurrentSettings.mAutoCorrectEnabled - && !mInputAttributes.mInputTypeNoAutoCorrect; + final boolean shouldAutoCorrect = mCurrentSettings.isCorrectionOn(); if (shouldAutoCorrect && primaryCode != Keyboard.CODE_SINGLE_QUOTE) { commitCurrentAutoCorrection(primaryCode); didAutoCorrect = true; @@ -1914,14 +1913,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1); - if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_commitText(chosenWord); - } } else { mConnection.commitText(chosenWord, 1); - if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_commitText(chosenWord); - } + } + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_commitText(chosenWord); } // Add the word to the user history dictionary final CharSequence prevWord = addToUserHistoryDictionary(chosenWord); @@ -2231,7 +2227,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn); p.println(" mCorrectionMode=" + mCurrentSettings.mCorrectionMode); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); - p.println(" mAutoCorrectEnabled=" + mCurrentSettings.mAutoCorrectEnabled); + p.println(" isCorrectionOn=" + mCurrentSettings.isCorrectionOn()); p.println(" mSoundOn=" + mCurrentSettings.mSoundOn); p.println(" mVibrateOn=" + mCurrentSettings.mVibrateOn); p.println(" mKeyPreviewPopupOn=" + mCurrentSettings.mKeyPreviewPopupOn); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 10094b5ad..6a79aa611 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -91,7 +91,7 @@ public class SettingsValues { public final int mKeypressVibrationDuration; public final float mFxVolume; public final int mKeyPreviewPopupDismissDelay; - public final boolean mAutoCorrectEnabled; + private final boolean mAutoCorrectEnabled; public final float mAutoCorrectionThreshold; public final int mCorrectionMode; public final int mSuggestionVisibility; -- cgit v1.2.3-83-g751a From 15121cff3785f179e79b1b82753a145ffd913ea5 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 15 Jun 2012 04:20:45 +0900 Subject: Remove irrelevant options. Bug: 6667355 Change-Id: I39b6db17fb52e80f510cf6462f41d9cb1f8e0341 --- java/res/xml/prefs.xml | 1 - java/src/com/android/inputmethod/latin/Settings.java | 7 +++++-- java/src/com/android/inputmethod/latin/SettingsValues.java | 13 ++++--------- 3 files changed, 9 insertions(+), 12 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index 3598a685e..137981949 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -122,7 +122,6 @@ android:defaultValue="true" /> Date: Wed, 13 Jun 2012 01:10:18 +0900 Subject: Add a kind to the suggestion for bookkeeping (A1) This will help for debug as well as serve as groundwork for Bug: 6252660 Bug: 6166228 Bug: 2704000 Bug: 6225530 Change-Id: I74d0a7b943fb22c514ad79dc064d69ddf336d3ef --- .../com/android/inputmethod/latin/SettingsValues.java | 7 +++---- java/src/com/android/inputmethod/latin/Suggest.java | 14 ++++++++------ .../com/android/inputmethod/latin/SuggestedWords.java | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 13 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index f8a0a4df6..da4acea50 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -173,12 +173,11 @@ public class SettingsValues { // Helper functions to create member values. private static SuggestedWords createSuggestPuncList(final String[] puncs) { - final ArrayList puncList = - new ArrayList(); + final ArrayList puncList = new ArrayList(); if (puncs != null) { for (final String puncSpec : puncs) { - puncList.add(new SuggestedWords.SuggestedWordInfo( - KeySpecParser.getLabel(puncSpec), SuggestedWordInfo.MAX_SCORE)); + puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec), + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED)); } } return new SuggestedWords(puncList, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 68b7b913f..5b9d4a949 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -335,15 +335,16 @@ public class Suggest implements Dictionary.WordCallback { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); } - mSuggestions.add(0, new SuggestedWordInfo( - sb.toString(), SuggestedWordInfo.MAX_SCORE)); + mSuggestions.add(0, new SuggestedWordInfo(sb.toString(), + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST)); } else { - mSuggestions.add(0, new SuggestedWordInfo( - whitelistedWord, SuggestedWordInfo.MAX_SCORE)); + mSuggestions.add(0, new SuggestedWordInfo(whitelistedWord, + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST)); } } - mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE)); + mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, + SuggestedWordInfo.KIND_TYPED)); SuggestedWordInfo.removeDups(mSuggestions); final ArrayList suggestionsList; @@ -495,7 +496,8 @@ public class Suggest implements Dictionary.WordCallback { for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) { sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); } - suggestions.add(pos, new SuggestedWordInfo(sb, score)); + // TODO: figure out what type of suggestion this is + suggestions.add(pos, new SuggestedWordInfo(sb, score, SuggestedWordInfo.KIND_CORRECTION)); if (suggestions.size() > prefMaxSuggestions) { suggestions.remove(prefMaxSuggestions); } else { diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 497fd3bfa..1ed91fe71 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -91,7 +91,8 @@ public class SuggestedWords { final ArrayList result = new ArrayList(); for (CompletionInfo info : infos) { if (null != info && info.getText() != null) { - result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE)); + result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE, + SuggestedWordInfo.KIND_APP_DEFINED)); } } return result; @@ -103,7 +104,8 @@ public class SuggestedWords { final CharSequence typedWord, final SuggestedWords previousSuggestions) { final ArrayList suggestionsList = new ArrayList(); final HashSet alreadySeen = new HashSet(); - suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE)); + suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, + SuggestedWordInfo.KIND_TYPED)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { @@ -120,16 +122,25 @@ public class SuggestedWords { public static class SuggestedWordInfo { public static final int MAX_SCORE = Integer.MAX_VALUE; + public static final int KIND_TYPED = 0; // What user typed + public static final int KIND_CORRECTION = 1; // Simple correction/suggestion + public static final int KIND_COMPLETION = 2; // Completion (suggestion with appended chars) + public static final int KIND_WHITELIST = 3; // Whitelisted word + public static final int KIND_BLACKLIST = 4; // Blacklisted word + public static final int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation + public static final int KIND_APP_DEFINED = 6; // Suggested by the application private final String mWordStr; public final CharSequence mWord; public final int mScore; + public final int mKind; public final int mCodePointCount; private String mDebugString = ""; - public SuggestedWordInfo(final CharSequence word, final int score) { + public SuggestedWordInfo(final CharSequence word, final int score, final int kind) { mWordStr = word.toString(); mWord = word; mScore = score; + mKind = kind; mCodePointCount = mWordStr.codePointCount(0, mWordStr.length()); } -- cgit v1.2.3-83-g751a From dca729fddd69f03d8eaca238c62478a7fd77db96 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 12 Jun 2012 09:35:51 +0900 Subject: Move final attributes to SettingsValues (B2) Bug: 6675475 Bug: 6677394 Change-Id: I4a26efb9226d3f909f331c4d2e47cd83a05c011e --- .../com/android/inputmethod/latin/LatinIME.java | 65 +++++++++++----------- .../android/inputmethod/latin/SettingsValues.java | 33 ++++++++++- 2 files changed, 62 insertions(+), 36 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index b9f39c1e1..107d9344e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -872,33 +872,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions); } - if (null != mInputAttributes && mInputAttributes.mApplicationSpecifiedCompletionOn) { - mApplicationSpecifiedCompletions = applicationSpecifiedCompletions; - if (applicationSpecifiedCompletions == null) { - clearSuggestions(); - return; - } - - final ArrayList applicationSuggestedWords = - SuggestedWords.getFromApplicationSpecifiedCompletions( - applicationSpecifiedCompletions); - final SuggestedWords suggestedWords = new SuggestedWords( - applicationSuggestedWords, - false /* typedWordValid */, - false /* hasAutoCorrectionCandidate */, - false /* allowsToBeAutoCorrected */, - false /* isPunctuationSuggestions */, - false /* isObsoleteSuggestions */, - false /* isPrediction */); - // When in fullscreen mode, show completions generated by the application - final boolean isAutoCorrection = false; - setSuggestions(suggestedWords, isAutoCorrection); - setAutoCorrectionIndicator(isAutoCorrection); - // TODO: is this the right thing to do? What should we auto-correct to in - // this case? This says to keep whatever the user typed. - mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); - setSuggestionStripShown(true); + if (!mCurrentSettings.isApplicationSpecifiedCompletionsOn()) return; + mApplicationSpecifiedCompletions = applicationSpecifiedCompletions; + if (applicationSpecifiedCompletions == null) { + clearSuggestions(); + return; } + + final ArrayList applicationSuggestedWords = + SuggestedWords.getFromApplicationSpecifiedCompletions( + applicationSpecifiedCompletions); + final SuggestedWords suggestedWords = new SuggestedWords( + applicationSuggestedWords, + false /* typedWordValid */, + false /* hasAutoCorrectionCandidate */, + false /* allowsToBeAutoCorrected */, + false /* isPunctuationSuggestions */, + false /* isObsoleteSuggestions */, + false /* isPrediction */); + // When in fullscreen mode, show completions generated by the application + final boolean isAutoCorrection = false; + setSuggestions(suggestedWords, isAutoCorrection); + setAutoCorrectionIndicator(isAutoCorrection); + // TODO: is this the right thing to do? What should we auto-correct to in + // this case? This says to keep whatever the user typed. + mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); + setSuggestionStripShown(true); } private void setSuggestionStripShownInternal(boolean shown, boolean needsInputViewShown) { @@ -1277,8 +1276,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } break; default: - if (primaryCode == Keyboard.CODE_TAB - && mInputAttributes.mEditorAction == EditorInfo.IME_ACTION_NEXT) { + if (primaryCode == Keyboard.CODE_TAB && mCurrentSettings.isEditorActionNext()) { performEditorAction(EditorInfo.IME_ACTION_NEXT); break; } @@ -1628,7 +1626,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public boolean isSuggestionsRequested() { // TODO: move this method to mCurrentSettings - return (null != mInputAttributes && mInputAttributes.mIsSettingsSuggestionStripOn) + return mCurrentSettings.isSuggestionStripRequestedByTextField() && (mCurrentSettings.isCorrectionOn() || mCurrentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation)); } @@ -1645,7 +1643,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return true; if (!mCurrentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation)) return false; - if (null != mInputAttributes && mInputAttributes.mApplicationSpecifiedCompletionOn) + if (mCurrentSettings.isApplicationSpecifiedCompletionsOn()) return true; return isSuggestionsRequested(); } @@ -1827,7 +1825,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } - if ((null != mInputAttributes && mInputAttributes.mApplicationSpecifiedCompletionOn) + if (mCurrentSettings.isApplicationSpecifiedCompletionsOn() && mApplicationSpecifiedCompletions != null && index >= 0 && index < mApplicationSpecifiedCompletions.length) { if (mSuggestionsView != null) { @@ -2224,13 +2222,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; p.println(" Keyboard mode = " + keyboardMode); - p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn); + p.println(" mIsSuggestionsStripRequestedByTextField = " + + mCurrentSettings.isSuggestionStripRequestedByTextField()); p.println(" mCorrectionMode=" + mCurrentSettings.mCorrectionMode); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); p.println(" isCorrectionOn=" + mCurrentSettings.isCorrectionOn()); p.println(" mSoundOn=" + mCurrentSettings.mSoundOn); p.println(" mVibrateOn=" + mCurrentSettings.mVibrateOn); p.println(" mKeyPreviewPopupOn=" + mCurrentSettings.mKeyPreviewPopupOn); - p.println(" mInputAttributes=" + mInputAttributes.toString()); + p.println(" inputAttributes=" + mCurrentSettings.getInputAttributesDebugString()); } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index f8a0a4df6..5d33923df 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -87,6 +87,9 @@ public class SettingsValues { private final float mKeypressSoundVolumeRawValue; private final InputMethodSubtype[] mAdditionalSubtypes; + // From the input box + private final InputAttributes mInputAttributes; + // Deduced settings public final int mKeypressVibrationDuration; public final float mFxVolume; @@ -125,6 +128,13 @@ public class SettingsValues { mSymbolsExcludedFromWordSeparators, res); mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); + // Store the input attributes + if (null == inputAttributes) { + mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); + } else { + mInputAttributes = inputAttributes; + } + // Get the settings preferences mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); mVibrateOn = isVibrateOn(context, prefs, res); @@ -167,7 +177,7 @@ public class SettingsValues { mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( getPrefAdditionalSubtypes(prefs, res)); - mCorrectionMode = createCorrectionMode(inputAttributes); + mCorrectionMode = createCorrectionMode(); mSuggestionVisibility = createSuggestionVisibility(res); } @@ -202,9 +212,9 @@ public class SettingsValues { return wordSeparators; } - private int createCorrectionMode(final InputAttributes inputAttributes) { + private int createCorrectionMode() { final boolean shouldAutoCorrect = mAutoCorrectEnabled - && (null == inputAttributes || !inputAttributes.mInputTypeNoAutoCorrect); + && !mInputAttributes.mInputTypeNoAutoCorrect; if (mBigramSuggestionEnabled && shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM; return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; } @@ -226,6 +236,18 @@ public class SettingsValues { res.getBoolean(R.bool.config_default_vibration_enabled)); } + public boolean isApplicationSpecifiedCompletionsOn() { + return mInputAttributes.mApplicationSpecifiedCompletionOn; + } + + public boolean isEditorActionNext() { + return mInputAttributes.mEditorAction == EditorInfo.IME_ACTION_NEXT; + } + + public boolean isSuggestionStripRequestedByTextField() { + return mInputAttributes.mIsSettingsSuggestionStripOn; + } + public boolean isCorrectionOn() { return mCorrectionMode == Suggest.CORRECTION_FULL || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM; @@ -413,4 +435,9 @@ public class SettingsValues { final String newStr = Utils.localeAndTimeHashMapToStr(map); prefs.edit().putString(Settings.PREF_LAST_USER_DICTIONARY_WRITE_TIME, newStr).apply(); } + + // For debug. + public String getInputAttributesDebugString() { + return mInputAttributes.toString(); + } } -- cgit v1.2.3-83-g751a From 6883153dd074e2c5c373b2ac2c4fed72ee330c03 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 10:38:57 +0900 Subject: Cleanup, part 1 (C1) Change-Id: I2b1ddd836aaf6bfc0bd2befb78f98239ffcdbb22 --- java/src/com/android/inputmethod/latin/SettingsValues.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 5d33923df..a9a4313d4 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -157,8 +157,7 @@ public class SettingsValues { Integer.toString(res.getInteger(R.integer.config_key_preview_linger_timeout))); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); - mBigramSuggestionEnabled = mAutoCorrectEnabled - && isBigramSuggestionEnabled(prefs, res, mAutoCorrectEnabled); + mBigramSuggestionEnabled = mAutoCorrectEnabled; mBigramPredictionEnabled = mBigramSuggestionEnabled && isBigramPredictionEnabled(prefs, res); // TODO: remove mEnableSuggestionSpanInsertion. It's always true. @@ -308,12 +307,6 @@ public class SettingsValues { R.integer.config_key_preview_linger_timeout)))); } - private static boolean isBigramSuggestionEnabled(final SharedPreferences sp, - final Resources resources, final boolean autoCorrectEnabled) { - // TODO: remove this method. Bigram suggestion is always true. - return true; - } - private static boolean isBigramPredictionEnabled(final SharedPreferences sp, final Resources resources) { return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, resources.getBoolean( -- cgit v1.2.3-83-g751a From 71dc2804269f81a4b50c54b42cce3859106d326b Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 10:40:16 +0900 Subject: Cleanup, part 2 (C2) Change-Id: I860f41807e9bc2e38b6ad84e1527fc8707a9aa40 --- java/src/com/android/inputmethod/latin/SettingsValues.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index a9a4313d4..772d18ef8 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -76,9 +76,7 @@ public class SettingsValues { @SuppressWarnings("unused") // TODO: Use this private final String mKeyPreviewPopupDismissDelayRawValue; public final boolean mUseContactsDict; - // Suggestion: use bigrams to adjust scores of suggestions obtained from unigram dictionary - public final boolean mBigramSuggestionEnabled; - // Prediction: use bigrams to predict the next word when there is no input for it yet + // Use bigrams to predict the next word when there is no input for it yet public final boolean mBigramPredictionEnabled; public final boolean mEnableSuggestionSpanInsertion; @SuppressWarnings("unused") // TODO: Use this @@ -157,9 +155,7 @@ public class SettingsValues { Integer.toString(res.getInteger(R.integer.config_key_preview_linger_timeout))); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); - mBigramSuggestionEnabled = mAutoCorrectEnabled; - mBigramPredictionEnabled = mBigramSuggestionEnabled - && isBigramPredictionEnabled(prefs, res); + mBigramPredictionEnabled = isBigramPredictionEnabled(prefs, res); // TODO: remove mEnableSuggestionSpanInsertion. It's always true. mEnableSuggestionSpanInsertion = true; mVibrationDurationSettingsRawValue = @@ -214,7 +210,7 @@ public class SettingsValues { private int createCorrectionMode() { final boolean shouldAutoCorrect = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect; - if (mBigramSuggestionEnabled && shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM; + if (shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM; return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; } -- cgit v1.2.3-83-g751a From 5475e92b3fb33dd7d6b021ddcbe1ca593112b5c8 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 10:46:18 +0900 Subject: Cleanup, part 3 (C3) Change-Id: Ib0be8dc26b6fa366a3dabeea940d466602073244 --- java/src/com/android/inputmethod/latin/LatinIME.java | 2 +- java/src/com/android/inputmethod/latin/SettingsValues.java | 4 +--- java/src/com/android/inputmethod/latin/Suggest.java | 9 +++++---- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 107d9344e..fc4d1150c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1932,7 +1932,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } final SuggestedWords suggestedWords; - if (mCurrentSettings.mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) { + if (mCurrentSettings.isCorrectionOn()) { final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); if (!TextUtils.isEmpty(prevWord)) { suggestedWords = mSuggest.getBigramPredictions(prevWord); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 772d18ef8..106cd2c0c 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -210,7 +210,6 @@ public class SettingsValues { private int createCorrectionMode() { final boolean shouldAutoCorrect = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect; - if (shouldAutoCorrect) return Suggest.CORRECTION_FULL_BIGRAM; return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; } @@ -244,8 +243,7 @@ public class SettingsValues { } public boolean isCorrectionOn() { - return mCorrectionMode == Suggest.CORRECTION_FULL - || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM; + return mCorrectionMode == Suggest.CORRECTION_FULL; } public boolean isSuggestionStripVisibleInOrientation(final int orientation) { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 68b7b913f..958b4533b 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -39,9 +39,10 @@ public class Suggest implements Dictionary.WordCallback { public static final int APPROX_MAX_WORD_LENGTH = 32; + // TODO: rename this to CORRECTION_OFF public static final int CORRECTION_NONE = 0; + // TODO: rename this to CORRECTION_ON public static final int CORRECTION_FULL = 1; - public static final int CORRECTION_FULL_BIGRAM = 2; // It seems the following values are only used for logging. public static final int DIC_USER_TYPED = 0; @@ -262,7 +263,7 @@ public class Suggest implements Dictionary.WordCallback { LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED, Dictionary.UNIGRAM); mConsideredWord = consideredWord; - if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL_BIGRAM)) { + if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL)) { // At first character typed, search only the bigrams mBigramSuggestions = new ArrayList(PREF_MAX_BIGRAMS); @@ -319,7 +320,7 @@ public class Suggest implements Dictionary.WordCallback { mIsFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord)); final boolean hasAutoCorrection; - if (CORRECTION_FULL == correctionMode || CORRECTION_FULL_BIGRAM == correctionMode) { + if (CORRECTION_FULL == correctionMode) { final CharSequence autoCorrection = AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer, mSuggestions, consideredWord, mAutoCorrectionThreshold, @@ -368,7 +369,7 @@ public class Suggest implements Dictionary.WordCallback { && mHasMainDictionary; boolean autoCorrectionAvailable = hasAutoCorrection; - if (correctionMode == CORRECTION_FULL || correctionMode == CORRECTION_FULL_BIGRAM) { + if (correctionMode == CORRECTION_FULL) { autoCorrectionAvailable |= !allowsToBeAutoCorrected; } // Don't auto-correct words with multiple capital letter -- cgit v1.2.3-83-g751a From 9b233ecef2e6fce4024caa4da4b88d75edfd7b00 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 10:51:04 +0900 Subject: Cleanup, part 4 (C4) Change-Id: I2821ae71ec49e4b6b512157d17b80198f74321e4 --- java/src/com/android/inputmethod/latin/LatinIME.java | 2 +- .../com/android/inputmethod/latin/SettingsValues.java | 8 +++++--- java/src/com/android/inputmethod/latin/Suggest.java | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index fc4d1150c..29ebe3967 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1716,7 +1716,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), - mCurrentSettings.mCorrectionMode); + mCurrentSettings.isCorrectionOn()); // Basically, we update the suggestion strip only when suggestion count > 1. However, // there is an exception: We update the suggestion strip whenever typed word's length diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 106cd2c0c..84e66a032 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -208,9 +208,11 @@ public class SettingsValues { } private int createCorrectionMode() { - final boolean shouldAutoCorrect = mAutoCorrectEnabled - && !mInputAttributes.mInputTypeNoAutoCorrect; - return shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; + if (mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect) { + return Suggest.CORRECTION_FULL; + } else { + return Suggest.CORRECTION_NONE; + } } private int createSuggestionVisibility(final Resources res) { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 958b4533b..c203e52ac 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -245,10 +245,18 @@ public class Suggest implements Dictionary.WordCallback { true /* isPrediction */); } - // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder + // Wrapper for test compatibility. TODO: remove this method public SuggestedWords getSuggestedWords( final WordComposer wordComposer, CharSequence prevWordForBigram, final ProximityInfo proximityInfo, final int correctionMode) { + return getSuggestedWords(wordComposer, prevWordForBigram, proximityInfo, + Suggest.CORRECTION_FULL == correctionMode); + } + + // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder + public SuggestedWords getSuggestedWords( + final WordComposer wordComposer, CharSequence prevWordForBigram, + final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) { LatinImeLogger.onStartSuggestion(prevWordForBigram); mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); mIsAllUpperCase = wordComposer.isAllUpperCase(); @@ -263,7 +271,7 @@ public class Suggest implements Dictionary.WordCallback { LatinImeLogger.onAddSuggestedWord(typedWord, Suggest.DIC_USER_TYPED, Dictionary.UNIGRAM); mConsideredWord = consideredWord; - if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL)) { + if (wordComposer.size() <= 1 && isCorrectionEnabled) { // At first character typed, search only the bigrams mBigramSuggestions = new ArrayList(PREF_MAX_BIGRAMS); @@ -320,7 +328,7 @@ public class Suggest implements Dictionary.WordCallback { mIsFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord)); final boolean hasAutoCorrection; - if (CORRECTION_FULL == correctionMode) { + if (isCorrectionEnabled) { final CharSequence autoCorrection = AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer, mSuggestions, consideredWord, mAutoCorrectionThreshold, @@ -369,7 +377,7 @@ public class Suggest implements Dictionary.WordCallback { && mHasMainDictionary; boolean autoCorrectionAvailable = hasAutoCorrection; - if (correctionMode == CORRECTION_FULL) { + if (isCorrectionEnabled) { autoCorrectionAvailable |= !allowsToBeAutoCorrected; } // Don't auto-correct words with multiple capital letter -- cgit v1.2.3-83-g751a From fe53e5c060dc4fd0acdfdffcadba94f9bb6062c3 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 12 Jun 2012 10:00:07 +0900 Subject: Move a settings method to SettingsValues (B3) Change-Id: Ibfa27bd919c92be219c4d107b3ace008ca80a19f --- .../com/android/inputmethod/latin/LatinIME.java | 27 ++++++++-------------- .../android/inputmethod/latin/SettingsValues.java | 7 +++++- 2 files changed, 16 insertions(+), 18 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 559f5ec26..a0744e574 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -828,7 +828,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ @Override public void onExtractedTextClicked() { - if (isSuggestionsRequested()) return; + if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return; super.onExtractedTextClicked(); } @@ -844,7 +844,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ @Override public void onExtractedCursorMovement(int dx, int dy) { - if (isSuggestionsRequested()) return; + if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return; super.onExtractedCursorMovement(dx, dy); } @@ -1449,7 +1449,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } } - if (isSuggestionsRequested()) { + if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { restartSuggestionsOnWordBeforeCursorIfAtEndOfWord(); } } @@ -1494,7 +1494,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // thread here. if (!isComposingWord && (isAlphabet(primaryCode) || mCurrentSettings.isSymbolExcludedFromWordSeparators(primaryCode)) - && isSuggestionsRequested() && + && mCurrentSettings.isSuggestionsRequested(mDisplayOrientation) && !mConnection.isCursorTouchingWord(mCurrentSettings)) { // Reset entirely the composing state anyway, then start composing a new word unless // the character is a single quote. The idea here is, single quote is not a @@ -1576,7 +1576,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen sendKeyCodePoint(primaryCode); if (Keyboard.CODE_SPACE == primaryCode) { - if (isSuggestionsRequested()) { + if (mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { if (maybeDoubleSpace()) { mSpaceState = SPACE_STATE_DOUBLE; } else if (!isShowingPunctuationList()) { @@ -1627,13 +1627,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen inputView.closing(); } - public boolean isSuggestionsRequested() { - // TODO: move this method to mCurrentSettings - return mCurrentSettings.isSuggestionStripRequestedByTextField() - && (mCurrentSettings.isCorrectionOn() - || mCurrentSettings.isSuggestionStripVisibleInOrientation(mDisplayOrientation)); - } - public boolean isShowingPunctuationList() { if (mSuggestionsView == null) return false; return mCurrentSettings.mSuggestPuncList == mSuggestionsView.getSuggestions(); @@ -1648,7 +1641,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return false; if (mCurrentSettings.isApplicationSpecifiedCompletionsOn()) return true; - return isSuggestionsRequested(); + return mCurrentSettings.isSuggestionsRequested(mDisplayOrientation); } public void switchToKeyboardView() { @@ -1697,7 +1690,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public void updateSuggestions() { // Check if we have a suggestion engine attached. - if ((mSuggest == null || !isSuggestionsRequested())) { + if ((mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation))) { if (mWordComposer.isComposingWord()) { Log.w(TAG, "Called updateSuggestions but suggestions were not requested!"); mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); @@ -1926,7 +1919,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void updateBigramPredictions() { - if (mSuggest == null || !isSuggestionsRequested()) + if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) return; if (!mCurrentSettings.mBigramPredictionEnabled) { @@ -2225,8 +2218,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1; p.println(" Keyboard mode = " + keyboardMode); - p.println(" mIsSuggestionsStripRequestedByTextField = " - + mCurrentSettings.isSuggestionStripRequestedByTextField()); + p.println(" mIsSuggestionsSuggestionsRequested = " + + mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)); p.println(" mCorrectionMode=" + mCurrentSettings.mCorrectionMode); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); p.println(" isCorrectionOn=" + mCurrentSettings.isCorrectionOn()); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index d6d6c6c88..c05ffffec 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -238,10 +238,15 @@ public class SettingsValues { return mInputAttributes.mEditorAction == EditorInfo.IME_ACTION_NEXT; } - public boolean isSuggestionStripRequestedByTextField() { + private boolean isSuggestionStripRequestedByTextField() { return mInputAttributes.mIsSettingsSuggestionStripOn; } + public boolean isSuggestionsRequested(final int displayOrientation) { + return isSuggestionStripRequestedByTextField() + && (isCorrectionOn() || isSuggestionStripVisibleInOrientation(displayOrientation)); + } + public boolean isCorrectionOn() { return mCorrectionMode == Suggest.CORRECTION_FULL || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM; -- cgit v1.2.3-83-g751a From 64e52051cfa62523c3f09c61a9dae34198470792 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 12 Jun 2012 10:03:04 +0900 Subject: Simplification (B4) Change-Id: Id5abf722a533980ed2d89381dbddc0a71b6f5b6b --- java/src/com/android/inputmethod/latin/SettingsValues.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index c05ffffec..30fee576f 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -238,12 +238,8 @@ public class SettingsValues { return mInputAttributes.mEditorAction == EditorInfo.IME_ACTION_NEXT; } - private boolean isSuggestionStripRequestedByTextField() { - return mInputAttributes.mIsSettingsSuggestionStripOn; - } - public boolean isSuggestionsRequested(final int displayOrientation) { - return isSuggestionStripRequestedByTextField() + return mInputAttributes.mIsSettingsSuggestionStripOn && (isCorrectionOn() || isSuggestionStripVisibleInOrientation(displayOrientation)); } -- cgit v1.2.3-83-g751a From 2f3a694e29ad5a63052a2f963327855fee099f55 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 10:59:12 +0900 Subject: Cleanup, part 7 (C7) Change-Id: I662be9d3b31fb9e157722f38cab1e6fb8a1152ab --- java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++---- java/src/com/android/inputmethod/latin/SettingsValues.java | 14 +++----------- 2 files changed, 5 insertions(+), 15 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 02b966625..48f93c5a2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1076,7 +1076,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private boolean maybeDoubleSpace() { - if (mCurrentSettings.mCorrectionMode == Suggest.CORRECTION_NONE) return false; + if (!mCurrentSettings.mCorrectionEnabled) return false; if (!mHandler.isAcceptingDoubleSpaces()) return false; final CharSequence lastThree = mConnection.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 @@ -1864,8 +1864,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // - There is a dictionary and the word is not in it // Please note that if mSuggest is null, it means that everything is off: suggestion // and correction, so we shouldn't try to show the hint - // We used to look at mCorrectionMode here, but showing the hint should have nothing - // to do with the autocorrection setting. final boolean showingAddToDictionaryHint = index == 0 && mSuggest != null // If there is no dictionary the hint should be shown. && (!mSuggest.hasMainDictionary() @@ -2220,7 +2218,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen p.println(" Keyboard mode = " + keyboardMode); p.println(" mIsSuggestionsSuggestionsRequested = " + mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)); - p.println(" mCorrectionMode=" + mCurrentSettings.mCorrectionMode); + p.println(" mCorrectionEnabled=" + mCurrentSettings.mCorrectionEnabled); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); p.println(" isCorrectionOn=" + mCurrentSettings.isCorrectionOn()); p.println(" mSoundOn=" + mCurrentSettings.mSoundOn); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 53f2dfcdb..bc33b173a 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -94,7 +94,7 @@ public class SettingsValues { public final int mKeyPreviewPopupDismissDelay; private final boolean mAutoCorrectEnabled; public final float mAutoCorrectionThreshold; - public final int mCorrectionMode; + public final boolean mCorrectionEnabled; public final int mSuggestionVisibility; private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyOnMain; @@ -172,7 +172,7 @@ public class SettingsValues { mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray( getPrefAdditionalSubtypes(prefs, res)); - mCorrectionMode = createCorrectionMode(); + mCorrectionEnabled = mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect; mSuggestionVisibility = createSuggestionVisibility(res); } @@ -206,14 +206,6 @@ public class SettingsValues { return wordSeparators; } - private int createCorrectionMode() { - if (mAutoCorrectEnabled && !mInputAttributes.mInputTypeNoAutoCorrect) { - return Suggest.CORRECTION_FULL; - } else { - return Suggest.CORRECTION_NONE; - } - } - private int createSuggestionVisibility(final Resources res) { final String suggestionVisiblityStr = mShowSuggestionsSetting; for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) { @@ -245,7 +237,7 @@ public class SettingsValues { } public boolean isCorrectionOn() { - return mCorrectionMode == Suggest.CORRECTION_FULL; + return mCorrectionEnabled; } public boolean isSuggestionStripVisibleInOrientation(final int orientation) { -- cgit v1.2.3-83-g751a From ca6b7d52650917b92bf00e092ddad25d9f3f2537 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 11:03:22 +0900 Subject: Cleanup, part 8 (C8) Change-Id: Iecc9b3d43c191614c2951408e14085cb77eefd4d --- java/src/com/android/inputmethod/latin/LatinIME.java | 20 +++++++++----------- .../android/inputmethod/latin/SettingsValues.java | 7 ++----- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 48f93c5a2..8f1facd9d 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -452,7 +452,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen oldContactsDictionary = null; } mSuggest = new Suggest(this, subtypeLocale); - if (mCurrentSettings.isCorrectionOn()) { + if (mCurrentSettings.mCorrectionEnabled) { mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); } @@ -685,7 +685,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadSettings(); - if (mSuggest != null && mCurrentSettings.isCorrectionOn()) { + if (mSuggest != null && mCurrentSettings.mCorrectionEnabled) { mSuggest.setAutoCorrectionThreshold(mCurrentSettings.mAutoCorrectionThreshold); } @@ -1557,8 +1557,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // not to auto correct, but accept the typed word. For instance, // in Italian dov' should not be expanded to dove' because the elision // requires the last vowel to be removed. - final boolean shouldAutoCorrect = mCurrentSettings.isCorrectionOn(); - if (shouldAutoCorrect && primaryCode != Keyboard.CODE_SINGLE_QUOTE) { + if (mCurrentSettings.mCorrectionEnabled && primaryCode != Keyboard.CODE_SINGLE_QUOTE) { commitCurrentAutoCorrection(primaryCode); didAutoCorrect = true; } else { @@ -1712,7 +1711,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), - mCurrentSettings.isCorrectionOn()); + mCurrentSettings.mCorrectionEnabled); // Basically, we update the suggestion strip only when suggestion count > 1. However, // there is an exception: We update the suggestion strip whenever typed word's length @@ -1926,7 +1925,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } final SuggestedWords suggestedWords; - if (mCurrentSettings.isCorrectionOn()) { + if (mCurrentSettings.mCorrectionEnabled) { final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); if (!TextUtils.isEmpty(prevWord)) { suggestedWords = mSuggest.getBigramPredictions(prevWord); @@ -1959,10 +1958,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private CharSequence addToUserHistoryDictionary(final CharSequence suggestion) { if (TextUtils.isEmpty(suggestion)) return null; - // Only auto-add to dictionary if auto-correct is ON. Otherwise we'll be - // adding words in situations where the user or application really didn't - // want corrections enabled or learned. - if (!mCurrentSettings.isCorrectionOn()) return null; + // If correction is not enabled, we don't add words to the user history dictionary. + // That's to avoid unintended additions in some sensitive fields, or fields that + // expect to receive non-words. + if (!mCurrentSettings.mCorrectionEnabled) return null; if (mUserHistoryDictionary != null) { final CharSequence prevWord @@ -2220,7 +2219,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen + mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)); p.println(" mCorrectionEnabled=" + mCurrentSettings.mCorrectionEnabled); p.println(" isComposingWord=" + mWordComposer.isComposingWord()); - p.println(" isCorrectionOn=" + mCurrentSettings.isCorrectionOn()); p.println(" mSoundOn=" + mCurrentSettings.mSoundOn); p.println(" mVibrateOn=" + mCurrentSettings.mVibrateOn); p.println(" mKeyPreviewPopupOn=" + mCurrentSettings.mKeyPreviewPopupOn); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index bc33b173a..6b4b85ff6 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -233,11 +233,8 @@ public class SettingsValues { public boolean isSuggestionsRequested(final int displayOrientation) { return mInputAttributes.mIsSettingsSuggestionStripOn - && (isCorrectionOn() || isSuggestionStripVisibleInOrientation(displayOrientation)); - } - - public boolean isCorrectionOn() { - return mCorrectionEnabled; + && (mCorrectionEnabled + || isSuggestionStripVisibleInOrientation(displayOrientation)); } public boolean isSuggestionStripVisibleInOrientation(final int orientation) { -- cgit v1.2.3-83-g751a From e8bb8351d6f09f461851af619cabe5fcd2f66c0a Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Sat, 16 Jun 2012 11:06:29 +0900 Subject: Cleanup, part 9 (C9) Change-Id: Ifb15553824915d0634aea83689302c2418b093f3 --- java/src/com/android/inputmethod/latin/LatinIME.java | 11 +++-------- java/src/com/android/inputmethod/latin/SettingsValues.java | 3 --- 2 files changed, 3 insertions(+), 11 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8f1facd9d..b8aab4cdf 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1894,14 +1894,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen */ private void commitChosenWord(final CharSequence chosenWord, final int commitType, final int separatorCode) { - if (mCurrentSettings.mEnableSuggestionSpanInsertion) { - final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); - mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( - this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), - 1); - } else { - mConnection.commitText(chosenWord, 1); - } + final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); + mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( + this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1); if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_commitText(chosenWord); } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 6b4b85ff6..ef423f19b 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -78,7 +78,6 @@ public class SettingsValues { public final boolean mUseContactsDict; // Use bigrams to predict the next word when there is no input for it yet public final boolean mBigramPredictionEnabled; - public final boolean mEnableSuggestionSpanInsertion; @SuppressWarnings("unused") // TODO: Use this private final int mVibrationDurationSettingsRawValue; @SuppressWarnings("unused") // TODO: Use this @@ -156,8 +155,6 @@ public class SettingsValues { mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mAutoCorrectEnabled = isAutoCorrectEnabled(res, mAutoCorrectionThresholdRawValue); mBigramPredictionEnabled = isBigramPredictionEnabled(prefs, res); - // TODO: remove mEnableSuggestionSpanInsertion. It's always true. - mEnableSuggestionSpanInsertion = true; mVibrationDurationSettingsRawValue = prefs.getInt(Settings.PREF_VIBRATION_DURATION_SETTINGS, -1); mKeypressSoundVolumeRawValue = prefs.getFloat(Settings.PREF_KEYPRESS_SOUND_VOLUME, -1.0f); -- cgit v1.2.3-83-g751a From 24eec0fa680f97e64d1fa0df754acbad95ed9a76 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 27 Jun 2012 18:17:28 +0900 Subject: Remember the source dictionary for each suggestion. Change-Id: I3c63372bd5572a479a67eaecfe8c8ea1cabc70d9 --- java/src/com/android/inputmethod/latin/BinaryDictionary.java | 4 ++-- java/src/com/android/inputmethod/latin/Dictionary.java | 2 ++ .../com/android/inputmethod/latin/ExpandableDictionary.java | 6 +++--- java/src/com/android/inputmethod/latin/SettingsValues.java | 3 ++- java/src/com/android/inputmethod/latin/Suggest.java | 12 +++++++----- java/src/com/android/inputmethod/latin/SuggestedWords.java | 9 ++++++--- 6 files changed, 22 insertions(+), 14 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 8d5bc1595..e4ffa7599 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -137,7 +137,7 @@ public class BinaryDictionary extends Dictionary { if (len > 0) { suggestions.add(new SuggestedWordInfo( new String(mOutputChars_bigrams, start, len), - mBigramScores[j], SuggestedWordInfo.KIND_CORRECTION)); + mBigramScores[j], SuggestedWordInfo.KIND_CORRECTION, mDictType)); } } return suggestions; @@ -162,7 +162,7 @@ public class BinaryDictionary extends Dictionary { // TODO: actually get the kind from native code suggestions.add(new SuggestedWordInfo( new String(mOutputChars, start, len), - mScores[j], SuggestedWordInfo.KIND_CORRECTION)); + mScores[j], SuggestedWordInfo.KIND_CORRECTION, mDictType)); } } return suggestions; diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 0a853c4cb..0835450c1 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -34,6 +34,8 @@ public abstract class Dictionary { public static final int NOT_A_PROBABILITY = -1; public static final String TYPE_USER_TYPED = "user_typed"; + public static final String TYPE_APPLICATION_DEFINED = "application_defined"; + public static final String TYPE_HARDCODED = "hardcoded"; // punctuation signs and such public static final String TYPE_MAIN = "main"; public static final String TYPE_CONTACTS = "contacts"; // User dictionary, the system-managed one. diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index e86a657e9..cfecc664a 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -382,7 +382,7 @@ public class ExpandableDictionary extends Dictionary { // the respective size of the typed word and the suggestion if it matters sometime // in the future. suggestions.add(new SuggestedWordInfo(new String(word, 0, depth + 1), finalFreq, - SuggestedWordInfo.KIND_CORRECTION)); + SuggestedWordInfo.KIND_CORRECTION, mDictType)); if (suggestions.size() >= Suggest.MAX_SUGGESTIONS) return false; } if (null != node.mShortcutTargets) { @@ -390,7 +390,7 @@ public class ExpandableDictionary extends Dictionary { for (int shortcutIndex = 0; shortcutIndex < length; ++shortcutIndex) { final char[] shortcut = node.mShortcutTargets.get(shortcutIndex); suggestions.add(new SuggestedWordInfo(new String(shortcut, 0, shortcut.length), - finalFreq, SuggestedWordInfo.KIND_SHORTCUT)); + finalFreq, SuggestedWordInfo.KIND_SHORTCUT, mDictType)); if (suggestions.size() > Suggest.MAX_SUGGESTIONS) return false; } } @@ -665,7 +665,7 @@ public class ExpandableDictionary extends Dictionary { if (freq >= 0) { suggestions.add(new SuggestedWordInfo(new String(mLookedUpString, index, BinaryDictionary.MAX_WORD_LENGTH - index), - freq, SuggestedWordInfo.KIND_CORRECTION)); + freq, SuggestedWordInfo.KIND_CORRECTION, mDictType)); } } } diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index ef423f19b..2cc9b8ce9 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -179,7 +179,8 @@ public class SettingsValues { if (puncs != null) { for (final String puncSpec : puncs) { puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec), - SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED)); + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED, + Dictionary.TYPE_HARDCODED)); } } return new SuggestedWords(puncList, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 9f3df05e7..93e6d6602 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -201,7 +201,6 @@ public class Suggest { final String consideredWord = mTrailingSingleQuotesCount > 0 ? typedWord.substring(0, typedWord.length() - mTrailingSingleQuotesCount) : typedWord; - // Treating USER_TYPED as UNIGRAM suggestion for logging now. LatinImeLogger.onAddSuggestedWord(typedWord, Dictionary.TYPE_USER_TYPED); if (wordComposer.size() <= 1 && isCorrectionEnabled) { @@ -272,16 +271,19 @@ public class Suggest { sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); } suggestionsContainer.add(0, new SuggestedWordInfo(sb.toString(), - SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST)); + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST, + Dictionary.TYPE_WHITELIST)); } else { suggestionsContainer.add(0, new SuggestedWordInfo(whitelistedWord, - SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST)); + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST, + Dictionary.TYPE_WHITELIST)); } } if (!isPrediction) { suggestionsContainer.add(0, new SuggestedWordInfo(typedWord, - SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED)); + SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, + Dictionary.TYPE_USER_TYPED)); } SuggestedWordInfo.removeDups(suggestionsContainer); @@ -403,7 +405,7 @@ public class Suggest { for (int i = trailingSingleQuotesCount - 1; i >= 0; --i) { sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE); } - return new SuggestedWordInfo(sb, wordInfo.mScore, wordInfo.mKind); + return new SuggestedWordInfo(sb, wordInfo.mScore, wordInfo.mKind, wordInfo.mSourceDict); } public void close() { diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 9883cd6bc..f6926f3bb 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -92,7 +92,7 @@ public class SuggestedWords { for (CompletionInfo info : infos) { if (null != info && info.getText() != null) { result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE, - SuggestedWordInfo.KIND_APP_DEFINED)); + SuggestedWordInfo.KIND_APP_DEFINED, Dictionary.TYPE_APPLICATION_DEFINED)); } } return result; @@ -105,7 +105,7 @@ public class SuggestedWords { final ArrayList suggestionsList = new ArrayList(); final HashSet alreadySeen = new HashSet(); suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, - SuggestedWordInfo.KIND_TYPED)); + SuggestedWordInfo.KIND_TYPED, Dictionary.TYPE_USER_TYPED)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { @@ -135,13 +135,16 @@ public class SuggestedWords { public final int mScore; public final int mKind; // one of the KIND_* constants above public final int mCodePointCount; + public final String mSourceDict; private String mDebugString = ""; - public SuggestedWordInfo(final CharSequence word, final int score, final int kind) { + public SuggestedWordInfo(final CharSequence word, final int score, final int kind, + final String sourceDict) { mWordStr = word.toString(); mWord = word; mScore = score; mKind = kind; + mSourceDict = sourceDict; mCodePointCount = StringUtils.codePointCount(mWordStr); } -- cgit v1.2.3-83-g751a From 0a63111821b9377bf37d18f26a9e09618bec128d Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 28 Jun 2012 18:33:46 +0900 Subject: Remove a useless parameter (A29) Change-Id: I52625e707abf61da9b95e542f0814c66b532f483 --- java/src/com/android/inputmethod/latin/LatinIME.java | 2 -- java/src/com/android/inputmethod/latin/SettingsValues.java | 1 - java/src/com/android/inputmethod/latin/Suggest.java | 1 - java/src/com/android/inputmethod/latin/SuggestedWords.java | 3 +-- 4 files changed, 1 insertion(+), 6 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/SettingsValues.java') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8a9e9ee86..e7f547812 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -887,7 +887,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen applicationSuggestedWords, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, - false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, false /* isPrediction */); @@ -1733,7 +1732,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen new SuggestedWords(typedWordAndPreviousSuggestions, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, - false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, true /* isObsoleteSuggestions */, false /* isPrediction */); diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 2cc9b8ce9..aab84fccd 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -186,7 +186,6 @@ public class SettingsValues { return new SuggestedWords(puncList, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, - false /* allowsToBeAutoCorrected */, true /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, false /* isPrediction */); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 69f37dd94..952296227 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -306,7 +306,6 @@ public class Suggest { // rename the attribute or change the value. !isPrediction && !allowsToBeAutoCorrected /* typedWordValid */, !isPrediction && autoCorrectionAvailable /* hasAutoCorrectionCandidate */, - !isPrediction && allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, isPrediction); diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index a740d9ce7..0d64ad321 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -25,7 +25,7 @@ import java.util.HashSet; public class SuggestedWords { public static final SuggestedWords EMPTY = new SuggestedWords( - new ArrayList(0), false, false, false, false, false, false); + new ArrayList(0), false, false, false, false, false); public final boolean mTypedWordValid; public final boolean mHasAutoCorrectionCandidate; @@ -37,7 +37,6 @@ public class SuggestedWords { public SuggestedWords(final ArrayList suggestedWordInfoList, final boolean typedWordValid, final boolean hasAutoCorrectionCandidate, - final boolean allowsToBeAutoCorrected, final boolean isPunctuationSuggestions, final boolean isObsoleteSuggestions, final boolean isPrediction) { -- cgit v1.2.3-83-g751a