Use left/right-edge popup preview background

Bug: 4902361
Change-Id: Iafbadd0e44c0db2fb6a0875c964304bec6ac8cb0
main
Tadashi G. Takaoka 2011-06-28 03:01:35 +09:00
parent f41e9f79eb
commit d87f28f145
5 changed files with 70 additions and 9 deletions

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_long_pressable="true"
android:drawable="@drawable/keyboard_key_feedback_left_more_background_holo" />
<item android:drawable="@drawable/keyboard_key_feedback_left_background_holo" />
</selector>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_long_pressable="true"
android:drawable="@drawable/keyboard_key_feedback_right_more_background_holo" />
<item android:drawable="@drawable/keyboard_key_feedback_right_background_holo" />
</selector>

View File

@ -68,6 +68,10 @@
<attr name="keyPreviewLayout" format="reference" /> <attr name="keyPreviewLayout" format="reference" />
<!-- The background for key press feedback. --> <!-- The background for key press feedback. -->
<attr name="keyPreviewBackground" format="reference" /> <attr name="keyPreviewBackground" format="reference" />
<!-- The background for the left edge key press feedback. -->
<attr name="keyPreviewLeftBackground" format="reference" />
<!-- The background for the right edge key press feedback. -->
<attr name="keyPreviewRightBackground" format="reference" />
<!-- The background for spacebar press feedback. --> <!-- The background for spacebar press feedback. -->
<attr name="keyPreviewSpacebarBackground" format="reference" /> <attr name="keyPreviewSpacebarBackground" format="reference" />
<!-- The text color for key press feedback. --> <!-- The text color for key press feedback. -->

View File

@ -51,6 +51,8 @@
<item name="keyUppercaseLetterActivatedColor">#CCE0E4E5</item> <item name="keyUppercaseLetterActivatedColor">#CCE0E4E5</item>
<item name="keyPreviewLayout">@layout/key_preview</item> <item name="keyPreviewLayout">@layout/key_preview</item>
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback</item>
<item name="keyPreviewLeftBackground">@null</item>
<item name="keyPreviewRightBackground">@null</item>
<item name="keyPreviewSpacebarBackground">@drawable/keyboard_key_feedback</item> <item name="keyPreviewSpacebarBackground">@drawable/keyboard_key_feedback</item>
<item name="keyPreviewTextColor">#FFFFFFFF</item> <item name="keyPreviewTextColor">#FFFFFFFF</item>
<item name="keyPreviewOffset">@dimen/key_preview_offset</item> <item name="keyPreviewOffset">@dimen/key_preview_offset</item>
@ -152,6 +154,8 @@
<item name="keyUppercaseLetterInactivatedColor">#66E0E4E5</item> <item name="keyUppercaseLetterInactivatedColor">#66E0E4E5</item>
<item name="keyUppercaseLetterActivatedColor">#FFFFFFFF</item> <item name="keyUppercaseLetterActivatedColor">#FFFFFFFF</item>
<item name="keyPreviewBackground">@drawable/keyboard_key_feedback_ics</item> <item name="keyPreviewBackground">@drawable/keyboard_key_feedback_ics</item>
<item name="keyPreviewLeftBackground">@drawable/keyboard_key_feedback_left_ics</item>
<item name="keyPreviewRightBackground">@drawable/keyboard_key_feedback_right_ics</item>
<item name="keyPreviewSpacebarBackground">@drawable/transparent</item> <item name="keyPreviewSpacebarBackground">@drawable/transparent</item>
<item name="keyPreviewTextColor">#FFFFFFFF</item> <item name="keyPreviewTextColor">#FFFFFFFF</item>
<item name="keyPreviewHeight">@dimen/key_preview_height_ics</item> <item name="keyPreviewHeight">@dimen/key_preview_height_ics</item>

View File

@ -118,6 +118,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
private final float mKeyHysteresisDistance; private final float mKeyHysteresisDistance;
private final float mVerticalCorrection; private final float mVerticalCorrection;
private final Drawable mPreviewBackground; private final Drawable mPreviewBackground;
private final Drawable mPreviewLeftBackground;
private final Drawable mPreviewRightBackground;
private final Drawable mPreviewSpacebarBackground; private final Drawable mPreviewSpacebarBackground;
private final int mPreviewTextColor; private final int mPreviewTextColor;
private final float mPreviewTextRatio; 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 static final String KEY_LABEL_REFERENCE_CHAR = "M";
private final int mKeyLabelHorizontalPadding; private final int mKeyLabelHorizontalPadding;
private static final int MEASURESPEC_UNSPECIFIED = MeasureSpec.makeMeasureSpec(
0, MeasureSpec.UNSPECIFIED);
private final UIHandler mHandler = new UIHandler(this); private final UIHandler mHandler = new UIHandler(this);
public static class UIHandler extends StaticInnerHandlerWrapper<KeyboardView> { public static class UIHandler extends StaticInnerHandlerWrapper<KeyboardView> {
@ -354,6 +359,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mShowKeyPreviewPopup = false; mShowKeyPreviewPopup = false;
} }
mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground); mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground);
mPreviewLeftBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewLeftBackground);
mPreviewRightBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewRightBackground);
mPreviewSpacebarBackground = a.getDrawable( mPreviewSpacebarBackground = a.getDrawable(
R.styleable.KeyboardView_keyPreviewSpacebarBackground); R.styleable.KeyboardView_keyPreviewSpacebarBackground);
mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0); mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0);
@ -1016,21 +1023,25 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
} else { } else {
previewText.setBackgroundDrawable(mPreviewBackground); 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), previewText.measure(MEASURESPEC_UNSPECIFIED, MEASURESPEC_UNSPECIFIED);
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
final int previewWidth = Math.max(previewText.getMeasuredWidth(), keyDrawWidth final int previewWidth = Math.max(previewText.getMeasuredWidth(), keyDrawWidth
+ previewText.getPaddingLeft() + previewText.getPaddingRight()); + previewText.getPaddingLeft() + previewText.getPaddingRight());
final int previewHeight = mPreviewHeight; final int previewHeight = mPreviewHeight;
getLocationInWindow(mCoordinates); 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; 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. // Set the preview background state
// TODO: Adjust position of key previews which touch screen edges previewText.getBackground().setState(
key.mPopupCharacters != null ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
FrameLayoutCompatUtils.placeViewAt( FrameLayoutCompatUtils.placeViewAt(
previewText, previewX, previewY, previewWidth, previewHeight); previewText, previewX, previewY, previewWidth, previewHeight);
previewText.setVisibility(VISIBLE); previewText.setVisibility(VISIBLE);
@ -1147,7 +1158,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
miniKeyboardView.setKeyboard(keyboard); miniKeyboardView.setKeyboard(keyboard);
container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST), container.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); MEASURESPEC_UNSPECIFIED);
return miniKeyboardView; return miniKeyboardView;
} }