diff options
Diffstat (limited to 'java/src')
6 files changed, 169 insertions, 182 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index af54fb674..618d38962 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -58,7 +58,9 @@ public class Key implements Comparable<Key> { private final String mHintLabel; /** Flags of the label */ private final int mLabelFlags; - private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08; + private static final int LABEL_FLAGS_ALIGN_HINT_LABEL_TO_BOTTOM = 0x02; + private static final int LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM = 0x04; + private static final int LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER = 0x08; // Font typeface specification. private static final int LABEL_FLAGS_FONT_MASK = 0x30; private static final int LABEL_FLAGS_FONT_NORMAL = 0x10; @@ -69,7 +71,6 @@ public class Key implements Comparable<Key> { private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LETTER_RATIO = 0x40; private static final int LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO = 0x80; private static final int LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO = 0xC0; - private static final int LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO = 0x100; private static final int LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO = 0x140; // End of key text ratio mask enum values private static final int LABEL_FLAGS_HAS_POPUP_HINT = 0x200; @@ -123,9 +124,10 @@ public class Key implements Comparable<Key> { public static final int BACKGROUND_TYPE_EMPTY = 0; public static final int BACKGROUND_TYPE_NORMAL = 1; public static final int BACKGROUND_TYPE_FUNCTIONAL = 2; - public static final int BACKGROUND_TYPE_ACTION = 3; - public static final int BACKGROUND_TYPE_STICKY_OFF = 4; - public static final int BACKGROUND_TYPE_STICKY_ON = 5; + public static final int BACKGROUND_TYPE_STICKY_OFF = 3; + public static final int BACKGROUND_TYPE_STICKY_ON = 4; + public static final int BACKGROUND_TYPE_ACTION = 5; + public static final int BACKGROUND_TYPE_CUSTOM_ACTION = 6; private final int mActionFlags; private static final int ACTION_FLAGS_IS_REPEATABLE = 0x01; @@ -483,9 +485,10 @@ public class Key implements Comparable<Key> { case BACKGROUND_TYPE_EMPTY: return "empty"; case BACKGROUND_TYPE_NORMAL: return "normal"; case BACKGROUND_TYPE_FUNCTIONAL: return "functional"; - case BACKGROUND_TYPE_ACTION: return "action"; case BACKGROUND_TYPE_STICKY_OFF: return "stickyOff"; case BACKGROUND_TYPE_STICKY_ON: return "stickyOn"; + case BACKGROUND_TYPE_ACTION: return "action"; + case BACKGROUND_TYPE_CUSTOM_ACTION: return "customAction"; default: return null; } } @@ -577,8 +580,6 @@ public class Key implements Comparable<Key> { return params.mLargeLetterSize; case LABEL_FLAGS_FOLLOW_KEY_LABEL_RATIO: return params.mLabelSize; - case LABEL_FLAGS_FOLLOW_KEY_LARGE_LABEL_RATIO: - return params.mLargeLabelSize; case LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO: return params.mHintLabelSize; default: // No follow key ratio flag specified. @@ -641,8 +642,16 @@ public class Key implements Comparable<Key> { return Typeface.DEFAULT_BOLD; } - public final boolean isAlignLeftOfCenter() { - return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0; + public final boolean isAlignHintLabelToBottom(final int defaultFlags) { + return ((mLabelFlags | defaultFlags) & LABEL_FLAGS_ALIGN_HINT_LABEL_TO_BOTTOM) != 0; + } + + public final boolean isAlignIconToBottom() { + return (mLabelFlags & LABEL_FLAGS_ALIGN_ICON_TO_BOTTOM) != 0; + } + + public final boolean isAlignLabelOffCenter() { + return (mLabelFlags & LABEL_FLAGS_ALIGN_LABEL_OFF_CENTER) != 0; } public final boolean hasPopupHint() { @@ -814,47 +823,37 @@ public class Key implements Comparable<Key> { return dx * dx + dy * dy; } - private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_ON = { - android.R.attr.state_checkable, - android.R.attr.state_checked - }; - - private final static int[] KEY_STATE_PRESSED_HIGHLIGHT_ON = { - android.R.attr.state_pressed, - android.R.attr.state_checkable, - android.R.attr.state_checked - }; - - private final static int[] KEY_STATE_NORMAL_HIGHLIGHT_OFF = { - android.R.attr.state_checkable - }; + static class KeyBackgroundState { + private final int[] mReleasedState; + private final int[] mPressedState; - private final static int[] KEY_STATE_PRESSED_HIGHLIGHT_OFF = { - android.R.attr.state_pressed, - android.R.attr.state_checkable - }; - - private final static int[] KEY_STATE_NORMAL = { - }; - - private final static int[] KEY_STATE_PRESSED = { - android.R.attr.state_pressed - }; - - private final static int[] KEY_STATE_EMPTY = { - android.R.attr.state_empty - }; + private KeyBackgroundState(final int ... attrs) { + mReleasedState = attrs; + mPressedState = Arrays.copyOf(attrs, attrs.length + 1); + mPressedState[attrs.length] = android.R.attr.state_pressed; + } - // action normal state (with properties) - private static final int[] KEY_STATE_ACTIVE_NORMAL = { - android.R.attr.state_active - }; + public int[] getState(final boolean pressed) { + return pressed ? mPressedState : mReleasedState; + } - // action pressed state (with properties) - private static final int[] KEY_STATE_ACTIVE_PRESSED = { - android.R.attr.state_active, - android.R.attr.state_pressed - }; + public static final KeyBackgroundState[] STATES = { + // 0: BACKGROUND_TYPE_EMPTY + new KeyBackgroundState(android.R.attr.state_empty), + // 1: BACKGROUND_TYPE_NORMAL + new KeyBackgroundState(), + // 2: BACKGROUND_TYPE_FUNCTIONAL + new KeyBackgroundState(), + // 3: BACKGROUND_TYPE_STICKY_OFF + new KeyBackgroundState(android.R.attr.state_checkable), + // 4: BACKGROUND_TYPE_STICKY_ON + new KeyBackgroundState(android.R.attr.state_checkable, android.R.attr.state_checked), + // 5: BACKGROUND_TYPE_ACTION + new KeyBackgroundState(android.R.attr.state_active), + // 6: BACKGROUND_TYPE_CUSTOM_ACTION + new KeyBackgroundState(android.R.attr.state_active, android.R.attr.state_checked) + }; + } /** * Returns the background drawable for the key, based on the current state and type of the key. @@ -871,28 +870,8 @@ public class Key implements Comparable<Key> { } else { background = keyBackground; } - final int[] stateSet; - switch (mBackgroundType) { - case BACKGROUND_TYPE_ACTION: - stateSet = mPressed ? KEY_STATE_ACTIVE_PRESSED : KEY_STATE_ACTIVE_NORMAL; - break; - case BACKGROUND_TYPE_STICKY_OFF: - stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_OFF : KEY_STATE_NORMAL_HIGHLIGHT_OFF; - break; - case BACKGROUND_TYPE_STICKY_ON: - stateSet = mPressed ? KEY_STATE_PRESSED_HIGHLIGHT_ON : KEY_STATE_NORMAL_HIGHLIGHT_ON; - break; - case BACKGROUND_TYPE_EMPTY: - stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_EMPTY; - break; - case BACKGROUND_TYPE_FUNCTIONAL: - stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; - break; - default: /* BACKGROUND_TYPE_NORMAL */ - stateSet = mPressed ? KEY_STATE_PRESSED : KEY_STATE_NORMAL; - break; - } - background.setState(stateSet); + final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mPressed); + background.setState(state); return background; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 5af0be649..075cd901d 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -48,6 +48,7 @@ import java.util.HashSet; * @attr ref R.styleable#KeyboardView_functionalKeyBackground * @attr ref R.styleable#KeyboardView_spacebarBackground * @attr ref R.styleable#KeyboardView_spacebarIconWidthRatio + * @attr ref R.styleable#Keyboard_Key_keyLabelFlags * @attr ref R.styleable#KeyboardView_keyHintLetterPadding * @attr ref R.styleable#KeyboardView_keyPopupHintLetter * @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding @@ -62,6 +63,8 @@ import java.util.HashSet; * @attr ref R.styleable#Keyboard_Key_keyHintLetterRatio * @attr ref R.styleable#Keyboard_Key_keyShiftedLetterHintRatio * @attr ref R.styleable#Keyboard_Key_keyHintLabelRatio + * @attr ref R.styleable#Keyboard_Key_keyLabelOffCenterRatio + * @attr ref R.styleable#Keyboard_Key_keyHintLabelOffCenterRatio * @attr ref R.styleable#Keyboard_Key_keyPreviewTextRatio * @attr ref R.styleable#Keyboard_Key_keyTextColor * @attr ref R.styleable#Keyboard_Key_keyTextColorDisabled @@ -75,6 +78,9 @@ import java.util.HashSet; public class KeyboardView extends View { // XML attributes private final KeyVisualAttributes mKeyVisualAttributes; + // Default keyLabelFlags from {@link KeyboardTheme}. + // Currently only "alignHintLabelToBottom" is supported. + private final int mDefaultKeyLabelFlags; private final float mKeyHintLetterPadding; private final String mKeyPopupHintLetter; private final float mKeyPopupHintLetterPadding; @@ -146,6 +152,7 @@ public class KeyboardView extends View { final TypedArray keyAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView); + mDefaultKeyLabelFlags = keyAttr.getInt(R.styleable.Keyboard_Key_keyLabelFlags, 0); mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr); keyAttr.recycle(); @@ -357,7 +364,8 @@ public class KeyboardView extends View { // Draw key label. final Drawable icon = key.getIcon(mKeyboard.mIconsSet, params.mAnimAlpha); - float positionX = centerX; + float labelX = centerX; + float labelBaseline = centerY; final String label = key.getLabel(); if (label != null) { paint.setTypeface(key.selectTypeface(params)); @@ -366,15 +374,15 @@ public class KeyboardView extends View { final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint); // Vertical label text alignment. - final float baseline = centerY + labelCharHeight / 2.0f; + labelBaseline = centerY + labelCharHeight / 2.0f; // Horizontal label text alignment - if (key.isAlignLeftOfCenter()) { - // TODO: Parameterise this? - positionX = centerX - labelCharWidth * 7.0f / 4.0f; + if (key.isAlignLabelOffCenter()) { + // The label is placed off center of the key. Used mainly on "phone number" layout. + labelX = centerX + params.mLabelOffCenterRatio * labelCharWidth; paint.setTextAlign(Align.LEFT); } else { - positionX = centerX; + labelX = centerX; paint.setTextAlign(Align.CENTER); } if (key.needsAutoXScale()) { @@ -402,7 +410,7 @@ public class KeyboardView extends View { paint.clearShadowLayer(); } blendAlpha(paint, params.mAnimAlpha); - canvas.drawText(label, 0, label.length(), positionX, baseline, paint); + canvas.drawText(label, 0, label.length(), labelX, labelBaseline, paint); // Turn off drop shadow and reset x-scale. paint.clearShadowLayer(); paint.setTextScaleX(1.0f); @@ -418,22 +426,22 @@ public class KeyboardView extends View { blendAlpha(paint, params.mAnimAlpha); final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint); final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint); - final KeyVisualAttributes visualAttr = key.getVisualAttributes(); - final float adjustmentY = (visualAttr == null) ? 0.0f - : visualAttr.mHintLabelVerticalAdjustment * labelCharHeight; - final float hintX, hintY; + final float hintX, hintBaseline; if (key.hasHintLabel()) { // The hint label is placed just right of the key label. Used mainly on // "phone number" layout. - // TODO: Generalize the following calculations. - hintX = positionX + labelCharWidth * 2.0f; - hintY = centerY + labelCharHeight / 2.0f; + hintX = labelX + params.mHintLabelOffCenterRatio * labelCharWidth; + if (key.isAlignHintLabelToBottom(mDefaultKeyLabelFlags)) { + hintBaseline = labelBaseline; + } else { + hintBaseline = centerY + labelCharHeight / 2.0f; + } paint.setTextAlign(Align.LEFT); } else if (key.hasShiftedLetterHint()) { // The hint label is placed at top-right corner of the key. Used mainly on tablet. hintX = keyWidth - mKeyShiftedLetterHintPadding - labelCharWidth / 2.0f; paint.getFontMetrics(mFontMetrics); - hintY = -mFontMetrics.top; + hintBaseline = -mFontMetrics.top; paint.setTextAlign(Align.CENTER); } else { // key.hasHintLetter() // The hint letter is placed at top-right corner of the key. Used mainly on phone. @@ -441,10 +449,12 @@ public class KeyboardView extends View { final float hintLabelWidth = TypefaceUtils.getStringWidth(hintLabel, paint); hintX = keyWidth - mKeyHintLetterPadding - Math.max(hintDigitWidth, hintLabelWidth) / 2.0f; - hintY = -paint.ascent(); + hintBaseline = -paint.ascent(); paint.setTextAlign(Align.CENTER); } - canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY + adjustmentY, paint); + final float adjustmentY = params.mHintLabelVerticalAdjustment * labelCharHeight; + canvas.drawText( + hintLabel, 0, hintLabel.length(), hintX, hintBaseline + adjustmentY, paint); } // Draw key icon. @@ -456,9 +466,13 @@ public class KeyboardView extends View { iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth); } final int iconHeight = icon.getIntrinsicHeight(); - // Align center. - final int iconY = (keyHeight - iconHeight) / 2; - final int iconX = (keyWidth - iconWidth) / 2; + final int iconY; + if (key.isAlignIconToBottom()) { + iconY = keyHeight - iconHeight; + } else { + iconY = (keyHeight - iconHeight) / 2; // Align vertically center. + } + final int iconX = (keyWidth - iconWidth) / 2; // Align horizontally center. drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyDrawParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyDrawParams.java index 07ac06bab..df50efdc1 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyDrawParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyDrawParams.java @@ -26,7 +26,6 @@ public final class KeyDrawParams { public int mLetterSize; public int mLabelSize; public int mLargeLetterSize; - public int mLargeLabelSize; public int mHintLetterSize; public int mShiftedLetterHintSize; public int mHintLabelSize; @@ -42,6 +41,10 @@ public final class KeyDrawParams { public int mShiftedLetterHintActivatedColor; public int mPreviewTextColor; + public float mHintLabelVerticalAdjustment; + public float mLabelOffCenterRatio; + public float mHintLabelOffCenterRatio; + public int mAnimAlpha; public KeyDrawParams() {} @@ -52,7 +55,6 @@ public final class KeyDrawParams { mLetterSize = copyFrom.mLetterSize; mLabelSize = copyFrom.mLabelSize; mLargeLetterSize = copyFrom.mLargeLetterSize; - mLargeLabelSize = copyFrom.mLargeLabelSize; mHintLetterSize = copyFrom.mHintLetterSize; mShiftedLetterHintSize = copyFrom.mShiftedLetterHintSize; mHintLabelSize = copyFrom.mHintLabelSize; @@ -68,6 +70,10 @@ public final class KeyDrawParams { mShiftedLetterHintActivatedColor = copyFrom.mShiftedLetterHintActivatedColor; mPreviewTextColor = copyFrom.mPreviewTextColor; + mHintLabelVerticalAdjustment = copyFrom.mHintLabelVerticalAdjustment; + mLabelOffCenterRatio = copyFrom.mLabelOffCenterRatio; + mHintLabelOffCenterRatio = copyFrom.mHintLabelOffCenterRatio; + mAnimAlpha = copyFrom.mAnimAlpha; } @@ -84,7 +90,6 @@ public final class KeyDrawParams { attr.mLetterSize, attr.mLetterRatio, mLetterSize); mLabelSize = selectTextSizeFromDimensionOrRatio(keyHeight, attr.mLabelSize, attr.mLabelRatio, mLabelSize); - mLargeLabelSize = selectTextSize(keyHeight, attr.mLargeLabelRatio, mLargeLabelSize); mLargeLetterSize = selectTextSize(keyHeight, attr.mLargeLetterRatio, mLargeLetterSize); mHintLetterSize = selectTextSize(keyHeight, attr.mHintLetterRatio, mHintLetterSize); mShiftedLetterHintSize = selectTextSize(keyHeight, @@ -103,6 +108,13 @@ public final class KeyDrawParams { mShiftedLetterHintActivatedColor = selectColor( attr.mShiftedLetterHintActivatedColor, mShiftedLetterHintActivatedColor); mPreviewTextColor = selectColor(attr.mPreviewTextColor, mPreviewTextColor); + + mHintLabelVerticalAdjustment = selectFloatIfNonZero( + attr.mHintLabelVerticalAdjustment, mHintLabelVerticalAdjustment); + mLabelOffCenterRatio = selectFloatIfNonZero( + attr.mLabelOffCenterRatio, mLabelOffCenterRatio); + mHintLabelOffCenterRatio = selectFloatIfNonZero( + attr.mHintLabelOffCenterRatio, mHintLabelOffCenterRatio); } public KeyDrawParams mayCloneAndUpdateParams(final int keyHeight, @@ -115,7 +127,7 @@ public final class KeyDrawParams { return newParams; } - private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight, + private static int selectTextSizeFromDimensionOrRatio(final int keyHeight, final int dimens, final float ratio, final int defaultDimens) { if (ResourceUtils.isValidDimensionPixelSize(dimens)) { return dimens; @@ -126,7 +138,7 @@ public final class KeyDrawParams { return defaultDimens; } - private static final int selectTextSize(final int keyHeight, final float ratio, + private static int selectTextSize(final int keyHeight, final float ratio, final int defaultSize) { if (ResourceUtils.isValidFraction(ratio)) { return (int)(keyHeight * ratio); @@ -134,10 +146,17 @@ public final class KeyDrawParams { return defaultSize; } - private static final int selectColor(final int attrColor, final int defaultColor) { + private static int selectColor(final int attrColor, final int defaultColor) { if (attrColor != 0) { return attrColor; } return defaultColor; } + + private static float selectFloatIfNonZero(final float attrFloat, final float defaultFloat) { + if (attrFloat != 0) { + return attrFloat; + } + return defaultFloat; + } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java b/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java index 133462ac7..c60d587db 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java @@ -31,7 +31,6 @@ public final class KeyVisualAttributes { public final float mLabelRatio; public final int mLabelSize; public final float mLargeLetterRatio; - public final float mLargeLabelRatio; public final float mHintLetterRatio; public final float mShiftedLetterHintRatio; public final float mHintLabelRatio; @@ -48,13 +47,14 @@ public final class KeyVisualAttributes { public final int mPreviewTextColor; public final float mHintLabelVerticalAdjustment; + public final float mLabelOffCenterRatio; + public final float mHintLabelOffCenterRatio; private static final int[] VISUAL_ATTRIBUTE_IDS = { R.styleable.Keyboard_Key_keyTypeface, R.styleable.Keyboard_Key_keyLetterSize, R.styleable.Keyboard_Key_keyLabelSize, R.styleable.Keyboard_Key_keyLargeLetterRatio, - R.styleable.Keyboard_Key_keyLargeLabelRatio, R.styleable.Keyboard_Key_keyHintLetterRatio, R.styleable.Keyboard_Key_keyShiftedLetterHintRatio, R.styleable.Keyboard_Key_keyHintLabelRatio, @@ -69,6 +69,8 @@ public final class KeyVisualAttributes { R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, R.styleable.Keyboard_Key_keyPreviewTextColor, R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, + R.styleable.Keyboard_Key_keyLabelOffCenterRatio, + R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio }; private static final SparseIntArray sVisualAttributeIds = new SparseIntArray(); private static final int ATTR_DEFINED = 1; @@ -109,8 +111,6 @@ public final class KeyVisualAttributes { R.styleable.Keyboard_Key_keyLabelSize); mLargeLetterRatio = ResourceUtils.getFraction(keyAttr, R.styleable.Keyboard_Key_keyLargeLetterRatio); - mLargeLabelRatio = ResourceUtils.getFraction(keyAttr, - R.styleable.Keyboard_Key_keyLargeLabelRatio); mHintLetterRatio = ResourceUtils.getFraction(keyAttr, R.styleable.Keyboard_Key_keyHintLetterRatio); mShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr, @@ -135,5 +135,9 @@ public final class KeyVisualAttributes { mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr, R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f); + mLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr, + R.styleable.Keyboard_Key_keyLabelOffCenterRatio, 0.0f); + mHintLabelOffCenterRatio = ResourceUtils.getFraction(keyAttr, + R.styleable.Keyboard_Key_keyHintLabelOffCenterRatio, 0.0f); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c7c3aaa18..3a5f85d63 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -295,8 +295,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } - public void postResetInputConnectionCaches(final boolean tryResumeSuggestions, - final int remainingTries) { + public void postResetCaches(final boolean tryResumeSuggestions, final int remainingTries) { removeMessages(MSG_RESET_CACHES); sendMessage(obtainMessage(MSG_RESET_CACHES, tryResumeSuggestions ? 1 : 0, remainingTries, null)); @@ -753,92 +752,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen loadKeyboard(); } - /** - * A class that holds information to pass from onStartInputInternal to onStartInputViewInternal - * - * OnStartInput needs to reload the settings and that will prevent onStartInputViewInternal - * from comparing the old settings with the new ones, so we use this memory to pass the - * necessary information along. - */ - private static class EditorChangeInfo { - public final boolean mIsSameInputType; - public final boolean mHasSameOrientation; - public final boolean mCanReachInputConnection; - public EditorChangeInfo(final boolean isSameInputType, final boolean hasSameOrientation, - final boolean canReachInputConnection) { - mIsSameInputType = isSameInputType; - mHasSameOrientation = hasSameOrientation; - mCanReachInputConnection = canReachInputConnection; - } - } - - private EditorChangeInfo mLastEditorChangeInfo; - private void onStartInputInternal(final EditorInfo editorInfo, final boolean restarting) { super.onStartInput(editorInfo, restarting); - if (editorInfo == null) { - Log.e(TAG, "Null EditorInfo in onStartInput()"); - return; - } - SettingsValues currentSettingsValues = mSettings.getCurrent(); - final boolean isSameInputType = currentSettingsValues.isSameInputType(editorInfo); - final boolean hasSameOrientation = - currentSettingsValues.hasSameOrientation(getResources().getConfiguration()); - mRichImm.clearSubtypeCaches(); - final boolean inputTypeChanged = !isSameInputType; - final boolean isDifferentTextField = !restarting || inputTypeChanged; - if (isDifferentTextField || !hasSameOrientation) { - loadSettings(); - currentSettingsValues = mSettings.getCurrent(); - } - - // Note: the following does a round-trip IPC on the main thread: be careful - final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); - final Suggest suggest = mInputLogic.mSuggest; - if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) { - // TODO: Do this automatically. - resetSuggest(); - } - if (isDifferentTextField && currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) { - suggest.setAutoCorrectionThreshold(currentSettingsValues.mAutoCorrectionThreshold); - } - - // The app calling setText() has the effect of clearing the composing - // span, so we should reset our state unconditionally, even if restarting is true. - // We also tell the input logic about the combining rules for the current subtype, so - // it can adjust its combiners if needed. - mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype()); - // TODO[IL]: Can the following be moved to InputLogic#startInput? - final boolean canReachInputConnection; - if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess( - editorInfo.initialSelStart, editorInfo.initialSelEnd, - false /* shouldFinishComposition */)) { - // Sometimes, while rotating, for some reason the framework tells the app we are not - // connected to it and that means we can't refresh the cache. In this case, schedule a - // refresh later. - // We try resetting the caches up to 5 times before giving up. - mHandler.postResetInputConnectionCaches(isDifferentTextField || !hasSameOrientation, - 5 /* remainingTries */); - canReachInputConnection = false; - } else { - // When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best - // effort to work around this bug. - mInputLogic.mConnection.tryFixLyingCursorPosition(); - mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */, - true /* shouldDelay */); - canReachInputConnection = true; - } - - mLastEditorChangeInfo = new EditorChangeInfo(isSameInputType, hasSameOrientation, - canReachInputConnection); } @SuppressWarnings("deprecation") private void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restarting) { super.onStartInputView(editorInfo, restarting); + mRichImm.clearSubtypeCaches(); final KeyboardSwitcher switcher = mKeyboardSwitcher; switcher.updateKeyboardTheme(); final MainKeyboardView mainKeyboardView = switcher.getMainKeyboardView(); + // If we are starting input in a different text field from before, we'll have to reload + // settings, so currentSettingsValues can't be final. + SettingsValues currentSettingsValues = mSettings.getCurrent(); if (editorInfo == null) { Log.e(TAG, "Null EditorInfo in onStartInputView()"); @@ -881,7 +808,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen accessUtils.onStartInputViewInternal(mainKeyboardView, editorInfo, restarting); } - final boolean inputTypeChanged = !mLastEditorChangeInfo.mIsSameInputType; + final boolean inputTypeChanged = !currentSettingsValues.isSameInputType(editorInfo); final boolean isDifferentTextField = !restarting || inputTypeChanged; if (isDifferentTextField) { mSubtypeSwitcher.updateParametersOnStartInputView(); @@ -891,13 +818,57 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Note: This call should be done by InputMethodService? updateFullscreenMode(); - final SettingsValues currentSettingsValues = mSettings.getCurrent(); + // The app calling setText() has the effect of clearing the composing + // span, so we should reset our state unconditionally, even if restarting is true. + // We also tell the input logic about the combining rules for the current subtype, so + // it can adjust its combiners if needed. + mInputLogic.startInput(mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype()); + + // Note: the following does a round-trip IPC on the main thread: be careful + final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); + final Suggest suggest = mInputLogic.mSuggest; + if (null != currentLocale && !currentLocale.equals(suggest.getLocale())) { + // TODO: Do this automatically. + resetSuggest(); + } + + // TODO[IL]: Can the following be moved to InputLogic#startInput? + final boolean canReachInputConnection; + if (!mInputLogic.mConnection.resetCachesUponCursorMoveAndReturnSuccess( + editorInfo.initialSelStart, editorInfo.initialSelEnd, + false /* shouldFinishComposition */)) { + // Sometimes, while rotating, for some reason the framework tells the app we are not + // connected to it and that means we can't refresh the cache. In this case, schedule a + // refresh later. + // We try resetting the caches up to 5 times before giving up. + mHandler.postResetCaches(isDifferentTextField, 5 /* remainingTries */); + // mLastSelection{Start,End} are reset later in this method, don't need to do it here + canReachInputConnection = false; + } else { + // When rotating, initialSelStart and initialSelEnd sometimes are lying. Make a best + // effort to work around this bug. + mInputLogic.mConnection.tryFixLyingCursorPosition(); + mHandler.postResumeSuggestions(true /* shouldIncludeResumedWordInSuggestions */, + true /* shouldDelay */); + canReachInputConnection = true; + } + + if (isDifferentTextField || + !currentSettingsValues.hasSameOrientation(getResources().getConfiguration())) { + loadSettings(); + } if (isDifferentTextField) { mainKeyboardView.closing(); + currentSettingsValues = mSettings.getCurrent(); + + if (currentSettingsValues.mAutoCorrectionEnabledPerUserSettings) { + suggest.setAutoCorrectionThreshold( + currentSettingsValues.mAutoCorrectionThreshold); + } switcher.loadKeyboard(editorInfo, currentSettingsValues, getCurrentAutoCapsState(), getCurrentRecapitalizeState()); - if (!mLastEditorChangeInfo.mCanReachInputConnection) { + if (!canReachInputConnection) { // If we can't reach the input connection, we will call loadKeyboard again later, // so we need to save its state now. The call will be done in #retryResetCaches. switcher.saveKeyboardState(); diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 2be792040..418866ae1 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -2035,7 +2035,7 @@ public final class InputLogic { mConnection.getExpectedSelectionStart(), mConnection.getExpectedSelectionEnd(), shouldFinishComposition)) { if (0 < remainingTries) { - handler.postResetInputConnectionCaches(tryResumeSuggestions, remainingTries - 1); + handler.postResetCaches(tryResumeSuggestions, remainingTries - 1); return false; } // If remainingTries is 0, we should stop waiting for new tries, however we'll still |