• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.homepage;
18 
19 import static com.android.settings.search.actionbar.SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR;
20 import static com.android.settingslib.search.SearchIndexable.MOBILE;
21 
22 import android.app.settings.SettingsEnums;
23 import android.content.Context;
24 import android.os.Bundle;
25 import android.provider.SearchIndexableResource;
26 
27 import androidx.fragment.app.Fragment;
28 import androidx.preference.Preference;
29 import androidx.preference.PreferenceFragmentCompat;
30 
31 import com.android.settings.R;
32 import com.android.settings.core.SubSettingLauncher;
33 import com.android.settings.dashboard.DashboardFragment;
34 import com.android.settings.search.BaseSearchIndexProvider;
35 import com.android.settings.support.SupportPreferenceController;
36 import com.android.settingslib.core.instrumentation.Instrumentable;
37 import com.android.settingslib.search.SearchIndexable;
38 
39 import java.util.Arrays;
40 import java.util.List;
41 
42 @SearchIndexable(forTarget = MOBILE)
43 public class TopLevelSettings extends DashboardFragment implements
44         PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
45 
46     private static final String TAG = "TopLevelSettings";
47 
TopLevelSettings()48     public TopLevelSettings() {
49         final Bundle args = new Bundle();
50         // Disable the search icon because this page uses a full search view in actionbar.
51         args.putBoolean(NEED_SEARCH_ICON_IN_ACTION_BAR, false);
52         setArguments(args);
53     }
54 
55     @Override
getPreferenceScreenResId()56     protected int getPreferenceScreenResId() {
57         return R.xml.top_level_settings;
58     }
59 
60     @Override
getLogTag()61     protected String getLogTag() {
62         return TAG;
63     }
64 
65     @Override
getMetricsCategory()66     public int getMetricsCategory() {
67         return SettingsEnums.DASHBOARD_SUMMARY;
68     }
69 
70     @Override
onAttach(Context context)71     public void onAttach(Context context) {
72         super.onAttach(context);
73         use(SupportPreferenceController.class).setActivity(getActivity());
74     }
75 
76     @Override
getHelpResource()77     public int getHelpResource() {
78         // Disable the help icon because this page uses a full search view in actionbar.
79         return 0;
80     }
81 
82     @Override
getCallbackFragment()83     public Fragment getCallbackFragment() {
84         return this;
85     }
86 
87     @Override
onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref)88     public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
89         new SubSettingLauncher(getActivity())
90                 .setDestination(pref.getFragment())
91                 .setArguments(pref.getExtras())
92                 .setSourceMetricsCategory(caller instanceof Instrumentable
93                         ? ((Instrumentable) caller).getMetricsCategory()
94                         : Instrumentable.METRICS_CATEGORY_UNKNOWN)
95                 .setTitleRes(-1)
96                 .launch();
97         return true;
98     }
99 
100     @Override
shouldForceRoundedIcon()101     protected boolean shouldForceRoundedIcon() {
102         return getContext().getResources()
103                 .getBoolean(R.bool.config_force_rounded_icon_TopLevelSettings);
104     }
105 
106     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
107             new BaseSearchIndexProvider() {
108                 @Override
109                 public List<SearchIndexableResource> getXmlResourcesToIndex(
110                         Context context, boolean enabled) {
111                     final SearchIndexableResource sir = new SearchIndexableResource(context);
112                     sir.xmlResId = R.xml.top_level_settings;
113                     return Arrays.asList(sir);
114                 }
115 
116                 @Override
117                 protected boolean isPageSearchEnabled(Context context) {
118                     // Never searchable, all entries in this page are already indexed elsewhere.
119                     return false;
120                 }
121             };
122 }
123