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 static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED; 20 21 import android.content.Context; 22 import android.content.SharedPreferences; 23 import android.provider.Settings; 24 import android.text.TextUtils; 25 26 import com.android.settings.Utils; 27 28 public class SwipeToNotificationPreferenceController extends GesturePreferenceController { 29 30 private static final int ON = 1; 31 private static final int OFF = 0; 32 33 private static final String PREF_KEY_VIDEO = "gesture_swipe_down_fingerprint_video"; 34 35 private static final String SECURE_KEY = SYSTEM_NAVIGATION_KEYS_ENABLED; 36 SwipeToNotificationPreferenceController(Context context, String key)37 public SwipeToNotificationPreferenceController(Context context, String key) { 38 super(context, key); 39 } 40 isSuggestionComplete(Context context, SharedPreferences prefs)41 public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { 42 return !isGestureAvailable(context) 43 || prefs.getBoolean(SwipeToNotificationSettings.PREF_KEY_SUGGESTION_COMPLETE, 44 false); 45 } 46 isGestureAvailable(Context context)47 private static boolean isGestureAvailable(Context context) { 48 return Utils.hasFingerprintHardware(context) 49 && context.getResources() 50 .getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys); 51 } 52 53 @Override getVideoPrefKey()54 protected String getVideoPrefKey() { 55 return PREF_KEY_VIDEO; 56 } 57 58 @Override getAvailabilityStatus()59 public int getAvailabilityStatus() { 60 return isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 61 } 62 63 @Override isSliceable()64 public boolean isSliceable() { 65 return TextUtils.equals(getPreferenceKey(), "gesture_swipe_down_fingerprint"); 66 } 67 68 @Override isPublicSlice()69 public boolean isPublicSlice() { 70 return true; 71 } 72 73 @Override setChecked(boolean isChecked)74 public boolean setChecked(boolean isChecked) { 75 setSwipeToNotification(mContext, isChecked); 76 return true; 77 } 78 79 @Override isChecked()80 public boolean isChecked() { 81 return isSwipeToNotificationOn(mContext); 82 } 83 isSwipeToNotificationOn(Context context)84 public static boolean isSwipeToNotificationOn(Context context) { 85 return Settings.Secure.getInt(context.getContentResolver(), SECURE_KEY, OFF) == ON; 86 } 87 setSwipeToNotification(Context context, boolean isEnabled)88 public static boolean setSwipeToNotification(Context context, boolean isEnabled) { 89 return Settings.Secure.putInt( 90 context.getContentResolver(), SECURE_KEY, isEnabled ? ON : OFF); 91 } 92 isAvailable(Context context)93 public static boolean isAvailable(Context context) { 94 return isGestureAvailable(context); 95 } 96 } 97