diff options
author | John Spurlock <jspurlock@google.com> | 2014-09-23 14:59:51 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2014-09-25 15:04:32 -0400 |
commit | 27c7b9295d0ebb0223bd10eb582d171ade870c7e (patch) | |
tree | ce3e56591de3d527f8864b9b9f8e26db8a4d5b96 /packages/SystemUI/src/com/android/systemui/volume | |
parent | e1b032a84086a5d6f36b6910171110543224bdf5 (diff) | |
download | frameworks_base-27c7b9295d0ebb0223bd10eb582d171ade870c7e.zip frameworks_base-27c7b9295d0ebb0223bd10eb582d171ade870c7e.tar.gz frameworks_base-27c7b9295d0ebb0223bd10eb582d171ade870c7e.tar.bz2 |
Supertoast when user changes zen mode.
If the user selects a new zen mode, display a quick toast
with the mode icon + text to aid in association.
Also fix a recent regression in the zen subhead alignment.
Bug:16215680
Bug:17641211
Change-Id: I4ead88d81be4d9c26459aed82c47b8c2fb32eafa
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/volume')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java | 7 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/ZenToast.java | 151 |
2 files changed, 158 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index 2b541d3..c1681c7 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -78,6 +78,7 @@ public class ZenModePanel extends LinearLayout { private final Interpolator mFastOutSlowInInterpolator; private final int mSubheadWarningColor; private final int mSubheadColor; + private final ZenToast mZenToast; private String mTag = TAG + "/" + Integer.toHexString(System.identityHashCode(this)); @@ -112,6 +113,7 @@ public class ZenModePanel extends LinearLayout { final Resources res = mContext.getResources(); mSubheadWarningColor = res.getColor(R.color.system_warning_color); mSubheadColor = res.getColor(R.color.qs_subhead); + mZenToast = new ZenToast(mContext); if (DEBUG) Log.d(mTag, "new ZenModePanel"); } @@ -155,6 +157,7 @@ public class ZenModePanel extends LinearLayout { protected void onAttachedToWindow() { super.onAttachedToWindow(); if (DEBUG) Log.d(mTag, "onAttachedToWindow"); + mZenToast.hide(); mAttachedZen = getSelectedZen(-1); mSessionZen = mAttachedZen; mSessionExitCondition = copy(mExitCondition); @@ -187,6 +190,10 @@ public class ZenModePanel extends LinearLayout { if (selectedZen == Global.ZEN_MODE_NO_INTERRUPTIONS) { mPrefs.trackNoneSelected(); } + if (selectedZen == Global.ZEN_MODE_NO_INTERRUPTIONS + || selectedZen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS) { + mZenToast.show(selectedZen); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenToast.java b/packages/SystemUI/src/com/android/systemui/volume/ZenToast.java new file mode 100644 index 0000000..96e2a8e --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenToast.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2014 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.volume; + +import static android.provider.Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; +import static android.provider.Settings.Global.ZEN_MODE_NO_INTERRUPTIONS; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.res.Resources; +import android.graphics.PixelFormat; +import android.os.Handler; +import android.os.Message; +import android.os.UserHandle; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import com.android.systemui.R; + +public class ZenToast { + private static final String ACTION_SHOW = ZenToast.class.getName() + ".SHOW"; + private static final String ACTION_HIDE = ZenToast.class.getName() + ".HIDE"; + private static final String EXTRA_ZEN = "zen"; + private static final String EXTRA_TEXT = "text"; + + private static final int MSG_SHOW = 1; + private static final int MSG_HIDE = 2; + + private final Context mContext; + private final WindowManager mWindowManager; + + private View mZenToast; + + public ZenToast(Context context) { + mContext = context; + mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); + final IntentFilter filter = new IntentFilter(); + filter.addAction(ACTION_SHOW); + filter.addAction(ACTION_HIDE); + mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler); + } + + public void show(int zen) { + mHandler.removeMessages(MSG_HIDE); + mHandler.removeMessages(MSG_SHOW); + mHandler.obtainMessage(MSG_SHOW, zen, 0).sendToTarget(); + } + + public void hide() { + mHandler.removeMessages(MSG_HIDE); + mHandler.removeMessages(MSG_SHOW); + mHandler.obtainMessage(MSG_HIDE).sendToTarget(); + } + + private void handleShow(int zen, String overrideText) { + handleHide(); + + String text; + final int iconRes; + switch (zen) { + case ZEN_MODE_NO_INTERRUPTIONS: + text = mContext.getString(R.string.zen_no_interruptions); + iconRes = R.drawable.ic_zen_none; + break; + case ZEN_MODE_IMPORTANT_INTERRUPTIONS: + text = mContext.getString(R.string.zen_important_interruptions); + iconRes = R.drawable.ic_zen_important; + break; + default: + return; + } + if (overrideText != null) { + text = overrideText; + } + final Resources res = mContext.getResources(); + final WindowManager.LayoutParams params = new WindowManager.LayoutParams(); + params.height = WindowManager.LayoutParams.WRAP_CONTENT; + params.width = res.getDimensionPixelSize(R.dimen.zen_toast_width); + params.format = PixelFormat.TRANSLUCENT; + params.windowAnimations = R.style.ZenToastAnimations; + params.type = WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; + params.setTitle(getClass().getSimpleName()); + params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; + params.gravity = Gravity.CENTER; + params.packageName = mContext.getPackageName(); + mZenToast = LayoutInflater.from(mContext).inflate(R.layout.zen_toast, null); + final TextView message = (TextView) mZenToast.findViewById(android.R.id.message); + message.setText(text); + final ImageView icon = (ImageView) mZenToast.findViewById(android.R.id.icon); + icon.setImageResource(iconRes); + mWindowManager.addView(mZenToast, params); + final int animDuration = res.getInteger(R.integer.zen_toast_animation_duration); + final int visibleDuration = res.getInteger(R.integer.zen_toast_visible_duration); + mHandler.sendEmptyMessageDelayed(MSG_HIDE, animDuration + visibleDuration); + } + + private void handleHide() { + if (mZenToast != null) { + mWindowManager.removeView(mZenToast); + mZenToast = null; + } + } + + private final Handler mHandler = new Handler() { + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_SHOW: + handleShow(msg.arg1, null); + break; + case MSG_HIDE: + handleHide(); + break; + } + } + }; + + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (ACTION_SHOW.equals(intent.getAction())) { + final int zen = intent.getIntExtra(EXTRA_ZEN, ZEN_MODE_IMPORTANT_INTERRUPTIONS); + final String text = intent.getStringExtra(EXTRA_TEXT); + handleShow(zen, text); + } else if (ACTION_HIDE.equals(intent.getAction())) { + handleHide(); + } + } + }; +} |