diff options
author | 2012-08-28 12:39:28 +0900 | |
---|---|---|
committer | 2012-08-28 16:04:59 +0900 | |
commit | 9fa0736d6ac8a171a5f9620a5d0980dc01dc65a2 (patch) | |
tree | b947734140d8ad602f4b5131976e9ce5c67d081f /java/src | |
parent | ef2bfad5903fb55adca61dbea51984fbc7e4375f (diff) | |
download | latinime-9fa0736d6ac8a171a5f9620a5d0980dc01dc65a2.tar.gz latinime-9fa0736d6ac8a171a5f9620a5d0980dc01dc65a2.tar.xz latinime-9fa0736d6ac8a171a5f9620a5d0980dc01dc65a2.zip |
Consolidate KeyboardView.keyLetterSize and keyLetterRatio
This change also consolidates keyboardView.keyLabelSize and
keyLabelRatio.
Change-Id: I4a45bcb6e7fc104ae4a9ae3ecdae9842d813840e
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardView.java | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index f233a8625..79fe43bfb 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -85,6 +85,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // Miscellaneous constants private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable }; private static final float UNDEFINED_RATIO = -1.0f; + private static final int UNDEFINED_DIMENSION = -1; // XML attributes protected final float mVerticalCorrection; @@ -214,19 +215,15 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { public int mKeyHintLabelSize; public int mAnimAlpha; - public KeyDrawParams(TypedArray a) { + public KeyDrawParams(final TypedArray a) { mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground); - if (a.hasValue(R.styleable.KeyboardView_keyLetterSize)) { - mKeyLetterRatio = UNDEFINED_RATIO; - mKeyLetterSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLetterSize, 0); - } else { - mKeyLetterRatio = getFraction(a, R.styleable.KeyboardView_keyLetterRatio); + if (!isValidFraction(mKeyLetterRatio = getFraction(a, + R.styleable.KeyboardView_keyLetterSize))) { + mKeyLetterSize = getDimensionPixelSize(a, R.styleable.KeyboardView_keyLetterSize); } - if (a.hasValue(R.styleable.KeyboardView_keyLabelSize)) { - mKeyLabelRatio = UNDEFINED_RATIO; - mKeyLabelSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLabelSize, 0); - } else { - mKeyLabelRatio = getFraction(a, R.styleable.KeyboardView_keyLabelRatio); + if (!isValidFraction(mKeyLabelRatio = getFraction(a, + R.styleable.KeyboardView_keyLabelSize))) { + mKeyLabelSize = getDimensionPixelSize(a, R.styleable.KeyboardView_keyLabelSize); } mKeyLargeLabelRatio = getFraction(a, R.styleable.KeyboardView_keyLargeLabelRatio); mKeyLargeLetterRatio = getFraction(a, R.styleable.KeyboardView_keyLargeLetterRatio); @@ -392,9 +389,21 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } static float getFraction(final TypedArray a, final int index) { + final TypedValue value = a.peekValue(index); + if (value == null || value.type != TypedValue.TYPE_FRACTION) { + return UNDEFINED_RATIO; + } return a.getFraction(index, 1, 1, UNDEFINED_RATIO); } + public static int getDimensionPixelSize(final TypedArray a, final int index) { + final TypedValue value = a.peekValue(index); + if (value == null || value.type != TypedValue.TYPE_DIMENSION) { + return UNDEFINED_DIMENSION; + } + return a.getDimensionPixelSize(index, UNDEFINED_DIMENSION); + } + /** * Attaches a keyboard to this view. The keyboard can be switched at any time and the * view will re-layout itself to accommodate the keyboard. |