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

Commit e895f5f9 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Move logic to determine spacebar text to LanguageOnSpacebarHelper"

parents 0c1822df 0d6ce465
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;

import javax.annotation.Nonnull;

/**
 * This class determines that the language name on the spacebar should be displayed in what format.
 */
@@ -37,7 +39,7 @@ public final class LanguageOnSpacebarHelper {
    private List<InputMethodSubtype> mEnabledSubtypes = Collections.emptyList();
    private boolean mIsSystemLanguageSameAsInputLanguage;

    public int getLanguageOnSpacebarFormatType(final RichInputMethodSubtype subtype) {
    public int getLanguageOnSpacebarFormatType(@Nonnull final RichInputMethodSubtype subtype) {
        if (subtype.isNoLanguage()) {
            return FORMAT_TYPE_FULL_LOCALE;
        }
@@ -65,11 +67,30 @@ public final class LanguageOnSpacebarHelper {
                : FORMAT_TYPE_LANGUAGE_ONLY;
    }

    public void updateEnabledSubtypes(final List<InputMethodSubtype> enabledSubtypes) {
    public void onUpdateEnabledSubtypes(@Nonnull final List<InputMethodSubtype> enabledSubtypes) {
        mEnabledSubtypes = enabledSubtypes;
    }

    public void updateIsSystemLanguageSameAsInputLanguage(final boolean isSame) {
        mIsSystemLanguageSameAsInputLanguage = isSame;
    public void onSubtypeChanged(@Nonnull final RichInputMethodSubtype subtype,
           final boolean implicitlyEnabledSubtype, @Nonnull final Locale systemLocale) {
        final Locale[] newLocales = subtype.getLocales();
        if (newLocales.length > 1) {
            // In multi-locales mode, the system language is never the same as the input language
            // because there is no single input language.
            mIsSystemLanguageSameAsInputLanguage = false;
            return;
        }
        final Locale newLocale = newLocales[0];
        if (systemLocale.equals(newLocale)) {
            mIsSystemLanguageSameAsInputLanguage = true;
            return;
        }
        if (!systemLocale.getLanguage().equals(newLocale.getLanguage())) {
            mIsSystemLanguageSameAsInputLanguage = false;
            return;
        }
        // If the subtype is enabled explicitly, the language name should be displayed even when
        // the keyboard language and the system language are equal.
        mIsSystemLanguageSameAsInputLanguage = implicitlyEnabledSubtype;
    }
}
+5 −17
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import com.android.inputmethod.keyboard.internal.LanguageOnSpacebarHelper;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;

import java.util.List;
import java.util.Locale;

import javax.annotation.Nonnull;

@@ -69,28 +68,17 @@ public final class SubtypeSwitcher {
    public void updateParametersOnStartInputView() {
        final List<InputMethodSubtype> enabledSubtypesOfThisIme =
                mRichImm.getMyEnabledInputMethodSubtypeList(true);
        mLanguageOnSpacebarHelper.updateEnabledSubtypes(enabledSubtypesOfThisIme);
        mLanguageOnSpacebarHelper.onUpdateEnabledSubtypes(enabledSubtypesOfThisIme);
        mRichImm.updateShortcutIME();
    }

    // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function.
    public void onSubtypeChanged(@Nonnull final InputMethodSubtype newSubtype) {
        final RichInputMethodSubtype richSubtype = mRichImm.onSubtypeChanged(newSubtype);
        final Locale[] newLocales = richSubtype.getLocales();
        if (newLocales.length > 1) {
            // In multi-locales mode, the system language is never the same as the input language
            // because there is no single input language.
            mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(false);
        } else {
            final Locale newLocale = newLocales[0];
            final Locale systemLocale = mResources.getConfiguration().locale;
            final boolean sameLocale = systemLocale.equals(newLocale);
            final boolean sameLanguage = systemLocale.getLanguage().equals(newLocale.getLanguage());
            final boolean implicitlyEnabled = mRichImm
        final boolean implicitlyEnabledSubtype = mRichImm
                .checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(newSubtype);
            mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(
                    sameLocale || (sameLanguage && implicitlyEnabled));
        }
        mLanguageOnSpacebarHelper.onSubtypeChanged(
                richSubtype, implicitlyEnabledSubtype, mResources.getConfiguration().locale);
        mRichImm.updateShortcutIME();
    }

+4 −8
Original line number Diff line number Diff line
@@ -89,19 +89,15 @@ public class LanguageOnSpacebarHelperTests extends AndroidTestCase {
        for (final RichInputMethodSubtype subtype : subtypes) {
            enabledSubtypes.add(subtype.getRawSubtype());
        }
        mLanguageOnSpacebarHelper.updateEnabledSubtypes(enabledSubtypes);
        mLanguageOnSpacebarHelper.onUpdateEnabledSubtypes(enabledSubtypes);
    }

    private void assertFormatType(final RichInputMethodSubtype subtype,
            final boolean implicitlyEnabledSubtype, final Locale systemLocale,
            final int expectedFormat) {
        final Locale newLocale = subtype.getLocales()[0];
        final boolean sameLocale = systemLocale.equals(newLocale);
        final boolean sameLanguage = systemLocale.getLanguage().equals(newLocale.getLanguage());
        mLanguageOnSpacebarHelper.updateIsSystemLanguageSameAsInputLanguage(
                sameLocale || (sameLanguage && implicitlyEnabledSubtype));
        assertEquals(newLocale + " implicitly=" + implicitlyEnabledSubtype + " in " + systemLocale,
                expectedFormat,
        mLanguageOnSpacebarHelper.onSubtypeChanged(subtype, implicitlyEnabledSubtype, systemLocale);
        assertEquals(subtype.getLocales()[0] + " implicitly=" + implicitlyEnabledSubtype
                + " in " + systemLocale, expectedFormat,
                mLanguageOnSpacebarHelper.getLanguageOnSpacebarFormatType(subtype));
    }