1 /* 2 * Copyright (C) 2019 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 android.content.Context; 20 import android.provider.Settings; 21 22 import com.android.settings.R; 23 import com.android.settings.core.BasePreferenceController; 24 25 import androidx.annotation.VisibleForTesting; 26 27 public class GentleNotificationsPreferenceController extends BasePreferenceController { 28 29 @VisibleForTesting 30 static final int ON = 1; 31 32 private NotificationBackend mBackend; 33 GentleNotificationsPreferenceController(Context context, String preferenceKey)34 public GentleNotificationsPreferenceController(Context context, String preferenceKey) { 35 super(context, preferenceKey); 36 mBackend = new NotificationBackend(); 37 } 38 39 @VisibleForTesting setBackend(NotificationBackend backend)40 void setBackend(NotificationBackend backend) { 41 mBackend = backend; 42 } 43 44 @Override getSummary()45 public CharSequence getSummary() { 46 boolean showOnLockscreen = showOnLockscreen(); 47 boolean showOnStatusBar = showOnStatusBar(); 48 49 if (showOnLockscreen) { 50 if (showOnStatusBar) { 51 return mContext.getString( 52 R.string.gentle_notifications_display_summary_shade_status_lock); 53 } else { 54 return mContext.getString(R.string.gentle_notifications_display_summary_shade_lock); 55 } 56 } else if (showOnStatusBar) { 57 return mContext.getString(R.string.gentle_notifications_display_summary_shade_status); 58 } else { 59 return mContext.getString(R.string.gentle_notifications_display_summary_shade); 60 } 61 } 62 63 @Override getAvailabilityStatus()64 public int getAvailabilityStatus() { 65 return AVAILABLE; 66 } 67 showOnLockscreen()68 private boolean showOnLockscreen() { 69 return Settings.Secure.getInt(mContext.getContentResolver(), 70 Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, ON) == ON; 71 } 72 showOnStatusBar()73 private boolean showOnStatusBar() { 74 return !mBackend.shouldHideSilentStatusBarIcons(mContext); 75 } 76 } 77