diff options
author | John Spurlock <jspurlock@google.com> | 2014-05-31 23:18:12 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-31 23:18:13 +0000 |
commit | 254310450a5e03a8e7113ed9d159d01cb67f93f0 (patch) | |
tree | 6d1f4b20044b2a0e4505f6356cb30a3aef26d195 /packages | |
parent | 9dcfe06154f6bd7c1de2fab2e436b8251b7d5fca (diff) | |
parent | 7f1df5e98578f8532a5e009009e7c1f82ed5885c (diff) | |
download | frameworks_base-254310450a5e03a8e7113ed9d159d01cb67f93f0.zip frameworks_base-254310450a5e03a8e7113ed9d159d01cb67f93f0.tar.gz frameworks_base-254310450a5e03a8e7113ed9d159d01cb67f93f0.tar.bz2 |
Merge "VolumeZen: Slider icon as ringer-mode toggle." into lmp-preview-dev
Diffstat (limited to 'packages')
4 files changed, 97 insertions, 30 deletions
diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml new file mode 100644 index 0000000..5afa967 --- /dev/null +++ b/packages/SystemUI/res/layout/volume_dialog.xml @@ -0,0 +1,26 @@ +<?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. +--> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@drawable/qs_panel_background" + android:translationZ="@dimen/volume_panel_z" + android:layout_margin="@dimen/volume_panel_z"> + + <include layout="@layout/volume_panel" /> + +</FrameLayout>
\ No newline at end of file diff --git a/packages/SystemUI/res/layout/volume_panel_item.xml b/packages/SystemUI/res/layout/volume_panel_item.xml index 98cb8f4..759679b 100644 --- a/packages/SystemUI/res/layout/volume_panel_item.xml +++ b/packages/SystemUI/res/layout/volume_panel_item.xml @@ -24,19 +24,21 @@ <ImageView android:id="@+id/stream_icon" + style="@style/BorderlessButton.Tiny" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="16dip" - android:background="?android:attr/selectableItemBackground" + android:padding="16dip" android:contentDescription="@null" /> - <SeekBar style="?android:attr/seekBarStyle" android:id="@+id/seekbar" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" - android:padding="16dip" + android:paddingTop="16dip" + android:paddingBottom="16dip" + android:paddingStart="11dip" + android:paddingEnd="11dip" android:layout_marginEnd="16dip" /> </LinearLayout> diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java b/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java index cbfc641..7000e82 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java @@ -42,6 +42,8 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; +import android.view.View.OnClickListener; +import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.ViewStub; import android.view.Window; @@ -284,7 +286,6 @@ public class VolumePanel extends Handler { } } if (LOGD) Log.d(mTag, String.format("new VolumePanel hasParent=%s", parent != null)); - final int layoutId = com.android.systemui.R.layout.volume_panel; if (parent == null) { // dialog mode mDialog = new Dialog(context) { @@ -318,15 +319,7 @@ public class VolumePanel extends Handler { | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | LayoutParams.FLAG_HARDWARE_ACCELERATED); mDialog.setCanceledOnTouchOutside(true); - // temporary workaround for no window shadows - final FrameLayout layout = new FrameLayout(mContext); - final int z = res.getDimensionPixelSize(com.android.systemui.R.dimen.volume_panel_z); - layout.setPadding(z, z, z, z); - final View v = LayoutInflater.from(mContext).inflate(layoutId, layout, false); - v.setBackgroundResource(com.android.systemui.R.drawable.qs_panel_background); - v.setElevation(z); - layout.addView(v); - mDialog.setContentView(layout); + mDialog.setContentView(com.android.systemui.R.layout.volume_dialog); mDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { @@ -336,6 +329,7 @@ public class VolumePanel extends Handler { }); mDialog.create(); + // temporary workaround, until we support window-level shadows mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000)); mView = window.findViewById(R.id.content); @@ -350,7 +344,8 @@ public class VolumePanel extends Handler { } else { // embedded mode mDialog = null; - mView = LayoutInflater.from(mContext).inflate(layoutId, parent, true); + mView = LayoutInflater.from(mContext).inflate( + com.android.systemui.R.layout.volume_panel, parent, true); } mPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.visible_panel); mSliderPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.slider_panel); @@ -460,6 +455,24 @@ public class VolumePanel extends Handler { sc.iconRes = streamRes.iconRes; sc.iconMuteRes = streamRes.iconMuteRes; sc.icon.setImageResource(sc.iconRes); + sc.icon.setClickable(isNotificationOrRing(streamType)); + if (sc.icon.isClickable()) { + sc.icon.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + resetTimeout(); + toggle(sc); + } + }); + sc.icon.setOnLongClickListener(new OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + resetTimeout(); + longToggle(sc); + return true; + } + }); + } sc.seekbarView = (SeekBar) sc.group.findViewById(com.android.systemui.R.id.seekbar); final int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO || streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0; @@ -470,6 +483,26 @@ public class VolumePanel extends Handler { } } + private void toggle(StreamControl sc) { + if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { + mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); + postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE); + } else { + mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); + postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND); + } + } + + private void longToggle(StreamControl sc) { + if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { + mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); + postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND); + } else { + mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); + postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI); // disable the slider + } + } + private void reorderSliders(int activeStreamType) { mSliderPanel.removeAllViews(); @@ -493,23 +526,35 @@ public class VolumePanel extends Handler { // Force reloading the image resource sc.icon.setImageDrawable(null); sc.icon.setImageResource(muted ? sc.iconMuteRes : sc.iconRes); - if (((sc.streamType == AudioManager.STREAM_RING) || - (sc.streamType == AudioManager.STREAM_NOTIFICATION)) && + if (isNotificationOrRing(sc.streamType) && mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { sc.icon.setImageResource(com.android.systemui.R.drawable.ic_ringer_vibrate); } + updateSliderEnabled(sc, muted, false); + } + + private void updateSliderEnabled(StreamControl sc, boolean muted, boolean fixedVolume) { if (sc.streamType == AudioService.STREAM_REMOTE_MUSIC) { // never disable touch interactions for remote playback, the muting is not tied to // the state of the phone. sc.seekbarView.setEnabled(true); - } else if ((sc.streamType != mAudioManager.getMasterStreamType() && muted) || + } else if (fixedVolume || + (sc.streamType != mAudioManager.getMasterStreamType() && muted) || (sConfirmSafeVolumeDialog != null)) { sc.seekbarView.setEnabled(false); + } else if (isNotificationOrRing(sc.streamType) + && mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { + sc.seekbarView.setEnabled(false); } else { sc.seekbarView.setEnabled(true); } } + private static boolean isNotificationOrRing(int streamType) { + return streamType == AudioManager.STREAM_RING + || streamType == AudioManager.STREAM_NOTIFICATION; + } + public void setZenModePanelCallback(ZenModePanel.Callback callback) { mZenPanelCallback = callback; } @@ -562,8 +607,7 @@ public class VolumePanel extends Handler { private void updateZenMode(boolean zen) { if (mZenModeCapable) { - final boolean show = mActiveStreamType == AudioManager.STREAM_NOTIFICATION - || mActiveStreamType == AudioManager.STREAM_RING; + final boolean show = isNotificationOrRing(mActiveStreamType); mExpandButton.setVisibility(show ? View.VISIBLE : View.GONE); mExpandDivider.setVisibility(show ? View.VISIBLE : View.GONE); mExpandButton.setImageResource(zen ? com.android.systemui.R.drawable.ic_vol_zen_on @@ -790,15 +834,8 @@ public class VolumePanel extends Handler { } sc.seekbarView.setProgress(index); - if (((flags & AudioManager.FLAG_FIXED_VOLUME) != 0) || - (streamType != mAudioManager.getMasterStreamType() && - streamType != AudioService.STREAM_REMOTE_MUSIC && - isMuted(streamType)) || - sConfirmSafeVolumeDialog != null) { - sc.seekbarView.setEnabled(false); - } else { - sc.seekbarView.setEnabled(true); - } + updateSliderEnabled(sc, isMuted(streamType), + (flags & AudioManager.FLAG_FIXED_VOLUME) != 0); } if (!isShowing()) { @@ -1173,7 +1210,7 @@ public class VolumePanel extends Handler { private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() { public void onZenChanged(boolean zen) { - updateZenMode(zen); + postZenModeChanged(zen); } }; } diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index 77d267e..c338563 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -45,6 +45,7 @@ public class ZenModePanel extends LinearLayout { private static final int[] MINUTES = new int[] { 15, 30, 45, 60, 120, 180, 240, 480 }; public static final Intent ZEN_SETTINGS = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS); + private final Context mContext; private final LayoutInflater mInflater; private final HashSet<RadioButton> mRadioButtons = new HashSet<RadioButton>(); private final H mHandler = new H(); @@ -56,6 +57,7 @@ public class ZenModePanel extends LinearLayout { public ZenModePanel(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; mInflater = LayoutInflater.from(new ContextThemeWrapper(context, R.style.QSWhiteTheme)); } |