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 DoubleTwistGestureSettings extends DashboardFragment { 37 38 private static final String TAG = "DoubleTwistGesture"; 39 private static final String KEY_DOUBLE_TWIST = "gesture_double_twist"; 40 41 public static final String PREF_KEY_SUGGESTION_COMPLETE = 42 "pref_double_twist_suggestion_complete"; 43 44 @Override onAttach(Context context)45 public void onAttach(Context context) { 46 super.onAttach(context); 47 SuggestionFeatureProvider suggestionFeatureProvider = FeatureFactory.getFactory(context) 48 .getSuggestionFeatureProvider(context); 49 SharedPreferences prefs = suggestionFeatureProvider.getSharedPrefs(context); 50 prefs.edit().putBoolean(PREF_KEY_SUGGESTION_COMPLETE, true).apply(); 51 } 52 53 @Override getMetricsCategory()54 public int getMetricsCategory() { 55 return MetricsProto.MetricsEvent.SETTINGS_GESTURE_DOUBLE_TWIST; 56 } 57 58 @Override getLogTag()59 protected String getLogTag() { 60 return TAG; 61 } 62 63 @Override getPreferenceScreenResId()64 protected int getPreferenceScreenResId() { 65 return R.xml.double_twist_gesture_settings; 66 } 67 68 @Override getPreferenceControllers(Context context)69 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { 70 return buildPreferenceControllers(context, getLifecycle()); 71 } 72 buildPreferenceControllers(Context context, Lifecycle lifecycle)73 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 74 Lifecycle lifecycle) { 75 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 76 controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST)); 77 return controllers; 78 } 79 80 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 81 new BaseSearchIndexProvider() { 82 @Override 83 public List<SearchIndexableResource> getXmlResourcesToIndex( 84 Context context, boolean enabled) { 85 final SearchIndexableResource sir = new SearchIndexableResource(context); 86 sir.xmlResId = R.xml.double_twist_gesture_settings; 87 return Arrays.asList(sir); 88 } 89 90 @Override 91 public List<AbstractPreferenceController> getPreferenceControllers(Context context) { 92 return buildPreferenceControllers(context, null /* lifecycle */); 93 } 94 }; 95 96 } 97