diff options
author | 2011-09-07 00:30:32 -0700 | |
---|---|---|
committer | 2011-09-07 00:30:32 -0700 | |
commit | ae56d5c33de1faa7813fab301208d86934c6c934 (patch) | |
tree | 87f56ee3812ae178f9ec740fe02be120a2700533 /java/src | |
parent | 25047fca0b0a0335194bcba0c9ed9ba400db3205 (diff) | |
parent | 2ed13003affdeea89f2b8d0ed1a6a19dcbc22da8 (diff) | |
download | latinime-ae56d5c33de1faa7813fab301208d86934c6c934.tar.gz latinime-ae56d5c33de1faa7813fab301208d86934c6c934.tar.xz latinime-ae56d5c33de1faa7813fab301208d86934c6c934.zip |
Merge "Use different reference character for hit label"
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardView.java | 76 |
1 files changed, 43 insertions, 33 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 96eb69407..1e7c32638 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -124,7 +124,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // This map caches key label text width in pixel as value and key label text size as map key. private static final HashMap<Integer, Float> sTextWidthCache = new HashMap<Integer, Float>(); - private static final String KEY_LABEL_REFERENCE_CHAR = "M"; + private static final char[] KEY_LABEL_REFERENCE_CHAR = { 'M' }; + private static final char[] KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR = { '8' }; private final DrawingHandler mDrawingHandler = new DrawingHandler(this); @@ -545,8 +546,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { final int labelSize = key.selectTextSize(params.mKeyLetterSize, params.mKeyLargeLetterSize, params.mKeyLabelSize, params.mKeyHintLabelSize); paint.setTextSize(labelSize); - final float labelCharHeight = getCharHeight(paint); - final float labelCharWidth = getCharWidth(paint); + final float labelCharHeight = getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint); + final float labelCharWidth = getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint); // Vertical label text alignment. final float baseline = centerY + labelCharHeight / 2; @@ -634,20 +635,25 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } paint.setColor(hintColor); paint.setTextSize(hintSize); - final float hintCharWidth = getCharWidth(paint); final float hintX, hintY; if (key.hasHintLabel()) { + // The hint label is placed just right of the key label. Used mainly on + // "phone number" layout. // TODO: Generalize the following calculations. - hintX = positionX + hintCharWidth * 2; - hintY = centerY + getCharHeight(paint) / 2; + hintX = positionX + getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) * 2; + hintY = centerY + getCharHeight(KEY_LABEL_REFERENCE_CHAR, paint) / 2; paint.setTextAlign(Align.LEFT); } else if (key.hasUppercaseLetter()) { - hintX = keyWidth - params.mKeyUppercaseLetterPadding - hintCharWidth / 2; - hintY = -paint.ascent() + params.mKeyUppercaseLetterPadding; + // The hint label is placed at top-right corner of the key. Used mainly on tablet. + hintX = keyWidth - params.mKeyUppercaseLetterPadding + - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; + hintY = -paint.ascent(); paint.setTextAlign(Align.CENTER); } else { // key.hasHintLetter() - hintX = keyWidth - params.mKeyHintLetterPadding - hintCharWidth / 2; - hintY = -paint.ascent() + params.mKeyHintLetterPadding; + // The hint label is placed at top-right corner of the key. Used mainly on phone. + hintX = keyWidth - params.mKeyHintLetterPadding + - getCharWidth(KEY_NUMERIC_HINT_LABEL_REFERENCE_CHAR, paint) / 2; + hintY = -paint.ascent(); paint.setTextAlign(Align.CENTER); } canvas.drawText(hint, 0, hint.length(), hintX, hintY, paint); @@ -690,7 +696,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { paint.setTextSize(params.mKeyHintLetterSize); paint.setColor(params.mKeyHintLabelColor); paint.setTextAlign(Align.CENTER); - final float hintX = keyWidth - params.mKeyHintLetterPadding - getCharWidth(paint) / 2; + final float hintX = keyWidth - params.mKeyHintLetterPadding + - getCharWidth(KEY_LABEL_REFERENCE_CHAR, paint) / 2; final float hintY = keyHeight - params.mKeyHintLetterPadding; canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint); @@ -704,37 +711,40 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { private static final Rect sTextBounds = new Rect(); - private static float getCharHeight(Paint paint) { - final int labelSize = (int)paint.getTextSize(); - final Float cachedValue = sTextHeightCache.get(labelSize); - if (cachedValue != null) - return cachedValue; - - paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, sTextBounds); - final float height = sTextBounds.height(); - sTextHeightCache.put(labelSize, height); - return height; - } - - private static float getCharWidth(Paint paint) { + private static int getCharGeometryCacheKey(char reference, Paint paint) { final int labelSize = (int)paint.getTextSize(); final Typeface face = paint.getTypeface(); - final Integer key; + final int codePointOffset = reference << 15; if (face == Typeface.DEFAULT) { - key = labelSize; + return codePointOffset + labelSize; } else if (face == Typeface.DEFAULT_BOLD) { - key = labelSize + 1000; + return codePointOffset + labelSize + 0x1000; } else if (face == Typeface.MONOSPACE) { - key = labelSize + 2000; + return codePointOffset + labelSize + 0x2000; } else { - key = labelSize; + return codePointOffset + labelSize; } + } - final Float cached = sTextWidthCache.get(key); - if (cached != null) - return cached; + private static float getCharHeight(char[] character, Paint paint) { + final Integer key = getCharGeometryCacheKey(character[0], paint); + final Float cachedValue = sTextHeightCache.get(key); + if (cachedValue != null) + return cachedValue; + + paint.getTextBounds(character, 0, 1, sTextBounds); + final float height = sTextBounds.height(); + sTextHeightCache.put(key, height); + return height; + } + + private static float getCharWidth(char[] character, Paint paint) { + final Integer key = getCharGeometryCacheKey(character[0], paint); + final Float cachedValue = sTextWidthCache.get(key); + if (cachedValue != null) + return cachedValue; - paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, sTextBounds); + paint.getTextBounds(character, 0, 1, sTextBounds); final float width = sTextBounds.width(); sTextWidthCache.put(key, width); return width; |