Joe Onorato | 2039e48 | 2010-11-29 14:54:24 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
| 19 | import android.app.StatusBarManager; |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.Context; |
| 22 | import android.content.SharedPreferences; |
| 23 | import android.os.RemoteException; |
| 24 | import android.os.ServiceManager; |
| 25 | import android.util.Slog; |
| 26 | |
| 27 | import com.android.systemui.statusbar.policy.Prefs; |
| 28 | |
| 29 | public 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 | |