diff options
Diffstat (limited to 'java/src')
22 files changed, 258 insertions, 574 deletions
diff --git a/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java index 8e22bbc79..831559809 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodInfoCompatWrapper.java @@ -16,6 +16,7 @@ package com.android.inputmethod.compat; +import android.content.pm.PackageManager; import android.content.pm.ServiceInfo; import android.view.inputmethod.InputMethodInfo; @@ -56,4 +57,21 @@ public class InputMethodInfoCompatWrapper { return new InputMethodSubtypeCompatWrapper(CompatUtils.invoke(mImi, null, METHOD_getSubtypeAt, index)); } + + public CharSequence loadLabel(PackageManager pm) { + return mImi.loadLabel(pm); + } + + @Override + public boolean equals(Object o) { + if (o instanceof InputMethodInfoCompatWrapper) { + return mImi.equals(((InputMethodInfoCompatWrapper)o).mImi); + } + return false; + } + + @Override + public int hashCode() { + return mImi.hashCode(); + } } diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index 1cc13f249..51dc4cd37 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -16,21 +16,28 @@ package com.android.inputmethod.compat; -import com.android.inputmethod.deprecated.LanguageSwitcherProxy; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.Utils; - +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.os.IBinder; import android.text.TextUtils; import android.util.Log; import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodManager; +import com.android.inputmethod.deprecated.LanguageSwitcherProxy; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SubtypeSwitcher; +import com.android.inputmethod.latin.Utils; + import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -72,27 +79,27 @@ public class InputMethodManagerCompatWrapper { private static final String VOICE_MODE = "voice"; private static final String KEYBOARD_MODE = "keyboard"; + private InputMethodServiceCompatWrapper mService; private InputMethodManager mImm; + private PackageManager mPackageManager; + private ApplicationInfo mApplicationInfo; private LanguageSwitcherProxy mLanguageSwitcherProxy; private String mLatinImePackageName; - private InputMethodManagerCompatWrapper() { - } - - public static InputMethodManagerCompatWrapper getInstance(Context context) { - if (sInstance.mImm == null) { - sInstance.init(context); - } + public static InputMethodManagerCompatWrapper getInstance() { + if (sInstance.mImm == null) + Log.w(TAG, "getInstance() is called before initialization"); return sInstance; } - private synchronized void init(Context context) { - mImm = (InputMethodManager) context.getSystemService( + public static void init(InputMethodServiceCompatWrapper service) { + sInstance.mService = service; + sInstance.mImm = (InputMethodManager) service.getSystemService( Context.INPUT_METHOD_SERVICE); - if (context instanceof LatinIME) { - mLatinImePackageName = context.getPackageName(); - } - mLanguageSwitcherProxy = LanguageSwitcherProxy.getInstance(); + sInstance.mLatinImePackageName = service.getPackageName(); + sInstance.mPackageManager = service.getPackageManager(); + sInstance.mApplicationInfo = service.getApplicationInfo(); + sInstance.mLanguageSwitcherProxy = LanguageSwitcherProxy.getInstance(); } public InputMethodSubtypeCompatWrapper getCurrentInputMethodSubtype() { @@ -196,11 +203,15 @@ public class InputMethodManagerCompatWrapper { return shortcutMap; } + // We don't call this method when we switch between subtypes within this IME. public void setInputMethodAndSubtype( IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) { + // TODO: Support subtype change on non-subtype-supported platform. if (subtype != null && subtype.hasOriginalObject()) { CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype, token, id, subtype.getOriginalObject()); + } else { + mImm.setInputMethod(token, id); } } @@ -222,6 +233,87 @@ public class InputMethodManagerCompatWrapper { public void showInputMethodPicker() { if (mImm == null) return; - mImm.showInputMethodPicker(); + if (SUBTYPE_SUPPORTED) { + mImm.showInputMethodPicker(); + return; + } + + // The code below are based on {@link InputMethodManager#showInputMethodMenuInternal}. + + final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( + this, mLatinImePackageName); + final List<InputMethodSubtypeCompatWrapper> myImsList = getEnabledInputMethodSubtypeList( + myImi, true); + final InputMethodSubtypeCompatWrapper currentIms = getCurrentInputMethodSubtype(); + final List<InputMethodInfoCompatWrapper> imiList = getEnabledInputMethodList(); + imiList.remove(myImi); + Collections.sort(imiList, new Comparator<InputMethodInfoCompatWrapper>() { + @Override + public int compare(InputMethodInfoCompatWrapper imi1, + InputMethodInfoCompatWrapper imi2) { + final CharSequence imiId1 = imi1.loadLabel(mPackageManager) + "/" + imi1.getId(); + final CharSequence imiId2 = imi2.loadLabel(mPackageManager) + "/" + imi2.getId(); + return imiId1.toString().compareTo(imiId2.toString()); + } + }); + + final int myImsCount = myImsList.size(); + final int imiCount = imiList.size(); + final CharSequence[] items = new CharSequence[myImsCount + imiCount]; + + int checkedItem = 0; + int index = 0; + final CharSequence myImiLabel = myImi.loadLabel(mPackageManager); + for (int i = 0; i < myImsCount; i++) { + InputMethodSubtypeCompatWrapper ims = myImsList.get(i); + if (currentIms.equals(ims)) + checkedItem = index; + final CharSequence title = TextUtils.concat( + ims.getDisplayName(mService, mLatinImePackageName, mApplicationInfo), + " (" + myImiLabel, ")"); + items[index] = title; + index++; + } + + for (int i = 0; i < imiCount; i++) { + final InputMethodInfoCompatWrapper imi = imiList.get(i); + final CharSequence title = imi.loadLabel(mPackageManager); + items[index] = title; + index++; + } + + final OnClickListener buttonListener = new OnClickListener() { + @Override + public void onClick(DialogInterface di, int whichButton) { + final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS"); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED + | Intent.FLAG_ACTIVITY_CLEAR_TOP); + mService.startActivity(intent); + } + }; + final InputMethodServiceCompatWrapper service = mService; + final IBinder token = service.getWindow().getWindow().getAttributes().token; + final OnClickListener selectionListener = new OnClickListener() { + @Override + public void onClick(DialogInterface di, int which) { + di.dismiss(); + if (which < myImsCount) { + final int imsIndex = which; + final InputMethodSubtypeCompatWrapper ims = myImsList.get(imsIndex); + service.notifyOnCurrentInputMethodSubtypeChanged(ims); + } else { + final int imiIndex = which - myImsCount; + final InputMethodInfoCompatWrapper imi = imiList.get(imiIndex); + setInputMethodAndSubtype(token, imi.getId(), null); + } + } + }; + + final AlertDialog.Builder builder = new AlertDialog.Builder(mService) + .setTitle(mService.getString(R.string.selectInputMethod)) + .setNeutralButton(R.string.configure_input_method, buttonListener) + .setSingleChoiceItems(items, checkedItem, selectionListener); + mService.showOptionDialogInternal(builder.create()); } } diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java index 7d8c745c3..7aab66d05 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java @@ -16,10 +16,15 @@ package com.android.inputmethod.compat; +import android.app.AlertDialog; import android.inputmethodservice.InputMethodService; +import android.os.IBinder; +import android.view.Window; +import android.view.WindowManager; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.deprecated.LanguageSwitcherProxy; +import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher; public class InputMethodServiceCompatWrapper extends InputMethodService { @@ -32,10 +37,33 @@ public class InputMethodServiceCompatWrapper extends InputMethodService { private InputMethodManagerCompatWrapper mImm; + // For compatibility of {@link InputMethodManager#showInputMethodPicker}. + // TODO: Move this variable back to LatinIME when this compatibility wrapper is removed. + protected AlertDialog mOptionsDialog; + + public void showOptionDialogInternal(AlertDialog dialog) { + final IBinder windowToken = KeyboardSwitcher.getInstance().getKeyboardView() + .getWindowToken(); + if (windowToken == null) return; + + dialog.setCancelable(true); + dialog.setCanceledOnTouchOutside(true); + + final Window window = dialog.getWindow(); + final WindowManager.LayoutParams lp = window.getAttributes(); + lp.token = windowToken; + lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; + window.setAttributes(lp); + window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); + + mOptionsDialog = dialog; + dialog.show(); + } + @Override public void onCreate() { super.onCreate(); - mImm = InputMethodManagerCompatWrapper.getInstance(this); + mImm = InputMethodManagerCompatWrapper.getInstance(); } // When the API level is 10 or previous, notifyOnCurrentInputMethodSubtypeChanged should diff --git a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java index 667d86c42..b6b86a4a0 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java @@ -16,13 +16,16 @@ package com.android.inputmethod.compat; -import com.android.inputmethod.latin.LatinImeLogger; - +import android.content.Context; +import android.content.pm.ApplicationInfo; import android.text.TextUtils; import android.util.Log; +import com.android.inputmethod.latin.LatinImeLogger; + import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Locale; // TODO: Override this class with the concrete implementation if we need to take care of the // performance. @@ -50,6 +53,9 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper CompatUtils.getMethod(CLASS_InputMethodSubtype, "getExtraValueOf", String.class); private static final Method METHOD_isAuxiliary = CompatUtils.getMethod(CLASS_InputMethodSubtype, "isAuxiliary"); + private static final Method METHOD_getDisplayName = + CompatUtils.getMethod(CLASS_InputMethodSubtype, "getDisplayName", Context.class, + String.class, ApplicationInfo.class); private final int mDummyNameResId; private final int mDummyIconResId; @@ -122,6 +128,28 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper return (Boolean)CompatUtils.invoke(mObj, false, METHOD_isAuxiliary); } + public CharSequence getDisplayName(Context context, String packageName, + ApplicationInfo appInfo) { + if (mObj != null) { + return (CharSequence)CompatUtils.invoke( + mObj, "", METHOD_getDisplayName, context, packageName, appInfo); + } + + // The code below are based on {@link InputMethodSubtype#getDisplayName}. + + final Locale locale = new Locale(getLocale()); + final String localeStr = locale.getDisplayName(); + if (getNameResId() == 0) { + return localeStr; + } + final CharSequence subtypeName = context.getText(getNameResId()); + if (!TextUtils.isEmpty(localeStr)) { + return String.format(subtypeName.toString(), localeStr); + } else { + return localeStr; + } + } + public boolean isDummy() { return !hasOriginalObject(); } diff --git a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java index 8e2a2e0b8..a6304d877 100644 --- a/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/VibratorCompatWrapper.java @@ -23,7 +23,7 @@ import java.lang.reflect.Method; public class VibratorCompatWrapper { private static final Method METHOD_hasVibrator = CompatUtils.getMethod(Vibrator.class, - "hasVibrator", int.class); + "hasVibrator"); private static final VibratorCompatWrapper sInstance = new VibratorCompatWrapper(); private Vibrator mVibrator; diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 85993ea4d..c82c570ee 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -129,7 +129,7 @@ public class VoiceProxy implements VoiceInput.UiListener { mHandler = h; mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); - mImm = InputMethodManagerCompatWrapper.getInstance(service); + mImm = InputMethodManagerCompatWrapper.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); if (VOICE_INSTALLED) { mVoiceInput = new VoiceInput(service, this); diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 45bf68cdf..33ab511a5 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -95,7 +95,7 @@ public class Key { * {@link Keyboard#EDGE_LEFT}, {@link Keyboard#EDGE_RIGHT}, * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}. */ - public final int mEdgeFlags; + private int mEdgeFlags; /** Whether this is a functional key which has different key top than normal key */ public final boolean mFunctional; /** Whether this key repeats itself when held down */ @@ -273,8 +273,7 @@ public class Key { mFunctional = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional, false); mSticky = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky, false); mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true); - mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0) - | row.mRowEdgeFlags; + mEdgeFlags = 0; final KeyboardIconsSet iconsSet = mKeyboard.mIconsSet; mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr, @@ -316,6 +315,10 @@ public class Key { } } + public void addEdgeFlags(int flags) { + mEdgeFlags |= flags; + } + public CharSequence getCaseAdjustedLabel() { return mKeyboard.adjustLabelCase(mLabel); } @@ -441,15 +444,18 @@ public class Key { * assume that all points between the key and the edge are considered to be on the key. */ public boolean isOnKey(int x, int y) { + final int left = mX - mGap / 2; + final int right = left + mWidth + mGap; + final int top = mY; + final int bottom = top + mHeight + mKeyboard.getVerticalGap(); final int flags = mEdgeFlags; + if (flags == 0) { + return x >= left && x <= right && y >= top && y <= bottom; + } final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0; final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0; final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0; final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0; - final int left = mX - mGap / 2; - final int right = left + mWidth + mGap; - final int top = mY; - final int bottom = top + mHeight + mKeyboard.getVerticalGap(); // In order to mitigate rounding errors, we use (left <= x <= right) here. return (x >= left || leftEdge) && (x <= right || rightEdge) && (y >= top || topEdge) && (y <= bottom || bottomEdge); 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 7ad947c67..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; } @@ -821,7 +820,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW)) || (settingsKeyMode.equals(res.getString(SETTINGS_KEY_MODE_AUTO)) && Utils.hasMultipleEnabledIMEsOrSubtypes( - (InputMethodManagerCompatWrapper.getInstance(context))))) { + (InputMethodManagerCompatWrapper.getInstance())))) { return true; } return false; 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/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java index e35db8955..fcda91990 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -135,6 +135,8 @@ public class KeyboardParser { private int mMaxRowWidth = 0; private int mTotalHeight = 0; private Row mCurrentRow = null; + private boolean mLeftEdge; + private Key mRightEdgeKey = null; private final KeyStyles mKeyStyles = new KeyStyles(); public KeyboardParser(Keyboard keyboard, Context context) { @@ -623,6 +625,8 @@ public class KeyboardParser { mCurrentX = 0; setSpacer(mCurrentX, mHorizontalEdgesPadding); mCurrentRow = row; + mLeftEdge = true; + mRightEdgeKey = null; } private void endRow() { @@ -633,10 +637,19 @@ public class KeyboardParser { mMaxRowWidth = mCurrentX; mCurrentY += mCurrentRow.mDefaultHeight; mCurrentRow = null; + if (mRightEdgeKey != null) { + mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT); + mRightEdgeKey = null; + } } private void endKey(Key key) { mCurrentX = key.mX - key.mGap / 2 + key.mWidth + key.mGap; + if (mLeftEdge) { + key.addEdgeFlags(Keyboard.EDGE_LEFT); + mLeftEdge = false; + } + mRightEdgeKey = key; } private void endKeyboard(int defaultVerticalGap) { @@ -646,6 +659,8 @@ public class KeyboardParser { private void setSpacer(int keyXPos, int width) { mCurrentX = keyXPos + width; + mLeftEdge = false; + mRightEdgeKey = null; } public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/Row.java b/java/src/com/android/inputmethod/keyboard/internal/Row.java index 06aadcc05..b34d6d06f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/Row.java +++ b/java/src/com/android/inputmethod/keyboard/internal/Row.java @@ -38,11 +38,6 @@ public class Row { public final int mDefaultHorizontalGap; /** Vertical gap following this row. */ public final int mVerticalGap; - /** - * Edge flags for this row of keys. Possible values that can be assigned are - * {@link Keyboard#EDGE_TOP EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM EDGE_BOTTOM} - */ - public final int mRowEdgeFlags; private final Keyboard mKeyboard; @@ -61,10 +56,6 @@ public class Row { mVerticalGap = KeyboardParser.getDimensionOrFraction(a, R.styleable.Keyboard_verticalGap, keyboardHeight, keyboard.getVerticalGap()); a.recycle(); - a = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.Keyboard_Row); - mRowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0); - a.recycle(); } public Keyboard getKeyboard() { 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 95cae6ed5..5d8fd3411 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -29,7 +29,6 @@ import android.inputmethodservice.InputMethodService; import android.media.AudioManager; import android.net.ConnectivityManager; import android.os.Debug; -import android.os.IBinder; import android.os.Message; import android.os.SystemClock; import android.preference.PreferenceActivity; @@ -45,8 +44,6 @@ import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; -import android.view.Window; -import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; @@ -142,8 +139,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private Suggest mSuggest; private CompletionInfo[] mApplicationSpecifiedCompletions; - private AlertDialog mOptionsDialog; - private InputMethodManagerCompatWrapper mImm; private Resources mResources; private SharedPreferences mPrefs; @@ -361,14 +356,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mPrefs = prefs; LatinImeLogger.init(this, prefs); LanguageSwitcherProxy.init(this, prefs); - SubtypeSwitcher.init(this, prefs); + InputMethodManagerCompatWrapper.init(this); + SubtypeSwitcher.init(this); KeyboardSwitcher.init(this, prefs); Recorrection.init(this, prefs); AccessibilityUtils.init(this, prefs); super.onCreate(); - mImm = InputMethodManagerCompatWrapper.getInstance(this); + mImm = InputMethodManagerCompatWrapper.getInstance(); mInputMethodId = Utils.getInputMethodId(mImm, getPackageName()); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance(); @@ -1134,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; @@ -1911,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()) { @@ -2097,7 +2076,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } }; - showOptionsMenuInternal(title, items, listener); + final AlertDialog.Builder builder = new AlertDialog.Builder(this) + .setIcon(R.drawable.ic_dialog_keyboard) + .setNegativeButton(android.R.string.cancel, null) + .setItems(items, listener) + .setTitle(title); + showOptionDialogInternal(builder.create()); } private void showOptionsMenu() { @@ -2120,28 +2104,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } }; - showOptionsMenuInternal(title, items, listener); - } - - private void showOptionsMenuInternal(CharSequence title, CharSequence[] items, - DialogInterface.OnClickListener listener) { - final IBinder windowToken = mKeyboardSwitcher.getKeyboardView().getWindowToken(); - if (windowToken == null) return; - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setCancelable(true); - builder.setIcon(R.drawable.ic_dialog_keyboard); - builder.setNegativeButton(android.R.string.cancel, null); - builder.setItems(items, listener); - builder.setTitle(title); - mOptionsDialog = builder.create(); - mOptionsDialog.setCanceledOnTouchOutside(true); - Window window = mOptionsDialog.getWindow(); - WindowManager.LayoutParams lp = window.getAttributes(); - lp.token = windowToken; - lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; - window.setAttributes(lp); - window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); - mOptionsDialog.show(); + final AlertDialog.Builder builder = new AlertDialog.Builder(this) + .setIcon(R.drawable.ic_dialog_keyboard) + .setNegativeButton(android.R.string.cancel, null) + .setItems(items, listener) + .setTitle(title); + showOptionDialogInternal(builder.create()); } @Override diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 33e9bc35f..54f0a1b4d 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -498,7 +498,7 @@ public class Settings extends InputMethodSettingsActivity if (pref == mInputLanguageSelection) { startActivity(CompatUtils.getInputLanguageSelectionIntent( Utils.getInputMethodId( - InputMethodManagerCompatWrapper.getInstance(getActivityInternal()), + InputMethodManagerCompatWrapper.getInstance(), getActivityInternal().getApplicationInfo().packageName), 0)); return true; } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 8fc19ae87..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,10 +95,10 @@ 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(service); + mImm = InputMethodManagerCompatWrapper.getInstance(); mConnectivityManager = (ConnectivityManager) service.getSystemService( Context.CONNECTIVITY_SERVICE); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); @@ -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(); - } - } } |