ConfigureNotificationSettings.java revision 742467ec9f384983f37d9a0e4e9775c27451816b
1/*
2 * Copyright (C) 2015 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.notification;
18
19import android.content.Context;
20import android.provider.SearchIndexableResource;
21
22import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
23import com.android.settings.R;
24import com.android.settings.core.PreferenceController;
25import com.android.settings.dashboard.DashboardFragment;
26import com.android.settings.gestures.SwipeToNotificationPreferenceController;
27import com.android.settings.search.BaseSearchIndexProvider;
28import com.android.settings.search.Indexable;
29import com.android.settingslib.core.lifecycle.Lifecycle;
30
31import java.util.ArrayList;
32import java.util.Arrays;
33import java.util.List;
34
35public class ConfigureNotificationSettings extends DashboardFragment {
36    private static final String TAG = "ConfigNotiSettings";
37
38    private static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint_notifications";
39
40    @Override
41    public int getMetricsCategory() {
42        return MetricsEvent.CONFIGURE_NOTIFICATION;
43    }
44
45    @Override
46    protected String getLogTag() {
47        return TAG;
48    }
49
50    @Override
51    protected int getPreferenceScreenResId() {
52        return R.xml.configure_notification_settings;
53    }
54
55    @Override
56    protected List<PreferenceController> getPreferenceControllers(Context context) {
57        return buildPreferenceControllers(context, getLifecycle());
58    }
59
60    private static List<PreferenceController> buildPreferenceControllers(Context context,
61            Lifecycle lifecycle) {
62        final List<PreferenceController> controllers = new ArrayList<>();
63        final BadgingNotificationPreferenceController badgeController =
64                new BadgingNotificationPreferenceController(context);
65        final PulseNotificationPreferenceController pulseController =
66                new PulseNotificationPreferenceController(context);
67        final LockScreenNotificationPreferenceController lockScreenNotificationController =
68                new LockScreenNotificationPreferenceController(context);
69        if (lifecycle != null) {
70            lifecycle.addObserver(pulseController);
71            lifecycle.addObserver(lockScreenNotificationController);
72        }
73        controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle,
74                KEY_SWIPE_DOWN));
75        controllers.add(badgeController);
76        controllers.add(pulseController);
77        controllers.add(lockScreenNotificationController);
78        return controllers;
79    }
80
81    /**
82     * For Search.
83     */
84    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
85            new BaseSearchIndexProvider() {
86                @Override
87                public List<SearchIndexableResource> getXmlResourcesToIndex(
88                        Context context, boolean enabled) {
89                    final SearchIndexableResource sir = new SearchIndexableResource(context);
90                    sir.xmlResId = R.xml.configure_notification_settings;
91                    return Arrays.asList(sir);
92                }
93
94                @Override
95                public List<PreferenceController> getPreferenceControllers(Context context) {
96                    return buildPreferenceControllers(context, null);
97                }
98            };
99}
100