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

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

Show dialog to guide the user to input subtype enabler

Bug: 6370433
Change-Id: Ic5777c1d95fe2ce9f48c72b8cc05c7ac250f4cdf
parent f91739b4
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -275,18 +275,24 @@

    <!-- Title of the preference settings for custom input styles (language and keyboard layout pairs) [CHAR LIMIT=35]-->
    <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=16] -->
    <!-- Title of the option menu to add a new style entry in the preference settings [CHAR LIMIT=16] -->
    <string name="add_style">Add style</string>
    <!-- Title of the button to add custom style entry in the settings dialog [CHAR_LIMIT=12]  -->
    <!-- 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]  -->
    <!-- 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]  -->
    <!-- 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]  -->
    <!-- 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]  -->
    <!-- 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>
    <!-- The message of the dialog to note that a custom input style needs to be enabled. [CHAR LIMIT=64] -->
    <string name="custom_input_style_note_message">"Your custom input style needs to be enabled before you start using it. Do you want to enable it now?"</string>
    <!-- Title of the button to enable a custom input style entry in the settings dialog [CHAR LIMIT=12] -->
    <string name="enable">Enable</string>
    <!-- Title of the button to postpone enabling a custom input style entry in the settings dialog [CHAR LIMIT=12] -->
    <string name="not_now">Not now</string>

    <!-- Title of an option for usability study mode -->
    <string name="prefs_usability_study_mode">Usability study mode</string>
+58 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Parcel;
@@ -41,6 +42,8 @@ import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;

import com.android.inputmethod.compat.CompatUtils;

import java.util.TreeSet;

public class AdditionalSubtypeSettings extends PreferenceFragment {
@@ -49,9 +52,14 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
    private KeyboardLayoutSetAdapter mKeyboardLayoutSetAdapter;

    private boolean mIsAddingNewSubtype;
    private AlertDialog mSubtypeEnablerNotificationDialog;
    private String mSubtypePreferenceKeyForSubtypeEnabler;

    private static final int MENU_ADD_SUBTYPE = Menu.FIRST;
    private static final String SAVE_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype";
    private static final String KEY_IS_ADDING_NEW_SUBTYPE = "is_adding_new_subtype";
    private static final String KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN =
            "is_subtype_enabler_notification_dialog_open";
    private static final String KEY_SUBTYPE_FOR_SUBTYPE_ENABLER = "subtype_for_subtype_enabler";

    static class SubtypeLocaleItem extends Pair<String, String>
            implements Comparable<SubtypeLocaleItem> {
@@ -368,20 +376,36 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
        setPrefSubtypes(prefSubtypes, context);

        mIsAddingNewSubtype = (savedInstanceState != null)
                && savedInstanceState.containsKey(SAVE_IS_ADDING_NEW_SUBTYPE);
                && savedInstanceState.containsKey(KEY_IS_ADDING_NEW_SUBTYPE);
        if (mIsAddingNewSubtype) {
            getPreferenceScreen().addPreference(
                    SubtypePreference.newIncompleteSubtypePreference(context, mSubtypeProxy));
        }

        super.onActivityCreated(savedInstanceState);

        if (savedInstanceState != null && savedInstanceState.containsKey(
                KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN)) {
            mSubtypePreferenceKeyForSubtypeEnabler = savedInstanceState.getString(
                    KEY_SUBTYPE_FOR_SUBTYPE_ENABLER);
            final SubtypePreference subtypePref = (SubtypePreference)findPreference(
                    mSubtypePreferenceKeyForSubtypeEnabler);
            mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
            mSubtypeEnablerNotificationDialog.show();
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (mIsAddingNewSubtype) {
            outState.putBoolean(SAVE_IS_ADDING_NEW_SUBTYPE, true);
            outState.putBoolean(KEY_IS_ADDING_NEW_SUBTYPE, true);
        }
        if (mSubtypeEnablerNotificationDialog != null
                && mSubtypeEnablerNotificationDialog.isShowing()) {
            outState.putBoolean(KEY_IS_SUBTYPE_ENABLER_NOTIFICATION_DIALOG_OPEN, true);
            outState.putString(
                    KEY_SUBTYPE_FOR_SUBTYPE_ENABLER, mSubtypePreferenceKeyForSubtypeEnabler);
        }
    }

@@ -398,6 +422,10 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
        @Override
        public void onAddPressed(SubtypePreference subtypePref) {
            mIsAddingNewSubtype = false;
            setAdditionalInputMethodSubtypes(getPrefSubtypes());
            mSubtypePreferenceKeyForSubtypeEnabler = subtypePref.getKey();
            mSubtypeEnablerNotificationDialog = createDialog(subtypePref);
            mSubtypeEnablerNotificationDialog.show();
        }

        @Override
@@ -411,6 +439,29 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
        }
    };

    private AlertDialog createDialog(SubtypePreference subtypePref) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.custom_input_styles_title)
                .setMessage(R.string.custom_input_style_note_message)
                .setNegativeButton(R.string.not_now, null)
                .setPositiveButton(R.string.enable, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final Intent intent = CompatUtils.getInputLanguageSelectionIntent(
                                ImfUtils.getInputMethodIdOfThisIme(getActivity()),
                                Intent.FLAG_ACTIVITY_NEW_TASK
                                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        // TODO: Add newly adding subtype to extra value of the intent as a hint
                        // for the input language selection activity.
                        // intent.putExtra("newlyAddedSubtype", subtypePref.getSubtype());
                        startActivity(intent);
                    }
                });

        return builder.create();
    }

    private void setPrefSubtypes(String prefSubtypes, Context context) {
        final PreferenceGroup group = getPreferenceScreen();
        group.removeAll();
@@ -458,6 +509,10 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
        } finally {
            editor.apply();
        }
        setAdditionalInputMethodSubtypes(prefSubtypes);
    }

    private void setAdditionalInputMethodSubtypes(final String prefSubtypes) {
        final InputMethodSubtype[] subtypes =
                AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes);
        ImfUtils.setAdditionalInputMethodSubtypes(getActivity(), subtypes);