am cb077f75: Merge "Resolve an old TODO." into lmp-dev

* commit 'cb077f75ac750d50c305ac5da20d81df5003907a':
  Resolve an old TODO.
This commit is contained in:
Jean Chalard 2014-09-08 09:18:13 +00:00 committed by Android Git Automerger
commit 1f74ba178b
4 changed files with 37 additions and 30 deletions

View file

@ -38,6 +38,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager; import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.WordComposer; import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.ScriptUtils; import com.android.inputmethod.latin.utils.ScriptUtils;
@ -60,7 +61,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private KeyboardLayoutSet mKeyboardLayoutSet; private KeyboardLayoutSet mKeyboardLayoutSet;
// TODO: The following {@link KeyboardTextsSet} should be in {@link KeyboardLayoutSet}. // TODO: The following {@link KeyboardTextsSet} should be in {@link KeyboardLayoutSet}.
private final KeyboardTextsSet mKeyboardTextsSet = new KeyboardTextsSet(); private final KeyboardTextsSet mKeyboardTextsSet = new KeyboardTextsSet();
private SettingsValues mCurrentSettingsValues;
private KeyboardTheme mKeyboardTheme; private KeyboardTheme mKeyboardTheme;
private Context mThemeContext; private Context mThemeContext;
@ -120,7 +120,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey); builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey()); builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
mKeyboardLayoutSet = builder.build(); mKeyboardLayoutSet = builder.build();
mCurrentSettingsValues = settingsValues;
try { try {
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState); mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState);
mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocale(), mThemeContext); mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocale(), mThemeContext);
@ -144,22 +143,24 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private void setKeyboard(final Keyboard keyboard) { private void setKeyboard(final Keyboard keyboard) {
// Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}. // Make {@link MainKeyboardView} visible and hide {@link EmojiPalettesView}.
setMainKeyboardFrame(); final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent();
setMainKeyboardFrame(currentSettingsValues);
// TODO: pass this object to setKeyboard instead of getting the current values.
final MainKeyboardView keyboardView = mKeyboardView; final MainKeyboardView keyboardView = mKeyboardView;
final Keyboard oldKeyboard = keyboardView.getKeyboard(); final Keyboard oldKeyboard = keyboardView.getKeyboard();
keyboardView.setKeyboard(keyboard); keyboardView.setKeyboard(keyboard);
mCurrentInputView.setKeyboardTopPadding(keyboard.mTopPadding); mCurrentInputView.setKeyboardTopPadding(keyboard.mTopPadding);
keyboardView.setKeyPreviewPopupEnabled( keyboardView.setKeyPreviewPopupEnabled(
mCurrentSettingsValues.mKeyPreviewPopupOn, currentSettingsValues.mKeyPreviewPopupOn,
mCurrentSettingsValues.mKeyPreviewPopupDismissDelay); currentSettingsValues.mKeyPreviewPopupDismissDelay);
keyboardView.setKeyPreviewAnimationParams( keyboardView.setKeyPreviewAnimationParams(
mCurrentSettingsValues.mHasCustomKeyPreviewAnimationParams, currentSettingsValues.mHasCustomKeyPreviewAnimationParams,
mCurrentSettingsValues.mKeyPreviewShowUpStartXScale, currentSettingsValues.mKeyPreviewShowUpStartXScale,
mCurrentSettingsValues.mKeyPreviewShowUpStartYScale, currentSettingsValues.mKeyPreviewShowUpStartYScale,
mCurrentSettingsValues.mKeyPreviewShowUpDuration, currentSettingsValues.mKeyPreviewShowUpDuration,
mCurrentSettingsValues.mKeyPreviewDismissEndXScale, currentSettingsValues.mKeyPreviewDismissEndXScale,
mCurrentSettingsValues.mKeyPreviewDismissEndYScale, currentSettingsValues.mKeyPreviewDismissEndYScale,
mCurrentSettingsValues.mKeyPreviewDismissDuration); currentSettingsValues.mKeyPreviewDismissDuration);
keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
final boolean subtypeChanged = (oldKeyboard == null) final boolean subtypeChanged = (oldKeyboard == null)
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale); || !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
@ -236,22 +237,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS));
} }
private void setMainKeyboardFrame() { private void setMainKeyboardFrame(final SettingsValues settingsValues) {
mMainKeyboardFrame.setVisibility(hasHardwareKeyboard() ? View.GONE : View.VISIBLE); mMainKeyboardFrame.setVisibility(
settingsValues.mHasHardwareKeyboard ? View.GONE : View.VISIBLE);
mEmojiPalettesView.setVisibility(View.GONE); mEmojiPalettesView.setVisibility(View.GONE);
mEmojiPalettesView.stopEmojiPalettes(); mEmojiPalettesView.stopEmojiPalettes();
} }
// TODO: Move this boolean to a member of {@link SettingsValues} and reset it
// at {@link LatinIME#onConfigurationChanged(Configuration)}.
public boolean hasHardwareKeyboard() {
// Copied from {@link InputMethodServce#onEvaluateInputViewShown()}.
final Configuration config = mLatinIME.getResources().getConfiguration();
final boolean noHardwareKeyboard = config.keyboard == Configuration.KEYBOARD_NOKEYS
|| config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES;
return !noHardwareKeyboard;
}
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setEmojiKeyboard() { public void setEmojiKeyboard() {

View file

@ -1074,12 +1074,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public void onComputeInsets(final InputMethodService.Insets outInsets) { public void onComputeInsets(final InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets); super.onComputeInsets(outInsets);
final SettingsValues settingsValues = mSettings.getCurrent();
final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView(); final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
if (visibleKeyboardView == null || !hasSuggestionStripView()) { if (visibleKeyboardView == null || !hasSuggestionStripView()) {
return; return;
} }
final int inputHeight = mInputView.getHeight(); final int inputHeight = mInputView.getHeight();
final boolean hasHardwareKeyboard = mKeyboardSwitcher.hasHardwareKeyboard(); final boolean hasHardwareKeyboard = settingsValues.mHasHardwareKeyboard;
if (hasHardwareKeyboard && visibleKeyboardView.getVisibility() == View.GONE) { if (hasHardwareKeyboard && visibleKeyboardView.getVisibility() == View.GONE) {
// If there is a hardware keyboard and a visible software keyboard view has been hidden, // If there is a hardware keyboard and a visible software keyboard view has been hidden,
// no visual element will be shown on the screen. // no visual element will be shown on the screen.
@ -1115,7 +1116,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public boolean onShowInputRequested(final int flags, final boolean configChange) { public boolean onShowInputRequested(final int flags, final boolean configChange) {
if ((flags & InputMethod.SHOW_EXPLICIT) == 0 && mKeyboardSwitcher.hasHardwareKeyboard()) { final SettingsValues settingsValues = mSettings.getCurrent();
if ((flags & InputMethod.SHOW_EXPLICIT) == 0 && settingsValues.mHasHardwareKeyboard) {
// Even when IME is implicitly shown and physical keyboard is connected, we should // Even when IME is implicitly shown and physical keyboard is connected, we should
// show {@link InputView}. // show {@link InputView}.
// See {@link InputMethodService#onShowInputRequested(int,boolean)}. // See {@link InputMethodService#onShowInputRequested(int,boolean)}.
@ -1126,7 +1128,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override @Override
public boolean onEvaluateFullscreenMode() { public boolean onEvaluateFullscreenMode() {
if (mKeyboardSwitcher.hasHardwareKeyboard()) { final SettingsValues settingsValues = mSettings.getCurrent();
if (settingsValues.mHasHardwareKeyboard) {
// If there is a hardware keyboard, disable full screen mode. // If there is a hardware keyboard, disable full screen mode.
return false; return false;
} }

View file

@ -19,6 +19,7 @@ package com.android.inputmethod.latin.settings;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -368,6 +369,15 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return prefs.getBoolean(PREF_SHOW_SETUP_WIZARD_ICON, false); return prefs.getBoolean(PREF_SHOW_SETUP_WIZARD_ICON, false);
} }
public static boolean readHasHardwareKeyboard(final Configuration conf) {
// The standard way of finding out whether we have a hardware keyboard. This code is taken
// from InputMethodService#onEvaluateInputShown, which canonically determines this.
// In a nutshell, we have a keyboard if the configuration says the type of hardware keyboard
// is NOKEYS and if it's not hidden (e.g. folded inside the device).
return conf.keyboard != Configuration.KEYBOARD_NOKEYS
&& conf.hardKeyboardHidden != Configuration.HARDKEYBOARDHIDDEN_YES;
}
public static boolean isInternal(final SharedPreferences prefs) { public static boolean isInternal(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_KEY_IS_INTERNAL, false); return prefs.getBoolean(PREF_KEY_IS_INTERNAL, false);
} }

View file

@ -52,7 +52,10 @@ public final class SettingsValues {
public final SpacingAndPunctuations mSpacingAndPunctuations; public final SpacingAndPunctuations mSpacingAndPunctuations;
public final int mDelayInMillisecondsToUpdateOldSuggestions; public final int mDelayInMillisecondsToUpdateOldSuggestions;
public final long mDoubleSpacePeriodTimeout; public final long mDoubleSpacePeriodTimeout;
// From configuration:
public final Locale mLocale;
public final boolean mHasHardwareKeyboard;
public final int mDisplayOrientation;
// From preferences, in the same order as xml/prefs.xml: // From preferences, in the same order as xml/prefs.xml:
public final boolean mAutoCap; public final boolean mAutoCap;
public final boolean mVibrateOn; public final boolean mVibrateOn;
@ -73,7 +76,6 @@ public final class SettingsValues {
public final boolean mSlidingKeyInputPreviewEnabled; public final boolean mSlidingKeyInputPreviewEnabled;
public final boolean mPhraseGestureEnabled; public final boolean mPhraseGestureEnabled;
public final int mKeyLongpressTimeout; public final int mKeyLongpressTimeout;
public final Locale mLocale;
public final boolean mEnableMetricsLogging; public final boolean mEnableMetricsLogging;
public final boolean mShouldShowUiToAcceptTypedWord; public final boolean mShouldShowUiToAcceptTypedWord;
@ -88,7 +90,6 @@ public final class SettingsValues {
public final float mAutoCorrectionThreshold; public final float mAutoCorrectionThreshold;
public final boolean mAutoCorrectionEnabledPerUserSettings; public final boolean mAutoCorrectionEnabledPerUserSettings;
private final boolean mSuggestionsEnabledPerUserSettings; private final boolean mSuggestionsEnabledPerUserSettings;
public final int mDisplayOrientation;
private final AsyncResultHolder<AppWorkaroundsUtils> mAppWorkarounds; private final AsyncResultHolder<AppWorkaroundsUtils> mAppWorkarounds;
// Setting values for additional features // Setting values for additional features
@ -152,6 +153,7 @@ public final class SettingsValues {
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true); mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
mShouldShowUiToAcceptTypedWord = Settings.HAS_UI_TO_ACCEPT_TYPED_WORD mShouldShowUiToAcceptTypedWord = Settings.HAS_UI_TO_ACCEPT_TYPED_WORD
&& prefs.getBoolean(DebugSettings.PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD, true); && prefs.getBoolean(DebugSettings.PREF_SHOW_UI_TO_ACCEPT_TYPED_WORD, true);