am bc781e96: Can override key drawing methods of KeyboardView

* commit 'bc781e963ff51576109aca9626728d09222cfca7':
  Can override key drawing methods of KeyboardView
main
Tadashi G. Takaoka 2011-12-17 23:17:09 -08:00 committed by Android Git Automerger
commit 87296a0fe2
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 // XML attributes
public final int mKeyTextColor; public final int mKeyTextColor;
public final int mKeyTextInactivatedColor; 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. // XML attributes.
public final Drawable mPreviewBackground; public final Drawable mPreviewBackground;
public final Drawable mPreviewLeftBackground; public final Drawable mPreviewLeftBackground;
@ -474,7 +474,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
if (mKeyboard == null) return; if (mKeyboard == null) return;
final boolean isManualTemporaryUpperCase = mKeyboard.isManualTemporaryUpperCase();
final KeyDrawParams params = mKeyDrawParams; final KeyDrawParams params = mKeyDrawParams;
if (mInvalidatedKey != null && mInvalidatedKeyRect.contains(mDirtyRect)) { if (mInvalidatedKey != null && mInvalidatedKeyRect.contains(mDirtyRect)) {
// Draw a single key. // Draw a single key.
@ -482,8 +481,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
+ getPaddingLeft(); + getPaddingLeft();
final int keyDrawY = mInvalidatedKey.mY + getPaddingTop(); final int keyDrawY = mInvalidatedKey.mY + getPaddingTop();
canvas.translate(keyDrawX, keyDrawY); canvas.translate(keyDrawX, keyDrawY);
onBufferDrawKey(mInvalidatedKey, mKeyboard, canvas, mPaint, params, onDrawKey(mInvalidatedKey, canvas, mPaint, params);
isManualTemporaryUpperCase);
canvas.translate(-keyDrawX, -keyDrawY); canvas.translate(-keyDrawX, -keyDrawY);
} else { } else {
// Draw all keys. // 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 keyDrawX = key.mX + key.mVisualInsetsLeft + getPaddingLeft();
final int keyDrawY = key.mY + getPaddingTop(); final int keyDrawY = key.mY + getPaddingTop();
canvas.translate(keyDrawX, keyDrawY); canvas.translate(keyDrawX, keyDrawY);
onBufferDrawKey(key, mKeyboard, canvas, mPaint, params, isManualTemporaryUpperCase); onDrawKey(key, canvas, mPaint, params);
canvas.translate(-keyDrawX, -keyDrawY); 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, private void onDrawKey(Key key, Canvas canvas, Paint paint, KeyDrawParams params) {
Paint paint, KeyDrawParams params, boolean isManualTemporaryUpperCase) { if (key.isSpacer()) return;
final boolean debugShowAlign = LatinImeLogger.sVISUALDEBUG; onDrawKeyBackground(key, canvas, params);
onDrawKeyTopVisuals(key, canvas, paint, params);
}
// Draw key background. // Draw key background.
if (!key.isSpacer()) { /* package */ void onDrawKeyBackground(Key key, Canvas canvas, KeyDrawParams params) {
final int bgWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight final int bgWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight
+ params.mPadding.left + params.mPadding.right; + params.mPadding.left + params.mPadding.right;
final int bgHeight = key.mHeight + params.mPadding.top + params.mPadding.bottom; 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); canvas.translate(bgX, bgY);
background.draw(canvas); background.draw(canvas);
if (debugShowAlign) { if (LatinImeLogger.sVISUALDEBUG) {
drawRectangle(canvas, 0, 0, bgWidth, bgHeight, 0x80c00000, new Paint()); drawRectangle(canvas, 0, 0, bgWidth, bgHeight, 0x80c00000, new Paint());
} }
canvas.translate(-bgX, -bgY); canvas.translate(-bgX, -bgY);
} }
// Draw key top visuals. // 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 keyWidth = key.mWidth - key.mVisualInsetsLeft - key.mVisualInsetsRight;
final int keyHeight = key.mHeight; final int keyHeight = key.mHeight;
final float centerX = keyWidth * 0.5f; final float centerX = keyWidth * 0.5f;
final float centerY = keyHeight * 0.5f; final float centerY = keyHeight * 0.5f;
if (debugShowAlign) { if (LatinImeLogger.sVISUALDEBUG) {
drawRectangle(canvas, 0, 0, keyWidth, keyHeight, 0x800000c0, new Paint()); drawRectangle(canvas, 0, 0, keyWidth, keyHeight, 0x800000c0, new Paint());
} }
@ -554,7 +557,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
float positionX = centerX; float positionX = centerX;
if (key.mLabel != null) { if (key.mLabel != null) {
// Switch the character to uppercase if shift is pressed // 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. // For characters, use large font. For labels like "Done", use smaller font.
paint.setTypeface(key.selectTypeface(params.mKeyTextStyle)); paint.setTypeface(key.selectTypeface(params.mKeyTextStyle));
final int labelSize = key.selectTextSize(params.mKeyLetterSize, 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))); Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint)));
} }
if (key.hasUppercaseLetter() && isManualTemporaryUpperCase) { if (key.hasUppercaseLetter() && mKeyboard.isManualTemporaryUpperCase()) {
paint.setColor(params.mKeyTextInactivatedColor); paint.setColor(params.mKeyTextInactivatedColor);
} else { } else {
paint.setColor(params.mKeyTextColor); 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(); final Paint line = new Paint();
drawHorizontalLine(canvas, baseline, keyWidth, 0xc0008000, line); drawHorizontalLine(canvas, baseline, keyWidth, 0xc0008000, line);
drawVerticalLine(canvas, positionX, keyHeight, 0xc0800080, line); drawVerticalLine(canvas, positionX, keyHeight, 0xc0800080, line);
@ -644,7 +647,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
hintSize = params.mKeyHintLabelSize; hintSize = params.mKeyHintLabelSize;
paint.setTypeface(Typeface.DEFAULT); paint.setTypeface(Typeface.DEFAULT);
} else if (key.hasUppercaseLetter()) { } else if (key.hasUppercaseLetter()) {
hintColor = isManualTemporaryUpperCase hintColor = mKeyboard.isManualTemporaryUpperCase()
? params.mKeyUppercaseLetterActivatedColor ? params.mKeyUppercaseLetterActivatedColor
: params.mKeyUppercaseLetterInactivatedColor; : params.mKeyUppercaseLetterInactivatedColor;
hintSize = params.mKeyUppercaseLetterSize; hintSize = params.mKeyUppercaseLetterSize;
@ -677,7 +680,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
canvas.drawText(hint, 0, hint.length(), hintX, hintY, paint); canvas.drawText(hint, 0, hint.length(), hintX, hintY, paint);
if (debugShowAlign) { if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint(); final Paint line = new Paint();
drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line); drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line);
drawVerticalLine(canvas, (int)hintX, keyHeight, 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); drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
if (debugShowAlign) { if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint(); final Paint line = new Paint();
drawVerticalLine(canvas, alignX, keyHeight, 0xc0800080, line); drawVerticalLine(canvas, alignX, keyHeight, 0xc0800080, line);
drawRectangle(canvas, iconX, iconY, iconWidth, iconHeight, 0x80c00000, 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) if ((key.hasPopupHint() && key.mMoreKeys != null && key.mMoreKeys.length > 0)
|| key.needsSpecialPopupHint()) { || 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.setTextSize(params.mKeyHintLetterSize);
paint.setColor(params.mKeyHintLabelColor); paint.setColor(params.mKeyHintLabelColor);
paint.setTextAlign(Align.CENTER); paint.setTextAlign(Align.CENTER);
@ -720,13 +731,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
final float hintY = keyHeight - params.mKeyPopupHintLetterPadding; final float hintY = keyHeight - params.mKeyPopupHintLetterPadding;
canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint); canvas.drawText(POPUP_HINT_CHAR, hintX, hintY, paint);
if (debugShowAlign) { if (LatinImeLogger.sVISUALDEBUG) {
final Paint line = new Paint(); final Paint line = new Paint();
drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line); drawHorizontalLine(canvas, (int)hintY, keyWidth, 0xc0808000, line);
drawVerticalLine(canvas, (int)hintX, keyHeight, 0xc0808000, line); drawVerticalLine(canvas, (int)hintX, keyHeight, 0xc0808000, line);
} }
} }
}
private static final Rect sTextBounds = new Rect(); private static final Rect sTextBounds = new Rect();