diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 51a0758e6..5b3898709 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -173,13 +173,6 @@
-
-
-
-
-
-
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index f07f2d352..19d6da86e 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -21,9 +21,6 @@
- 0
- @array/touch_position_correction_data_default
- 25%p
- - @dimen/keyboardHeight
- - @fraction/maxKeyboardHeight
- - @fraction/minKeyboardHeight
- @xml/kbd_more_keys_keyboard_template
- @fraction/keyboard_top_padding
- @fraction/keyboard_bottom_padding
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 4b43bcc5c..ee8ee9a4f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
+import android.content.res.Configuration;
import android.text.InputType;
import android.text.TextUtils;
import android.view.inputmethod.EditorInfo;
@@ -62,8 +63,10 @@ public final class KeyboardId {
public final InputMethodSubtype mSubtype;
public final Locale mLocale;
public final int mDeviceFormFactor;
+ // TODO: Remove this member. It is used only for logging purpose.
public final int mOrientation;
public final int mWidth;
+ public final int mHeight;
public final int mMode;
public final int mElementId;
private final EditorInfo mEditorInfo;
@@ -81,7 +84,8 @@ public final class KeyboardId {
mLocale = SubtypeLocale.getSubtypeLocale(mSubtype);
mDeviceFormFactor = params.mDeviceFormFactor;
mOrientation = params.mOrientation;
- mWidth = params.mWidth;
+ mWidth = params.mKeyboardWidth;
+ mHeight = params.mKeyboardHeight;
mMode = params.mMode;
mElementId = elementId;
mEditorInfo = params.mEditorInfo;
@@ -108,6 +112,7 @@ public final class KeyboardId {
id.mElementId,
id.mMode,
id.mWidth,
+ id.mHeight,
id.passwordInput(),
id.mClobberSettingsKey,
id.mShortcutKeyEnabled,
@@ -130,6 +135,7 @@ public final class KeyboardId {
&& other.mElementId == mElementId
&& other.mMode == mMode
&& other.mWidth == mWidth
+ && other.mHeight == mHeight
&& other.passwordInput() == passwordInput()
&& other.mClobberSettingsKey == mClobberSettingsKey
&& other.mShortcutKeyEnabled == mShortcutKeyEnabled
@@ -187,11 +193,13 @@ public final class KeyboardId {
@Override
public String toString() {
- return String.format("[%s %s:%s %s-%s:%d %s %s %s%s%s%s%s%s%s%s%s]",
+ final String orientation = (mOrientation == Configuration.ORIENTATION_PORTRAIT)
+ ? "port" : "land";
+ return String.format("[%s %s:%s %s-%s:%dx%d %s %s %s%s%s%s%s%s%s%s%s]",
elementIdToName(mElementId),
mLocale,
mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
- deviceFormFactor(mDeviceFormFactor), (mOrientation == 1 ? "port" : "land"), mWidth,
+ deviceFormFactor(mDeviceFormFactor), orientation, mWidth, mHeight,
modeName(mMode),
imeAction(),
(navigateNext() ? "navigateNext" : ""),
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index f060ad083..f28bc9471 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -28,9 +28,11 @@ import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.text.InputType;
+import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.util.Xml;
+import android.view.ViewDebug.HierarchyTraceType;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
@@ -44,6 +46,7 @@ import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.InputTypeUtils;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.ResourceUtils;
import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.XmlParseUtils;
@@ -106,7 +109,8 @@ public final class KeyboardLayoutSet {
InputMethodSubtype mSubtype;
int mDeviceFormFactor;
int mOrientation;
- int mWidth;
+ int mKeyboardWidth;
+ int mKeyboardHeight;
// Sparse array of KeyboardLayoutSet element parameters indexed by element's id.
final SparseArray mKeyboardLayoutSetElementIdToParamsMap =
CollectionUtils.newSparseArray();
@@ -214,15 +218,43 @@ public final class KeyboardLayoutSet {
mPackageName, NO_SETTINGS_KEY, mEditorInfo);
}
- public Builder setScreenGeometry(final int deviceFormFactor, final int orientation,
- final int widthPixels) {
+ public Builder setScreenGeometry(final int deviceFormFactor, final int widthPixels,
+ final int heightPixels) {
final Params params = mParams;
params.mDeviceFormFactor = deviceFormFactor;
- params.mOrientation = orientation;
- params.mWidth = widthPixels;
+ params.mOrientation = (heightPixels > widthPixels)
+ ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
+ setDefaultKeyboardSize(widthPixels, heightPixels);
return this;
}
+ private void setDefaultKeyboardSize(final int widthPixels, final int heightPixels) {
+ final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue(
+ mResources, R.array.keyboard_heights);
+ final float keyboardHeight;
+ if (TextUtils.isEmpty(keyboardHeightString)) {
+ keyboardHeight = mResources.getDimension(R.dimen.keyboardHeight);
+ } else {
+ keyboardHeight = Float.parseFloat(keyboardHeightString)
+ * mResources.getDisplayMetrics().density;
+ }
+ final float maxKeyboardHeight = mResources.getFraction(
+ R.fraction.maxKeyboardHeight, heightPixels, heightPixels);
+ float minKeyboardHeight = mResources.getFraction(
+ R.fraction.minKeyboardHeight, heightPixels, heightPixels);
+ if (minKeyboardHeight < 0.0f) {
+ // Specified fraction was negative, so it should be calculated against display
+ // width.
+ minKeyboardHeight = -mResources.getFraction(
+ R.fraction.minKeyboardHeight, widthPixels, widthPixels);
+ }
+ // Keyboard height will not exceed maxKeyboardHeight and will not be less than
+ // minKeyboardHeight.
+ mParams.mKeyboardHeight = (int)Math.max(
+ Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
+ mParams.mKeyboardWidth = widthPixels;
+ }
+
public Builder setSubtype(final InputMethodSubtype subtype) {
final boolean asciiCapable = subtype.containsExtraValueKey(ASCII_CAPABLE);
@SuppressWarnings("deprecation")
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 30949aea8..d15f14f88 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.preference.PreferenceManager;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@@ -140,8 +141,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
mThemeContext, editorInfo);
final Resources res = mThemeContext.getResources();
+ final DisplayMetrics dm = res.getDisplayMetrics();
builder.setScreenGeometry(res.getInteger(R.integer.config_device_form_factor),
- res.getConfiguration().orientation, res.getDisplayMetrics().widthPixels);
+ dm.widthPixels, dm.heightPixels);
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
builder.setOptions(
settingsValues.isVoiceKeyEnabled(editorInfo),
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 04b8ecba1..802d926ce 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -20,9 +20,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
-import android.text.TextUtils;
import android.util.AttributeSet;
-import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.util.Xml;
@@ -138,7 +136,6 @@ public class KeyboardBuilder {
protected final KP mParams;
protected final Context mContext;
protected final Resources mResources;
- private final DisplayMetrics mDisplayMetrics;
private int mCurrentY = 0;
private KeyboardRow mCurrentRow = null;
@@ -150,7 +147,6 @@ public class KeyboardBuilder {
mContext = context;
final Resources res = context.getResources();
mResources = res;
- mDisplayMetrics = res.getDisplayMetrics();
mParams = params;
@@ -232,39 +228,14 @@ public class KeyboardBuilder {
}
private void parseKeyboardAttributes(final XmlPullParser parser) {
- final int displayWidth = mDisplayMetrics.widthPixels;
final TypedArray keyboardAttr = mContext.obtainStyledAttributes(
Xml.asAttributeSet(parser), R.styleable.Keyboard, R.attr.keyboardStyle,
R.style.Keyboard);
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
try {
- final int displayHeight = mDisplayMetrics.heightPixels;
- final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue(
- mResources, R.array.keyboard_heights);
- final float keyboardHeight;
- if (TextUtils.isEmpty(keyboardHeightString)) {
- keyboardHeight = keyboardAttr.getDimension(
- R.styleable.Keyboard_keyboardHeight, displayHeight / 2);
- } else {
- keyboardHeight = Float.parseFloat(keyboardHeightString)
- * mDisplayMetrics.density;
- }
- final float maxKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr,
- R.styleable.Keyboard_maxKeyboardHeight, displayHeight, displayHeight / 2);
- float minKeyboardHeight = ResourceUtils.getDimensionOrFraction(keyboardAttr,
- R.styleable.Keyboard_minKeyboardHeight, displayHeight, displayHeight / 2);
- if (minKeyboardHeight < 0) {
- // Specified fraction was negative, so it should be calculated against display
- // width.
- minKeyboardHeight = -ResourceUtils.getDimensionOrFraction(keyboardAttr,
- R.styleable.Keyboard_minKeyboardHeight, displayWidth, displayWidth / 2);
- }
final KeyboardParams params = mParams;
- // Keyboard height will not exceed maxKeyboardHeight and will not be less than
- // minKeyboardHeight.
- params.mOccupiedHeight = (int)Math.max(
- Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
+ params.mOccupiedHeight = params.mId.mHeight;
params.mOccupiedWidth = params.mId.mWidth;
params.mTopPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0);