diff options
Diffstat (limited to 'java/src')
12 files changed, 23 insertions, 502 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 3e45793cb..d4a23aa15 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -400,15 +400,6 @@ public class Keyboard { return mMostCommonKeyWidth; } - /** - * Return true if spacebar needs showing preview even when "popup on keypress" is off. - * @param keyIndex index of the pressing key - * @return true if spacebar needs showing preview - */ - public boolean needSpacebarPreview(int keyIndex) { - return false; - } - private void loadKeyboard(Context context, int xmlLayoutResId) { try { KeyboardParser parser = new KeyboardParser(this, context); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index f9593215d..37c501468 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -241,7 +241,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // we should reset the text fade factor. It is also applicable to shortcut key. keyboard.setSpacebarTextFadeFactor(0.0f, null); keyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady(), null); - keyboard.setSpacebarSlidingLanguageSwitchDiff(0); return keyboard; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 2e0683115..71c4896a7 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -265,7 +265,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public final Drawable mPreviewBackground; public final Drawable mPreviewLeftBackground; public final Drawable mPreviewRightBackground; - public final Drawable mPreviewSpacebarBackground; public final int mPreviewTextColor; public final int mPreviewOffset; public final int mPreviewHeight; @@ -286,8 +285,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { R.styleable.KeyboardView_keyPreviewLeftBackground); mPreviewRightBackground = a.getDrawable( R.styleable.KeyboardView_keyPreviewRightBackground); - mPreviewSpacebarBackground = a.getDrawable( - R.styleable.KeyboardView_keyPreviewSpacebarBackground); setAlpha(mPreviewBackground, PREVIEW_ALPHA); setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA); setAlpha(mPreviewRightBackground, PREVIEW_ALPHA); @@ -768,9 +765,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public void showKeyPreview(int keyIndex, PointerTracker tracker) { if (mShowKeyPreviewPopup) { mDrawingHandler.showKeyPreview(mDelayBeforePreview, keyIndex, tracker); - } else if (mKeyboard.needSpacebarPreview(keyIndex)) { - // Show key preview (in this case, slide language switcher) without any delay. - showKey(keyIndex, tracker); } } @@ -784,9 +778,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { if (mShowKeyPreviewPopup) { mDrawingHandler.cancelShowKeyPreview(tracker); mDrawingHandler.dismissKeyPreview(mDelayAfterPreview, tracker); - } else if (mKeyboard.needSpacebarPreview(KeyDetector.NOT_A_KEY)) { - // Dismiss key preview (in this case, slide language switcher) without any delay. - mPreviewText.setVisibility(View.INVISIBLE); } } @@ -838,11 +829,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { previewIcon != null ? previewIcon : key.getIcon()); previewText.setText(null); } - if (key.mCode == Keyboard.CODE_SPACE) { - previewText.setBackgroundDrawable(params.mPreviewSpacebarBackground); - } else { - previewText.setBackgroundDrawable(params.mPreviewBackground); - } + previewText.setBackgroundDrawable(params.mPreviewBackground); previewText.measure(MEASURESPEC_UNSPECIFIED, MEASURESPEC_UNSPECIFIED); final int previewWidth = Math.max(previewText.getMeasuredWidth(), keyDrawWidth diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index d925b8c33..3c27129ec 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -31,7 +31,6 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.text.TextUtils; -import com.android.inputmethod.keyboard.internal.SlidingLocaleDrawable; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; @@ -45,9 +44,6 @@ import java.util.Locale; public class LatinKeyboard extends Keyboard { private static final int SPACE_LED_LENGTH_PERCENT = 80; - public static final int CODE_NEXT_LANGUAGE = -100; - public static final int CODE_PREV_LANGUAGE = -101; - private final Resources mRes; private final Theme mTheme; private final SubtypeSwitcher mSubtypeSwitcher = SubtypeSwitcher.getInstance(); @@ -55,16 +51,11 @@ public class LatinKeyboard extends Keyboard { /* Space key and its icons, drawables and colors. */ private final Key mSpaceKey; private final Drawable mSpaceIcon; - private final Drawable mSpacePreviewIcon; - private final int mSpaceKeyIndex; private final boolean mAutoCorrectionSpacebarLedEnabled; private final Drawable mAutoCorrectionSpacebarLedIcon; private final int mSpacebarTextColor; private final int mSpacebarTextShadowColor; private float mSpacebarTextFadeFactor = 0.0f; - private final int mSpacebarLanguageSwitchThreshold; - private int mSpacebarSlidingLanguageSwitchDiff; - private final SlidingLocaleDrawable mSlidingLocaleIcon; private final HashMap<Integer, SoftReference<BitmapDrawable>> mSpaceDrawableCache = new HashMap<Integer, SoftReference<BitmapDrawable>>(); @@ -73,16 +64,6 @@ public class LatinKeyboard extends Keyboard { private final Drawable mEnabledShortcutIcon; private final Drawable mDisabledShortcutIcon; - // BLACK LEFT-POINTING TRIANGLE and two spaces. - public static final String ARROW_LEFT = "\u25C0 "; - // Two spaces and BLACK RIGHT-POINTING TRIANGLE. - public static final String ARROW_RIGHT = " \u25B6"; - - // Minimum width of spacebar dragging to trigger the language switch (represented by the number - // of the most common key width of this keyboard). - private static final int SPACEBAR_DRAG_WIDTH = 3; - // Minimum width of space key preview (proportional to keyboard width). - private static final float SPACEBAR_POPUP_MIN_RATIO = 0.5f; // 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, @@ -116,8 +97,6 @@ public class LatinKeyboard extends Keyboard { // The index of space key is available only after Keyboard constructor has finished. mSpaceKey = (spaceKeyIndex >= 0) ? keys.get(spaceKeyIndex) : null; mSpaceIcon = (mSpaceKey != null) ? mSpaceKey.getIcon() : null; - mSpacePreviewIcon = (mSpaceKey != null) ? mSpaceKey.getPreviewIcon() : null; - mSpaceKeyIndex = spaceKeyIndex; mShortcutKey = (shortcutKeyIndex >= 0) ? keys.get(shortcutKeyIndex) : null; mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null; @@ -133,20 +112,6 @@ public class LatinKeyboard extends Keyboard { mSpacebarTextShadowColor = a.getColor( R.styleable.LatinKeyboard_spacebarTextShadowColor, 0); a.recycle(); - - // The threshold is "key width" x 1.25 - mSpacebarLanguageSwitchThreshold = (getMostCommonKeyWidth() * 5) / 4; - - if (mSpaceKey != null && mSpacePreviewIcon != null) { - final int slidingIconWidth = Math.max(mSpaceKey.mWidth, - (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO)); - final int spaceKeyheight = mSpacePreviewIcon.getIntrinsicHeight(); - mSlidingLocaleIcon = new SlidingLocaleDrawable( - context, mSpacePreviewIcon, slidingIconWidth, spaceKeyheight); - mSlidingLocaleIcon.setBounds(0, 0, slidingIconWidth, spaceKeyheight); - } else { - mSlidingLocaleIcon = null; - } } public void setSpacebarTextFadeFactor(float fadeFactor, LatinKeyboardView view) { @@ -219,8 +184,7 @@ public class LatinKeyboard extends Keyboard { final Rect bounds = new Rect(); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = ARROW_LEFT + SubtypeSwitcher.getFullDisplayName(locale, true) - + ARROW_RIGHT; + String language = SubtypeSwitcher.getFullDisplayName(locale, true); int textWidth = getTextWidth(paint, language, origTextSize, bounds); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(width / textWidth, 1.0f); @@ -232,7 +196,7 @@ public class LatinKeyboard extends Keyboard { final boolean useShortName; if (useMiddleName) { - language = ARROW_LEFT + SubtypeSwitcher.getMiddleDisplayLanguage(locale) + ARROW_RIGHT; + language = SubtypeSwitcher.getMiddleDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(width / textWidth, 1.0f); useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) @@ -242,7 +206,7 @@ public class LatinKeyboard extends Keyboard { } if (useShortName) { - language = ARROW_LEFT + SubtypeSwitcher.getShortDisplayLanguage(locale) + ARROW_RIGHT; + language = SubtypeSwitcher.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize, bounds); textSize = origTextSize * Math.min(width / textWidth, 1.0f); } @@ -327,63 +291,6 @@ public class LatinKeyboard extends Keyboard { return buffer; } - public void setSpacebarSlidingLanguageSwitchDiff(int diff) { - mSpacebarSlidingLanguageSwitchDiff = diff; - } - - public void updateSpacebarPreviewIcon(int diff) { - if (mSpacebarSlidingLanguageSwitchDiff == diff) - return; - mSpacebarSlidingLanguageSwitchDiff = diff; - if (mSlidingLocaleIcon == null) - return; - mSlidingLocaleIcon.setDiff(diff); - if (Math.abs(diff) == Integer.MAX_VALUE) { - mSpaceKey.setPreviewIcon(mSpacePreviewIcon); - } else { - mSpaceKey.setPreviewIcon(mSlidingLocaleIcon); - } - mSpaceKey.getPreviewIcon().invalidateSelf(); - } - - public boolean shouldTriggerSpacebarSlidingLanguageSwitch(int diff) { - // On phone and number layouts, sliding language switch is disabled. - // TODO: Sort out how to enable language switch on these layouts. - if (isPhoneKeyboard() || isNumberKeyboard()) - return false; - return Math.abs(diff) > mSpacebarLanguageSwitchThreshold; - } - - /** - * Return true if spacebar needs showing preview even when "popup on keypress" is off. - * @param keyIndex index of the pressing key - * @return true if spacebar needs showing preview - */ - @Override - public boolean needSpacebarPreview(int keyIndex) { - // This method is called when "popup on keypress" is off. - if (!mSubtypeSwitcher.useSpacebarLanguageSwitcher()) - return false; - // Dismiss key preview. - if (keyIndex == KeyDetector.NOT_A_KEY) - return true; - // Key is not a spacebar. - if (keyIndex != mSpaceKeyIndex) - return false; - // The language switcher will be displayed only when the dragging distance is greater - // than the threshold. - return shouldTriggerSpacebarSlidingLanguageSwitch(mSpacebarSlidingLanguageSwitchDiff); - } - - public int getLanguageChangeDirection() { - if (mSpaceKey == null || mSubtypeSwitcher.getEnabledKeyboardLocaleCount() <= 1 - || Math.abs(mSpacebarSlidingLanguageSwitchDiff) - < getMostCommonKeyWidth() * SPACEBAR_DRAG_WIDTH) { - return 0; // No change - } - return mSpacebarSlidingLanguageSwitchDiff > 0 ? 1 : -1; - } - @Override public int[] getNearestKeys(int x, int y) { // Avoid dead pixels at edges of the keyboard diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java index 078d89f49..fb57a2dba 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardBaseView.java @@ -348,7 +348,6 @@ public class LatinKeyboardBaseView extends KeyboardView implements PointerTracke } // This default implementation returns a popup mini keyboard panel. - // A derived class may return a language switcher popup panel, for instance. protected PopupPanel onCreatePopupPanel(Key parentKey) { if (parentKey.mPopupCharacters == null) return null; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 617961b59..c404a5dfb 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -40,8 +40,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { private boolean mDisableDisambiguation; /** The distance threshold at which we start treating the touch session as a multi-touch */ private int mJumpThresholdSquare = Integer.MAX_VALUE; - /** The y coordinate of the last row */ - private int mLastRowY; private int mLastX; private int mLastY; @@ -71,8 +69,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { // One-seventh of the keyboard width seems like a reasonable threshold mJumpThresholdSquare = newKeyboard.getMinWidth() / 7; mJumpThresholdSquare *= mJumpThresholdSquare; - // Assuming there are 4 rows, this is the coordinate of the last row - mLastRowY = (newKeyboard.getHeight() * 3) / 4; } private LatinKeyboard getLatinKeyboard() { @@ -127,7 +123,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { * the sudden moves subside, a DOWN event is simulated for the second key. * @param me the motion event * @return true if the event was consumed, so that it doesn't continue to be handled by - * KeyboardView. + * {@link LatinKeyboardBaseView}. */ private boolean handleSuddenJump(MotionEvent me) { // If device has distinct multi touch panel, there is no need to check sudden jump. @@ -157,11 +153,8 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { case MotionEvent.ACTION_MOVE: // Is this a big jump? final int distanceSquare = (mLastX - x) * (mLastX - x) + (mLastY - y) * (mLastY - y); - // Check the distance and also if the move is not entirely within the bottom row - // If it's only in the bottom row, it might be an intentional slide gesture - // for language switching - if (distanceSquare > mJumpThresholdSquare - && (mLastY < mLastRowY || y < mLastRowY)) { + // Check the distance. + if (distanceSquare > mJumpThresholdSquare) { // If we're not yet dropping events, start dropping and send an UP event if (!mDroppingEvents) { mDroppingEvents = true; diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 8d7496c54..5b03ef4a1 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -23,7 +23,6 @@ import android.util.Log; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; import java.util.ArrayList; import java.util.Arrays; @@ -133,12 +132,6 @@ public class PointerTracker { // ignore modifier key if true private boolean mIgnoreModifierKey; - // TODO: Remove these hacking variables - // true if this pointer is in sliding language switch - private boolean mIsInSlidingLanguageSwitch; - private int mSpaceKeyIndex; - private static SubtypeSwitcher sSubtypeSwitcher; - // Empty {@link KeyboardActionListener} private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() { @Override @@ -172,7 +165,6 @@ public class PointerTracker { sTouchNoiseThresholdDistanceSquared = (int)( touchNoiseThresholdDistance * touchNoiseThresholdDistance); sKeyboardSwitcher = KeyboardSwitcher.getInstance(); - sSubtypeSwitcher = SubtypeSwitcher.getInstance(); } public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { @@ -436,7 +428,6 @@ public class PointerTracker { mKeyAlreadyProcessed = false; mIsRepeatableKey = false; mIsInSlidingKeyInput = false; - mIsInSlidingLanguageSwitch = false; mIgnoreModifierKey = false; if (isValidKeyIndex(keyIndex)) { // This onPress call may have changed keyboard layout. Those cases are detected at @@ -464,12 +455,6 @@ public class PointerTracker { if (mKeyAlreadyProcessed) return; - // TODO: Remove this hacking code - if (mIsInSlidingLanguageSwitch) { - ((LatinKeyboard)mKeyboard).updateSpacebarPreviewIcon(x - mKeyX); - showKeyPreview(mSpaceKeyIndex); - return; - } final int lastX = mLastX; final int lastY = mLastY; final int oldKeyIndex = mKeyIndex; @@ -527,26 +512,6 @@ public class PointerTracker { } } } - // TODO: Remove this hack code - else if (isSpaceKey(keyIndex) && !mIsInSlidingLanguageSwitch - && mKeyboard instanceof LatinKeyboard) { - final LatinKeyboard keyboard = ((LatinKeyboard)mKeyboard); - if (sSubtypeSwitcher.useSpacebarLanguageSwitcher() - && sSubtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { - final int diff = x - mKeyX; - if (keyboard.shouldTriggerSpacebarSlidingLanguageSwitch(diff)) { - // Detect start sliding language switch. - mIsInSlidingLanguageSwitch = true; - mSpaceKeyIndex = keyIndex; - keyboard.updateSpacebarPreviewIcon(diff); - // Display spacebar slide language switcher. - showKeyPreview(keyIndex); - final PointerTrackerQueue queue = sPointerTrackerQueue; - if (queue != null) - queue.releaseAllPointersExcept(this, eventTime, true); - } - } - } } else { if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) { // The pointer has been slid out from the previous key, we must call onRelease() to @@ -613,20 +578,6 @@ public class PointerTracker { setReleasedKeyGraphics(keyIndex); if (mKeyAlreadyProcessed) return; - // TODO: Remove this hacking code - if (mIsInSlidingLanguageSwitch) { - setReleasedKeyGraphics(mSpaceKeyIndex); - final int languageDir = ((LatinKeyboard)mKeyboard).getLanguageChangeDirection(); - if (languageDir != 0) { - final int code = (languageDir == 1) - ? LatinKeyboard.CODE_NEXT_LANGUAGE : LatinKeyboard.CODE_PREV_LANGUAGE; - // This will change keyboard layout. - mListener.onCodeInput(code, new int[] {code}, keyX, keyY); - } - mIsInSlidingLanguageSwitch = false; - ((LatinKeyboard)mKeyboard).setSpacebarSlidingLanguageSwitchDiff(0); - return; - } if (!mIsRepeatableKey) { detectAndSendKey(keyIndex, keyX, keyY); } @@ -700,9 +651,6 @@ public class PointerTracker { final Key key = getKey(keyIndex); if (key == null || !key.isEnabled()) return true; - // Such as spacebar sliding language switch. - if (mKeyboard.needSpacebarPreview(keyIndex)) - return false; final int code = key.mCode; return isModifierCode(code) || code == Keyboard.CODE_DELETE || code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index 535a6954c..6256e7fbd 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -35,7 +35,7 @@ public class KeyboardIconsSet { private static final int ICON_TO_SYMBOL_KEY_WITH_SHORTCUT = 3; private static final int ICON_DELETE_KEY = 4; private static final int ICON_DELETE_RTL_KEY = 5; - private static final int ICON_SETTINGS_KEY = 6; + private static final int ICON_SETTINGS_KEY = 6; // This is also represented as "@icon/6" in xml. private static final int ICON_SHORTCUT_KEY = 7; private static final int ICON_SPACE_KEY = 8; private static final int ICON_RETURN_KEY = 9; @@ -44,12 +44,11 @@ public class KeyboardIconsSet { // This should be aligned with Keyboard.keyIconShifted enum. private static final int ICON_SHIFTED_SHIFT_KEY = 12; // This should be aligned with Keyboard.keyIconPreview enum. - private static final int ICON_PREVIEW_SPACE_KEY = 13; - private static final int ICON_PREVIEW_TAB_KEY = 14; - private static final int ICON_PREVIEW_SETTINGS_KEY = 15; - private static final int ICON_PREVIEW_SHORTCUT_KEY = 16; + private static final int ICON_PREVIEW_TAB_KEY = 13; + private static final int ICON_PREVIEW_SETTINGS_KEY = 14; + private static final int ICON_PREVIEW_SHORTCUT_KEY = 15; - private static final int ICON_LAST = 16; + private static final int ICON_LAST = 15; private final Drawable mIcons[] = new Drawable[ICON_LAST + 1]; @@ -79,8 +78,6 @@ public class KeyboardIconsSet { return ICON_TAB_KEY; case R.styleable.Keyboard_iconShiftedShiftKey: return ICON_SHIFTED_SHIFT_KEY; - case R.styleable.Keyboard_iconPreviewSpaceKey: - return ICON_PREVIEW_SPACE_KEY; case R.styleable.Keyboard_iconPreviewTabKey: return ICON_PREVIEW_TAB_KEY; case R.styleable.Keyboard_iconPreviewSettingsKey: diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java deleted file mode 100644 index ef3ea4c12..000000000 --- a/java/src/com/android/inputmethod/keyboard/internal/SlidingLocaleDrawable.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.android.inputmethod.keyboard.internal; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.Paint.Align; -import android.graphics.PixelFormat; -import android.graphics.drawable.Drawable; -import android.text.TextPaint; -import android.view.ViewConfiguration; - -import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.LatinKeyboard; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; - -/** - * Animation to be displayed on the spacebar preview popup when switching languages by swiping the - * spacebar. It draws the current, previous and next languages and moves them by the delta of touch - * movement on the spacebar. - */ -public class SlidingLocaleDrawable extends Drawable { - private static final int SLIDE_SPEED_MULTIPLIER_RATIO = 150; - private final int mWidth; - private final int mHeight; - private final Drawable mBackground; - private final int mSpacebarTextColor; - private final TextPaint mTextPaint; - private final int mMiddleX; - private final boolean mDrawArrows; - private final int mThreshold; - - private int mDiff; - private boolean mHitThreshold; - private String mCurrentLanguage; - private String mNextLanguage; - private String mPrevLanguage; - - public SlidingLocaleDrawable(Context context, Drawable background, int width, int height) { - mBackground = background; - Keyboard.setDefaultBounds(background); - mWidth = width; - mHeight = height; - final TextPaint textPaint = new TextPaint(); - textPaint.setTextSize(LatinKeyboard.getTextSizeFromTheme( - context.getTheme(), android.R.style.TextAppearance_Medium, 18)); - textPaint.setColor(Color.TRANSPARENT); - textPaint.setAntiAlias(true); - mTextPaint = textPaint; - mMiddleX = (background != null) ? (mWidth - mBackground.getIntrinsicWidth()) / 2 : 0; - - final TypedArray a = context.obtainStyledAttributes( - null, R.styleable.KeyboardView, R.attr.keyboardViewStyle, R.style.KeyboardView); - mSpacebarTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0); - final int spacebarPreviewBackrgound = a.getResourceId( - R.styleable.KeyboardView_keyPreviewSpacebarBackground, 0); - // If spacebar preview background is transparent, we need not draw arrows. - mDrawArrows = (spacebarPreviewBackrgound != R.drawable.transparent); - a.recycle(); - - mThreshold = ViewConfiguration.get(context).getScaledTouchSlop(); - } - - public void setDiff(int diff) { - if (diff == Integer.MAX_VALUE) { - mHitThreshold = false; - mCurrentLanguage = null; - return; - } - mDiff = Math.max(diff, diff * SLIDE_SPEED_MULTIPLIER_RATIO / 100); - if (mDiff > mWidth) mDiff = mWidth; - if (mDiff < -mWidth) mDiff = -mWidth; - if (Math.abs(mDiff) > mThreshold) mHitThreshold = true; - invalidateSelf(); - } - - - @Override - public void draw(Canvas canvas) { - canvas.save(); - if (mHitThreshold) { - Paint paint = mTextPaint; - final int width = mWidth; - final int height = mHeight; - final int diff = mDiff; - canvas.clipRect(0, 0, width, height); - if (mCurrentLanguage == null) { - SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); - mCurrentLanguage = subtypeSwitcher.getInputLanguageName(); - mNextLanguage = subtypeSwitcher.getNextInputLanguageName(); - mPrevLanguage = subtypeSwitcher.getPreviousInputLanguageName(); - } - // Draw language text. - final float baseline = mHeight * LatinKeyboard.SPACEBAR_LANGUAGE_BASELINE - - paint.descent(); - paint.setColor(mSpacebarTextColor); - paint.setTextAlign(Align.CENTER); - canvas.drawText(mCurrentLanguage, width / 2 + diff, baseline, paint); - canvas.drawText(mNextLanguage, diff - width / 2, baseline, paint); - canvas.drawText(mPrevLanguage, diff + width + width / 2, baseline, paint); - if (mDrawArrows) { - paint.setTextAlign(Align.LEFT); - canvas.drawText(LatinKeyboard.ARROW_LEFT, 0, baseline, paint); - paint.setTextAlign(Align.RIGHT); - canvas.drawText(LatinKeyboard.ARROW_RIGHT, width, baseline, paint); - } - } - if (mBackground != null) { - canvas.translate(mMiddleX, 0); - mBackground.draw(canvas); - } - canvas.restore(); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } - - @Override - public void setAlpha(int alpha) { - // Ignore - } - - @Override - public void setColorFilter(ColorFilter cf) { - // Ignore - } - - @Override - public int getIntrinsicWidth() { - return mWidth; - } - - @Override - public int getIntrinsicHeight() { - return mHeight; - } -} diff --git a/java/src/com/android/inputmethod/latin/DebugSettings.java b/java/src/com/android/inputmethod/latin/DebugSettings.java index fd62d61c3..2f1e7c2b8 100644 --- a/java/src/com/android/inputmethod/latin/DebugSettings.java +++ b/java/src/com/android/inputmethod/latin/DebugSettings.java @@ -33,7 +33,6 @@ public class DebugSettings extends PreferenceActivity private boolean mServiceNeedsRestart = false; private CheckBoxPreference mDebugMode; - private CheckBoxPreference mUseSpacebarLanguageSwitch; @Override protected void onCreate(Bundle icicle) { @@ -61,13 +60,6 @@ public class DebugSettings extends PreferenceActivity updateDebugMode(); mServiceNeedsRestart = true; } - } else if (key.equals(SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCH_KEY)) { - if (mUseSpacebarLanguageSwitch != null) { - mUseSpacebarLanguageSwitch.setChecked( - prefs.getBoolean(SubtypeSwitcher.USE_SPACEBAR_LANGUAGE_SWITCH_KEY, - getResources().getBoolean( - R.bool.config_use_spacebar_language_switcher))); - } } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 29cf63de4..5d8fd3411 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -357,7 +357,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinImeLogger.init(this, prefs); LanguageSwitcherProxy.init(this, prefs); InputMethodManagerCompatWrapper.init(this); - SubtypeSwitcher.init(this, prefs); + SubtypeSwitcher.init(this); KeyboardSwitcher.init(this, prefs); Recorrection.init(this, prefs); AccessibilityUtils.init(this, prefs); @@ -1130,12 +1130,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case Keyboard.CODE_SETTINGS_LONGPRESS: onSettingsKeyLongPressed(); break; - case LatinKeyboard.CODE_NEXT_LANGUAGE: - toggleLanguage(true); - break; - case LatinKeyboard.CODE_PREV_LANGUAGE: - toggleLanguage(false); - break; case Keyboard.CODE_CAPSLOCK: switcher.toggleCapsLock(); break; @@ -1907,17 +1901,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mKeyboardSwitcher.updateShiftState(); } - // "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER. - private void toggleLanguage(boolean next) { - if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) { - mSubtypeSwitcher.toggleLanguage(next); - } - // The following is necessary because on API levels < 10, we don't get notified when - // subtype changes. - if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) - onRefreshKeyboard(); - } - @Override public void onPress(int primaryCode, boolean withSliding) { if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 7f13643ae..6580cbc08 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -16,16 +16,8 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; -import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.keyboard.LatinKeyboard; - import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; @@ -37,6 +29,13 @@ import android.os.IBinder; import android.text.TextUtils; import android.util.Log; +import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; +import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; +import com.android.inputmethod.deprecated.VoiceProxy; +import com.android.inputmethod.keyboard.KeyboardSwitcher; +import com.android.inputmethod.keyboard.LatinKeyboard; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -52,7 +51,6 @@ public class SubtypeSwitcher { private static final String VOICE_MODE = "voice"; private static final String SUBTYPE_EXTRAVALUE_REQUIRE_NETWORK_CONNECTIVITY = "requireNetworkConnectivity"; - public static final String USE_SPACEBAR_LANGUAGE_SWITCH_KEY = "use_spacebar_language_switch"; private final TextUtils.SimpleStringSplitter mLocaleSplitter = new TextUtils.SimpleStringSplitter(LOCALE_SEPARATER); @@ -62,13 +60,10 @@ public class SubtypeSwitcher { private /* final */ InputMethodManagerCompatWrapper mImm; private /* final */ Resources mResources; private /* final */ ConnectivityManager mConnectivityManager; - private /* final */ boolean mConfigUseSpacebarLanguageSwitcher; - private /* final */ SharedPreferences mPrefs; private final ArrayList<InputMethodSubtypeCompatWrapper> mEnabledKeyboardSubtypesOfCurrentInputMethod = new ArrayList<InputMethodSubtypeCompatWrapper>(); private final ArrayList<String> mEnabledLanguagesOfCurrentInputMethod = new ArrayList<String>(); - private final LanguageBarInfo mLanguageBarInfo = new LanguageBarInfo(); /*-----------------------------------------------------------*/ // Variants which should be changed only by reload functions. @@ -81,7 +76,6 @@ public class SubtypeSwitcher { private Locale mSystemLocale; private Locale mInputLocale; private String mInputLocaleStr; - private String mInputMethodId; private VoiceProxy.VoiceInputWrapper mVoiceInputWrapper; /*-----------------------------------------------------------*/ @@ -91,9 +85,9 @@ public class SubtypeSwitcher { return sInstance; } - public static void init(LatinIME service, SharedPreferences prefs) { + public static void init(LatinIME service) { SubtypeLocale.init(service); - sInstance.initialize(service, prefs); + sInstance.initialize(service); sInstance.updateAllParameters(); } @@ -101,7 +95,7 @@ public class SubtypeSwitcher { // Intentional empty constructor for singleton. } - private void initialize(LatinIME service, SharedPreferences prefs) { + private void initialize(LatinIME service) { mService = service; mResources = service.getResources(); mImm = InputMethodManagerCompatWrapper.getInstance(); @@ -115,11 +109,9 @@ public class SubtypeSwitcher { mCurrentSubtype = null; mAllEnabledSubtypesOfCurrentInputMethod = null; mVoiceInputWrapper = null; - mPrefs = prefs; final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); mIsNetworkConnected = (info != null && info.isConnected()); - mInputMethodId = Utils.getInputMethodId(mImm, service.getPackageName()); } // Update all parameters stored in SubtypeSwitcher. @@ -133,9 +125,6 @@ public class SubtypeSwitcher { // Update parameters which are changed outside LatinIME. This parameters affect UI so they // should be updated every time onStartInputview. public void updateParametersOnStartInputView() { - mConfigUseSpacebarLanguageSwitcher = mPrefs.getBoolean(USE_SPACEBAR_LANGUAGE_SWITCH_KEY, - mService.getResources().getBoolean( - R.bool.config_use_spacebar_language_switcher)); updateEnabledSubtypes(); updateShortcutIME(); } @@ -170,10 +159,6 @@ public class SubtypeSwitcher { Log.w(TAG, "Last subtype was disabled. Update to the current one."); } updateSubtype(mImm.getCurrentInputMethodSubtype()); - } else { - // mLanguageBarInfo.update() will be called in updateSubtype so there is no need - // to call this in the if-clause above. - mLanguageBarInfo.update(); } } @@ -273,7 +258,6 @@ public class SubtypeSwitcher { mVoiceInputWrapper.reset(); } } - mLanguageBarInfo.update(); } // Update the current input locale from Locale string. @@ -427,10 +411,6 @@ public class SubtypeSwitcher { return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } - public boolean useSpacebarLanguageSwitcher() { - return mConfigUseSpacebarLanguageSwitcher; - } - public boolean needsToDisplayLanguage() { return mNeedsToDisplayLanguage; } @@ -508,75 +488,6 @@ public class SubtypeSwitcher { KeyboardSwitcher.getInstance().getKeyboardView().getWindowToken()); } - ////////////////////////////////////// - // Spacebar Language Switch support // - ////////////////////////////////////// - - private class LanguageBarInfo { - private int mCurrentKeyboardSubtypeIndex; - private InputMethodSubtypeCompatWrapper mNextKeyboardSubtype; - private InputMethodSubtypeCompatWrapper mPreviousKeyboardSubtype; - private String mNextLanguage; - private String mPreviousLanguage; - public LanguageBarInfo() { - update(); - } - - private String getNextLanguage() { - return mNextLanguage; - } - - private String getPreviousLanguage() { - return mPreviousLanguage; - } - - public InputMethodSubtypeCompatWrapper getNextKeyboardSubtype() { - return mNextKeyboardSubtype; - } - - public InputMethodSubtypeCompatWrapper getPreviousKeyboardSubtype() { - return mPreviousKeyboardSubtype; - } - - public void update() { - if (!mConfigUseSpacebarLanguageSwitcher - || mEnabledKeyboardSubtypesOfCurrentInputMethod == null - || mEnabledKeyboardSubtypesOfCurrentInputMethod.size() == 0) return; - mCurrentKeyboardSubtypeIndex = getCurrentIndex(); - mNextKeyboardSubtype = getNextKeyboardSubtypeInternal(mCurrentKeyboardSubtypeIndex); - Locale locale = Utils.constructLocaleFromString(mNextKeyboardSubtype.getLocale()); - mNextLanguage = getFullDisplayName(locale, true); - mPreviousKeyboardSubtype = getPreviousKeyboardSubtypeInternal( - mCurrentKeyboardSubtypeIndex); - locale = Utils.constructLocaleFromString(mPreviousKeyboardSubtype.getLocale()); - mPreviousLanguage = getFullDisplayName(locale, true); - } - - private int normalize(int index) { - final int N = mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); - final int ret = index % N; - return ret < 0 ? ret + N : ret; - } - - private int getCurrentIndex() { - final int N = mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); - for (int i = 0; i < N; ++i) { - if (mEnabledKeyboardSubtypesOfCurrentInputMethod.get(i).equals(mCurrentSubtype)) { - return i; - } - } - return 0; - } - - private InputMethodSubtypeCompatWrapper getNextKeyboardSubtypeInternal(int index) { - return mEnabledKeyboardSubtypesOfCurrentInputMethod.get(normalize(index + 1)); - } - - private InputMethodSubtypeCompatWrapper getPreviousKeyboardSubtypeInternal(int index) { - return mEnabledKeyboardSubtypesOfCurrentInputMethod.get(normalize(index - 1)); - } - } - public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { if (returnsNameInThisLocale) { return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); @@ -609,14 +520,6 @@ public class SubtypeSwitcher { return getDisplayLanguage(getInputLocale()); } - public String getNextInputLanguageName() { - return mLanguageBarInfo.getNextLanguage(); - } - - public String getPreviousInputLanguageName() { - return mLanguageBarInfo.getPreviousLanguage(); - } - ///////////////////////////// // Other utility functions // ///////////////////////////// @@ -653,24 +556,4 @@ public class SubtypeSwitcher { supportedLocalesString.split("\\s+")); return voiceInputSupportedLocales.contains(locale); } - - private void changeToNextSubtype() { - final InputMethodSubtypeCompatWrapper subtype = - mLanguageBarInfo.getNextKeyboardSubtype(); - switchToTargetIME(mInputMethodId, subtype); - } - - private void changeToPreviousSubtype() { - final InputMethodSubtypeCompatWrapper subtype = - mLanguageBarInfo.getPreviousKeyboardSubtype(); - switchToTargetIME(mInputMethodId, subtype); - } - - public void toggleLanguage(boolean next) { - if (next) { - changeToNextSubtype(); - } else { - changeToPreviousSubtype(); - } - } } |