2 * Copyright (C) 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.notification;
19 import android.app.FragmentManager;
20 import android.content.Context;
21 import android.support.v7.preference.Preference;
22 import android.support.v7.preference.PreferenceScreen;
24 import com.android.settings.R;
25 import com.android.settings.core.PreferenceControllerMixin;
26 import com.android.settingslib.core.lifecycle.Lifecycle;
28 public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController
29 implements PreferenceControllerMixin, Preference.OnPreferenceClickListener {
31 private static final String TAG = "ZenModeDurationDialog";
32 protected static final String KEY = "zen_mode_duration_settings";
33 private FragmentManager mFragment;
35 public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
37 super(context, KEY, lifecycle);
42 public boolean isAvailable() {
47 public String getPreferenceKey() {
52 public void displayPreference(PreferenceScreen screen) {
53 super.displayPreference(screen);
54 screen.findPreference(KEY).setOnPreferenceClickListener(this);
58 public void updateState(Preference preference) {
59 super.updateState(preference);
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);
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);
73 summary = mContext.getResources().getString(
74 R.string.zen_mode_duration_summary_time_minutes, zenDuration);
78 preference.setSummary(summary);
82 public boolean onPreferenceClick(Preference preference) {
83 new SettingsZenDurationDialog().show(mFragment, TAG);