• 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.FragmentManager;
20 import android.content.Context;
21 import android.support.v7.preference.Preference;
22 import android.support.v7.preference.PreferenceScreen;
23 
24 import com.android.settings.R;
25 import com.android.settings.core.PreferenceControllerMixin;
26 import com.android.settingslib.core.lifecycle.Lifecycle;
27 
28 public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController
29         implements PreferenceControllerMixin, Preference.OnPreferenceClickListener {
30 
31     private static final String TAG = "ZenModeDurationDialog";
32     protected static final String KEY = "zen_mode_duration_settings";
33     private FragmentManager mFragment;
34 
ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager fragment)35     public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
36             fragment) {
37         super(context, KEY, lifecycle);
38         mFragment = fragment;
39     }
40 
41     @Override
isAvailable()42     public boolean isAvailable() {
43         return true;
44     }
45 
46     @Override
getPreferenceKey()47     public String getPreferenceKey() {
48         return KEY;
49     }
50 
51     @Override
displayPreference(PreferenceScreen screen)52     public void displayPreference(PreferenceScreen screen) {
53         super.displayPreference(screen);
54         screen.findPreference(KEY).setOnPreferenceClickListener(this);
55     }
56 
57     @Override
updateState(Preference preference)58     public void updateState(Preference preference) {
59         super.updateState(preference);
60 
61         String summary = "";
62         int zenDuration = getZenDuration();
63         if (zenDuration < 0) {
64             summary = mContext.getString(R.string.zen_mode_duration_summary_always_prompt);
65         } else if (zenDuration == 0) {
66             summary = mContext.getString(R.string.zen_mode_duration_summary_forever);
67         } else {
68             if (zenDuration >= 60) {
69                 int hours = zenDuration / 60;
70                 summary = mContext.getResources().getQuantityString(
71                         R.plurals.zen_mode_duration_summary_time_hours, hours, hours);
72             } else {
73                 summary = mContext.getResources().getString(
74                         R.string.zen_mode_duration_summary_time_minutes, zenDuration);
75             }
76         }
77 
78         preference.setSummary(summary);
79     }
80 
81     @Override
onPreferenceClick(Preference preference)82     public boolean onPreferenceClick(Preference preference) {
83         new SettingsZenDurationDialog().show(mFragment, TAG);
84         return true;
85     }
86 }