1 /* 2 * Copyright (C) 2020 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.zen; 18 19 import android.app.NotificationManager; 20 import android.content.Context; 21 import android.provider.Settings; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceScreen; 25 26 import com.android.settingslib.core.lifecycle.Lifecycle; 27 28 /** 29 * Controls the summary for preference found at: 30 * Settings > Sound > Do Not Disturb > People > Conversations 31 */ 32 public class ZenModeConversationsPreferenceController extends AbstractZenModePreferenceController { 33 private final ZenModeBackend mBackend; 34 private Preference mPreference; 35 ZenModeConversationsPreferenceController(Context context, String key, Lifecycle lifecycle)36 public ZenModeConversationsPreferenceController(Context context, 37 String key, Lifecycle lifecycle) { 38 super(context, key, lifecycle); 39 mBackend = ZenModeBackend.getInstance(context); 40 } 41 42 @Override getPreferenceKey()43 public String getPreferenceKey() { 44 return KEY; 45 } 46 47 @Override isAvailable()48 public boolean isAvailable() { 49 return true; 50 } 51 52 @Override displayPreference(PreferenceScreen screen)53 public void displayPreference(PreferenceScreen screen) { 54 super.displayPreference(screen); 55 mPreference = screen.findPreference(KEY); 56 } 57 58 @Override updateState(Preference preference)59 public void updateState(Preference preference) { 60 super.updateState(preference); 61 switch (getZenMode()) { 62 case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS: 63 case Settings.Global.ZEN_MODE_ALARMS: 64 mPreference.setEnabled(false); 65 mPreference.setSummary(mBackend.getAlarmsTotalSilencePeopleSummary( 66 NotificationManager.Policy.PRIORITY_CATEGORY_CONVERSATIONS)); 67 break; 68 default: 69 preference.setEnabled(true); 70 preference.setSummary(mBackend.getConversationSummary()); 71 } 72 } 73 } 74