• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2023 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 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 
27 import androidx.annotation.NonNull;
28 import androidx.annotation.Nullable;
29 import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
30 import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.CollectionInfoCompat;
31 import androidx.preference.PreferenceRecyclerViewAccessibilityDelegate;
32 import androidx.recyclerview.widget.RecyclerView;
33 
34 import com.android.settings.R;
35 import com.android.settings.dashboard.DashboardFragment;
36 import com.android.settings.overlay.FeatureFactory;
37 import com.android.settings.search.BaseSearchIndexProvider;
38 import com.android.settingslib.core.AbstractPreferenceController;
39 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
40 import com.android.settingslib.search.SearchIndexable;
41 
42 import java.util.ArrayList;
43 import java.util.Collection;
44 import java.util.List;
45 
46 /** Main fragment to display first day of week. */
47 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
48 public class FirstDayOfWeekItemFragment extends DashboardFragment {
49 
50     private static final String LOG_TAG = "FirstDayOfWeekItemFragment";
51     private static final String KEY_PREFERENCE_CATEGORY_FIRST_DAY_OF_WEEK_ITEM =
52             "first_day_of_week_item_category";
53 
54     @Override
onAttach(@onNull Context context)55     public void onAttach(@NonNull Context context) {
56         super.onAttach(context);
57 
58         MetricsFeatureProvider metricsFeatureProvider =
59                 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
60         String action = getIntent() != null ? getIntent().getAction() : "";
61         if (Settings.ACTION_FIRST_DAY_OF_WEEK_SETTINGS.equals(action)) {
62             metricsFeatureProvider.action(
63                     context, SettingsEnums.ACTION_OPEN_FIRST_DAY_OF_WEEK_OUTSIDE_SETTINGS);
64         }
65     }
66 
67     @NonNull
68     @Override
onCreateRecyclerView( @onNull LayoutInflater inflater, @NonNull ViewGroup parent, @Nullable Bundle savedInstanceState)69     public RecyclerView onCreateRecyclerView(
70             @NonNull LayoutInflater inflater, @NonNull ViewGroup parent,
71             @Nullable Bundle savedInstanceState) {
72 
73         // Talkback shouldn't announce in list numbers
74         final RecyclerView recyclerView =
75                 super.onCreateRecyclerView(inflater, parent, savedInstanceState);
76         recyclerView.setAccessibilityDelegateCompat(
77             new PreferenceRecyclerViewAccessibilityDelegate(recyclerView) {
78                     @Override
79                     public void onInitializeAccessibilityNodeInfo(@NonNull View host,
80                             @NonNull AccessibilityNodeInfoCompat info) {
81                         super.onInitializeAccessibilityNodeInfo(host, info);
82                         int availableCount = (int) getPreferenceControllers()
83                                 .stream()
84                                 .flatMap(Collection::stream)
85                                 .filter(AbstractPreferenceController::isAvailable)
86                                 .count();
87                         info.setCollectionInfo(
88                                 CollectionInfoCompat.obtain(
89                                         /*rowCount=*/availableCount,
90                                         /*columnCount=*/1,
91                                         /*hierarchical=*/false,
92                                         CollectionInfoCompat.SELECTION_MODE_SINGLE)
93                         );
94                     }
95             });
96         return recyclerView;
97     }
98 
99     @Override
getPreferenceScreenResId()100     protected int getPreferenceScreenResId() {
101         return R.xml.regional_preferences_first_day_of_week;
102     }
103 
104     @Override
getMetricsCategory()105     public int getMetricsCategory() {
106         return SettingsEnums.FIRST_DAY_OF_WEEK_PREFERENCE;
107     }
108 
109     @Override
getLogTag()110     protected String getLogTag() {
111         return LOG_TAG;
112     }
113 
114     @Override
createPreferenceControllers(Context context)115     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
116         final List<AbstractPreferenceController> controllers = new ArrayList<>();
117         controllers.add(new FirstDayOfWeekItemCategoryController(context,
118                 KEY_PREFERENCE_CATEGORY_FIRST_DAY_OF_WEEK_ITEM));
119         return controllers;
120     }
121 
122     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
123             new BaseSearchIndexProvider(R.xml.regional_preferences_first_day_of_week);
124 }
125