Remove {max,min}keyboardHeight attribute from Keyboard

This change removes a DisplayMetrics reference from KeyboardBuilder.

Change-Id: I512694274e69e5281d5be47c3f938bcfd6571152
main
Tadashi G. Takaoka 2013-01-29 16:11:52 +09:00
parent 56012e5ab9
commit 17dae3057c
6 changed files with 52 additions and 49 deletions

View File

@ -173,13 +173,6 @@
<attr name="themeId" format="integer" />
<!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" />
<!-- Default keyboard height -->
<attr name="keyboardHeight" format="dimension|fraction" />
<!-- Maximum keyboard height, in pixels or percentage of display height -->
<attr name="maxKeyboardHeight" format="dimension|fraction" />
<!-- Minimum keyboard height represented in pixels, percentage of display height if fraction
is positive, or percentage of display width if fraction is negative. -->
<attr name="minKeyboardHeight" format="dimension|fraction" />
<!-- Keyboard top, bottom, both horizontal edges paddings. -->
<attr name="keyboardTopPadding" format="dimension|fraction" />
<attr name="keyboardBottomPadding" format="dimension|fraction" />

View File

@ -21,9 +21,6 @@
<item name="themeId">0</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_default</item>
<item name="rowHeight">25%p</item>
<item name="keyboardHeight">@dimen/keyboardHeight</item>
<item name="maxKeyboardHeight">@fraction/maxKeyboardHeight</item>
<item name="minKeyboardHeight">@fraction/minKeyboardHeight</item>
<item name="moreKeysTemplate">@xml/kbd_more_keys_keyboard_template</item>
<item name="keyboardTopPadding">@fraction/keyboard_top_padding</item>
<item name="keyboardBottomPadding">@fraction/keyboard_bottom_padding</item>

View File

@ -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" : ""),

View File

@ -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<ElementParams> 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")

View File

@ -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),

View File

@ -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<KP extends KeyboardParams> {
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<KP extends KeyboardParams> {
mContext = context;
final Resources res = context.getResources();
mResources = res;
mDisplayMetrics = res.getDisplayMetrics();
mParams = params;
@ -232,39 +228,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
}
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);