ConfigureNotificationSettings.java revision 485e75e063be9258bcf28d9b2da5cd06d821f2bb
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.core.lifecycle.Lifecycle;
26import com.android.settings.dashboard.DashboardFragment;
27import com.android.settings.gestures.SwipeToNotificationPreferenceController;
28import com.android.settings.search.BaseSearchIndexProvider;
29import com.android.settings.search.Indexable;
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    @Override
39    public int getMetricsCategory() {
40        return MetricsEvent.CONFIGURE_NOTIFICATION;
41    }
42
43    @Override
44    protected String getLogTag() {
45        return TAG;
46    }
47
48    @Override
49    protected int getPreferenceScreenResId() {
50        return R.xml.configure_notification_settings;
51    }
52
53    @Override
54    protected List<PreferenceController> getPreferenceControllers(Context context) {
55        return buildPreferenceControllers(context, getLifecycle());
56    }
57
58    private static List<PreferenceController> buildPreferenceControllers(Context context,
59            Lifecycle lifecycle) {
60        final List<PreferenceController> controllers = new ArrayList<>();
61        final BadgingNotificationPreferenceController badgeController =
62                new BadgingNotificationPreferenceController(context);
63        final PulseNotificationPreferenceController pulseController =
64                new PulseNotificationPreferenceController(context);
65        final LockScreenNotificationPreferenceController lockScreenNotificationController =
66                new LockScreenNotificationPreferenceController(context);
67        if (lifecycle != null) {
68            lifecycle.addObserver(pulseController);
69            lifecycle.addObserver(lockScreenNotificationController);
70        }
71        controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle));
72        controllers.add(badgeController);
73        controllers.add(pulseController);
74        controllers.add(lockScreenNotificationController);
75        return controllers;
76    }
77
78    /**
79     * For Search.
80     */
81    public static final Indexable.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.configure_notification_settings;
88                    return Arrays.asList(sir);
89                }
90
91                @Override
92                public List<PreferenceController> getPreferenceControllers(Context context) {
93                    return buildPreferenceControllers(context, null);
94                }
95            };
96}
97