summaryrefslogtreecommitdiff
path: root/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2011-09-22 19:29:58 +0900
committerTadashi G. Takaoka <takaoka@google.com>2011-09-26 10:25:49 +0900
commit8fbfac4ffb7079e8e71fd4e3ddc04e362239ebb3 (patch)
treebb7441453c6dff3f98220d3dc3d712905fbc7a25 /java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
parent8d6fd877c5ac11aa0852b5a28bf1a52081ae9157 (diff)
Fix keyboard row height calculation
The keyboard height will be distrubuted as: top_padding + (key_height + vertical_gap) * row_count - vertical_gap + bottom_padding Change-Id: I841f356b9dbf8cfaf3756178bc9e4e6b2aa61364
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java41
1 files changed, 31 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index 593c3dc5b..01f9d3bb1 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -32,11 +32,13 @@ import java.util.Set;
public class KeyboardParams {
public KeyboardId mId;
+ /** Total height and width of the keyboard, including the paddings and keys */
public int mOccupiedHeight;
public int mOccupiedWidth;
- public int mHeight;
- public int mWidth;
+ /** Base height and width of the keyboard used to calculate rows' or keys' heights and widths */
+ public int mBaseHeight;
+ public int mBaseWidth;
public int mTopPadding;
public int mBottomPadding;
@@ -62,6 +64,7 @@ public class KeyboardParams {
public final Map<Key, Drawable> mUnshiftedIcons = new HashMap<Key, Drawable>();
public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet();
+ public int mMostCommonKeyHeight = 0;
public int mMostCommonKeyWidth = 0;
protected void clearKeys() {
@@ -89,21 +92,39 @@ public class KeyboardParams {
mShiftedIcons.put(key, icon);
}
- private int mMaxCount = 0;
- private final Map<Integer, Integer> mHistogram = new HashMap<Integer, Integer>();
+ private int mMaxHeightCount = 0;
+ private int mMaxWidthCount = 0;
+ private final Map<Integer, Integer> mHeightHistogram = new HashMap<Integer, Integer>();
+ private final Map<Integer, Integer> mWidthHistogram = new HashMap<Integer, Integer>();
private void clearHistogram() {
+ mMostCommonKeyHeight = 0;
+ mMaxHeightCount = 0;
+ mHeightHistogram.clear();
+
+ mMaxWidthCount = 0;
mMostCommonKeyWidth = 0;
- mMaxCount = 0;
- mHistogram.clear();
+ mWidthHistogram.clear();
+ }
+
+ private static int updateHistogramCounter(Map<Integer, Integer> histogram, Integer key) {
+ final int count = (histogram.containsKey(key) ? histogram.get(key) : 0) + 1;
+ histogram.put(key, count);
+ return count;
}
private void updateHistogram(Key key) {
+ final Integer height = key.mHeight + key.mVerticalGap;
+ final int heightCount = updateHistogramCounter(mHeightHistogram, height);
+ if (heightCount > mMaxHeightCount) {
+ mMaxHeightCount = heightCount;
+ mMostCommonKeyHeight = height;
+ }
+
final Integer width = key.mWidth + key.mHorizontalGap;
- final int count = (mHistogram.containsKey(width) ? mHistogram.get(width) : 0) + 1;
- mHistogram.put(width, count);
- if (count > mMaxCount) {
- mMaxCount = count;
+ final int widthCount = updateHistogramCounter(mWidthHistogram, width);
+ if (widthCount > mMaxWidthCount) {
+ mMaxWidthCount = widthCount;
mMostCommonKeyWidth = width;
}
}