From d87f28f1457f5490df3796fa2a8d815b2bcde152 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 28 Jun 2011 03:01:35 +0900 Subject: [PATCH] Use left/right-edge popup preview background Bug: 4902361 Change-Id: Iafbadd0e44c0db2fb6a0875c964304bec6ac8cb0 --- .../keyboard_key_feedback_left_ics.xml | 21 ++++++++++++++ .../keyboard_key_feedback_right_ics.xml | 21 ++++++++++++++ java/res/values/attrs.xml | 4 +++ java/res/values/styles.xml | 4 +++ .../inputmethod/keyboard/KeyboardView.java | 29 +++++++++++++------ 5 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 java/res/drawable/keyboard_key_feedback_left_ics.xml create mode 100644 java/res/drawable/keyboard_key_feedback_right_ics.xml diff --git a/java/res/drawable/keyboard_key_feedback_left_ics.xml b/java/res/drawable/keyboard_key_feedback_left_ics.xml new file mode 100644 index 000000000..b68b37f6b --- /dev/null +++ b/java/res/drawable/keyboard_key_feedback_left_ics.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/java/res/drawable/keyboard_key_feedback_right_ics.xml b/java/res/drawable/keyboard_key_feedback_right_ics.xml new file mode 100644 index 000000000..830678a5a --- /dev/null +++ b/java/res/drawable/keyboard_key_feedback_right_ics.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 6b063efff..d89f55a50 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -68,6 +68,10 @@ + + + + diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml index 1f1488e26..08301be5c 100644 --- a/java/res/values/styles.xml +++ b/java/res/values/styles.xml @@ -51,6 +51,8 @@ #CCE0E4E5 @layout/key_preview @drawable/keyboard_key_feedback + @null + @null @drawable/keyboard_key_feedback #FFFFFFFF @dimen/key_preview_offset @@ -152,6 +154,8 @@ #66E0E4E5 #FFFFFFFF @drawable/keyboard_key_feedback_ics + @drawable/keyboard_key_feedback_left_ics + @drawable/keyboard_key_feedback_right_ics @drawable/transparent #FFFFFFFF @dimen/key_preview_height_ics diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 52e2a6a6d..da738b24c 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -118,6 +118,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private final float mKeyHysteresisDistance; private final float mVerticalCorrection; private final Drawable mPreviewBackground; + private final Drawable mPreviewLeftBackground; + private final Drawable mPreviewRightBackground; private final Drawable mPreviewSpacebarBackground; private final int mPreviewTextColor; private final float mPreviewTextRatio; @@ -203,6 +205,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private static final String KEY_LABEL_REFERENCE_CHAR = "M"; private final int mKeyLabelHorizontalPadding; + private static final int MEASURESPEC_UNSPECIFIED = MeasureSpec.makeMeasureSpec( + 0, MeasureSpec.UNSPECIFIED); + private final UIHandler mHandler = new UIHandler(this); public static class UIHandler extends StaticInnerHandlerWrapper { @@ -354,6 +359,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mShowKeyPreviewPopup = false; } mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground); + mPreviewLeftBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewLeftBackground); + mPreviewRightBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewRightBackground); mPreviewSpacebarBackground = a.getDrawable( R.styleable.KeyboardView_keyPreviewSpacebarBackground); mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0); @@ -1016,21 +1023,25 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { } else { previewText.setBackgroundDrawable(mPreviewBackground); } - // Set the preview background state - previewText.getBackground().setState( - key.mPopupCharacters != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); - previewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + previewText.measure(MEASURESPEC_UNSPECIFIED, MEASURESPEC_UNSPECIFIED); final int previewWidth = Math.max(previewText.getMeasuredWidth(), keyDrawWidth + previewText.getPaddingLeft() + previewText.getPaddingRight()); final int previewHeight = mPreviewHeight; getLocationInWindow(mCoordinates); - final int previewX = keyDrawX - (previewWidth - keyDrawWidth) / 2 + mCoordinates[0]; + int previewX = keyDrawX - (previewWidth - keyDrawWidth) / 2 + mCoordinates[0]; final int previewY = key.mY - previewHeight + mCoordinates[1] + mPreviewOffset; + if (previewX < 0 && mPreviewLeftBackground != null) { + previewText.setBackgroundDrawable(mPreviewLeftBackground); + previewX = 0; + } else if (previewX + previewWidth > getWidth() && mPreviewRightBackground != null) { + previewText.setBackgroundDrawable(mPreviewRightBackground); + previewX = getWidth() - previewWidth; + } - // Place the key preview. - // TODO: Adjust position of key previews which touch screen edges + // Set the preview background state + previewText.getBackground().setState( + key.mPopupCharacters != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET); FrameLayoutCompatUtils.placeViewAt( previewText, previewX, previewY, previewWidth, previewHeight); previewText.setVisibility(VISIBLE); @@ -1147,7 +1158,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { miniKeyboardView.setKeyboard(keyboard); container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); + MEASURESPEC_UNSPECIFIED); return miniKeyboardView; }