From e84f8c3308428bb68574bb85a56b4777bfefd38c Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 9 Dec 2014 09:00:12 +0000 Subject: [PATCH] am be819dbe: Revert "Add keyboard margin options to place the keyboard dynamically." * commit 'be819dbe2b7a5c418530a2fa1182766a4d31d6d5': Revert "Add keyboard margin options to place the keyboard dynamically." Change-Id: I4d0d31b04aa083e32ea86cf394444a5eec4fe647 --- java/res/layout/input_view.xml | 20 ++----- .../values/donottranslate-debug-settings.xml | 6 -- java/res/xml/prefs_screen_debug.xml | 18 ------ .../keyboard/KeyboardSwitcher.java | 15 +---- .../keyboard/emoji/EmojiLayoutParams.java | 2 +- .../keyboard/emoji/EmojiPalettesView.java | 9 +-- .../android/inputmethod/latin/LatinIME.java | 8 +-- .../latin/settings/DebugSettings.java | 3 - .../latin/settings/DebugSettingsFragment.java | 13 +---- .../inputmethod/latin/settings/Settings.java | 7 ++- .../latin/settings/SettingsValues.java | 13 +---- ...terCheckingExactMatchesAndSuggestions.java | 2 +- .../latin/utils/ResourceUtils.java | 55 ++----------------- .../keyboard/KeyboardLayoutSetTestsBase.java | 2 +- 14 files changed, 29 insertions(+), 144 deletions(-) diff --git a/java/res/layout/input_view.xml b/java/res/layout/input_view.xml index 98ef02b25..ae3c19db5 100644 --- a/java/res/layout/input_view.xml +++ b/java/res/layout/input_view.xml @@ -23,18 +23,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" style="?attr/inputViewStyle"> - - - - + + diff --git a/java/res/values/donottranslate-debug-settings.xml b/java/res/values/donottranslate-debug-settings.xml index 55ab9335d..491043f1a 100644 --- a/java/res/values/donottranslate-debug-settings.xml +++ b/java/res/values/donottranslate-debug-settings.xml @@ -47,12 +47,6 @@ Enable keyboard resizing Keyboard height scale - - Keyboard bottom margin - - Keyboard left margin - - Keyboard right margin No dictionary files in the Downloads folder diff --git a/java/res/xml/prefs_screen_debug.xml b/java/res/xml/prefs_screen_debug.xml index 31347271c..905bc045c 100644 --- a/java/res/xml/prefs_screen_debug.xml +++ b/java/res/xml/prefs_screen_debug.xml @@ -87,24 +87,6 @@ android:title="@string/prefs_keyboard_height_scale" latin:minValue="50" latin:maxValue="120" /> - - - diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index d19f506ab..6ccd19f0a 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -22,7 +22,6 @@ import android.util.Log; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.widget.LinearLayout; @@ -66,7 +65,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { private KeyboardTheme mKeyboardTheme; private Context mThemeContext; - private View mHorizontalKeyboardFrame; + private static final KeyboardSwitcher sInstance = new KeyboardSwitcher(); public static KeyboardSwitcher getInstance() { @@ -113,16 +112,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( mThemeContext, editorInfo); final Resources res = mThemeContext.getResources(); - 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 keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues); - final int keyboardWidth = ResourceUtils.getKeyboardWidth(res, settingsValues); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setSubtype(RichInputMethodManager.getInstance().getCurrentSubtype()); builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey); @@ -421,8 +412,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled( isHardwareAcceleratedDrawingEnabled); mEmojiPalettesView.setKeyboardActionListener(mLatinIME); - mHorizontalKeyboardFrame = (LinearLayout)mCurrentInputView.findViewById( - R.id.horizontal_keyboard_frame); return mCurrentInputView; } diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiLayoutParams.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiLayoutParams.java index 2ac79975d..582e09124 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiLayoutParams.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiLayoutParams.java @@ -39,7 +39,7 @@ final class EmojiLayoutParams { public EmojiLayoutParams(final Resources res) { final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); - final int defaultKeyboardWidth = ResourceUtils.getKeyboardFrameWidth(res); + final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo, defaultKeyboardHeight, defaultKeyboardHeight); mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo, diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java index 223947e38..cf4dd3db3 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java @@ -50,8 +50,6 @@ import com.android.inputmethod.latin.AudioAndHapticFeedbackManager; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.RichInputMethodSubtype; 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 java.util.concurrent.TimeUnit; @@ -115,10 +113,9 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange context, null /* editorInfo */); final Resources res = context.getResources(); mEmojiLayoutParams = new EmojiLayoutParams(res); - final SettingsValues s = Settings.getInstance().getCurrent(); builder.setSubtype(RichInputMethodSubtype.getEmojiSubtype()); - builder.setKeyboardGeometry(ResourceUtils.getKeyboardWidth(res, s), - ResourceUtils.getKeyboardHeight(res, s)); + builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res), + mEmojiLayoutParams.mEmojiKeyboardHeight); final KeyboardLayoutSet layoutSet = builder.build(); final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs, R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView); @@ -143,7 +140,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange super.onMeasure(widthMeasureSpec, heightMeasureSpec); final Resources res = getContext().getResources(); // The main keyboard expands to the entire this {@link KeyboardView}. - final int width = ResourceUtils.getKeyboardFrameWidth(res) + final int width = ResourceUtils.getDefaultKeyboardWidth(res) + getPaddingLeft() + getPaddingRight(); final int height = ResourceUtils.getDefaultKeyboardHeight(res) + res.getDimensionPixelSize(R.dimen.config_suggestions_strip_height) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index bd660c5f3..27115e266 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -100,7 +100,6 @@ import com.android.inputmethod.latin.utils.ImportantNoticeUtils; import com.android.inputmethod.latin.utils.IntentUtils; import com.android.inputmethod.latin.utils.JniUtils; 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.StatsUtilsManager; import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; @@ -1212,7 +1211,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } final SettingsValues settingsValues = mSettings.getCurrent(); - final Resources res = getResources(); final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView(); if (visibleKeyboardView == null || !hasSuggestionStripView()) { return; @@ -1230,15 +1228,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final int suggestionsHeight = (!mKeyboardSwitcher.isShowingEmojiPalettes() && mSuggestionStripView.getVisibility() == View.VISIBLE) ? mSuggestionStripView.getHeight() : 0; - final int visibleTopY = inputHeight - - ResourceUtils.getKeyboardFrameHeight(res, settingsValues) - - suggestionsHeight; + final int visibleTopY = inputHeight - visibleKeyboardView.getHeight() - suggestionsHeight; mSuggestionStripView.setMoreSuggestionsHeight(visibleTopY); // Need to set expanded touchable region only if a keyboard view is being shown. if (visibleKeyboardView.isShown()) { final int touchLeft = 0; final int touchTop = mKeyboardSwitcher.isShowingMoreKeysPanel() ? 0 : visibleTopY; - final int touchRight = ResourceUtils.getKeyboardFrameWidth(res); + final int touchRight = visibleKeyboardView.getWidth(); final int touchBottom = inputHeight // Extend touchable region below the keyboard. + EXTENDED_TOUCHABLE_REGION_HEIGHT; diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java index eff7bde5d..6fffb8e9d 100644 --- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java +++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java @@ -31,9 +31,6 @@ public final class DebugSettings { "pref_has_custom_key_preview_animation_params"; 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_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 = "pref_key_preview_dismiss_duration"; public static final String PREF_KEY_PREVIEW_DISMISS_END_X_SCALE = diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java index 779bf47c9..b788d7fcf 100644 --- a/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/DebugSettingsFragment.java @@ -89,14 +89,8 @@ public final class DebugSettingsFragment extends SubScreenFragment defaultKeyPreviewDismissEndScale); setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE, defaultKeyPreviewDismissEndScale); - setupKeyboardScale( + setupKeyboardHeight( 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; mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE); @@ -259,7 +253,7 @@ public final class DebugSettingsFragment extends SubScreenFragment }); } - private void setupKeyboardScale(final String prefKey, final float defaultValue) { + private void setupKeyboardHeight(final String prefKey, final float defaultValue) { final SharedPreferences prefs = getSharedPreferences(); final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey); if (pref == null) { @@ -287,8 +281,7 @@ public final class DebugSettingsFragment extends SubScreenFragment @Override public int readValue(final String key) { - return getPercentageFromValue( - Settings.readKeyboardScale(prefs, key, defaultValue)); + return getPercentageFromValue(Settings.readKeyboardHeight(prefs, defaultValue)); } @Override diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 196fef4cd..0d3dab57c 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -367,9 +367,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang return (milliseconds != UNDEFINED_PREFERENCE_VALUE_INT) ? milliseconds : defaultValue; } - public static float readKeyboardScale(final SharedPreferences prefs, - final String prefKey, final float defaultValue) { - final float percentage = prefs.getFloat(prefKey, UNDEFINED_PREFERENCE_VALUE_FLOAT); + public static float readKeyboardHeight(final SharedPreferences prefs, + final float defaultValue) { + final float percentage = prefs.getFloat( + DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, UNDEFINED_PREFERENCE_VALUE_FLOAT); return (percentage != UNDEFINED_PREFERENCE_VALUE_FLOAT) ? percentage : defaultValue; } diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index 99e0565ca..5f1a7af44 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -50,7 +50,6 @@ public class SettingsValues { private static final String FLOAT_NEGATIVE_INFINITY_MARKER_STRING = "floatNegativeInfinity"; 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_MARGIN_SCALE = 0.0f; // 0% // From resources: public final SpacingAndPunctuations mSpacingAndPunctuations; @@ -114,9 +113,6 @@ public class SettingsValues { public final boolean mHasCustomKeyPreviewAnimationParams; public final boolean mHasKeyboardResize; public final float mKeyboardHeightScale; - public final float mKeyboardBottomMarginScale; - public final float mKeyboardLeftMarginScale; - public final float mKeyboardRightMarginScale; public final int mKeyPreviewShowUpDuration; public final int mKeyPreviewDismissDuration; public final float mKeyPreviewShowUpStartXScale; @@ -194,14 +190,7 @@ public class SettingsValues { mHasCustomKeyPreviewAnimationParams = prefs.getBoolean( DebugSettings.PREF_HAS_CUSTOM_KEY_PREVIEW_ANIMATION_PARAMS, false); mHasKeyboardResize = prefs.getBoolean(DebugSettings.PREF_RESIZE_KEYBOARD, false); - 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); + mKeyboardHeightScale = Settings.readKeyboardHeight(prefs, DEFAULT_SIZE_SCALE); mKeyPreviewShowUpDuration = Settings.readKeyPreviewAnimationDuration( prefs, DebugSettings.PREF_KEY_PREVIEW_SHOW_UP_DURATION, res.getInteger(R.integer.config_key_preview_show_up_duration)); diff --git a/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java b/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java index 0c01a737c..9c6a94810 100644 --- a/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java +++ b/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java @@ -143,7 +143,7 @@ public class DistracterFilterCheckingExactMatchesAndSuggestions implements Distr final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder( mContext, editorInfo); final Resources res = mContext.getResources(); - final int keyboardWidth = ResourceUtils.getKeyboardFrameWidth(res); + final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight); builder.setSubtype(new RichInputMethodSubtype(subtype)); diff --git a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java index 0a757877a..cc0d470df 100644 --- a/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ResourceUtils.java @@ -182,63 +182,18 @@ public final class ResourceUtils { return matchedAll; } - public static int getKeyboardFrameWidth(final Resources res) { + public static int getDefaultKeyboardWidth(final Resources res) { final DisplayMetrics dm = res.getDisplayMetrics(); return dm.widthPixels; } - public static int getKeyboardWidth(final Resources res, final SettingsValues settingsValues) { - final int frameWidth = getKeyboardFrameWidth(res); - if (settingsValues.mHasKeyboardResize) { - final float widthFraction = 1f - settingsValues.mKeyboardLeftMarginScale - - settingsValues.mKeyboardRightMarginScale; - return (int)(frameWidth * widthFraction); - } - 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); + final int defaultKeyboardHeight = getDefaultKeyboardHeight(res); if (settingsValues.mHasKeyboardResize) { - return (int)(keyboardHeight * settingsValues.mKeyboardHeightScale); + // mKeyboardHeightScale Ranges from [.5,1.2], from xml/prefs_screen_debug.xml + return (int)(defaultKeyboardHeight * 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; + return defaultKeyboardHeight; } public static int getDefaultKeyboardHeight(final Resources res) { diff --git a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java index 88550802c..7f828111d 100644 --- a/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java +++ b/tests/src/com/android/inputmethod/keyboard/KeyboardLayoutSetTestsBase.java @@ -155,7 +155,7 @@ public abstract class KeyboardLayoutSetTestsBase extends AndroidTestCase { final boolean languageSwitchKeyEnabled, final boolean splitLayoutEnabled) { final Context context = getContext(); final Resources res = context.getResources(); - final int keyboardWidth = ResourceUtils.getKeyboardFrameWidth(res); + final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res); final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res); final Builder builder = new Builder(context, editorInfo); builder.setKeyboardGeometry(keyboardWidth, keyboardHeight)