1/*
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;
18
19import android.app.StatusBarManager;
20import android.content.ContentResolver;
21import android.content.Context;
22import android.content.SharedPreferences;
23import android.os.RemoteException;
24import android.os.ServiceManager;
25import android.util.Slog;
26
27import com.android.systemui.statusbar.policy.Prefs;
28
29public class DoNotDisturb implements SharedPreferences.OnSharedPreferenceChangeListener {
30    private Context mContext;
31    private StatusBarManager mStatusBar;
32    SharedPreferences mPrefs;
33    private boolean mDoNotDisturb;
34
35    public DoNotDisturb(Context context) {
36        mContext = context;
37        mStatusBar = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE);
38        mPrefs = Prefs.read(context);
39        mPrefs.registerOnSharedPreferenceChangeListener(this);
40        mDoNotDisturb = mPrefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT);
41        updateDisableRecord();
42    }
43
44    public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
45        final boolean val = prefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF,
46                Prefs.DO_NOT_DISTURB_DEFAULT);
47        if (val != mDoNotDisturb) {
48            mDoNotDisturb = val;
49            updateDisableRecord();
50        }
51    }
52
53    private void updateDisableRecord() {
54        final int disabled = StatusBarManager.DISABLE_NOTIFICATION_ICONS
55                | StatusBarManager.DISABLE_NOTIFICATION_ALERTS
56                | StatusBarManager.DISABLE_NOTIFICATION_TICKER;
57        mStatusBar.disable(mDoNotDisturb ? disabled : 0);
58    }
59}
60
61