1 /*
2  * Copyright (C) 2016 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 package com.android.settings.accounts;
17 
18 import static android.provider.Settings.EXTRA_AUTHORITIES;
19 
20 import android.app.settings.SettingsEnums;
21 import android.content.Context;
22 import android.provider.SearchIndexableResource;
23 
24 import com.android.settings.R;
25 import com.android.settings.SettingsPreferenceFragment;
26 import com.android.settings.dashboard.DashboardFragment;
27 import com.android.settings.search.BaseSearchIndexProvider;
28 import com.android.settings.users.AutoSyncDataPreferenceController;
29 import com.android.settings.users.AutoSyncPersonalDataPreferenceController;
30 import com.android.settings.users.AutoSyncWorkDataPreferenceController;
31 import com.android.settingslib.core.AbstractPreferenceController;
32 import com.android.settingslib.search.SearchIndexable;
33 
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 
38 @SearchIndexable
39 public class AccountDashboardFragment extends DashboardFragment {
40 
41     private static final String TAG = "AccountDashboardFrag";
42 
43 
44     @Override
getMetricsCategory()45     public int getMetricsCategory() {
46         return SettingsEnums.ACCOUNT;
47     }
48 
49     @Override
getLogTag()50     protected String getLogTag() {
51         return TAG;
52     }
53 
54     @Override
getPreferenceScreenResId()55     protected int getPreferenceScreenResId() {
56         return R.xml.accounts_dashboard_settings;
57     }
58 
59     @Override
getHelpResource()60     public int getHelpResource() {
61         return R.string.help_url_user_and_account_dashboard;
62     }
63 
64     @Override
createPreferenceControllers(Context context)65     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
66         final String[] authorities = getIntent().getStringArrayExtra(EXTRA_AUTHORITIES);
67         return buildPreferenceControllers(context, this /* parent */, authorities);
68     }
69 
buildPreferenceControllers(Context context, SettingsPreferenceFragment parent, String[] authorities)70     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
71             SettingsPreferenceFragment parent, String[] authorities) {
72         final List<AbstractPreferenceController> controllers = new ArrayList<>();
73 
74         final AccountPreferenceController accountPrefController =
75                 new AccountPreferenceController(context, parent, authorities);
76         if (parent != null) {
77             parent.getSettingsLifecycle().addObserver(accountPrefController);
78         }
79         controllers.add(accountPrefController);
80         controllers.add(new AutoSyncDataPreferenceController(context, parent));
81         controllers.add(new AutoSyncPersonalDataPreferenceController(context, parent));
82         controllers.add(new AutoSyncWorkDataPreferenceController(context, parent));
83         return controllers;
84     }
85 
86     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
87             new BaseSearchIndexProvider() {
88                 @Override
89                 public List<SearchIndexableResource> getXmlResourcesToIndex(
90                         Context context, boolean enabled) {
91                     final SearchIndexableResource sir = new SearchIndexableResource(context);
92                     sir.xmlResId = R.xml.accounts_dashboard_settings;
93                     return Arrays.asList(sir);
94                 }
95 
96                 @Override
97                 public List<AbstractPreferenceController> createPreferenceControllers(
98                         Context context) {
99                     return buildPreferenceControllers(
100                             context, null /* parent */, null /* authorities*/);
101                 }
102             };
103 }