diff --git a/java/res/drawable-mdpi/keyboard_hint_at.9.png b/java/res/drawable-mdpi/keyboard_hint_at.9.png new file mode 100644 index 000000000..69baedef4 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_at.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_colon.9.png b/java/res/drawable-mdpi/keyboard_hint_colon.9.png new file mode 100644 index 000000000..9d0d7cbab Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_colon.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_doublecross.9.png b/java/res/drawable-mdpi/keyboard_hint_doublecross.9.png new file mode 100644 index 000000000..d24aa0f07 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_doublecross.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_exclamation.9.png b/java/res/drawable-mdpi/keyboard_hint_exclamation.9.png new file mode 100644 index 000000000..f6cc7fe84 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_exclamation.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_greater.9.png b/java/res/drawable-mdpi/keyboard_hint_greater.9.png new file mode 100644 index 000000000..5210392bf Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_greater.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_plus.9.png b/java/res/drawable-mdpi/keyboard_hint_plus.9.png new file mode 100644 index 000000000..d1d85ac87 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_plus.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_question.9.png b/java/res/drawable-mdpi/keyboard_hint_question.9.png new file mode 100644 index 000000000..37f6e5f36 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_question.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_quote.9.png b/java/res/drawable-mdpi/keyboard_hint_quote.9.png new file mode 100644 index 000000000..e7d2cb5e3 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_quote.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_smaller.9.png b/java/res/drawable-mdpi/keyboard_hint_smaller.9.png new file mode 100644 index 000000000..76553cf96 Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_smaller.9.png differ diff --git a/java/res/drawable-mdpi/keyboard_hint_star.9.png b/java/res/drawable-mdpi/keyboard_hint_star.9.png new file mode 100644 index 000000000..47978c46c Binary files /dev/null and b/java/res/drawable-mdpi/keyboard_hint_star.9.png differ diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 943a43b70..19002140c 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -106,8 +106,12 @@ + + + + diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 94fe76d54..a05d29192 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -212,6 +212,8 @@ ABC ALT + + More diff --git a/java/res/xml-da/kbd_qwerty.xml b/java/res/xml-da/kbd_qwerty.xml index 4aef4b448..431c5d7a6 100644 --- a/java/res/xml-da/kbd_qwerty.xml +++ b/java/res/xml-da/kbd_qwerty.xml @@ -34,44 +34,54 @@ diff --git a/java/res/xml-de/kbd_qwerty_black.xml b/java/res/xml-de/kbd_qwerty_black.xml index dfa7ef600..fc0ede3c5 100644 --- a/java/res/xml-de/kbd_qwerty_black.xml +++ b/java/res/xml-de/kbd_qwerty_black.xml @@ -28,43 +28,53 @@ diff --git a/java/res/xml-fr/kbd_qwerty.xml b/java/res/xml-fr/kbd_qwerty.xml index 80d4d25de..c18339cb3 100644 --- a/java/res/xml-fr/kbd_qwerty.xml +++ b/java/res/xml-fr/kbd_qwerty.xml @@ -28,43 +28,53 @@ diff --git a/java/res/xml-fr/kbd_qwerty_black.xml b/java/res/xml-fr/kbd_qwerty_black.xml index 28bf3f9ef..c0f263f25 100644 --- a/java/res/xml-fr/kbd_qwerty_black.xml +++ b/java/res/xml-fr/kbd_qwerty_black.xml @@ -28,43 +28,53 @@ diff --git a/java/res/xml-nb/kbd_qwerty.xml b/java/res/xml-nb/kbd_qwerty.xml index 8921d5353..ea7fb3042 100644 --- a/java/res/xml-nb/kbd_qwerty.xml +++ b/java/res/xml-nb/kbd_qwerty.xml @@ -34,44 +34,54 @@ diff --git a/java/res/xml-xlarge/kbd_symbols.xml b/java/res/xml-xlarge/kbd_symbols.xml index 7d23dc540..8391ef761 100644 --- a/java/res/xml-xlarge/kbd_symbols.xml +++ b/java/res/xml-xlarge/kbd_symbols.xml @@ -30,6 +30,7 @@ @@ -102,7 +103,7 @@ @@ -102,7 +103,7 @@ diff --git a/java/res/xml/kbd_qwerty_black.xml b/java/res/xml/kbd_qwerty_black.xml index fff409340..a35731815 100644 --- a/java/res/xml/kbd_qwerty_black.xml +++ b/java/res/xml/kbd_qwerty_black.xml @@ -28,43 +28,53 @@ diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboard.java b/java/src/com/android/inputmethod/latin/BaseKeyboard.java index 6f32f9c1a..0bf4f4eaa 100644 --- a/java/src/com/android/inputmethod/latin/BaseKeyboard.java +++ b/java/src/com/android/inputmethod/latin/BaseKeyboard.java @@ -194,9 +194,13 @@ public class BaseKeyboard { /** Label to display */ public CharSequence label; + /** Label to display when keyboard is in temporary shift mode */ + public CharSequence temporaryShiftLabel; /** Icon to display instead of a label. Icon takes precedence over a label */ public Drawable icon; + /** Hint icon to display on the key in conjunction with the label */ + public Drawable hintIcon; /** Preview version of the icon, for the preview popup */ public Drawable iconPreview; /** Width of the key, not including the gap */ @@ -294,22 +298,17 @@ public class BaseKeyboard { TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.BaseKeyboard); - width = getDimensionOrFraction(a, - R.styleable.BaseKeyboard_keyWidth, + width = getDimensionOrFraction(a, R.styleable.BaseKeyboard_keyWidth, keyboard.mDisplayWidth, parent.defaultWidth); - height = getDimensionOrFraction(a, - R.styleable.BaseKeyboard_keyHeight, + height = getDimensionOrFraction(a, R.styleable.BaseKeyboard_keyHeight, keyboard.mDisplayHeight, parent.defaultHeight); - gap = getDimensionOrFraction(a, - R.styleable.BaseKeyboard_horizontalGap, + gap = getDimensionOrFraction(a, R.styleable.BaseKeyboard_horizontalGap, keyboard.mDisplayWidth, parent.defaultHorizontalGap); a.recycle(); - a = res.obtainAttributes(Xml.asAttributeSet(parser), - R.styleable.BaseKeyboard_Key); + a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.BaseKeyboard_Key); this.x += gap; TypedValue codesValue = new TypedValue(); - a.getValue(R.styleable.BaseKeyboard_Key_codes, - codesValue); + a.getValue(R.styleable.BaseKeyboard_Key_codes, codesValue); if (codesValue.type == TypedValue.TYPE_INT_DEC || codesValue.type == TypedValue.TYPE_INT_HEX) { codes = new int[] { codesValue.data }; @@ -318,29 +317,22 @@ public class BaseKeyboard { } iconPreview = a.getDrawable(R.styleable.BaseKeyboard_Key_iconPreview); - if (iconPreview != null) { - iconPreview.setBounds(0, 0, iconPreview.getIntrinsicWidth(), - iconPreview.getIntrinsicHeight()); - } - popupCharacters = a.getText( - R.styleable.BaseKeyboard_Key_popupCharacters); - popupResId = a.getResourceId( - R.styleable.BaseKeyboard_Key_popupKeyboard, 0); - repeatable = a.getBoolean( - R.styleable.BaseKeyboard_Key_isRepeatable, false); - modifier = a.getBoolean( - R.styleable.BaseKeyboard_Key_isModifier, false); - sticky = a.getBoolean( - R.styleable.BaseKeyboard_Key_isSticky, false); + setDefaultBounds(iconPreview); + popupCharacters = a.getText(R.styleable.BaseKeyboard_Key_popupCharacters); + popupResId = a.getResourceId(R.styleable.BaseKeyboard_Key_popupKeyboard, 0); + repeatable = a.getBoolean(R.styleable.BaseKeyboard_Key_isRepeatable, false); + modifier = a.getBoolean(R.styleable.BaseKeyboard_Key_isModifier, false); + sticky = a.getBoolean(R.styleable.BaseKeyboard_Key_isSticky, false); edgeFlags = a.getInt(R.styleable.BaseKeyboard_Key_keyEdgeFlags, 0); edgeFlags |= parent.rowEdgeFlags; - icon = a.getDrawable( - R.styleable.BaseKeyboard_Key_keyIcon); - if (icon != null) { - icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); - } + icon = a.getDrawable(R.styleable.BaseKeyboard_Key_keyIcon); + setDefaultBounds(icon); + hintIcon = a.getDrawable(R.styleable.BaseKeyboard_Key_keyHintIcon); + setDefaultBounds(hintIcon); + label = a.getText(R.styleable.BaseKeyboard_Key_keyLabel); + temporaryShiftLabel = a.getText(R.styleable.BaseKeyboard_Key_temporaryShiftKeyLabel); text = a.getText(R.styleable.BaseKeyboard_Key_keyOutputText); if (codes == null && !TextUtils.isEmpty(label)) { @@ -679,10 +671,12 @@ public class BaseKeyboard { return new int[0]; } + // TODO should be private protected Row createRowFromXml(Resources res, XmlResourceParser parser) { return new Row(res, this, parser); } + // TODO should be private protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) { return new Key(res, parent, x, y, parser); @@ -707,6 +701,7 @@ public class BaseKeyboard { if (TAG_ROW.equals(tag)) { inRow = true; x = 0; + // TODO createRowFromXml should not be called from BaseKeyboard constructor. currentRow = createRowFromXml(res, parser); skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode; if (skipRow) { @@ -715,6 +710,7 @@ public class BaseKeyboard { } } else if (TAG_KEY.equals(tag)) { inKey = true; + // TODO createKeyFromXml should not be called from BaseKeyboard constructor. key = createKeyFromXml(res, currentRow, x, y, parser); mKeys.add(key); if (key.codes[0] == KEYCODE_SHIFT) { @@ -793,4 +789,10 @@ public class BaseKeyboard { } return defValue; } + + protected static void setDefaultBounds(Drawable drawable) { + if (drawable != null) + drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), + drawable.getIntrinsicHeight()); + } } diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 53ccf3629..3fc484d09 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -62,9 +62,6 @@ public class LatinKeyboard extends BaseKeyboard { 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; @@ -119,9 +116,7 @@ public class LatinKeyboard extends BaseKeyboard { mRes = res; mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked); - mShiftLockPreviewIcon.setBounds(0, 0, - mShiftLockPreviewIcon.getIntrinsicWidth(), - mShiftLockPreviewIcon.getIntrinsicHeight()); + setDefaultBounds(mShiftLockPreviewIcon); mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space); mSpaceAutoCompletionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); mSpacePreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_space); @@ -138,37 +133,11 @@ public class LatinKeyboard extends BaseKeyboard { mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty || xmlLayoutResId == R.xml.kbd_qwerty_black; mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE); - 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); - } - - // TODO: delete this method and do initialization in constructor. - private void initializeMemberVariablesAsNeeded() { - if (mNumberHintKeys == null) - mNumberHintKeys = new Key[NUMBER_HINT_COUNT]; } @Override protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) { - // TODO: This initialization is needed because this protected method is being called from - // the base class constructor before this class constructor gets called. We need to fix - // this. - initializeMemberVariablesAsNeeded(); - Key key = new LatinKey(res, parent, x, y, parser); switch (key.codes[0]) { case LatinIME.KEYCODE_ENTER: @@ -186,17 +155,6 @@ public class LatinKeyboard extends BaseKeyboard { break; } - // For number hints on the upper-right corner of key - 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; } @@ -251,11 +209,7 @@ public class LatinKeyboard extends BaseKeyboard { break; } // Set the initial size of the preview icon - if (mEnterKey.iconPreview != null) { - mEnterKey.iconPreview.setBounds(0, 0, - mEnterKey.iconPreview.getIntrinsicWidth(), - mEnterKey.iconPreview.getIntrinsicHeight()); - } + setDefaultBounds(mEnterKey.iconPreview); } } @@ -279,7 +233,7 @@ public class LatinKeyboard extends BaseKeyboard { public boolean isShiftLocked() { return mShiftState == SHIFT_LOCKED; } - + @Override public boolean setShifted(boolean shiftState) { boolean shiftChanged = false; @@ -314,6 +268,10 @@ public class LatinKeyboard extends BaseKeyboard { } } + public boolean isTemporaryUpperCase() { + return mIsAlphaKeyboard && isShifted() && !isShiftLocked(); + } + /* package */ boolean isAlphaKeyboard() { return mIsAlphaKeyboard; } @@ -335,11 +293,6 @@ public class LatinKeyboard extends BaseKeyboard { if (mSpaceKey != null) { updateSpaceBarForLocale(isAutoCompletion, isBlack); } - updateNumberHintKeys(); - } - - private void setDefaultBounds(Drawable drawable) { - drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); } public void setVoiceMode(boolean hasVoiceButton, boolean hasVoice) { @@ -385,14 +338,6 @@ public class LatinKeyboard extends BaseKeyboard { return mSpaceKey; } - private void updateNumberHintKeys() { - for (int i = 0; i < mNumberHintKeys.length; ++i) { - if (mNumberHintKeys[i] != null) { - mNumberHintKeys[i].icon = mNumberHintIcons[i]; - } - } - } - public boolean isLanguageSwitchEnabled() { return mLocale != null; } @@ -828,8 +773,7 @@ public class LatinKeyboard extends BaseKeyboard { public SlidingLocaleDrawable(Drawable background, int width, int height) { mBackground = background; - mBackground.setBounds(0, 0, - mBackground.getIntrinsicWidth(), mBackground.getIntrinsicHeight()); + setDefaultBounds(mBackground); mWidth = width; mHeight = height; mTextPaint = new TextPaint(); @@ -887,7 +831,7 @@ public class LatinKeyboard extends BaseKeyboard { 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()); + setDefaultBounds(lArrow); rArrow.setBounds(width - rArrow.getIntrinsicWidth(), 0, width, rArrow.getIntrinsicHeight()); lArrow.draw(canvas); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java index 264e2f18f..05b29b9b5 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java @@ -578,7 +578,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx mKeys = mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(), -getPaddingTop() + mVerticalCorrection); for (PointerTracker tracker : mPointerTrackers) { - tracker.setKeyboard(mKeys, mKeyHysteresisDistance); + tracker.setKeyboard(keyboard, mKeys, mKeyHysteresisDistance); } requestLayout(); // Hint to reallocate the buffer if the size changed @@ -802,8 +802,19 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop); keyBackground.draw(canvas); - boolean shouldDrawIcon = true; + boolean drawHintIcon = true; if (label != null) { + // If keyboard is multi-touch capable and in temporary upper case state and key has + // tempoarary shift label, label should be hint character and hint icon should not + // be drawn. + if (mHasDistinctMultitouch + && mKeyboard instanceof LatinKeyboard + && ((LatinKeyboard)mKeyboard).isTemporaryUpperCase() + && key.temporaryShiftLabel != null) { + label = key.temporaryShiftLabel.toString(); + drawHintIcon = false; + } + // For characters, use large font. For labels like "Done", use small font. if (label.length() > 1 && key.codes.length < 2) { paint.setTextSize(mLabelTextSize); @@ -823,25 +834,26 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx paint); // Turn off drop shadow paint.setShadowLayer(0, 0, 0, 0); - - // 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(); + Drawable icon = null; + if (key.label == null && key.icon != null) + icon = key.icon; + if (icon == null && key.hintIcon != null && drawHintIcon) + icon = key.hintIcon; + if (icon != null) { + // Hack for key hint icon displaying at the top right corner of the key. + final int drawableWidth = icon == key.hintIcon + ? key.width : icon.getIntrinsicWidth(); + final int drawableHeight = icon == key.hintIcon + ? key.height : icon.getIntrinsicHeight(); final int drawableX = (key.width - padding.left - padding.right - drawableWidth) / 2 + padding.left; final int drawableY = (key.height - padding.top - padding.bottom - drawableHeight) / 2 + padding.top; canvas.translate(drawableX, drawableY); - key.icon.setBounds(0, 0, drawableWidth, drawableHeight); - key.icon.draw(canvas); + icon.setBounds(0, 0, drawableWidth, drawableHeight); + icon.draw(canvas); canvas.translate(-drawableX, -drawableY); } canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop); @@ -906,16 +918,18 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx } } + // TODO Must fix popup preview on xlarge layout private void showKey(final int keyIndex, PointerTracker tracker) { Key key = tracker.getKey(keyIndex); if (key == null) return; // Should not draw number hint icons - if (key.icon != null && !isNumberAtEdgeOfPopupChars(key)) { + if (key.icon != null && key.label == null) { mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon); mPreviewText.setText(null); } else { + // TODO Should take care of temporaryShiftLabel here. mPreviewText.setCompoundDrawables(null, null, null, null); mPreviewText.setText(adjustCase(tracker.getPreviewText(key))); if (key.label.length() > 1 && key.codes.length < 2) { @@ -997,7 +1011,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx * Invalidates a key so that it will be redrawn on the next repaint. Use this method if only * one key is changing it's content. Any changes that affect the position or size of the key * may not be honored. - * @param key key in the attached {@link Keyboard}. + * @param key key in the attached {@link BaseKeyboard}. * @see #invalidateAllKeys */ public void invalidateKey(Key key) { @@ -1182,11 +1196,7 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx return false; } - private static boolean isNumberAtEdgeOfPopupChars(Key key) { - return isNumberAtLeftmostPopupChar(key) || isNumberAtRightmostPopupChar(key); - } - - /* package */ static boolean isNumberAtLeftmostPopupChar(Key key) { + private static boolean isNumberAtLeftmostPopupChar(Key key) { if (key.popupCharacters != null && key.popupCharacters.length() > 0 && isAsciiDigit(key.popupCharacters.charAt(0))) { return true; @@ -1194,14 +1204,6 @@ public class LatinKeyboardBaseView extends View implements PointerTracker.UIProx 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); } @@ -1221,7 +1223,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, mKeyHysteresisDistance); + tracker.setKeyboard(mKeyboard, keys, mKeyHysteresisDistance); if (listener != null) tracker.setOnKeyboardActionListener(listener); pointers.add(tracker); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java index 912af7e2a..f3d045bec 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java @@ -109,9 +109,9 @@ public class LatinKeyboardView extends LatinKeyboardBaseView { @Override protected CharSequence adjustCase(CharSequence label) { BaseKeyboard keyboard = getKeyboard(); - if (keyboard.isShifted() - && keyboard instanceof LatinKeyboard + if (keyboard instanceof LatinKeyboard && ((LatinKeyboard) keyboard).isAlphaKeyboard() + && keyboard.isShifted() && !TextUtils.isEmpty(label) && label.length() < 3 && Character.isLowerCase(label.charAt(0))) { label = label.toString().toUpperCase(); diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java index cf4f7d5c2..6517a206e 100644 --- a/java/src/com/android/inputmethod/latin/PointerTracker.java +++ b/java/src/com/android/inputmethod/latin/PointerTracker.java @@ -52,6 +52,7 @@ public class PointerTracker { private OnKeyboardActionListener mListener; private final boolean mHasDistinctMultitouch; + private BaseKeyboard mKeyboard; private Key[] mKeys; private int mKeyHysteresisDistanceSquared = -1; @@ -179,9 +180,10 @@ public class PointerTracker { mListener = listener; } - public void setKeyboard(Key[] keys, float keyHysteresisDistance) { - if (keys == null || keyHysteresisDistance < 0) + public void setKeyboard(BaseKeyboard keyboard, Key[] keys, float keyHysteresisDistance) { + if (keyboard == null || keys == null || keyHysteresisDistance < 0) throw new IllegalArgumentException(); + mKeyboard = keyboard; mKeys = keys; mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance); // Update current key index because keyboard layout has been changed. @@ -280,7 +282,7 @@ public class PointerTracker { mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex, this); mIsRepeatableKey = true; } - mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this); + startLongPressTimer(keyIndex); } showKeyPreviewAndUpdateKey(keyIndex); } @@ -292,14 +294,15 @@ public class PointerTracker { return; KeyState keyState = mKeyState; int keyIndex = keyState.onMoveKey(x, y); - if (isValidKeyIndex(keyIndex)) { + Key key = getKey(keyIndex); + if (key != null) { if (keyState.getKeyIndex() == NOT_A_KEY) { keyState.onMoveToNewKey(keyIndex, x, y); - mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this); + startLongPressTimer(keyIndex); } else if (!isMinorMoveBounce(x, y, keyIndex)) { resetMultiTap(); keyState.onMoveToNewKey(keyIndex, x, y); - mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this); + startLongPressTimer(keyIndex); } } else { if (keyState.getKeyIndex() != NOT_A_KEY) { @@ -415,6 +418,20 @@ public class PointerTracker { } } + private void startLongPressTimer(int keyIndex) { + Key key = getKey(keyIndex); + // If keyboard is in temporary upper case state and the key has temporary shift label, + // long press should not be started. + if (isTemporaryUpperCase() && key.temporaryShiftLabel != null) + return; + mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this); + } + + private boolean isTemporaryUpperCase() { + return mKeyboard instanceof LatinKeyboard + && ((LatinKeyboard)mKeyboard).isTemporaryUpperCase(); + } + private void detectAndSendKey(int index, int x, int y, long eventTime) { final OnKeyboardActionListener listener = mListener; final Key key = getKey(index); @@ -442,6 +459,14 @@ public class PointerTracker { } code = key.codes[mTapCount]; } + + // If keyboard is in temporary upper case state and key has temporary shift label, + // alternate character code should be sent. + if (isTemporaryUpperCase() && key.temporaryShiftLabel != null) { + code = key.temporaryShiftLabel.charAt(0); + codes[0] = code; + } + /* * Swap the first and second values in the codes array if the primary code is not * the first value but the second value in the array. This happens when key