diff options
Diffstat (limited to 'java/src')
4 files changed, 117 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 4db673a30..a4aa0c1ea 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -237,10 +237,10 @@ public class Key { try { mHeight = KeyboardParser.getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_rowHeight, - keyboard.getKeyboardHeight(), row.mDefaultHeight) - row.mVerticalGap; + keyboard.getKeyboardHeight(), row.mDefaultHeight) - keyboard.getVerticalGap(); mHorizontalGap = KeyboardParser.getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_horizontalGap, - keyboard.getDisplayWidth(), row.mDefaultHorizontalGap); + keyboard.getDisplayWidth(), keyboard.getHorizontalGap()); mVerticalGap = keyboard.getVerticalGap(); keyWidth = KeyboardParser.getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_keyWidth, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java new file mode 100644 index 000000000..58d742003 --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.android.inputmethod.keyboard.internal; + +import android.graphics.drawable.Drawable; + +import com.android.inputmethod.keyboard.Key; +import com.android.inputmethod.keyboard.KeyboardId; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class KeyboardParams { + public KeyboardId mId; + + public int mTotalHeight; + public int mTotalWidth; + + public int mHeight; + public int mWidth; + + public int mTopPadding; + public int mBottomPadding; + public int mHorizontalEdgesPadding; + public int mHorizontalCenterPadding; + + public int mDefaultRowHeight; + public int mDefaultKeyWidth; + public int mHorizontalGap; + public int mVerticalGap; + + public boolean mIsRtlKeyboard; + public int mPopupKeyboardResId; + public int mMaxPopupColumn; + + public int GRID_WIDTH; + public int GRID_HEIGHT; + + public final List<Key> mKeys = new ArrayList<Key>(); + public final List<Key> mShiftKeys = new ArrayList<Key>(); + public final Set<Key> mShiftLockKeys = new HashSet<Key>(); + public final Map<Key, Drawable> mShiftedIcons = new HashMap<Key, Drawable>(); + public final Map<Key, Drawable> mUnshiftedIcons = new HashMap<Key, Drawable>(); + public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); + + public void addShiftKey(Key key) { + if (key == null) return; + mShiftKeys.add(key); + if (key.mSticky) { + mShiftLockKeys.add(key); + } + } + + public void addShiftedIcon(Key key, Drawable icon) { + if (key == null) return; + mUnshiftedIcons.put(key, key.getIcon()); + mShiftedIcons.put(key, icon); + } + + /** + * Compute the most common key width in order to use it as proximity key detection threshold. + * + * @return The most common key width in the keyboard + */ + public int getMostCommonKeyWidth() { + final HashMap<Integer, Integer> histogram = new HashMap<Integer, Integer>(); + int maxCount = 0; + int mostCommonWidth = 0; + for (final Key key : mKeys) { + final Integer width = key.mWidth + key.mHorizontalGap; + Integer count = histogram.get(width); + if (count == null) + count = 0; + histogram.put(width, ++count); + if (count > maxCount) { + maxCount = count; + mostCommonWidth = width; + } + } + return mostCommonWidth; + } +} diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java index ed87029ff..e3238c30c 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -256,7 +256,7 @@ public class KeyboardParser { if (event == XmlPullParser.START_TAG) { final String tag = parser.getName(); if (TAG_ROW.equals(tag)) { - Row row = new Row(mResources, mKeyboard, parser); + Row row = parseRowAttributes(parser); if (DEBUG) Log.d(TAG, String.format("<%s>", TAG_ROW)); if (keys != null) startRow(row); @@ -288,6 +288,20 @@ public class KeyboardParser { } } + private Row parseRowAttributes(XmlResourceParser parser) { + final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser), + R.styleable.Keyboard); + try { + if (a.hasValue(R.styleable.Keyboard_horizontalGap)) + throw new IllegalAttribute(parser, "horizontalGap"); + if (a.hasValue(R.styleable.Keyboard_verticalGap)) + throw new IllegalAttribute(parser, "verticalGap"); + return new Row(mResources, mKeyboard, parser); + } finally { + a.recycle(); + } + } + private void parseRowContent(XmlResourceParser parser, Row row, List<Key> keys) throws XmlPullParserException, IOException { int event; diff --git a/java/src/com/android/inputmethod/keyboard/internal/Row.java b/java/src/com/android/inputmethod/keyboard/internal/Row.java index b34d6d06f..34b8d91b9 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/Row.java +++ b/java/src/com/android/inputmethod/keyboard/internal/Row.java @@ -34,10 +34,6 @@ public class Row { public final int mDefaultWidth; /** Default height of a key in this row. */ public final int mDefaultHeight; - /** Default horizontal gap between keys in this row. */ - public final int mDefaultHorizontalGap; - /** Vertical gap following this row. */ - public final int mVerticalGap; private final Keyboard mKeyboard; @@ -51,10 +47,6 @@ public class Row { R.styleable.Keyboard_keyWidth, keyboardWidth, keyboard.getKeyWidth()); mDefaultHeight = KeyboardParser.getDimensionOrFraction(a, R.styleable.Keyboard_rowHeight, keyboardHeight, keyboard.getRowHeight()); - mDefaultHorizontalGap = KeyboardParser.getDimensionOrFraction(a, - R.styleable.Keyboard_horizontalGap, keyboardWidth, keyboard.getHorizontalGap()); - mVerticalGap = KeyboardParser.getDimensionOrFraction(a, - R.styleable.Keyboard_verticalGap, keyboardHeight, keyboard.getVerticalGap()); a.recycle(); } |