blob: 94c8aa5d3dde53d2435566e060fe2b8bc45dc12c [file] [log] [blame]
Joe Onorato2039e482010-11-29 14:54:24 -08001/*
2 * Copyright (C) 2010 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
17package com.android.systemui.statusbar.policy;
18
19import android.content.ContentResolver;
20import android.content.Context;
21import android.content.SharedPreferences;
22import android.os.RemoteException;
23import android.os.ServiceManager;
24import android.provider.Settings;
25import android.util.Slog;
26import android.view.IWindowManager;
27import android.widget.CompoundButton;
28
29public class DoNotDisturbController implements CompoundButton.OnCheckedChangeListener,
30 SharedPreferences.OnSharedPreferenceChangeListener {
31 private static final String TAG = "StatusBar.DoNotDisturbController";
32
33 SharedPreferences mPrefs;
34 private Context mContext;
35 private CompoundButton mCheckBox;
36
37 private boolean mDoNotDisturb;
38
39 public DoNotDisturbController(Context context, CompoundButton checkbox) {
40 mContext = context;
41
42 mPrefs = Prefs.read(context);
43 mPrefs.registerOnSharedPreferenceChangeListener(this);
44 mDoNotDisturb = mPrefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);
45
46 mCheckBox = checkbox;
47 checkbox.setOnCheckedChangeListener(this);
48
49 checkbox.setChecked(!mDoNotDisturb);
50 }
51
52 // The checkbox is ON for notifications coming in and OFF for Do not disturb, so we
53 // don't have a double negative.
54 public void onCheckedChanged(CompoundButton view, boolean checked) {
55 //Slog.d(TAG, "onCheckedChanged checked=" + checked + " mDoNotDisturb=" + mDoNotDisturb);
56 final boolean value = !checked;
57 if (value != mDoNotDisturb) {
58 SharedPreferences.Editor editor = Prefs.edit(mContext);
59 editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, value);
60 editor.apply();
61 }
62 }
63
64 public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
65 final boolean val = prefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF,
66 Prefs.DO_NOT_DISTURB_DEFAULT);
67 if (val != mDoNotDisturb) {
68 mDoNotDisturb = val;
69 mCheckBox.setChecked(!val);
70 }
71 }
72
73 public void release() {
74 mPrefs.unregisterOnSharedPreferenceChangeListener(this);
75 }
76}
77