diff options
Diffstat (limited to 'java/src')
13 files changed, 226 insertions, 155 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index cf89ef210..1dd7b06dd 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -879,6 +879,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mDrawingHandler.dismissKeyPreview(mKeyPreviewLingerTimeout, tracker); } + public void setSlidingKeyInputPreviewEnabled(final boolean enabled) { + mSlidingKeyInputPreview.setPreviewEnabled(enabled); + } + @Override public void showSlidingKeyInputPreview(final PointerTracker tracker) { locatePreviewPlacerView(); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 1988bb855..d54b98ccc 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -951,12 +951,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element { return; } - if (isShowingMoreKeysPanel()) { - final int translatedX = mMoreKeysPanel.translateX(x); - final int translatedY = mMoreKeysPanel.translateY(y); - mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime); - } - if (sShouldHandleGesture && me != null) { // Add historical points to gesture path. final int pointerIndex = me.findPointerIndex(mPointerId); @@ -971,7 +965,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element { } if (isShowingMoreKeysPanel()) { - // Do not handle sliding keys (or show key pop-ups) when the MoreKeysPanel is visible. + final int translatedX = mMoreKeysPanel.translateX(x); + final int translatedY = mMoreKeysPanel.translateY(y); + mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime); + onMoveKey(x, y); + mDrawingProxy.showSlidingKeyInputPreview(this); return; } onMoveEventInternal(x, y, eventTime); diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java b/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java index 0954a7a5d..28655a930 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingPreviewText.java @@ -157,6 +157,7 @@ public class GestureFloatingPreviewText extends AbstractDrawingPreview { */ protected void updatePreviewPosition() { if (mSuggestedWords.isEmpty() || TextUtils.isEmpty(mSuggestedWords.getWord(0))) { + getDrawingView().invalidate(); return; } final String text = mSuggestedWords.getWord(0); diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java index 322f981c4..37f4e3582 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputPreview.java @@ -18,25 +18,40 @@ package com.android.inputmethod.keyboard.internal; import android.content.res.TypedArray; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Path; import android.view.View; import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.latin.CoordinateUtils; +import com.android.inputmethod.latin.R; /** * Draw rubber band preview graphics during sliding key input. */ public final class SlidingKeyInputPreview extends AbstractDrawingPreview { + private final int mPreviewWidth; + private boolean mShowSlidingKeyInputPreview; - private final int[] mRubberBandFrom = CoordinateUtils.newInstance(); - private final int[] mRubberBandTo = CoordinateUtils.newInstance(); + private final int[] mPreviewFrom = CoordinateUtils.newInstance(); + private final int[] mPreviewTo = CoordinateUtils.newInstance(); + + // TODO: Finalize the rubber band preview implementation. + private final RoundedLine mRoundedLine = new RoundedLine(); + private final Paint mPaint = new Paint(); public SlidingKeyInputPreview(final View drawingView, final TypedArray mainKeyboardViewAttr) { super(drawingView); + final int previewColor = mainKeyboardViewAttr.getColor( + R.styleable.MainKeyboardView_slidingKeyInputPreviewColor, 0); + mPreviewWidth = mainKeyboardViewAttr.getDimensionPixelSize( + R.styleable.MainKeyboardView_slidingKeyInputPreviewWidth, 0); + mPaint.setColor(previewColor); } public void dismissSlidingKeyInputPreview() { mShowSlidingKeyInputPreview = false; + getDrawingView().invalidate(); } /** @@ -45,10 +60,16 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview { */ @Override public void drawPreview(final Canvas canvas) { - if (!isPreviewEnabled() || mShowSlidingKeyInputPreview == false) { + if (!isPreviewEnabled() || !mShowSlidingKeyInputPreview) { return; } - // TODO: Implement rubber band preview + + // TODO: Finalize the rubber band preview implementation. + final int radius = mPreviewWidth / 2; + final Path path = mRoundedLine.makePath( + CoordinateUtils.x(mPreviewFrom), CoordinateUtils.y(mPreviewFrom), radius, + CoordinateUtils.x(mPreviewTo), CoordinateUtils.y(mPreviewTo), radius); + canvas.drawPath(path, mPaint); } /** @@ -61,8 +82,8 @@ public final class SlidingKeyInputPreview extends AbstractDrawingPreview { mShowSlidingKeyInputPreview = false; return; } - tracker.getDownCoordinates(mRubberBandFrom); - tracker.getLastCoordinates(mRubberBandTo); + tracker.getDownCoordinates(mPreviewFrom); + tracker.getLastCoordinates(mPreviewTo); mShowSlidingKeyInputPreview = true; getDrawingView().invalidate(); } diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java index a56c78bcd..f7877226d 100644 --- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java +++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java @@ -72,7 +72,8 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { } public SubtypeLocaleItem(final String localeString) { - this(localeString, SubtypeLocale.getSubtypeLocaleDisplayName(localeString)); + this(localeString, + SubtypeLocale.getSubtypeLocaleDisplayNameInSystemLocale(localeString)); } @Override @@ -103,7 +104,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { if (DEBUG_SUBTYPE_ID) { android.util.Log.d(TAG, String.format("%-6s 0x%08x %11d %s", subtype.getLocale(), subtype.hashCode(), subtype.hashCode(), - SubtypeLocale.getSubtypeDisplayName(subtype))); + SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype))); } if (subtype.containsExtraValueKey(ASCII_CAPABLE)) { items.add(createItem(context, subtype.getLocale())); @@ -205,7 +206,8 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { setDialogTitle(R.string.add_style); setKey(KEY_NEW_SUBTYPE); } else { - final String displayName = SubtypeLocale.getSubtypeDisplayName(subtype); + final String displayName = + SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype); setTitle(displayName); setDialogTitle(displayName); setKey(KEY_PREFIX + subtype.getLocale() + "_" @@ -497,7 +499,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment { final Context context = getActivity(); final Resources res = context.getResources(); final String message = res.getString(R.string.custom_input_style_already_exists, - SubtypeLocale.getSubtypeDisplayName(subtype)); + SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype)); Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6b0d74170..d6487cb0c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -71,7 +71,6 @@ import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.latin.Utils.Stats; import com.android.inputmethod.latin.define.ProductionFlag; @@ -653,6 +652,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction super.onStartInputView(editorInfo, restarting); final KeyboardSwitcher switcher = mKeyboardSwitcher; final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView(); + final SettingsValues currentSettings = mSettings.getCurrent(); if (editorInfo == null) { Log.e(TAG, "Null EditorInfo in onStartInputView()"); @@ -706,7 +706,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting); } - final boolean inputTypeChanged = !mSettings.getCurrent().isSameInputType(editorInfo); + final boolean inputTypeChanged = !currentSettings.isSameInputType(editorInfo); final boolean isDifferentTextField = !restarting || inputTypeChanged; if (isDifferentTextField) { mSubtypeSwitcher.updateParametersOnStartInputView(); @@ -737,12 +737,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mainKeyboardView.closing(); loadSettings(); - if (mSuggest != null && mSettings.getCurrent().mCorrectionEnabled) { - mSuggest.setAutoCorrectionThreshold( - mSettings.getCurrent().mAutoCorrectionThreshold); + if (mSuggest != null && currentSettings.mCorrectionEnabled) { + mSuggest.setAutoCorrectionThreshold(currentSettings.mAutoCorrectionThreshold); } - switcher.loadKeyboard(editorInfo, mSettings.getCurrent()); + switcher.loadKeyboard(editorInfo, currentSettings); } else if (restarting) { // TODO: Come up with a more comprehensive way to reset the keyboard layout when // a keyboard layout set doesn't get reloaded in this method. @@ -764,12 +763,14 @@ public final class LatinIME extends InputMethodService implements KeyboardAction mHandler.cancelDoubleSpacePeriodTimer(); mainKeyboardView.setMainDictionaryAvailability(mIsMainDictionaryAvailable); - mainKeyboardView.setKeyPreviewPopupEnabled(mSettings.getCurrent().mKeyPreviewPopupOn, - mSettings.getCurrent().mKeyPreviewPopupDismissDelay); + mainKeyboardView.setKeyPreviewPopupEnabled(currentSettings.mKeyPreviewPopupOn, + currentSettings.mKeyPreviewPopupDismissDelay); + mainKeyboardView.setSlidingKeyInputPreviewEnabled( + currentSettings.mSlidingKeyInputPreviewEnabled); mainKeyboardView.setGestureHandlingEnabledByUser( - mSettings.getCurrent().mGestureInputEnabled); - mainKeyboardView.setGesturePreviewMode(mSettings.getCurrent().mGesturePreviewTrailEnabled, - mSettings.getCurrent().mGestureFloatingPreviewTextEnabled); + currentSettings.mGestureInputEnabled); + mainKeyboardView.setGesturePreviewMode(currentSettings.mGesturePreviewTrailEnabled, + currentSettings.mGestureFloatingPreviewTextEnabled); // If we have a user dictionary addition in progress, we should check now if we should // replace the previously committed string with the word that has actually been added @@ -1480,6 +1481,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction @Override public void onStartBatchInput() { BatchInputUpdater.getInstance().onStartBatchInput(this); + mHandler.cancelUpdateSuggestionStrip(); mConnection.beginBatchEdit(); if (mWordComposer.isComposingWord()) { if (ProductionFlag.IS_INTERNAL) { diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 408ea4a49..02b44c7f6 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -55,6 +55,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction"; public static final String PREF_GESTURE_SETTINGS = "gesture_typing_settings"; public static final String PREF_GESTURE_INPUT = "gesture_input"; + public static final String PREF_SLIDING_KEY_INPUT_PREVIEW = "pref_sliding_key_input_preview"; public static final String PREF_KEY_LONGPRESS_TIMEOUT = "pref_key_longpress_timeout"; public static final String PREF_VIBRATION_DURATION_SETTINGS = "pref_vibration_duration_settings"; @@ -125,13 +126,49 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang } // Accessed from the settings interface, hence public + public static boolean readKeypressSoundEnabled(final SharedPreferences prefs, + final Resources res) { + return prefs.getBoolean(Settings.PREF_SOUND_ON, + res.getBoolean(R.bool.config_default_sound_enabled)); + } + + public static boolean readVibrationEnabled(final SharedPreferences prefs, + final Resources res) { + final boolean hasVibrator = AudioAndHapticFeedbackManager.getInstance().hasVibrator(); + return hasVibrator && prefs.getBoolean(PREF_VIBRATE_ON, + res.getBoolean(R.bool.config_default_vibration_enabled)); + } + + public static boolean readAutoCorrectEnabled(final String currentAutoCorrectionSetting, + final Resources res) { + final String autoCorrectionOff = res.getString( + R.string.auto_correction_threshold_mode_index_off); + return !currentAutoCorrectionSetting.equals(autoCorrectionOff); + } + + public static boolean readFromBuildConfigIfGestureInputEnabled(final Resources res) { + return res.getBoolean(R.bool.config_gesture_input_enabled_by_build_config); + } + + public static boolean readGestureInputEnabled(final SharedPreferences prefs, + final Resources res) { + return readFromBuildConfigIfGestureInputEnabled(res) + && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true); + } + + public static boolean readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption( + final Resources res) { + return res.getBoolean(R.bool.config_enable_show_option_of_key_preview_popup); + } + public static boolean readKeyPreviewPopupEnabled(final SharedPreferences prefs, final Resources res) { - final boolean showPopupOption = res.getBoolean( - R.bool.config_enable_show_popup_on_keypress_option); - if (!showPopupOption) return res.getBoolean(R.bool.config_default_popup_preview); - return prefs.getBoolean(PREF_POPUP_ON, - res.getBoolean(R.bool.config_default_popup_preview)); + final boolean defaultKeyPreviewPopup = res.getBoolean( + R.bool.config_default_key_preview_popup); + if (!readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) { + return defaultKeyPreviewPopup; + } + return prefs.getBoolean(PREF_POPUP_ON, defaultKeyPreviewPopup); } public static int readKeyPreviewPopupDismissDelay(final SharedPreferences prefs, diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java index 3ba24fb65..edd064c0b 100644 --- a/java/src/com/android/inputmethod/latin/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java @@ -41,7 +41,6 @@ public final class SettingsFragment extends InputMethodSettingsFragment private ListPreference mKeyPreviewPopupDismissDelay; // Use bigrams to predict the next word when there is no input for it yet private CheckBoxPreference mBigramPrediction; - private Preference mDebugSettingsPreference; private void setPreferenceEnabled(final String preferenceKey, final boolean enabled) { final Preference preference = findPreference(preferenceKey); @@ -50,11 +49,14 @@ public final class SettingsFragment extends InputMethodSettingsFragment } } - private void ensureConsistencyOfAutoCorrectionSettings() { - final String autoCorrectionOff = getResources().getString( - R.string.auto_correction_threshold_mode_index_off); - final String currentSetting = mAutoCorrectionThresholdPreference.getValue(); - mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff)); + private static void removePreference(final String preferenceKey, final PreferenceGroup parent) { + if (parent == null) { + return; + } + final Preference preference = parent.findPreference(preferenceKey); + if (preference != null) { + parent.removePreference(preference); + } } @Override @@ -84,22 +86,18 @@ public final class SettingsFragment extends InputMethodSettingsFragment final PreferenceGroup generalSettings = (PreferenceGroup) findPreference(Settings.PREF_GENERAL_SETTINGS); - final PreferenceGroup textCorrectionGroup = - (PreferenceGroup) findPreference(Settings.PREF_CORRECTION_SETTINGS); - final PreferenceGroup gestureTypingSettings = - (PreferenceGroup) findPreference(Settings.PREF_GESTURE_SETTINGS); final PreferenceGroup miscSettings = (PreferenceGroup) findPreference(Settings.PREF_MISC_SETTINGS); - mDebugSettingsPreference = findPreference(Settings.PREF_DEBUG_SETTINGS); - if (mDebugSettingsPreference != null) { + final Preference debugSettings = findPreference(Settings.PREF_DEBUG_SETTINGS); + if (debugSettings != null) { if (ProductionFlag.IS_INTERNAL) { final Intent debugSettingsIntent = new Intent(Intent.ACTION_MAIN); debugSettingsIntent.setClassName( context.getPackageName(), DebugSettingsActivity.class.getName()); - mDebugSettingsPreference.setIntent(debugSettingsIntent); + debugSettings.setIntent(debugSettingsIntent); } else { - miscSettings.removePreference(mDebugSettingsPreference); + miscSettings.removePreference(debugSettings); } } @@ -112,32 +110,26 @@ public final class SettingsFragment extends InputMethodSettingsFragment final PreferenceGroup advancedSettings = (PreferenceGroup) findPreference(Settings.PREF_ADVANCED_SETTINGS); if (!AudioAndHapticFeedbackManager.getInstance().hasVibrator()) { - generalSettings.removePreference(findPreference(Settings.PREF_VIBRATE_ON)); - if (null != advancedSettings) { // Theoretically advancedSettings cannot be null - advancedSettings.removePreference( - findPreference(Settings.PREF_VIBRATION_DURATION_SETTINGS)); - } + removePreference(Settings.PREF_VIBRATE_ON, generalSettings); + removePreference(Settings.PREF_VIBRATION_DURATION_SETTINGS, advancedSettings); } - final boolean showKeyPreviewPopupOption = res.getBoolean( - R.bool.config_enable_show_popup_on_keypress_option); mKeyPreviewPopupDismissDelay = (ListPreference) findPreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); - if (!showKeyPreviewPopupOption) { - generalSettings.removePreference(findPreference(Settings.PREF_POPUP_ON)); - if (null != advancedSettings) { // Theoretically advancedSettings cannot be null - advancedSettings.removePreference(mKeyPreviewPopupDismissDelay); - } + if (!Settings.readFromBuildConfigIfToShowKeyPreviewPopupSettingsOption(res)) { + removePreference(Settings.PREF_POPUP_ON, generalSettings); + removePreference(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, advancedSettings); } else { - final String[] entries = new String[] { - res.getString(R.string.key_preview_popup_dismiss_no_delay), - res.getString(R.string.key_preview_popup_dismiss_default_delay), - }; final String popupDismissDelayDefaultValue = Integer.toString(res.getInteger( R.integer.config_key_preview_linger_timeout)); - mKeyPreviewPopupDismissDelay.setEntries(entries); - mKeyPreviewPopupDismissDelay.setEntryValues( - new String[] { "0", popupDismissDelayDefaultValue }); + mKeyPreviewPopupDismissDelay.setEntries(new String[] { + res.getString(R.string.key_preview_popup_dismiss_no_delay), + res.getString(R.string.key_preview_popup_dismiss_default_delay), + }); + mKeyPreviewPopupDismissDelay.setEntryValues(new String[] { + "0", + popupDismissDelayDefaultValue + }); if (null == mKeyPreviewPopupDismissDelay.getValue()) { mKeyPreviewPopupDismissDelay.setValue(popupDismissDelayDefaultValue); } @@ -148,20 +140,19 @@ public final class SettingsFragment extends InputMethodSettingsFragment setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, Settings.readShowsLanguageSwitchKey(prefs)); + final PreferenceGroup textCorrectionGroup = + (PreferenceGroup) findPreference(Settings.PREF_CORRECTION_SETTINGS); final PreferenceScreen dictionaryLink = (PreferenceScreen) findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); final Intent intent = dictionaryLink.getIntent(); - final int number = context.getPackageManager().queryIntentActivities(intent, 0).size(); // TODO: The experimental version is not supported by the Dictionary Pack Service yet if (ProductionFlag.IS_EXPERIMENTAL || 0 >= number) { textCorrectionGroup.removePreference(dictionaryLink); } - final boolean gestureInputEnabledByBuildConfig = res.getBoolean( - R.bool.config_gesture_input_enabled_by_build_config); - if (!gestureInputEnabledByBuildConfig) { - getPreferenceScreen().removePreference(gestureTypingSettings); + if (!Settings.readFromBuildConfigIfGestureInputEnabled(res)) { + removePreference(Settings.PREF_GESTURE_SETTINGS, getPreferenceScreen()); } setupKeyLongpressTimeoutSettings(prefs, res); @@ -194,23 +185,17 @@ public final class SettingsFragment extends InputMethodSettingsFragment @Override public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { (new BackupManager(getActivity())).dataChanged(); + final Resources res = getResources(); if (key.equals(Settings.PREF_POPUP_ON)) { setPreferenceEnabled(Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY, - prefs.getBoolean(Settings.PREF_POPUP_ON, true)); + Settings.readKeyPreviewPopupEnabled(prefs, res)); } else if (key.equals(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY)) { setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, Settings.readShowsLanguageSwitchKey(prefs)); } else if (key.equals(Settings.PREF_GESTURE_INPUT)) { - final boolean gestureInputEnabledByConfig = getResources().getBoolean( - R.bool.config_gesture_input_enabled_by_build_config); - if (gestureInputEnabledByConfig) { - final boolean gestureInputEnabledByUser = prefs.getBoolean( - Settings.PREF_GESTURE_INPUT, true); - setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, - gestureInputEnabledByUser); - setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, - gestureInputEnabledByUser); - } + final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res); + setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled); + setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled); } ensureConsistencyOfAutoCorrectionSettings(); updateVoiceModeSummary(); @@ -219,6 +204,13 @@ public final class SettingsFragment extends InputMethodSettingsFragment refreshEnablingsOfKeypressSoundAndVibrationSettings(prefs, getResources()); } + private void ensureConsistencyOfAutoCorrectionSettings() { + final String autoCorrectionOff = getResources().getString( + R.string.auto_correction_threshold_mode_index_off); + final String currentSetting = mAutoCorrectionThresholdPreference.getValue(); + mBigramPrediction.setEnabled(!currentSetting.equals(autoCorrectionOff)); + } + private void updateShowCorrectionSuggestionsSummary() { mShowCorrectionSuggestionsPreference.setSummary( getResources().getStringArray(R.array.prefs_suggestion_visibilities) @@ -237,7 +229,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment final StringBuilder styles = new StringBuilder(); for (final InputMethodSubtype subtype : subtypes) { if (styles.length() > 0) styles.append(", "); - styles.append(SubtypeLocale.getSubtypeDisplayName(subtype)); + styles.append(SubtypeLocale.getSubtypeDisplayNameInSystemLocale(subtype)); } customInputStyles.setSummary(styles); } @@ -257,16 +249,10 @@ public final class SettingsFragment extends InputMethodSettingsFragment private void refreshEnablingsOfKeypressSoundAndVibrationSettings( final SharedPreferences sp, final Resources res) { - final boolean hasVibratorHardware = - AudioAndHapticFeedbackManager.getInstance().hasVibrator(); - final boolean vibrateOnByUser = sp.getBoolean(Settings.PREF_VIBRATE_ON, - res.getBoolean(R.bool.config_default_vibration_enabled)); setPreferenceEnabled(Settings.PREF_VIBRATION_DURATION_SETTINGS, - hasVibratorHardware && vibrateOnByUser); - - final boolean soundOn = sp.getBoolean(Settings.PREF_SOUND_ON, - res.getBoolean(R.bool.config_default_sound_enabled)); - setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME, soundOn); + Settings.readVibrationEnabled(sp, res)); + setPreferenceEnabled(Settings.PREF_KEYPRESS_SOUND_VOLUME, + Settings.readKeypressSoundEnabled(sp, res)); } private void setupKeypressVibrationDurationSettings(final SharedPreferences sp, diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 29e79e4cc..728f6b281 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -59,6 +59,7 @@ public final class SettingsValues { public final boolean mGestureInputEnabled; public final boolean mGesturePreviewTrailEnabled; public final boolean mGestureFloatingPreviewTextEnabled; + public final boolean mSlidingKeyInputPreviewEnabled; public final int mKeyLongpressTimeout; // From the input box @@ -103,10 +104,11 @@ public final class SettingsValues { // Get the settings preferences mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); - mVibrateOn = readVibrationEnabled(prefs, res); - mSoundOn = prefs.getBoolean(Settings.PREF_SOUND_ON, - res.getBoolean(R.bool.config_default_sound_enabled)); + mVibrateOn = Settings.readVibrationEnabled(prefs, res); + mSoundOn = Settings.readKeypressSoundEnabled(prefs, res); mKeyPreviewPopupOn = Settings.readKeyPreviewPopupEnabled(prefs, res); + mSlidingKeyInputPreviewEnabled = prefs.getBoolean( + Settings.PREF_SLIDING_KEY_INPUT_PREVIEW, true); 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); @@ -118,7 +120,7 @@ public final class SettingsValues { mShowsLanguageSwitchKey = Settings.readShowsLanguageSwitchKey(prefs); mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true); - mAutoCorrectEnabled = readAutoCorrectEnabled(res, autoCorrectionThresholdRawValue); + mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); // Compute other readable settings @@ -130,10 +132,7 @@ public final class SettingsValues { autoCorrectionThresholdRawValue); mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff); mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain); - final boolean gestureInputEnabledByBuildConfig = res.getBoolean( - R.bool.config_gesture_input_enabled_by_build_config); - mGestureInputEnabled = gestureInputEnabledByBuildConfig - && prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true); + mGestureInputEnabled = Settings.readGestureInputEnabled(prefs, res); mGesturePreviewTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true); mGestureFloatingPreviewTextEnabled = prefs.getBoolean( Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, true); @@ -247,20 +246,6 @@ public final class SettingsValues { throw new RuntimeException("Bug: visibility string is not configured correctly"); } - private static boolean readVibrationEnabled(final SharedPreferences prefs, - final Resources res) { - final boolean hasVibrator = AudioAndHapticFeedbackManager.getInstance().hasVibrator(); - return hasVibrator && prefs.getBoolean(Settings.PREF_VIBRATE_ON, - res.getBoolean(R.bool.config_default_vibration_enabled)); - } - - private static boolean readAutoCorrectEnabled(final Resources res, - final String currentAutoCorrectionSetting) { - final String autoCorrectionOff = res.getString( - R.string.auto_correction_threshold_mode_index_off); - return !currentAutoCorrectionSetting.equals(autoCorrectionOff); - } - private static boolean readBigramPredictionEnabled(final SharedPreferences prefs, final Resources res) { return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean( diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index 068c34ed6..2f26f9296 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -51,20 +51,22 @@ public final class SubtypeLocale { private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap = CollectionUtils.newHashMap(); // Exceptional locale to subtype name resource id map. + private static final HashMap<String, Integer> sExceptionalLocaleToNameIdsMap = + CollectionUtils.newHashMap(); + // Exceptional locale to subtype name with layout resource id map. private static final HashMap<String, Integer> sExceptionalLocaleToWithLayoutNameIdsMap = CollectionUtils.newHashMap(); + private static final String SUBTYPE_NAME_RESOURCE_PREFIX = + "string/subtype_"; private static final String SUBTYPE_NAME_RESOURCE_GENERIC_PREFIX = "string/subtype_generic_"; private static final String SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX = "string/subtype_with_layout_"; private static final String SUBTYPE_NAME_RESOURCE_NO_LANGUAGE_PREFIX = "string/subtype_no_language_"; - // Exceptional locales to display name map. - private static final HashMap<String, String> sExceptionalDisplayNamesMap = - CollectionUtils.newHashMap(); // Keyboard layout set name for the subtypes that don't have a keyboardLayoutSet extra value. // This is for compatibility to keep the same subtype ids as pre-JellyBean. - private static final HashMap<String,String> sLocaleAndExtraValueToKeyboardLayoutSetMap = + private static final HashMap<String, String> sLocaleAndExtraValueToKeyboardLayoutSetMap = CollectionUtils.newHashMap(); private SubtypeLocale() { @@ -98,14 +100,16 @@ public final class SubtypeLocale { final String[] exceptionalLocales = res.getStringArray( R.array.subtype_locale_exception_keys); - final String[] exceptionalDisplayNames = res.getStringArray( - R.array.subtype_locale_exception_values); for (int i = 0; i < exceptionalLocales.length; i++) { final String localeString = exceptionalLocales[i]; - sExceptionalDisplayNamesMap.put(localeString, exceptionalDisplayNames[i]); - final String resourceName = SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX + localeString; + final String resourceName = SUBTYPE_NAME_RESOURCE_PREFIX + localeString; final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME); - sExceptionalLocaleToWithLayoutNameIdsMap.put(localeString, resId); + sExceptionalLocaleToNameIdsMap.put(localeString, resId); + final String resourceNameWithLayout = + SUBTYPE_NAME_RESOURCE_WITH_LAYOUT_PREFIX + localeString; + final int resIdWithLayout = res.getIdentifier( + resourceNameWithLayout, null, RESOURCE_PACKAGE_NAME); + sExceptionalLocaleToWithLayoutNameIdsMap.put(localeString, resIdWithLayout); } final String[] keyboardLayoutSetMap = res.getStringArray( @@ -124,7 +128,7 @@ public final class SubtypeLocale { } public static boolean isExceptionalLocale(final String localeString) { - return sExceptionalLocaleToWithLayoutNameIdsMap.containsKey(localeString); + return sExceptionalLocaleToNameIdsMap.containsKey(localeString); } private static final String getNoLanguageLayoutKey(final String keyboardLayoutName) { @@ -143,13 +147,33 @@ public final class SubtypeLocale { return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId; } + public static String getSubtypeLocaleDisplayNameInSystemLocale(final String localeString) { + final Locale displayLocale = sResources.getConfiguration().locale; + return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale); + } + public static String getSubtypeLocaleDisplayName(final String localeString) { - final String exceptionalValue = sExceptionalDisplayNamesMap.get(localeString); - if (exceptionalValue != null) { - return exceptionalValue; - } + final Locale displayLocale = LocaleUtils.constructLocaleFromString(localeString); + return getSubtypeLocaleDisplayNameInternal(localeString, displayLocale); + } + + private static String getSubtypeLocaleDisplayNameInternal(final String localeString, + final Locale displayLocale) { final Locale locale = LocaleUtils.constructLocaleFromString(localeString); - return StringUtils.toTitleCase(locale.getDisplayName(locale), locale); + final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString); + final String displayName; + if (exceptionalNameResId != null) { + final RunInLocale<String> getExceptionalName = new RunInLocale<String>() { + @Override + protected String job(final Resources res) { + return res.getString(exceptionalNameResId); + } + }; + displayName = getExceptionalName.runInLocale(sResources, displayLocale); + } else { + displayName = locale.getDisplayName(displayLocale); + } + return StringUtils.toTitleCase(displayName, displayLocale); } // InputMethodSubtype's display name in its locale. @@ -165,24 +189,36 @@ public final class SubtypeLocale { // zz qwerty F No language (QWERTY) in system locale // fr qwertz T Français (QWERTZ) // de qwerty T Deutsch (QWERTY) - // en_US azerty T English (US) (AZERTY) + // en_US azerty T English (US) (AZERTY) exception // zz azerty T No language (AZERTY) in system locale - private static String getReplacementString(final InputMethodSubtype subtype) { + private static String getReplacementString(final InputMethodSubtype subtype, + final Locale displayLocale) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && subtype.containsExtraValueKey(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)) { return subtype.getExtraValueOf(UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME); } else { - return getSubtypeLocaleDisplayName(subtype.getLocale()); + return getSubtypeLocaleDisplayNameInternal(subtype.getLocale(), displayLocale); } } + public static String getSubtypeDisplayNameInSystemLocale(final InputMethodSubtype subtype) { + final Locale subtypeLocale = sResources.getConfiguration().locale; + return getSubtypeDisplayNameInternal(subtype, subtypeLocale); + } + public static String getSubtypeDisplayName(final InputMethodSubtype subtype) { - final String replacementString = getReplacementString(subtype); + final Locale subtypeLocale = LocaleUtils.constructLocaleFromString(subtype.getLocale()); + return getSubtypeDisplayNameInternal(subtype, subtypeLocale); + } + + private static String getSubtypeDisplayNameInternal(final InputMethodSubtype subtype, + final Locale displayLocale) { + final String replacementString = getReplacementString(subtype, displayLocale); final int nameResId = subtype.getNameResId(); final RunInLocale<String> getSubtypeName = new RunInLocale<String>() { @Override - protected String job(Resources res) { + protected String job(final Resources res) { try { return res.getString(nameResId, replacementString); } catch (Resources.NotFoundException e) { @@ -197,8 +233,9 @@ public final class SubtypeLocale { } }; final Locale locale = isNoLanguage(subtype) - ? sResources.getConfiguration().locale : getSubtypeLocale(subtype); - return getSubtypeName.runInLocale(sResources, locale); + ? sResources.getConfiguration().locale : displayLocale; + return StringUtils.toTitleCase( + getSubtypeName.runInLocale(sResources, locale), locale); } public static boolean isNoLanguage(final InputMethodSubtype subtype) { diff --git a/java/src/com/android/inputmethod/research/FixedLogBuffer.java b/java/src/com/android/inputmethod/research/FixedLogBuffer.java index 73f284a73..78dc59562 100644 --- a/java/src/com/android/inputmethod/research/FixedLogBuffer.java +++ b/java/src/com/android/inputmethod/research/FixedLogBuffer.java @@ -61,7 +61,7 @@ public class FixedLogBuffer extends LogBuffer { */ @Override public void shiftIn(final LogUnit newLogUnit) { - if (newLogUnit.getWord() == null) { + if (!newLogUnit.hasWord()) { // This LogUnit isn't a word, so it doesn't count toward the word-limit. super.shiftIn(newLogUnit); return; @@ -153,8 +153,7 @@ public class FixedLogBuffer extends LogBuffer { for (int i = 0; i < length && n > 0; i++) { final LogUnit logUnit = logUnits.get(i); list.add(logUnit); - final String word = logUnit.getWord(); - if (word != null) { + if (logUnit.hasWord()) { n--; } } diff --git a/java/src/com/android/inputmethod/research/LogUnit.java b/java/src/com/android/inputmethod/research/LogUnit.java index 0234bbc5b..638b7d9d4 100644 --- a/java/src/com/android/inputmethod/research/LogUnit.java +++ b/java/src/com/android/inputmethod/research/LogUnit.java @@ -286,7 +286,7 @@ import java.util.Map; * string. */ public void setWord(final String word) { - if (mWord != null) { + if (hasWord()) { // The word was already set once, and it is now being changed. See if the new word // is close to the old word. If so, then the change is probably a typo correction. // If not, the user may have decided to enter a different word, so flag it. @@ -310,7 +310,7 @@ import java.util.Map; } public boolean hasWord() { - return mWord != null; + return mWord != null && !TextUtils.isEmpty(mWord.trim()); } public void setMayContainDigit() { diff --git a/java/src/com/android/inputmethod/research/MainLogBuffer.java b/java/src/com/android/inputmethod/research/MainLogBuffer.java index 57d5c41d7..3a87bf1df 100644 --- a/java/src/com/android/inputmethod/research/MainLogBuffer.java +++ b/java/src/com/android/inputmethod/research/MainLogBuffer.java @@ -117,20 +117,19 @@ public abstract class MainLogBuffer extends FixedLogBuffer { if (IS_LOGGING_EVERYTHING) { if (mIsStopping) { return true; - } else { - // Only check that it is the right length. If not, wait for later words to make - // complete n-grams. - int numWordsInLogUnitList = 0; - final int length = logUnits.size(); - for (int i = 0; i < length; i++) { - final LogUnit logUnit = logUnits.get(i); - final String word = logUnit.getWord(); - if (word != null) { - numWordsInLogUnitList++; - } + } + // Only check that it is the right length. If not, wait for later words to make + // complete n-grams. + int numWordsInLogUnitList = 0; + final int length = logUnits.size(); + for (int i = 0; i < length; i++) { + final LogUnit logUnit = logUnits.get(i); + final String word = logUnit.getWord(); + if (word != null) { + numWordsInLogUnitList++; } - return numWordsInLogUnitList >= minNGramSize; } + return numWordsInLogUnitList >= minNGramSize; } // Check that we are not sampling too frequently. Having sampled recently might disclose @@ -157,14 +156,14 @@ public abstract class MainLogBuffer extends FixedLogBuffer { final int length = logUnits.size(); for (int i = 0; i < length; i++) { final LogUnit logUnit = logUnits.get(i); - final String word = logUnit.getWord(); - if (word == null) { + if (!logUnit.hasWord()) { // Digits outside words are a privacy threat. if (logUnit.mayContainDigit()) { return false; } } else { numWordsInLogUnitList++; + final String word = logUnit.getWord(); // Words not in the dictionary are a privacy threat. if (ResearchLogger.hasLetters(word) && !(dictionary.isValidWord(word))) { if (DEBUG) { |