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

Commit fac678e1 authored by Jean Chalard's avatar Jean Chalard Committed by Android (Google) Code Review
Browse files

Merge "Create the path for specifying combining rules in the subtype"

parents 4fb490ff be99616a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -503,7 +503,7 @@
            android:subtypeId="0xea266ea4"
            android:imeSubtypeLocale="my_MM"
            android:imeSubtypeMode="keyboard"
            android:imeSubtypeExtraValue="KeyboardLayoutSet=myanmar,EmojiCapable"
            android:imeSubtypeExtraValue="KeyboardLayoutSet=myanmar,EmojiCapable,CombiningRules=MyanmarReordering"
            android:isAsciiCapable="false"
    />
    <subtype android:icon="@drawable/ic_ime_switcher_dark"
+36 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.utils.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * This class implements the logic chain between receiving events and generating code points.
@@ -43,6 +44,13 @@ public class CombinerChain {
    private SpannableStringBuilder mStateFeedback;
    private final ArrayList<Combiner> mCombiners;

    private static final HashMap<String, Class> IMPLEMENTED_COMBINERS
            = new HashMap<String, Class>();
    static {
        IMPLEMENTED_COMBINERS.put("MyanmarReordering", MyanmarReordering.class);
    }
    private static final String COMBINER_SPEC_SEPARATOR = ";";

    /**
     * Create an combiner chain.
     *
@@ -56,6 +64,9 @@ public class CombinerChain {
        mCombiners = CollectionUtils.newArrayList();
        // The dead key combiner is always active, and always first
        mCombiners.add(new DeadKeyCombiner());
        for (final Combiner combiner : combinerList) {
            mCombiners.add(combiner);
        }
        mCombinedText = new StringBuilder();
        mStateFeedback = new SpannableStringBuilder();
    }
@@ -114,4 +125,29 @@ public class CombinerChain {
        final SpannableStringBuilder s = new SpannableStringBuilder(mCombinedText);
        return s.append(mStateFeedback);
    }

    public static Combiner[] createCombiners(final String spec) {
        if (TextUtils.isEmpty(spec)) {
            return new Combiner[0];
        }
        final String[] combinerDescriptors = spec.split(COMBINER_SPEC_SEPARATOR);
        final Combiner[] combiners = new Combiner[combinerDescriptors.length];
        int i = 0;
        for (final String combinerDescriptor : combinerDescriptors) {
            final Class combinerClass = IMPLEMENTED_COMBINERS.get(combinerDescriptor);
            if (null == combinerClass) {
                throw new RuntimeException("Unknown combiner descriptor: " + combinerDescriptor);
            }
            try {
                combiners[i++] = (Combiner)combinerClass.newInstance();
            } catch (InstantiationException e) {
                throw new RuntimeException("Unable to instantiate combiner: " + combinerDescriptor,
                        e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException("Unable to instantiate combiner: " + combinerDescriptor,
                        e);
            }
        }
        return combiners;
    }
}
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.
 */

package com.android.inputmethod.event;

import java.util.ArrayList;

/**
 * A combiner that reorders input for Myanmar.
 */
public class MyanmarReordering implements Combiner {
    @Override
    public Event processEvent(ArrayList<Event> previousEvents, Event event) {
        return event;
    }

    @Override
    public CharSequence getCombiningStateFeedback() {
        return "";
    }

    @Override
    public void reset() {
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -115,6 +115,11 @@ public final class Constants {
             */
            public static final String IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype";

            /**
             * The subtype extra value used to specify the combining rules.
             */
            public static final String COMBINING_RULES = "CombiningRules";

            private ExtraValue() {
                // This utility class is not publicly instantiable.
            }
+5 −1
Original line number Diff line number Diff line
@@ -733,6 +733,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        // Note that the calling sequence of onCreate() and onCurrentInputMethodSubtypeChanged()
        // is not guaranteed. It may even be called at the same time on a different thread.
        mSubtypeSwitcher.onSubtypeChanged(subtype);
        mInputLogic.onSubtypeChanged(SubtypeLocaleUtils.getCombiningRulesExtraValue(subtype));
        loadKeyboard();
    }

@@ -808,7 +809,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen

        // The app calling setText() has the effect of clearing the composing
        // span, so we should reset our state unconditionally, even if restarting is true.
        mInputLogic.startInput(restarting, editorInfo);
        // We also tell the input logic about the combining rules for the current subtype, so
        // it can adjust its combiners if needed.
        mInputLogic.startInput(restarting, editorInfo,
                mSubtypeSwitcher.getCombiningRulesExtraValueOfCurrentSubtype());

        // Note: the following does a round-trip IPC on the main thread: be careful
        final Locale currentLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
Loading