ConfigureNotificationSettings.java revision a25bc6983e14d9bd1175791b28e1086b539b11b7
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 PulseNotificationPreferenceController pulseController = 62 new PulseNotificationPreferenceController(context); 63 final LockScreenNotificationPreferenceController lockScreenNotificationController = 64 new LockScreenNotificationPreferenceController(context); 65 if (lifecycle != null) { 66 lifecycle.addObserver(pulseController); 67 lifecycle.addObserver(lockScreenNotificationController); 68 } 69 controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle)); 70 controllers.add(pulseController); 71 controllers.add(lockScreenNotificationController); 72 return controllers; 73 } 74 75 /** 76 * For Search. 77 */ 78 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 79 new BaseSearchIndexProvider() { 80 @Override 81 public List<SearchIndexableResource> getXmlResourcesToIndex( 82 Context context, boolean enabled) { 83 final SearchIndexableResource sir = new SearchIndexableResource(context); 84 sir.xmlResId = R.xml.configure_notification_settings; 85 return Arrays.asList(sir); 86 } 87 88 @Override 89 public List<PreferenceController> getPreferenceControllers(Context context) { 90 return buildPreferenceControllers(context, null); 91 } 92 }; 93} 94