Merge "Optimize drawing key text shadow layer"
This commit is contained in:
commit
dcd74ba929
7 changed files with 35 additions and 15 deletions
|
@ -74,6 +74,7 @@
|
||||||
<!-- Size of the text for spacebar language label, in the proportion of key height. -->
|
<!-- Size of the text for spacebar language label, in the proportion of key height. -->
|
||||||
<attr name="languageOnSpacebarTextRatio" format="fraction" />
|
<attr name="languageOnSpacebarTextRatio" format="fraction" />
|
||||||
<attr name="languageOnSpacebarTextColor" format="color" />
|
<attr name="languageOnSpacebarTextColor" format="color" />
|
||||||
|
<attr name="languageOnSpacebarTextShadowRadius" format="float" />
|
||||||
<attr name="languageOnSpacebarTextShadowColor" format="color" />
|
<attr name="languageOnSpacebarTextShadowColor" format="color" />
|
||||||
<!-- Background image for the spacebar. -->
|
<!-- Background image for the spacebar. -->
|
||||||
<attr name="spacebarBackground" format="reference" />
|
<attr name="spacebarBackground" format="reference" />
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
<color name="suggested_word_color_ics">#B233B5E5</color>
|
<color name="suggested_word_color_ics">#B233B5E5</color>
|
||||||
<color name="highlight_translucent_color_ics">#9933B5E5</color>
|
<color name="highlight_translucent_color_ics">#9933B5E5</color>
|
||||||
<color name="key_text_color_holo">@android:color/white</color>
|
<color name="key_text_color_holo">@android:color/white</color>
|
||||||
<color name="key_text_shadow_color_holo">@android:color/transparent</color>
|
|
||||||
<color name="key_text_inactivated_color_holo">#66E0E4E5</color>
|
<color name="key_text_inactivated_color_holo">#66E0E4E5</color>
|
||||||
<color name="key_hint_letter_color_holo">#80000000</color>
|
<color name="key_hint_letter_color_holo">#80000000</color>
|
||||||
<color name="key_hint_label_color_holo">#A0FFFFFF</color>
|
<color name="key_hint_label_color_holo">#A0FFFFFF</color>
|
||||||
|
|
|
@ -56,8 +56,8 @@
|
||||||
<item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_holo</item>
|
<item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_holo</item>
|
||||||
<item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_holo</item>
|
<item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_holo</item>
|
||||||
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
|
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
|
||||||
<item name="keyTextShadowColor">@color/key_text_shadow_color_holo</item>
|
<!-- A negative value to disable key text shadow layer. -->
|
||||||
<item name="keyTextShadowRadius">0.0</item>
|
<item name="keyTextShadowRadius">-1.0</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
name="MainKeyboardView.ICS"
|
name="MainKeyboardView.ICS"
|
||||||
|
@ -71,6 +71,7 @@
|
||||||
<item name="autoCorrectionSpacebarLedEnabled">false</item>
|
<item name="autoCorrectionSpacebarLedEnabled">false</item>
|
||||||
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
|
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
|
||||||
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
||||||
|
<item name="languageOnSpacebarTextShadowRadius">1.0</item>
|
||||||
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
||||||
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_ics</item>
|
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_ics</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -56,8 +56,8 @@
|
||||||
<item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_holo</item>
|
<item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_holo</item>
|
||||||
<item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_holo</item>
|
<item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_holo</item>
|
||||||
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
|
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
|
||||||
<item name="keyTextShadowColor">@color/key_text_shadow_color_holo</item>
|
<!-- A negative value to disable key text shadow layer. -->
|
||||||
<item name="keyTextShadowRadius">0.0</item>
|
<item name="keyTextShadowRadius">-1.0</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
name="MainKeyboardView.KLP"
|
name="MainKeyboardView.KLP"
|
||||||
|
@ -71,6 +71,7 @@
|
||||||
<item name="autoCorrectionSpacebarLedEnabled">false</item>
|
<item name="autoCorrectionSpacebarLedEnabled">false</item>
|
||||||
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
|
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
|
||||||
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
||||||
|
<item name="languageOnSpacebarTextShadowRadius">1.0</item>
|
||||||
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
||||||
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_klp</item>
|
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_klp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -56,8 +56,8 @@
|
||||||
<item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_holo</item>
|
<item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_holo</item>
|
||||||
<item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_holo</item>
|
<item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_holo</item>
|
||||||
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
|
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
|
||||||
<item name="keyTextShadowColor">@color/key_text_shadow_color_holo</item>
|
<!-- A negative value to disable key text shadow layer. -->
|
||||||
<item name="keyTextShadowRadius">0.0</item>
|
<item name="keyTextShadowRadius">-1.0</item>
|
||||||
</style>
|
</style>
|
||||||
<style
|
<style
|
||||||
name="MainKeyboardView.LMP"
|
name="MainKeyboardView.LMP"
|
||||||
|
@ -71,6 +71,7 @@
|
||||||
<item name="autoCorrectionSpacebarLedEnabled">false</item>
|
<item name="autoCorrectionSpacebarLedEnabled">false</item>
|
||||||
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
|
<item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
|
||||||
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
<item name="languageOnSpacebarTextColor">@color/spacebar_text_color_holo</item>
|
||||||
|
<item name="languageOnSpacebarTextShadowRadius">1.0</item>
|
||||||
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
<item name="languageOnSpacebarTextShadowColor">@color/spacebar_text_shadow_color_holo</item>
|
||||||
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lmp</item>
|
<item name="spacebarBackground">@drawable/btn_keyboard_spacebar_lmp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -82,6 +82,7 @@ public class KeyboardView extends View {
|
||||||
private final float mVerticalCorrection;
|
private final float mVerticalCorrection;
|
||||||
private final Drawable mKeyBackground;
|
private final Drawable mKeyBackground;
|
||||||
private final Rect mKeyBackgroundPadding = new Rect();
|
private final Rect mKeyBackgroundPadding = new Rect();
|
||||||
|
private static final float KET_TEXT_SHADOW_RADIUS_DISABLED = -1.0f;
|
||||||
|
|
||||||
// HORIZONTAL ELLIPSIS "...", character for popup hint.
|
// HORIZONTAL ELLIPSIS "...", character for popup hint.
|
||||||
private static final String POPUP_HINT_CHAR = "\u2026";
|
private static final String POPUP_HINT_CHAR = "\u2026";
|
||||||
|
@ -133,7 +134,7 @@ public class KeyboardView extends View {
|
||||||
mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension(
|
mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension(
|
||||||
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0.0f);
|
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0.0f);
|
||||||
mKeyTextShadowRadius = keyboardViewAttr.getFloat(
|
mKeyTextShadowRadius = keyboardViewAttr.getFloat(
|
||||||
R.styleable.KeyboardView_keyTextShadowRadius, 0.0f);
|
R.styleable.KeyboardView_keyTextShadowRadius, KET_TEXT_SHADOW_RADIUS_DISABLED);
|
||||||
mVerticalCorrection = keyboardViewAttr.getDimension(
|
mVerticalCorrection = keyboardViewAttr.getDimension(
|
||||||
R.styleable.KeyboardView_verticalCorrection, 0.0f);
|
R.styleable.KeyboardView_verticalCorrection, 0.0f);
|
||||||
keyboardViewAttr.recycle();
|
keyboardViewAttr.recycle();
|
||||||
|
@ -414,18 +415,23 @@ public class KeyboardView extends View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
paint.setColor(key.selectTextColor(params));
|
|
||||||
if (key.isEnabled()) {
|
if (key.isEnabled()) {
|
||||||
// Set a drop shadow for the text
|
paint.setColor(key.selectTextColor(params));
|
||||||
paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor);
|
// 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 {
|
} else {
|
||||||
// Make label invisible
|
// Make label invisible
|
||||||
paint.setColor(Color.TRANSPARENT);
|
paint.setColor(Color.TRANSPARENT);
|
||||||
|
paint.clearShadowLayer();
|
||||||
}
|
}
|
||||||
blendAlpha(paint, params.mAnimAlpha);
|
blendAlpha(paint, params.mAnimAlpha);
|
||||||
canvas.drawText(label, 0, label.length(), positionX, baseline, paint);
|
canvas.drawText(label, 0, label.length(), positionX, baseline, paint);
|
||||||
// Turn off drop shadow and reset x-scale.
|
// Turn off drop shadow and reset x-scale.
|
||||||
paint.setShadowLayer(0.0f, 0.0f, 0.0f, Color.TRANSPARENT);
|
paint.clearShadowLayer();
|
||||||
paint.setTextScaleX(1.0f);
|
paint.setTextScaleX(1.0f);
|
||||||
|
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
|
|
|
@ -74,6 +74,7 @@ import java.util.WeakHashMap;
|
||||||
* @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedIcon
|
* @attr ref R.styleable#MainKeyboardView_autoCorrectionSpacebarLedIcon
|
||||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextRatio
|
||||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextColor
|
||||||
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowRadius
|
||||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarTextShadowColor
|
||||||
* @attr ref R.styleable#MainKeyboardView_spacebarBackground
|
* @attr ref R.styleable#MainKeyboardView_spacebarBackground
|
||||||
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
|
* @attr ref R.styleable#MainKeyboardView_languageOnSpacebarFinalAlpha
|
||||||
|
@ -129,7 +130,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
private final float mLanguageOnSpacebarTextRatio;
|
private final float mLanguageOnSpacebarTextRatio;
|
||||||
private float mLanguageOnSpacebarTextSize;
|
private float mLanguageOnSpacebarTextSize;
|
||||||
private final int mLanguageOnSpacebarTextColor;
|
private final int mLanguageOnSpacebarTextColor;
|
||||||
|
private final float mLanguageOnSpacebarTextShadowRadius;
|
||||||
private final int mLanguageOnSpacebarTextShadowColor;
|
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.
|
// The minimum x-scale to fit the language name on spacebar.
|
||||||
private static final float MINIMUM_XSCALE_OF_LANGUAGE_NAME = 0.8f;
|
private static final float MINIMUM_XSCALE_OF_LANGUAGE_NAME = 0.8f;
|
||||||
// Stuff to draw auto correction LED on spacebar.
|
// 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);
|
R.styleable.MainKeyboardView_languageOnSpacebarTextRatio, 1, 1, 1.0f);
|
||||||
mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor(
|
mLanguageOnSpacebarTextColor = mainKeyboardViewAttr.getColor(
|
||||||
R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
|
R.styleable.MainKeyboardView_languageOnSpacebarTextColor, 0);
|
||||||
|
mLanguageOnSpacebarTextShadowRadius = mainKeyboardViewAttr.getFloat(
|
||||||
|
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowRadius,
|
||||||
|
LANGUAGE_ON_SPACEBAR_TEXT_SHADOW_RADIUS_DISABLED);
|
||||||
mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
|
mLanguageOnSpacebarTextShadowColor = mainKeyboardViewAttr.getColor(
|
||||||
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0);
|
R.styleable.MainKeyboardView_languageOnSpacebarTextShadowColor, 0);
|
||||||
mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
|
mLanguageOnSpacebarFinalAlpha = mainKeyboardViewAttr.getInt(
|
||||||
|
@ -948,12 +954,17 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
final float descent = paint.descent();
|
final float descent = paint.descent();
|
||||||
final float textHeight = -paint.ascent() + descent;
|
final float textHeight = -paint.ascent() + descent;
|
||||||
final float baseline = height / 2 + textHeight / 2;
|
final float baseline = height / 2 + textHeight / 2;
|
||||||
paint.setColor(mLanguageOnSpacebarTextShadowColor);
|
if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
|
||||||
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
|
||||||
canvas.drawText(language, width / 2, baseline - descent - 1, paint);
|
mLanguageOnSpacebarTextShadowColor);
|
||||||
|
} else {
|
||||||
|
paint.clearShadowLayer();
|
||||||
|
}
|
||||||
paint.setColor(mLanguageOnSpacebarTextColor);
|
paint.setColor(mLanguageOnSpacebarTextColor);
|
||||||
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
|
||||||
canvas.drawText(language, width / 2, baseline - descent, paint);
|
canvas.drawText(language, width / 2, baseline - descent, paint);
|
||||||
|
paint.clearShadowLayer();
|
||||||
|
paint.setTextScaleX(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the spacebar icon at the bottom
|
// Draw the spacebar icon at the bottom
|
||||||
|
|
Loading…
Reference in a new issue