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

Commit c27fe625 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka
Browse files

Add custom subtype settings

Bug: 4460018
Change-Id: I4919d79516dcf574be2761bbaf9adcdc381b2ddc
parent 344af156
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:columnCount="2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="8dip"
    android:layout_marginRight="8dip"
    android:padding="8dip">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        style="?android:attr/textAppearanceSmall"
        android:text="@string/subtype_locale" />
    <Spinner
        android:id="@+id/subtype_locale_spinner"
        android:layout_width="wrap_content"
        android:layout_marginLeft="8dip"
        android:layout_marginBottom="8dip"
        android:layout_marginTop="8dip"
        android:layout_gravity="fill_horizontal|center_vertical"
        android:prompt="@string/subtype_locale" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left|center_vertical"
        style="?android:attr/textAppearanceSmall"
        android:text="@string/keyboard_layout_set" />
    <Spinner
        android:id="@+id/keyboard_layout_set_spinner"
        android:layout_width="wrap_content"
        android:layout_marginLeft="8dip"
        android:layout_marginBottom="8dip"
        android:layout_marginTop="8dip"
        android:layout_gravity="fill_horizontal|center_vertical"
        android:prompt="@string/keyboard_layout_set" />
</GridLayout>
+17 −0
Original line number Diff line number Diff line
@@ -252,9 +252,26 @@
    <string name="subtype_en_GB">English (UK)</string>
    <!-- Description for English (United States) keyboard subtype [CHAR LIMIT=22] -->
    <string name="subtype_en_US">English (US)</string>
    <!-- Description for language agnostic keyboard subtype [CHAR LIMIT=22] -->
    <string name="subtype_no_language">No language</string>
    <!-- Description for language agnostic QWERTY keyboard subtype [CHAR LIMIT=22] -->
    <string name="subtype_no_language_qwerty">No language (QWERTY)</string>

    <!-- Title of the preference settings for custom input styles (language and keyboard layout pairs) [CHAR LIMIT=22]-->
    <string name="custom_input_styles_title">Custom input styles</string>
    <!-- Title of the option menu to add a new style entry in the preference settings [CHAR_LIMIT=12] -->
    <string name="add_style">Add style</string>
    <!-- Title of the button to add custom style entry in the settings dialog [CHAR_LIMIT=12]  -->
    <string name="add">Add</string>
    <!-- Title of the button to remove a custom style entry in the settings dialog [CHAR_LIMIT=12]  -->
    <string name="remove">Remove</string>
    <!-- Title of the button to save a custom style entry in the settings dialog [CHAR_LIMIT=12]  -->
    <string name="save">Save</string>
    <!-- Title of the spinner for choosing a language of custom style in the settings dialog [CHAR_LIMIT=12]  -->
    <string name="subtype_locale">Language</string>
    <!-- Title of the spinner for choosing a keyboard layout of custom style in the settings dialog [CHAR_LIMIT=12]  -->
    <string name="keyboard_layout_set">Layout</string>

    <!-- Title of an option for usability study mode -->
    <string name="prefs_usability_study_mode">Usability study mode</string>
    <!-- Title of the settings for keypress vibration duration -->
+19 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2012 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Items will be added at runtime -->
</PreferenceScreen>
+4 −0
Original line number Diff line number Diff line
@@ -100,6 +100,10 @@
                android:summary="@string/include_other_imes_in_language_switch_list_summary"
                android:persistent="true"
                android:defaultValue="false" />
            <PreferenceScreen
                android:fragment="com.android.inputmethod.latin.AdditionalSubtypeSettings"
                android:key="custom_input_styles"
                android:title="@string/custom_input_styles_title" />
            <!-- Values for popup dismiss delay are added programatically -->
            <ListPreference
                android:key="pref_key_preview_popup_dismiss_delay"
+40 −15
Original line number Diff line number Diff line
@@ -24,6 +24,11 @@ public class AdditionalSubtype {
    public static final String QWERTY = "qwerty";
    public static final String QWERTZ = "qwertz";
    public static final String AZERTY = "azerty";
    public static final String[] PREDEFINED_KEYBOARD_LAYOUT_SET = {
        QWERTY,
        QWERTZ,
        AZERTY
    };

    private static final String SUBTYPE_MODE_KEYBOARD = "keyboard";
    private static final String SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype";
@@ -38,40 +43,60 @@ public class AdditionalSubtype {
        sKeyboardLayoutToNameIdsMap.put(AZERTY, R.string.subtype_generic_azerty);
    }

    private AdditionalSubtype() {
        // This utility class is not publicly instantiable.
    }

    public static boolean isAdditionalSubtype(InputMethodSubtype subtype) {
        return subtype.containsExtraValueKey(SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE);
    }

    private static final String LOCALE_AND_LAYOUT_SEPARATOR = ":";
    public static final String PREF_SUBTYPE_SEPARATOR = ";";

    public static InputMethodSubtype createAdditionalSubtype(
            String localeString, String keyboardLayoutSetName, String extraValue) {
        final String layoutExtraValue = LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET + "="
                + keyboardLayoutSetName;
        final String filteredExtraValue = StringUtils.appendToCsvIfNotExists(
                SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE,
                StringUtils.removeFromCsvIfExists(layoutExtraValue, extraValue));
                SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE, extraValue);
        Integer nameId = sKeyboardLayoutToNameIdsMap.get(keyboardLayoutSetName);
        if (nameId == null) nameId = R.string.subtype_generic;
        return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
                localeString, SUBTYPE_MODE_KEYBOARD, filteredExtraValue, false, false);
                localeString, SUBTYPE_MODE_KEYBOARD,
                layoutExtraValue + "," + filteredExtraValue, false, false);
    }

    private static final String LOCALE_AND_LAYOUT_SEPARATOR = ":";
    private static final String PREF_SUBTYPE_SEPARATOR = ";";
    public static String getPrefSubtype(InputMethodSubtype subtype) {
        final String localeString = subtype.getLocale();
        final String keyboardLayoutSetName = SubtypeLocale.getKeyboardLayoutSetName(subtype);
        final String layoutExtraValue = LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET + "="
                + keyboardLayoutSetName;
        final String extraValue = StringUtils.removeFromCsvIfExists(layoutExtraValue,
                StringUtils.removeFromCsvIfExists(SUBTYPE_EXTRA_VALUE_IS_ADDITIONAL_SUBTYPE,
                        subtype.getExtraValue()));
        final String basePrefSubtype = localeString + LOCALE_AND_LAYOUT_SEPARATOR
                + keyboardLayoutSetName;
        return extraValue.isEmpty() ? basePrefSubtype
                : basePrefSubtype + LOCALE_AND_LAYOUT_SEPARATOR + extraValue;
    }

    public static InputMethodSubtype[] createAdditionalSubtypesArray(String prefSubtypes) {
        final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR);
        final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[prefSubtypeArray.length];
        for (int i = 0; i < prefSubtypeArray.length; i++) {
            final String prefSubtype = prefSubtypeArray[i];
    public static InputMethodSubtype createAdditionalSubtype(String prefSubtype) {
        final String elems[] = prefSubtype.split(LOCALE_AND_LAYOUT_SEPARATOR);
        if (elems.length < 2 || elems.length > 3) {
                throw new RuntimeException("Unknown subtype found in preference: " + prefSubtype);
            throw new RuntimeException("Unknown additional subtype specified: " + prefSubtype);
        }
        final String localeString = elems[0];
        final String keyboardLayoutSetName = elems[1];
        final String extraValue = (elems.length == 3) ? elems[2] : null;
            subtypesArray[i] = AdditionalSubtype.createAdditionalSubtype(
                    localeString, keyboardLayoutSetName, extraValue);
        return createAdditionalSubtype(localeString, keyboardLayoutSetName, extraValue);
    }

    public static InputMethodSubtype[] createAdditionalSubtypesArray(String prefSubtypes) {
        final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR);
        final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[prefSubtypeArray.length];
        for (int i = 0; i < prefSubtypeArray.length; i++) {
            subtypesArray[i] = createAdditionalSubtype(prefSubtypeArray[i]);
        }
        return subtypesArray;
    }
Loading