• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.regionalpreferences;
18 
19 import android.app.Activity;
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.os.Bundle;
23 import android.os.LocaleList;
24 
25 import androidx.annotation.NonNull;
26 
27 import com.android.internal.app.LocaleStore;
28 import com.android.settings.R;
29 import com.android.settings.dashboard.DashboardFragment;
30 import com.android.settingslib.core.AbstractPreferenceController;
31 
32 import java.util.ArrayList;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Locale;
36 import java.util.Set;
37 
38 /** Provides locale list for numbering system settings. */
39 public class NumberingSystemLocaleListFragment extends DashboardFragment {
40 
41     @Override
onCreate(@onNull Bundle icicle)42     public void onCreate(@NonNull Bundle icicle) {
43         super.onCreate(icicle);
44 
45         if (isEmptyNumberingSystemLocale()) {
46             getActivity().setResult(Activity.RESULT_CANCELED);
47             finish();
48         }
49 
50         getActivity().setTitle(R.string.numbers_preferences_title);
51         getActivity().setResult(Activity.RESULT_OK);
52     }
53 
54     /**
55      * Get a list of {@link AbstractPreferenceController} for this fragment.
56      */
57     @Override
createPreferenceControllers(Context context)58     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
59         NumberingSystemItemController controller =
60                 new NumberingSystemItemController(context, getExtraData());
61         controller.setParentFragment(this);
62         List<AbstractPreferenceController> listControllers = new ArrayList<>();
63         listControllers.add(controller);
64         return listControllers;
65     }
66 
67     @Override
getPreferenceScreenResId()68     protected int getPreferenceScreenResId() {
69         return R.xml.regional_preference_numbering_system_page;
70     }
71 
72     @Override
getLogTag()73     protected String getLogTag() {
74         return NumberingSystemLocaleListFragment.class.getSimpleName();
75     }
76 
77     @Override
getMetricsCategory()78     public int getMetricsCategory() {
79         return SettingsEnums.NUMBERING_SYSTEM_LANGUAGE_SELECTION_PREFERENCE;
80     }
81 
isEmptyNumberingSystemLocale()82     private static boolean isEmptyNumberingSystemLocale() {
83         LocaleList localeList = LocaleList.getDefault();
84         Set<Locale> localesHasNumberingSystems = new HashSet<>();
85         for (int i = 0; i < localeList.size(); i++) {
86             Locale locale = localeList.get(i);
87             LocaleStore.LocaleInfo localeInfo = LocaleStore.getLocaleInfo(locale);
88             if (localeInfo.hasNumberingSystems()) {
89                 localesHasNumberingSystems.add(locale);
90             }
91         }
92         return localesHasNumberingSystems.isEmpty();
93     }
94 
getExtraData()95     private static Bundle getExtraData() {
96         Bundle extra = new Bundle();
97         extra.putString(RegionalPreferencesEntriesFragment.ARG_KEY_REGIONAL_PREFERENCE,
98                 NumberingSystemItemController.ARG_VALUE_LANGUAGE_SELECT);
99         return extra;
100     }
101 }
102