From 3de8f34b8c8c7113386b6cd7c9101ef20df6ec7d Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 10 Sep 2010 13:15:45 +0900 Subject: Code cleanup Change-Id: I333693ab8e4088180cc25768d874ad7320d9da8b --- .../inputmethod/latin/LatinKeyboardBaseView.java | 41 +++++++++------------- 1 file changed, 16 insertions(+), 25 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 8f1ec6591..45ecca35e 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -180,7 +180,6 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private Key[] mKeys; // Key preview popup - private final static boolean PREVIEW_CENTERED = false; private TextView mPreviewText; private PopupWindow mPreviewPopup; private int mPreviewTextSizeLarge; @@ -188,8 +187,6 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private int mOldPreviewKeyIndex = NOT_A_KEY; private boolean mShowPreview = true; private boolean mShowTouchPoints = true; - private int mPopupPreviewX; - private int mPopupPreviewY; private int mPopupPreviewOffsetX; private int mPopupPreviewOffsetY; private int mWindowY; @@ -869,7 +866,6 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx Key key = tracker.getKey(keyIndex); if (key == null) return; - final PopupWindow previewPopup = mPreviewPopup; if (key.icon != null) { mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon); @@ -895,14 +891,10 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx lp.width = popupWidth; lp.height = popupHeight; } - if (PREVIEW_CENTERED) { - // TODO: Fix this if centering is brought back - mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2; - mPopupPreviewY = - mPreviewText.getMeasuredHeight(); - } else { - mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + getPaddingLeft(); - mPopupPreviewY = key.y - popupHeight + mPreviewOffset; - } + + int popupPreviewX = key.x - mPreviewText.getPaddingLeft() + getPaddingLeft(); + int popupPreviewY = key.y - popupHeight + mPreviewOffset; + mHandler.cancelDismissPreview(); if (mOffsetInWindow == null) { mOffsetInWindow = new int[2]; @@ -916,29 +908,28 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Set the preview background state mPreviewText.getBackground().setState( key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); - mPopupPreviewX += mOffsetInWindow[0]; - mPopupPreviewY += mOffsetInWindow[1]; + popupPreviewX += mOffsetInWindow[0]; + popupPreviewY += mOffsetInWindow[1]; // If the popup cannot be shown above the key, put it on the side - if (mPopupPreviewY + mWindowY < 0) { + 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.x + key.width <= getWidth() / 2) { - mPopupPreviewX += (int) (key.width * 2.5); + popupPreviewX += (int) (key.width * 2.5); } else { - mPopupPreviewX -= (int) (key.width * 2.5); + popupPreviewX -= (int) (key.width * 2.5); } - mPopupPreviewY += popupHeight; + popupPreviewY += popupHeight; } - if (previewPopup.isShowing()) { - previewPopup.update(mPopupPreviewX, mPopupPreviewY, - popupWidth, popupHeight); + if (mPreviewPopup.isShowing()) { + mPreviewPopup.update(popupPreviewX, popupPreviewY, popupWidth, popupHeight); } else { - previewPopup.setWidth(popupWidth); - previewPopup.setHeight(popupHeight); - previewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY, - mPopupPreviewX, mPopupPreviewY); + mPreviewPopup.setWidth(popupWidth); + mPreviewPopup.setHeight(popupHeight); + mPreviewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY, + popupPreviewX, popupPreviewY); } mPreviewText.setVisibility(VISIBLE); } -- cgit v1.2.3-83-g751a From f62166c13bdf7fe99092565dd0425d8693a5cec8 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 10 Sep 2010 15:41:55 +0900 Subject: Mini popup keyboard adjustment: Have the leftmost number right above the key. Also fixed an issue when the mini popup keyboard hits the right edge of the view. A few code cleanups as well. bug: 2980864 Change-Id: I95f8392521e57560907d54b662e3483ebaf6f7ce --- .../inputmethod/latin/LatinKeyboardBaseView.java | 48 ++++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 45ecca35e..5732cf703 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -989,8 +989,9 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx if (container == null) throw new NullPointerException(); - mMiniKeyboard = (LatinKeyboardBaseView)container.findViewById(R.id.LatinKeyboardBaseView); - mMiniKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() { + LatinKeyboardBaseView miniKeyboard = + (LatinKeyboardBaseView)container.findViewById(R.id.LatinKeyboardBaseView); + miniKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() { public void onKey(int primaryCode, int[] keyCodes, int x, int y) { mKeyboardActionListener.onKey(primaryCode, keyCodes, x, y); dismissPopupKeyboard(); @@ -1028,8 +1029,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } else { keyboard = new Keyboard(getContext(), popupKeyboardId); } - mMiniKeyboard.setKeyboard(keyboard); - mMiniKeyboard.setPopupParent(this); + miniKeyboard.setKeyboard(keyboard); + miniKeyboard.setPopupParent(this); container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST)); @@ -1061,17 +1062,38 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mWindowOffset = new int[2]; getLocationInWindow(mWindowOffset); } - int popupX = popupKey.x + popupKey.width + getPaddingLeft(); - int popupY = popupKey.y + getPaddingTop(); - popupX -= container.getMeasuredWidth(); + + // HACK: Have the leftmost number in the popup characters right above the key + boolean isNumberAtLeftmost = false; + if (popupKey.popupCharacters != null && popupKey.popupCharacters.length() > 1) { + char leftmostChar = popupKey.popupCharacters.charAt(0); + isNumberAtLeftmost = leftmostChar >= '0' && leftmostChar <= '9'; + } + + int popupX = popupKey.x + mWindowOffset[0]; + int popupY = popupKey.y + mWindowOffset[1]; + if (isNumberAtLeftmost) { + popupX -= container.getPaddingLeft(); + } else { + popupX += popupKey.width + getPaddingLeft(); + popupX -= container.getMeasuredWidth(); + popupX += container.getPaddingRight(); + } + popupY += getPaddingTop(); popupY -= container.getMeasuredHeight(); - popupX += mWindowOffset[0]; - popupY += mWindowOffset[1]; - final int x = popupX + container.getPaddingRight(); - final int y = popupY + container.getPaddingBottom(); - mMiniKeyboardOriginX = (x < 0 ? 0 : x) + container.getPaddingLeft(); + popupY += container.getPaddingBottom(); + final int x = popupX; + final int y = popupY; + + int adjustedX = x; + if (x < 0) { + adjustedX = 0; + } else if (x > (getMeasuredWidth() - container.getMeasuredWidth())) { + adjustedX = getMeasuredWidth() - container.getMeasuredWidth(); + } + mMiniKeyboardOriginX = adjustedX + container.getPaddingLeft(); mMiniKeyboardOriginY = y + container.getPaddingTop(); - mMiniKeyboard.setPopupOffset((x < 0) ? 0 : x, y); + mMiniKeyboard.setPopupOffset(adjustedX, y); mMiniKeyboard.setShifted(isShifted()); // Mini keyboard needs no pop-up key preview displayed. mMiniKeyboard.setPreviewEnabled(false); -- cgit v1.2.3-83-g751a From aed0122734a6257e17068539950e78957266f35b Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Sun, 12 Sep 2010 19:08:41 +0900 Subject: Fix a bug in y-axis offset for sliding finger key detection for mini popup keyboard. Also, tentatively added key detection allowance for below of the keys in mini popup keyboard. bug: 2979407 Change-Id: I84794969facd929c84df23e0120d46dff71c6efb --- java/res/values/attrs.xml | 3 +++ java/res/values/styles.xml | 1 + .../android/inputmethod/latin/LatinKeyboardBaseView.java | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index e3171eb33..a8eaab9a3 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -46,6 +46,9 @@ + + + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 16478c883..6ec428603 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -27,6 +27,7 @@ 14sp @layout/keyboard_popup_keyboard -10dip + 30dip #BB000000 2.75 0.5 diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 5732cf703..610d95423 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -200,6 +200,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private int mMiniKeyboardOriginY; private long mMiniKeyboardPopupTime; private int[] mWindowOffset; + private float mMiniKeyboardSlideAllowance; /** Listener for {@link OnKeyboardActionListener}. */ private OnKeyboardActionListener mKeyboardActionListener; @@ -388,6 +389,9 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx case R.styleable.LatinKeyboardBaseView_verticalCorrection: mVerticalCorrection = a.getDimensionPixelOffset(attr, 0); break; + case R.styleable.LatinKeyboardBaseView_miniKeyboardSlideAllowance: + mMiniKeyboardSlideAllowance = a.getDimensionPixelOffset(attr, 0); + break; case R.styleable.LatinKeyboardBaseView_keyPreviewLayout: previewLayout = a.getResourceId(attr, 0); break; @@ -1091,8 +1095,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } else if (x > (getMeasuredWidth() - container.getMeasuredWidth())) { adjustedX = getMeasuredWidth() - container.getMeasuredWidth(); } - mMiniKeyboardOriginX = adjustedX + container.getPaddingLeft(); - mMiniKeyboardOriginY = y + container.getPaddingTop(); + mMiniKeyboardOriginX = adjustedX + container.getPaddingLeft() - mWindowOffset[0]; + mMiniKeyboardOriginY = y + container.getPaddingTop() - mWindowOffset[1]; mMiniKeyboard.setPopupOffset(adjustedX, y); mMiniKeyboard.setShifted(isShifted()); // Mini keyboard needs no pop-up key preview displayed. @@ -1116,7 +1120,12 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) { return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action, - x - mMiniKeyboardOriginX, y - mMiniKeyboardOriginY, 0); + x - mMiniKeyboardOriginX, + // TODO: Currently just taking care of "below" of the keys in a mini popup keyboard + // for key detection by sliding finger. Need to take care of left, right, and + // upper of "edge" keys. + y - mMiniKeyboardOriginY - (int)mMiniKeyboardSlideAllowance, + 0); } private PointerTracker getPointerTracker(final int id) { -- cgit v1.2.3-83-g751a From eb68036798f53763768e4ab37c7bfab9a2f36025 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 13 Sep 2010 19:26:23 +0900 Subject: Add keyHysteresisDistance xml attribute This change also introduces MiniKeyboardKeyDetector and mini_keyboad_slide_allowance parameter to tune the key detection behavior. Bug: 2993769 Change-Id: I1932b0a382e172cb77b9e098ae182049c834dfe0 --- java/res/layout/keyboard_popup.xml | 2 + java/res/values-land/dimens.xml | 5 +- java/res/values/attrs.xml | 6 +-- java/res/values/dimens.xml | 4 +- java/res/values/styles.xml | 2 +- .../inputmethod/latin/LatinKeyboardBaseView.java | 25 ++++----- .../inputmethod/latin/MiniKeyboardKeyDetector.java | 59 ++++++++++++++++++++++ .../android/inputmethod/latin/PointerTracker.java | 13 +++-- 8 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/MiniKeyboardKeyDetector.java (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/res/layout/keyboard_popup.xml b/java/res/layout/keyboard_popup.xml index 1005e7e11..9a52e2cbd 100644 --- a/java/res/layout/keyboard_popup.xml +++ b/java/res/layout/keyboard_popup.xml @@ -33,5 +33,7 @@ android:background="@drawable/keyboard_dark_background" latin:keyBackground="@drawable/btn_keyboard_key_gingerbread_popup" + latin:keyHysteresisDistance="0dip" + latin:verticalCorrection="-20dip" /> diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index 43951552e..4f87b79d2 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -22,4 +22,7 @@ 47dip 38dip 2dip - \ No newline at end of file + + + 79.9dip + diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index a8eaab9a3..995373e84 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -43,12 +43,12 @@ + + + - - - diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 39dce9db0..af8b38110 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -27,5 +27,7 @@ will not go into extract (fullscreen) mode. --> 2.5in 22sp - 0.05in + + + 91.8dip diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 48f0d5e54..258082eb6 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -26,8 +26,8 @@ 80dip 14sp @layout/keyboard_popup + 0.05in -10dip - 40dip #BB000000 2.75 0.5 diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 610d95423..a78e2b869 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -170,6 +170,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private float mShadowRadius; private Drawable mKeyBackground; private float mBackgroundDimAmount; + private float mKeyHysteresisDistance; private float mVerticalCorrection; private int mPreviewOffset; private int mPreviewHeight; @@ -200,14 +201,13 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private int mMiniKeyboardOriginY; private long mMiniKeyboardPopupTime; private int[] mWindowOffset; - private float mMiniKeyboardSlideAllowance; + private final float mMiniKeyboardSlideAllowance; /** Listener for {@link OnKeyboardActionListener}. */ private OnKeyboardActionListener mKeyboardActionListener; private final ArrayList mPointerTrackers = new ArrayList(); private final PointerQueue mPointerQueue = new PointerQueue(); - private final float mDebounceHysteresis; private final boolean mHasDistinctMultitouch; private int mOldPointerCount = 1; @@ -386,12 +386,12 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx case R.styleable.LatinKeyboardBaseView_keyBackground: mKeyBackground = a.getDrawable(attr); break; + case R.styleable.LatinKeyboardBaseView_keyHysteresisDistance: + mKeyHysteresisDistance = a.getDimensionPixelOffset(attr, 0); + break; case R.styleable.LatinKeyboardBaseView_verticalCorrection: mVerticalCorrection = a.getDimensionPixelOffset(attr, 0); break; - case R.styleable.LatinKeyboardBaseView_miniKeyboardSlideAllowance: - mMiniKeyboardSlideAllowance = a.getDimensionPixelOffset(attr, 0); - break; case R.styleable.LatinKeyboardBaseView_keyPreviewLayout: previewLayout = a.getResourceId(attr, 0); break; @@ -473,7 +473,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mSwipeThreshold = (int) (500 * res.getDisplayMetrics().density); // TODO: Refer frameworks/base/core/res/res/values/config.xml mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation); - mDebounceHysteresis = res.getDimension(R.dimen.key_debounce_hysteresis_distance); + mMiniKeyboardSlideAllowance = res.getDimension(R.dimen.mini_keyboard_slide_allowance); GestureDetector.SimpleOnGestureListener listener = new GestureDetector.SimpleOnGestureListener() { @@ -556,7 +556,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mKeys = mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); for (PointerTracker tracker : mPointerTrackers) { - tracker.setKeyboard(mKeys, mDebounceHysteresis); + tracker.setKeyboard(mKeys, mKeyHysteresisDistance); } requestLayout(); // Hint to reallocate the buffer if the size changed @@ -1025,6 +1025,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mKeyboardActionListener.onRelease(primaryCode); } }); + // Override default ProximityKeyDetector. + miniKeyboard.mKeyDetector = new MiniKeyboardKeyDetector(mMiniKeyboardSlideAllowance); Keyboard keyboard; if (popupKey.popupCharacters != null) { @@ -1120,12 +1122,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) { return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action, - x - mMiniKeyboardOriginX, - // TODO: Currently just taking care of "below" of the keys in a mini popup keyboard - // for key detection by sliding finger. Need to take care of left, right, and - // upper of "edge" keys. - y - mMiniKeyboardOriginY - (int)mMiniKeyboardSlideAllowance, - 0); + x - mMiniKeyboardOriginX, y - mMiniKeyboardOriginY, 0); } private PointerTracker getPointerTracker(final int id) { @@ -1138,7 +1135,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx final PointerTracker tracker = new PointerTracker(i, mHandler, mKeyDetector, this, mHasDistinctMultitouch); if (keys != null) - tracker.setKeyboard(keys, mDebounceHysteresis); + tracker.setKeyboard(keys, mKeyHysteresisDistance); if (listener != null) tracker.setOnKeyboardActionListener(listener); pointers.add(tracker); diff --git a/java/src/com/android/inputmethod/latin/MiniKeyboardKeyDetector.java b/java/src/com/android/inputmethod/latin/MiniKeyboardKeyDetector.java new file mode 100644 index 000000000..709d082be --- /dev/null +++ b/java/src/com/android/inputmethod/latin/MiniKeyboardKeyDetector.java @@ -0,0 +1,59 @@ +/* + * 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.inputmethodservice.Keyboard.Key; + +class MiniKeyboardKeyDetector extends KeyDetector { + private static final int MAX_NEARBY_KEYS = 1; + + private final int mSlideAllowanceSquare; + private final int mSlideAllowanceSquareTop; + + public MiniKeyboardKeyDetector(float slideAllowance) { + super(); + mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance); + // Top slide allowance is slightly longer (sqrt(2) times) than other edges. + mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2; + } + + @Override + protected int getMaxNearbyKeys() { + return MAX_NEARBY_KEYS; + } + + @Override + public int getKeyIndexAndNearbyCodes(int x, int y, int[] allKeys) { + final Key[] keys = getKeys(); + final int touchX = getTouchX(x); + final int touchY = getTouchY(y); + int closestKey = LatinKeyboardBaseView.NOT_A_KEY; + int closestKeyDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare; + final int keyCount = keys.length; + for (int i = 0; i < keyCount; i++) { + final Key key = keys[i]; + int dist = key.squaredDistanceFrom(touchX, touchY); + if (dist < closestKeyDist) { + closestKey = i; + closestKeyDist = dist; + } + } + if (allKeys != null && closestKey != LatinKeyboardBaseView.NOT_A_KEY) + allKeys[0] = closestKey; + return closestKey; + } +} diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java index e10c9b862..958e57618 100644 --- a/java/src/com/android/inputmethod/latin/PointerTracker.java +++ b/java/src/com/android/inputmethod/latin/PointerTracker.java @@ -55,7 +55,7 @@ public class PointerTracker { private final boolean mHasDistinctMultitouch; private Key[] mKeys; - private int mKeyDebounceThresholdSquared = -1; + private int mKeyHysteresisDistanceSquared = -1; private int mCurrentKey = NOT_A_KEY; private int mStartX; @@ -106,11 +106,11 @@ public class PointerTracker { mListener = listener; } - public void setKeyboard(Key[] keys, float hysteresisPixel) { - if (keys == null || hysteresisPixel < 1.0f) + public void setKeyboard(Key[] keys, float keyHysteresisDistance) { + if (keys == null || keyHysteresisDistance < 0) throw new IllegalArgumentException(); mKeys = keys; - mKeyDebounceThresholdSquared = (int)(hysteresisPixel * hysteresisPixel); + mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance); // Update current key index because keyboard layout has been changed. mCurrentKey = mKeyDetector.getKeyIndexAndNearbyCodes(mStartX, mStartY, null); } @@ -335,13 +335,12 @@ public class PointerTracker { } private boolean isMinorMoveBounce(int x, int y, int newKey, int curKey) { - if (mKeys == null || mKeyDebounceThresholdSquared < 0) + if (mKeys == null || mKeyHysteresisDistanceSquared < 0) throw new IllegalStateException("keyboard and/or hysteresis not set"); if (newKey == curKey) { return true; } else if (isValidKeyIndex(curKey)) { - return getSquareDistanceToKeyEdge(x, y, mKeys[curKey]) - < mKeyDebounceThresholdSquared; + return getSquareDistanceToKeyEdge(x, y, mKeys[curKey]) < mKeyHysteresisDistanceSquared; } else { return false; } -- cgit v1.2.3-83-g751a From 2aa8078df86029dab394d8dd616f4f6decb39035 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 15 Sep 2010 15:02:29 +0900 Subject: All keys should be processed before processing modifier key Bug: 2987077 Change-Id: I971c44be121d8780ec27aa1649fd0925e249fbbc --- .../inputmethod/latin/LatinKeyboardBaseView.java | 36 ++++++++++++++++++---- .../android/inputmethod/latin/PointerTracker.java | 12 ++++++-- 2 files changed, 40 insertions(+), 8 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index a78e2b869..3ae2e1c53 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -345,7 +345,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return -1; } - public void releasePointersOlderThan(PointerTracker tracker, long eventTime) { + public void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) { LinkedList queue = mQueue; int oldestPos = 0; for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) { @@ -353,11 +353,24 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx oldestPos++; } else { t.onUpEvent(t.getLastX(), t.getLastY(), eventTime); + t.setAlreadyProcessed(); queue.remove(oldestPos); } } } + public void releaseAllPointersExcept(PointerTracker tracker, long eventTime) { + for (PointerTracker t : mQueue) { + if (t == tracker) + continue; + t.onUpEvent(t.getLastX(), t.getLastY(), eventTime); + t.setAlreadyProcessed(); + } + mQueue.clear(); + if (tracker != null) + mQueue.add(tracker); + } + public void remove(PointerTracker tracker) { mQueue.remove(tracker); } @@ -1246,17 +1259,28 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } private void onDownEvent(PointerTracker tracker, int x, int y, long eventTime) { + if (tracker.isOnModifierKey(x, y)) { + // Before processing a down event of modifier key, all pointers already being tracked + // should be released. + mPointerQueue.releaseAllPointersExcept(null, eventTime); + } tracker.onDownEvent(x, y, eventTime); mPointerQueue.add(tracker); } private void onUpEvent(PointerTracker tracker, int x, int y, long eventTime) { - int index = mPointerQueue.lastIndexOf(tracker); - if (index >= 0) { - mPointerQueue.releasePointersOlderThan(tracker, eventTime); + if (tracker.isModifier()) { + // Before processing an up event of modifier key, all pointers already being tracked + // should be released. + mPointerQueue.releaseAllPointersExcept(tracker, eventTime); } else { - Log.w(TAG, "onUpEvent: corresponding down event not found for pointer " - + tracker.mPointerId); + int index = mPointerQueue.lastIndexOf(tracker); + if (index >= 0) { + mPointerQueue.releaseAllPointersOlderThan(tracker, eventTime); + } else { + Log.w(TAG, "onUpEvent: corresponding down event not found for pointer " + + tracker.mPointerId); + } } tracker.onUpEvent(x, y, eventTime); mPointerQueue.remove(tracker); diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java index 958e57618..a612c8eec 100644 --- a/java/src/com/android/inputmethod/latin/PointerTracker.java +++ b/java/src/com/android/inputmethod/latin/PointerTracker.java @@ -123,8 +123,8 @@ public class PointerTracker { return isValidKeyIndex(keyIndex) ? mKeys[keyIndex] : null; } - public boolean isModifier() { - Key key = getKey(mCurrentKey); + private boolean isModifierInternal(int keyIndex) { + Key key = getKey(keyIndex); if (key == null) return false; int primaryCode = key.codes[0]; @@ -132,6 +132,14 @@ public class PointerTracker { || primaryCode == Keyboard.KEYCODE_MODE_CHANGE; } + public boolean isModifier() { + return isModifierInternal(mCurrentKey); + } + + public boolean isOnModifierKey(int x, int y) { + return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null)); + } + public void updateKey(int keyIndex) { if (mKeyAlreadyProcessed) return; -- cgit v1.2.3-83-g751a From 1508c0e84f0cd93ab6f5d46fea5026e833f299bc Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Wed, 15 Sep 2010 13:37:52 +0900 Subject: Add a new preference item to show/hide the settings key. bug: 2998722 Change-Id: Iac1641c338388fd8f85e0cf47e31afdaeb34c0c0 --- java/res/values/donottranslate.xml | 8 + java/res/values/strings.xml | 21 +++ java/res/xml-da/kbd_qwerty.xml | 204 ++++++++++++++++++-- java/res/xml-da/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-de/kbd_qwerty.xml | 204 ++++++++++++++++++-- java/res/xml-de/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-fr/kbd_qwerty.xml | 204 ++++++++++++++++++-- java/res/xml-fr/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-iw/kbd_qwerty.xml | 208 +++++++++++++++++++-- java/res/xml-iw/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-nb/kbd_qwerty.xml | 204 ++++++++++++++++++-- java/res/xml-nb/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-ru/kbd_qwerty.xml | 204 ++++++++++++++++++-- java/res/xml-ru/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-sr/kbd_qwerty.xml | 208 +++++++++++++++++++-- java/res/xml-sr/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml-sv/kbd_qwerty.xml | 204 ++++++++++++++++++-- java/res/xml-sv/kbd_qwerty_black.xml | 206 ++++++++++++++++---- java/res/xml/kbd_qwerty.xml | 194 +++++++++++++++++-- java/res/xml/kbd_qwerty_black.xml | 196 +++++++++++++++---- java/res/xml/kbd_symbols.xml | 30 ++- java/res/xml/kbd_symbols_black.xml | 33 +++- java/res/xml/kbd_symbols_shift.xml | 29 ++- java/res/xml/kbd_symbols_shift_black.xml | 32 +++- java/res/xml/prefs.xml | 9 + .../inputmethod/latin/KeyboardSwitcher.java | 106 +++++++++-- .../com/android/inputmethod/latin/LatinIME.java | 13 +- .../inputmethod/latin/LatinIMESettings.java | 13 +- .../android/inputmethod/latin/LatinIMEUtil.java | 8 + .../inputmethod/latin/LatinKeyboardBaseView.java | 2 +- 30 files changed, 3473 insertions(+), 509 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/res/values/donottranslate.xml b/java/res/values/donottranslate.xml index 971e22965..936609924 100644 --- a/java/res/values/donottranslate.xml +++ b/java/res/values/donottranslate.xml @@ -24,4 +24,12 @@ .,!?) !?,\u0022\u0027:()-/@_ + + + + 0 + + 1 + + 2 diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index bf8e987c9..56dceef2d 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -91,6 +91,27 @@ Spacebar and punctuation automatically insert highlighted word + + Show settings key + + + @string/settings_key_mode_auto + @string/settings_key_mode_always_show + @string/settings_key_mode_always_hide + + + Automatic + + Always show + + Always hide + + + @string/settings_key_mode_auto_name + @string/settings_key_mode_always_show_name + @string/settings_key_mode_always_hide_name + + Bigram Suggestions diff --git a/java/res/xml-da/kbd_qwerty.xml b/java/res/xml-da/kbd_qwerty.xml index 1794d4c86..d9d6a15ac 100644 --- a/java/res/xml-da/kbd_qwerty.xml +++ b/java/res/xml-da/kbd_qwerty.xml @@ -165,6 +165,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:isModifier="true" + android:keyEdgeFlags="left" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:isModifier="true" + android:keyEdgeFlags="left" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:keyLabel="/" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:popupKeyboard="@xml/popup_punctuation" /> + android:iconPreview="@drawable/sym_keyboard_feedback_settings" /> + android:iconPreview="@drawable/sym_keyboard_feedback_mic" /> + android:iconPreview="@drawable/sym_keyboard_feedback_tab" /> + android:popupKeyboard="@xml/popup_punctuation" /> - + + + + + + + + + - + android:isModifier="true"/> + + android:popupKeyboard="@xml/popup_punctuation" android:isModifier="true"/> diff --git a/java/res/xml/kbd_symbols_black.xml b/java/res/xml/kbd_symbols_black.xml index 7eae55481..3bf1397ae 100644 --- a/java/res/xml/kbd_symbols_black.xml +++ b/java/res/xml/kbd_symbols_black.xml @@ -121,22 +121,39 @@ android:isRepeatable="true"/> - + + + + + + + + + - + android:iconPreview="@drawable/sym_keyboard_feedback_settings"/> + + android:popupKeyboard="@xml/popup_punctuation"/> + android:iconPreview="@drawable/sym_keyboard_feedback_return"/> diff --git a/java/res/xml/kbd_symbols_shift.xml b/java/res/xml/kbd_symbols_shift.xml index b0693917e..b72ea50e5 100644 --- a/java/res/xml/kbd_symbols_shift.xml +++ b/java/res/xml/kbd_symbols_shift.xml @@ -88,18 +88,39 @@ android:isRepeatable="true" android:isModifier="true"/> - + + + + + + + + + - + android:isModifier="true"/> + - + - + + + + + + + + + - + android:iconPreview="@drawable/sym_keyboard_feedback_settings"/> + - + + android:iconPreview="@drawable/sym_keyboard_feedback_return" /> diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index 762ada00c..2e6dffaf4 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -59,6 +59,15 @@ android:defaultValue="false" /> + + >(); mSymbolsId = makeSymbolsId(false); mSymbolsShiftedId = makeSymbolsShiftedId(false); - mInputMethodService = ims; } /** @@ -132,11 +163,15 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } private KeyboardId makeSymbolsId(boolean hasVoice) { - return new KeyboardId(KBD_SYMBOLS[getCharColorId()], hasVoice); + return new KeyboardId(KBD_SYMBOLS[getCharColorId()], mHasSettingsKey ? + KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, + false, hasVoice); } private KeyboardId makeSymbolsShiftedId(boolean hasVoice) { - return new KeyboardId(KBD_SYMBOLS_SHIFT[getCharColorId()], hasVoice); + return new KeyboardId(KBD_SYMBOLS_SHIFT[getCharColorId()], mHasSettingsKey ? + KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, + false, hasVoice); } void makeKeyboards(boolean forceCreate) { @@ -243,20 +278,22 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mInputView.setKeyboard(keyboard); keyboard.setShifted(false); keyboard.setShiftLocked(keyboard.isShiftLocked()); - keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions); + keyboard.setImeOptions(mInputMethodService.getResources(), mMode, imeOptions); keyboard.setColorOfSymbolIcons(mIsAutoCompletionActive, isBlackSym()); + // Update the settings key state because number of enabled IMEs could have been changed + updateSettingsKeyState(PreferenceManager.getDefaultSharedPreferences(mInputMethodService)); } private LatinKeyboard getKeyboard(KeyboardId id) { SoftReference ref = mKeyboards.get(id); LatinKeyboard keyboard = (ref == null) ? null : ref.get(); if (keyboard == null) { - Resources orig = mContext.getResources(); + Resources orig = mInputMethodService.getResources(); Configuration conf = orig.getConfiguration(); Locale saveLocale = conf.locale; conf.locale = mInputLocale; orig.updateConfiguration(conf, null); - keyboard = new LatinKeyboard(mContext, id.mXml, id.mKeyboardMode); + keyboard = new LatinKeyboard(mInputMethodService, id.mXml, id.mKeyboardMode); keyboard.setVoiceMode(hasVoiceButton(id.mXml == R.xml.kbd_symbols || id.mXml == R.xml.kbd_symbols_black), mHasVoice); keyboard.setLanguageSwitcher(mLanguageSwitcher, mIsAutoCompletionActive, isBlackSym()); @@ -281,7 +318,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (mode == MODE_PHONE) { return new KeyboardId(KBD_PHONE_SYMBOLS[charColorId], hasVoice); } else { - return new KeyboardId(KBD_SYMBOLS[charColorId], hasVoice); + return new KeyboardId(KBD_SYMBOLS[charColorId], mHasSettingsKey ? + KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, + false, hasVoice); } } switch (mode) { @@ -290,19 +329,27 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha "getKeyboardId:" + mode + "," + imeOptions + "," + isSymbols); /* fall through */ case MODE_TEXT: - return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_NORMAL, true, hasVoice); + return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? + KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY : KEYBOARDMODE_NORMAL, + true, hasVoice); case MODE_SYMBOLS: - return new KeyboardId(KBD_SYMBOLS[charColorId], hasVoice); + return new KeyboardId(KBD_SYMBOLS[charColorId], mHasSettingsKey ? + KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, + false, hasVoice); case MODE_PHONE: return new KeyboardId(KBD_PHONE[charColorId], hasVoice); case MODE_URL: - return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_URL, true, hasVoice); + return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? + KEYBOARDMODE_URL_WITH_SETTINGS_KEY : KEYBOARDMODE_URL, true, hasVoice); case MODE_EMAIL: - return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_EMAIL, true, hasVoice); + return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? + KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY : KEYBOARDMODE_EMAIL, true, hasVoice); case MODE_IM: - return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_IM, true, hasVoice); + return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? + KEYBOARDMODE_IM_WITH_SETTINGS_KEY : KEYBOARDMODE_IM, true, hasVoice); case MODE_WEB: - return new KeyboardId(keyboardRowsResId, KEYBOARDMODE_WEB, true, hasVoice); + return new KeyboardId(keyboardRowsResId, mHasSettingsKey ? + KEYBOARDMODE_WEB_WITH_SETTINGS_KEY : KEYBOARDMODE_WEB, true, hasVoice); } return null; } @@ -351,7 +398,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // called. symbolsShiftedKeyboard.enableShiftLock(); symbolsShiftedKeyboard.setShiftLocked(true); - symbolsShiftedKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); + symbolsShiftedKeyboard.setImeOptions(mInputMethodService.getResources(), + mMode, mImeOptions); } else if (mCurrentId.equals(mSymbolsShiftedId)) { LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId); mCurrentId = mSymbolsId; @@ -360,7 +408,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // indicator, we need to call enableShiftLock() and setShiftLocked(false). symbolsKeyboard.enableShiftLock(); symbolsKeyboard.setShifted(false); - symbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions); + symbolsKeyboard.setImeOptions(mInputMethodService.getResources(), mMode, mImeOptions); } } @@ -445,11 +493,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (PREF_KEYBOARD_LAYOUT.equals(key)) { changeLatinKeyboardView( Integer.valueOf(sharedPreferences.getString(key, DEFAULT_LAYOUT_ID)), false); + } else if (LatinIMESettings.PREF_SETTINGS_KEY.equals(key)) { + updateSettingsKeyState(sharedPreferences); + recreateInputView(); } } public boolean isBlackSym () { - if (mInputView != null && mInputView.getSymbolColorSheme() == 1) { + if (mInputView != null && mInputView.getSymbolColorScheme() == 1) { return true; } return false; @@ -471,4 +522,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha .onAutoCompletionStateChanged(isAutoCompletion)); } } + + private void updateSettingsKeyState(SharedPreferences prefs) { + Resources resources = mInputMethodService.getResources(); + final String settingsKeyMode = prefs.getString(LatinIMESettings.PREF_SETTINGS_KEY, + resources.getString(DEFAULT_SETTINGS_KEY_MODE)); + // We show the settings key when 1) SETTINGS_KEY_MODE_ALWAYS_SHOW or + // 2) SETTINGS_KEY_MODE_AUTO and there are two or more enabled IMEs on the system + if (settingsKeyMode.equals(resources.getString(SETTINGS_KEY_MODE_ALWAYS_SHOW)) + || (settingsKeyMode.equals(resources.getString(SETTINGS_KEY_MODE_AUTO)) + && LatinIMEUtil.hasMultipleEnabledIMEs(mInputMethodService))) { + mHasSettingsKey = true; + } else { + mHasSettingsKey = false; + } + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f80ecc6d4..ecfd41651 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -356,7 +356,7 @@ public class LatinIME extends InputMethodService final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mLanguageSwitcher = new LanguageSwitcher(this); mLanguageSwitcher.loadLocales(prefs); - mKeyboardSwitcher = new KeyboardSwitcher(this, this); + mKeyboardSwitcher = new KeyboardSwitcher(this); mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher); mSystemLocale = conf.locale.toString(); mLanguageSwitcher.setSystemLocale(conf.locale); @@ -984,7 +984,7 @@ public class LatinIME extends InputMethodService private void reloadKeyboards() { if (mKeyboardSwitcher == null) { - mKeyboardSwitcher = new KeyboardSwitcher(this, this); + mKeyboardSwitcher = new KeyboardSwitcher(this); } mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher); if (mKeyboardSwitcher.getInputView() != null @@ -1122,11 +1122,6 @@ public class LatinIME extends InputMethodService } } - private boolean hasMultipleEnabledIMEs() { - return ((InputMethodManager) getSystemService( - INPUT_METHOD_SERVICE)).getEnabledInputMethodList().size() > 1; - } - private void showInputMethodPicker() { ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)) .showInputMethodPicker(); @@ -1134,7 +1129,7 @@ public class LatinIME extends InputMethodService private void onOptionKeyPressed() { if (!isShowingOptionDialog()) { - if (hasMultipleEnabledIMEs()) { + if (LatinIMEUtil.hasMultipleEnabledIMEs(this)) { showOptionsMenu(); } else { launchSettings(); @@ -1144,7 +1139,7 @@ public class LatinIME extends InputMethodService private void onOptionKeyLongPressed() { if (!isShowingOptionDialog()) { - if (hasMultipleEnabledIMEs()) { + if (LatinIMEUtil.hasMultipleEnabledIMEs(this)) { showInputMethodPicker(); } else { launchSettings(); diff --git a/java/src/com/android/inputmethod/latin/LatinIMESettings.java b/java/src/com/android/inputmethod/latin/LatinIMESettings.java index 565c1e6e8..f9534d265 100644 --- a/java/src/com/android/inputmethod/latin/LatinIMESettings.java +++ b/java/src/com/android/inputmethod/latin/LatinIMESettings.java @@ -46,6 +46,7 @@ public class LatinIMESettings extends PreferenceActivity private static final String PREDICTION_SETTINGS_KEY = "prediction_settings"; private static final String VOICE_SETTINGS_KEY = "voice_mode"; private static final String DEBUG_MODE_KEY = "debug_mode"; + /* package */ static final String PREF_SETTINGS_KEY = "settings_key"; private static final String TAG = "LatinIMESettings"; @@ -55,6 +56,7 @@ public class LatinIMESettings extends PreferenceActivity private CheckBoxPreference mQuickFixes; private CheckBoxPreference mDebugMode; private ListPreference mVoicePreference; + private ListPreference mSettingsKeyPreference; private boolean mVoiceOn; private VoiceInputLogger mLogger; @@ -68,6 +70,7 @@ public class LatinIMESettings extends PreferenceActivity addPreferencesFromResource(R.xml.prefs); mQuickFixes = (CheckBoxPreference) findPreference(QUICK_FIXES_KEY); mVoicePreference = (ListPreference) findPreference(VOICE_SETTINGS_KEY); + mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY); SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); prefs.registerOnSharedPreferenceChangeListener(this); @@ -93,6 +96,7 @@ public class LatinIMESettings extends PreferenceActivity } else { updateVoiceModeSummary(); } + updateSettingsKeySummary(); } @Override @@ -106,7 +110,7 @@ public class LatinIMESettings extends PreferenceActivity (new BackupManager(this)).dataChanged(); // If turning on voice input, show dialog if (key.equals(VOICE_SETTINGS_KEY) && !mVoiceOn) { - if (! prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff) + if (!prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff) .equals(mVoiceModeOff)) { showVoiceConfirmation(); } @@ -118,6 +122,13 @@ public class LatinIMESettings extends PreferenceActivity } mVoiceOn = !(prefs.getString(VOICE_SETTINGS_KEY, mVoiceModeOff).equals(mVoiceModeOff)); updateVoiceModeSummary(); + updateSettingsKeySummary(); + } + + private void updateSettingsKeySummary() { + mSettingsKeyPreference.setSummary( + getResources().getStringArray(R.array.settings_key_modes) + [mSettingsKeyPreference.findIndexOfValue(mSettingsKeyPreference.getValue())]); } private void updateDebugMode() { diff --git a/java/src/com/android/inputmethod/latin/LatinIMEUtil.java b/java/src/com/android/inputmethod/latin/LatinIMEUtil.java index 93ad4072d..34b52845e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIMEUtil.java +++ b/java/src/com/android/inputmethod/latin/LatinIMEUtil.java @@ -16,6 +16,9 @@ package com.android.inputmethod.latin; +import android.view.inputmethod.InputMethodManager; + +import android.content.Context; import android.os.AsyncTask; import android.text.format.DateUtils; import android.util.Log; @@ -72,4 +75,9 @@ public class LatinIMEUtil { } } } + + public static boolean hasMultipleEnabledIMEs(Context context) { + return ((InputMethodManager) context.getSystemService( + Context.INPUT_METHOD_SERVICE)).getEnabledInputMethodList().size() > 1; + } } diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 3ae2e1c53..591235577 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -643,7 +643,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return mShowPreview; } - public int getSymbolColorSheme() { + public int getSymbolColorScheme() { return mSymbolColorScheme; } -- cgit v1.2.3-83-g751a From 4a3ffcbf32c21bdb553bf9aed894350ab07f47d8 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sat, 18 Sep 2010 01:48:03 +0900 Subject: Longer popup preview residual time (150ms) Bug: 3004787 Change-Id: Ia63662a549481d18046a46ef8292c0a4438b5588 --- java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 591235577..e75ec54e9 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -153,7 +153,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Timing constants private static final int DELAY_BEFORE_PREVIEW = 0; - private static final int DELAY_AFTER_PREVIEW = 70; + private static final int DELAY_AFTER_PREVIEW = 150; private static final int REPEAT_INTERVAL = PointerTracker.REPEAT_INTERVAL; // Miscellaneous constants -- cgit v1.2.3-83-g751a From 7763b36d6d95d78df49c5144291972d95ff7b4f6 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 17 Sep 2010 11:55:26 +0900 Subject: Align key preview and mini-keyboard positions Bug: 3004793 Change-Id: I1839e6ff3c8c66a576bfb3db9391c146ed225451 --- java/res/values/styles.xml | 2 +- .../inputmethod/latin/LatinKeyboardBaseView.java | 26 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 258082eb6..60fffe873 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -22,7 +22,7 @@ @dimen/key_text_size #FFFFFFFF @layout/key_preview - 5dip + 0dip 80dip 14sp @layout/keyboard_popup diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index e75ec54e9..51c96e124 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -48,6 +48,7 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; +import java.util.List; import java.util.Map; /** @@ -191,6 +192,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx private int mPopupPreviewOffsetX; private int mPopupPreviewOffsetY; private int mWindowY; + private int mPopupPreviewDisplayedY; // Popup mini keyboard private PopupWindow mMiniKeyboardPopup; @@ -918,9 +920,9 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx getLocationInWindow(mOffsetInWindow); mOffsetInWindow[0] += mPopupPreviewOffsetX; // Offset may be zero mOffsetInWindow[1] += mPopupPreviewOffsetY; // Offset may be zero - int[] mWindowLocation = new int[2]; - getLocationOnScreen(mWindowLocation); - mWindowY = mWindowLocation[1]; + int[] windowLocation = new int[2]; + getLocationOnScreen(windowLocation); + mWindowY = windowLocation[1]; } // Set the preview background state mPreviewText.getBackground().setState( @@ -948,6 +950,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mPreviewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY, popupPreviewX, popupPreviewY); } + // Record popup preview position to display mini-keyboard later at the same positon + mPopupPreviewDisplayedY = popupPreviewY; mPreviewText.setVisibility(VISIBLE); } @@ -1057,6 +1061,19 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return container; } + private static boolean isOneRowKeyboard(Keyboard keyboard) { + final List keys = keyboard.getKeys(); + if (keys.size() == 0) return false; + final int edgeFlags = keys.get(0).edgeFlags; + // HACK: The first key of mini keyboard which was inflated from xml and has multiple rows, + // does not have both top and bottom edge flags on at the same time. On the other hand, + // the first key of mini keyboard that was created with popupCharacters must have both top + // and bottom edge flags on. + // When you want to use one row mini-keyboard from xml file, make sure that the row has + // both top and bottom edge flags set. + return (edgeFlags & Keyboard.EDGE_TOP) != 0 && (edgeFlags & Keyboard.EDGE_BOTTOM) != 0; + } + /** * Called when a key is long pressed. By default this will open any popup keyboard associated * with this key through the attributes popupLayout and popupCharacters. @@ -1102,7 +1119,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx popupY -= container.getMeasuredHeight(); popupY += container.getPaddingBottom(); final int x = popupX; - final int y = popupY; + final int y = isOneRowKeyboard(mMiniKeyboard.getKeyboard()) + ? mPopupPreviewDisplayedY : popupY; int adjustedX = x; if (x < 0) { -- cgit v1.2.3-83-g751a From 4da43a25cb5826e96729c24a555111c7e390fbdd Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 21 Sep 2010 11:59:12 +0900 Subject: Shorten popup preview residual time (100ms) The residual time was formerly 150ms by Ia63662a549481d18046a46ef8292c0a4438b5588, and originally was 70ms. Bug: 3004787 Change-Id: If60a74c51e9a68f008711cca2423094e8204755f --- java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 51c96e124..5ec5eb9d9 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -154,7 +154,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx // Timing constants private static final int DELAY_BEFORE_PREVIEW = 0; - private static final int DELAY_AFTER_PREVIEW = 150; + private static final int DELAY_AFTER_PREVIEW = 100; private static final int REPEAT_INTERVAL = PointerTracker.REPEAT_INTERVAL; // Miscellaneous constants -- cgit v1.2.3-83-g751a From 6b75eaa12d69c1db048985a19df85215998f321e Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 21 Sep 2010 18:29:20 +0900 Subject: Fix mini keyboard display position when preview is disabled Bug: 3021082 Change-Id: I2cfb462c89b222449ee2ba5559462a9f5d2306ed --- java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 5ec5eb9d9..a2db12979 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -1119,7 +1119,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx popupY -= container.getMeasuredHeight(); popupY += container.getPaddingBottom(); final int x = popupX; - final int y = isOneRowKeyboard(mMiniKeyboard.getKeyboard()) + final int y = mShowPreview && isOneRowKeyboard(mMiniKeyboard.getKeyboard()) ? mPopupPreviewDisplayedY : popupY; int adjustedX = x; -- cgit v1.2.3-83-g751a From 75c23ced94979a6b3f7c59e95dd46385e9702e2d Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Mon, 20 Sep 2010 18:10:54 +0900 Subject: Add lightweight visual indication for numbers. This change adds lightweight visual hints of alternate numeric characters on the top row - e.g. having a light gray '1' on the upper right corner of letter 'q' Note that MDPI resources are tentative (the same as HDPI for now, until we get fixed MDPI visual assets). bug: 3004632 Change-Id: I7a25cf90b702433a844c88f5c47bf914706af9bc --- java/res/drawable-hdpi/keyboard_hint_0.9.png | Bin 0 -> 379 bytes java/res/drawable-hdpi/keyboard_hint_1.9.png | Bin 0 -> 301 bytes java/res/drawable-hdpi/keyboard_hint_2.9.png | Bin 0 -> 404 bytes java/res/drawable-hdpi/keyboard_hint_3.9.png | Bin 0 -> 413 bytes java/res/drawable-hdpi/keyboard_hint_4.9.png | Bin 0 -> 341 bytes java/res/drawable-hdpi/keyboard_hint_5.9.png | Bin 0 -> 388 bytes java/res/drawable-hdpi/keyboard_hint_6.9.png | Bin 0 -> 413 bytes java/res/drawable-hdpi/keyboard_hint_7.9.png | Bin 0 -> 367 bytes java/res/drawable-hdpi/keyboard_hint_8.9.png | Bin 0 -> 417 bytes java/res/drawable-hdpi/keyboard_hint_9.9.png | Bin 0 -> 417 bytes java/res/drawable-mdpi/keyboard_hint_0.9.png | Bin 0 -> 379 bytes java/res/drawable-mdpi/keyboard_hint_1.9.png | Bin 0 -> 301 bytes java/res/drawable-mdpi/keyboard_hint_2.9.png | Bin 0 -> 404 bytes java/res/drawable-mdpi/keyboard_hint_3.9.png | Bin 0 -> 413 bytes java/res/drawable-mdpi/keyboard_hint_4.9.png | Bin 0 -> 341 bytes java/res/drawable-mdpi/keyboard_hint_5.9.png | Bin 0 -> 388 bytes java/res/drawable-mdpi/keyboard_hint_6.9.png | Bin 0 -> 413 bytes java/res/drawable-mdpi/keyboard_hint_7.9.png | Bin 0 -> 367 bytes java/res/drawable-mdpi/keyboard_hint_8.9.png | Bin 0 -> 417 bytes java/res/drawable-mdpi/keyboard_hint_9.9.png | Bin 0 -> 417 bytes .../android/inputmethod/latin/LatinKeyboard.java | 44 ++++++++++++++ .../inputmethod/latin/LatinKeyboardBaseView.java | 63 +++++++++++++++++---- .../inputmethod/latin/LatinKeyboardView.java | 3 +- 23 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 java/res/drawable-hdpi/keyboard_hint_0.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_1.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_2.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_3.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_4.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_5.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_6.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_7.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_8.9.png create mode 100644 java/res/drawable-hdpi/keyboard_hint_9.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_0.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_1.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_2.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_3.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_4.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_5.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_6.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_7.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_8.9.png create mode 100644 java/res/drawable-mdpi/keyboard_hint_9.9.png (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/res/drawable-hdpi/keyboard_hint_0.9.png b/java/res/drawable-hdpi/keyboard_hint_0.9.png new file mode 100644 index 000000000..271264e92 Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_0.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_1.9.png b/java/res/drawable-hdpi/keyboard_hint_1.9.png new file mode 100644 index 000000000..eaf374262 Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_1.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_2.9.png b/java/res/drawable-hdpi/keyboard_hint_2.9.png new file mode 100644 index 000000000..8a1657117 Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_2.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_3.9.png b/java/res/drawable-hdpi/keyboard_hint_3.9.png new file mode 100644 index 000000000..34b501109 Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_3.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_4.9.png b/java/res/drawable-hdpi/keyboard_hint_4.9.png new file mode 100644 index 000000000..d4cc250dd Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_4.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_5.9.png b/java/res/drawable-hdpi/keyboard_hint_5.9.png new file mode 100644 index 000000000..6a054b42f Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_5.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_6.9.png b/java/res/drawable-hdpi/keyboard_hint_6.9.png new file mode 100644 index 000000000..66e91400a Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_6.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_7.9.png b/java/res/drawable-hdpi/keyboard_hint_7.9.png new file mode 100644 index 000000000..5eae24f4f Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_7.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_8.9.png b/java/res/drawable-hdpi/keyboard_hint_8.9.png new file mode 100644 index 000000000..ea7f512fd Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_8.9.png differ diff --git a/java/res/drawable-hdpi/keyboard_hint_9.9.png b/java/res/drawable-hdpi/keyboard_hint_9.9.png new file mode 100644 index 000000000..0bf85de93 Binary files /dev/null and b/java/res/drawable-hdpi/keyboard_hint_9.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_0.9.png b/java/res/drawable-mdpi/keyboard_hint_0.9.png new file mode 100644 index 000000000..271264e92 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_0.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_1.9.png b/java/res/drawable-mdpi/keyboard_hint_1.9.png new file mode 100644 index 000000000..eaf374262 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_1.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_2.9.png b/java/res/drawable-mdpi/keyboard_hint_2.9.png new file mode 100644 index 000000000..8a1657117 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_2.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_3.9.png b/java/res/drawable-mdpi/keyboard_hint_3.9.png new file mode 100644 index 000000000..34b501109 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_3.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_4.9.png b/java/res/drawable-mdpi/keyboard_hint_4.9.png new file mode 100644 index 000000000..d4cc250dd Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_4.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_5.9.png b/java/res/drawable-mdpi/keyboard_hint_5.9.png new file mode 100644 index 000000000..6a054b42f Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_5.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_6.9.png b/java/res/drawable-mdpi/keyboard_hint_6.9.png new file mode 100644 index 000000000..66e91400a Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_6.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_7.9.png b/java/res/drawable-mdpi/keyboard_hint_7.9.png new file mode 100644 index 000000000..5eae24f4f Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_7.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_8.9.png b/java/res/drawable-mdpi/keyboard_hint_8.9.png new file mode 100644 index 000000000..ea7f512fd Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_8.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_9.9.png b/java/res/drawable-mdpi/keyboard_hint_9.9.png new file mode 100644 index 000000000..0bf85de93 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_9.9.png differ diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 4e139e849..8b89f3900 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -63,6 +63,9 @@ public class LatinKeyboard extends Keyboard { private Key mF1Key; private Key mSpaceKey; private Key m123Key; + private final int NUMBER_HINT_COUNT = 10; + private Key[] mNumberHintKeys; + private Drawable[] mNumberHintIcons = new Drawable[NUMBER_HINT_COUNT]; private int mSpaceKeyIndex = -1; private int mSpaceDragStartX; private int mSpaceDragLastDiff; @@ -129,6 +132,21 @@ public class LatinKeyboard extends Keyboard { mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty || xmlLayoutResId == R.xml.kbd_qwerty_black; mSpaceKeyIndex = indexOf(' '); + initializeNumberHintResources(context); + } + + private void initializeNumberHintResources(Context context) { + final Resources res = context.getResources(); + mNumberHintIcons[0] = res.getDrawable(R.drawable.keyboard_hint_0); + mNumberHintIcons[1] = res.getDrawable(R.drawable.keyboard_hint_1); + mNumberHintIcons[2] = res.getDrawable(R.drawable.keyboard_hint_2); + mNumberHintIcons[3] = res.getDrawable(R.drawable.keyboard_hint_3); + mNumberHintIcons[4] = res.getDrawable(R.drawable.keyboard_hint_4); + mNumberHintIcons[5] = res.getDrawable(R.drawable.keyboard_hint_5); + mNumberHintIcons[6] = res.getDrawable(R.drawable.keyboard_hint_6); + mNumberHintIcons[7] = res.getDrawable(R.drawable.keyboard_hint_7); + mNumberHintIcons[8] = res.getDrawable(R.drawable.keyboard_hint_8); + mNumberHintIcons[9] = res.getDrawable(R.drawable.keyboard_hint_9); } @Override @@ -150,6 +168,23 @@ public class LatinKeyboard extends Keyboard { m123Label = key.label; break; } + + // For number hints on the upper-right corner of key + if (mNumberHintKeys == null) { + // NOTE: This protected method is being called from the base class constructor before + // mNumberHintKeys gets initialized. + mNumberHintKeys = new Key[NUMBER_HINT_COUNT]; + } + int hintNumber = -1; + if (LatinKeyboardBaseView.isNumberAtLeftmostPopupChar(key)) { + hintNumber = key.popupCharacters.charAt(0) - '0'; + } else if (LatinKeyboardBaseView.isNumberAtRightmostPopupChar(key)) { + hintNumber = key.popupCharacters.charAt(key.popupCharacters.length() - 1) - '0'; + } + if (hintNumber >= 0 && hintNumber <= 9) { + mNumberHintKeys[hintNumber] = key; + } + return key; } @@ -293,6 +328,7 @@ public class LatinKeyboard extends Keyboard { if (mSpaceKey != null) { updateSpaceBarForLocale(isAutoCompletion, isBlack); } + updateNumberHintKeys(); } private void setDefaultBounds(Drawable drawable) { @@ -340,6 +376,14 @@ public class LatinKeyboard extends Keyboard { return mSpaceKey; } + private void updateNumberHintKeys() { + for (int i = 0; i < mNumberHintKeys.length; ++i) { + if (mNumberHintKeys[i] != null) { + mNumberHintKeys[i].icon = mNumberHintIcons[i]; + } + } + } + private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) { // If application locales are explicitly selected. if (mLocale != null) { diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index a2db12979..26b3c0581 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -797,6 +797,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); + boolean shouldDrawIcon = true; if (label != null) { // For characters, use large font. For labels like "Done", use small font. if (label.length() > 1 && key.codes.length < 2) { @@ -817,14 +818,24 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx paint); // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); - } else if (key.icon != null) { + + // Usually don't draw icon if label is not null, but we draw icon for the number + // hint. + shouldDrawIcon = isNumberAtEdgeOfPopupChars(key); + } + if (key.icon != null && shouldDrawIcon) { + // Special handing for the upper-right number hint icons + final int drawableWidth = isNumberAtEdgeOfPopupChars(key) ? + key.width : key.icon.getIntrinsicWidth(); + final int drawableHeight = isNumberAtEdgeOfPopupChars(key) ? + key.height : key.icon.getIntrinsicHeight(); + final int drawableX = (key.width - padding.left - padding.right - - key.icon.getIntrinsicWidth()) / 2 + padding.left; + - drawableWidth) / 2 + padding.left; final int drawableY = (key.height - padding.top - padding.bottom - - key.icon.getIntrinsicHeight()) / 2 + padding.top; + - drawableHeight) / 2 + padding.top; canvas.translate(drawableX, drawableY); - key.icon.setBounds(0, 0, - key.icon.getIntrinsicWidth(), key.icon.getIntrinsicHeight()); + key.icon.setBounds(0, 0, drawableWidth, drawableHeight); key.icon.draw(canvas); canvas.translate(-drawableX, -drawableY); } @@ -885,7 +896,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx Key key = tracker.getKey(keyIndex); if (key == null) return; - if (key.icon != null) { + // Should not draw number hint icons + if (key.icon != null && !isNumberAtEdgeOfPopupChars(key)) { mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon); mPreviewText.setText(null); @@ -1100,12 +1112,8 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } // HACK: Have the leftmost number in the popup characters right above the key - boolean isNumberAtLeftmost = false; - if (popupKey.popupCharacters != null && popupKey.popupCharacters.length() > 1) { - char leftmostChar = popupKey.popupCharacters.charAt(0); - isNumberAtLeftmost = leftmostChar >= '0' && leftmostChar <= '9'; - } - + boolean isNumberAtLeftmost = + hasMultiplePopupChars(popupKey) && isNumberAtLeftmostPopupChar(popupKey); int popupX = popupKey.x + mWindowOffset[0]; int popupY = popupKey.y + mWindowOffset[1]; if (isNumberAtLeftmost) { @@ -1151,6 +1159,37 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return true; } + private static boolean hasMultiplePopupChars(Key key) { + if (key.popupCharacters != null && key.popupCharacters.length() > 1) { + return true; + } + return false; + } + + private static boolean isNumberAtEdgeOfPopupChars(Key key) { + return isNumberAtLeftmostPopupChar(key) || isNumberAtRightmostPopupChar(key); + } + + /* package */ static boolean isNumberAtLeftmostPopupChar(Key key) { + if (key.popupCharacters != null && key.popupCharacters.length() > 0 + && isAsciiDigit(key.popupCharacters.charAt(0))) { + return true; + } + return false; + } + + /* package */ static boolean isNumberAtRightmostPopupChar(Key key) { + if (key.popupCharacters != null && key.popupCharacters.length() > 0 + && isAsciiDigit(key.popupCharacters.charAt(key.popupCharacters.length() - 1))) { + return true; + } + return false; + } + + private static boolean isAsciiDigit(char c) { + return (c < 0x80) && Character.isDigit(c); + } + private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) { return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action, x - mMiniKeyboardOriginX, y - mMiniKeyboardOriginY, 0); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index c17d7c555..a45bb21e9 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -24,6 +24,7 @@ import android.inputmethodservice.Keyboard.Key; import android.os.Handler; import android.os.Message; import android.os.SystemClock; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.MotionEvent; @@ -101,7 +102,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { if (keyboard.isShifted() && keyboard instanceof LatinKeyboard && ((LatinKeyboard) keyboard).isAlphaKeyboard() - && label != null && label.length() < 3 + && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { label = label.toString().toUpperCase(); } -- cgit v1.2.3-83-g751a From 3a2896c80475094f751ef447fc9c97028bfc2265 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 21 Sep 2010 16:55:18 +0900 Subject: Fix issue space key preview remains on screen and would not dismiss The space key preview should be displayed one of the following case. - Popup preview is enabled - Language switcher is in action, whether popup preview is enabled or not. For phone number keyboard, popup preview is never displayed even if popup preview is enabled. Bug: 3006612 Bug: 3021091 Change-Id: I5385c776d0e8e3981fc8d8851db9140d92599ce5 --- .../inputmethod/latin/KeyboardSwitcher.java | 44 +++++++++------------- .../android/inputmethod/latin/LatinKeyboard.java | 6 ++- .../inputmethod/latin/LatinKeyboardBaseView.java | 13 ++++++- .../inputmethod/latin/LatinKeyboardView.java | 10 +++++ .../android/inputmethod/latin/PointerTracker.java | 5 +++ 5 files changed, 48 insertions(+), 30 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 0ccb7d98d..ebf2f4e60 100644 --- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -16,7 +16,6 @@ package com.android.inputmethod.latin; -import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; @@ -87,7 +86,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private static final int SYMBOLS_MODE_STATE_BEGIN = 1; private static final int SYMBOLS_MODE_STATE_SYMBOL = 2; - LatinKeyboardView mInputView; + private LatinKeyboardView mInputView; private static final int[] ALPHABET_MODES = { KEYBOARDMODE_NORMAL, KEYBOARDMODE_URL, @@ -100,7 +99,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha KEYBOARDMODE_IM_WITH_SETTINGS_KEY, KEYBOARDMODE_WEB_WITH_SETTINGS_KEY }; - final LatinIME mInputMethodService; + private final LatinIME mInputMethodService; private KeyboardId mSymbolsId; private KeyboardId mSymbolsShiftedId; @@ -120,7 +119,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; // Indicates whether or not we have the settings key - boolean mHasSettingsKey; + private boolean mHasSettingsKey; private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto; private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW = R.string.settings_key_mode_always_show; // NOTE: No need to have SETTINGS_KEY_MODE_ALWAYS_HIDE here because it's not being referred to @@ -134,7 +133,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private int mLayoutId; - KeyboardSwitcher(LatinIME ims) { + public KeyboardSwitcher(LatinIME ims) { mInputMethodService = ims; final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ims); @@ -153,15 +152,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha * @param locale the current input locale, or null for default locale with no locale * button. */ - void setLanguageSwitcher(LanguageSwitcher languageSwitcher) { + public void setLanguageSwitcher(LanguageSwitcher languageSwitcher) { mLanguageSwitcher = languageSwitcher; mInputLocale = mLanguageSwitcher.getInputLocale(); } - void setInputView(LatinKeyboardView inputView) { - mInputView = inputView; - } - private KeyboardId makeSymbolsId(boolean hasVoice) { return new KeyboardId(KBD_SYMBOLS[getCharColorId()], mHasSettingsKey ? KEYBOARDMODE_SYMBOLS_WITH_SETTINGS_KEY : KEYBOARDMODE_SYMBOLS, @@ -174,7 +169,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha false, hasVoice); } - void makeKeyboards(boolean forceCreate) { + public void makeKeyboards(boolean forceCreate) { mSymbolsId = makeSymbolsId(mHasVoice && !mVoiceOnPrimary); mSymbolsShiftedId = makeSymbolsShiftedId(mHasVoice && !mVoiceOnPrimary); @@ -229,7 +224,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - void setVoiceMode(boolean enableVoice, boolean voiceOnPrimary) { + public void setVoiceMode(boolean enableVoice, boolean voiceOnPrimary) { if (enableVoice != mHasVoice || voiceOnPrimary != mVoiceOnPrimary) { mKeyboards.clear(); } @@ -238,11 +233,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha setKeyboardMode(mMode, mImeOptions, mHasVoice, mIsSymbols); } - boolean hasVoiceButton(boolean isSymbols) { + private boolean hasVoiceButton(boolean isSymbols) { return mHasVoice && (isSymbols != mVoiceOnPrimary); } - void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) { + public void setKeyboardMode(int mode, int imeOptions, boolean enableVoice) { mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; mPreferSymbols = mode == MODE_SYMBOLS; if (mode == MODE_SYMBOLS) { @@ -255,7 +250,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) { + private void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) { if (mInputView == null) return; mMode = mode; mImeOptions = imeOptions; @@ -271,7 +266,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (mode == MODE_PHONE) { mInputView.setPhoneKeyboard(keyboard); - mInputView.setPreviewEnabled(false); } mCurrentId = id; @@ -354,15 +348,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return null; } - int getKeyboardMode() { + public int getKeyboardMode() { return mMode; } - boolean isTextMode() { - return mMode == MODE_TEXT; - } - - boolean isAlphabetMode() { + public boolean isAlphabetMode() { if (mCurrentId == null) { return false; } @@ -375,19 +365,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return false; } - void setShifted(boolean shifted) { + public void setShifted(boolean shifted) { if (mInputView != null) { mInputView.setShifted(shifted); } } - void setShiftLocked(boolean shiftLocked) { + public void setShiftLocked(boolean shiftLocked) { if (mInputView != null) { mInputView.setShiftLocked(shiftLocked); } } - void toggleShift() { + public void toggleShift() { if (mCurrentId.equals(mSymbolsId)) { LatinKeyboard symbolsShiftedKeyboard = getKeyboard(mSymbolsShiftedId); mCurrentId = mSymbolsShiftedId; @@ -412,7 +402,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - void toggleSymbols() { + public void toggleSymbols() { setKeyboardMode(mMode, mImeOptions, mHasVoice, !mIsSymbols); if (mIsSymbols && !mPreferSymbols) { mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN; @@ -429,7 +419,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha * Updates state machine to figure out when to automatically switch back to alpha mode. * Returns true if the keyboard needs to switch back */ - boolean onKey(int key) { + public boolean onKey(int key) { // Switch back to alpha mode if user types one or more non-space/enter characters // followed by a space/enter switch (mSymbolsModeState) { diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 8b89f3900..d39766d53 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -131,7 +131,7 @@ public class LatinKeyboard extends Keyboard { R.dimen.spacebar_vertical_correction); mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty || xmlLayoutResId == R.xml.kbd_qwerty_black; - mSpaceKeyIndex = indexOf(' '); + mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE); initializeNumberHintResources(context); } @@ -384,6 +384,10 @@ public class LatinKeyboard extends Keyboard { } } + public boolean isLanguageSwitchEnabled() { + return mLocale != null; + } + private void updateSpaceBarForLocale(boolean isAutoCompletion, boolean isBlack) { // If application locales are explicitly selected. if (mLocale != null) { diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 26b3c0581..fd25d7521 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -881,8 +881,17 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx public void showPreview(int keyIndex, PointerTracker tracker) { int oldKeyIndex = mOldPreviewKeyIndex; mOldPreviewKeyIndex = keyIndex; - // If key changed and preview is on ... - if (oldKeyIndex != keyIndex && mShowPreview) { + final boolean isLanguageSwitchEnabled = (mKeyboard instanceof LatinKeyboard) + && ((LatinKeyboard)mKeyboard).isLanguageSwitchEnabled(); + // We should re-draw popup preview when 1) we need to hide the preview, 2) we will show + // the space key preview and 3) pointer moves off the space key to other letter key, we + // should hide the preview of the previous key. + final boolean hidePreviewOrShowSpaceKeyPreview = (tracker == null) + || tracker.isSpaceKey(keyIndex) || tracker.isSpaceKey(oldKeyIndex); + // If key changed and preview is on or the key is space (language switch is enabled) + if (oldKeyIndex != keyIndex + && (mShowPreview + || (hidePreviewOrShowSpaceKeyPreview && isLanguageSwitchEnabled))) { if (keyIndex == NOT_A_KEY) { mHandler.cancelPopupPreview(); mHandler.dismissPreview(DELAY_AFTER_PREVIEW); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index a45bb21e9..2872f6b46 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -65,6 +65,16 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { mPhoneKeyboard = phoneKeyboard; } + @Override + public void setPreviewEnabled(boolean previewEnabled) { + if (getKeyboard() == mPhoneKeyboard) { + // Phone keyboard never shows popup preview (except language switch). + super.setPreviewEnabled(false); + } else { + super.setPreviewEnabled(previewEnabled); + } + } + @Override public void setKeyboard(Keyboard k) { super.setKeyboard(k); diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java index a612c8eec..cb717cbe7 100644 --- a/java/src/com/android/inputmethod/latin/PointerTracker.java +++ b/java/src/com/android/inputmethod/latin/PointerTracker.java @@ -140,6 +140,11 @@ public class PointerTracker { return isModifierInternal(mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null)); } + public boolean isSpaceKey(int keyIndex) { + Key key = getKey(keyIndex); + return key != null && key.codes[0] == LatinIME.KEYCODE_SPACE; + } + public void updateKey(int keyIndex) { if (mKeyAlreadyProcessed) return; -- cgit v1.2.3-83-g751a From 8243c7a5e52d4b03bb456b591be6af43363f0831 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 17 Sep 2010 20:25:13 +0900 Subject: Choose smaller or shorter language name for space bar To fit a language name to the space bar or the language switcher, this change chooses smaller text size or shorter language name appropriately. This change also tunes the vertical position of a language name in the space bar by parameter SPACEBAR_LANGUAGE_BASELINE. Bug: 3004640 Bug: 3001021 Change-Id: Idb3adcb6fac1a23836510912d35312fa11b4f259 --- .../android/inputmethod/latin/LatinKeyboard.java | 210 ++++++++++++--------- .../inputmethod/latin/LatinKeyboardBaseView.java | 2 +- 2 files changed, 126 insertions(+), 86 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java') diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index d39766d53..9067023ff 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -99,6 +99,13 @@ public class LatinKeyboard extends Keyboard { private static final float SPACEBAR_DRAG_THRESHOLD = 0.8f; private static final float OVERLAP_PERCENTAGE_LOW_PROB = 0.70f; private static final float OVERLAP_PERCENTAGE_HIGH_PROB = 0.85f; + // Minimum width of space key preview (proportional to keyboard width) + private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f; + // Height in space key the language name will be drawn. (proportional to space key height) + private static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f; + // If the full language name needs to be smaller than this value to be drawn on space key, + // its short language name will be used instead. + private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; private static int sSpacebarVerticalCorrection; @@ -405,43 +412,94 @@ public class LatinKeyboard extends Keyboard { } } + // Compute width of text with specified text size using paint. + private static int getTextWidth(Paint paint, String text, float textSize, Rect bounds) { + paint.setTextSize(textSize); + paint.getTextBounds(text, 0, text.length(), bounds); + return bounds.width(); + } + + // Layout local language name and left and right arrow on space bar. + private static String layoutSpaceBar(Paint paint, Locale locale, Drawable lArrow, + Drawable rArrow, int width, int height, float origTextSize, + boolean allowVariableTextSize) { + final float arrowWidth = lArrow.getIntrinsicWidth(); + final float arrowHeight = lArrow.getIntrinsicHeight(); + final float maxTextWidth = width - (arrowWidth + arrowWidth); + final Rect bounds = new Rect(); + + // Estimate appropriate language name text size to fit in maxTextWidth. + String language = LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale)); + int textWidth = getTextWidth(paint, language, origTextSize, bounds); + // Assuming text width and text size are proportional to each other. + float textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + + final boolean useShortName; + if (allowVariableTextSize) { + textWidth = getTextWidth(paint, language, textSize, bounds); + // If text size goes too small or text does not fit, use short name + useShortName = textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME + || textWidth > maxTextWidth; + } else { + useShortName = textWidth > maxTextWidth; + textSize = origTextSize; + } + if (useShortName) { + language = LanguageSwitcher.toTitleCase(locale.getLanguage()); + textWidth = getTextWidth(paint, language, origTextSize, bounds); + textSize = origTextSize * Math.min(maxTextWidth / textWidth, 1.0f); + } + paint.setTextSize(textSize); + + // Place left and right arrow just before and after language text. + final float baseline = height * SPACEBAR_LANGUAGE_BASELINE; + final int top = (int)(baseline - arrowHeight); + final float remains = (width - textWidth) / 2; + lArrow.setBounds((int)(remains - arrowWidth), top, (int)remains, (int)baseline); + rArrow.setBounds((int)(remains + textWidth), top, (int)(remains + textWidth + arrowWidth), + (int)baseline); + + return language; + } + private Bitmap drawSpaceBar(int opacity, boolean isAutoCompletion, boolean isBlack) { - int width = mSpaceKey.width; - int height = mSpaceIcon.getIntrinsicHeight(); - Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(buffer); + final int width = mSpaceKey.width; + final int height = mSpaceIcon.getIntrinsicHeight(); + final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(buffer); canvas.drawColor(mRes.getColor(R.color.latinkeyboard_transparent), PorterDuff.Mode.CLEAR); + // If application locales are explicitly selected. if (mLocale != null) { - Paint paint = new Paint(); - paint.setAntiAlias(true); + final Paint paint = new Paint(); paint.setAlpha(opacity); - // Get the text size from the theme - paint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14)); + paint.setAntiAlias(true); paint.setTextAlign(Align.CENTER); - final String language = getInputLanguage(mSpaceKey.width, paint); - final int ascent = (int) -paint.ascent(); - - int shadowColor = isBlack ? - mRes.getColor(R.color.latinkeyboard_bar_language_shadow_black) - : mRes.getColor(R.color.latinkeyboard_bar_language_shadow_white); + final boolean allowVariableTextSize = true; + final String language = layoutSpaceBar(paint, mLanguageSwitcher.getInputLocale(), + mButtonArrowLeftIcon, mButtonArrowRightIcon, width, height, + getTextSizeFromTheme(android.R.style.TextAppearance_Small, 14), + allowVariableTextSize); + + // Draw language text with shadow + final int shadowColor = mRes.getColor(isBlack + ? R.color.latinkeyboard_bar_language_shadow_black + : R.color.latinkeyboard_bar_language_shadow_white); + final float baseline = height * SPACEBAR_LANGUAGE_BASELINE; + final float descent = paint.descent(); paint.setColor(shadowColor); - canvas.drawText(language, width / 2, ascent - 1, paint); + canvas.drawText(language, width / 2, baseline - descent - 1, paint); paint.setColor(mRes.getColor(R.color.latinkeyboard_bar_language_text)); - canvas.drawText(language, width / 2, ascent, paint); - // Put arrows on either side of the text + canvas.drawText(language, width / 2, baseline - descent, paint); + + // Put arrows that are already layed out on either side of the text if (mLanguageSwitcher.getLocaleCount() > 1) { - Rect bounds = new Rect(); - paint.getTextBounds(language, 0, language.length(), bounds); - drawButtonArrow(mButtonArrowLeftIcon, canvas, - (mSpaceKey.width - bounds.right) / 2 - - mButtonArrowLeftIcon.getIntrinsicWidth(), - (int) paint.getTextSize()); - drawButtonArrow(mButtonArrowRightIcon, canvas, - (mSpaceKey.width + bounds.right) / 2, (int) paint.getTextSize()); + mButtonArrowLeftIcon.draw(canvas); + mButtonArrowRightIcon.draw(canvas); } } + // Draw the spacebar icon at the bottom if (isAutoCompletion) { final int iconWidth = width * SPACE_LED_LENGTH_PERCENT / 100; @@ -461,38 +519,13 @@ public class LatinKeyboard extends Keyboard { return buffer; } - private void drawButtonArrow(Drawable arrow, Canvas canvas, int x, int bottomY) { - arrow.setBounds(x, bottomY - arrow.getIntrinsicHeight(), x + arrow.getIntrinsicWidth(), - bottomY); - arrow.draw(canvas); - } - - private String getInputLanguage(int widthAvail, Paint paint) { - return chooseDisplayName(mLanguageSwitcher.getInputLocale(), widthAvail, paint); - } - - private String getNextInputLanguage(int widthAvail, Paint paint) { - return chooseDisplayName(mLanguageSwitcher.getNextInputLocale(), widthAvail, paint); - } - - private String getPrevInputLanguage(int widthAvail, Paint paint) { - return chooseDisplayName(mLanguageSwitcher.getPrevInputLocale(), widthAvail, paint); - } - - private String chooseDisplayName(Locale locale, int widthAvail, Paint paint) { - if (widthAvail < (int) (.35 * getMinWidth())) { - return LanguageSwitcher.toTitleCase(locale.getLanguage().substring(0, 2)); - } else { - return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale)); - } - } - private void updateLocaleDrag(int diff) { if (mSlidingLocaleIcon == null) { - mSlidingLocaleIcon = new SlidingLocaleDrawable(mSpacePreviewIcon, mSpaceKey.width, - mSpacePreviewIcon.getIntrinsicHeight()); - mSlidingLocaleIcon.setBounds(0, 0, mSpaceKey.width, - mSpacePreviewIcon.getIntrinsicHeight()); + final int width = Math.max(mSpaceKey.width, + (int)(getMinWidth() * SPACEBAR_POPUP_MIN_RATIO)); + final int height = mSpacePreviewIcon.getIntrinsicHeight(); + mSlidingLocaleIcon = new SlidingLocaleDrawable(mSpacePreviewIcon, width, height); + mSlidingLocaleIcon.setBounds(0, 0, width, height); mSpaceKey.iconPreview = mSlidingLocaleIcon; } mSlidingLocaleIcon.setDiff(diff); @@ -777,17 +810,16 @@ public class LatinKeyboard extends Keyboard { */ class SlidingLocaleDrawable extends Drawable { - private int mWidth; - private int mHeight; - private Drawable mBackground; + private final int mWidth; + private final int mHeight; + private final Drawable mBackground; + private final TextPaint mTextPaint; + private final int mMiddleX; + private final Drawable mLeftDrawable; + private final Drawable mRightDrawable; + private final int mThreshold; private int mDiff; - private TextPaint mTextPaint; - private int mMiddleX; - private int mAscent; - private Drawable mLeftDrawable; - private Drawable mRightDrawable; private boolean mHitThreshold; - private int mThreshold; private String mCurrentLanguage; private String mNextLanguage; private String mPrevLanguage; @@ -799,26 +831,20 @@ public class LatinKeyboard extends Keyboard { mWidth = width; mHeight = height; mTextPaint = new TextPaint(); - int textSize = getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18); - mTextPaint.setTextSize(textSize); + mTextPaint.setTextSize(getTextSizeFromTheme(android.R.style.TextAppearance_Medium, 18)); mTextPaint.setColor(R.color.latinkeyboard_transparent); mTextPaint.setTextAlign(Align.CENTER); mTextPaint.setAlpha(OPACITY_FULLY_OPAQUE); mTextPaint.setAntiAlias(true); - mAscent = (int) mTextPaint.ascent(); mMiddleX = (mWidth - mBackground.getIntrinsicWidth()) / 2; mLeftDrawable = mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_left); mRightDrawable = mRes.getDrawable(R.drawable.sym_keyboard_feedback_language_arrows_right); - mLeftDrawable.setBounds(0, 0, - mLeftDrawable.getIntrinsicWidth(), mLeftDrawable.getIntrinsicHeight()); - mRightDrawable.setBounds(mWidth - mRightDrawable.getIntrinsicWidth(), 0, - mWidth, mRightDrawable.getIntrinsicHeight()); mThreshold = ViewConfiguration.get(mContext).getScaledTouchSlop(); } - void setDiff(int diff) { + private void setDiff(int diff) { if (diff == Integer.MAX_VALUE) { mHitThreshold = false; mCurrentLanguage = null; @@ -831,25 +857,39 @@ public class LatinKeyboard extends Keyboard { invalidateSelf(); } + private String getLanguageName(Locale locale) { + return LanguageSwitcher.toTitleCase(locale.getDisplayLanguage(locale)); + } + @Override public void draw(Canvas canvas) { canvas.save(); if (mHitThreshold) { - mTextPaint.setColor(mRes.getColor(R.color.latinkeyboard_feedback_language_text)); - canvas.clipRect(0, 0, mWidth, mHeight); + Paint paint = mTextPaint; + final int width = mWidth; + final int height = mHeight; + final int diff = mDiff; + final Drawable lArrow = mLeftDrawable; + final Drawable rArrow = mRightDrawable; + canvas.clipRect(0, 0, width, height); if (mCurrentLanguage == null) { - mCurrentLanguage = getInputLanguage(mWidth, mTextPaint); - mNextLanguage = getNextInputLanguage(mWidth, mTextPaint); - mPrevLanguage = getPrevInputLanguage(mWidth, mTextPaint); + final LanguageSwitcher languageSwitcher = mLanguageSwitcher; + mCurrentLanguage = getLanguageName(languageSwitcher.getInputLocale()); + mNextLanguage = getLanguageName(languageSwitcher.getNextInputLocale()); + mPrevLanguage = getLanguageName(languageSwitcher.getPrevInputLocale()); } - canvas.drawText(mCurrentLanguage, - mWidth / 2 + mDiff, -mAscent + 4, mTextPaint); - canvas.drawText(mNextLanguage, - mDiff - mWidth / 2, -mAscent + 4, mTextPaint); - canvas.drawText(mPrevLanguage, - mDiff + mWidth + mWidth / 2, -mAscent + 4, mTextPaint); - mLeftDrawable.draw(canvas); - mRightDrawable.draw(canvas); + // Draw language text with shadow + final float baseline = mHeight * SPACEBAR_LANGUAGE_BASELINE - paint.descent(); + paint.setColor(mRes.getColor(R.color.latinkeyboard_feedback_language_text)); + canvas.drawText(mCurrentLanguage, width / 2 + diff, baseline, paint); + canvas.drawText(mNextLanguage, diff - width / 2, baseline, paint); + canvas.drawText(mPrevLanguage, diff + width + width / 2, baseline, paint); + + lArrow.setBounds(0, 0, lArrow.getIntrinsicWidth(), lArrow.getIntrinsicHeight()); + rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width, + rArrow.getIntrinsicHeight()); + lArrow.draw(canvas); + rArrow.draw(canvas); } if (mBackground != null) { canvas.translate(mMiddleX, 0); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index fd25d7521..dafbb669e 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -932,7 +932,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx lp.height = popupHeight; } - int popupPreviewX = key.x - mPreviewText.getPaddingLeft() + getPaddingLeft(); + int popupPreviewX = key.x - (popupWidth - key.width) / 2; int popupPreviewY = key.y - popupHeight + mPreviewOffset; mHandler.cancelDismissPreview(); -- cgit v1.2.3-83-g751a