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.content.Context; 20 import android.provider.Settings; 21 22 import androidx.preference.Preference; 23 24 import com.android.settings.R; 25 import com.android.settings.core.PreferenceControllerMixin; 26 import com.android.settingslib.core.lifecycle.Lifecycle; 27 28 /** 29 * Controls the summary for preference found at: 30 * Settings > Sound > Do Not Disturb > Alarms & other interruptions 31 */ 32 public class ZenModeSoundVibrationPreferenceController extends 33 AbstractZenModePreferenceController implements PreferenceControllerMixin { 34 private final String mKey; 35 private final ZenModeSettings.SummaryBuilder mSummaryBuilder; 36 ZenModeSoundVibrationPreferenceController(Context context, Lifecycle lifecycle, String key)37 public ZenModeSoundVibrationPreferenceController(Context context, Lifecycle lifecycle, 38 String key) { 39 super(context, key, lifecycle); 40 mKey = key; 41 mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context); 42 } 43 44 @Override getPreferenceKey()45 public String getPreferenceKey() { 46 return mKey; 47 } 48 49 @Override isAvailable()50 public boolean isAvailable() { 51 return true; 52 } 53 54 @Override updateState(Preference preference)55 public void updateState(Preference preference) { 56 super.updateState(preference); 57 58 switch (getZenMode()) { 59 case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS: 60 preference.setEnabled(false); 61 preference.setSummary(mContext.getString(R.string.zen_mode_other_sounds_none)); 62 break; 63 case Settings.Global.ZEN_MODE_ALARMS: 64 preference.setEnabled(false); 65 preference.setSummary(mContext.getString(R.string.zen_mode_behavior_alarms_only)); 66 break; 67 default: 68 preference.setEnabled(true); 69 preference.setSummary(mSummaryBuilder.getOtherSoundCategoriesSummary(getPolicy())); 70 } 71 } 72 } 73