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 17 package com.android.settings.gestures; 18 19 import android.content.Context; 20 import android.hardware.display.AmbientDisplayConfiguration; 21 22 import androidx.annotation.NonNull; 23 24 import com.android.settings.core.BasePreferenceController; 25 import com.android.settingslib.core.AbstractPreferenceController; 26 27 import java.util.ArrayList; 28 import java.util.List; 29 30 public class GesturesSettingPreferenceController extends BasePreferenceController { 31 private List<AbstractPreferenceController> mGestureControllers; 32 33 private static final String FAKE_PREF_KEY = "fake_key_only_for_get_available"; 34 GesturesSettingPreferenceController(Context context, String key)35 public GesturesSettingPreferenceController(Context context, String key) { 36 super(context, key); 37 } 38 39 @Override getAvailabilityStatus()40 public int getAvailabilityStatus() { 41 if (mGestureControllers == null) { 42 mGestureControllers = buildAllPreferenceControllers(mContext); 43 } 44 boolean isAvailable = false; 45 for (AbstractPreferenceController controller : mGestureControllers) { 46 isAvailable = isAvailable || controller.isAvailable(); 47 } 48 return isAvailable ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 49 } 50 51 /** 52 * Get all controllers for their availability status when doing getAvailabilityStatus. 53 * Do not use this method to add controllers into fragment, most of below controllers already 54 * convert to TogglePreferenceController, please register them in xml. 55 * The key is fake because those controllers won't be use to control preference. 56 */ buildAllPreferenceControllers( @onNull Context context)57 private static List<AbstractPreferenceController> buildAllPreferenceControllers( 58 @NonNull Context context) { 59 final AmbientDisplayConfiguration ambientDisplayConfiguration = 60 new AmbientDisplayConfiguration(context); 61 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 62 63 controllers.add(new SwipeToNotificationPreferenceController(context, FAKE_PREF_KEY)); 64 controllers.add(new DoubleTwistPreferenceController(context, FAKE_PREF_KEY)); 65 controllers.add(new DoubleTapPowerPreferenceController(context, FAKE_PREF_KEY)); 66 controllers.add(new PickupGesturePreferenceController(context, FAKE_PREF_KEY) 67 .setConfig(ambientDisplayConfiguration)); 68 controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY) 69 .setConfig(ambientDisplayConfiguration)); 70 controllers.add(new PreventRingingParentPreferenceController(context, FAKE_PREF_KEY)); 71 return controllers; 72 } 73 } 74