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

Commit 7f35c8cc authored by satok's avatar satok
Browse files

Show "more" button in the dialog of InputMethodSubtypePicker

- Handle subtypes correctly in InputMethodPicker

Change-Id: I0ff9baec46724ca9dee2a7943fee69d4b204589e
parent 5847b20c
Loading
Loading
Loading
Loading
+60 −24
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import java.io.PrintWriter;
import java.text.Collator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@@ -1567,14 +1568,15 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        int lastInputMethodSubtypeId = getSelectedInputMethodSubtypeId(lastInputMethodId);
        if (DEBUG) Slog.v(TAG, "Current IME: " + lastInputMethodId);

        final List<InputMethodInfo> immis = getEnabledInputMethodList();
        synchronized (mMethodMap) {
            final List<Pair<InputMethodInfo, ArrayList<String>>> immis =
                    mSettings.getEnabledInputMethodAndSubtypeListLocked();
            ArrayList<Integer> subtypeIds = new ArrayList<Integer>();

        if (immis == null) {
            if (immis == null || immis.size() == 0) {
                return;
            }

        synchronized (mMethodMap) {
            hideInputMethodMenuLocked();

            int N = immis.size();
@@ -1583,16 +1585,21 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                new TreeMap<CharSequence, Pair<InputMethodInfo, Integer>>(Collator.getInstance());

            for (int i = 0; i < N; ++i) {
                InputMethodInfo property = immis.get(i);
                InputMethodInfo property = immis.get(i).first;
                final ArrayList<String> enabledSubtypeIds = immis.get(i).second;
                HashSet<String> enabledSubtypeSet = new HashSet<String>();
                for (String s : enabledSubtypeIds) {
                    enabledSubtypeSet.add(s);
                }
                if (property == null) {
                    continue;
                }
                // TODO: Show only enabled subtypes
                ArrayList<InputMethodSubtype> subtypes = property.getSubtypes();
                CharSequence label = property.loadLabel(pm);
                if (showSubtypes && subtypes.size() > 0) {
                if (showSubtypes && enabledSubtypeSet.size() > 0) {
                    for (int j = 0; j < subtypes.size(); ++j) {
                        InputMethodSubtype subtype = subtypes.get(j);
                        if (enabledSubtypeSet.contains(String.valueOf(subtype.hashCode()))) {
                            CharSequence title;
                            int nameResId = subtype.getNameResId();
                            int modeResId = subtype.getModeResId();
@@ -1610,6 +1617,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            }
                            imMap.put(title, new Pair<InputMethodInfo, Integer>(property, j));
                        }
                    }
                } else {
                    imMap.put(label,
                            new Pair<InputMethodInfo, Integer>(property, NOT_A_SUBTYPE_ID));
@@ -1678,6 +1686,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                        }
                    });

            if (showSubtypes) {
                mDialogBuilder.setPositiveButton(com.android.internal.R.string.more_item_label,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                showInputMethodAndSubtypeEnabler();
                            }
                        });
            }
            mSwitchingDialog = mDialogBuilder.create();
            mSwitchingDialog.getWindow().setType(
                    WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
@@ -1864,6 +1880,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    getEnabledInputMethodsAndSubtypeListLocked());
        }

        public List<Pair<InputMethodInfo, ArrayList<String>>>
                getEnabledInputMethodAndSubtypeListLocked() {
            return createEnabledInputMethodAndSubtypeListLocked(
                    getEnabledInputMethodsAndSubtypeListLocked());
        }

        // At the initial boot, the settings for input methods are not set,
        // so we need to enable IME in that case.
        public void enableAllIMEsIfThereIsNoEnabledIME() {
@@ -1960,6 +1982,20 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            return res;
        }

        private List<Pair<InputMethodInfo, ArrayList<String>>>
                createEnabledInputMethodAndSubtypeListLocked(
                        List<Pair<String, ArrayList<String>>> imsList) {
            final ArrayList<Pair<InputMethodInfo, ArrayList<String>>> res
                    = new ArrayList<Pair<InputMethodInfo, ArrayList<String>>>();
            for (Pair<String, ArrayList<String>> ims : imsList) {
                InputMethodInfo info = mMethodMap.get(ims.first);
                if (info != null) {
                    res.add(new Pair<InputMethodInfo, ArrayList<String>>(info, ims.second));
                }
            }
            return res;
        }

        private void putEnabledInputMethodsStr(String str) {
            Settings.Secure.putString(mResolver, Settings.Secure.ENABLED_INPUT_METHODS, str);
            mEnabledInputMethodsStrCache = str;