• 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.settings.SettingsEnums;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.provider.Settings;
23 
24 import androidx.annotation.NonNull;
25 
26 import com.android.internal.app.LocaleStore;
27 import com.android.settings.R;
28 import com.android.settings.dashboard.DashboardFragment;
29 import com.android.settings.flags.Flags;
30 import com.android.settings.overlay.FeatureFactory;
31 import com.android.settings.search.BaseSearchIndexProvider;
32 import com.android.settingslib.core.AbstractPreferenceController;
33 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
34 
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Locale;
38 
39 public class RegionPickerFragment extends DashboardFragment{
40 
41     private static final String TAG = "RegionPickerFragment";
42     private static final String KEY_PREFERENCE_SYSTEM_REGION_LIST = "system_region_list";
43     private static final String KEY_PREFERENCE_SYSTEM_REGION_SUGGESTED_LIST =
44             "system_region_suggested_list";
45 
46     @Override
onCreate(@onNull Bundle icicle)47     public void onCreate(@NonNull Bundle icicle) {
48         super.onCreate(icicle);
49     }
50 
51     @Override
onAttach(@onNull Context context)52     public void onAttach(@NonNull Context context) {
53         super.onAttach(context);
54 
55         MetricsFeatureProvider metricsFeatureProvider =
56                 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
57         String action = getIntent() != null ? getIntent().getAction() : "";
58         if (Settings.ACTION_REGION_SETTINGS.equals(action)) {
59             metricsFeatureProvider.action(
60                     context, SettingsEnums.ACTION_OPEN_REGION_OUTSIDE_SETTINGS);
61         }
62     }
63 
64     @Override
getPreferenceScreenResId()65     protected int getPreferenceScreenResId() {
66         return R.xml.system_region_picker;
67     }
68 
69     @Override
getLogTag()70     protected String getLogTag() {
71         return TAG;
72     }
73 
74     @Override
getMetricsCategory()75     public int getMetricsCategory() {
76         return SettingsEnums.REGION_SETTINGS;
77     }
78 
79     @Override
createPreferenceControllers(Context context)80     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
81         return buildPreferenceControllers(context);
82     }
83 
buildPreferenceControllers( @onNull Context context)84     private List<AbstractPreferenceController> buildPreferenceControllers(
85             @NonNull Context context) {
86         Locale parentLocale = LocaleStore.getLocaleInfo(Locale.getDefault()).getParent();
87         LocaleStore.LocaleInfo parentLocaleInfo = LocaleStore.getLocaleInfo(parentLocale);
88         SystemRegionSuggestedListPreferenceController mSuggestedListPreferenceController =
89                 new SystemRegionSuggestedListPreferenceController(
90                     context, KEY_PREFERENCE_SYSTEM_REGION_SUGGESTED_LIST, parentLocaleInfo);
91         SystemRegionAllListPreferenceController mSystemRegionAllListPreferenceController =
92                 new SystemRegionAllListPreferenceController(
93                     context, KEY_PREFERENCE_SYSTEM_REGION_LIST, parentLocaleInfo);
94         final List<AbstractPreferenceController> controllers = new ArrayList<>();
95         mSuggestedListPreferenceController.setFragment(this);
96         mSystemRegionAllListPreferenceController.setFragment(this);
97         controllers.add(mSuggestedListPreferenceController);
98         controllers.add(mSystemRegionAllListPreferenceController);
99         return controllers;
100     }
101 
102     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
103             new BaseSearchIndexProvider(R.xml.system_region_picker) {
104                 @Override
105                 protected boolean isPageSearchEnabled(Context context) {
106                     if (!Flags.regionalPreferencesApiEnabled()) {
107                         return false;
108                     }
109                     return true;
110                 }
111             };
112 }
113