1 /* 2 * Copyright (C) 2023 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.notification; 18 19 import static android.provider.Settings.Secure.LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS; 20 21 import android.content.Context; 22 import android.provider.Settings; 23 24 import androidx.annotation.VisibleForTesting; 25 26 import com.android.settings.R; 27 import com.android.settings.core.TogglePreferenceController; 28 29 public class ShowOnlyUnseenNotificationsOnLockscreenPreferenceController 30 extends TogglePreferenceController { 31 32 private static final int UNSET = 0; 33 @VisibleForTesting 34 static final int ON = 1; 35 @VisibleForTesting 36 static final int OFF = 2; 37 ShowOnlyUnseenNotificationsOnLockscreenPreferenceController( Context context, String preferenceKey)38 public ShowOnlyUnseenNotificationsOnLockscreenPreferenceController( 39 Context context, 40 String preferenceKey) { 41 super(context, preferenceKey); 42 } 43 44 @Override isChecked()45 public boolean isChecked() { 46 return Settings.Secure.getInt(mContext.getContentResolver(), 47 LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET) == ON; 48 } 49 50 @Override setChecked(boolean isChecked)51 public boolean setChecked(boolean isChecked) { 52 return Settings.Secure.putInt(mContext.getContentResolver(), 53 LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, isChecked ? ON : OFF); 54 } 55 56 @Override getAvailabilityStatus()57 public int getAvailabilityStatus() { 58 int setting = Settings.Secure.getInt(mContext.getContentResolver(), 59 LOCK_SCREEN_SHOW_ONLY_UNSEEN_NOTIFICATIONS, UNSET); 60 if (setting == UNSET) { 61 return CONDITIONALLY_UNAVAILABLE; 62 } else { 63 return AVAILABLE; 64 } 65 } 66 67 @Override getSliceHighlightMenuRes()68 public int getSliceHighlightMenuRes() { 69 return R.string.menu_key_notifications; 70 } 71 } 72