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

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

Make predefined subtype configurable by XML resource

Change-Id: I1f8486a1fb652f1e06789e7bfd2cc57273092234
parent 55d28fd1
Loading
Loading
Loading
Loading
+23 −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.
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- Predefined subtypes (language:layout) in CSV format -->
    <string name="predefined_subtypes" translatable="false">de:qwerty,fr:qwertz</string>
</resources>
+16 −0
Original line number Diff line number Diff line
@@ -52,4 +52,20 @@ public class AdditionalSubtype {
        return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
                localeString, SUBTYPE_MODE_KEYBOARD, extraValue, false, false);
    }

    private static final String LOCALE_AND_LAYOUT_SEPARATOR = ":";
    private static final String SUBTYPE_SEPARATOR = ",";

    public static InputMethodSubtype[] createAdditionalSubtypesArray(String csvSubtypes) {
        final String[] subtypeSpecs = csvSubtypes.split(SUBTYPE_SEPARATOR);
        final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[subtypeSpecs.length];
        for (int i = 0; i < subtypeSpecs.length; i++) {
            final String elems[] = subtypeSpecs[i].split(LOCALE_AND_LAYOUT_SEPARATOR);
            final String localeString = elems[0];
            final String keyboardLayoutSetName = elems[1];
            subtypesArray[i] = AdditionalSubtype.createAdditionalSubtype(
                    localeString, keyboardLayoutSetName);
        }
        return subtypesArray;
    }
}
+1 −2
Original line number Diff line number Diff line
@@ -441,8 +441,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen

        loadSettings();

        ImfUtils.setAdditionalInputMethodSubtypes(
                this, mSettingsValues.getPrefefinedAdditionalSubtypes());
        ImfUtils.setAdditionalInputMethodSubtypes(this, mSettingsValues.getAdditionalSubtypes());

        // TODO: remove the following when it's not needed by updateCorrectionMode() any more
        mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public class Settings extends InputMethodSettingsFragment
            "pref_suppress_language_switch_key";
    public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
            "pref_include_other_imes_in_language_switch_list";
    public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
    public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
            "pref_key_preview_popup_dismiss_delay";
    public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
+11 −13
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class SettingsValues {
    private final int mVibrationDurationSettingsRawValue;
    @SuppressWarnings("unused") // TODO: Use this
    private final float mKeypressSoundVolumeRawValue;
    private final InputMethodSubtype[] mPredefinedAdditionalSubtypes;
    private final InputMethodSubtype[] mAdditionalSubtypes;

    // Deduced settings
    public final int mKeypressVibrationDuration;
@@ -149,15 +149,8 @@ public class SettingsValues {
        mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
        mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);

        // Predefined additional subtypes
        final InputMethodSubtype DE_QWERTY = AdditionalSubtype.createAdditionalSubtype(
                Locale.GERMAN.toString(), AdditionalSubtype.QWERTY);
        final InputMethodSubtype FR_QWERTZ = AdditionalSubtype.createAdditionalSubtype(
                Locale.FRENCH.toString(), AdditionalSubtype.QWERTZ);
        mPredefinedAdditionalSubtypes = new InputMethodSubtype[] {
                DE_QWERTY,
                FR_QWERTZ,
        };
        mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray(
                getCsvAdditionalSubtypes(prefs, res));
    }

    // Helper functions to create member values.
@@ -318,9 +311,14 @@ public class SettingsValues {
        return res.getBoolean(R.bool.config_use_fullscreen_mode);
    }

    // TODO: Should be able to add/remove/edit.
    public InputMethodSubtype[] getPrefefinedAdditionalSubtypes() {
        return mPredefinedAdditionalSubtypes;
    public InputMethodSubtype[] getAdditionalSubtypes() {
        return mAdditionalSubtypes;
    }

    public static String getCsvAdditionalSubtypes(final SharedPreferences prefs,
            final Resources res) {
        final String csvPredefinedSubtypes = res.getString(R.string.predefined_subtypes, "");
        return prefs.getString(Settings.PREF_CUSTOM_INPUT_STYLES, csvPredefinedSubtypes);
    }

    // Accessed from the settings interface, hence public