• 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.graphics.drawable.Drawable;
25 import android.os.Bundle;
26 
27 import androidx.fragment.app.Fragment;
28 import androidx.preference.Preference;
29 import androidx.preference.PreferenceFragmentCompat;
30 import androidx.preference.PreferenceScreen;
31 
32 import com.android.settings.R;
33 import com.android.settings.Utils;
34 import com.android.settings.core.SubSettingLauncher;
35 import com.android.settings.dashboard.DashboardFragment;
36 import com.android.settings.search.BaseSearchIndexProvider;
37 import com.android.settings.support.SupportPreferenceController;
38 import com.android.settingslib.core.instrumentation.Instrumentable;
39 import com.android.settingslib.search.SearchIndexable;
40 
41 @SearchIndexable(forTarget = MOBILE)
42 public class TopLevelSettings extends DashboardFragment implements
43         PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
44 
45     private static final String TAG = "TopLevelSettings";
46 
TopLevelSettings()47     public TopLevelSettings() {
48         final Bundle args = new Bundle();
49         // Disable the search icon because this page uses a full search view in actionbar.
50         args.putBoolean(NEED_SEARCH_ICON_IN_ACTION_BAR, false);
51         setArguments(args);
52     }
53 
54     @Override
getPreferenceScreenResId()55     protected int getPreferenceScreenResId() {
56         return R.xml.top_level_settings;
57     }
58 
59     @Override
getLogTag()60     protected String getLogTag() {
61         return TAG;
62     }
63 
64     @Override
getMetricsCategory()65     public int getMetricsCategory() {
66         return SettingsEnums.DASHBOARD_SUMMARY;
67     }
68 
69     @Override
onAttach(Context context)70     public void onAttach(Context context) {
71         super.onAttach(context);
72         use(SupportPreferenceController.class).setActivity(getActivity());
73     }
74 
75     @Override
getHelpResource()76     public int getHelpResource() {
77         // Disable the help icon because this page uses a full search view in actionbar.
78         return 0;
79     }
80 
81     @Override
getCallbackFragment()82     public Fragment getCallbackFragment() {
83         return this;
84     }
85 
86     @Override
onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref)87     public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
88         new SubSettingLauncher(getActivity())
89                 .setDestination(pref.getFragment())
90                 .setArguments(pref.getExtras())
91                 .setSourceMetricsCategory(caller instanceof Instrumentable
92                         ? ((Instrumentable) caller).getMetricsCategory()
93                         : Instrumentable.METRICS_CATEGORY_UNKNOWN)
94                 .setTitleRes(-1)
95                 .launch();
96         return true;
97     }
98 
99     @Override
onCreatePreferences(Bundle savedInstanceState, String rootKey)100     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
101         super.onCreatePreferences(savedInstanceState, rootKey);
102         final PreferenceScreen screen = getPreferenceScreen();
103         if (screen == null) {
104             return;
105         }
106         // Tint the homepage icons
107         final int tintColor = Utils.getHomepageIconColor(getContext());
108         final int count = screen.getPreferenceCount();
109         for (int i = 0; i < count; i++) {
110             final Preference preference = screen.getPreference(i);
111             if (preference == null) {
112                 break;
113             }
114             final Drawable icon = preference.getIcon();
115             if (icon != null) {
116                 icon.setTint(tintColor);
117             }
118         }
119     }
120 
121     @Override
shouldForceRoundedIcon()122     protected boolean shouldForceRoundedIcon() {
123         return getContext().getResources()
124                 .getBoolean(R.bool.config_force_rounded_icon_TopLevelSettings);
125     }
126 
127     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
128             new BaseSearchIndexProvider(R.xml.top_level_settings) {
129 
130                 @Override
131                 protected boolean isPageSearchEnabled(Context context) {
132                     // Never searchable, all entries in this page are already indexed elsewhere.
133                     return false;
134                 }
135             };
136 }
137