Resolve an old TODO.

This is cleaner.

Bug: 17347779
Change-Id: I5b612783b1ec98a1a11401f00d68db49654f3023
This commit is contained in:
Jean Chalard 2014-09-03 19:36:35 +09:00
parent 6888ec0099
commit 6bb6d30344
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.SubtypeSwitcher;
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.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.ScriptUtils;
@ -60,7 +61,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private KeyboardLayoutSet mKeyboardLayoutSet;
// TODO: The following {@link KeyboardTextsSet} should be in {@link KeyboardLayoutSet}.
private final KeyboardTextsSet mKeyboardTextsSet = new KeyboardTextsSet();
private SettingsValues mCurrentSettingsValues;
private KeyboardTheme mKeyboardTheme;
private Context mThemeContext;
@ -120,7 +120,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
builder.setLanguageSwitchKeyEnabled(mLatinIME.shouldShowLanguageSwitchKey());
mKeyboardLayoutSet = builder.build();
mCurrentSettingsValues = settingsValues;
try {
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState);
mKeyboardTextsSet.setLocale(mSubtypeSwitcher.getCurrentSubtypeLocale(), mThemeContext);
@ -144,22 +143,24 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private void setKeyboard(final Keyboard keyboard) {
// 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 Keyboard oldKeyboard = keyboardView.getKeyboard();
keyboardView.setKeyboard(keyboard);
mCurrentInputView.setKeyboardTopPadding(keyboard.mTopPadding);
keyboardView.setKeyPreviewPopupEnabled(
mCurrentSettingsValues.mKeyPreviewPopupOn,
mCurrentSettingsValues.mKeyPreviewPopupDismissDelay);
currentSettingsValues.mKeyPreviewPopupOn,
currentSettingsValues.mKeyPreviewPopupDismissDelay);
keyboardView.setKeyPreviewAnimationParams(
mCurrentSettingsValues.mHasCustomKeyPreviewAnimationParams,
mCurrentSettingsValues.mKeyPreviewShowUpStartXScale,
mCurrentSettingsValues.mKeyPreviewShowUpStartYScale,
mCurrentSettingsValues.mKeyPreviewShowUpDuration,
mCurrentSettingsValues.mKeyPreviewDismissEndXScale,
mCurrentSettingsValues.mKeyPreviewDismissEndYScale,
mCurrentSettingsValues.mKeyPreviewDismissDuration);
currentSettingsValues.mHasCustomKeyPreviewAnimationParams,
currentSettingsValues.mKeyPreviewShowUpStartXScale,
currentSettingsValues.mKeyPreviewShowUpStartYScale,
currentSettingsValues.mKeyPreviewShowUpDuration,
currentSettingsValues.mKeyPreviewDismissEndXScale,
currentSettingsValues.mKeyPreviewDismissEndYScale,
currentSettingsValues.mKeyPreviewDismissDuration);
keyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
final boolean subtypeChanged = (oldKeyboard == null)
|| !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
@ -236,22 +237,13 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS));
}
private void setMainKeyboardFrame() {
mMainKeyboardFrame.setVisibility(hasHardwareKeyboard() ? View.GONE : View.VISIBLE);
private void setMainKeyboardFrame(final SettingsValues settingsValues) {
mMainKeyboardFrame.setVisibility(
settingsValues.mHasHardwareKeyboard ? View.GONE : View.VISIBLE);
mEmojiPalettesView.setVisibility(View.GONE);
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}.
@Override
public void setEmojiKeyboard() {

View file

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

View file

@ -19,6 +19,7 @@ package com.android.inputmethod.latin.settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.preference.PreferenceManager;
@ -368,6 +369,15 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
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) {
return prefs.getBoolean(PREF_KEY_IS_INTERNAL, false);
}

View file

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