• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ContentResolver;
20 import android.content.Context;
21 import android.provider.Settings;
22 import android.support.annotation.NonNull;
23 
24 import com.android.internal.hardware.AmbientDisplayConfiguration;
25 import com.android.settings.R;
26 import com.android.settings.core.BasePreferenceController;
27 import com.android.settings.overlay.FeatureFactory;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 public class GesturesSettingPreferenceController extends BasePreferenceController {
34     private final AssistGestureFeatureProvider mFeatureProvider;
35     private List<AbstractPreferenceController> mGestureControllers;
36 
37     private static final String KEY_GESTURES_SETTINGS = "gesture_settings";
38     private static final String FAKE_PREF_KEY = "fake_key_only_for_get_available";
39 
GesturesSettingPreferenceController(Context context)40     public GesturesSettingPreferenceController(Context context) {
41         super(context, KEY_GESTURES_SETTINGS);
42         mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
43     }
44 
45     @Override
getAvailabilityStatus()46     public int getAvailabilityStatus() {
47         if (mGestureControllers == null) {
48             mGestureControllers = buildAllPreferenceControllers(mContext);
49         }
50         boolean isAvailable = false;
51         for (AbstractPreferenceController controller : mGestureControllers) {
52             isAvailable = isAvailable || controller.isAvailable();
53         }
54         return isAvailable ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
55     }
56 
57     /**
58      * Get all controllers for their availability status when doing getAvailabilityStatus.
59      * Do not use this method to add controllers into fragment, most of below controllers already
60      * convert to TogglePreferenceController, please register them in xml.
61      * The key is fake because those controllers won't be use to control preference.
62      */
buildAllPreferenceControllers( @onNull Context context)63     private static List<AbstractPreferenceController> buildAllPreferenceControllers(
64             @NonNull Context context) {
65         final AmbientDisplayConfiguration ambientDisplayConfiguration =
66                 new AmbientDisplayConfiguration(context);
67         final List<AbstractPreferenceController> controllers = new ArrayList<>();
68 
69         controllers.add(new AssistGestureSettingsPreferenceController(context, FAKE_PREF_KEY)
70                 .setAssistOnly(false));
71         controllers.add(new SwipeToNotificationPreferenceController(context, FAKE_PREF_KEY));
72         controllers.add(new DoubleTwistPreferenceController(context, FAKE_PREF_KEY));
73         controllers.add(new DoubleTapPowerPreferenceController(context, FAKE_PREF_KEY));
74         controllers.add(new PickupGesturePreferenceController(context, FAKE_PREF_KEY)
75                 .setConfig(ambientDisplayConfiguration));
76         controllers.add(new DoubleTapScreenPreferenceController(context, FAKE_PREF_KEY)
77                 .setConfig(ambientDisplayConfiguration));
78         controllers.add(new PreventRingingPreferenceController(context, FAKE_PREF_KEY));
79         return controllers;
80     }
81 
82     @Override
getSummary()83     public CharSequence getSummary() {
84         if (!mFeatureProvider.isSensorAvailable(mContext)) {
85             return "";
86         }
87         final ContentResolver contentResolver = mContext.getContentResolver();
88         final boolean assistGestureEnabled = Settings.Secure.getInt(
89                 contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0;
90         final boolean assistGestureSilenceEnabled = Settings.Secure.getInt(
91                 contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0;
92 
93         if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) {
94             return mContext.getText(
95                     R.string.language_input_gesture_summary_on_with_assist);
96         }
97         if (assistGestureSilenceEnabled) {
98             return mContext.getText(
99                     R.string.language_input_gesture_summary_on_non_assist);
100         }
101         return mContext.getText(R.string.language_input_gesture_summary_off);
102     }
103 }