From 41f9f1ef703ca4d63f1ef08b51d1365a17b4065a Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 13 May 2014 11:19:43 +0900 Subject: [PATCH] Optimize drawing key text shadow layer Change-Id: Id226fe8042ba0f538d5109459a3615d7e7113d7f --- java/res/values/attrs.xml | 1 + java/res/values/colors.xml | 1 - java/res/values/themes-ics.xml | 5 +++-- java/res/values/themes-klp.xml | 5 +++-- java/res/values/themes-lmp.xml | 5 +++-- .../inputmethod/keyboard/KeyboardView.java | 16 +++++++++++----- .../inputmethod/keyboard/MainKeyboardView.java | 17 ++++++++++++++--- 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 475e92f2e..aa505e10b 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -74,6 +74,7 @@ + diff --git a/java/res/values/colors.xml b/java/res/values/colors.xml index dabb4d65e..baa0887bc 100644 --- a/java/res/values/colors.xml +++ b/java/res/values/colors.xml @@ -26,7 +26,6 @@ #B233B5E5 #9933B5E5 @android:color/white - @android:color/transparent #66E0E4E5 #80000000 #A0FFFFFF diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml index 616dbd82c..d7943eeaf 100644 --- a/java/res/values/themes-ics.xml +++ b/java/res/values/themes-ics.xml @@ -56,8 +56,8 @@ @color/key_shifted_letter_hint_inactivated_color_holo @color/key_shifted_letter_hint_activated_color_holo @color/key_text_color_holo - @color/key_text_shadow_color_holo - 0.0 + + -1.0 diff --git a/java/res/values/themes-klp.xml b/java/res/values/themes-klp.xml index 9bb3d79a7..13500fef2 100644 --- a/java/res/values/themes-klp.xml +++ b/java/res/values/themes-klp.xml @@ -56,8 +56,8 @@ @color/key_shifted_letter_hint_inactivated_color_holo @color/key_shifted_letter_hint_activated_color_holo @color/key_text_color_holo - @color/key_text_shadow_color_holo - 0.0 + + -1.0 diff --git a/java/res/values/themes-lmp.xml b/java/res/values/themes-lmp.xml index 773da196d..41c4d09d5 100644 --- a/java/res/values/themes-lmp.xml +++ b/java/res/values/themes-lmp.xml @@ -56,8 +56,8 @@ @color/key_shifted_letter_hint_inactivated_color_holo @color/key_shifted_letter_hint_activated_color_holo @color/key_text_color_holo - @color/key_text_shadow_color_holo - 0.0 + + -1.0 diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 8ca00b005..4450a4474 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -82,6 +82,7 @@ public class KeyboardView extends View { private final float mVerticalCorrection; private final Drawable mKeyBackground; private final Rect mKeyBackgroundPadding = new Rect(); + private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; // HORIZONTAL ELLIPSIS "...", character for popup hint. private static final String POPUP_HINT_CHAR = "\u2026"; @@ -133,7 +134,7 @@ public class KeyboardView extends View { mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension( R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0.0f); mKeyTextShadowRadius = keyboardViewAttr.getFloat( - R.styleable.KeyboardView_keyTextShadowRadius, 0.0f); + R.styleable.KeyboardView_keyTextShadowRadius, KET_TEXT_SHADOW_RADIUS_DISABLED); mVerticalCorrection = keyboardViewAttr.getDimension( R.styleable.KeyboardView_verticalCorrection, 0.0f); keyboardViewAttr.recycle(); @@ -414,18 +415,23 @@ public class KeyboardView extends View { } } - paint.setColor(key.selectTextColor(params)); if (key.isEnabled()) { - // Set a drop shadow for the text - paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor); + paint.setColor(key.selectTextColor(params)); + // Set a drop shadow for the text if the shadow radius is positive value. + if (mKeyTextShadowRadius > 0.0f) { + paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor); + } else { + paint.clearShadowLayer(); + } } else { // Make label invisible paint.setColor(Color.TRANSPARENT); + paint.clearShadowLayer(); } blendAlpha(paint, params.mAnimAlpha); canvas.drawText(label, 0, label.length(), positionX, baseline, paint); // Turn off drop shadow and reset x-scale. - paint.setShadowLayer(0.0f, 0.0f, 0.0f, Color.TRANSPARENT); + paint.clearShadowLayer(); paint.setTextScaleX(1.0f); if (icon != null) { diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 8f79a9128..1a8e4b7e9 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -74,6 +74,7 @@ import java.util.WeakHashMap; * @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedIcon * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor + * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor * @attr ref R.styleable#MainKeyboardView_spacebarBackground * @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha @@ -129,7 +130,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack private final float mLanguageOnSpacebarTextRatio; private float mLanguageOnSpacebarTextSize; private final int mLanguageOnSpacebarTextColor; + private final float mLanguageOnSpacebarTextShadowRadius; private final int mLanguageOnSpacebarTextShadowColor; + private static final float LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED = -1.0f; // The minimum x-scale to fit the language name on spacebar. private static final float MINIMUM_XSCALE_OF_LANGUAGE_NAME = 0.8f; // Stuff to draw auto correction LED on spacebar. @@ -231,6 +234,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f); mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor( R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0); + mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat( + R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius, + LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED); mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor( R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0); mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt( @@ -948,12 +954,17 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack final float descent = paint.descent(); final float textHeight = -paint.ascent() + descent; final float baseline = height / 2 + textHeight / 2; - paint.setColor(mLanguageOnSpacebarTextShadowColor); - paint.setAlpha(mLanguageOnSpacebarAnimAlpha); - canvas.drawText(language, width / 2, baseline - descent - 1, paint); + 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.clearShadowLayer(); + paint.setTextScaleX(1.0f); } // Draw the spacebar icon at the bottom