am 83f173cc: Merge "Remove {max,min}keyboardHeight attribute from Keyboard"

# Via Android (Google) Code Review (1) and Tadashi G. Takaoka (1)
* commit '83f173cccd4cd6be0a9ab56ac2d199625ec03525':
  Remove {max,min}keyboardHeight attribute from Keyboard
main
Tadashi G. Takaoka 2013-01-29 01:36:23 -08:00 committed by Android Git Automerger
commit c6be8b5d8d
6 changed files with 52 additions and 49 deletions

View File

@ -173,13 +173,6 @@
<attr name="themeId" format="integer" /> <attr name="themeId" format="integer" />
<!-- Touch position correction --> <!-- Touch position correction -->
<attr name="touchPositionCorrectionData" format="reference" /> <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. --> <!-- Keyboard top, bottom, both horizontal edges paddings. -->
<attr name="keyboardTopPadding" format="dimension|fraction" /> <attr name="keyboardTopPadding" format="dimension|fraction" />
<attr name="keyboardBottomPadding" format="dimension|fraction" /> <attr name="keyboardBottomPadding" format="dimension|fraction" />

View File

@ -21,9 +21,6 @@
<item name="themeId">0</item> <item name="themeId">0</item>
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_default</item> <item name="touchPositionCorrectionData">@array/touch_position_correction_data_default</item>
<item name="rowHeight">25%p</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="moreKeysTemplate">@xml/kbd_more_keys_keyboard_template</item>
<item name="keyboardTopPadding">@fraction/keyboard_top_padding</item> <item name="keyboardTopPadding">@fraction/keyboard_top_padding</item>
<item name="keyboardBottomPadding">@fraction/keyboard_bottom_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 static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
import android.content.res.Configuration;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
@ -62,8 +63,10 @@ public final class KeyboardId {
public final InputMethodSubtype mSubtype; public final InputMethodSubtype mSubtype;
public final Locale mLocale; public final Locale mLocale;
public final int mDeviceFormFactor; public final int mDeviceFormFactor;
// TODO: Remove this member. It is used only for logging purpose.
public final int mOrientation; public final int mOrientation;
public final int mWidth; public final int mWidth;
public final int mHeight;
public final int mMode; public final int mMode;
public final int mElementId; public final int mElementId;
private final EditorInfo mEditorInfo; private final EditorInfo mEditorInfo;
@ -81,7 +84,8 @@ public final class KeyboardId {
mLocale = SubtypeLocale.getSubtypeLocale(mSubtype); mLocale = SubtypeLocale.getSubtypeLocale(mSubtype);
mDeviceFormFactor = params.mDeviceFormFactor; mDeviceFormFactor = params.mDeviceFormFactor;
mOrientation = params.mOrientation; mOrientation = params.mOrientation;
mWidth = params.mWidth; mWidth = params.mKeyboardWidth;
mHeight = params.mKeyboardHeight;
mMode = params.mMode; mMode = params.mMode;
mElementId = elementId; mElementId = elementId;
mEditorInfo = params.mEditorInfo; mEditorInfo = params.mEditorInfo;
@ -108,6 +112,7 @@ public final class KeyboardId {
id.mElementId, id.mElementId,
id.mMode, id.mMode,
id.mWidth, id.mWidth,
id.mHeight,
id.passwordInput(), id.passwordInput(),
id.mClobberSettingsKey, id.mClobberSettingsKey,
id.mShortcutKeyEnabled, id.mShortcutKeyEnabled,
@ -130,6 +135,7 @@ public final class KeyboardId {
&& other.mElementId == mElementId && other.mElementId == mElementId
&& other.mMode == mMode && other.mMode == mMode
&& other.mWidth == mWidth && other.mWidth == mWidth
&& other.mHeight == mHeight
&& other.passwordInput() == passwordInput() && other.passwordInput() == passwordInput()
&& other.mClobberSettingsKey == mClobberSettingsKey && other.mClobberSettingsKey == mClobberSettingsKey
&& other.mShortcutKeyEnabled == mShortcutKeyEnabled && other.mShortcutKeyEnabled == mShortcutKeyEnabled
@ -187,11 +193,13 @@ public final class KeyboardId {
@Override @Override
public String toString() { 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), elementIdToName(mElementId),
mLocale, mLocale,
mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET), mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
deviceFormFactor(mDeviceFormFactor), (mOrientation == 1 ? "port" : "land"), mWidth, deviceFormFactor(mDeviceFormFactor), orientation, mWidth, mHeight,
modeName(mMode), modeName(mMode),
imeAction(), imeAction(),
(navigateNext() ? "navigateNext" : ""), (navigateNext() ? "navigateNext" : ""),

View File

@ -28,9 +28,11 @@ import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.Xml; import android.util.Xml;
import android.view.ViewDebug.HierarchyTraceType;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype; 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.InputTypeUtils;
import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.ResourceUtils;
import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SubtypeLocale;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.XmlParseUtils; import com.android.inputmethod.latin.XmlParseUtils;
@ -106,7 +109,8 @@ public final class KeyboardLayoutSet {
InputMethodSubtype mSubtype; InputMethodSubtype mSubtype;
int mDeviceFormFactor; int mDeviceFormFactor;
int mOrientation; int mOrientation;
int mWidth; int mKeyboardWidth;
int mKeyboardHeight;
// Sparse array of KeyboardLayoutSet element parameters indexed by element's id. // Sparse array of KeyboardLayoutSet element parameters indexed by element's id.
final SparseArray<ElementParams> mKeyboardLayoutSetElementIdToParamsMap = final SparseArray<ElementParams> mKeyboardLayoutSetElementIdToParamsMap =
CollectionUtils.newSparseArray(); CollectionUtils.newSparseArray();
@ -214,15 +218,43 @@ public final class KeyboardLayoutSet {
mPackageName, NO_SETTINGS_KEY, mEditorInfo); mPackageName, NO_SETTINGS_KEY, mEditorInfo);
} }
public Builder setScreenGeometry(final int deviceFormFactor, final int orientation, public Builder setScreenGeometry(final int deviceFormFactor, final int widthPixels,
final int widthPixels) { final int heightPixels) {
final Params params = mParams; final Params params = mParams;
params.mDeviceFormFactor = deviceFormFactor; params.mDeviceFormFactor = deviceFormFactor;
params.mOrientation = orientation; params.mOrientation = (heightPixels > widthPixels)
params.mWidth = widthPixels; ? Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE;
setDefaultKeyboardSize(widthPixels, heightPixels);
return this; 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) { public Builder setSubtype(final InputMethodSubtype subtype) {
final boolean asciiCapable = subtype.containsExtraValueKey(ASCII_CAPABLE); final boolean asciiCapable = subtype.containsExtraValueKey(ASCII_CAPABLE);
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -20,6 +20,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -140,8 +141,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
mThemeContext, editorInfo); mThemeContext, editorInfo);
final Resources res = mThemeContext.getResources(); final Resources res = mThemeContext.getResources();
final DisplayMetrics dm = res.getDisplayMetrics();
builder.setScreenGeometry(res.getInteger(R.integer.config_device_form_factor), 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.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
builder.setOptions( builder.setOptions(
settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyEnabled(editorInfo),

View File

@ -20,9 +20,7 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.content.res.XmlResourceParser; import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.util.Xml; import android.util.Xml;
@ -138,7 +136,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
protected final KP mParams; protected final KP mParams;
protected final Context mContext; protected final Context mContext;
protected final Resources mResources; protected final Resources mResources;
private final DisplayMetrics mDisplayMetrics;
private int mCurrentY = 0; private int mCurrentY = 0;
private KeyboardRow mCurrentRow = null; private KeyboardRow mCurrentRow = null;
@ -150,7 +147,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
mContext = context; mContext = context;
final Resources res = context.getResources(); final Resources res = context.getResources();
mResources = res; mResources = res;
mDisplayMetrics = res.getDisplayMetrics();
mParams = params; mParams = params;
@ -232,39 +228,14 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
} }
private void parseKeyboardAttributes(final XmlPullParser parser) { private void parseKeyboardAttributes(final XmlPullParser parser) {
final int displayWidth = mDisplayMetrics.widthPixels;
final TypedArray keyboardAttr = mContext.obtainStyledAttributes( final TypedArray keyboardAttr = mContext.obtainStyledAttributes(
Xml.asAttributeSet(parser), R.styleable.Keyboard, R.attr.keyboardStyle, Xml.asAttributeSet(parser), R.styleable.Keyboard, R.attr.keyboardStyle,
R.style.Keyboard); R.style.Keyboard);
final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser), final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key); R.styleable.Keyboard_Key);
try { 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; final KeyboardParams params = mParams;
// Keyboard height will not exceed maxKeyboardHeight and will not be less than params.mOccupiedHeight = params.mId.mHeight;
// minKeyboardHeight.
params.mOccupiedHeight = (int)Math.max(
Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
params.mOccupiedWidth = params.mId.mWidth; params.mOccupiedWidth = params.mId.mWidth;
params.mTopPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr, params.mTopPadding = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0); R.styleable.Keyboard_keyboardTopPadding, params.mOccupiedHeight, 0);