diff options
| author | 2014-09-25 19:08:39 +0000 | |
|---|---|---|
| committer | 2014-09-25 19:08:40 +0000 | |
| commit | cf4ef820074944bc48ca11647845149cf0895d81 (patch) | |
| tree | 2cd5b3c31a9926c955be4c930e27592e09230138 | |
| parent | 99cee61cbc8ed1ec5514639f9fdac656b5e4934b (diff) | |
| parent | 27c7b9295d0ebb0223bd10eb582d171ade870c7e (diff) | |
Merge "Supertoast when user changes zen mode." into lmp-dev
| -rw-r--r-- | packages/SystemUI/res/anim/zen_toast_enter.xml | 20 | ||||
| -rw-r--r-- | packages/SystemUI/res/anim/zen_toast_exit.xml | 20 | ||||
| -rw-r--r-- | packages/SystemUI/res/drawable/ic_zen_important.xml | 25 | ||||
| -rw-r--r-- | packages/SystemUI/res/drawable/ic_zen_none.xml | 25 | ||||
| -rw-r--r-- | packages/SystemUI/res/drawable/zen_toast_background.xml | 19 | ||||
| -rw-r--r-- | packages/SystemUI/res/layout/zen_mode_panel.xml | 1 | ||||
| -rw-r--r-- | packages/SystemUI/res/layout/zen_toast.xml | 41 | ||||
| -rw-r--r-- | packages/SystemUI/res/values/config.xml | 6 | ||||
| -rw-r--r-- | packages/SystemUI/res/values/dimens.xml | 3 | ||||
| -rw-r--r-- | packages/SystemUI/res/values/styles.xml | 9 | ||||
| -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 |
12 files changed, 327 insertions, 0 deletions
diff --git a/packages/SystemUI/res/anim/zen_toast_enter.xml b/packages/SystemUI/res/anim/zen_toast_enter.xml new file mode 100644 index 000000000000..e236782fb3c5 --- /dev/null +++ b/packages/SystemUI/res/anim/zen_toast_enter.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<alpha xmlns:android="http://schemas.android.com/apk/res/android" + android:interpolator="@android:interpolator/decelerate_quad" + android:fromAlpha="0.0" android:toAlpha="1.0" + android:duration="@integer/zen_toast_animation_duration" /> diff --git a/packages/SystemUI/res/anim/zen_toast_exit.xml b/packages/SystemUI/res/anim/zen_toast_exit.xml new file mode 100644 index 000000000000..a9b1ab243b49 --- /dev/null +++ b/packages/SystemUI/res/anim/zen_toast_exit.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<alpha xmlns:android="http://schemas.android.com/apk/res/android" + android:interpolator="@android:interpolator/accelerate_quad" + android:fromAlpha="1.0" android:toAlpha="0.0" + android:duration="@integer/zen_toast_animation_duration" /> diff --git a/packages/SystemUI/res/drawable/ic_zen_important.xml b/packages/SystemUI/res/drawable/ic_zen_important.xml new file mode 100644 index 000000000000..11e90637e18d --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_zen_important.xml @@ -0,0 +1,25 @@ +<!-- +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. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="32dp" + android:height="32dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + + <path + android:fillColor="#FFFFFFFF" + android:pathData="M12.0,17.273l6.1800003,3.7269993 -1.6350002,-7.0290003 5.455,-4.7269993 -7.191,-0.6170006 -2.809,-6.627 -2.809,6.627 -7.191,0.6170006 5.455,4.7269993 -1.6349998,7.0290003z"/> +</vector>
\ No newline at end of file diff --git a/packages/SystemUI/res/drawable/ic_zen_none.xml b/packages/SystemUI/res/drawable/ic_zen_none.xml new file mode 100644 index 000000000000..681d49931d44 --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_zen_none.xml @@ -0,0 +1,25 @@ +<!-- +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. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="32dp" + android:height="32dp" + android:viewportWidth="48.0" + android:viewportHeight="48.0"> + + <path + android:fillColor="#FFFFFFFF" + android:pathData="M24.0,4.0C13.0,4.0 4.0,13.0 4.0,24.0c0.0,11.0 9.0,20.0 20.0,20.0c11.0,0.0 20.0,-9.0 20.0,-20.0C44.0,13.0 35.0,4.0 24.0,4.0zM24.0,40.0c-8.8,0.0 -16.0,-7.2 -16.0,-16.0c0.0,-3.7 1.3,-7.1 3.4,-9.8l22.4,22.4C31.1,38.7 27.7,40.0 24.0,40.0zM36.6,33.8L14.2,11.4C16.9,9.3 20.3,8.0 24.0,8.0c8.8,0.0 16.0,7.2 16.0,16.0C40.0,27.7 38.7,31.1 36.6,33.8z"/> +</vector>
\ No newline at end of file diff --git a/packages/SystemUI/res/drawable/zen_toast_background.xml b/packages/SystemUI/res/drawable/zen_toast_background.xml new file mode 100644 index 000000000000..619fe208802b --- /dev/null +++ b/packages/SystemUI/res/drawable/zen_toast_background.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <solid android:color="@color/system_primary_color" /> + <corners android:radius="@dimen/notification_material_rounded_rect_radius" /> +</shape> diff --git a/packages/SystemUI/res/layout/zen_mode_panel.xml b/packages/SystemUI/res/layout/zen_mode_panel.xml index d0fba20d53e4..ece6979724db 100644 --- a/packages/SystemUI/res/layout/zen_mode_panel.xml +++ b/packages/SystemUI/res/layout/zen_mode_panel.xml @@ -44,6 +44,7 @@ android:id="@+id/zen_subhead" android:layout_width="match_parent" android:layout_height="62dp" + android:gravity="center_vertical" android:paddingLeft="8dp" android:paddingRight="8dp" > diff --git a/packages/SystemUI/res/layout/zen_toast.xml b/packages/SystemUI/res/layout/zen_toast.xml new file mode 100644 index 000000000000..1e3d3cf12755 --- /dev/null +++ b/packages/SystemUI/res/layout/zen_toast.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + 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. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/zen_toast_background" + android:translationZ="@dimen/volume_panel_z" + android:padding="18dp" + android:gravity="center_horizontal" + android:orientation="vertical" > + + <ImageView + android:id="@android:id/icon" + android:layout_width="32dp" + android:layout_height="32dp" + android:scaleType="center" /> + + <TextView + android:id="@android:id/message" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:lineSpacingExtra="4dp" + android:gravity="center_horizontal" + android:textAppearance="@style/TextAppearance.QS.ZenToast" /> + +</LinearLayout> diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 2e6f898dc470..8267846f0145 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -239,5 +239,11 @@ <!-- Number of times to show the strong alarm warning text in the volume dialog --> <integer name="zen_mode_alarm_warning_threshold">5</integer> + + <!-- Zen toast fade in/out duration --> + <integer name="zen_toast_animation_duration">500</integer> + + <!-- Zen toast visibility duration --> + <integer name="zen_toast_visible_duration">2000</integer> </resources> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index c690ef4f89e9..4f41cd560ae4 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -193,6 +193,9 @@ <dimen name="zen_mode_condition_detail_button_padding">8dp</dimen> + <!-- Explicit width of the zen toast window --> + <dimen name="zen_toast_width">224dp</dimen> + <!-- used by DessertCase --> <dimen name="dessert_case_cell_size">192dp</dimen> diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml index 46e7587cb14e..909dc4279609 100644 --- a/packages/SystemUI/res/values/styles.xml +++ b/packages/SystemUI/res/values/styles.xml @@ -167,6 +167,10 @@ <item name="android:textColor">@color/qs_subhead</item> </style> + <style name="TextAppearance.QS.ZenToast"> + <item name="android:textSize">14sp</item> + </style> + <style name="TextAppearance.QS.SegmentedButton"> <item name="android:textSize">14sp</item> <item name="android:textAllCaps">true</item> @@ -262,4 +266,9 @@ <style name="UserDetailView"> <item name="numColumns">3</item> </style> + + <style name="ZenToastAnimations"> + <item name="android:windowEnterAnimation">@anim/zen_toast_enter</item> + <item name="android:windowExitAnimation">@anim/zen_toast_exit</item> + </style> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index 2b541d39e091..c1681c7c36d2 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 000000000000..96e2a8eb566f --- /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(); + } + } + }; +} |