diff options
author | Joe Onorato <joeo@google.com> | 2010-11-29 14:54:24 -0800 |
---|---|---|
committer | Joe Onorato <joeo@google.com> | 2010-11-29 14:54:24 -0800 |
commit | 2039e484740ae5c314082398e5696339b615cb22 (patch) | |
tree | a93c0f83871844c9c1bc0ae1d354b59934dbf864 /packages | |
parent | 536c58fbe51a53d0e6e78c360c9f6069ae0fd465 (diff) | |
download | frameworks_base-2039e484740ae5c314082398e5696339b615cb22.zip frameworks_base-2039e484740ae5c314082398e5696339b615cb22.tar.gz frameworks_base-2039e484740ae5c314082398e5696339b615cb22.tar.bz2 |
Do not disturb.
Change-Id: I9550970f322872787ef903ca762dfdf2ed9d2835
Diffstat (limited to 'packages')
6 files changed, 184 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/DoNotDisturb.java b/packages/SystemUI/src/com/android/systemui/statusbar/DoNotDisturb.java new file mode 100644 index 0000000..9e44e71 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/DoNotDisturb.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar; + +import android.app.StatusBarManager; +import android.content.ContentResolver; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.util.Slog; + +import com.android.systemui.statusbar.policy.Prefs; + +public class DoNotDisturb implements SharedPreferences.OnSharedPreferenceChangeListener { + private Context mContext; + private StatusBarManager mStatusBar; + SharedPreferences mPrefs; + private boolean mDoNotDisturb; + + public DoNotDisturb(Context context) { + mContext = context; + mStatusBar = (StatusBarManager)context.getSystemService(Context.STATUS_BAR_SERVICE); + mPrefs = Prefs.read(context); + mPrefs.registerOnSharedPreferenceChangeListener(this); + mDoNotDisturb = mPrefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT); + updateDisableRecord(); + } + + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + final boolean val = prefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, + Prefs.DO_NOT_DISTURB_DEFAULT); + if (val != mDoNotDisturb) { + mDoNotDisturb = val; + updateDisableRecord(); + } + } + + private void updateDisableRecord() { + final int disabled = StatusBarManager.DISABLE_NOTIFICATION_ICONS + | StatusBarManager.DISABLE_NOTIFICATION_ALERTS + | StatusBarManager.DISABLE_NOTIFICATION_TICKER; + mStatusBar.disable(mDoNotDisturb ? disabled : 0); + } +} + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java index d7f3730..472a225 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBar.java @@ -53,6 +53,8 @@ public abstract class StatusBar extends SystemUI implements CommandQueue.Callbac protected abstract View makeStatusBarView(); protected abstract int getStatusBarGravity(); + private DoNotDisturb mDoNotDisturb; + public void start() { // First set up our views and stuff. View sb = makeStatusBarView(); @@ -127,5 +129,7 @@ public abstract class StatusBar extends SystemUI implements CommandQueue.Callbac + " imeButton=" + switches[3] ); } + + mDoNotDisturb = new DoNotDisturb(mContext); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DoNotDisturbController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DoNotDisturbController.java new file mode 100644 index 0000000..94c8aa5 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DoNotDisturbController.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.ContentResolver; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.provider.Settings; +import android.util.Slog; +import android.view.IWindowManager; +import android.widget.CompoundButton; + +public class DoNotDisturbController implements CompoundButton.OnCheckedChangeListener, + SharedPreferences.OnSharedPreferenceChangeListener { + private static final String TAG = "StatusBar.DoNotDisturbController"; + + SharedPreferences mPrefs; + private Context mContext; + private CompoundButton mCheckBox; + + private boolean mDoNotDisturb; + + public DoNotDisturbController(Context context, CompoundButton checkbox) { + mContext = context; + + mPrefs = Prefs.read(context); + mPrefs.registerOnSharedPreferenceChangeListener(this); + mDoNotDisturb = mPrefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, Prefs.DO_NOT_DISTURB_DEFAULT); + + mCheckBox = checkbox; + checkbox.setOnCheckedChangeListener(this); + + checkbox.setChecked(!mDoNotDisturb); + } + + // The checkbox is ON for notifications coming in and OFF for Do not disturb, so we + // don't have a double negative. + public void onCheckedChanged(CompoundButton view, boolean checked) { + //Slog.d(TAG, "onCheckedChanged checked=" + checked + " mDoNotDisturb=" + mDoNotDisturb); + final boolean value = !checked; + if (value != mDoNotDisturb) { + SharedPreferences.Editor editor = Prefs.edit(mContext); + editor.putBoolean(Prefs.DO_NOT_DISTURB_PREF, value); + editor.apply(); + } + } + + public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { + final boolean val = prefs.getBoolean(Prefs.DO_NOT_DISTURB_PREF, + Prefs.DO_NOT_DISTURB_DEFAULT); + if (val != mDoNotDisturb) { + mDoNotDisturb = val; + mCheckBox.setChecked(!val); + } + } + + public void release() { + mPrefs.unregisterOnSharedPreferenceChangeListener(this); + } +} + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java new file mode 100644 index 0000000..05eafe8 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Prefs.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.Context; +import android.content.SharedPreferences; + +public class Prefs { + private static final String SHARED_PREFS_NAME = "status_bar"; + + // a boolean + public static final String DO_NOT_DISTURB_PREF = "do_not_disturb"; + public static final boolean DO_NOT_DISTURB_DEFAULT = false; + + public static SharedPreferences read(Context context) { + return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE); + } + + public static SharedPreferences.Editor edit(Context context) { + return context.getSharedPreferences(Prefs.SHARED_PREFS_NAME, Context.MODE_PRIVATE).edit(); + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java index f9ba908..d1f8dd0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java @@ -31,12 +31,14 @@ import android.widget.TextView; import com.android.systemui.R; import com.android.systemui.statusbar.policy.AirplaneModeController; import com.android.systemui.statusbar.policy.AutoRotateController; +import com.android.systemui.statusbar.policy.DoNotDisturbController; public class SettingsView extends LinearLayout implements View.OnClickListener { static final String TAG = "SettingsView"; AirplaneModeController mAirplane; AutoRotateController mRotate; + DoNotDisturbController mDoNotDisturb; public SettingsView(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -57,6 +59,8 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { findViewById(R.id.network).setOnClickListener(this); mRotate = new AutoRotateController(context, (CompoundButton)findViewById(R.id.rotate_checkbox)); + mDoNotDisturb = new DoNotDisturbController(context, + (CompoundButton)findViewById(R.id.do_not_disturb_checkbox)); findViewById(R.id.settings).setOnClickListener(this); } @@ -64,6 +68,7 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mAirplane.release(); + mDoNotDisturb.release(); } public void onClick(View v) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java index 3cae088..5f4d542 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java @@ -580,12 +580,12 @@ public class TabletStatusBar extends StatusBar { if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) { Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes"); // synchronize with current shadow state - mShadowController.hideElement(mNotificationArea); + mShadowController.hideElement(mNotificationIconArea); mTicker.halt(); } else { Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no"); // synchronize with current shadow state - mShadowController.showElement(mNotificationArea); + mShadowController.showElement(mNotificationIconArea); } } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { if ((state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) { |