From 41808192d3a64d3e823e13ace27e3ce80b1c5bda Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" 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;{$&--a7ar*80cOkTiuqvtH+%KtCfwgTe~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$hUDIkeyF!Z|`j6ZBP(#4Gb&z z|8&lQ2Q2Yi+Pz(zibCf- + @@ -284,6 +285,7 @@ + diff --git a/java/res/values/keyboard-icons-lxx.xml b/java/res/values/keyboard-icons-lxx.xml index 8a3886316..56d660475 100644 --- a/java/res/values/keyboard-icons-lxx.xml +++ b/java/res/values/keyboard-icons-lxx.xml @@ -25,7 +25,7 @@ @drawable/sym_keyboard_shift_holo_dark @drawable/sym_keyboard_delete_lxx_dark @drawable/sym_keyboard_settings_lxx_dark - @drawable/sym_keyboard_space_holo_dark + @drawable/sym_keyboard_spacebar_lxx_dark @drawable/sym_keyboard_return_holo_dark @drawable/sym_keyboard_go_lxx_dark @drawable/sym_keyboard_search_lxx_dark diff --git a/java/res/values/themes-lxx.xml b/java/res/values/themes-lxx.xml index 3c7a2b511..03babd259 100644 --- a/java/res/values/themes-lxx.xml +++ b/java/res/values/themes-lxx.xml @@ -50,6 +50,7 @@ @drawable/btn_keyboard_key_lxx @drawable/btn_keyboard_key_functional_lxx @drawable/btn_keyboard_spacebar_lxx + 0.9 bold @color/key_text_color_holo @color/key_text_inactive_color_lxx diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml index 35b3576af..d302ab270 100644 --- a/java/res/xml-sw600dp/key_styles_common.xml +++ b/java/res/xml-sw600dp/key_styles_common.xml @@ -79,6 +79,7 @@ diff --git a/java/res/xml/key_styles_common.xml b/java/res/xml/key_styles_common.xml index f8b4a2a60..0a274e009 100644 --- a/java/res/xml/key_styles_common.xml +++ b/java/res/xml/key_styles_common.xml @@ -88,6 +88,7 @@ diff --git a/java/res/xml/key_styles_number.xml b/java/res/xml/key_styles_number.xml index df4448c25..8a76fe397 100644 --- a/java/res/xml/key_styles_number.xml +++ b/java/res/xml/key_styles_number.xml @@ -120,6 +120,7 @@ diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index a1269c801..cf68c565d 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 { 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 { 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 a6eac4cd7..edfc5fded 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 ac11dca97..26b6dd06a 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