1/* 2 * Copyright (C) 2017 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.gestures; 18 19import android.content.Context; 20import android.os.UserHandle; 21import android.provider.SearchIndexableResource; 22import android.support.annotation.NonNull; 23import android.support.annotation.Nullable; 24 25import com.android.internal.hardware.AmbientDisplayConfiguration; 26import com.android.internal.logging.nano.MetricsProto; 27import com.android.settings.R; 28import com.android.settings.dashboard.DashboardFragment; 29import com.android.settings.search.BaseSearchIndexProvider; 30import com.android.settingslib.core.AbstractPreferenceController; 31import com.android.settingslib.core.lifecycle.Lifecycle; 32 33import java.util.ArrayList; 34import java.util.Arrays; 35import java.util.List; 36 37public class GestureSettings extends DashboardFragment { 38 39 private static final String TAG = "GestureSettings"; 40 41 private static final String KEY_ASSIST = "gesture_assist_input_summary"; 42 private static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint_input_summary"; 43 private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power_input_summary"; 44 private static final String KEY_DOUBLE_TWIST = "gesture_double_twist_input_summary"; 45 private static final String KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen_input_summary"; 46 private static final String KEY_PICK_UP = "gesture_pick_up_input_summary"; 47 48 private AmbientDisplayConfiguration mAmbientDisplayConfig; 49 50 @Override 51 public int getMetricsCategory() { 52 return MetricsProto.MetricsEvent.SETTINGS_GESTURES; 53 } 54 55 @Override 56 protected String getLogTag() { 57 return TAG; 58 } 59 60 @Override 61 protected int getPreferenceScreenResId() { 62 return R.xml.gestures; 63 } 64 65 @Override 66 protected List<AbstractPreferenceController> getPreferenceControllers(Context context) { 67 if (mAmbientDisplayConfig == null) { 68 mAmbientDisplayConfig = new AmbientDisplayConfiguration(context); 69 } 70 71 return buildPreferenceControllers(context, getLifecycle(), mAmbientDisplayConfig); 72 } 73 74 static List<AbstractPreferenceController> buildPreferenceControllers( 75 @NonNull Context context, @Nullable Lifecycle lifecycle, 76 @NonNull AmbientDisplayConfiguration ambientDisplayConfiguration) { 77 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 78 controllers.add(new AssistGestureSettingsPreferenceController(context, lifecycle, 79 KEY_ASSIST, false /* assistOnly */)); 80 controllers.add(new SwipeToNotificationPreferenceController(context, lifecycle, 81 KEY_SWIPE_DOWN)); 82 controllers.add(new DoubleTwistPreferenceController(context, lifecycle, KEY_DOUBLE_TWIST)); 83 controllers.add(new DoubleTapPowerPreferenceController(context, lifecycle, 84 KEY_DOUBLE_TAP_POWER)); 85 controllers.add(new PickupGesturePreferenceController(context, lifecycle, 86 ambientDisplayConfiguration, UserHandle.myUserId(), KEY_PICK_UP)); 87 controllers.add(new DoubleTapScreenPreferenceController(context, lifecycle, 88 ambientDisplayConfiguration, UserHandle.myUserId(), KEY_DOUBLE_TAP_SCREEN)); 89 return controllers; 90 } 91 92 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 93 new BaseSearchIndexProvider() { 94 @Override 95 public List<SearchIndexableResource> getXmlResourcesToIndex( 96 Context context, boolean enabled) { 97 final SearchIndexableResource sir = new SearchIndexableResource(context); 98 sir.xmlResId = R.xml.gestures; 99 return Arrays.asList(sir); 100 } 101 102 @Override 103 public List<AbstractPreferenceController> getPreferenceControllers( 104 Context context) { 105 return buildPreferenceControllers(context, null, 106 new AmbientDisplayConfiguration(context)); 107 } 108 109 @Override 110 public List<String> getNonIndexableKeys(Context context) { 111 List<String> keys = super.getNonIndexableKeys(context); 112 // Duplicates in summary and details pages. 113 keys.add(KEY_ASSIST); 114 keys.add(KEY_SWIPE_DOWN); 115 keys.add(KEY_DOUBLE_TAP_POWER); 116 keys.add(KEY_DOUBLE_TWIST); 117 keys.add(KEY_DOUBLE_TAP_SCREEN); 118 keys.add(KEY_PICK_UP); 119 120 return keys; 121 } 122 }; 123} 124