Merge "[Settings] Refactor: Add LocalePickerBaseListPreferenceController" into main
This commit is contained in:
@@ -71,6 +71,7 @@ import java.util.Locale;
|
|||||||
public class LocaleListEditor extends RestrictedSettingsFragment implements View.OnTouchListener {
|
public class LocaleListEditor extends RestrictedSettingsFragment implements View.OnTouchListener {
|
||||||
protected static final String INTENT_LOCALE_KEY = "localeInfo";
|
protected static final String INTENT_LOCALE_KEY = "localeInfo";
|
||||||
protected static final String EXTRA_SYSTEM_LOCALE_DIALOG_TYPE = "system_locale_dialog_type";
|
protected static final String EXTRA_SYSTEM_LOCALE_DIALOG_TYPE = "system_locale_dialog_type";
|
||||||
|
protected static final String EXTRA_RESULT_LOCALE = "result_locale";
|
||||||
protected static final String LOCALE_SUGGESTION = "locale_suggestion";
|
protected static final String LOCALE_SUGGESTION = "locale_suggestion";
|
||||||
|
|
||||||
private static final String TAG = LocaleListEditor.class.getSimpleName();
|
private static final String TAG = LocaleListEditor.class.getSimpleName();
|
||||||
|
@@ -21,7 +21,7 @@ import com.android.internal.app.LocaleStore;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Interface for when locale list changes in SearchView . */
|
/** Interface for when locale list changes in SearchView. */
|
||||||
public interface LocaleListSearchCallback {
|
public interface LocaleListSearchCallback {
|
||||||
|
|
||||||
/** Callback method for searching changes. */
|
/** Callback method for searching changes. */
|
||||||
|
@@ -16,13 +16,17 @@
|
|||||||
|
|
||||||
package com.android.settings.localepicker;
|
package com.android.settings.localepicker;
|
||||||
|
|
||||||
|
import static com.android.settings.localepicker.LocaleListEditor.EXTRA_RESULT_LOCALE;
|
||||||
|
import static com.android.settings.localepicker.RegionAndNumberingSystemPickerFragment.EXTRA_IS_NUMBERING_SYSTEM;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.LocaleList;
|
import android.os.LocaleList;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
@@ -30,7 +34,10 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.internal.app.LocaleCollectorBase;
|
import com.android.internal.app.LocaleCollectorBase;
|
||||||
import com.android.internal.app.LocaleHelper;
|
import com.android.internal.app.LocaleHelper;
|
||||||
import com.android.internal.app.LocaleStore;
|
import com.android.internal.app.LocaleStore;
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
|
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -43,40 +50,27 @@ import java.util.stream.Collectors;
|
|||||||
/** A base controller for handling locale controllers. */
|
/** A base controller for handling locale controllers. */
|
||||||
public abstract class LocalePickerBaseListPreferenceController extends
|
public abstract class LocalePickerBaseListPreferenceController extends
|
||||||
BasePreferenceController implements LocaleListSearchCallback {
|
BasePreferenceController implements LocaleListSearchCallback {
|
||||||
|
|
||||||
private static final String TAG = "LocalePickerBaseListPreference";
|
private static final String TAG = "LocalePickerBaseListPreference";
|
||||||
private static final String KEY_SUGGESTED = "suggested";
|
private static final String KEY_SUGGESTED = "suggested";
|
||||||
|
private static final String KEY_SUPPORTED = "supported";
|
||||||
|
|
||||||
private PreferenceCategory mPreferenceCategory;
|
private PreferenceCategory mPreferenceCategory;
|
||||||
private LocaleList mExplicitLocales;
|
|
||||||
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
||||||
private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
||||||
private Map<String, Preference> mPreferences;
|
private Map<String, Preference> mPreferences;
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
private boolean mCountryMode;
|
private boolean mIsCountryMode;
|
||||||
|
@Nullable private LocaleStore.LocaleInfo mParentLocale;
|
||||||
|
|
||||||
public LocalePickerBaseListPreferenceController(@NonNull Context context,
|
public LocalePickerBaseListPreferenceController(@NonNull Context context,
|
||||||
@NonNull String preferenceKey) {
|
@NonNull String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
// TODO: Should get extra from fragment.
|
|
||||||
// if (isDeviceDemoMode()) {
|
|
||||||
// Bundle bundle = preference.getExtras();
|
|
||||||
// mExplicitLocales = bundle == null
|
|
||||||
// ? null
|
|
||||||
// : bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
|
|
||||||
// Log.d(TAG, "Has explicit locales : " + mExplicitLocales);
|
|
||||||
// }
|
|
||||||
mLocaleList = getLocaleCollectorController(context).getSupportedLocaleList(null,
|
mLocaleList = getLocaleCollectorController(context).getSupportedLocaleList(null,
|
||||||
false, false);
|
false, false);
|
||||||
mLocaleOptions = new ArrayList<>(mLocaleList.size());
|
mLocaleOptions = new ArrayList<>(mLocaleList.size());
|
||||||
mPreferences = new ArrayMap<>();
|
mPreferences = new ArrayMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDeviceDemoMode() {
|
|
||||||
return Settings.Global.getInt(
|
|
||||||
mContext.getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 0) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
@@ -91,8 +85,21 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<LocaleStore.LocaleInfo> result;
|
List<LocaleStore.LocaleInfo> result;
|
||||||
|
mParentLocale = getParentLocale();
|
||||||
|
if (mParentLocale != null) {
|
||||||
|
mIsCountryMode = true;
|
||||||
|
mLocaleList = getLocaleCollectorController(mContext).getSupportedLocaleList(
|
||||||
|
mParentLocale, false, mIsCountryMode);
|
||||||
|
mLocaleOptions = new ArrayList<>(mLocaleList.size());
|
||||||
|
if (!getPreferenceCategoryKey().contains(KEY_SUGGESTED)) {
|
||||||
|
mPreferenceCategory.setTitle(
|
||||||
|
mContext.getString(R.string.all_supported_locales_regions_title));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = getSortedLocaleList(
|
result = getSortedLocaleList(
|
||||||
getPreferenceCategoryKey().contains(KEY_SUGGESTED) ? getSuggestedLocaleList()
|
getPreferenceCategoryKey().contains(KEY_SUGGESTED)
|
||||||
|
? getSuggestedLocaleList()
|
||||||
: getSupportedLocaleList());
|
: getSupportedLocaleList());
|
||||||
|
|
||||||
final Map<String, Preference> existingPreferences = mPreferences;
|
final Map<String, Preference> existingPreferences = mPreferences;
|
||||||
@@ -113,12 +120,7 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
newList = getSortedSuggestedLocaleFromSearchList(
|
newList = getSortedSuggestedLocaleFromSearchList(
|
||||||
newList, getSuggestedLocaleList());
|
newList, getSuggestedLocaleList());
|
||||||
}
|
}
|
||||||
if (!newList.isEmpty()) {
|
setupPreference(newList, existingPreferences);
|
||||||
mPreferenceCategory.setVisible(true);
|
|
||||||
setupPreference(newList, existingPreferences);
|
|
||||||
} else {
|
|
||||||
mPreferenceCategory.setVisible(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<LocaleStore.LocaleInfo> getSortedSuggestedLocaleFromSearchList(
|
private List<LocaleStore.LocaleInfo> getSortedSuggestedLocaleFromSearchList(
|
||||||
@@ -138,6 +140,12 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
|
|
||||||
private void setupPreference(List<LocaleStore.LocaleInfo> localeInfoList,
|
private void setupPreference(List<LocaleStore.LocaleInfo> localeInfoList,
|
||||||
Map<String, Preference> existingPreferences) {
|
Map<String, Preference> existingPreferences) {
|
||||||
|
Log.d(TAG, "setupPreference: isNumberingMode = " + isNumberingMode());
|
||||||
|
if (isNumberingMode() && getPreferenceCategoryKey().contains(KEY_SUPPORTED)) {
|
||||||
|
mPreferenceCategory.setTitle(
|
||||||
|
mContext.getString(R.string.all_supported_numbering_system_title));
|
||||||
|
}
|
||||||
|
|
||||||
localeInfoList.stream().forEach(locale ->
|
localeInfoList.stream().forEach(locale ->
|
||||||
{
|
{
|
||||||
Preference pref = existingPreferences.remove(locale.getId());
|
Preference pref = existingPreferences.remove(locale.getId());
|
||||||
@@ -146,15 +154,16 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
mPreferenceCategory.addPreference(pref);
|
mPreferenceCategory.addPreference(pref);
|
||||||
}
|
}
|
||||||
String localeName =
|
String localeName =
|
||||||
mCountryMode ? locale.getFullCountryNameNative() : locale.getFullNameNative();
|
mIsCountryMode ? locale.getFullCountryNameNative() : locale.getFullNameNative();
|
||||||
pref.setTitle(localeName);
|
pref.setTitle(localeName);
|
||||||
pref.setKey(locale.toString());
|
pref.setKey(locale.toString());
|
||||||
pref.setOnPreferenceClickListener(clickedPref -> {
|
pref.setOnPreferenceClickListener(clickedPref -> {
|
||||||
// TODO: Click locale to show region or numbering system page if needed.
|
switchFragment(locale);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
mPreferences.put(locale.getId(), pref);
|
mPreferences.put(locale.getId(), pref);
|
||||||
});
|
});
|
||||||
|
mPreferenceCategory.setVisible(mPreferenceCategory.getPreferenceCount() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -166,14 +175,16 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
|
|
||||||
protected abstract LocaleCollectorBase getLocaleCollectorController(Context context);
|
protected abstract LocaleCollectorBase getLocaleCollectorController(Context context);
|
||||||
|
|
||||||
|
@Nullable protected abstract LocaleStore.LocaleInfo getParentLocale();
|
||||||
|
|
||||||
|
protected abstract boolean isNumberingMode();
|
||||||
|
|
||||||
|
@Nullable protected abstract LocaleList getExplicitLocaleList();
|
||||||
|
|
||||||
protected String getPackageName() {
|
protected String getPackageName() {
|
||||||
return mPackageName;
|
return mPackageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected LocaleList getExplicitLocaleList() {
|
|
||||||
return mExplicitLocales;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<LocaleStore.LocaleInfo> getSuggestedLocaleList() {
|
protected List<LocaleStore.LocaleInfo> getSuggestedLocaleList() {
|
||||||
mLocaleOptions.clear();
|
mLocaleOptions.clear();
|
||||||
if (mLocaleList != null && !mLocaleList.isEmpty()) {
|
if (mLocaleList != null && !mLocaleList.isEmpty()) {
|
||||||
@@ -203,8 +214,46 @@ public abstract class LocalePickerBaseListPreferenceController extends
|
|||||||
List<LocaleStore.LocaleInfo> localeInfos) {
|
List<LocaleStore.LocaleInfo> localeInfos) {
|
||||||
final Locale sortingLocale = Locale.getDefault();
|
final Locale sortingLocale = Locale.getDefault();
|
||||||
final LocaleHelper.LocaleInfoComparator comp =
|
final LocaleHelper.LocaleInfoComparator comp =
|
||||||
new LocaleHelper.LocaleInfoComparator(sortingLocale, mCountryMode);
|
new LocaleHelper.LocaleInfoComparator(sortingLocale, mIsCountryMode);
|
||||||
Collections.sort(localeInfos, comp);
|
Collections.sort(localeInfos, comp);
|
||||||
return localeInfos;
|
return localeInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void switchFragment(LocaleStore.LocaleInfo localeInfo) {
|
||||||
|
boolean shouldShowLocaleEditor = shouldShowLocaleEditor(localeInfo);
|
||||||
|
String extraKey = shouldShowLocaleEditor ? LocaleListEditor.INTENT_LOCALE_KEY
|
||||||
|
: RegionAndNumberingSystemPickerFragment.EXTRA_TARGET_LOCALE;
|
||||||
|
String fragmentName = shouldShowLocaleEditor ? LocaleListEditor.class.getCanonicalName()
|
||||||
|
: RegionAndNumberingSystemPickerFragment.class.getCanonicalName();
|
||||||
|
|
||||||
|
final Bundle extra = new Bundle();
|
||||||
|
extra.putSerializable(extraKey, localeInfo);
|
||||||
|
extra.putBoolean(EXTRA_IS_NUMBERING_SYSTEM, localeInfo.hasNumberingSystems());
|
||||||
|
if (shouldShowLocaleEditor) {
|
||||||
|
extra.putBoolean(EXTRA_RESULT_LOCALE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
new SubSettingLauncher(mContext)
|
||||||
|
.setDestination(fragmentName)
|
||||||
|
.setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN)
|
||||||
|
.setArguments(extra)
|
||||||
|
.launch();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldShowLocaleEditor(LocaleStore.LocaleInfo localeInfo) {
|
||||||
|
boolean isSystemLocale = localeInfo.isSystemLocale();
|
||||||
|
boolean isRegionLocale = localeInfo.getParent() != null;
|
||||||
|
boolean mayHaveDifferentNumberingSystem = localeInfo.hasNumberingSystems();
|
||||||
|
mLocaleList = getLocaleCollectorController(mContext).getSupportedLocaleList(localeInfo,
|
||||||
|
false, localeInfo != null);
|
||||||
|
Log.d(TAG,
|
||||||
|
"shouldShowLocaleEditor: isSystemLocale = " + isSystemLocale + ", isRegionLocale = "
|
||||||
|
+ isRegionLocale + ", mayHaveDifferentNumberingSystem = "
|
||||||
|
+ mayHaveDifferentNumberingSystem + ", isSuggested = "
|
||||||
|
+ localeInfo.isSuggested() + ", isNumberingMode = " + isNumberingMode());
|
||||||
|
|
||||||
|
return mLocaleList.size() == 1 || isSystemLocale || localeInfo.isSuggested()
|
||||||
|
|| (isRegionLocale && !mayHaveDifferentNumberingSystem)
|
||||||
|
|| isNumberingMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -55,19 +55,41 @@ import java.util.Set;
|
|||||||
* default locale.</p>
|
* default locale.</p>
|
||||||
*/
|
*/
|
||||||
public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
|
public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
|
||||||
private static final String TAG = "RegionAndNumberingSystemPickerFragment";
|
|
||||||
|
|
||||||
|
public static final String EXTRA_TARGET_LOCALE = "extra_target_locale";
|
||||||
|
public static final String EXTRA_IS_NUMBERING_SYSTEM = "extra_is_numbering_system";
|
||||||
|
|
||||||
|
private static final String TAG = "RegionAndNumberingSystemPickerFragment";
|
||||||
|
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_LIST = "system_locale_list";
|
||||||
|
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST =
|
||||||
|
"system_locale_suggested_list";
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private SystemLocaleAllListPreferenceController mSystemLocaleAllListPreferenceController;
|
||||||
|
@Nullable
|
||||||
|
private SystemLocaleSuggestedListPreferenceController mSuggestedListPreferenceController;
|
||||||
|
@Nullable
|
||||||
|
private LocaleStore.LocaleInfo mLocaleInfo;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private AppBarLayout mAppBarLayout;
|
private AppBarLayout mAppBarLayout;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
|
private boolean mIsNumberingMode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@NonNull Bundle icicle) {
|
public void onCreate(@NonNull Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
if (mActivity.isFinishing()) {
|
if (mActivity == null || mActivity.isFinishing()) {
|
||||||
|
Log.d(TAG, "onCreate, no activity or activity is finishing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mLocaleInfo == null) {
|
||||||
|
Log.d(TAG, "onCreate, can not get localeInfo");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mActivity.setTitle(mLocaleInfo.getFullNameNative());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -102,8 +124,15 @@ public class RegionAndNumberingSystemPickerFragment extends DashboardFragment {
|
|||||||
private List<AbstractPreferenceController> buildPreferenceControllers(
|
private List<AbstractPreferenceController> buildPreferenceControllers(
|
||||||
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
|
mLocaleInfo = (LocaleStore.LocaleInfo) getArguments().getSerializable(EXTRA_TARGET_LOCALE);
|
||||||
// TODO: b/30358431 - Add preference of region locales.
|
mIsNumberingMode = getArguments().getBoolean(EXTRA_IS_NUMBERING_SYSTEM);
|
||||||
|
mSuggestedListPreferenceController = new SystemLocaleSuggestedListPreferenceController(
|
||||||
|
context, KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST, mLocaleInfo,
|
||||||
|
mIsNumberingMode);
|
||||||
|
mSystemLocaleAllListPreferenceController = new SystemLocaleAllListPreferenceController(
|
||||||
|
context, KEY_PREFERENCE_SYSTEM_LOCALE_LIST, mLocaleInfo, mIsNumberingMode);
|
||||||
|
controllers.add(mSuggestedListPreferenceController);
|
||||||
|
controllers.add(mSystemLocaleAllListPreferenceController);
|
||||||
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,87 @@
|
|||||||
|
/**
|
||||||
|
* 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.settings.localepicker;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
|
||||||
|
import com.android.internal.app.LocaleCollectorBase;
|
||||||
|
import com.android.internal.app.LocaleStore;
|
||||||
|
import com.android.internal.app.SystemLocaleCollector;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class SystemLocaleAllListPreferenceController extends
|
||||||
|
LocalePickerBaseListPreferenceController {
|
||||||
|
private static final String KEY_PREFERENCE_CATEGORY_ADD_LANGUAGE_ALL_SUPPORTED =
|
||||||
|
"system_language_all_supported_category";
|
||||||
|
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_LIST = "system_locale_list";
|
||||||
|
|
||||||
|
private boolean mIsNumberingSystemMode;
|
||||||
|
@Nullable private LocaleStore.LocaleInfo mLocaleInfo;
|
||||||
|
@Nullable private LocaleList mExplicitLocales;
|
||||||
|
|
||||||
|
public SystemLocaleAllListPreferenceController(@NonNull Context context,
|
||||||
|
@NonNull String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemLocaleAllListPreferenceController(@NonNull Context context,
|
||||||
|
@NonNull String preferenceKey, @NonNull LocaleStore.LocaleInfo parentLocale,
|
||||||
|
boolean isNumberingSystemMode) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mLocaleInfo = parentLocale;
|
||||||
|
mIsNumberingSystemMode = isNumberingSystemMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemLocaleAllListPreferenceController(@NonNull Context context,
|
||||||
|
@NonNull String preferenceKey, @Nullable LocaleList explicitLocales) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mExplicitLocales = explicitLocales;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPreferenceCategoryKey() {
|
||||||
|
return KEY_PREFERENCE_CATEGORY_ADD_LANGUAGE_ALL_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getPreferenceKey() {
|
||||||
|
return KEY_PREFERENCE_SYSTEM_LOCALE_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LocaleCollectorBase getLocaleCollectorController(Context context) {
|
||||||
|
return new SystemLocaleCollector(context, getExplicitLocaleList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @Nullable LocaleStore.LocaleInfo getParentLocale() {
|
||||||
|
return mLocaleInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isNumberingMode() {
|
||||||
|
return mIsNumberingSystemMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @Nullable LocaleList getExplicitLocaleList() {
|
||||||
|
return mExplicitLocales;
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,8 @@ import android.app.Activity;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -48,8 +50,6 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -68,12 +68,24 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
private static final String TAG = "SystemLocalePickerFragment";
|
private static final String TAG = "SystemLocalePickerFragment";
|
||||||
private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
private static final String EXTRA_EXPAND_SEARCH_VIEW = "expand_search_view";
|
||||||
|
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_LIST = "system_locale_list";
|
||||||
|
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST =
|
||||||
|
"system_locale_suggested_list";
|
||||||
|
|
||||||
@Nullable private SearchView mSearchView = null;
|
@Nullable
|
||||||
@Nullable private SearchFilter mSearchFilter = null;
|
private SearchView mSearchView = null;
|
||||||
@Nullable private Set<LocaleStore.LocaleInfo> mLocaleList;
|
@Nullable
|
||||||
@Nullable private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
private SearchFilter mSearchFilter = null;
|
||||||
@Nullable private List<LocaleStore.LocaleInfo> mOriginalLocaleInfos;
|
@Nullable
|
||||||
|
private Set<LocaleStore.LocaleInfo> mLocaleList;
|
||||||
|
@Nullable
|
||||||
|
private List<LocaleStore.LocaleInfo> mLocaleOptions;
|
||||||
|
@Nullable
|
||||||
|
private List<LocaleStore.LocaleInfo> mOriginalLocaleInfos;
|
||||||
|
@Nullable
|
||||||
|
private SystemLocaleAllListPreferenceController mSystemLocaleAllListPreferenceController;
|
||||||
|
@Nullable
|
||||||
|
private SystemLocaleSuggestedListPreferenceController mSuggestedListPreferenceController;
|
||||||
private AppBarLayout mAppBarLayout;
|
private AppBarLayout mAppBarLayout;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
@@ -138,12 +150,16 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void filterSearch(@Nullable String query) {
|
private void filterSearch(@Nullable String query) {
|
||||||
|
if (mSystemLocaleAllListPreferenceController == null) {
|
||||||
|
Log.d(TAG, "filterSearch(), can not get preference.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mSearchFilter == null) {
|
if (mSearchFilter == null) {
|
||||||
mSearchFilter = new SearchFilter();
|
mSearchFilter = new SearchFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: b/30358431 - Add preference of system locales.
|
mOriginalLocaleInfos = mSystemLocaleAllListPreferenceController.getSupportedLocaleList();
|
||||||
// mOriginalLocaleInfos = mSystemLocaleAllListPreferenceController.getSupportedLocaleList();
|
|
||||||
// If we haven't load apps list completely, don't filter anything.
|
// If we haven't load apps list completely, don't filter anything.
|
||||||
if (mOriginalLocaleInfos == null) {
|
if (mOriginalLocaleInfos == null) {
|
||||||
Log.w(TAG, "Locales haven't loaded completely yet, so nothing can be filtered");
|
Log.w(TAG, "Locales haven't loaded completely yet, so nothing can be filtered");
|
||||||
@@ -195,14 +211,19 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||||
|
if (mSystemLocaleAllListPreferenceController == null
|
||||||
|
|| mSuggestedListPreferenceController == null) {
|
||||||
|
Log.d(TAG, "publishResults(), can not get preference.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mLocaleOptions = (ArrayList<LocaleStore.LocaleInfo>) results.values;
|
mLocaleOptions = (ArrayList<LocaleStore.LocaleInfo>) results.values;
|
||||||
// Need to scroll to first preference when searching.
|
// Need to scroll to first preference when searching.
|
||||||
if (mRecyclerView != null) {
|
if (mRecyclerView != null) {
|
||||||
mRecyclerView.post(() -> mRecyclerView.scrollToPosition(0));
|
mRecyclerView.post(() -> mRecyclerView.scrollToPosition(0));
|
||||||
}
|
}
|
||||||
// TODO: b/30358431 - Add preference of system locales.
|
mSystemLocaleAllListPreferenceController.onSearchListChanged(mLocaleOptions);
|
||||||
// mSystemLocaleAllListPreferenceController.onSearchListChanged(mLocaleOptions);
|
mSuggestedListPreferenceController.onSearchListChanged(mLocaleOptions);
|
||||||
// mSuggestedListPreferenceController.onSearchListChanged(mLocaleOptions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: decide if this is enough, or we want to use a BreakIterator...
|
// TODO: decide if this is enough, or we want to use a BreakIterator...
|
||||||
@@ -271,11 +292,31 @@ public class SystemLocalePickerFragment extends DashboardFragment implements
|
|||||||
|
|
||||||
private List<AbstractPreferenceController> buildPreferenceControllers(
|
private List<AbstractPreferenceController> buildPreferenceControllers(
|
||||||
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
@NonNull Context context, @Nullable Lifecycle lifecycle) {
|
||||||
|
LocaleList explicitLocales = null;
|
||||||
|
if (isDeviceDemoMode()) {
|
||||||
|
Bundle bundle = getIntent().getExtras();
|
||||||
|
explicitLocales = bundle == null
|
||||||
|
? null
|
||||||
|
: bundle.getParcelable(Settings.EXTRA_EXPLICIT_LOCALES, LocaleList.class);
|
||||||
|
Log.i(TAG, "Has explicit locales : " + explicitLocales);
|
||||||
|
}
|
||||||
|
mSuggestedListPreferenceController =
|
||||||
|
new SystemLocaleSuggestedListPreferenceController(context,
|
||||||
|
KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST);
|
||||||
|
mSystemLocaleAllListPreferenceController = new SystemLocaleAllListPreferenceController(
|
||||||
|
context, KEY_PREFERENCE_SYSTEM_LOCALE_LIST, explicitLocales);
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
// TODO: b/30358431 - Add preference of system locales.
|
controllers.add(mSuggestedListPreferenceController);
|
||||||
|
controllers.add(mSystemLocaleAllListPreferenceController);
|
||||||
|
|
||||||
return controllers;
|
return controllers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDeviceDemoMode() {
|
||||||
|
return Settings.Global.getInt(
|
||||||
|
getContentResolver(), Settings.Global.DEVICE_DEMO_MODE, 0) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||||
new BaseSearchIndexProvider(R.xml.system_language_picker);
|
new BaseSearchIndexProvider(R.xml.system_language_picker);
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* 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.settings.localepicker;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
|
||||||
|
import com.android.internal.app.LocaleCollectorBase;
|
||||||
|
import com.android.internal.app.LocaleStore;
|
||||||
|
import com.android.internal.app.SystemLocaleCollector;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class SystemLocaleSuggestedListPreferenceController extends
|
||||||
|
LocalePickerBaseListPreferenceController {
|
||||||
|
private static final String KEY_PREFERENCE_CATEGORY_ADD_A_LANGUAGE_SUGGESTED =
|
||||||
|
"system_language_suggested_category";
|
||||||
|
private static final String KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST =
|
||||||
|
"system_locale_suggested_list";
|
||||||
|
|
||||||
|
@Nullable private LocaleStore.LocaleInfo mLocaleInfo;
|
||||||
|
private boolean mIsNumberingSystemMode;
|
||||||
|
|
||||||
|
public SystemLocaleSuggestedListPreferenceController(@NonNull Context context,
|
||||||
|
@NonNull String preferenceKey) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemLocaleSuggestedListPreferenceController(@NonNull Context context,
|
||||||
|
@NonNull String preferenceKey,
|
||||||
|
@NonNull LocaleStore.LocaleInfo parentLocale, boolean isNumberingSystemMode) {
|
||||||
|
super(context, preferenceKey);
|
||||||
|
mLocaleInfo = parentLocale;
|
||||||
|
mIsNumberingSystemMode = isNumberingSystemMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NonNull String getPreferenceCategoryKey() {
|
||||||
|
return KEY_PREFERENCE_CATEGORY_ADD_A_LANGUAGE_SUGGESTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getPreferenceKey() {
|
||||||
|
return KEY_PREFERENCE_SYSTEM_LOCALE_SUGGESTED_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected LocaleCollectorBase getLocaleCollectorController(Context context) {
|
||||||
|
return new SystemLocaleCollector(context, getExplicitLocaleList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @Nullable LocaleStore.LocaleInfo getParentLocale() {
|
||||||
|
return mLocaleInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isNumberingMode() {
|
||||||
|
return mIsNumberingSystemMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @Nullable LocaleList getExplicitLocaleList() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user