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