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