Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ca400c8 authored by Andy Wang's avatar Andy Wang Committed by Android (Google) Code Review
Browse files

Merge "Add a preference to resize the keyboard height."

parents d9b1327c bb9400ae
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@
    <string name="prefs_key_popup_dismiss_end_y_scale_settings">Key popup dismiss end Y scale</string>
    <!-- Title of the settings for reading an external dictionary file -->
    <string name="prefs_read_external_dictionary">Read external dictionary file</string>
    <!-- Title of the settings to enable keyboard resizing -->
    <string name="prefs_resize_keyboard">Enable keyboard resizing</string>
    <!-- Title of the settings for setting keyboard height -->
    <string name="prefs_keyboard_height_scale">Keyboard height scale</string>
    <!-- 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>
    <!-- Title of the dialog that selects a file to install as an external dictionary [CHAR LIMIT=50] -->
+11 −0
Original line number Diff line number Diff line
@@ -76,6 +76,17 @@
        android:key="pref_key_preview_dismiss_duration"
        android:title="@string/prefs_key_popup_dismiss_duration_settings"
        latin:maxValue="100" /> <!-- milliseconds -->
    <CheckBoxPreference
        android:key="pref_resize_keyboard"
        android:title="@string/prefs_resize_keyboard"
        android:defaultValue="false"
        android:persistent="true" />
    <com.android.inputmethod.latin.settings.SeekBarDialogPreference
        android:dependency="pref_resize_keyboard"
        android:key="pref_keyboard_height_scale"
        android:title="@string/prefs_keyboard_height_scale"
        latin:minValue="50"
        latin:maxValue="120" /> <!-- percentage -->
    <PreferenceScreen
        android:key="read_external_dictionary"
        android:title="@string/prefs_read_external_dictionary" />
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
                mThemeContext, editorInfo);
        final Resources res = mThemeContext.getResources();
        final int keyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
        final int keyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
        final int keyboardHeight = ResourceUtils.getKeyboardHeight(res, settingsValues);
        builder.setKeyboardGeometry(keyboardWidth, keyboardHeight);
        builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype());
        builder.setVoiceInputKeyEnabled(settingsValues.mShowsVoiceInputKey);
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ public final class DebugSettings {
    public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
    public static final String 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_KEYBOARD_HEIGHT_SCALE = "pref_keyboard_height_scale";
    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 =
+49 −0
Original line number Diff line number Diff line
@@ -89,6 +89,8 @@ public final class DebugSettingsFragment extends SubScreenFragment
                defaultKeyPreviewDismissEndScale);
        setupKeyPreviewAnimationScale(DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_Y_SCALE,
                defaultKeyPreviewDismissEndScale);
        setupKeyboardHeight(
                DebugSettings.PREF_KEYBOARD_HEIGHT_SCALE, SettingsValues.DEFAULT_SIZE_SCALE);

        mServiceNeedsRestart = false;
        mDebugMode = (TwoStatePreference) findPreference(DebugSettings.PREF_DEBUG_MODE);
@@ -250,4 +252,51 @@ public final class DebugSettingsFragment extends SubScreenFragment
            public void feedbackValue(final int value) {}
        });
    }

    private void setupKeyboardHeight(final String prefKey, final float defaultValue) {
        final SharedPreferences prefs = getSharedPreferences();
        final SeekBarDialogPreference pref = (SeekBarDialogPreference)findPreference(prefKey);
        if (pref == null) {
            return;
        }
        pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
            private static final float PERCENTAGE_FLOAT = 100.0f;
            private float getValueFromPercentage(final int percentage) {
                return percentage / PERCENTAGE_FLOAT;
            }

            private int getPercentageFromValue(final float floatValue) {
                return (int)(floatValue * PERCENTAGE_FLOAT);
            }

            @Override
            public void writeValue(final int value, final String key) {
                prefs.edit().putFloat(key, getValueFromPercentage(value)).apply();
            }

            @Override
            public void writeDefaultValue(final String key) {
                prefs.edit().remove(key).apply();
            }

            @Override
            public int readValue(final String key) {
                return getPercentageFromValue(
                        Settings.readKeyboardHeight(prefs, key, defaultValue));
            }

            @Override
            public int readDefaultValue(final String key) {
                return getPercentageFromValue(defaultValue);
            }

            @Override
            public String getValueText(final int value) {
                return String.format(Locale.ROOT, "%d%%", value);
            }

            @Override
            public void feedbackValue(final int value) {}
        });
    }
}
Loading