Home | History | Annotate | Download | only in gestures
      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 DoubleTapPowerSettings extends DashboardFragment {
     37 
     38     private static final String TAG = "DoubleTapPower";
     39     private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
     40 
     41     public static final String PREF_KEY_SUGGESTION_COMPLETE =
     42             "pref_double_tap_power_suggestion_complete";
     43 
     44     @Override
     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
     54     public int getMetricsCategory() {
     55         return MetricsProto.MetricsEvent.SETTINGS_GESTURE_DOUBLE_TAP_POWER;
     56     }
     57 
     58     @Override
     59     protected String getLogTag() {
     60         return TAG;
     61     }
     62 
     63     @Override
     64     protected int getPreferenceScreenResId() {
     65         return R.xml.double_tap_power_settings;
     66     }
     67 
     68     @Override
     69     protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
     70         return buildPreferenceControllers(context, getLifecycle());
     71     }
     72 
     73     private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
     74             Lifecycle lifecycle) {
     75         final List<AbstractPreferenceController> controllers = new ArrayList<>();
     76         controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle,
     77                 KEY_DOUBLE_TAP_POWER));
     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.double_tap_power_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