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 17 package com.android.settings.gestures; 18 19 import android.content.Context; 20 import android.content.SharedPreferences; 21 import android.provider.SearchIndexableResource; 22 23 import com.android.internal.logging.nano.MetricsProto; 24 import com.android.settings.R; 25 import com.android.settings.dashboard.DashboardFragment; 26 import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider; 27 import com.android.settings.overlay.FeatureFactory; 28 import com.android.settings.search.BaseSearchIndexProvider; 29 import com.android.settingslib.core.AbstractPreferenceController; 30 import com.android.settingslib.core.lifecycle.Lifecycle; 31 32 import java.util.ArrayList; 33 import java.util.Arrays; 34 import java.util.List; 35 36 public class SwipeToNotificationSettings extends DashboardFragment { 37 38 private static final String TAG = "SwipeToNotifSettings"; 39 40 private static final String KEY = "gesture_swipe_down_fingerprint"; 41 42 public static final String PREF_KEY_SUGGESTION_COMPLETE = 43 "pref_swipe_to_notification_suggestion_complete"; 44 45 @Override onAttach(Context context)46 public void onAttach(Context context) { 47 super.onAttach(context); 48 SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) 49 .getSuggestionFeatureProvider(context); 50 SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); 51 prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); 52 } 53 54 @Override getMetricsCategory()55 public int getMetricsCategory() { 56 return MetricsProto.MetricsEvent.SETTINGS_GESTURE_SWIPE_TO_NOTIFICATION; 57 } 58 59 @Override getLogTag()60 protected String getLogTag() { 61 return TAG; 62 } 63 64 @Override getPreferenceScreenResId()65 protected int getPreferenceScreenResId() { 66 return R.xml.swipe_to_notification_settings; 67 } 68 69 @Override getPreferenceControllers(Context context)70 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { 71 return buildPreferenceControllers(context, getLifecycle()); 72 } 73 buildPreferenceControllers(Context context, Lifecycle lifecycle)74 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 75 Lifecycle lifecycle) { 76 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 77 controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, KEY)); 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.swipe_to_notification_settings; 88 return Arrays.asList(sir); 89 } 90 91 @Override 92 public List<AbstractPreferenceController> getPreferenceControllers(Context context) { 93 return buildPreferenceControllers(context, null /* lifecycle */); 94 } 95 }; 96 } 97