am 15b80c4e: Merge "Add ResouceUtils.getDefaultKeyboardHeight"
* commit '15b80c4ec264d8fcc457988bc695453093e6f577': Add ResouceUtils.getDefaultKeyboardHeightmain
commit
f6872b3601
|
@ -18,7 +18,6 @@ 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;
|
||||||
|
|
|
@ -23,13 +23,10 @@ import static com.android.inputmethod.latin.Constants.ImeOption.NO_SETTINGS_KEY;
|
||||||
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
|
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
|
||||||
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.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
@ -75,7 +72,7 @@ public final class KeyboardLayoutSet {
|
||||||
|
|
||||||
private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "keyboard_layout_set_";
|
private static final String KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX = "keyboard_layout_set_";
|
||||||
private static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
|
private static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
|
||||||
private static final int SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT = 800;
|
private static final int SPELLCHECKER_DUMMY_KEYBOARD_HEIGHT = 368;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Params mParams;
|
private final Params mParams;
|
||||||
|
@ -240,38 +237,12 @@ public final class KeyboardLayoutSet {
|
||||||
mPackageName, NO_SETTINGS_KEY, mEditorInfo);
|
mPackageName, NO_SETTINGS_KEY, mEditorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setScreenGeometry(final int widthPixels, final int heightPixels) {
|
public Builder setKeyboardGeometry(final int keyboardWidth, final int keyboardHeight) {
|
||||||
setDefaultKeyboardSize(widthPixels, heightPixels);
|
mParams.mKeyboardWidth = keyboardWidth;
|
||||||
|
mParams.mKeyboardHeight = keyboardHeight;
|
||||||
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")
|
||||||
|
@ -450,31 +421,21 @@ public final class KeyboardLayoutSet {
|
||||||
public static KeyboardLayoutSet createKeyboardSetForTest(final Context context,
|
public static KeyboardLayoutSet createKeyboardSetForTest(final Context context,
|
||||||
final InputMethodSubtype subtype, final int orientation,
|
final InputMethodSubtype subtype, final int orientation,
|
||||||
final boolean testCasesHaveTouchCoordinates) {
|
final boolean testCasesHaveTouchCoordinates) {
|
||||||
final DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
final Resources res = context.getResources();
|
||||||
final int width;
|
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
||||||
final int height;
|
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
|
||||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
return createKeyboardSet(context, subtype, keyboardWidth, keyboardHeight,
|
||||||
width = Math.max(dm.widthPixels, dm.heightPixels);
|
testCasesHaveTouchCoordinates, false /* isSpellChecker */);
|
||||||
height = Math.min(dm.widthPixels, dm.heightPixels);
|
|
||||||
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
||||||
width = Math.min(dm.widthPixels, dm.heightPixels);
|
|
||||||
height = Math.max(dm.widthPixels, dm.heightPixels);
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Orientation should be ORIENTATION_LANDSCAPE or "
|
|
||||||
+ "ORIENTATION_PORTRAIT: orientation=" + orientation);
|
|
||||||
}
|
|
||||||
return createKeyboardSet(context, subtype, width, height, testCasesHaveTouchCoordinates,
|
|
||||||
false /* isSpellChecker */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static KeyboardLayoutSet createKeyboardSet(final Context context,
|
private static KeyboardLayoutSet createKeyboardSet(final Context context,
|
||||||
final InputMethodSubtype subtype, final int width, final int height,
|
final InputMethodSubtype subtype, final int keyboardWidth, final int keyboardHeight,
|
||||||
final boolean testCasesHaveTouchCoordinates, final boolean isSpellChecker) {
|
final boolean testCasesHaveTouchCoordinates, final boolean isSpellChecker) {
|
||||||
final EditorInfo editorInfo = new EditorInfo();
|
final EditorInfo editorInfo = new EditorInfo();
|
||||||
editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
|
editorInfo.inputType = InputType.TYPE_CLASS_TEXT;
|
||||||
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
|
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
|
||||||
context, editorInfo);
|
context, editorInfo);
|
||||||
builder.setScreenGeometry(width, height);
|
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
|
||||||
builder.setSubtype(subtype);
|
builder.setSubtype(subtype);
|
||||||
builder.setIsSpellChecker(isSpellChecker);
|
builder.setIsSpellChecker(isSpellChecker);
|
||||||
if (!testCasesHaveTouchCoordinates) {
|
if (!testCasesHaveTouchCoordinates) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ 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;
|
||||||
|
@ -39,6 +38,7 @@ import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||||
import com.android.inputmethod.latin.WordComposer;
|
import com.android.inputmethod.latin.WordComposer;
|
||||||
import com.android.inputmethod.latin.settings.Settings;
|
import com.android.inputmethod.latin.settings.Settings;
|
||||||
import com.android.inputmethod.latin.settings.SettingsValues;
|
import com.android.inputmethod.latin.settings.SettingsValues;
|
||||||
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
||||||
|
|
||||||
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
|
||||||
|
@ -137,8 +137,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();
|
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
|
||||||
builder.setScreenGeometry(dm.widthPixels, dm.heightPixels);
|
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
|
||||||
|
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
|
||||||
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
|
builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
|
||||||
builder.setOptions(
|
builder.setOptions(
|
||||||
settingsValues.isVoiceKeyEnabled(editorInfo),
|
settingsValues.isVoiceKeyEnabled(editorInfo),
|
||||||
|
|
|
@ -20,10 +20,12 @@ import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
|
import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -215,6 +217,35 @@ public final class ResourceUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getDefaultKeyboardWidth(final Resources res) {
|
||||||
|
final DisplayMetrics dm = res.getDisplayMetrics();
|
||||||
|
return dm.widthPixels;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getDefaultKeyboardHeight(final Resources res) {
|
||||||
|
final DisplayMetrics dm = res.getDisplayMetrics();
|
||||||
|
final String keyboardHeightString = getDeviceOverrideValue(res, R.array.keyboard_heights);
|
||||||
|
final float keyboardHeight;
|
||||||
|
if (TextUtils.isEmpty(keyboardHeightString)) {
|
||||||
|
keyboardHeight = res.getDimension(R.dimen.keyboardHeight);
|
||||||
|
} else {
|
||||||
|
keyboardHeight = Float.parseFloat(keyboardHeightString) * dm.density;
|
||||||
|
}
|
||||||
|
final float maxKeyboardHeight = res.getFraction(
|
||||||
|
R.fraction.maxKeyboardHeight, dm.heightPixels, dm.heightPixels);
|
||||||
|
float minKeyboardHeight = res.getFraction(
|
||||||
|
R.fraction.minKeyboardHeight, dm.heightPixels, dm.heightPixels);
|
||||||
|
if (minKeyboardHeight < 0.0f) {
|
||||||
|
// Specified fraction was negative, so it should be calculated against display
|
||||||
|
// width.
|
||||||
|
minKeyboardHeight = -res.getFraction(
|
||||||
|
R.fraction.minKeyboardHeight, dm.widthPixels, dm.widthPixels);
|
||||||
|
}
|
||||||
|
// Keyboard height will not exceed maxKeyboardHeight and will not be less than
|
||||||
|
// minKeyboardHeight.
|
||||||
|
return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isValidFraction(final float fraction) {
|
public static boolean isValidFraction(final float fraction) {
|
||||||
return fraction >= 0.0f;
|
return fraction >= 0.0f;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue