Refactor KeyboardView constructor
Change-Id: I1fd869c180c6c9f966936fce90bc031bc7824983main
parent
d157834345
commit
bdd9341f61
|
@ -58,14 +58,22 @@ import java.util.WeakHashMap;
|
||||||
* A view that renders a virtual {@link Keyboard}. It handles rendering of keys and detecting key
|
* A view that renders a virtual {@link Keyboard}. It handles rendering of keys and detecting key
|
||||||
* presses and touch movements.
|
* presses and touch movements.
|
||||||
*
|
*
|
||||||
|
* @attr ref R.styleable#KeyboardView_backgroundDimAmount
|
||||||
|
* @attr ref R.styleable#KeyboardView_colorScheme
|
||||||
* @attr ref R.styleable#KeyboardView_keyBackground
|
* @attr ref R.styleable#KeyboardView_keyBackground
|
||||||
|
* @attr ref R.styleable#KeyboardView_keyHysteresisDistance
|
||||||
|
* @attr ref R.styleable#KeyboardView_keyLetterRatio
|
||||||
|
* @attr ref R.styleable#KeyboardView_keyLetterStyle
|
||||||
* @attr ref R.styleable#KeyboardView_keyPreviewLayout
|
* @attr ref R.styleable#KeyboardView_keyPreviewLayout
|
||||||
* @attr ref R.styleable#KeyboardView_keyPreviewOffset
|
* @attr ref R.styleable#KeyboardView_keyPreviewOffset
|
||||||
* @attr ref R.styleable#KeyboardView_labelTextSize
|
* @attr ref R.styleable#KeyboardView_keyPreviewHeight
|
||||||
* @attr ref R.styleable#KeyboardView_keyTextSize
|
|
||||||
* @attr ref R.styleable#KeyboardView_keyTextColor
|
* @attr ref R.styleable#KeyboardView_keyTextColor
|
||||||
|
* @attr ref R.styleable#KeyboardView_keyTextColorDisabled
|
||||||
|
* @attr ref R.styleable#KeyboardView_labelTextRatio
|
||||||
* @attr ref R.styleable#KeyboardView_verticalCorrection
|
* @attr ref R.styleable#KeyboardView_verticalCorrection
|
||||||
* @attr ref R.styleable#KeyboardView_popupLayout
|
* @attr ref R.styleable#KeyboardView_popupLayout
|
||||||
|
* @attr ref R.styleable#KeyboardView_shadowColor
|
||||||
|
* @attr ref R.styleable#KeyboardView_shadowRadius
|
||||||
*/
|
*/
|
||||||
public class KeyboardView extends View implements PointerTracker.UIProxy {
|
public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
private static final String TAG = KeyboardView.class.getSimpleName();
|
private static final String TAG = KeyboardView.class.getSimpleName();
|
||||||
|
@ -86,26 +94,26 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1;
|
private static final int HINT_ICON_VERTICAL_ADJUSTMENT_PIXEL = -1;
|
||||||
|
|
||||||
// XML attribute
|
// XML attribute
|
||||||
private float mKeyLetterRatio;
|
private final float mKeyLetterRatio;
|
||||||
private int mKeyLetterSize;
|
private final int mKeyTextColor;
|
||||||
private int mKeyTextColor;
|
private final int mKeyTextColorDisabled;
|
||||||
private int mKeyTextColorDisabled;
|
private final Typeface mKeyLetterStyle;
|
||||||
private Typeface mKeyLetterStyle = Typeface.DEFAULT;
|
private final float mLabelTextRatio;
|
||||||
private float mLabelTextRatio;
|
private final int mColorScheme;
|
||||||
private int mLabelTextSize;
|
private final int mShadowColor;
|
||||||
private int mColorScheme = COLOR_SCHEME_WHITE;
|
private final float mShadowRadius;
|
||||||
private int mShadowColor;
|
private final Drawable mKeyBackground;
|
||||||
private float mShadowRadius;
|
private final float mBackgroundDimAmount;
|
||||||
private Drawable mKeyBackground;
|
private final float mKeyHysteresisDistance;
|
||||||
private float mBackgroundDimAmount;
|
private final float mVerticalCorrection;
|
||||||
private float mKeyHysteresisDistance;
|
private final int mPreviewOffset;
|
||||||
private float mVerticalCorrection;
|
private final int mPreviewHeight;
|
||||||
private int mPreviewOffset;
|
private final int mPopupLayout;
|
||||||
private int mPreviewHeight;
|
|
||||||
private int mPopupLayout;
|
|
||||||
|
|
||||||
// Main keyboard
|
// Main keyboard
|
||||||
private Keyboard mKeyboard;
|
private Keyboard mKeyboard;
|
||||||
|
private int mKeyLetterSize;
|
||||||
|
private int mLabelTextSize;
|
||||||
|
|
||||||
// Key preview
|
// Key preview
|
||||||
private boolean mInForeground;
|
private boolean mInForeground;
|
||||||
|
@ -303,66 +311,28 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
|
|
||||||
final TypedArray a = context.obtainStyledAttributes(
|
final TypedArray a = context.obtainStyledAttributes(
|
||||||
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
||||||
int previewLayout = 0;
|
|
||||||
int keyTextSize = 0;
|
|
||||||
|
|
||||||
int n = a.getIndexCount();
|
mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
|
||||||
|
mKeyHysteresisDistance = a.getDimensionPixelOffset(
|
||||||
for (int i = 0; i < n; i++) {
|
R.styleable.KeyboardView_keyHysteresisDistance, 0);
|
||||||
int attr = a.getIndex(i);
|
mVerticalCorrection = a.getDimensionPixelOffset(
|
||||||
|
R.styleable.KeyboardView_verticalCorrection, 0);
|
||||||
switch (attr) {
|
final int previewLayout = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
|
||||||
case R.styleable.KeyboardView_keyBackground:
|
mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0);
|
||||||
mKeyBackground = a.getDrawable(attr);
|
mPreviewHeight = a.getDimensionPixelSize(R.styleable.KeyboardView_keyPreviewHeight, 80);
|
||||||
break;
|
mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio);
|
||||||
case R.styleable.KeyboardView_keyHysteresisDistance:
|
mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000);
|
||||||
mKeyHysteresisDistance = a.getDimensionPixelOffset(attr, 0);
|
mKeyTextColorDisabled = a.getColor(
|
||||||
break;
|
R.styleable.KeyboardView_keyTextColorDisabled, 0xFF000000);
|
||||||
case R.styleable.KeyboardView_verticalCorrection:
|
mLabelTextRatio = getRatio(a, R.styleable.KeyboardView_labelTextRatio);
|
||||||
mVerticalCorrection = a.getDimensionPixelOffset(attr, 0);
|
mPopupLayout = a.getResourceId(R.styleable.KeyboardView_popupLayout, 0);
|
||||||
break;
|
mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0);
|
||||||
case R.styleable.KeyboardView_keyPreviewLayout:
|
mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f);
|
||||||
previewLayout = a.getResourceId(attr, 0);
|
// TODO: Use Theme (android.R.styleable.Theme_backgroundDimAmount)
|
||||||
break;
|
mBackgroundDimAmount = a.getFloat(R.styleable.KeyboardView_backgroundDimAmount, 0.5f);
|
||||||
case R.styleable.KeyboardView_keyPreviewOffset:
|
mKeyLetterStyle = Typeface.defaultFromStyle(
|
||||||
mPreviewOffset = a.getDimensionPixelOffset(attr, 0);
|
a.getInt(R.styleable.KeyboardView_keyLetterStyle, Typeface.NORMAL));
|
||||||
break;
|
mColorScheme = a.getInt(R.styleable.KeyboardView_colorScheme, COLOR_SCHEME_WHITE);
|
||||||
case R.styleable.KeyboardView_keyPreviewHeight:
|
|
||||||
mPreviewHeight = a.getDimensionPixelSize(attr, 80);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_keyLetterRatio:
|
|
||||||
mKeyLetterRatio = getRatio(a, attr);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_keyTextColor:
|
|
||||||
mKeyTextColor = a.getColor(attr, 0xFF000000);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_keyTextColorDisabled:
|
|
||||||
mKeyTextColorDisabled = a.getColor(attr, 0xFF000000);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_labelTextRatio:
|
|
||||||
mLabelTextRatio = getRatio(a, attr);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_popupLayout:
|
|
||||||
mPopupLayout = a.getResourceId(attr, 0);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_shadowColor:
|
|
||||||
mShadowColor = a.getColor(attr, 0);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_shadowRadius:
|
|
||||||
mShadowRadius = a.getFloat(attr, 0f);
|
|
||||||
break;
|
|
||||||
// TODO: Use Theme (android.R.styleable.Theme_backgroundDimAmount)
|
|
||||||
case R.styleable.KeyboardView_backgroundDimAmount:
|
|
||||||
mBackgroundDimAmount = a.getFloat(attr, 0.5f);
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_keyLetterStyle:
|
|
||||||
mKeyLetterStyle = Typeface.defaultFromStyle(a.getInt(attr, Typeface.NORMAL));
|
|
||||||
break;
|
|
||||||
case R.styleable.KeyboardView_colorScheme:
|
|
||||||
mColorScheme = a.getInt(attr, COLOR_SCHEME_WHITE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
|
|
||||||
|
@ -379,7 +349,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setTextSize(keyTextSize);
|
|
||||||
mPaint.setTextAlign(Align.CENTER);
|
mPaint.setTextAlign(Align.CENTER);
|
||||||
mPaint.setAlpha(255);
|
mPaint.setAlpha(255);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue