From 41808192d3a64d3e823e13ace27e3ce80b1c5bda Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" <takaoka@google.com> Date: Thu, 15 May 2014 17:28:54 +0900 Subject: [PATCH] Support 9-patch drawable for spacebar icon Bug: 14419121 Change-Id: I901ea2a5bfae870b3aae8fea3bc38d999b2354b8 --- .../sym_keyboard_spacebar_lxx_dark.9.png | Bin 0 -> 199 bytes .../sym_keyboard_spacebar_lxx_dark.9.png | Bin 0 -> 185 bytes .../sym_keyboard_spacebar_lxx_dark.9.png | Bin 0 -> 246 bytes .../sym_keyboard_spacebar_lxx_dark.9.png | Bin 0 -> 180 bytes java/res/values/attrs.xml | 2 + java/res/values/keyboard-icons-lxx.xml | 2 +- java/res/values/themes-lxx.xml | 1 + java/res/xml-sw600dp/key_styles_common.xml | 1 + java/res/xml/key_styles_common.xml | 1 + java/res/xml/key_styles_number.xml | 1 + .../com/android/inputmethod/keyboard/Key.java | 5 ++ .../inputmethod/keyboard/KeyboardView.java | 18 +++-- .../keyboard/MainKeyboardView.java | 64 +++++++----------- 13 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png create mode 100644 java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png create mode 100644 java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png create mode 100644 java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png diff --git a/java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-hdpi/sym_keyboard_spacebar_lxx_dark.9.png new file mode 100644 index 0000000000000000000000000000000000000000..e70f0c1e84e8c8e7034ee1bbfe7f829d67e61a62 GIT binary patch literal 199 zcmeAS@N?(olHy`uVBq!ia0vp^hCr;&!3HFk2``uhr20Hv978H@y}fG4b;v=W^`UL| zHnC-!FI0&BeqzL?;_fNv;l<6}Z{nA5aP2hJ4JUQ}$nVMP`o5}APyZt$P&)&|jXndW zN*R|YD_@%QZp?Fkd*%0*jfbQD-8<%Xr#Y|q&4*c4JDNA#o={~WDP0(8{AjUd<~g=a xUn<r}CPtPVSvx^6Imcxw`+cTQkEEG4yk~FUbkpt$*DW28$)2u$F6*2UngGqyP!j+E literal 0 HcmV?d00001 diff --git a/java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-mdpi/sym_keyboard_spacebar_lxx_dark.9.png new file mode 100644 index 0000000000000000000000000000000000000000..86e816d5b002e2d05dae3f067cd1d3a75098bdb7 GIT binary patch literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^3P3Ey!3HF+&5pANQVpIijv*Ddk`os2{Aqs_Xu#!m zP(y-saY9D(f8~3O1_!v0XgTP(I9ppRDDy~SJN*BDp~D~H6FEy4GW$4|F?_7b;qzci z3MeVLaDlPyzhVNn8M}(3>;{$&--a7ar*80cOkTiuqvtH+%KtCfw<Q-hhzrQKJaRTU jqVV~)yZ8P;24;rURs7qmgFdSR-NNAM>gTe~DWM4fk}N^P literal 0 HcmV?d00001 diff --git a/java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-xhdpi/sym_keyboard_spacebar_lxx_dark.9.png new file mode 100644 index 0000000000000000000000000000000000000000..cb660545ebad5ca08a77e1303ea8a02562fb6f7a GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^jzDa}!3HF+N`#sNslA>qjv*Dd-rhLR#TY1Z{G+D+ z1OIsqnH3`WuT_^!5e+-V9dY82lk)MIyHbTpPwAd}`FrL2bGqNRPnfyrhps0h(1ah^ ze{$1VfD8tP2K^6dt%4r{-Ct)nhnOFzZChJ4&3S2u%+|?e*QT9wU-5-c{Ozo$2tMC0 z&E}Q2Eae}5wbOpRa93%DbVAE4L8G1xg?3IelUw$hUDIkey<a^ox#ig1%1OyB9zM!G s_t%J@yk&Gq<1e2~liBlyK-(g08A2E@9QV3gRtd7))78&qol`;+033T`+5i9m literal 0 HcmV?d00001 diff --git a/java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png b/java/res/drawable-xxhdpi/sym_keyboard_spacebar_lxx_dark.9.png new file mode 100644 index 0000000000000000000000000000000000000000..1f25e272d0f97825e09c5a24ab812ee4022c75c4 GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^i9qbf!3HD^{!};sscKIb$B>F!Z|`j6ZBP(#4Gb&z z|8&lQ2Q2Yi+Pz(zibCf-<FXIxZctjf@u(e8ISP2t#BSxn!0;;XO~=k0%X24f=0*2y zzVj*h-!c~gM;1W{@gu4wY18eswn`u7aVRM?ada5euz*ad%VnPOCB@BRf5k2k*VEO{ JWt~$(69Bh8IXeIV literal 0 HcmV?d00001 diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 7363b6108e..b90e82b539 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -51,6 +51,7 @@ <!-- Background image for the spacebar. This image needs to be a {@link StateListDrawable}, with the following possible states: normal, pressed. --> <attr name="spacebarBackground" format="reference" /> + <attr name="spacebarIconWidthRatio" format="float" /> <!-- Horizontal padding of left/right aligned key label to the edge of the key. --> <attr name="keyLabelHorizontalPadding" format="dimension" /> <!-- Right padding of hint letter to the edge of the key.--> @@ -284,6 +285,7 @@ <!-- This should be aligned with Key.LABEL_FLAGS__* --> <flag name="alignLeft" value="0x01" /> <flag name="alignRight" value="0x02" /> + <flag name="alignButtom" value="0x04" /> <flag name="alignLeftOfCenter" value="0x08" /> <flag name="fontNormal" value="0x10" /> <flag name="fontMonoSpace" value="0x20" /> diff --git a/java/res/values/keyboard-icons-lxx.xml b/java/res/values/keyboard-icons-lxx.xml index 8a38863166..56d6604753 100644 --- a/java/res/values/keyboard-icons-lxx.xml +++ b/java/res/values/keyboard-icons-lxx.xml @@ -25,7 +25,7 @@ <item name="iconShiftKey">@drawable/sym_keyboard_shift_holo_dark</item> <item name="iconDeleteKey">@drawable/sym_keyboard_delete_lxx_dark</item> <item name="iconSettingsKey">@drawable/sym_keyboard_settings_lxx_dark</item> - <item name="iconSpaceKey">@drawable/sym_keyboard_space_holo_dark</item> + <item name="iconSpaceKey">@drawable/sym_keyboard_spacebar_lxx_dark</item> <item name="iconEnterKey">@drawable/sym_keyboard_return_holo_dark</item> <item name="iconGoKey">@drawable/sym_keyboard_go_lxx_dark</item> <item name="iconSearchKey">@drawable/sym_keyboard_search_lxx_dark</item> diff --git a/java/res/values/themes-lxx.xml b/java/res/values/themes-lxx.xml index 3c7a2b511b..03babd2599 100644 --- a/java/res/values/themes-lxx.xml +++ b/java/res/values/themes-lxx.xml @@ -50,6 +50,7 @@ <item name="keyBackground">@drawable/btn_keyboard_key_lxx</item> <item name="functionalKeyBackground">@drawable/btn_keyboard_key_functional_lxx</item> <item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lxx</item> + <item name="spacebarIconWidthRatio">0.9</item> <item name="keyTypeface">bold</item> <item name="keyTextColor">@color/key_text_color_holo</item> <item name="keyTextInactivatedColor">@color/key_text_inactive_color_lxx</item> diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml index 35b3576af5..d302ab270c 100644 --- a/java/res/xml-sw600dp/key_styles_common.xml +++ b/java/res/xml-sw600dp/key_styles_common.xml @@ -79,6 +79,7 @@ <key-style latin:styleName="spaceKeyStyle" latin:keySpec="!icon/space_key|!code/key_space" + latin:keyLabelFlags="alignButtom" latin:keyActionFlags="noKeyPreview|enableLongPress" /> <!-- U+200C: ZERO WIDTH NON-JOINER U+200D: ZERO WIDTH JOINER --> diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index f8b4a2a601..0a274e009f 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -88,6 +88,7 @@ <key-style latin:styleName="spaceKeyStyle" latin:keySpec="!icon/space_key|!code/key_space" + latin:keyLabelFlags="alignButtom" latin:keyActionFlags="noKeyPreview|enableLongPress" /> <!-- U+200C: ZERO WIDTH NON-JOINER U+200D: ZERO WIDTH JOINER --> diff --git a/java/res/xml/key_styles_number.xml b/java/res/xml/key_styles_number.xml index df4448c254..8a76fe397e 100644 --- a/java/res/xml/key_styles_number.xml +++ b/java/res/xml/key_styles_number.xml @@ -120,6 +120,7 @@ <key-style latin:styleName="numSpaceKeyStyle" latin:keySpec="!icon/space_key_for_number_layout|!code/key_space" + latin:keyLabelFlags="alignButtom" latin:keyActionFlags="enableLongPress" latin:parentStyle="numKeyBaseStyle" /> <!-- Override defaultEnterKeyStyle in key_styles_enter.xml --> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index a1269c8010..cf68c565df 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -60,6 +60,7 @@ public class Key implements Comparable<Key> { private final int mLabelFlags; private static final int LABEL_FLAGS_ALIGN_LEFT = 0x01; private static final int LABEL_FLAGS_ALIGN_RIGHT = 0x02; + private static final int LABEL_FLAGS_ALIGN_BUTTOM = 0x04; private static final int LABEL_FLAGS_ALIGN_LEFT_OF_CENTER = 0x08; private static final int LABEL_FLAGS_FONT_NORMAL = 0x10; private static final int LABEL_FLAGS_FONT_MONO_SPACE = 0x20; @@ -646,6 +647,10 @@ public class Key implements Comparable<Key> { return (mLabelFlags & LABEL_FLAGS_ALIGN_RIGHT) != 0; } + public final boolean isAlignButtom() { + return (mLabelFlags & LABEL_FLAGS_ALIGN_BUTTOM) != 0; + } + public final boolean isAlignLeftOfCenter() { return (mLabelFlags & LABEL_FLAGS_ALIGN_LEFT_OF_CENTER) != 0; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index a6eac4cd7a..edfc5fded1 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -28,6 +28,7 @@ import android.graphics.Rect; import android.graphics.Region; import android.graphics.Typeface; import android.graphics.drawable.Drawable; +import android.graphics.drawable.NinePatchDrawable; import android.util.AttributeSet; import android.view.View; @@ -49,6 +50,7 @@ import java.util.HashSet; * @attr ref R.styleable#KeyboardView_keyBackground * @attr ref R.styleable#KeyboardView_functionalKeyBackground * @attr ref R.styleable#KeyboardView_spacebarBackground + * @attr ref R.styleable#KeyboardView_spacebarIconWidthRatio * @attr ref R.styleable#KeyboardView_keyLabelHorizontalPadding * @attr ref R.styleable#KeyboardView_keyHintLetterPadding * @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding @@ -85,6 +87,7 @@ public class KeyboardView extends View { private final Drawable mKeyBackground; private final Drawable mFunctionalKeyBackground; private final Drawable mSpacebarBackground; + private final float mSpacebarIconWidthRatio; private final Rect mKeyBackgroundPadding = new Rect(); private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; @@ -135,8 +138,9 @@ public class KeyboardView extends View { : mKeyBackground; final Drawable spacebarBackground = keyboardViewAttr.getDrawable( R.styleable.KeyboardView_spacebarBackground); - mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground - : mKeyBackground; + mSpacebarBackground = (spacebarBackground != null) ? spacebarBackground : mKeyBackground; + mSpacebarIconWidthRatio = keyboardViewAttr.getFloat( + R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f); mKeyLabelHorizontalPadding = keyboardViewAttr.getDimensionPixelOffset( R.styleable.KeyboardView_keyLabelHorizontalPadding, 0); mKeyHintLetterPadding = keyboardViewAttr.getDimension( @@ -513,10 +517,16 @@ public class KeyboardView extends View { // Draw key icon. if (label == null && icon != null) { - final int iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth); + final int iconWidth; + if (key.getCode() == Constants.CODE_SPACE && icon instanceof NinePatchDrawable) { + iconWidth = (int)(keyWidth * mSpacebarIconWidthRatio); + } else { + iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth); + } final int iconHeight = icon.getIntrinsicHeight(); final int iconX, alignX; - final int iconY = (keyHeight - iconHeight) / 2; + final int iconY = key.isAlignButtom() ? keyHeight - iconHeight + : (keyHeight - iconHeight) / 2; if (key.isAlignLeft()) { iconX = mKeyLabelHorizontalPadding; alignX = iconX; diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index ac11dca974..26b6dd06ae 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -27,7 +27,6 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Typeface; -import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; import android.util.AttributeSet; import android.util.Log; @@ -116,7 +115,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack /* Space key and its icon and background. */ private Key mSpaceKey; - private Drawable mSpacebarIcon; // Stuff to draw language name on spacebar. private final int mLanguageOnSpacebarFinalAlpha; private ObjectAnimator mLanguageOnSpacebarFadeoutAnimator; @@ -389,8 +387,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mMoreKeysKeyboardCache.clear(); mSpaceKey = keyboard.getKey(Constants.CODE_SPACE); - mSpacebarIcon = (mSpaceKey != null) - ? mSpaceKey.getIcon(keyboard.mIconsSet, Constants.Color.ALPHA_OPAQUE) : null; final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio; if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { @@ -847,18 +843,19 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack if (key.altCodeWhileTyping() && key.isEnabled()) { params.mAnimAlpha = mAltCodeKeyWhileTypingAnimAlpha; } + super.onDrawKeyTopVisuals(key, canvas, paint, params); final int code = key.getCode(); if (code == Constants.CODE_SPACE) { - drawSpacebar(key, canvas, paint); + // If input language are explicitly selected. + if (mLanguageOnSpacebarFormatType != LanguageOnSpacebarHelper.FORMAT_TYPE_NONE) { + drawLanguageOnSpacebar(key, canvas, paint); + } // Whether space key needs to show the "..." popup hint for special purposes if (key.isLongPressEnabled() && mHasMultipleEnabledIMEsOrSubtypes) { drawKeyPopupHint(key, canvas, paint, params); } } else if (code == Constants.CODE_LANGUAGE_SWITCH) { - super.onDrawKeyTopVisuals(key, canvas, paint, params); drawKeyPopupHint(key, canvas, paint, params); - } else { - super.onDrawKeyTopVisuals(key, canvas, paint, params); } } @@ -898,42 +895,29 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return ""; } - private void drawSpacebar(final Key key, final Canvas canvas, final Paint paint) { + private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) { final int width = key.getWidth(); final int height = key.getHeight(); - - // If input language are explicitly selected. - if (mLanguageOnSpacebarFormatType != LanguageOnSpacebarHelper.FORMAT_TYPE_NONE) { - paint.setTextAlign(Align.CENTER); - paint.setTypeface(Typeface.DEFAULT); - paint.setTextSize(mLanguageOnSpacebarTextSize); - final InputMethodSubtype subtype = getKeyboard().mId.mSubtype; - final String language = layoutLanguageOnSpacebar(paint, subtype, width); - // Draw language text with shadow - final float descent = paint.descent(); - final float textHeight = -paint.ascent() + descent; - final float baseline = height / 2 + textHeight / 2; - if (mLanguageOnSpacebarTextShadowRadius > 0.0f) { - paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0, - mLanguageOnSpacebarTextShadowColor); - } else { - paint.clearShadowLayer(); - } - paint.setColor(mLanguageOnSpacebarTextColor); - paint.setAlpha(mLanguageOnSpacebarAnimAlpha); - canvas.drawText(language, width / 2, baseline - descent, paint); + paint.setTextAlign(Align.CENTER); + paint.setTypeface(Typeface.DEFAULT); + paint.setTextSize(mLanguageOnSpacebarTextSize); + final InputMethodSubtype subtype = getKeyboard().mId.mSubtype; + final String language = layoutLanguageOnSpacebar(paint, subtype, width); + // Draw language text with shadow + final float descent = paint.descent(); + final float textHeight = -paint.ascent() + descent; + final float baseline = height / 2 + textHeight / 2; + if (mLanguageOnSpacebarTextShadowRadius > 0.0f) { + paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0, + mLanguageOnSpacebarTextShadowColor); + } else { paint.clearShadowLayer(); - paint.setTextScaleX(1.0f); - } - - // Draw the spacebar icon at the bottom - if (mSpacebarIcon != null) { - final int iconWidth = mSpacebarIcon.getIntrinsicWidth(); - final int iconHeight = mSpacebarIcon.getIntrinsicHeight(); - int x = (width - iconWidth) / 2; - int y = height - iconHeight; - drawIcon(canvas, mSpacebarIcon, x, y, iconWidth, iconHeight); } + paint.setColor(mLanguageOnSpacebarTextColor); + paint.setAlpha(mLanguageOnSpacebarAnimAlpha); + canvas.drawText(language, width / 2, baseline - descent, paint); + paint.clearShadowLayer(); + paint.setTextScaleX(1.0f); } @Override -- GitLab