1 /* 2 * Copyright (C) 2018 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.AutomaticZenRule; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.util.Slog; 23 24 import androidx.preference.Preference; 25 26 import com.android.settings.core.PreferenceControllerMixin; 27 import com.android.settingslib.core.lifecycle.Lifecycle; 28 29 abstract class AbstractZenCustomRulePreferenceController extends 30 AbstractZenModePreferenceController implements PreferenceControllerMixin { 31 32 String mId; 33 AutomaticZenRule mRule; 34 AbstractZenCustomRulePreferenceController(Context context, String key, Lifecycle lifecycle)35 AbstractZenCustomRulePreferenceController(Context context, String key, 36 Lifecycle lifecycle) { 37 super(context, key, lifecycle); 38 } 39 40 @Override updateState(Preference preference)41 public void updateState(Preference preference) { 42 if (mId != null) { 43 mRule = mBackend.getAutomaticZenRule(mId); 44 } 45 } 46 47 @Override isAvailable()48 public boolean isAvailable() { 49 return mRule != null; 50 } 51 onResume(AutomaticZenRule rule, String id)52 public void onResume(AutomaticZenRule rule, String id) { 53 mId = id; 54 mRule = rule; 55 } 56 createBundle()57 Bundle createBundle() { 58 Bundle bundle = new Bundle(); 59 bundle.putString(ZenCustomRuleSettings.RULE_ID, mId); 60 return bundle; 61 } 62 } 63