Clean up some MiniKeyboard.Builder code

Change-Id: I5832421cab3d496d4bb8a5e9902d0b5f4929fd0b
main
Tadashi G. Takaoka 2011-08-29 21:12:36 +09:00
parent a9311741b8
commit 2315bfc7c8
2 changed files with 12 additions and 19 deletions

View File

@ -681,15 +681,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
} }
// This method is currently being used only by MiniKeyboardBuilder
public int getDefaultLabelSizeAndSetPaint(Paint paint) {
// For characters, use large font. For labels like "Done", use small font.
final int labelSize = mKeyDrawParams.mKeyLabelSize;
paint.setTextSize(labelSize);
paint.setTypeface(mKeyDrawParams.mKeyTextStyle);
return labelSize;
}
private static final Rect sTextBounds = new Rect(); private static final Rect sTextBounds = new Rect();
private static float getCharHeight(Paint paint) { private static float getCharHeight(Paint paint) {
@ -733,6 +724,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
return sTextBounds.width(); return sTextBounds.width();
} }
public float getDefaultLabelWidth(CharSequence label, Paint paint) {
paint.setTextSize(mKeyDrawParams.mKeyLabelSize);
paint.setTypeface(mKeyDrawParams.mKeyTextStyle);
return getLabelWidth(label, paint);
}
private static void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width, private static void drawIcon(Canvas canvas, Drawable icon, int x, int y, int width,
int height) { int height) {
canvas.translate(x, y); canvas.translate(x, y);

View File

@ -236,8 +236,7 @@ public class MiniKeyboard extends Keyboard {
private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters, private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters,
int minKeyWidth) { int minKeyWidth) {
Paint paint = null; Paint paint = null;
Rect bounds = null; int maxWidth = minKeyWidth;
int maxWidth = 0;
for (CharSequence popupSpec : popupCharacters) { for (CharSequence popupSpec : popupCharacters) {
final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString()); final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString());
// If the label is single letter, minKeyWidth is enough to hold // If the label is single letter, minKeyWidth is enough to hold
@ -247,18 +246,15 @@ public class MiniKeyboard extends Keyboard {
paint = new Paint(); paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
} }
final int labelSize = view.getDefaultLabelSizeAndSetPaint(paint); final int width = (int)view.getDefaultLabelWidth(label, paint);
paint.setTextSize(labelSize); if (maxWidth < width) {
if (bounds == null) maxWidth = width;
bounds = new Rect(); }
paint.getTextBounds(label.toString(), 0, label.length(), bounds);
if (maxWidth < bounds.width())
maxWidth = bounds.width();
} }
} }
final int horizontalPadding = (int) view.getContext().getResources() final int horizontalPadding = (int) view.getContext().getResources()
.getDimension(R.dimen.mini_keyboard_key_horizontal_padding); .getDimension(R.dimen.mini_keyboard_key_horizontal_padding);
return Math.max(minKeyWidth, maxWidth + horizontalPadding); return maxWidth + horizontalPadding;
} }
@Override @Override