Can override key drawing methods of KeyboardView

Change-Id: Ie303df4f5e944ea868f5c28ba3bb72a57cc9a35f
main
Tadashi G. Takaoka 2011-12-18 02:58:13 +09:00
parent 605f730959
commit bc781e963f
1 changed files with 61 additions and 51 deletions

View File

@ -194,7 +194,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
private static class KeyDrawParams {
/* package */ static class KeyDrawParams {
// XML attributes
public final int mKeyTextColor;
public final int mKeyTextInactivatedColor;
@ -283,7 +283,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
protected static class KeyPreviewDrawParams {
/* package */ static class KeyPreviewDrawParams {
// XML attributes.
public final Drawable mPreviewBackground;
public final Drawable mPreviewLeftBackground;
@ -474,7 +474,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
if (mKeyboard == null) return;
final boolean isManualTemporaryUpperCase = mKeyboard.isManualTemporaryUpperCase();
final KeyDrawParams params = mKeyDrawParams;
if (mInvalidatedKey != null && mInvalidatedKeyRect.contains(mDirtyRect)) {
// Draw a single key.
@ -482,8 +481,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
+ getPaddingLeft();
final int keyDrawY = mInvalidatedKey.mY + getPaddingTop();
canvas.translate(keyDrawX, keyDrawY);
onBufferDrawKey(mInvalidatedKey, mKeyboard, canvas, mPaint, params,
isManualTemporaryUpperCase);
onDrawKey(mInvalidatedKey, canvas, mPaint, params);
canvas.translate(-keyDrawX, -keyDrawY);
} else {
// Draw all keys.
@ -491,7 +489,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final int keyDrawX = key.mX + key.mVisualInsetsLeft + getPaddingLeft();
final int keyDrawY = key.mY + getPaddingTop();
canvas.translate(keyDrawX, keyDrawY);
onBufferDrawKey(key, mKeyboard, canvas, mPaint, params, isManualTemporaryUpperCase);
onDrawKey(key, canvas, mPaint, params);
canvas.translate(-keyDrawX, -keyDrawY);
}
}
@ -514,11 +512,14 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
private static void onBufferDrawKey(final Key key, final Keyboard keyboard, final Canvas canvas,
Paint paint, KeyDrawParams params, boolean isManualTemporaryUpperCase) {
final boolean debugShowAlign = LatinImeLogger.sVISUALDEBUG;
private void onDrawKey(Key key, Canvas canvas, Paint paint, KeyDrawParams params) {
if (key.isSpacer()) return;
onDrawKeyBackground(key, canvas, params);
onDrawKeyTopVisuals(key, canvas, paint, params);
}
// Draw key background.
if (!key.isSpacer()) {
/* package */ void onDrawKeyBackground(Key key, Canvas canvas, KeyDrawParams params) {
final int bgWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight
+ params.mPadding.left + params.mPadding.right;
final int bgHeight = key.mHeight + params.mPadding.top + params.mPadding.bottom;
@ -533,19 +534,21 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
canvas.translate(bgX, bgY);
background.draw(canvas);
if (debugShowAlign) {
if (LatinImeLogger.sVISUALDEBUG) {
drawRectangle(canvas, 0, 0, bgWidth, bgHeight, 0x80c00000, new Paint());
}
canvas.translate(-bgX, -bgY);
}
// Draw key top visuals.
/* package */ void onDrawKeyTopVisuals(Key key, Canvas canvas, Paint paint,
KeyDrawParams params) {
final int keyWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
final int keyHeight = key.mHeight;
final float centerX = keyWidth * 0.5f;
final float centerY = keyHeight * 0.5f;
if (debugShowAlign) {
if (LatinImeLogger.sVISUALDEBUG) {
drawRectangle(canvas, 0, 0, keyWidth, keyHeight, 0x800000c0, new Paint());
}
@ -554,7 +557,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
float positionX = centerX;
if (key.mLabel != null) {
// Switch the character to uppercase if shift is pressed
final CharSequence label = keyboard.adjustLabelCase(key.mLabel);
final CharSequence label = mKeyboard.adjustLabelCase(key.mLabel);
// For characters, use large font. For labels like "Done", use smaller font.
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
final int labelSize = key.selectTextSize(params.mKeyLetterSize,
@ -597,7 +600,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint)));
}
if (key.hasUppercaseLetter() && isManualTemporaryUpperCase) {
if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) {
paint.setColor(params.mKeyTextInactivatedColor);
} else {
paint.setColor(params.mKeyTextColor);
@ -627,7 +630,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
}
if (debugShowAlign) {
if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint();
drawHorizontalLine(canvas, baseline, keyWidth, 0xc0008000, line);
drawVerticalLine(canvas, positionX, keyHeight, 0xc0800080, line);
@ -644,7 +647,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintSize = params.mKeyHintLabelSize;
paint.setTypeface(Typeface.DEFAULT);
} else if (key.hasUppercaseLetter()) {
hintColor = isManualTemporaryUpperCase
hintColor = mKeyboard.isManualTemporaryUpperCase()
? params.mKeyUppercaseLetterActivatedColor
: params.mKeyUppercaseLetterInactivatedColor;
hintSize = params.mKeyUppercaseLetterSize;
@ -677,7 +680,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
canvas.drawText(hint, 0, hint.length(), hintX, hintY, paint);
if (debugShowAlign) {
if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint();
drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line);
drawVerticalLine(canvas, (int)hintX, keyHeight, 0xc0808000, line);
@ -702,16 +705,24 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
if (debugShowAlign) {
if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint();
drawVerticalLine(canvas, alignX, keyHeight, 0xc0800080, line);
drawRectangle(canvas, iconX, iconY, iconWidth, iconHeight, 0x80c00000, line);
}
}
// Draw popup hint "..." at the bottom right corner of the key.
if ((key.hasPopupHint() && key.mMoreKeys != null && key.mMoreKeys.length > 0)
|| key.needsSpecialPopupHint()) {
drawKeyPopupHint(key, canvas, paint, params);
}
}
// Draw popup hint "..." at the bottom right corner of the key.
/* package */ void drawKeyPopupHint(Key key, Canvas canvas, Paint paint, KeyDrawParams params) {
final int keyWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
final int keyHeight = key.mHeight;
paint.setTextSize(params.mKeyHintLetterSize);
paint.setColor(params.mKeyHintLabelColor);
paint.setTextAlign(Align.CENTER);
@ -720,13 +731,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final float hintY = keyHeight - params.mKeyPopupHintLetterPadding;
canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint);
if (debugShowAlign) {
if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint();
drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line);
drawVerticalLine(canvas, (int)hintX, keyHeight, 0xc0808000, line);
}
}
}
private static final Rect sTextBounds = new Rect();