From 3e2368286294077421240b89e7e3cadb435ce4e0 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 6 Apr 2011 11:17:08 +0900 Subject: Reinforce user-history based bigram use. - Have user-history based bigrams used as soon as they are entered, not after 6 times. - Limit bigram frequency to 255 (this limits the multiplier to 1.8, and has no effect on main dict bigrams which already have this limit) - Some TODO resolving bug: 4192129 Change-Id: I4777f1a58c43dd55381c4b01252d722ab3a70547 --- .../inputmethod/latin/ExpandableDictionary.java | 29 ++++++++++++---------- .../inputmethod/latin/UserBigramDictionary.java | 6 ----- 2 files changed, 16 insertions(+), 19 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index d87fbce51..be2c6b21b 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -32,12 +32,14 @@ public class ExpandableDictionary extends Dictionary { */ protected static final int MAX_WORD_LENGTH = 32; + // Bigram frequency is a fixed point number with 1 meaning 1.2 and 255 meaning 1.8. + protected static final int BIGRAM_MAX_FREQUENCY = 255; + private Context mContext; private char[] mWordBuilder = new char[MAX_WORD_LENGTH]; private int mDicTypeId; private int mMaxDepth; private int mInputLength; - private StringBuilder sb = new StringBuilder(MAX_WORD_LENGTH); private static final char QUOTE = '\''; @@ -98,6 +100,7 @@ public class ExpandableDictionary extends Dictionary { public int addFrequency(int add) { mFrequency += add; + if (mFrequency > BIGRAM_MAX_FREQUENCY) mFrequency = BIGRAM_MAX_FREQUENCY; return mFrequency; } } @@ -462,6 +465,9 @@ public class ExpandableDictionary extends Dictionary { } } + // Local to reverseLookUp, but do not allocate each time. + private final char[] mLookedUpString = new char[MAX_WORD_LENGTH]; + /** * reverseLookUp retrieves the full word given a list of terminal nodes and adds those words * through callback. @@ -474,18 +480,15 @@ public class ExpandableDictionary extends Dictionary { for (NextWord nextWord : terminalNodes) { node = nextWord.mWord; freq = nextWord.getFrequency(); - // TODO Not the best way to limit suggestion threshold - if (freq >= UserBigramDictionary.SUGGEST_THRESHOLD) { - sb.setLength(0); - do { - sb.insert(0, node.mCode); - node = node.mParent; - } while(node != null); - - // TODO better way to feed char array? - callback.addWord(sb.toString().toCharArray(), 0, sb.length(), freq, mDicTypeId, - DataType.BIGRAM); - } + int index = MAX_WORD_LENGTH; + do { + --index; + mLookedUpString[index] = node.mCode; + node = node.mParent; + } while (node != null); + + callback.addWord(mLookedUpString, index, MAX_WORD_LENGTH - index, freq, mDicTypeId, + DataType.BIGRAM); } } diff --git a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java index 4750fb991..bb6642cd9 100644 --- a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java @@ -44,12 +44,6 @@ public class UserBigramDictionary extends ExpandableDictionary { /** Maximum frequency for all pairs */ private static final int FREQUENCY_MAX = 127; - /** - * If this pair is typed 6 times, it would be suggested. - * Should be smaller than ContactsDictionary.FREQUENCY_FOR_CONTACTS_BIGRAM - */ - protected static final int SUGGEST_THRESHOLD = 6 * FREQUENCY_FOR_TYPED; - /** Maximum number of pairs. Pruning will start when databases goes above this number. */ private static int sMaxUserBigrams = 10000; -- cgit v1.2.3-83-g751a From da4bfbbbb3d3aa5dce8f0507d3f3b07ea3e0f26f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 6 Apr 2011 13:54:37 +0900 Subject: Fix popup key preview on tablet This change temporally enable popup key preview option on tablet. (config_enable_show_popup_on_keypress_option). Bug: 3286117 Change-Id: Iabbac5a333460e1ed2f8d05ba82f4bae81854b85 --- .../keyboard_key_feedback_background_holo.9.png | Bin 136 -> 4040 bytes .../keyboard_key_feedback_background_holo.9.png | Bin 1004 -> 3804 bytes .../drawable/keyboard_key_feedback_honeycomb.xml | 2 +- .../res/layout-xlarge/keyboard_popup_honeycomb.xml | 41 --------------------- java/res/layout/input_honeycomb.xml | 2 + java/res/layout/key_preview_honeycomb.xml | 2 +- java/res/layout/keyboard_popup.xml | 9 ++--- java/res/layout/keyboard_popup_honeycomb.xml | 9 ++--- java/res/values-xlarge-land/dimens.xml | 7 ++-- java/res/values-xlarge/config.xml | 3 +- java/res/values-xlarge/dimens.xml | 9 +++-- java/res/values/colors.xml | 1 - java/res/values/dimens.xml | 17 +++++---- .../android/inputmethod/keyboard/KeyboardView.java | 2 +- .../inputmethod/keyboard/LatinKeyboard.java | 2 +- .../keyboard/SlidingLocaleDrawable.java | 2 +- 16 files changed, 36 insertions(+), 72 deletions(-) delete mode 100644 java/res/layout-xlarge/keyboard_popup_honeycomb.xml (limited to 'java/src/com/android/inputmethod') diff --git a/java/res/drawable-hdpi/keyboard_key_feedback_background_holo.9.png b/java/res/drawable-hdpi/keyboard_key_feedback_background_holo.9.png index 943f9e4bc..8d6acacfb 100644 Binary files a/java/res/drawable-hdpi/keyboard_key_feedback_background_holo.9.png and b/java/res/drawable-hdpi/keyboard_key_feedback_background_holo.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_key_feedback_background_holo.9.png b/java/res/drawable-mdpi/keyboard_key_feedback_background_holo.9.png index a7acb4a4d..286cf84fc 100644 Binary files a/java/res/drawable-mdpi/keyboard_key_feedback_background_holo.9.png and b/java/res/drawable-mdpi/keyboard_key_feedback_background_holo.9.png differ diff --git a/java/res/drawable/keyboard_key_feedback_honeycomb.xml b/java/res/drawable/keyboard_key_feedback_honeycomb.xml index dd9b53e46..a3ea140cd 100644 --- a/java/res/drawable/keyboard_key_feedback_honeycomb.xml +++ b/java/res/drawable/keyboard_key_feedback_honeycomb.xml @@ -16,6 +16,6 @@ + android:drawable="@drawable/keyboard_key_feedback_more_background_holo" /> diff --git a/java/res/layout-xlarge/keyboard_popup_honeycomb.xml b/java/res/layout-xlarge/keyboard_popup_honeycomb.xml deleted file mode 100644 index 0b8229ca5..000000000 --- a/java/res/layout-xlarge/keyboard_popup_honeycomb.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - diff --git a/java/res/layout/input_honeycomb.xml b/java/res/layout/input_honeycomb.xml index 6ccc63c2b..96b10b7cc 100644 --- a/java/res/layout/input_honeycomb.xml +++ b/java/res/layout/input_honeycomb.xml @@ -31,6 +31,8 @@ latin:keyBackground="@drawable/btn_keyboard_key_honeycomb" latin:keyPreviewLayout="@layout/key_preview_honeycomb" + latin:keyPreviewHeight="@dimen/key_preview_height_holo" + latin:keyPreviewOffset="@dimen/key_preview_offset_holo" latin:popupLayout="@layout/keyboard_popup_honeycomb" latin:keyTextColorDisabled="#FF63666D" latin:keyLetterStyle="bold" diff --git a/java/res/layout/key_preview_honeycomb.xml b/java/res/layout/key_preview_honeycomb.xml index a90fe5588..2fbfbb517 100644 --- a/java/res/layout/key_preview_honeycomb.xml +++ b/java/res/layout/key_preview_honeycomb.xml @@ -23,7 +23,7 @@ android:layout_height="80sp" android:textSize="40sp" android:textColor="@color/latinkeyboard_key_color_white" - android:minWidth="24dip" + android:minWidth="32dip" android:gravity="center" android:background="@drawable/keyboard_key_feedback_honeycomb" /> diff --git a/java/res/layout/keyboard_popup.xml b/java/res/layout/keyboard_popup.xml index ac8134bfb..013662240 100644 --- a/java/res/layout/keyboard_popup.xml +++ b/java/res/layout/keyboard_popup.xml @@ -19,20 +19,19 @@ --> - + 58.0mm @@ -28,12 +28,13 @@ 13.0mm 1.1mm 0.0mm - - 13.0mm 28dip 20dip 18dip + 26.5mm + 7.5mm + 40.0mm diff --git a/java/res/values-xlarge/config.xml b/java/res/values-xlarge/config.xml index f075b1b50..ed8dc3e52 100644 --- a/java/res/values-xlarge/config.xml +++ b/java/res/values-xlarge/config.xml @@ -22,7 +22,8 @@ false false false - false + + true false false false diff --git a/java/res/values-xlarge/dimens.xml b/java/res/values-xlarge/dimens.xml index 69283202e..cdb6e89a4 100644 --- a/java/res/values-xlarge/dimens.xml +++ b/java/res/values-xlarge/dimens.xml @@ -19,7 +19,7 @@ --> - + 48.0mm @@ -28,8 +28,7 @@ 10.0mm 1.1mm 0.0mm - - 13.0mm + 40dip 12dip @@ -39,9 +38,11 @@ 26dip 16dip - 24dip 6dip + 24dip + 23.0mm + 8.0mm 46dip 15.0mm diff --git a/java/res/values/colors.xml b/java/res/values/colors.xml index 0161589a4..5e9d63203 100644 --- a/java/res/values/colors.xml +++ b/java/res/values/colors.xml @@ -21,7 +21,6 @@ #FFFFFFFF #FFFCAE00 #FFFCAE00 - #00000000 #80000000 #80FFFFFF #FFC0C0C0 diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 7f00cdba3..2cfc17de9 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -19,7 +19,7 @@ --> - + 1.265in @@ -28,24 +28,27 @@ 0.325in 0.00in 0.06in - - 80sp + 16dip + 32dip 8dip 0.390in -0.325in + + -0.05in 0.13in 0.083in - 40sp 0.13in + 80sp 0.000in - - -0.05in + 36sp + 130sp + 0.193in 42dip 63dip diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 61af15b1d..cc14589f6 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -37,7 +37,6 @@ import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Message; import android.os.SystemClock; -import android.provider.Settings; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; @@ -378,6 +377,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } mPreviewPopup.setTouchable(false); mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation); + mPreviewPopup.setClippingEnabled(false); mDelayBeforePreview = res.getInteger(R.integer.config_delay_before_preview); mDelayAfterPreview = res.getInteger(R.integer.config_delay_after_preview); mKeyLabelHorizontalPadding = (int)res.getDimension( diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 5820049bb..9b87df3fe 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -229,7 +229,7 @@ public class LatinKeyboard extends Keyboard { final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(buffer); final Resources res = mContext.getResources(); - canvas.drawColor(res.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); + canvas.drawColor(res.getColor(android.R.color.transparent), PorterDuff.Mode.CLEAR); SubtypeSwitcher subtypeSwitcher = SubtypeSwitcher.getInstance(); // If application locales are explicitly selected. diff --git a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java index 41f8c2a7c..eee0ac61b 100644 --- a/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java +++ b/java/src/com/android/inputmethod/keyboard/SlidingLocaleDrawable.java @@ -63,7 +63,7 @@ public class SlidingLocaleDrawable extends Drawable { mHeight = height; final TextPaint textPaint = new TextPaint(); textPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); - textPaint.setColor(R.color.latinkeyboard_transparent); + textPaint.setColor(android.R.color.transparent); textPaint.setTextAlign(Align.CENTER); textPaint.setAlpha(LatinKeyboard.OPACITY_FULLY_OPAQUE); textPaint.setAntiAlias(true); -- cgit v1.2.3-83-g751a From 996db15d3c018ed2a7b4eee96ea94b9f80d8e379 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 7 Apr 2011 17:16:30 +0900 Subject: Disable successive modifier key while sliding input When user starts sliding key input, sliding through successive modifier key will be ignored. Bug: 4181843 Depends: I082885bd2376ae26bdfc378c14add2b5d6be1d4e Change-Id: Ibe890b9cc1183dbe9f68a421650fcd97e7ff221c --- .../inputmethod/keyboard/PointerTracker.java | 44 ++++++++++++++++------ 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 746857819..1c918b995 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -87,6 +87,9 @@ public class PointerTracker { // true if sliding key is allowed. private boolean mIsAllowedSlidingKeyInput; + // ignore modifier key if true + private boolean mIgnoreModifierKey; + // pressed key private int mPreviousKey = NOT_A_KEY; @@ -139,8 +142,12 @@ public class PointerTracker { // Returns true if keyboard has been changed by this callback. private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) - Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding); + Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding + + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return false; if (key.mEnabled) { mListener.onPress(key.mCode, withSliding); final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; @@ -153,9 +160,13 @@ public class PointerTracker { // Note that we need primaryCode argument because the keyboard may in shifted state and the // primaryCode is different from {@link Key#mCode}. private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode) - + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y); + + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y + + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return; if (key.mEnabled) mListener.onCodeInput(primaryCode, keyCodes, x, y); } @@ -170,8 +181,12 @@ public class PointerTracker { // Note that we need primaryCode argument because the keyboard may in shifted state and the // primaryCode is different from {@link Key#mCode}. private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) { + final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode); if (DEBUG_LISTENER) - Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + withSliding); + Log.d(TAG, "onRelease : " + keyCodePrintable(primaryCode) + " sliding=" + + withSliding + " ignoreModifier=" + ignoreModifierKey); + if (ignoreModifierKey) + return; if (key.mEnabled) mListener.onRelease(primaryCode, withSliding); } @@ -329,17 +344,18 @@ public class PointerTracker { mKeyAlreadyProcessed = false; mIsRepeatableKey = false; mIsInSlidingKeyInput = false; - if (isValidKeyIndex(keyIndex)) { + mIgnoreModifierKey = false; + final Key key = getKey(keyIndex); + if (key != null) { // This onPress call may have changed keyboard layout. Those cases are detected at // {@link #setKeyboard}. In those cases, we should update keyIndex according to the new // keyboard layout. - if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex], false)) + if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false)) keyIndex = mKeyState.onDownKey(x, y, eventTime); - } - if (isValidKeyIndex(keyIndex)) { + // Accessibility disables key repeat because users may need to pause on a key to hear // its spoken description. - if (mKeys[keyIndex].mRepeatable && !mIsAccessibilityEnabled) { + if (key.mRepeatable && !mIsAccessibilityEnabled) { repeatKey(keyIndex); mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); mIsRepeatableKey = true; @@ -349,6 +365,12 @@ public class PointerTracker { showKeyPreviewAndUpdateKeyGraphics(keyIndex); } + private void startSlidingKeyInput(Key key) { + if (!mIsInSlidingKeyInput) + mIgnoreModifierKey = isModifierCode(key.mCode); + mIsInSlidingKeyInput = true; + } + public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { if (ENABLE_ASSERTION) checkAssertion(queue); if (DEBUG_MOVE_EVENT) @@ -376,8 +398,8 @@ public class PointerTracker { // The pointer has been slid in to the new key from the previous key, we must call // onRelease() first to notify that the previous key has been released, then call // onPress() to notify that the new key is being pressed. - mIsInSlidingKeyInput = true; callListenerOnRelease(oldKey, oldKey.mCode, true); + startSlidingKeyInput(oldKey); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { // This onPress call may have changed keyboard layout. Those cases are detected @@ -411,8 +433,8 @@ public class PointerTracker { if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) { // The pointer has been slid out from the previous key, we must call onRelease() to // notify that the previous key has been released. - mIsInSlidingKeyInput = true; callListenerOnRelease(oldKey, oldKey.mCode, true); + startSlidingKeyInput(oldKey); mHandler.cancelLongPressTimers(); if (mIsAllowedSlidingKeyInput) { keyState.onMoveToNewKey(keyIndex, x ,y); @@ -423,7 +445,7 @@ public class PointerTracker { } } } - showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex()); + showKeyPreviewAndUpdateKeyGraphics(keyState.getKeyIndex()); } public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { -- cgit v1.2.3-83-g751a From e7c0e73a19e6eb6cb9a4aded8a0a7240db544d85 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 7 Apr 2011 16:12:00 +0900 Subject: Simplify the Key's on state transition Because handling shift locked state of alphabet keyboard is done by KeyboardSwitcher, there is no need to change the "on" state of Key when releasing the key. On the other hand, symbol and symbol shifted keyboard has fixed "on" state "ALT/MORE" key. This change also renames the attribute "isModifier" to "isFunctional". Change-Id: I082885bd2376ae26bdfc378c14add2b5d6be1d4e --- java/res/values/attrs.xml | 4 +-- java/res/xml-xlarge/kbd_key_styles.xml | 2 +- java/res/xml/kbd_key_styles.xml | 2 +- java/res/xml/kbd_qwerty_black_symbol.xml | 8 ++--- java/res/xml/kbd_qwerty_f1.xml | 8 ++--- java/src/com/android/inputmethod/keyboard/Key.java | 37 ++++++++-------------- .../android/inputmethod/keyboard/KeyStyles.java | 2 +- .../com/android/inputmethod/keyboard/Keyboard.java | 2 +- .../inputmethod/keyboard/KeyboardSwitcher.java | 12 +++---- .../inputmethod/keyboard/PointerTracker.java | 4 +-- 10 files changed, 34 insertions(+), 47 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index f0da2744b..28c948b65 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -107,8 +107,8 @@ - - + + diff --git a/java/res/xml-xlarge/kbd_key_styles.xml b/java/res/xml-xlarge/kbd_key_styles.xml index fc06d00fc..4fefe0056 100644 --- a/java/res/xml-xlarge/kbd_key_styles.xml +++ b/java/res/xml-xlarge/kbd_key_styles.xml @@ -28,7 +28,7 @@ > + latin:isFunctional="true" /> + latin:isFunctional="true" /> @@ -46,7 +46,7 @@ latin:code="@integer/key_switch_alpha_symbol" latin:keyLabel="@string/label_to_symbol_key" latin:keyWidth="20%p" - latin:isModifier="true" + latin:isFunctional="true" latin:keyEdgeFlags="left" /> @@ -67,7 +67,7 @@ latin:keyIcon="@drawable/sym_bkeyboard_123_mic" latin:iconPreview="@drawable/sym_keyboard_feedback_123_mic" latin:keyWidth="15%p" - latin:isModifier="true" + latin:isFunctional="true" latin:keyEdgeFlags="left" /> @@ -75,7 +75,7 @@ latin:code="@integer/key_switch_alpha_symbol" latin:keyLabel="@string/label_to_symbol_key" latin:keyWidth="15%p" - latin:isModifier="true" + latin:isFunctional="true" latin:keyEdgeFlags="left" /> diff --git a/java/res/xml/kbd_qwerty_f1.xml b/java/res/xml/kbd_qwerty_f1.xml index 6bb96c0a0..008448b26 100644 --- a/java/res/xml/kbd_qwerty_f1.xml +++ b/java/res/xml/kbd_qwerty_f1.xml @@ -29,7 +29,7 @@ latin:keyLabel="/" latin:keyHintIcon="@drawable/hint_popup" latin:popupCharacters="@string/alternates_for_settings_slash" - latin:isModifier="true" /> + latin:isFunctional="true" /> + latin:isFunctional="true" /> @@ -57,7 +57,7 @@ > + latin:isFunctional="true" /> + latin:isFunctional="true" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 7396f0518..f578bd613 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -83,8 +83,8 @@ public class Key { * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}. */ public final int mEdgeFlags; - /** Whether this is a modifier key, such as Shift or Alt */ - public final boolean mModifier; + /** 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 */ public final boolean mRepeatable; @@ -93,8 +93,8 @@ public class Key { /** The current pressed state of this key */ public boolean mPressed; - /** If this is a sticky key, is it on? */ - public boolean mOn; + /** If this is a sticky key, is its highlight on? */ + public boolean mHighlightOn; /** Key is enabled and responds on press */ public boolean mEnabled = true; @@ -150,7 +150,7 @@ public class Key { mManualTemporaryUpperCaseHintIcon = null; mManualTemporaryUpperCaseCode = Keyboard.CODE_DUMMY; mLabelOption = 0; - mModifier = false; + mFunctional = false; mSticky = false; mRepeatable = false; mPopupCharacters = null; @@ -224,7 +224,7 @@ public class Key { mKeyboard.getMaxPopupKeyboardColumn()); mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false); - mModifier = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isModifier, false); + 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) @@ -315,22 +315,19 @@ public class Key { /** * Informs the key that it has been pressed, in case it needs to change its appearance or * state. - * @see #onReleased(boolean) + * @see #onReleased() */ public void onPressed() { - mPressed = !mPressed; + mPressed = true; } /** - * Changes the pressed state of the key. If it is a sticky key, it will also change the - * toggled state of the key if the finger was release inside. - * @param inside whether the finger was released inside the key + * Informs the key that it has been released, in case it needs to change its appearance or + * state. * @see #onPressed() */ - public void onReleased(boolean inside) { - mPressed = !mPressed; - if (mSticky && !mKeyboard.isShiftLockEnabled(this)) - mOn = !mOn; + public void onReleased() { + mPressed = false; } public boolean isInside(int x, int y) { @@ -376,12 +373,6 @@ public class Key { return dx * dx + dy * dy; } - // sticky is used for shift key. If a key is not sticky and is modifier, - // the key will be treated as functional. - private boolean isFunctionalKey() { - return !mSticky && mModifier; - } - /** * Returns the drawable state for the key, based on the current state and type of the key. * @return the drawable state of the key. @@ -389,7 +380,7 @@ public class Key { */ public int[] getCurrentDrawableState() { final boolean pressed = mEnabled && mPressed; - if (isFunctionalKey()) { + if (!mSticky && mFunctional) { if (pressed) { return KEY_STATE_FUNCTIONAL_PRESSED; } else { @@ -399,7 +390,7 @@ public class Key { int[] states = KEY_STATE_NORMAL; - if (mOn) { + if (mHighlightOn) { if (pressed) { states = KEY_STATE_PRESSED_ON; } else { diff --git a/java/src/com/android/inputmethod/keyboard/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/KeyStyles.java index 169f2e6c3..d464c2029 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/KeyStyles.java @@ -185,7 +185,7 @@ public class KeyStyles { readDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); readDrawable(keyAttr, R.styleable.Keyboard_Key_keyHintIcon); readDrawable(keyAttr, R.styleable.Keyboard_Key_shiftedIcon); - readBoolean(keyAttr, R.styleable.Keyboard_Key_isModifier); + readBoolean(keyAttr, R.styleable.Keyboard_Key_isFunctional); readBoolean(keyAttr, R.styleable.Keyboard_Key_isSticky); readBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable); readBoolean(keyAttr, R.styleable.Keyboard_Key_enabled); diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 06d44680d..418188209 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -293,7 +293,7 @@ public class Keyboard { public boolean setShiftLocked(boolean newShiftLockState) { final Map shiftedIcons = getShiftedIcons(); for (final Key key : getShiftKeys()) { - key.mOn = newShiftLockState; + key.mHighlightOn = newShiftLockState; key.setIcon(newShiftLockState ? shiftedIcons.get(key) : mNormalShiftIcons.get(key)); } mShiftState.setShiftLocked(newShiftLockState); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index cfa3c446e..dd25b3427 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -263,10 +263,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols; final String xmlName = res.getResourceEntryName(xmlId); mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true); + attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, false); xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift; mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode, - attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true); + attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, false); } public int getKeyboardMode() { @@ -565,16 +565,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mCurrentId = mSymbolsShiftedId; keyboard = getKeyboard(mCurrentId); // Symbol shifted keyboard has an ALT key that has a caps lock style indicator. To - // enable the indicator, we need to call enableShiftLock() and setShiftLocked(true). - // Thus we can keep the ALT key's Key.on value true while LatinKey.onRelease() is - // called. + // enable the indicator, we need to call setShiftLocked(true). keyboard.setShiftLocked(true); } else { mCurrentId = mSymbolsId; keyboard = getKeyboard(mCurrentId); // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the - // indicator, we need to call enableShiftLock() and setShiftLocked(false). - keyboard.setShifted(false); + // indicator, we need to call setShiftLocked(false). + keyboard.setShiftLocked(false); } setKeyboard(keyboard); } diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 1c918b995..c28197014 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -258,9 +258,7 @@ public class PointerTracker { mPreviousKey = keyIndex; if (keyIndex != oldKeyIndex) { if (isValidKeyIndex(oldKeyIndex)) { - // if new key index is not a key, old key was just released inside of the key. - final boolean inside = (keyIndex == NOT_A_KEY); - mKeys[oldKeyIndex].onReleased(inside); + mKeys[oldKeyIndex].onReleased(); mProxy.invalidateKey(mKeys[oldKeyIndex]); } if (isValidKeyIndex(keyIndex)) { -- cgit v1.2.3-83-g751a From b5d17e52fcda39d540822e615bfb7ed5074e0034 Mon Sep 17 00:00:00 2001 From: satok Date: Wed, 6 Apr 2011 11:14:20 +0900 Subject: Add logOnSeparator This is a supplement for I9abb8141f23100d Change-Id: I529d2a78f4fe630611db4cba830d933370c8c34f --- .../com/android/inputmethod/latin/LatinIME.java | 23 +++++++++++----------- .../android/inputmethod/latin/LatinImeLogger.java | 7 +++++-- .../android/inputmethod/latin/TextEntryState.java | 18 +++++++++++++---- java/src/com/android/inputmethod/latin/Utils.java | 17 +++++++++++----- 4 files changed, 42 insertions(+), 23 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 35f43124d..6a858fe99 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -30,7 +30,6 @@ import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardView; import com.android.inputmethod.keyboard.LatinKeyboard; import com.android.inputmethod.keyboard.LatinKeyboardView; -import com.android.inputmethod.latin.Utils.RingCharBuffer; import android.app.AlertDialog; import android.content.BroadcastReceiver; @@ -1174,10 +1173,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (primaryCode != Keyboard.CODE_ENTER) { mJustAddedAutoSpace = false; } - RingCharBuffer.getInstance().push((char)primaryCode, x, y); - LatinImeLogger.logOnInputChar(); if (isWordSeparator(primaryCode)) { - handleSeparator(primaryCode); + handleSeparator(primaryCode, x, y); } else { handleCharacter(primaryCode, keyCodes, x, y); } @@ -1357,10 +1354,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } switcher.updateShiftState(); if (LatinIME.PERF_DEBUG) measureCps(); - TextEntryState.typedCharacter((char) code, isWordSeparator(code)); + TextEntryState.typedCharacter((char) code, isWordSeparator(code), x, y); } - private void handleSeparator(int primaryCode) { + private void handleSeparator(int primaryCode, int x, int y) { mVoiceProxy.handleSeparator(); // Should dismiss the "Touch again to save" message when handling separator @@ -1381,7 +1378,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // in Italian dov' should not be expanded to dove' because the elision // requires the last vowel to be removed. if (mAutoCorrectOn && primaryCode != '\'') { - pickedDefault = pickDefaultSuggestion(); + pickedDefault = pickDefaultSuggestion(primaryCode); // Picked the suggestion by the space key. We consider this // as "added an auto space". if (primaryCode == Keyboard.CODE_SPACE) { @@ -1403,7 +1400,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar reswapPeriodAndSpace(); } - TextEntryState.typedCharacter((char) primaryCode, true); + TextEntryState.typedCharacter((char) primaryCode, true, x, y); if (TextEntryState.isPunctuationAfterAccepted() && primaryCode != Keyboard.CODE_ENTER) { swapPunctuationAndSpace(); } else if (isSuggestionsRequested() && primaryCode == Keyboard.CODE_SPACE) { @@ -1592,14 +1589,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar setCandidatesViewShown(isCandidateStripVisible()); } - private boolean pickDefaultSuggestion() { + private boolean pickDefaultSuggestion(int separatorCode) { // Complete any pending candidate query first if (mHandler.hasPendingUpdateSuggestions()) { mHandler.cancelUpdateSuggestions(); updateSuggestions(); } if (mBestWord != null && mBestWord.length() > 0) { - TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord); + TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode); mJustAccepted = true; pickSuggestion(mBestWord); // Add the word to the auto dictionary if it's not a known word @@ -1688,7 +1685,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Fool the state watcher so that a subsequent backspace will not do a revert, unless // we just did a correction, in which case we need to stay in // TextEntryState.State.PICKED_SUGGESTION state. - TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true); + TextEntryState.typedCharacter((char) Keyboard.CODE_SPACE, true, + WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); setPunctuationSuggestions(); } else if (!showingAddToDictionaryHint) { // If we're not showing the "Touch again to save", then show corrections again. @@ -1895,7 +1893,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ic.commitText(mComposing, 1); TextEntryState.acceptedTyped(mComposing); ic.commitText(punctuation, 1); - TextEntryState.typedCharacter(punctuation.charAt(0), true); + TextEntryState.typedCharacter(punctuation.charAt(0), true, + WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); // Clear composing text mComposing.setLength(0); } else { diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java index aaecfffdd..e460471a5 100644 --- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java +++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java @@ -45,10 +45,10 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang String before, String after, int position, List suggestions) { } - public static void logOnAutoSuggestion(String before, String after) { + public static void logOnAutoCorrection(String before, String after, int separatorCode) { } - public static void logOnAutoSuggestionCanceled() { + public static void logOnAutoCorrectionCancelled() { } public static void logOnDelete() { @@ -57,6 +57,9 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang public static void logOnInputChar() { } + public static void logOnInputSeparator() { + } + public static void logOnException(String metaData, Throwable e) { } diff --git a/java/src/com/android/inputmethod/latin/TextEntryState.java b/java/src/com/android/inputmethod/latin/TextEntryState.java index 63196430b..de13f3ae4 100644 --- a/java/src/com/android/inputmethod/latin/TextEntryState.java +++ b/java/src/com/android/inputmethod/latin/TextEntryState.java @@ -16,6 +16,8 @@ package com.android.inputmethod.latin; +import com.android.inputmethod.latin.Utils.RingCharBuffer; + import android.util.Log; public class TextEntryState { @@ -43,10 +45,12 @@ public class TextEntryState { sState = newState; } - public static void acceptedDefault(CharSequence typedWord, CharSequence actualWord) { + public static void acceptedDefault(CharSequence typedWord, CharSequence actualWord, + int separatorCode) { if (typedWord == null) return; setState(ACCEPTED_DEFAULT); - LatinImeLogger.logOnAutoSuggestion(typedWord.toString(), actualWord.toString()); + LatinImeLogger.logOnAutoCorrection( + typedWord.toString(), actualWord.toString(), separatorCode); if (DEBUG) displayState("acceptedDefault", "typedWord", typedWord, "actualWord", actualWord); } @@ -95,7 +99,7 @@ public class TextEntryState { if (DEBUG) displayState("onAbortRecorrection"); } - public static void typedCharacter(char c, boolean isSeparator) { + public static void typedCharacter(char c, boolean isSeparator, int x, int y) { final boolean isSpace = (c == ' '); switch (sState) { case IN_WORD: @@ -149,13 +153,19 @@ public class TextEntryState { setState(START); break; } + RingCharBuffer.getInstance().push(c, x, y); + if (isSeparator) { + LatinImeLogger.logOnInputSeparator(); + } else { + LatinImeLogger.logOnInputChar(); + } if (DEBUG) displayState("typedCharacter", "char", c, "isSeparator", isSeparator); } public static void backspace() { if (sState == ACCEPTED_DEFAULT) { setState(UNDO_COMMIT); - LatinImeLogger.logOnAutoSuggestionCanceled(); + LatinImeLogger.logOnAutoCorrectionCancelled(); } else if (sState == UNDO_COMMIT) { setState(IN_WORD); } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 3e092d938..7b334ac0a 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -209,11 +209,11 @@ public class Utils { return mCharBuf[mEnd]; } } - public char getLastChar() { - if (mLength < 1) { + public char getBackwardNthChar(int n) { + if (mLength <= n || n < 0) { return PLACEHOLDER_DELIMITER_CHAR; } else { - return mCharBuf[normalize(mEnd - 1)]; + return mCharBuf[normalize(mEnd - n - 1)]; } } public int getPreviousX(char c, int back) { @@ -234,9 +234,16 @@ public class Utils { return mYBuf[index]; } } - public String getLastString() { + public String getLastWord(int ignoreCharCount) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < mLength; ++i) { + int i = ignoreCharCount; + for (; i < mLength; ++i) { + char c = mCharBuf[normalize(mEnd - 1 - i)]; + if (!((LatinIME)mContext).isWordSeparator(c)) { + break; + } + } + for (; i < mLength; ++i) { char c = mCharBuf[normalize(mEnd - 1 - i)]; if (!((LatinIME)mContext).isWordSeparator(c)) { sb.append(c); -- cgit v1.2.3-83-g751a From 6d81e2b79bce557c3eb8f91adcad82ce1cac2afb Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 8 Apr 2011 14:45:19 +0900 Subject: Increase the horizontal gap between shift/delete and normal keys This change also adds capability to add horizontal padding to the keyboard. Bug: 4269094 Change-Id: I805e76b253a497079517c01bd2a976f8702f7e56 --- java/res/layout/input_basic.xml | 1 + java/res/layout/input_basic_highcontrast.xml | 2 +- java/res/layout/input_gingerbread.xml | 3 +- java/res/layout/input_honeycomb.xml | 3 +- java/res/layout/input_stone_bold.xml | 3 +- java/res/layout/input_stone_normal.xml | 3 +- java/res/layout/input_stone_popup.xml | 41 ---------------------- java/res/layout/keyboard_popup_stone.xml | 40 +++++++++++++++++++++ java/res/values-land/dimens.xml | 1 + java/res/values-xlarge-land/dimens.xml | 1 + java/res/values-xlarge/dimens.xml | 1 + java/res/values/dimens.xml | 1 + java/res/xml/kbd_qwerty_row3.xml | 8 +++-- .../com/android/inputmethod/keyboard/Keyboard.java | 4 ++- .../inputmethod/keyboard/KeyboardParser.java | 14 ++++++-- .../android/inputmethod/keyboard/KeyboardView.java | 2 +- 16 files changed, 74 insertions(+), 54 deletions(-) delete mode 100644 java/res/layout/input_stone_popup.xml create mode 100644 java/res/layout/keyboard_popup_stone.xml (limited to 'java/src/com/android/inputmethod') diff --git a/java/res/layout/input_basic.xml b/java/res/layout/input_basic.xml index 7b85bae94..86ae82d51 100644 --- a/java/res/layout/input_basic.xml +++ b/java/res/layout/input_basic.xml @@ -25,6 +25,7 @@ android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" + android:padding="0dip" android:background="@drawable/keyboard_background" latin:keyBackground="@drawable/btn_keyboard_key" diff --git a/java/res/layout/input_basic_highcontrast.xml b/java/res/layout/input_basic_highcontrast.xml index d9200fd5e..03b22ef07 100644 --- a/java/res/layout/input_basic_highcontrast.xml +++ b/java/res/layout/input_basic_highcontrast.xml @@ -21,11 +21,11 @@ diff --git a/java/res/layout/input_stone_normal.xml b/java/res/layout/input_stone_normal.xml index 6ae9aed55..8baecabdb 100644 --- a/java/res/layout/input_stone_normal.xml +++ b/java/res/layout/input_stone_normal.xml @@ -25,6 +25,7 @@ android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" + android:padding="0dip" android:background="@drawable/keyboard_background" latin:keyBackground="@drawable/btn_keyboard_key_stone" @@ -32,5 +33,5 @@ latin:keyTextColorDisabled="#FF808080" latin:shadowColor="@color/latinkeyboard_key_color_white" latin:colorScheme="black" - latin:popupLayout="@layout/input_stone_popup" + latin:popupLayout="@layout/keyboard_popup_stone" /> diff --git a/java/res/layout/input_stone_popup.xml b/java/res/layout/input_stone_popup.xml deleted file mode 100644 index b4da04536..000000000 --- a/java/res/layout/input_stone_popup.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - diff --git a/java/res/layout/keyboard_popup_stone.xml b/java/res/layout/keyboard_popup_stone.xml new file mode 100644 index 000000000..e6acee374 --- /dev/null +++ b/java/res/layout/keyboard_popup_stone.xml @@ -0,0 +1,40 @@ + + + + + + diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index 7df124bfc..6954ba2ae 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -27,6 +27,7 @@ 0.270in 0.0in 0.0in + 0.0in 38dip 63dip 2dip diff --git a/java/res/values-xlarge-land/dimens.xml b/java/res/values-xlarge-land/dimens.xml index ba42ddde6..fd6b1f386 100644 --- a/java/res/values-xlarge-land/dimens.xml +++ b/java/res/values-xlarge-land/dimens.xml @@ -28,6 +28,7 @@ 13.0mm 1.1mm 0.0mm + 0.0mm 28dip 20dip diff --git a/java/res/values-xlarge/dimens.xml b/java/res/values-xlarge/dimens.xml index cdb6e89a4..0dc5621ff 100644 --- a/java/res/values-xlarge/dimens.xml +++ b/java/res/values-xlarge/dimens.xml @@ -28,6 +28,7 @@ 10.0mm 1.1mm 0.0mm + 0.0mm 40dip 12dip diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 2cfc17de9..767dc4aa9 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -28,6 +28,7 @@ 0.325in 0.00in 0.06in + 0.0in 16dip 32dip 8dip diff --git a/java/res/xml/kbd_qwerty_row3.xml b/java/res/xml/kbd_qwerty_row3.xml index 26608fd71..27016aff0 100644 --- a/java/res/xml/kbd_qwerty_row3.xml +++ b/java/res/xml/kbd_qwerty_row3.xml @@ -26,8 +26,10 @@ > + @@ -46,9 +48,11 @@ latin:popupCharacters="@string/alternates_for_n" /> + diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 418188209..f720334f1 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -165,7 +165,9 @@ public class Keyboard { GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height); GRID_SIZE = GRID_WIDTH * GRID_HEIGHT; - mDisplayWidth = width; + final int horizontalEdgesPadding = (int)res.getDimension( + R.dimen.keyboard_horizontal_edges_padding); + mDisplayWidth = width - horizontalEdgesPadding * 2; mDisplayHeight = height; mDefaultHorizontalGap = 0; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java index 62e6f302d..9c556c309 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java @@ -122,6 +122,7 @@ public class KeyboardParser { private final Keyboard mKeyboard; private final Resources mResources; + private int mHorizontalEdgesPadding; private int mCurrentX = 0; private int mCurrentY = 0; private int mMaxRowWidth = 0; @@ -132,6 +133,7 @@ public class KeyboardParser { public KeyboardParser(Keyboard keyboard, Resources res) { mKeyboard = keyboard; mResources = res; + mHorizontalEdgesPadding = (int)res.getDimension(R.dimen.keyboard_horizontal_edges_padding); } public int getMaxRowWidth() { @@ -151,6 +153,7 @@ public class KeyboardParser { final String tag = parser.getName(); if (TAG_KEYBOARD.equals(tag)) { parseKeyboardAttributes(parser); + startKeyboard(); parseKeyboardContent(parser, mKeyboard.getKeys()); break; } else { @@ -520,25 +523,32 @@ public class KeyboardParser { throw new NonEmptyTag(tag, parser); } + private void startKeyboard() { + mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_top_padding); + } + private void startRow(Row row) { mCurrentX = 0; + setSpacer(mHorizontalEdgesPadding); mCurrentRow = row; } private void endRow() { if (mCurrentRow == null) throw new InflateException("orphant end row tag"); + setSpacer(mHorizontalEdgesPadding); + if (mCurrentX > mMaxRowWidth) + mMaxRowWidth = mCurrentX; mCurrentY += mCurrentRow.mDefaultHeight; mCurrentRow = null; } private void endKey(Key key) { mCurrentX += key.mGap + key.mWidth; - if (mCurrentX > mMaxRowWidth) - mMaxRowWidth = mCurrentX; } private void endKeyboard(int defaultVerticalGap) { + mCurrentY += (int)mResources.getDimension(R.dimen.keyboard_bottom_padding); mTotalHeight = mCurrentY - defaultVerticalGap; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index cc14589f6..e82796bf4 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -1056,7 +1056,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); } - private void onDoubleTapShiftKey(PointerTracker tracker) { + private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) { // When shift key is double tapped, the first tap is correctly processed as usual tap. And // the second tap is treated as this double tap event, so that we need not mark tracker // calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue. -- cgit v1.2.3-83-g751a From 967d6073bfd5f3d0e21512754d78d2e87c958e27 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 8 Apr 2011 17:14:12 +0900 Subject: Disable popup preview and long press on disabled key Bug: 4268147 Change-Id: Ibcb54791ef78737dd09d8a594b5a53b0909609d6 --- java/src/com/android/inputmethod/keyboard/Key.java | 2 +- java/src/com/android/inputmethod/keyboard/PointerTracker.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index f578bd613..59c132e91 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -379,7 +379,7 @@ public class Key { * @see android.graphics.drawable.StateListDrawable#setState(int[]) */ public int[] getCurrentDrawableState() { - final boolean pressed = mEnabled && mPressed; + final boolean pressed = mPressed; if (!mSticky && mFunctional) { if (pressed) { return KEY_STATE_FUNCTIONAL_PRESSED; diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index c28197014..eb5335ffd 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -546,6 +546,9 @@ public class PointerTracker { } private void showKeyPreviewAndUpdateKeyGraphics(int keyIndex) { + final Key key = getKey(keyIndex); + if (key != null && !key.mEnabled) + return; updateKeyGraphics(keyIndex); // The modifier key, such as shift key, should not be shown as preview when multi-touch is // supported. On the other hand, if multi-touch is not supported, the modifier key should @@ -565,6 +568,8 @@ public class PointerTracker { return; } Key key = getKey(keyIndex); + if (!key.mEnabled) + return; if (key.mCode == Keyboard.CODE_SHIFT) { mHandler.startLongPressShiftTimer(mLongPressShiftKeyTimeout, keyIndex, this); } else if (key.mManualTemporaryUpperCaseCode != Keyboard.CODE_DUMMY -- cgit v1.2.3-83-g751a From 56abeabcedf68f4640bb4ebd4af3ead1e3916c3c Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 11 Apr 2011 11:30:15 +0900 Subject: Add visualInsetsLeft and Right as Key attribute Bug: 4269094 Change-Id: Ic38d326a8e9ef802453c909f3a81d556863acc9b --- java/res/values/attrs.xml | 3 ++ java/res/xml/kbd_azerty_rows.xml | 2 ++ java/res/xml/kbd_iw_rows.xml | 5 ++- java/res/xml/kbd_qwerty_row3.xml | 10 +++--- java/res/xml/kbd_qwertz_rows.xml | 2 ++ java/res/xml/kbd_symbols.xml | 2 ++ java/res/xml/kbd_symbols_shift.xml | 2 ++ java/src/com/android/inputmethod/keyboard/Key.java | 10 +++++- .../android/inputmethod/keyboard/KeyboardView.java | 36 ++++++++++++---------- 9 files changed, 46 insertions(+), 26 deletions(-) (limited to 'java/src/com/android/inputmethod') diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 28c948b65..9b38139f0 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -142,6 +142,9 @@ + + + diff --git a/java/res/xml/kbd_azerty_rows.xml b/java/res/xml/kbd_azerty_rows.xml index 9eeb22ecb..14a9d6e59 100644 --- a/java/res/xml/kbd_azerty_rows.xml +++ b/java/res/xml/kbd_azerty_rows.xml @@ -108,6 +108,7 @@ - diff --git a/java/res/xml/kbd_qwerty_row3.xml b/java/res/xml/kbd_qwerty_row3.xml index 27016aff0..8c99cbddb 100644 --- a/java/res/xml/kbd_qwerty_row3.xml +++ b/java/res/xml/kbd_qwerty_row3.xml @@ -26,10 +26,9 @@ > - @@ -48,11 +47,10 @@ latin:popupCharacters="@string/alternates_for_n" /> - diff --git a/java/res/xml/kbd_qwertz_rows.xml b/java/res/xml/kbd_qwertz_rows.xml index 375f12335..b04fff968 100644 --- a/java/res/xml/kbd_qwertz_rows.xml +++ b/java/res/xml/kbd_qwertz_rows.xml @@ -78,6 +78,7 @@ diff --git a/java/res/xml/kbd_symbols_shift.xml b/java/res/xml/kbd_symbols_shift.xml index 368ee805b..40c8d64a6 100644 --- a/java/res/xml/kbd_symbols_shift.xml +++ b/java/res/xml/kbd_symbols_shift.xml @@ -89,6 +89,7 @@ @@ -110,6 +111,7 @@ diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 59c132e91..1b7e8ef21 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -61,8 +61,11 @@ public class Key { public final int mWidth; /** Height of the key, not including the gap */ public final int mHeight; - /** The horizontal gap before this key */ + /** The horizontal gap around this key */ public final int mGap; + /** The visual insets */ + public final int mVisualInsetsLeft; + public final int mVisualInsetsRight; /** Whether this key is sticky, i.e., a toggle key */ public final boolean mSticky; /** X coordinate of the key in the keyboard layout */ @@ -144,6 +147,7 @@ public class Key { mKeyboard = keyboard; mHeight = keyboard.getRowHeight() - keyboard.getVerticalGap(); mGap = keyboard.getHorizontalGap(); + mVisualInsetsLeft = mVisualInsetsRight = 0; mWidth = width - mGap; mEdgeFlags = edgeFlags; mHintIcon = null; @@ -230,6 +234,10 @@ public class Key { mEdgeFlags = style.getFlag(keyAttr, R.styleable.Keyboard_Key_keyEdgeFlags, 0) | row.mRowEdgeFlags; + mVisualInsetsLeft = KeyboardParser.getDimensionOrFraction(keyAttr, + R.styleable.Keyboard_Key_visualInsetsLeft, mKeyboard.getDisplayHeight(), 0); + mVisualInsetsRight = KeyboardParser.getDimensionOrFraction(keyAttr, + R.styleable.Keyboard_Key_visualInsetsRight, mKeyboard.getDisplayHeight(), 0); mPreviewIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_iconPreview); Keyboard.setDefaultBounds(mPreviewIcon); mIcon = style.getDrawable(keyAttr, R.styleable.Keyboard_Key_keyIcon); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index e82796bf4..7b570d7ed 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -677,11 +677,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // Switch the character to uppercase if shift is pressed String label = key.mLabel == null? null : adjustCase(key.mLabel).toString(); + final int keyDrawX = key.mX + key.mVisualInsetsLeft; + final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight; final Rect bounds = keyBackground.getBounds(); - if (key.mWidth != bounds.right || key.mHeight != bounds.bottom) { - keyBackground.setBounds(0, 0, key.mWidth, key.mHeight); + if (keyDrawWidth != bounds.right || key.mHeight != bounds.bottom) { + keyBackground.setBounds(0, 0, keyDrawWidth, key.mHeight); } - canvas.translate(key.mX + kbdPaddingLeft, key.mY + kbdPaddingTop); + canvas.translate(keyDrawX + kbdPaddingLeft, key.mY + kbdPaddingTop); keyBackground.draw(canvas); final int rowHeight = padding.top + key.mHeight; @@ -697,14 +699,14 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { baseline = key.mHeight - + labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR; if (DEBUG_SHOW_ALIGN) - drawHorizontalLine(canvas, (int)baseline, key.mWidth, 0xc0008000, + drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000, new Paint()); } else { // Align center final float centerY = (key.mHeight + padding.top - padding.bottom) / 2; baseline = centerY + labelCharHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER; if (DEBUG_SHOW_ALIGN) - drawHorizontalLine(canvas, (int)baseline, key.mWidth, 0xc0008000, + drawHorizontalLine(canvas, (int)baseline, keyDrawWidth, 0xc0008000, new Paint()); } // Horizontal label text alignment @@ -715,12 +717,12 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, positionX, rowHeight, 0xc0800080, new Paint()); } else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) { - positionX = key.mWidth - mKeyLabelHorizontalPadding - padding.right; + positionX = keyDrawWidth - mKeyLabelHorizontalPadding - padding.right; paint.setTextAlign(Align.RIGHT); if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, positionX, rowHeight, 0xc0808000, new Paint()); } else { - positionX = (key.mWidth + padding.left - padding.right) / 2; + positionX = (keyDrawWidth + padding.left - padding.right) / 2; paint.setTextAlign(Align.CENTER); if (DEBUG_SHOW_ALIGN) { if (label.length() > 1) @@ -756,13 +758,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, drawableX, rowHeight, 0xc0800080, new Paint()); } else if ((key.mLabelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) { - drawableX = key.mWidth - padding.right - mKeyLabelHorizontalPadding + drawableX = keyDrawWidth - padding.right - mKeyLabelHorizontalPadding - drawableWidth; if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, drawableX + drawableWidth, rowHeight, 0xc0808000, new Paint()); } else { // Align center - drawableX = (key.mWidth + padding.left - padding.right - drawableWidth) / 2; + drawableX = (keyDrawWidth + padding.left - padding.right - drawableWidth) / 2; if (DEBUG_SHOW_ALIGN) drawVerticalLine(canvas, drawableX + drawableWidth / 2, rowHeight, 0xc0008080, new Paint()); @@ -773,7 +775,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { 0x80c00000, new Paint()); } if (key.mHintIcon != null) { - final int drawableWidth = key.mWidth; + final int drawableWidth = keyDrawWidth; final int drawableHeight = key.mHeight; final int drawableX = 0; final int drawableY = HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL; @@ -785,7 +787,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { drawRectangle(canvas, drawableX, drawableY, drawableWidth, drawableHeight, 0x80c0c000, new Paint()); } - canvas.translate(-key.mX - kbdPaddingLeft, -key.mY - kbdPaddingTop); + canvas.translate(-keyDrawX - kbdPaddingLeft, -key.mY - kbdPaddingTop); } // TODO: Move this function to ProximityInfo for getting rid of public declarations for @@ -921,6 +923,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { // WindowManager.BadTokenException. if (key == null || !mInForeground) return; + final int keyDrawX = key.mX + key.mVisualInsetsLeft; + final int keyDrawWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight; // What we show as preview should match what we show on key top in onBufferDraw(). if (key.mLabel != null) { // TODO Should take care of temporaryShiftLabel here. @@ -941,7 +945,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); - int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.mWidth + int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), keyDrawWidth + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight()); final int popupHeight = mPreviewHeight; LayoutParams lp = mPreviewText.getLayoutParams(); @@ -950,7 +954,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { lp.height = popupHeight; } - int popupPreviewX = key.mX - (popupWidth - key.mWidth) / 2; + int popupPreviewX = keyDrawX - (popupWidth - keyDrawWidth) / 2; int popupPreviewY = key.mY - popupHeight + mPreviewOffset; mHandler.cancelDismissPreview(); @@ -973,10 +977,10 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { if (popupPreviewY + mWindowY < 0) { // If the key you're pressing is on the left side of the keyboard, show the popup on // the right, offset by enough to see at least one key to the left/right. - if (key.mX + key.mWidth <= getWidth() / 2) { - popupPreviewX += (int) (key.mWidth * 2.5); + if (keyDrawX + keyDrawWidth <= getWidth() / 2) { + popupPreviewX += (int) (keyDrawWidth * 2.5); } else { - popupPreviewX -= (int) (key.mWidth * 2.5); + popupPreviewX -= (int) (keyDrawWidth * 2.5); } popupPreviewY += popupHeight; } -- cgit v1.2.3-83-g751a From 88fc9d44186120f9edc5cf7ec0e2af85260fed04 Mon Sep 17 00:00:00 2001 From: satok Date: Fri, 8 Apr 2011 19:57:13 +0900 Subject: Support language bar swich for InputMethodSubtype Change-Id: Ie49f0c1c7aea135331dc1d4a635197b3f4a96e93 --- .../compat/InputMethodManagerCompatWrapper.java | 29 +++ .../compat/InputMethodSubtypeCompatWrapper.java | 3 - .../deprecated/LanguageSwitcherProxy.java | 73 +++++++ .../languageswitcher/LanguageSwitcher.java | 226 +++++++++++++++++++++ .../inputmethod/keyboard/LatinKeyboard.java | 2 +- .../inputmethod/latin/LanguageSwitcher.java | 193 ------------------ .../com/android/inputmethod/latin/LatinIME.java | 31 +-- .../android/inputmethod/latin/SubtypeSwitcher.java | 223 ++++++++++---------- 8 files changed, 463 insertions(+), 317 deletions(-) create mode 100644 java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java create mode 100644 java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java delete mode 100644 java/src/com/android/inputmethod/latin/LanguageSwitcher.java (limited to 'java/src/com/android/inputmethod') diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index 80586b753..e7eaba2d8 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -16,6 +16,7 @@ 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; @@ -56,6 +57,14 @@ public class InputMethodManagerCompatWrapper { private static final InputMethodManagerCompatWrapper sInstance = new InputMethodManagerCompatWrapper(); + public static final boolean SUBTYPE_SUPPORTED; + + static { + // This static initializer guarantees that METHOD_getShortcutInputMethodsAndSubtypes is + // already instantiated. + SUBTYPE_SUPPORTED = METHOD_getShortcutInputMethodsAndSubtypes != null; + } + // For the compatibility, IMM will create dummy subtypes if subtypes are not found. // This is required to be false if the current behavior is broken. For now, it's ok to be true. private static final boolean ALLOW_DUMMY_SUBTYPE = true; @@ -64,7 +73,9 @@ public class InputMethodManagerCompatWrapper { private static final String KEYBOARD_MODE = "keyboard"; private InputMethodManager mImm; + private LanguageSwitcherProxy mLanguageSwitcherProxy; private String mLatinImePackageName; + private InputMethodManagerCompatWrapper() { } @@ -81,15 +92,29 @@ public class InputMethodManagerCompatWrapper { if (context instanceof LatinIME) { mLatinImePackageName = context.getPackageName(); } + mLanguageSwitcherProxy = LanguageSwitcherProxy.getInstance(); } public InputMethodSubtypeCompatWrapper getCurrentInputMethodSubtype() { + if (!SUBTYPE_SUPPORTED) { + return new InputMethodSubtypeCompatWrapper( + 0, 0, mLanguageSwitcherProxy.getInputLocale().toString(), KEYBOARD_MODE, ""); + } Object o = CompatUtils.invoke(mImm, null, METHOD_getCurrentInputMethodSubtype); return new InputMethodSubtypeCompatWrapper(o); } public List getEnabledInputMethodSubtypeList( InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) { + if (!SUBTYPE_SUPPORTED) { + String[] languages = mLanguageSwitcherProxy.getEnabledLanguages(); + List subtypeList = + new ArrayList(); + for (String lang: languages) { + subtypeList.add(new InputMethodSubtypeCompatWrapper(0, 0, lang, KEYBOARD_MODE, "")); + } + return subtypeList; + } Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList, (imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes); if (retval == null || !(retval instanceof List) || ((List)retval).isEmpty()) { @@ -170,6 +195,10 @@ public class InputMethodManagerCompatWrapper { public void setInputMethodAndSubtype( IBinder token, String id, InputMethodSubtypeCompatWrapper subtype) { + if (!SUBTYPE_SUPPORTED) { + mLanguageSwitcherProxy.setLocale(subtype.getLocale()); + return; + } CompatUtils.invoke(mImm, null, METHOD_setInputMethodAndSubtype, token, id, subtype.getOriginalObject()); } diff --git a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java index 317b02216..86c8af37f 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodSubtypeCompatWrapper.java @@ -58,9 +58,6 @@ public final class InputMethodSubtypeCompatWrapper extends AbstractCompatWrapper public InputMethodSubtypeCompatWrapper(Object subtype) { super((CLASS_InputMethodSubtype != null && CLASS_InputMethodSubtype.isInstance(subtype)) ? subtype : null); - if (DBG) { - Log.d(TAG, "CreateInputMethodSubtypeCompatWrapper"); - } mDummyNameResId = 0; mDummyIconResId = 0; mDummyLocale = DEFAULT_LOCALE; diff --git a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java new file mode 100644 index 000000000..5d165cda9 --- /dev/null +++ b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011 Google Inc. + * + * 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.deprecated; + +import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.deprecated.languageswitcher.LanguageSwitcher; +import com.android.inputmethod.latin.LatinIME; + +import android.content.SharedPreferences; +import android.content.res.Configuration; + +import java.util.Locale; + +// This class is used only when the IME doesn't use method.xml for language switching. +public class LanguageSwitcherProxy { + private static final LanguageSwitcherProxy sInstance = new LanguageSwitcherProxy(); + private LanguageSwitcher mLanguageSwitcher; + private SharedPreferences mPrefs; + + public static LanguageSwitcherProxy getInstance() { + if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return null; + return sInstance; + } + + public static void init(LatinIME service, SharedPreferences prefs) { + if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return; + final Configuration conf = service.getResources().getConfiguration(); + sInstance.mLanguageSwitcher = new LanguageSwitcher(service); + sInstance.mLanguageSwitcher.loadLocales(prefs, conf.locale); + sInstance.mPrefs = prefs; + } + + public static void onConfigurationChanged(Configuration conf) { + if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return; + sInstance.mLanguageSwitcher.onConfigurationChanged(conf, sInstance.mPrefs); + } + + public static void loadSettings() { + if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return; + sInstance.mLanguageSwitcher.loadLocales(sInstance.mPrefs, null); + } + + public int getLocaleCount() { + return mLanguageSwitcher.getLocaleCount(); + } + + public String[] getEnabledLanguages() { + return mLanguageSwitcher.getEnabledLanguages(); + } + + public Locale getInputLocale() { + return mLanguageSwitcher.getInputLocale(); + } + + public void setLocale(String localeStr) { + mLanguageSwitcher.setLocale(localeStr); + mLanguageSwitcher.persist(mPrefs); + } +} diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java new file mode 100644 index 000000000..639b7cdd0 --- /dev/null +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2010 Google Inc. + * + * 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.deprecated.languageswitcher; + +import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; +import com.android.inputmethod.latin.LatinIME; +import com.android.inputmethod.latin.Settings; +import com.android.inputmethod.latin.SharedPreferencesCompat; + +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.res.Configuration; +import android.text.TextUtils; + +import java.util.ArrayList; +import java.util.Locale; + +/** + * Keeps track of list of selected input languages and the current + * input language that the user has selected. + */ +public class LanguageSwitcher { + + private static final String KEYBOARD_MODE = "keyboard"; + + private final ArrayList mLocales = new ArrayList(); + private final LatinIME mIme; + private String[] mSelectedLanguageArray; + private String mSelectedLanguages; + private int mCurrentIndex = 0; + private String mDefaultInputLanguage; + private Locale mDefaultInputLocale; + private Locale mSystemLocale; + + public LanguageSwitcher(LatinIME ime) { + mIme = ime; + } + + public int getLocaleCount() { + return mLocales.size(); + } + + public void onConfigurationChanged(Configuration conf, SharedPreferences prefs) { + final Locale newLocale = conf.locale; + if (!getSystemLocale().toString().equals(newLocale.toString())) { + loadLocales(prefs, newLocale); + } + } + + /** + * Loads the currently selected input languages from shared preferences. + * @param sp shared preference for getting the current input language and enabled languages + * @param systemLocale the current system locale, stored for changing the current input language + * based on the system current system locale. + * @return whether there was any change + */ + public boolean loadLocales(SharedPreferences sp, Locale systemLocale) { + if (systemLocale != null) { + setSystemLocale(systemLocale); + } + String selectedLanguages = sp.getString(Settings.PREF_SELECTED_LANGUAGES, null); + String currentLanguage = sp.getString(Settings.PREF_INPUT_LANGUAGE, null); + if (selectedLanguages == null || selectedLanguages.length() < 1) { + loadDefaults(); + if (mLocales.size() == 0) { + return false; + } + mLocales.clear(); + return true; + } + if (selectedLanguages.equals(mSelectedLanguages)) { + return false; + } + mSelectedLanguageArray = selectedLanguages.split(","); + mSelectedLanguages = selectedLanguages; // Cache it for comparison later + constructLocales(); + mCurrentIndex = 0; + if (currentLanguage != null) { + // Find the index + mCurrentIndex = 0; + for (int i = 0; i < mLocales.size(); i++) { + if (mSelectedLanguageArray[i].equals(currentLanguage)) { + mCurrentIndex = i; + break; + } + } + // If we didn't find the index, use the first one + } + return true; + } + + private void loadDefaults() { + mDefaultInputLocale = mIme.getResources().getConfiguration().locale; + String country = mDefaultInputLocale.getCountry(); + mDefaultInputLanguage = mDefaultInputLocale.getLanguage() + + (TextUtils.isEmpty(country) ? "" : "_" + country); + } + + private void constructLocales() { + mLocales.clear(); + for (final String lang : mSelectedLanguageArray) { + final Locale locale = new Locale(lang.substring(0, 2), + lang.length() > 4 ? lang.substring(3, 5) : ""); + mLocales.add(locale); + } + } + + /** + * Returns the currently selected input language code, or the display language code if + * no specific locale was selected for input. + */ + public String getInputLanguage() { + if (getLocaleCount() == 0) return mDefaultInputLanguage; + + return mSelectedLanguageArray[mCurrentIndex]; + } + + /** + * Returns the list of enabled language codes. + */ + public String[] getEnabledLanguages() { + return mSelectedLanguageArray; + } + + /** + * Returns the currently selected input locale, or the display locale if no specific + * locale was selected for input. + * @return + */ + public Locale getInputLocale() { + if (getLocaleCount() == 0) return mDefaultInputLocale; + + return mLocales.get(mCurrentIndex); + } + + private int nextLocaleIndex() { + final int size = mLocales.size(); + return (mCurrentIndex + 1) % size; + } + + private int prevLocaleIndex() { + final int size = mLocales.size(); + return (mCurrentIndex - 1 + size) % size; + } + + /** + * Returns the next input locale in the list. Wraps around to the beginning of the + * list if we're at the end of the list. + * @return + */ + public Locale getNextInputLocale() { + if (getLocaleCount() == 0) return mDefaultInputLocale; + return mLocales.get(nextLocaleIndex()); + } + + /** + * Sets the system locale (display UI) used for comparing with the input language. + * @param locale the locale of the system + */ + private void setSystemLocale(Locale locale) { + mSystemLocale = locale; + } + + /** + * Returns the system locale. + * @return the system locale + */ + private Locale getSystemLocale() { + return mSystemLocale; + } + + /** + * Returns the previous input locale in the list. Wraps around to the end of the + * list if we're at the beginning of the list. + * @return + */ + public Locale getPrevInputLocale() { + if (getLocaleCount() == 0) return mDefaultInputLocale; + return mLocales.get(prevLocaleIndex()); + } + + public void reset() { + mCurrentIndex = 0; + } + + public void next() { + mCurrentIndex = nextLocaleIndex(); + } + + public void prev() { + mCurrentIndex = prevLocaleIndex(); + } + + public void setLocale(String localeStr) { + final int N = mLocales.size(); + for (int i = 0; i < N; ++i) { + if (mLocales.get(i).toString().equals(localeStr)) { + mCurrentIndex = i; + } + } + } + + public void persist(SharedPreferences prefs) { + Editor editor = prefs.edit(); + editor.putString(Settings.PREF_INPUT_LANGUAGE, getInputLanguage()); + SharedPreferencesCompat.apply(editor); + // When the current language is changed, the event for this change should be handled + // internally as a subtype switching. + mIme.notifyOnCurrentInputMethodSubtypeChanged(new InputMethodSubtypeCompatWrapper( + 0, 0, getInputLocale().toString(), KEYBOARD_MODE, "")); + } +} diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 9b87df3fe..9d9793e1e 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -271,7 +271,7 @@ public class LatinKeyboard extends Keyboard { canvas.drawText(language, width / 2, baseline - descent, paint); // Put arrows that are already layed out on either side of the text - if (SubtypeSwitcher.getInstance().useSpacebarLanguageSwitcher() + if (subtypeSwitcher.useSpacebarLanguageSwitcher() && subtypeSwitcher.getEnabledKeyboardLocaleCount() > 1) { mButtonArrowLeftIcon.draw(canvas); mButtonArrowRightIcon.draw(canvas); diff --git a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java b/java/src/com/android/inputmethod/latin/LanguageSwitcher.java deleted file mode 100644 index 6faf7f95e..000000000 --- a/java/src/com/android/inputmethod/latin/LanguageSwitcher.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2010 Google Inc. - * - * 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.latin; - -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.text.TextUtils; - -import java.util.ArrayList; -import java.util.Locale; - -/** - * Keeps track of list of selected input languages and the current - * input language that the user has selected. - */ -public class LanguageSwitcher { - - private final ArrayList mLocales = new ArrayList(); - private final LatinIME mIme; - private String[] mSelectedLanguageArray; - private String mSelectedLanguages; - private int mCurrentIndex = 0; - private String mDefaultInputLanguage; - private Locale mDefaultInputLocale; - private Locale mSystemLocale; - - public LanguageSwitcher(LatinIME ime) { - mIme = ime; - } - - public int getLocaleCount() { - return mLocales.size(); - } - - /** - * Loads the currently selected input languages from shared preferences. - * @param sp - * @return whether there was any change - */ - public boolean loadLocales(SharedPreferences sp) { - String selectedLanguages = sp.getString(Settings.PREF_SELECTED_LANGUAGES, null); - String currentLanguage = sp.getString(Settings.PREF_INPUT_LANGUAGE, null); - if (selectedLanguages == null || selectedLanguages.length() < 1) { - loadDefaults(); - if (mLocales.size() == 0) { - return false; - } - mLocales.clear(); - return true; - } - if (selectedLanguages.equals(mSelectedLanguages)) { - return false; - } - mSelectedLanguageArray = selectedLanguages.split(","); - mSelectedLanguages = selectedLanguages; // Cache it for comparison later - constructLocales(); - mCurrentIndex = 0; - if (currentLanguage != null) { - // Find the index - mCurrentIndex = 0; - for (int i = 0; i < mLocales.size(); i++) { - if (mSelectedLanguageArray[i].equals(currentLanguage)) { - mCurrentIndex = i; - break; - } - } - // If we didn't find the index, use the first one - } - return true; - } - - private void loadDefaults() { - mDefaultInputLocale = mIme.getResources().getConfiguration().locale; - String country = mDefaultInputLocale.getCountry(); - mDefaultInputLanguage = mDefaultInputLocale.getLanguage() + - (TextUtils.isEmpty(country) ? "" : "_" + country); - } - - private void constructLocales() { - mLocales.clear(); - for (final String lang : mSelectedLanguageArray) { - final Locale locale = new Locale(lang.substring(0, 2), - lang.length() > 4 ? lang.substring(3, 5) : ""); - mLocales.add(locale); - } - } - - /** - * Returns the currently selected input language code, or the display language code if - * no specific locale was selected for input. - */ - public String getInputLanguage() { - if (getLocaleCount() == 0) return mDefaultInputLanguage; - - return mSelectedLanguageArray[mCurrentIndex]; - } - - /** - * Returns the list of enabled language codes. - */ - public String[] getEnabledLanguages() { - return mSelectedLanguageArray; - } - - /** - * Returns the currently selected input locale, or the display locale if no specific - * locale was selected for input. - * @return - */ - public Locale getInputLocale() { - if (getLocaleCount() == 0) return mDefaultInputLocale; - - return mLocales.get(mCurrentIndex); - } - - private int nextLocaleIndex() { - final int size = mLocales.size(); - return (mCurrentIndex + 1) % size; - } - - private int prevLocaleIndex() { - final int size = mLocales.size(); - return (mCurrentIndex - 1 + size) % size; - } - - /** - * Returns the next input locale in the list. Wraps around to the beginning of the - * list if we're at the end of the list. - * @return - */ - public Locale getNextInputLocale() { - if (getLocaleCount() == 0) return mDefaultInputLocale; - return mLocales.get(nextLocaleIndex()); - } - - /** - * Sets the system locale (display UI) used for comparing with the input language. - * @param locale the locale of the system - */ - public void setSystemLocale(Locale locale) { - mSystemLocale = locale; - } - - /** - * Returns the system locale. - * @return the system locale - */ - public Locale getSystemLocale() { - return mSystemLocale; - } - - /** - * Returns the previous input locale in the list. Wraps around to the end of the - * list if we're at the beginning of the list. - * @return - */ - public Locale getPrevInputLocale() { - if (getLocaleCount() == 0) return mDefaultInputLocale; - return mLocales.get(prevLocaleIndex()); - } - - public void reset() { - mCurrentIndex = 0; - } - - public void next() { - mCurrentIndex = nextLocaleIndex(); - } - - public void prev() { - mCurrentIndex = prevLocaleIndex(); - } - - public void persist(SharedPreferences prefs) { - Editor editor = prefs.edit(); - editor.putString(Settings.PREF_INPUT_LANGUAGE, getInputLanguage()); - SharedPreferencesCompat.apply(editor); - } -} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 6a858fe99..3905a4c7a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -23,6 +23,7 @@ import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; @@ -379,6 +380,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar SubtypeSwitcher.init(this, prefs); KeyboardSwitcher.init(this, prefs); AccessibilityUtils.init(this, prefs); + LanguageSwitcherProxy.init(this, prefs); super.onCreate(); @@ -516,6 +518,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar super.onConfigurationChanged(conf); mVoiceProxy.onConfigurationChanged(conf); mConfigurationChanging = false; + + // This will work only when the subtype is not supported. + LanguageSwitcherProxy.onConfigurationChanged(conf); } @Override @@ -1155,10 +1160,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar onSettingsKeyLongPressed(); break; case Keyboard.CODE_NEXT_LANGUAGE: - toggleLanguage(false, true); + toggleLanguage(true); break; case Keyboard.CODE_PREV_LANGUAGE: - toggleLanguage(false, false); + toggleLanguage(false); break; case Keyboard.CODE_CAPSLOCK: switcher.toggleCapsLock(); @@ -1930,17 +1935,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return mWord.isFirstCharCapitalized(); } - // Notify that language or mode have been changed and toggleLanguage will update KeyboaredID + // Notify that language or mode have been changed and toggleLanguage will update KeyboardID // according to new language or mode. public void onRefreshKeyboard() { - toggleLanguage(true, true); - } - - // "reset" and "next" are used only for USE_SPACEBAR_LANGUAGE_SWITCHER. - private void toggleLanguage(boolean reset, boolean next) { - if (mSubtypeSwitcher.useSpacebarLanguageSwitcher()) { - mSubtypeSwitcher.toggleLanguage(reset, next); - } // Reload keyboard because the current language has been changed. mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(), @@ -1949,6 +1946,14 @@ 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); + } + onRefreshKeyboard();// no need?? + } + @Override public void onSwipeDown() { if (mConfigSwipeDownDismissKeyboardEnabled) @@ -2134,7 +2139,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar updateCorrectionMode(); updateAutoTextEnabled(); updateSuggestionVisibility(prefs); - SubtypeSwitcher.getInstance().loadSettings(); + + // This will work only when the subtype is not supported. + LanguageSwitcherProxy.loadSettings(); } /** diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 053e2abe4..2cdc4d2cd 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -57,7 +57,6 @@ public class SubtypeSwitcher { private static final SubtypeSwitcher sInstance = new SubtypeSwitcher(); private /* final */ LatinIME mService; - private /* final */ SharedPreferences mPrefs; private /* final */ InputMethodManagerCompatWrapper mImm; private /* final */ Resources mResources; private /* final */ ConnectivityManager mConnectivityManager; @@ -66,6 +65,7 @@ public class SubtypeSwitcher { mEnabledKeyboardSubtypesOfCurrentInputMethod = new ArrayList(); private final ArrayList mEnabledLanguagesOfCurrentInputMethod = new ArrayList(); + private final LanguageBarInfo mLanguageBarInfo = new LanguageBarInfo(); /*-----------------------------------------------------------*/ // Variants which should be changed only by reload functions. @@ -78,6 +78,7 @@ public class SubtypeSwitcher { private Locale mSystemLocale; private Locale mInputLocale; private String mInputLocaleStr; + private String mInputMethodId; private VoiceProxy.VoiceInputWrapper mVoiceInputWrapper; /*-----------------------------------------------------------*/ @@ -100,7 +101,6 @@ public class SubtypeSwitcher { private void initialize(LatinIME service, SharedPreferences prefs) { mService = service; - mPrefs = prefs; mResources = service.getResources(); mImm = InputMethodManagerCompatWrapper.getInstance(service); mConnectivityManager = (ConnectivityManager) service.getSystemService( @@ -114,13 +114,12 @@ public class SubtypeSwitcher { mAllEnabledSubtypesOfCurrentInputMethod = null; // TODO: Voice input should be created here mVoiceInputWrapper = null; - mConfigUseSpacebarLanguageSwitcher = mResources.getBoolean( + mConfigUseSpacebarLanguageSwitcher = service.getResources().getBoolean( R.bool.config_use_spacebar_language_switcher); - if (mConfigUseSpacebarLanguageSwitcher) - initLanguageSwitcher(service); final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); mIsNetworkConnected = (info != null && info.isConnected()); + mInputMethodId = Utils.getInputMethodId(mImm, service.getPackageName()); } // Update all parameters stored in SubtypeSwitcher. @@ -134,11 +133,7 @@ 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() { - if (mConfigUseSpacebarLanguageSwitcher) { - updateForSpacebarLanguageSwitch(); - } else { - updateEnabledSubtypes(); - } + updateEnabledSubtypes(); updateShortcutIME(); } @@ -150,7 +145,7 @@ public class SubtypeSwitcher { null, true); mEnabledLanguagesOfCurrentInputMethod.clear(); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); - for (InputMethodSubtypeCompatWrapper ims: mAllEnabledSubtypesOfCurrentInputMethod) { + for (InputMethodSubtypeCompatWrapper ims : mAllEnabledSubtypesOfCurrentInputMethod) { final String locale = ims.getLocale(); final String mode = ims.getMode(); mLocaleSplitter.setString(locale); @@ -172,6 +167,10 @@ 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(); } } @@ -269,6 +268,7 @@ public class SubtypeSwitcher { mVoiceInputWrapper.reset(); } } + mLanguageBarInfo.update(); } // Update the current input locale from Locale string. @@ -303,12 +303,21 @@ public class SubtypeSwitcher { //////////////////////////// public void switchToShortcutIME() { - final IBinder token = mService.getWindow().getWindow().getAttributes().token; - if (token == null || mShortcutInputMethodInfo == null) { + if (mShortcutInputMethodInfo == null) { return; } + final String imiId = mShortcutInputMethodInfo.getId(); final InputMethodSubtypeCompatWrapper subtype = mShortcutSubtype; + switchToTargetIME(imiId, subtype); + } + + private void switchToTargetIME( + final String imiId, final InputMethodSubtypeCompatWrapper subtype) { + final IBinder token = mService.getWindow().getWindow().getAttributes().token; + if (token == null) { + return; + } new AsyncTask() { @Override protected Void doInBackground(Void... params) { @@ -412,11 +421,7 @@ public class SubtypeSwitcher { ////////////////////////////////// public int getEnabledKeyboardLocaleCount() { - if (mConfigUseSpacebarLanguageSwitcher) { - return mLanguageSwitcher.getLocaleCount(); - } else { - return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); - } + return mEnabledKeyboardSubtypesOfCurrentInputMethod.size(); } public boolean useSpacebarLanguageSwitcher() { @@ -428,74 +433,37 @@ public class SubtypeSwitcher { } public Locale getInputLocale() { - if (mConfigUseSpacebarLanguageSwitcher) { - return mLanguageSwitcher.getInputLocale(); - } else { - return mInputLocale; - } + return mInputLocale; } public String getInputLocaleStr() { - if (mConfigUseSpacebarLanguageSwitcher) { - String inputLanguage = null; - inputLanguage = mLanguageSwitcher.getInputLanguage(); - // Should return system locale if there is no Language available. - if (inputLanguage == null) { - inputLanguage = getSystemLocale().getLanguage(); - } - return inputLanguage; - } else { - return mInputLocaleStr; - } + return mInputLocaleStr; } public String[] getEnabledLanguages() { - if (mConfigUseSpacebarLanguageSwitcher) { - return mLanguageSwitcher.getEnabledLanguages(); - } else { - int enabledLanguageCount = mEnabledLanguagesOfCurrentInputMethod.size(); - // Workaround for explicitly specifying the voice language - if (enabledLanguageCount == 1) { - mEnabledLanguagesOfCurrentInputMethod.add( - mEnabledLanguagesOfCurrentInputMethod.get(0)); - ++enabledLanguageCount; - } - return mEnabledLanguagesOfCurrentInputMethod.toArray( - new String[enabledLanguageCount]); + int enabledLanguageCount = mEnabledLanguagesOfCurrentInputMethod.size(); + // Workaround for explicitly specifying the voice language + if (enabledLanguageCount == 1) { + mEnabledLanguagesOfCurrentInputMethod.add(mEnabledLanguagesOfCurrentInputMethod + .get(0)); + ++enabledLanguageCount; } + return mEnabledLanguagesOfCurrentInputMethod.toArray(new String[enabledLanguageCount]); } public Locale getSystemLocale() { - if (mConfigUseSpacebarLanguageSwitcher) { - return mLanguageSwitcher.getSystemLocale(); - } else { - return mSystemLocale; - } + return mSystemLocale; } public boolean isSystemLanguageSameAsInputLanguage() { - if (mConfigUseSpacebarLanguageSwitcher) { - return getSystemLocale().getLanguage().equalsIgnoreCase( - getInputLocaleStr().substring(0, 2)); - } else { - return mIsSystemLanguageSameAsInputLanguage; - } + return mIsSystemLanguageSameAsInputLanguage; } public void onConfigurationChanged(Configuration conf) { final Locale systemLocale = conf.locale; // If system configuration was changed, update all parameters. if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) { - if (mConfigUseSpacebarLanguageSwitcher) { - // If the system locale changes and is different from the saved - // locale (mSystemLocale), then reload the input locale list from the - // latin ime settings (shared prefs) and reset the input locale - // to the first one. - mLanguageSwitcher.loadLocales(mPrefs); - mLanguageSwitcher.setSystemLocale(systemLocale); - } else { - updateAllParameters(); - } + updateAllParameters(); } } @@ -554,7 +522,70 @@ public class SubtypeSwitcher { // Spacebar Language Switch support // ////////////////////////////////////// - private LanguageSwitcher mLanguageSwitcher; + 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 = new Locale(mNextKeyboardSubtype.getLocale()); + mNextLanguage = getDisplayLanguage(locale); + mPreviousKeyboardSubtype = getPreviousKeyboardSubtypeInternal( + mCurrentKeyboardSubtypeIndex); + locale = new Locale(mPreviousKeyboardSubtype.getLocale()); + mPreviousLanguage = getDisplayLanguage(locale); + } + + 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) { @@ -579,32 +610,16 @@ public class SubtypeSwitcher { return Character.toUpperCase(s.charAt(0)) + s.substring(1); } - private void updateForSpacebarLanguageSwitch() { - // We need to update mNeedsToDisplayLanguage in onStartInputView because - // getEnabledKeyboardLocaleCount could have been changed. - mNeedsToDisplayLanguage = !(getEnabledKeyboardLocaleCount() <= 1 - && getSystemLocale().getLanguage().equalsIgnoreCase( - getInputLocale().getLanguage())); - } - public String getInputLanguageName() { return getDisplayLanguage(getInputLocale()); } public String getNextInputLanguageName() { - if (mConfigUseSpacebarLanguageSwitcher) { - return getDisplayLanguage(mLanguageSwitcher.getNextInputLocale()); - } else { - return ""; - } + return mLanguageBarInfo.getNextLanguage(); } public String getPreviousInputLanguageName() { - if (mConfigUseSpacebarLanguageSwitcher) { - return getDisplayLanguage(mLanguageSwitcher.getPrevInputLocale()); - } else { - return ""; - } + return mLanguageBarInfo.getPreviousLanguage(); } ///////////////////////////// @@ -644,31 +659,23 @@ public class SubtypeSwitcher { return voiceInputSupportedLocales.contains(locale); } - public void loadSettings() { - if (mConfigUseSpacebarLanguageSwitcher) { - mLanguageSwitcher.loadLocales(mPrefs); - } + private void changeToNextSubtype() { + final InputMethodSubtypeCompatWrapper subtype = + mLanguageBarInfo.getNextKeyboardSubtype(); + switchToTargetIME(mInputMethodId, subtype); } - public void toggleLanguage(boolean reset, boolean next) { - if (mConfigUseSpacebarLanguageSwitcher) { - if (reset) { - mLanguageSwitcher.reset(); - } else { - if (next) { - mLanguageSwitcher.next(); - } else { - mLanguageSwitcher.prev(); - } - } - mLanguageSwitcher.persist(mPrefs); - } + private void changeToPreviousSubtype() { + final InputMethodSubtypeCompatWrapper subtype = + mLanguageBarInfo.getPreviousKeyboardSubtype(); + switchToTargetIME(mInputMethodId, subtype); } - private void initLanguageSwitcher(LatinIME service) { - final Configuration conf = service.getResources().getConfiguration(); - mLanguageSwitcher = new LanguageSwitcher(service); - mLanguageSwitcher.loadLocales(mPrefs); - mLanguageSwitcher.setSystemLocale(conf.locale); + public void toggleLanguage(boolean next) { + if (next) { + changeToNextSubtype(); + } else { + changeToPreviousSubtype(); + } } } -- cgit v1.2.3-83-g751a