Make popup hint letter theme-aware

Bug: 16351091
Change-Id: I6af18ea210c00916157138b9cfbeb073aee6ca1b
main
Tadashi G. Takaoka 2014-08-05 17:32:53 +09:00
parent 85b7b967b7
commit 3410e16907
6 changed files with 18 additions and 5 deletions

View File

@ -52,7 +52,9 @@
<attr name="spacebarIconWidthRatio" format="float" />
<!-- Right padding of hint letter to the edge of the key.-->
<attr name="keyHintLetterPadding" format="dimension" />
<!-- Bottom padding of popup hint letter "..." to the edge of the key.-->
<!-- Popup hint letter string-->
<attr name="keyPopupHintLetter" format="string" />
<!-- Bottom padding of popup hint letter to the edge of the key.-->
<attr name="keyPopupHintLetterPadding" format="dimension" />
<!-- Right padding of shifted letter hint to the edge of the key.-->
<attr name="keyShiftedLetterHintPadding" format="dimension" />

View File

@ -60,6 +60,8 @@
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
<!-- A negative value to disable key text shadow layer. -->
<item name="keyTextShadowRadius">-1.0</item>
<!-- U+2026: "…" HORIZONTAL ELLIPSIS -->
<item name="keyPopupHintLetter">&#x2026;</item>
</style>
<style
name="MainKeyboardView.ICS"

View File

@ -60,6 +60,8 @@
<item name="keyPreviewTextColor">@color/key_text_color_holo</item>
<!-- A negative value to disable key text shadow layer. -->
<item name="keyTextShadowRadius">-1.0</item>
<!-- U+2026: "…" HORIZONTAL ELLIPSIS -->
<item name="keyPopupHintLetter">&#x2026;</item>
</style>
<style
name="MainKeyboardView.KLP"

View File

@ -61,6 +61,7 @@
<item name="keyPreviewTextColor">@color/key_text_color_lxx_dark</item>
<!-- A negative value to disable key text shadow layer. -->
<item name="keyTextShadowRadius">-1.0</item>
<item name="keyPopupHintLetter"></item> <!-- No popup hint letter -->
</style>
<style
name="MainKeyboardView.LXX_Dark"

View File

@ -61,6 +61,7 @@
<item name="keyPreviewTextColor">@color/key_text_color_lxx_light</item>
<!-- A negative value to disable key text shadow layer. -->
<item name="keyTextShadowRadius">-1.0</item>
<item name="keyPopupHintLetter"></item> <!-- No popup hint letter -->
</style>
<style
name="MainKeyboardView.LXX_Light"

View File

@ -29,6 +29,7 @@ import android.graphics.Region;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
@ -48,6 +49,7 @@ import java.util.HashSet;
* @attr ref R.styleable#KeyboardView_spacebarBackground
* @attr ref R.styleable#KeyboardView_spacebarIconWidthRatio
* @attr ref R.styleable#KeyboardView_keyHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyPopupHintLetter
* @attr ref R.styleable#KeyboardView_keyPopupHintLetterPadding
* @attr ref R.styleable#KeyboardView_keyShiftedLetterHintPadding
* @attr ref R.styleable#KeyboardView_keyTextShadowRadius
@ -74,6 +76,7 @@ public class KeyboardView extends View {
// XML attributes
private final KeyVisualAttributes mKeyVisualAttributes;
private final float mKeyHintLetterPadding;
private final String mKeyPopupHintLetter;
private final float mKeyPopupHintLetterPadding;
private final float mKeyShiftedLetterHintPadding;
private final float mKeyTextShadowRadius;
@ -85,9 +88,6 @@ public class KeyboardView extends View {
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";
// The maximum key label width in the proportion to the key width.
private static final float MAX_LABEL_RATIO = 0.90f;
@ -132,6 +132,8 @@ public class KeyboardView extends View {
R.styleable.KeyboardView_spacebarIconWidthRatio, 1.0f);
mKeyHintLetterPadding = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_keyHintLetterPadding, 0.0f);
mKeyPopupHintLetter = keyboardViewAttr.getString(
R.styleable.KeyboardView_keyPopupHintLetter);
mKeyPopupHintLetterPadding = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0.0f);
mKeyShiftedLetterHintPadding = keyboardViewAttr.getDimension(
@ -468,6 +470,9 @@ public class KeyboardView extends View {
// Draw popup hint "..." at the bottom right corner of the key.
protected void drawKeyPopupHint(final Key key, final Canvas canvas, final Paint paint,
final KeyDrawParams params) {
if (TextUtils.isEmpty(mKeyPopupHintLetter)) {
return;
}
final int keyWidth = key.getDrawWidth();
final int keyHeight = key.getHeight();
@ -478,7 +483,7 @@ public class KeyboardView extends View {
final float hintX = keyWidth - mKeyHintLetterPadding
- TypefaceUtils.getReferenceCharWidth(paint) / 2.0f;
final float hintY = keyHeight - mKeyPopupHintLetterPadding;
canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint);
canvas.drawText(mKeyPopupHintLetter, hintX, hintY, paint);
}
protected static void drawIcon(final Canvas canvas, final Drawable icon, final int x,