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

Commit 8b56597d authored by Zoey Chen's avatar Zoey Chen
Browse files

[Settings] Refactor: deprecate LocalePickerWithRegion and add a new interface for LocaleCollector

Bug: 377664066
Flag: EXEMPT refactor

Change-Id: I206ea81fc7dffde1c93b0f20065ab375fcd14ee0
parent a9c33352
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import java.util.Set;
import java.util.stream.Collectors;

/** The Locale data collector for per-app language. */
public class AppLocaleCollector implements LocalePickerWithRegion.LocaleCollectorBase {
public class AppLocaleCollector implements LocaleCollectorBase {
    private static final String TAG = AppLocaleCollector.class.getSimpleName();
    private final Context mContext;
    private final String mAppPackageName;
@@ -167,8 +167,8 @@ public class AppLocaleCollector implements LocalePickerWithRegion.LocaleCollecto
    }

    @Override
    public HashSet<String> getIgnoredLocaleList(boolean translatedOnly) {
        HashSet<String> langTagsToIgnore = new HashSet<>();
    public Set<String> getIgnoredLocaleList(boolean translatedOnly) {
        Set<String> langTagsToIgnore = new HashSet<>();

        if (mAppCurrentLocale != null) {
            langTagsToIgnore.add(mAppCurrentLocale.getLocale().toLanguageTag());
+36 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2024 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.internal.app;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * The interface which provides the locale list.
 */
public interface LocaleCollectorBase {

    /** Gets the ignored locale list. */
    Set<String> getIgnoredLocaleList(boolean translatedOnly);

    /** Gets the supported locale list. */
    Set<LocaleStore.LocaleInfo> getSupportedLocaleList(LocaleStore.LocaleInfo parent,
            boolean translatedOnly, boolean isForCountryMode);

    /** Indicates if the class work for specific package. */
    boolean hasSpecificPackageName();
}
+3 −15
Original line number Diff line number Diff line
@@ -44,7 +44,10 @@ import java.util.Set;
 * <p>It shows suggestions at the top, then the rest of the locales.
 * Allows the user to search for locales using both their native name and their name in the
 * default locale.</p>
 *
 * @deprecated use SettingLib's widget instead of customized UIs.
 */
@Deprecated
public class LocalePickerWithRegion extends ListFragment implements SearchView.OnQueryTextListener {
    private static final String TAG = LocalePickerWithRegion.class.getSimpleName();
    private static final String PARENT_FRAGMENT_NAME = "localeListEditor";
@@ -78,21 +81,6 @@ public class LocalePickerWithRegion extends ListFragment implements SearchView.O
        default void onParentLocaleSelected(LocaleStore.LocaleInfo locale) {}
    }

    /**
     * The interface which provides the locale list.
     */
    interface LocaleCollectorBase {
        /** Gets the ignored locale list. */
        HashSet<String> getIgnoredLocaleList(boolean translatedOnly);

        /** Gets the supported locale list. */
        Set<LocaleStore.LocaleInfo> getSupportedLocaleList(LocaleStore.LocaleInfo parent,
                boolean translatedOnly, boolean isForCountryMode);

        /** Indicates if the class work for specific package. */
        boolean hasSpecificPackageName();
    }

    private static LocalePickerWithRegion createNumberingSystemPicker(
            LocaleSelectedListener listener, LocaleStore.LocaleInfo parent,
            boolean translatedOnly, OnActionExpandListener onActionExpandListener,
+4 −4
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import java.util.HashSet;
import java.util.Set;

/** The Locale data collector for System language. */
class SystemLocaleCollector implements LocalePickerWithRegion.LocaleCollectorBase {
public class SystemLocaleCollector implements LocaleCollectorBase {
    private final Context mContext;
    private LocaleList mExplicitLocales;

@@ -32,14 +32,14 @@ class SystemLocaleCollector implements LocalePickerWithRegion.LocaleCollectorBas
        this(context, null);
    }

    SystemLocaleCollector(Context context, LocaleList explicitLocales) {
    public SystemLocaleCollector(Context context, LocaleList explicitLocales) {
        mContext = context;
        mExplicitLocales = explicitLocales;
    }

    @Override
    public HashSet<String> getIgnoredLocaleList(boolean translatedOnly) {
        HashSet<String> ignoreList = new HashSet<>();
    public Set<String> getIgnoredLocaleList(boolean translatedOnly) {
        Set<String> ignoreList = new HashSet<>();
        if (!translatedOnly) {
            final LocaleList userLocales = LocalePicker.getLocales();
            final String[] langTags = userLocales.toLanguageTags().split(",");