AppAndNotificationDashboardFragment.java revision ae2f2b5268e19423b85a5a8da86fc559b74143d6
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
17package com.android.settings.applications;
18
19import android.app.Activity;
20import android.app.Application;
21import android.app.Fragment;
22import android.content.Context;
23import android.provider.SearchIndexableResource;
24
25import com.android.internal.logging.nano.MetricsProto;
26import com.android.settings.R;
27import com.android.settings.core.PreferenceController;
28import com.android.settings.dashboard.DashboardFragment;
29import com.android.settings.search.BaseSearchIndexProvider;
30
31import java.util.ArrayList;
32import java.util.Arrays;
33import java.util.List;
34
35public class AppAndNotificationDashboardFragment extends DashboardFragment {
36
37    private static final String TAG = "AppAndNotifDashboard";
38
39    @Override
40    public int getMetricsCategory() {
41        return MetricsProto.MetricsEvent.SETTINGS_APP_NOTIF_CATEGORY;
42    }
43
44    @Override
45    protected String getLogTag() {
46        return TAG;
47    }
48
49    @Override
50    public void onAttach(Context context) {
51        super.onAttach(context);
52        mProgressiveDisclosureMixin.setTileLimit(3);
53    }
54
55    @Override
56    protected int getPreferenceScreenResId() {
57        return R.xml.app_and_notification;
58    }
59
60    @Override
61    protected List<PreferenceController> getPreferenceControllers(Context context) {
62        final Activity activity = getActivity();
63        final Application app;
64        if (activity != null) {
65            app = activity.getApplication();
66        } else {
67            app = null;
68        }
69        return buildPreferenceControllers(context, app, this);
70    }
71
72    private static List<PreferenceController> buildPreferenceControllers(Context context,
73            Application app, Fragment host) {
74        final List<PreferenceController> controllers = new ArrayList<>();
75        controllers.add(new SpecialAppAccessPreferenceController(context));
76        controllers.add(new AppPermissionsPreferenceController(context));
77        controllers.add(new RecentAppsPreferenceController(context, app, host));
78        return controllers;
79    }
80
81    public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
82            new BaseSearchIndexProvider() {
83                @Override
84                public List<SearchIndexableResource> getXmlResourcesToIndex(
85                        Context context, boolean enabled) {
86                    final SearchIndexableResource sir = new SearchIndexableResource(context);
87                    sir.xmlResId = R.xml.app_and_notification;
88                    return Arrays.asList(sir);
89                }
90
91                @Override
92                public List<PreferenceController> getPreferenceControllers(Context context) {
93                    return buildPreferenceControllers(context, null, null /* host */);
94                }
95            };
96}
97