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

Commit e9eff660 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Make getLanguageFromLocaleString private

As part of effort to lock down the use of InputMethodUtils only within
the core system components, this CL removes the dependency on
InputMethodUtils#getLanguageFromLocaleString() from the Settings UI
code.

At high level, there should be no user visible behavior change.

Bug: 77730201
Test: atest SettingsLibTests:com.android.settingslib.inputmethod.InputMethodSubtypePreferenceTest
Change-Id: I92cc0b0808f3e40ab92b60ec783ad218141f2bbd
parent 4572d6cb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -583,7 +583,7 @@ public class InputMethodUtils {
     * Returns the language component of a given locale string.
     * TODO: Use {@link Locale#toLanguageTag()} and {@link Locale#forLanguageTag(String)}
     */
    public static String getLanguageFromLocaleString(String locale) {
    private static String getLanguageFromLocaleString(String locale) {
        final int idx = locale.indexOf('_');
        if (idx < 0) {
            return locale;
+5 −6
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ public class InputMethodSubtypePreference extends SwitchWithNoTextPreference {
        this(context,
                imi.getId() + subtype.hashCode(),
                InputMethodAndSubtypeUtil.getSubtypeLocaleNameAsSentence(subtype, context, imi),
                subtype.getLocale(),
                subtype.getLocaleObject(),
                context.getResources().getConfiguration().locale);
    }

@@ -51,20 +51,19 @@ public class InputMethodSubtypePreference extends SwitchWithNoTextPreference {
            final Context context,
            final String prefKey,
            final CharSequence title,
            final String subtypeLocaleString,
            final Locale subtypeLocale,
            final Locale systemLocale) {
        super(context);
        setPersistent(false);
        setKey(prefKey);
        setTitle(title);
        if (TextUtils.isEmpty(subtypeLocaleString)) {
        if (subtypeLocale == null) {
            mIsSystemLocale = false;
            mIsSystemLanguage = false;
        } else {
            mIsSystemLocale = subtypeLocaleString.equals(systemLocale.toString());
            mIsSystemLocale = subtypeLocale.equals(systemLocale);
            mIsSystemLanguage = mIsSystemLocale
                    || InputMethodUtils.getLanguageFromLocaleString(subtypeLocaleString)
                            .equals(systemLocale.getLanguage());
                    || TextUtils.equals(subtypeLocale.getLanguage(), systemLocale.getLanguage());
        }
    }

+5 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settingslib.inputmethod;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;

import org.junit.Test;
import org.junit.runner.RunWith;
@@ -98,11 +99,14 @@ public class InputMethodSubtypePreferenceTest {
            final String subtypeLocaleString,
            final Locale systemLocale) {
        final String key = subtypeName + "-" + subtypeLocaleString + "-" + systemLocale;
        final String subtypeLanguageTag = subtypeLocaleString.replace('_', '-');
        final Locale subtypeLocale = TextUtils.isEmpty(subtypeLanguageTag)
                ? null : Locale.forLanguageTag(subtypeLanguageTag);
        return new InputMethodSubtypePreference(
                InstrumentationRegistry.getTargetContext(),
                key,
                subtypeName,
                subtypeLocaleString,
                subtypeLocale,
                systemLocale);
    }
}