aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-05-27 18:43:28 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-05-27 18:43:28 -0700
commit6ca8675ab4a2f1bf876f27e5ac8d3ea75ecf6166 (patch)
tree786bf8c17d5d8cbd86615af31712f3421a216c9b /java/src
parentd0a88868ca96e466b53efd0154d36f0a8bf91bf4 (diff)
parent6b38a5fd4c7697c962bff9f3964f20e00c470b1b (diff)
downloadlatinime-6ca8675ab4a2f1bf876f27e5ac8d3ea75ecf6166.tar.gz
latinime-6ca8675ab4a2f1bf876f27e5ac8d3ea75ecf6166.tar.xz
latinime-6ca8675ab4a2f1bf876f27e5ac8d3ea75ecf6166.zip
am 6b38a5fd: Adaptive keyboard width/position parser (DO NOT MERGE)
* commit '6b38a5fd4c7697c962bff9f3964f20e00c470b1b': Adaptive keyboard width/position parser (DO NOT MERGE)
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java49
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardParser.java40
3 files changed, 71 insertions, 24 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 8eadf4ba4..eccd0c822 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -16,10 +16,6 @@
package com.android.inputmethod.keyboard;
-import com.android.inputmethod.keyboard.KeyStyles.KeyStyle;
-import com.android.inputmethod.keyboard.KeyboardParser.ParseException;
-import com.android.inputmethod.latin.R;
-
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -27,6 +23,10 @@ import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Xml;
+import com.android.inputmethod.keyboard.KeyStyles.KeyStyle;
+import com.android.inputmethod.keyboard.KeyboardParser.ParseException;
+import com.android.inputmethod.latin.R;
+
import java.util.ArrayList;
/**
@@ -137,7 +137,7 @@ public class Key {
};
/**
- * This constructor is being used only for key in mini popup keyboard.
+ * This constructor is being used only for key in popup mini keyboard.
*/
public Key(Resources res, Keyboard keyboard, CharSequence popupCharacter, int x, int y,
int width, int height, int edgeFlags) {
@@ -174,6 +174,7 @@ public class Key {
* @param x the x coordinate of the top-left
* @param y the y coordinate of the top-left
* @param parser the XML parser containing the attributes for this key
+ * @param keyStyles active key styles set
*/
public Key(Resources res, Row row, int x, int y, XmlResourceParser parser,
KeyStyles keyStyles) {
@@ -181,6 +182,7 @@ public class Key {
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
+ int keyWidth;
try {
mHeight = KeyboardParser.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight,
@@ -188,17 +190,13 @@ public class Key {
mGap = KeyboardParser.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_horizontalGap,
mKeyboard.getDisplayWidth(), row.mDefaultHorizontalGap);
- mWidth = KeyboardParser.getDimensionOrFraction(keyboardAttr,
+ keyWidth = KeyboardParser.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyWidth,
- mKeyboard.getDisplayWidth(), row.mDefaultWidth) - mGap;
+ mKeyboard.getDisplayWidth(), row.mDefaultWidth);
} finally {
keyboardAttr.recycle();
}
- // Horizontal gap is divided equally to both sides of the key.
- mX = x + mGap / 2;
- mY = y;
-
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
try {
@@ -212,6 +210,35 @@ public class Key {
style = keyStyles.getEmptyKeyStyle();
}
+ final int keyboardWidth = mKeyboard.getDisplayWidth();
+ int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_keyXPos, keyboardWidth, x);
+ if (keyXPos < 0) {
+ // If keyXPos is negative, the actual x-coordinate will be k + keyXPos.
+ keyXPos += keyboardWidth;
+ if (keyXPos < x) {
+ // keyXPos shouldn't be less than x because drawable area for this key starts
+ // at x. Or, this key will overlaps the adjacent key on its left hand side.
+ keyXPos = x;
+ }
+ }
+ if (keyWidth == 0) {
+ // If keyWidth is zero, the actual key width will be determined to fill out the
+ // area up to the right edge of the keyboard.
+ keyWidth = keyboardWidth - keyXPos;
+ } else if (keyWidth < 0) {
+ // If keyWidth is negative, the actual key width will be determined to fill out the
+ // area between the nearest key on the left hand side and the right edge of the
+ // keyboard.
+ keyXPos = x;
+ keyWidth = keyboardWidth - keyXPos;
+ }
+
+ // Horizontal gap is divided equally to both sides of the key.
+ mX = keyXPos + mGap / 2;
+ mY = y;
+ mWidth = keyWidth - mGap;
+
final CharSequence[] popupCharacters = style.getTextArray(keyAttr,
R.styleable.Keyboard_Key_popupCharacters);
if (res.getBoolean(R.bool.config_digit_popup_characters_enabled)) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index bb2c0e3ba..d0e8b32c3 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -138,19 +138,19 @@ public class KeyboardId {
@Override
public String toString() {
- return String.format("[%s.xml %s %s %s imeAction=%s %s%s%s%s%s%s%s]",
+ return String.format("[%s.xml %s %s %s %s %s%s%s%s%s%s%s]",
mXmlName,
mLocale,
(mOrientation == 1 ? "port" : "land"),
modeName(mMode),
imeOptionsName(mImeAction),
+ colorSchemeName(mColorScheme),
(mWebInput ? " webInput" : ""),
(mPasswordInput ? " passwordInput" : ""),
(mHasSettingsKey ? " hasSettingsKey" : ""),
(mVoiceKeyEnabled ? " voiceKeyEnabled" : ""),
(mHasVoiceKey ? " hasVoiceKey" : ""),
- (mEnableShiftLock ? " enableShiftLock" : ""),
- colorSchemeName(mColorScheme)
+ (mEnableShiftLock ? " enableShiftLock" : "")
);
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
index bc9e8f0a0..308651a9e 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardParser.java
@@ -243,7 +243,7 @@ public class KeyboardParser {
if (TAG_KEY.equals(tag)) {
parseKey(parser, row, keys);
} else if (TAG_SPACER.equals(tag)) {
- parseSpacer(parser, keys);
+ parseSpacer(parser, row, keys);
} else if (TAG_INCLUDE.equals(tag)) {
parseIncludeRowContent(parser, row, keys);
} else if (TAG_SWITCH.equals(tag)) {
@@ -290,19 +290,32 @@ public class KeyboardParser {
}
}
- private void parseSpacer(XmlResourceParser parser, List<Key> keys)
+ private void parseSpacer(XmlResourceParser parser, Row row, List<Key> keys)
throws XmlPullParserException, IOException {
if (keys == null) {
checkEndTag(TAG_SPACER, parser);
} else {
if (DEBUG) Log.d(TAG, String.format("<%s />", TAG_SPACER));
- final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
+ final TypedArray keyboardAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
- final int gap = getDimensionOrFraction(a, R.styleable.Keyboard_horizontalGap,
- mKeyboard.getDisplayWidth(), 0);
- a.recycle();
+ if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap))
+ throw new IllegalAttribute(parser, "horizontalGap");
+ final int defaultWidth = (row != null) ? row.mDefaultWidth : 0;
+ final int keyWidth = getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth,
+ mKeyboard.getDisplayWidth(), defaultWidth);
+ keyboardAttr.recycle();
+
+ final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
+ R.styleable.Keyboard_Key);
+ int keyXPos = KeyboardParser.getDimensionOrFraction(keyAttr,
+ R.styleable.Keyboard_Key_keyXPos, mKeyboard.getDisplayWidth(), mCurrentX);
+ if (keyXPos < 0) {
+ // If keyXPos is negative, the actual x-coordinate will be display_width + keyXPos.
+ keyXPos += mKeyboard.getDisplayWidth();
+ }
+
checkEndTag(TAG_SPACER, parser);
- setSpacer(gap);
+ setSpacer(keyXPos, keyWidth);
}
}
@@ -536,7 +549,7 @@ public class KeyboardParser {
}
private void endKey(Key key) {
- mCurrentX += key.mGap + key.mWidth;
+ mCurrentX = key.mX + key.mGap + key.mWidth;
if (mCurrentX > mMaxRowWidth)
mMaxRowWidth = mCurrentX;
}
@@ -545,8 +558,8 @@ public class KeyboardParser {
mTotalHeight = mCurrentY - defaultVerticalGap;
}
- private void setSpacer(int gap) {
- mCurrentX += gap;
+ private void setSpacer(int keyXPos, int width) {
+ mCurrentX = keyXPos + width;
}
public static int getDimensionOrFraction(TypedArray a, int index, int base, int defValue) {
@@ -584,6 +597,13 @@ public class KeyboardParser {
}
@SuppressWarnings("serial")
+ private static class IllegalAttribute extends ParseException {
+ public IllegalAttribute(XmlResourceParser parser, String attribute) {
+ super("Tag " + parser.getName() + " has illegal attribute " + attribute, parser);
+ }
+ }
+
+ @SuppressWarnings("serial")
private static class NonEmptyTag extends ParseException {
public NonEmptyTag(String tag, XmlResourceParser parser) {
super(tag + " must be empty tag", parser);