Add keyboard margin options to place the keyboard dynamically.

Keyboard location and location can now be set in the debug options
section.

Change-Id: I87c5a1d679489e12dccf26632c399af28087629e
main
Andy Wang 2014-12-02 13:01:11 +09:00
parent d21db3cf61
commit 8584db1461
14 changed files with 146 additions and 30 deletions

View File

@ -23,10 +23,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="?attr/inputViewStyle"> style="?attr/inputViewStyle">
<LinearLayout
android:id="@+id/horizontal_keyboard_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal">
<include <include
android:id="@+id/main_keyboard_frame" android:id="@+id/main_keyboard_frame"
layout="@layout/main_keyboard_frame" /> layout="@layout/main_keyboard_frame" />
<include <include
android:id="@+id/emoji_palettes_view" android:id="@+id/emoji_palettes_view"
layout="@layout/emoji_palettes_view" /> layout="@layout/emoji_palettes_view" />
</LinearLayout>
</com.android.inputmethod.latin.InputView> </com.android.inputmethod.latin.InputView>

View File

@ -47,6 +47,12 @@
<string name="prefs_resize_keyboard">Enable keyboard resizing</string> <string name="prefs_resize_keyboard">Enable keyboard resizing</string>
<!-- Title of the settings for setting keyboard height --> <!-- Title of the settings for setting keyboard height -->
<string name="prefs_keyboard_height_scale">Keyboard height scale</string> <string name="prefs_keyboard_height_scale">Keyboard height scale</string>
<!-- Title of the settings for setting keyboard width -->
<string name="prefs_keyboard_bottom_margin">Keyboard bottom margin</string>
<!-- Title of the settings for setting keyboard width -->
<string name="prefs_keyboard_left_margin">Keyboard left margin</string>
<!-- Title of the settings for setting keyboard width -->
<string name="prefs_keyboard_right_margin">Keyboard right margin</string>
<!-- Message to show when there are no files to install as an external dictionary [CHAR LIMIT=100] --> <!-- Message to show when there are no files to install as an external dictionary [CHAR LIMIT=100] -->
<string name="read_external_dictionary_no_files_message">No dictionary files in the Downloads folder</string> <string name="read_external_dictionary_no_files_message">No dictionary files in the Downloads folder</string>
<!-- Title of the dialog that selects a file to install as an external dictionary [CHAR LIMIT=50] --> <!-- Title of the dialog that selects a file to install as an external dictionary [CHAR LIMIT=50] -->

View File

@ -87,6 +87,24 @@
android:title="@string/prefs_keyboard_height_scale" android:title="@string/prefs_keyboard_height_scale"
latin:minValue="50" latin:minValue="50"
latin:maxValue="120" /> <!-- percentage --> latin:maxValue="120" /> <!-- percentage -->
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:dependency="pref_resize_keyboard"
android:key="pref_keyboard_bottom_margin"
android:title="@string/prefs_keyboard_bottom_margin"
latin:minValue="0"
latin:maxValue="50" /> <!-- percentage -->
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:dependency="pref_resize_keyboard"
android:key="pref_keyboard_left_margin"
android:title="@string/prefs_keyboard_left_margin"
latin:minValue="0"
latin:maxValue="50" /> <!-- percentage -->
<com.android.inputmethod.latin.settings.SeekBarDialogPreference
android:dependency="pref_resize_keyboard"
android:key="pref_keyboard_right_margin"
android:title="@string/prefs_keyboard_right_margin"
latin:minValue="0"
latin:maxValue="50" /> <!-- percentage -->
<PreferenceScreen <PreferenceScreen
android:key="read_external_dictionary" android:key="read_external_dictionary"
android:title="@string/prefs_read_external_dictionary" /> android:title="@string/prefs_read_external_dictionary" />

View File

@ -22,7 +22,9 @@ import android.util.Log;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.event.Event; import com.android.inputmethod.event.Event;
@ -64,7 +66,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private KeyboardTheme mKeyboardTheme; private KeyboardTheme mKeyboardTheme;
private Context mThemeContext; private Context mThemeContext;
private View mHorizontalKeyboardFrame;
private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); private static final KeyboardSwitcher sInstance = new KeyboardSwitcher();
public static KeyboardSwitcher getInstance() { public static KeyboardSwitcher getInstance() {
@ -111,8 +113,16 @@ 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 int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final ViewGroup.MarginLayoutParams p =
(ViewGroup.MarginLayoutParams) mHorizontalKeyboardFrame.getLayoutParams();
final int keyboardLeftMargin = ResourceUtils.getKeyboardLeftMargin(res, settingsValues);
final int keyboardRightMargin = ResourceUtils.getKeyboardRightMargin(res, settingsValues);
final int keyboardBottomMargin = ResourceUtils.getKeyboardBottomMargin(res, settingsValues);
p.setMargins(keyboardLeftMargin, 0, keyboardRightMargin, keyboardBottomMargin);
final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues); final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues);
final int keyboardWidth = ResourceUtils.getKeyboardWidth(res, settingsValues);
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype()); builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype());
builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey); builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
@ -411,6 +421,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled( mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled(
isHardwareAcceleratedDrawingEnabled); isHardwareAcceleratedDrawingEnabled);
mEmojiPalettesView.setKeyboardActionListener(mLatinIME); mEmojiPalettesView.setKeyboardActionListener(mLatinIME);
mHorizontalKeyboardFrame = (LinearLayout)mCurrentInputView.findViewById(
R.id.horizontal_keyboard_frame);
return mCurrentInputView; return mCurrentInputView;
} }

View File

@ -39,7 +39,7 @@ final class EmojiLayoutParams {
public EmojiLayoutParams(final Resources res) { public EmojiLayoutParams(final Resources res) {
final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int defaultKeyboardWidth = ResourceUtils.getKeyboardFrameWidth(res);
mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo, mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo,
defaultKeyboardHeight, defaultKeyboardHeight); defaultKeyboardHeight, defaultKeyboardHeight);
mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo, mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo,

View File

@ -50,6 +50,8 @@ import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodSubtype; import com.android.inputmethod.latin.RichInputMethodSubtype;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.ResourceUtils;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -113,9 +115,10 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
context, null /* editorInfo */); context, null /* editorInfo */);
final Resources res = context.getResources(); final Resources res = context.getResources();
mEmojiLayoutParams = new EmojiLayoutParams(res); mEmojiLayoutParams = new EmojiLayoutParams(res);
final SettingsValues s = Settings.getInstance().getCurrent();
builder.setSubtype(RichInputMethodSubtype.getEmojiSubtype()); builder.setSubtype(RichInputMethodSubtype.getEmojiSubtype());
builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res), builder.setKeyboardGeometry(ResourceUtils.getKeyboardWidth(res, s),
mEmojiLayoutParams.mEmojiKeyboardHeight); ResourceUtils.getKeyboardHeight(res, s));
final KeyboardLayoutSet layoutSet = builder.build(); final KeyboardLayoutSet layoutSet = builder.build();
final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs, final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs,
R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView); R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView);
@ -140,7 +143,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final Resources res = getContext().getResources(); final Resources res = getContext().getResources();
// The main keyboard expands to the entire this {@link KeyboardView}. // The main keyboard expands to the entire this {@link KeyboardView}.
final int width = ResourceUtils.getDefaultKeyboardWidth(res) final int width = ResourceUtils.getKeyboardFrameWidth(res)
+ getPaddingLeft() + getPaddingRight(); + getPaddingLeft() + getPaddingRight();
final int height = ResourceUtils.getDefaultKeyboardHeight(res) final int height = ResourceUtils.getDefaultKeyboardHeight(res)
+ res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height) + res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height)

View File

@ -100,6 +100,7 @@ import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.IntentUtils;
import com.android.inputmethod.latin.utils.JniUtils; import com.android.inputmethod.latin.utils.JniUtils;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper; import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.StatsUtils; import com.android.inputmethod.latin.utils.StatsUtils;
import com.android.inputmethod.latin.utils.StatsUtilsManager; import com.android.inputmethod.latin.utils.StatsUtilsManager;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
@ -1211,6 +1212,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return; return;
} }
final SettingsValues settingsValues = mSettings.getCurrent(); final SettingsValues settingsValues = mSettings.getCurrent();
final Resources res = getResources();
final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView(); final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
if (visibleKeyboardView == null || !hasSuggestionStripView()) { if (visibleKeyboardView == null || !hasSuggestionStripView()) {
return; return;
@ -1228,13 +1230,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final int suggestionsHeight = (!mKeyboardSwitcher.isShowingEmojiPalettes() final int suggestionsHeight = (!mKeyboardSwitcher.isShowingEmojiPalettes()
&& mSuggestionStripView.getVisibility() == View.VISIBLE) && mSuggestionStripView.getVisibility() == View.VISIBLE)
? mSuggestionStripView.getHeight() : 0; ? mSuggestionStripView.getHeight() : 0;
final int visibleTopY = inputHeight - visibleKeyboardView.getHeight() - suggestionsHeight; final int visibleTopY = inputHeight
- ResourceUtils.getKeyboardFrameHeight(res, settingsValues)
- suggestionsHeight;
mSuggestionStripView.setMoreSuggestionsHeight(visibleTopY); mSuggestionStripView.setMoreSuggestionsHeight(visibleTopY);
// Need to set expanded touchable region only if a keyboard view is being shown. // Need to set expanded touchable region only if a keyboard view is being shown.
if (visibleKeyboardView.isShown()) { if (visibleKeyboardView.isShown()) {
final int touchLeft = 0; final int touchLeft = 0;
final int touchTop = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY; final int touchTop = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY;
final int touchRight = visibleKeyboardView.getWidth(); final int touchRight = ResourceUtils.getKeyboardFrameWidth(res);
final int touchBottom = inputHeight final int touchBottom = inputHeight
// Extend touchable region below the keyboard. // Extend touchable region below the keyboard.
+ EXTENDED_TOUCHABLE_REGION_HEIGHT; + EXTENDED_TOUCHABLE_REGION_HEIGHT;

View File

@ -31,6 +31,9 @@ public final class DebugSettings {
"pref_has_custom_key_preview_animation_params"; "pref_has_custom_key_preview_animation_params";
public static final String PREF_RESIZE_KEYBOARD = "pref_resize_keyboard"; public static final String PREF_RESIZE_KEYBOARD = "pref_resize_keyboard";
public static final String PREF_KEYBOARD_HEIGHT_SCALE = "pref_keyboard_height_scale"; public static final String PREF_KEYBOARD_HEIGHT_SCALE = "pref_keyboard_height_scale";
public static final String PREF_KEYBOARD_BOTTOM_MARGIN = "pref_keyboard_bottom_margin";
public static final String PREF_KEYBOARD_LEFT_MARGIN = "pref_keyboard_left_margin";
public static final String PREF_KEYBOARD_RIGHT_MARGIN = "pref_keyboard_right_margin";
public static final String PREF_KEY_PREVIEW_DISMISS_DURATION = public static final String PREF_KEY_PREVIEW_DISMISS_DURATION =
"pref_key_preview_dismiss_duration"; "pref_key_preview_dismiss_duration";
public static final String PREF_KEY_PREVIEW_DISMISS_END_X_SCALE = public static final String PREF_KEY_PREVIEW_DISMISS_END_X_SCALE =

View File

@ -89,8 +89,14 @@ public final class DebugSettingsFragment extends SubScreenFragment
defaultKeyPreviewDismissEndScale); defaultKeyPreviewDismissEndScale);
setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE, setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE,
defaultKeyPreviewDismissEndScale); defaultKeyPreviewDismissEndScale);
setupKeyboardHeight( setupKeyboardScale(
DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE); DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE);
setupKeyboardScale(
DebugSettings.PREF_KEYBOARD_BOTTOM_MARGIN, SettingsValues.DEFAULT_MARGIN_SCALE);
setupKeyboardScale(
DebugSettings.PREF_KEYBOARD_LEFT_MARGIN, SettingsValues.DEFAULT_MARGIN_SCALE);
setupKeyboardScale(
DebugSettings.PREF_KEYBOARD_RIGHT_MARGIN, SettingsValues.DEFAULT_MARGIN_SCALE);
mServiceNeedsRestart = false; mServiceNeedsRestart = false;
mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE);
@ -253,7 +259,7 @@ public final class DebugSettingsFragment extends SubScreenFragment
}); });
} }
private void setupKeyboardHeight(final String prefKey, final float defaultValue) { private void setupKeyboardScale(final String prefKey, final float defaultValue) {
final SharedPreferences prefs = getSharedPreferences(); final SharedPreferences prefs = getSharedPreferences();
final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey); final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
if (pref == null) { if (pref == null) {
@ -281,7 +287,8 @@ public final class DebugSettingsFragment extends SubScreenFragment
@Override @Override
public int readValue(final String key) { public int readValue(final String key) {
return getPercentageFromValue(Settings.readKeyboardHeight(prefs, defaultValue)); return getPercentageFromValue(
Settings.readKeyboardScale(prefs, key, defaultValue));
} }
@Override @Override

View File

@ -367,10 +367,9 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue; return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue;
} }
public static float readKeyboardHeight(final SharedPreferences prefs, public static float readKeyboardScale(final SharedPreferences prefs,
final float defaultValue) { final String prefKey, final float defaultValue) {
final float percentage = prefs.getFloat( final float percentage = prefs.getFloat(prefKey, UNDEFINED_PREFERENCE_VALUE_FLOAT);
DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, UNDEFINED_PREFERENCE_VALUE_FLOAT);
return (percentage != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? percentage : defaultValue; return (percentage != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? percentage : defaultValue;
} }

View File

@ -50,6 +50,7 @@ public class SettingsValues {
private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity"; private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity";
private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds private static final int TIMEOUT_TO_GET_TARGET_PACKAGE = 5; // seconds
public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100% public static final float DEFAULT_SIZE_SCALE = 1.0f; // 100%
public static final float DEFAULT_MARGIN_SCALE = 0.0f; // 0%
// From resources: // From resources:
public final SpacingAndPunctuations mSpacingAndPunctuations; public final SpacingAndPunctuations mSpacingAndPunctuations;
@ -113,6 +114,9 @@ public class SettingsValues {
public final boolean mHasCustomKeyPreviewAnimationParams; public final boolean mHasCustomKeyPreviewAnimationParams;
public final boolean mHasKeyboardResize; public final boolean mHasKeyboardResize;
public final float mKeyboardHeightScale; public final float mKeyboardHeightScale;
public final float mKeyboardBottomMarginScale;
public final float mKeyboardLeftMarginScale;
public final float mKeyboardRightMarginScale;
public final int mKeyPreviewShowUpDuration; public final int mKeyPreviewShowUpDuration;
public final int mKeyPreviewDismissDuration; public final int mKeyPreviewDismissDuration;
public final float mKeyPreviewShowUpStartXScale; public final float mKeyPreviewShowUpStartXScale;
@ -190,7 +194,14 @@ public class SettingsValues {
mHasCustomKeyPreviewAnimationParams = prefs.getBoolean( mHasCustomKeyPreviewAnimationParams = prefs.getBoolean(
DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false); DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false);
mHasKeyboardResize = prefs.getBoolean(DebugSettings.PREF_RESIZE_KEYBOARD, false); mHasKeyboardResize = prefs.getBoolean(DebugSettings.PREF_RESIZE_KEYBOARD, false);
mKeyboardHeightScale = Settings.readKeyboardHeight(prefs, DEFAULT_SIZE_SCALE); mKeyboardHeightScale = Settings.readKeyboardScale(
prefs, DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, DEFAULT_SIZE_SCALE);
mKeyboardBottomMarginScale = Settings.readKeyboardScale(
prefs, DebugSettings.PREF_KEYBOARD_BOTTOM_MARGIN, DEFAULT_MARGIN_SCALE);
mKeyboardLeftMarginScale = Settings.readKeyboardScale(
prefs, DebugSettings.PREF_KEYBOARD_LEFT_MARGIN, DEFAULT_MARGIN_SCALE);
mKeyboardRightMarginScale = Settings.readKeyboardScale(
prefs, DebugSettings.PREF_KEYBOARD_RIGHT_MARGIN, DEFAULT_MARGIN_SCALE);
mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration( mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration(
prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION, prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION,
res.getInteger(R.integer.config_key_preview_show_up_duration)); res.getInteger(R.integer.config_key_preview_show_up_duration));

View File

@ -143,7 +143,7 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr
final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(
mContext, editorInfo); mContext, editorInfo);
final Resources res = mContext.getResources(); final Resources res = mContext.getResources();
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardWidth = ResourceUtils.getKeyboardFrameWidth(res);
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
builder.setSubtype(new RichInputMethodSubtype(subtype)); builder.setSubtype(new RichInputMethodSubtype(subtype));

View File

@ -182,18 +182,63 @@ public final class ResourceUtils {
return matchedAll; return matchedAll;
} }
public static int getDefaultKeyboardWidth(final Resources res) { public static int getKeyboardFrameWidth(final Resources res) {
final DisplayMetrics dm = res.getDisplayMetrics(); final DisplayMetrics dm = res.getDisplayMetrics();
return dm.widthPixels; return dm.widthPixels;
} }
public static int getKeyboardHeight(final Resources res, final SettingsValues settingsValues) { public static int getKeyboardWidth(final Resources res, final SettingsValues settingsValues) {
final int defaultKeyboardHeight = getDefaultKeyboardHeight(res); final int frameWidth = getKeyboardFrameWidth(res);
if (settingsValues.mHasKeyboardResize) { if (settingsValues.mHasKeyboardResize) {
// mKeyboardHeightScale Ranges from [.5,1.2], from xml/prefs_screen_debug.xml final float widthFraction = 1f - settingsValues.mKeyboardLeftMarginScale
return (int)(defaultKeyboardHeight * settingsValues.mKeyboardHeightScale); - settingsValues.mKeyboardRightMarginScale;
return (int)(frameWidth * widthFraction);
} }
return defaultKeyboardHeight; return frameWidth;
}
public static int getKeyboardFrameHeight(final Resources res,
final SettingsValues settingsValues) {
if (settingsValues.mHasKeyboardResize) {
return getKeyboardHeight(res, settingsValues)
+ getKeyboardBottomMargin(res, settingsValues);
}
return getDefaultKeyboardHeight(res);
}
public static int getKeyboardHeight(final Resources res, final SettingsValues settingsValues) {
final int keyboardHeight = getDefaultKeyboardHeight(res);
if (settingsValues.mHasKeyboardResize) {
return (int)(keyboardHeight * settingsValues.mKeyboardHeightScale);
}
return keyboardHeight;
}
public static int getKeyboardLeftMargin(
final Resources res, final SettingsValues settingsValues) {
if (settingsValues.mHasKeyboardResize) {
final int frameWidth = getKeyboardFrameWidth(res);
return (int)(frameWidth * settingsValues.mKeyboardLeftMarginScale);
}
return 0;
}
public static int getKeyboardRightMargin(
final Resources res, final SettingsValues settingsValues) {
if (settingsValues.mHasKeyboardResize) {
final int frameWidth = getKeyboardFrameWidth(res);
return (int)(frameWidth * settingsValues.mKeyboardRightMarginScale);
}
return 0;
}
public static int getKeyboardBottomMargin(
final Resources res, final SettingsValues settingsValues) {
if (settingsValues.mHasKeyboardResize) {
final int defaultHeight = getDefaultKeyboardHeight(res);
return (int)(defaultHeight * settingsValues.mKeyboardBottomMarginScale);
}
return 0;
} }
public static int getDefaultKeyboardHeight(final Resources res) { public static int getDefaultKeyboardHeight(final Resources res) {

View File

@ -155,7 +155,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase {
final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) {
final Context context = getContext(); final Context context = getContext();
final Resources res = context.getResources(); final Resources res = context.getResources();
final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardWidth = ResourceUtils.getKeyboardFrameWidth(res);
final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
final Builder builder = new Builder(context, editorInfo); final Builder builder = new Builder(context, editorInfo);
builder.setKeyboardGeometry(keyboardWidth, keyboardHeight) builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)