diff options
Diffstat (limited to 'java/src')
3 files changed, 30 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 16f27b499..35734fb87 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -157,6 +157,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mKeyboardView.setKeyPreviewPopupEnabled( SettingsValues.isKeyPreviewPopupEnabled(mPrefs, mResources), SettingsValues.getKeyPreviewPopupDismissDelay(mPrefs, mResources)); + mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); final boolean localeChanged = (oldKeyboard == null) || !keyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale); if (keyboard instanceof LatinKeyboard) { @@ -168,7 +169,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mKeyboardView.updateSpacebar(); latinKeyboard.updateSpacebarLanguage(0.0f, mSubtypeSwitcher.needsToDisplayLanguage(latinKeyboard.mId.mLocale)); - latinKeyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); } updateShiftState(); mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged); @@ -411,12 +411,8 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, } public void onNetworkStateChanged() { - final LatinKeyboard keyboard = getLatinKeyboard(); - if (keyboard == null) return; - final Key updatedKey = keyboard.updateShortcutKey( - SubtypeSwitcher.getInstance().isShortcutImeReady()); - if (updatedKey != null && mKeyboardView != null) { - mKeyboardView.invalidateKey(updatedKey); + if (mKeyboardView != null) { + mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady()); } } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 29791108d..50a8d64ce 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -60,11 +60,6 @@ public class LatinKeyboard extends Keyboard { private boolean mNeedsToDisplayLanguage; private float mSpacebarTextFadeFactor = 0.0f; - /* Shortcut key and its icons if available */ - private final Key mShortcutKey; - private final Drawable mEnabledShortcutIcon; - private final Drawable mDisabledShortcutIcon; - // Height in space key the language name will be drawn. (proportional to space key height) public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f; // If the full language name needs to be smaller than this value to be drawn on space key, @@ -79,16 +74,13 @@ public class LatinKeyboard extends Keyboard { mSpaceKey = getKey(CODE_SPACE); mSpaceIcon = (mSpaceKey != null) ? mSpaceKey.getIcon() : null; - mShortcutKey = getKey(CODE_SHORTCUT); - mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null; - + // TODO: Move these to LatinKeyboardView attributes. final TypedArray a = context.obtainStyledAttributes( null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard); mAutoCorrectionSpacebarLedEnabled = a.getBoolean( R.styleable.LatinKeyboard_autoCorrectionSpacebarLedEnabled, false); mAutoCorrectionSpacebarLedIcon = a.getDrawable( R.styleable.LatinKeyboard_autoCorrectionSpacebarLedIcon); - mDisabledShortcutIcon = a.getDrawable(R.styleable.LatinKeyboard_disabledShortcutIcon); final float spacebarTextRatio = a.getFraction(R.styleable.LatinKeyboard_spacebarTextRatio, 1000, 1000, 1) / 1000.0f; final int keyHeight = mMostCommonKeyHeight - mVerticalGap; @@ -131,15 +123,6 @@ public class LatinKeyboard extends Keyboard { return newColor; } - // TODO: Move this drawing method to LatinKeyboardView. - public Key updateShortcutKey(boolean available) { - if (mShortcutKey == null) - return null; - mShortcutKey.setEnabled(available); - mShortcutKey.setIcon(available ? mEnabledShortcutIcon : mDisabledShortcutIcon); - return mShortcutKey; - } - // TODO: Get rid of this method public boolean needsAutoCorrectionSpacebarLed() { return mAutoCorrectionSpacebarLedEnabled; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 55fc5f92a..81f8640e9 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -19,8 +19,10 @@ package com.android.inputmethod.keyboard; import android.content.Context; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.drawable.Drawable; import android.os.Message; import android.text.TextUtils; import android.util.AttributeSet; @@ -65,6 +67,14 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke private final boolean mIsSpacebarTriggeringPopupByLongPress; private boolean mMultipleEnabledIMEsOrSubtypes; + /* Shortcut key and its icons if available */ + private Key mShortcutKey; + // TODO: Remove this variable, use KeyboardIconsSet instead. + private Drawable mEnabledShortcutIcon; + // TODO: Remove this variable and LatinKeyboardView.disabledShortcutIcon attribute. + // This should be moved to KeyboardIconsSet. + private final Drawable mDisabledShortcutIcon; + private final SuddenJumpingTouchEventHandler mTouchScreenRegulator; // Timing constants @@ -228,7 +238,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } public LatinKeyboardView(Context context, AttributeSet attrs) { - this(context, attrs, R.attr.keyboardViewStyle); + this(context, attrs, R.attr.latinKeyboardViewStyle); } public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) { @@ -256,6 +266,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final int longPressSpaceKeyTimeout = res.getInteger(R.integer.config_long_press_space_key_timeout); mIsSpacebarTriggeringPopupByLongPress = (longPressSpaceKeyTimeout > 0); + + final TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.LatinKeyboardView, defStyle, R.style.LatinKeyboardView); + mDisabledShortcutIcon = a.getDrawable(R.styleable.LatinKeyboardView_disabledShortcutIcon); + a.recycle(); } public void startIgnoringDoubleTap() { @@ -310,6 +325,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke PointerTracker.setKeyDetector(mKeyDetector); mTouchScreenRegulator.setKeyboard(keyboard); mMoreKeysPanelCache.clear(); + + mShortcutKey = keyboard.getKey(Keyboard.CODE_SHORTCUT); + mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null; } /** @@ -695,6 +713,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke return false; } + public void updateShortcutKey(boolean available) { + if (mShortcutKey == null) return; + mShortcutKey.setEnabled(available); + mShortcutKey.setIcon(available ? mEnabledShortcutIcon : mDisabledShortcutIcon); + invalidateKey(mShortcutKey); + } + public void updateSpacebar() { mMultipleEnabledIMEsOrSubtypes = Utils.hasMultipleEnabledIMEsOrSubtypes( true /* include aux subtypes */); |