Clean up some MiniKeyboard.Builder code
Change-Id: I5832421cab3d496d4bb8a5e9902d0b5f4929fd0bmain
parent
a9311741b8
commit
2315bfc7c8
|
@ -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 float getCharHeight(Paint paint) {
|
||||
|
@ -733,6 +724,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
|||
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,
|
||||
int height) {
|
||||
canvas.translate(x, y);
|
||||
|
|
|
@ -236,8 +236,7 @@ public class MiniKeyboard extends Keyboard {
|
|||
private static int getMaxKeyWidth(KeyboardView view, CharSequence[] popupCharacters,
|
||||
int minKeyWidth) {
|
||||
Paint paint = null;
|
||||
Rect bounds = null;
|
||||
int maxWidth = 0;
|
||||
int maxWidth = minKeyWidth;
|
||||
for (CharSequence popupSpec : popupCharacters) {
|
||||
final CharSequence label = PopupCharactersParser.getLabel(popupSpec.toString());
|
||||
// If the label is single letter, minKeyWidth is enough to hold
|
||||
|
@ -247,18 +246,15 @@ public class MiniKeyboard extends Keyboard {
|
|||
paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
}
|
||||
final int labelSize = view.getDefaultLabelSizeAndSetPaint(paint);
|
||||
paint.setTextSize(labelSize);
|
||||
if (bounds == null)
|
||||
bounds = new Rect();
|
||||
paint.getTextBounds(label.toString(), 0, label.length(), bounds);
|
||||
if (maxWidth < bounds.width())
|
||||
maxWidth = bounds.width();
|
||||
final int width = (int)view.getDefaultLabelWidth(label, paint);
|
||||
if (maxWidth < width) {
|
||||
maxWidth = width;
|
||||
}
|
||||
}
|
||||
}
|
||||
final int horizontalPadding = (int) view.getContext().getResources()
|
||||
.getDimension(R.dimen.mini_keyboard_key_horizontal_padding);
|
||||
return Math.max(minKeyWidth, maxWidth + horizontalPadding);
|
||||
return maxWidth + horizontalPadding;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue