From c791e05f768ff66e801f872cfdf27cc62b6195db Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 19 Feb 2016 16:02:01 -0500 Subject: [PATCH] Scale volume panel with density changes. Also remove invisible settings buttons. Bug: 26846853 Change-Id: I15722f5705a7718a90033d24c185eb21c8c41bc9 --- .../SystemUI/res/layout/volume_dialog.xml | 40 +-- .../SystemUI/res/layout/volume_dialog_row.xml | 18 +- .../SystemUI/res/layout/volume_zen_footer.xml | 4 +- .../android/systemui/volume/VolumeDialog.java | 250 ++++++++---------- .../volume/VolumeDialogComponent.java | 5 - .../android/systemui/volume/VolumePrefs.java | 2 +- .../android/systemui/volume/ZenFooter.java | 3 +- 7 files changed, 144 insertions(+), 178 deletions(-) diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml index e4effd4878967..baec8ef344cd1 100644 --- a/packages/SystemUI/res/layout/volume_dialog.xml +++ b/packages/SystemUI/res/layout/volume_dialog.xml @@ -13,25 +13,15 @@ See the License for the specific language governing permissions and limitations under the License. --> - - - + android:translationZ="4dp" + android:paddingTop="8dp"> + android:paddingStart="8dp"> + @@ -49,4 +45,18 @@ + + diff --git a/packages/SystemUI/res/layout/volume_dialog_row.xml b/packages/SystemUI/res/layout/volume_dialog_row.xml index 91e931da1f3ee..57bac4117e8da 100644 --- a/packages/SystemUI/res/layout/volume_dialog_row.xml +++ b/packages/SystemUI/res/layout/volume_dialog_row.xml @@ -13,13 +13,12 @@ See the License for the specific language governing permissions and limitations under the License. --> - + android:id="@+id/volume_dialog_row" > + android:paddingTop="4dp" + android:visibility="gone" /> - - \ No newline at end of file diff --git a/packages/SystemUI/res/layout/volume_zen_footer.xml b/packages/SystemUI/res/layout/volume_zen_footer.xml index 28447d772c867..f30023dc8ef47 100644 --- a/packages/SystemUI/res/layout/volume_zen_footer.xml +++ b/packages/SystemUI/res/layout/volume_zen_footer.xml @@ -32,9 +32,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" - android:orientation="horizontal" - android:paddingEnd="8dp" - android:paddingStart="8dp" > + android:orientation="horizontal" > mRows = new ArrayList(); + private CustomDialog mDialog; + private ViewGroup mDialogView; + private ViewGroup mDialogContentView; + private ViewGroup mVolumeRowContainer; + private ImageButton mExpandButton; + private final List mRows = new ArrayList<>(); private final SpTexts mSpTexts; private final SparseBooleanArray mDynamic = new SparseBooleanArray(); private final KeyguardManager mKeyguard; private final AudioManager mAudioManager; - private final int mExpandButtonAnimationDuration; - private final ZenFooter mZenFooter; + private int mExpandButtonAnimationDuration; + private ZenFooter mZenFooter; private final LayoutTransition mLayoutTransition; private final Object mSafetyWarningLock = new Object(); private final Accessibility mAccessibility = new Accessibility(); private final ColorStateList mActiveSliderTint; private final ColorStateList mInactiveSliderTint; - private final VolumeDialogMotion mMotion; + private VolumeDialogMotion mMotion; + private final int mWindowType; + private final ZenModeController mZenModeController; private boolean mShowing; private boolean mExpanded; + private int mActiveStream; private boolean mShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS; private boolean mAutomute = VolumePrefs.DEFAULT_ENABLE_AUTOMUTE; private boolean mSilentMode = VolumePrefs.DEFAULT_ENABLE_SILENT_MODE; private State mState; - private int mExpandButtonRes; private boolean mExpandButtonAnimationRunning; private SafetyWarningDialog mSafetyWarning; private Callback mCallback; @@ -131,22 +133,43 @@ public class VolumeDialog implements TunerService.Tunable { private boolean mPendingRecheckAll; private long mCollapseTime; private boolean mHovering = false; - private int mLastActiveStream; + private int mDensity; private boolean mShowFullZen; - private final TunerZenModePanel mZenPanel; + private TunerZenModePanel mZenPanel; public VolumeDialog(Context context, int windowType, VolumeDialogController controller, ZenModeController zenModeController, Callback callback) { mContext = context; mController = controller; mCallback = callback; + mWindowType = windowType; + mZenModeController = zenModeController; mSpTexts = new SpTexts(mContext); mKeyguard = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + mActiveSliderTint = loadColorStateList(R.color.system_accent_color); + mInactiveSliderTint = loadColorStateList(R.color.volume_slider_inactive); + mLayoutTransition = new LayoutTransition(); + mLayoutTransition.setDuration(new ValueAnimator().getDuration() / 2); + initDialog(); + + mAccessibility.init(); + + controller.addCallback(mControllerCallbackH, mHandler); + controller.getState(); + TunerService.get(mContext).addTunable(this, SHOW_FULL_ZEN); + + final Configuration currentConfig = mContext.getResources().getConfiguration(); + mDensity = currentConfig.densityDpi; + } + + private void initDialog() { mDialog = new CustomDialog(mContext); + mHovering = false; + mShowing = false; final Window window = mDialog.getWindow(); window.requestFeature(Window.FEATURE_NO_TITLE); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); @@ -160,7 +183,7 @@ public class VolumeDialog implements TunerService.Tunable { mDialog.setCanceledOnTouchOutside(true); final Resources res = mContext.getResources(); final WindowManager.LayoutParams lp = window.getAttributes(); - lp.type = windowType; + lp.type = mWindowType; lp.format = PixelFormat.TRANSLUCENT; lp.setTitle(VolumeDialog.class.getSimpleName()); lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; @@ -170,8 +193,7 @@ public class VolumeDialog implements TunerService.Tunable { window.setAttributes(lp); window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); - mActiveSliderTint = loadColorStateList(R.color.system_accent_color); - mInactiveSliderTint = loadColorStateList(R.color.volume_slider_inactive); + mDialog.setContentView(R.layout.volume_dialog); mDialogView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog); mDialogView.setOnHoverListener(new View.OnHoverListener() { @@ -185,56 +207,53 @@ public class VolumeDialog implements TunerService.Tunable { } }); mDialogContentView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog_content); + mVolumeRowContainer = + (ViewGroup) mDialogContentView.findViewById(R.id.volume_row_container); + mExpanded = false; mExpandButton = (ImageButton) mDialogView.findViewById(R.id.volume_expand_button); mExpandButton.setOnClickListener(mClickExpand); updateWindowWidthH(); updateExpandButtonH(); - mLayoutTransition = new LayoutTransition(); - mLayoutTransition.setDuration(new ValueAnimator().getDuration() / 2); + mDialogContentView.setLayoutTransition(mLayoutTransition); mMotion = new VolumeDialogMotion(mDialog, mDialogView, mDialogContentView, mExpandButton, new VolumeDialogMotion.Callback() { - @Override - public void onAnimatingChanged(boolean animating) { - if (animating) return; - if (mPendingStateChanged) { - mHandler.sendEmptyMessage(H.STATE_CHANGED); - mPendingStateChanged = false; - } - if (mPendingRecheckAll) { - mHandler.sendEmptyMessage(H.RECHECK_ALL); - mPendingRecheckAll = false; - } - } - }); + @Override + public void onAnimatingChanged(boolean animating) { + if (animating) return; + if (mPendingStateChanged) { + mHandler.sendEmptyMessage(H.STATE_CHANGED); + mPendingStateChanged = false; + } + if (mPendingRecheckAll) { + mHandler.sendEmptyMessage(H.RECHECK_ALL); + mPendingRecheckAll = false; + } + } + }); - addRow(AudioManager.STREAM_RING, - R.drawable.ic_volume_ringer, R.drawable.ic_volume_ringer_mute, true); - addRow(AudioManager.STREAM_MUSIC, - R.drawable.ic_volume_media, R.drawable.ic_volume_media_mute, true); - addRow(AudioManager.STREAM_ALARM, - R.drawable.ic_volume_alarm, R.drawable.ic_volume_alarm_mute, false); - addRow(AudioManager.STREAM_VOICE_CALL, - R.drawable.ic_volume_voice, R.drawable.ic_volume_voice, false); - addRow(AudioManager.STREAM_BLUETOOTH_SCO, - R.drawable.ic_volume_bt_sco, R.drawable.ic_volume_bt_sco, false); - addRow(AudioManager.STREAM_SYSTEM, - R.drawable.ic_volume_system, R.drawable.ic_volume_system_mute, false); - - mSettingsButton = mDialog.findViewById(R.id.volume_settings_button); - mSettingsButton.setOnClickListener(mClickSettings); + if (mRows.isEmpty()) { + addRow(AudioManager.STREAM_RING, + R.drawable.ic_volume_ringer, R.drawable.ic_volume_ringer_mute, true); + addRow(AudioManager.STREAM_MUSIC, + R.drawable.ic_volume_media, R.drawable.ic_volume_media_mute, true); + addRow(AudioManager.STREAM_ALARM, + R.drawable.ic_volume_alarm, R.drawable.ic_volume_alarm_mute, false); + addRow(AudioManager.STREAM_VOICE_CALL, + R.drawable.ic_volume_voice, R.drawable.ic_volume_voice, false); + addRow(AudioManager.STREAM_BLUETOOTH_SCO, + R.drawable.ic_volume_bt_sco, R.drawable.ic_volume_bt_sco, false); + addRow(AudioManager.STREAM_SYSTEM, + R.drawable.ic_volume_system, R.drawable.ic_volume_system_mute, false); + } else { + addExistingRows(); + } mExpandButtonAnimationDuration = res.getInteger(R.integer.volume_expand_animation_duration); mZenFooter = (ZenFooter) mDialog.findViewById(R.id.volume_zen_footer); - mZenFooter.init(zenModeController); + mZenFooter.init(mZenModeController); mZenPanel = (TunerZenModePanel) mDialog.findViewById(R.id.tuner_zen_mode_panel); - mZenPanel.init(zenModeController); + mZenPanel.init(mZenModeController); mZenPanel.setCallback(mZenPanelCallback); - - mAccessibility.init(); - - controller.addCallback(mControllerCallbackH, mHandler); - controller.getState(); - TunerService.get(mContext).addTunable(this, SHOW_FULL_ZEN); } @Override @@ -285,46 +304,38 @@ public class VolumeDialog implements TunerService.Tunable { } private void addRow(int stream, int iconRes, int iconMuteRes, boolean important) { - final VolumeRow row = initRow(stream, iconRes, iconMuteRes, important); + VolumeRow row = new VolumeRow(); + initRow(row, stream, iconRes, iconMuteRes, important); if (!mRows.isEmpty()) { - final View v = new View(mContext); - v.setId(android.R.id.background); - final int h = mContext.getResources() - .getDimensionPixelSize(R.dimen.volume_slider_interspacing); - final LinearLayout.LayoutParams lp = - new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, h); - mDialogContentView.addView(v, mDialogContentView.getChildCount() - 2, lp); - row.space = v; + addSpacer(row); } - row.settingsButton.addOnLayoutChangeListener(new OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - final boolean moved = mLastActiveStream != mActiveStream || - oldLeft != left || oldTop != top; - if (D.BUG) Log.d(TAG, "onLayoutChange moved=" + moved - + " old=" + new Rect(oldLeft, oldTop, oldRight, oldBottom).toShortString() - + "," + mLastActiveStream - + " new=" + new Rect(left,top,right,bottom).toShortString() - + "," + mActiveStream); - mLastActiveStream = mActiveStream; - if (moved) { - for (int i = 0; i < mDialogContentView.getChildCount(); i++) { - final View c = mDialogContentView.getChildAt(i); - if (!c.isShown()) continue; - if (c == row.view) { - repositionExpandAnim(row); - } - return; - } - } - } - }); - // add new row just before the footer - mDialogContentView.addView(row.view, mDialogContentView.getChildCount() - 2); + mVolumeRowContainer.addView(row.view); mRows.add(row); } + private void addExistingRows() { + int N = mRows.size(); + for (int i = 0; i < N; i++) { + final VolumeRow row = mRows.get(i); + initRow(row, row.stream, row.iconRes, row.iconMuteRes, row.important); + if (i > 0) { + addSpacer(row); + } + mVolumeRowContainer.addView(row.view); + } + } + + private void addSpacer(VolumeRow row) { + final View v = new View(mContext); + v.setId(android.R.id.background); + final int h = mContext.getResources() + .getDimensionPixelSize(R.dimen.volume_slider_interspacing); + final LinearLayout.LayoutParams lp = + new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, h); + mVolumeRowContainer.addView(v, lp); + row.space = v; + } + private boolean isAttached() { return mDialogContentView != null && mDialogContentView.isAttachedToWindow(); } @@ -345,18 +356,6 @@ public class VolumeDialog implements TunerService.Tunable { return null; } - private void repositionExpandAnim(VolumeRow row) { - final int[] loc = new int[2]; - row.settingsButton.getLocationInWindow(loc); - final MarginLayoutParams mlp = (MarginLayoutParams) mDialogView.getLayoutParams(); - final int x = loc[0] - mlp.leftMargin; - final int y = loc[1] - mlp.topMargin; - if (D.BUG) Log.d(TAG, "repositionExpandAnim x=" + x + " y=" + y); - mExpandButton.setTranslationX(x); - mExpandButton.setTranslationY(y); - mExpandButton.setTag((Integer) y); - } - public void dump(PrintWriter writer) { writer.println(VolumeDialog.class.getSimpleName() + " state:"); writer.print(" mShowing: "); writer.println(mShowing); @@ -374,8 +373,8 @@ public class VolumeDialog implements TunerService.Tunable { } @SuppressLint("InflateParams") - private VolumeRow initRow(final int stream, int iconRes, int iconMuteRes, boolean important) { - final VolumeRow row = new VolumeRow(); + private void initRow(final VolumeRow row, final int stream, int iconRes, int iconMuteRes, + boolean important) { row.stream = stream; row.iconRes = iconRes; row.iconMuteRes = iconMuteRes; @@ -442,9 +441,6 @@ public class VolumeDialog implements TunerService.Tunable { row.userAttempt = 0; // reset the grace period, slider should update immediately } }); - row.settingsButton = (ImageButton) row.view.findViewById(R.id.volume_settings_button); - row.settingsButton.setOnClickListener(mClickSettings); - return row; } public void destroy() { @@ -573,8 +569,6 @@ public class VolumeDialog implements TunerService.Tunable { if (mExpandButtonAnimationRunning && isAttached()) return; final int res = mExpanded ? R.drawable.ic_volume_collapse_animation : R.drawable.ic_volume_expand_animation; - if (res == mExpandButtonRes) return; - mExpandButtonRes = res; if (hasTouchFeature()) { mExpandButton.setImageResource(res); } else { @@ -606,16 +600,6 @@ public class VolumeDialog implements TunerService.Tunable { final boolean visible = isVisibleH(row, isActive); Util.setVisOrGone(row.view, visible); Util.setVisOrGone(row.space, visible && mExpanded); - final int expandButtonRes = mExpanded ? R.drawable.ic_volume_settings : 0; - if (expandButtonRes != row.cachedExpandButtonRes) { - row.cachedExpandButtonRes = expandButtonRes; - if (expandButtonRes == 0) { - row.settingsButton.setImageDrawable(null); - } else { - row.settingsButton.setImageResource(expandButtonRes); - } - } - Util.setVisOrInvis(row.settingsButton, false); updateVolumeRowHeaderVisibleH(row); row.header.setAlpha(mExpanded && isActive ? 1 : 0.5f); updateVolumeRowSliderTintH(row, isActive); @@ -629,8 +613,8 @@ public class VolumeDialog implements TunerService.Tunable { if (row.ss == null || !row.ss.dynamic) continue; if (!mDynamic.get(row.stream)) { mRows.remove(i); - mDialogContentView.removeView(row.view); - mDialogContentView.removeView(row.space); + mVolumeRowContainer.removeView(row.view); + mVolumeRowContainer.removeView(row.space); } } } @@ -911,6 +895,12 @@ public class VolumeDialog implements TunerService.Tunable { @Override public void onConfigurationChanged() { + Configuration newConfig = mContext.getResources().getConfiguration(); + final int density = newConfig.densityDpi; + if (density != mDensity) { + mDialog.dismiss(); + initDialog(); + } updateWindowWidthH(); mSpTexts.update(); mZenFooter.onConfigurationChanged(); @@ -963,21 +953,6 @@ public class VolumeDialog implements TunerService.Tunable { } }; - private final OnClickListener mClickSettings = new OnClickListener() { - @Override - public void onClick(View v) { - mSettingsButton.postDelayed(new Runnable() { - @Override - public void run() { - Events.writeEvent(mContext, Events.EVENT_SETTINGS_CLICK); - if (mCallback != null) { - mCallback.onSettingsClicked(); - } - } - }, WAIT_FOR_RIPPLE); - } - }; - private final class H extends Handler { private static final int SHOW = 1; private static final int DISMISS = 2; @@ -1155,7 +1130,6 @@ public class VolumeDialog implements TunerService.Tunable { private TextView header; private ImageButton icon; private SeekBar slider; - private ImageButton settingsButton; private int stream; private StreamState ss; private long userAttempt; // last user-driven slider change @@ -1168,12 +1142,10 @@ public class VolumeDialog implements TunerService.Tunable { private ColorStateList cachedSliderTint; private int iconState; // from Events private boolean cachedShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS; - private int cachedExpandButtonRes; private int lastAudibleLevel = 1; } public interface Callback { - void onSettingsClicked(); void onZenSettingsClicked(); void onZenPrioritySettingsClicked(); } diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java index d7635ad9acb13..3d338098fc2df 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java @@ -167,11 +167,6 @@ public class VolumeDialogComponent implements VolumeComponent, TunerService.Tuna } private final VolumeDialog.Callback mVolumeDialogCallback = new VolumeDialog.Callback() { - @Override - public void onSettingsClicked() { - startSettings(new Intent(Settings.ACTION_NOTIFICATION_SETTINGS)); - } - @Override public void onZenSettingsClicked() { startSettings(ZenModePanel.ZEN_SETTINGS); diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumePrefs.java b/packages/SystemUI/src/com/android/systemui/volume/VolumePrefs.java index 04339eb8e8028..bbb70ed6bf47a 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumePrefs.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumePrefs.java @@ -43,7 +43,7 @@ public class VolumePrefs { public static final String PREF_ADJUST_ALARMS = "pref_adjust_alarms"; public static final String PREF_ADJUST_NOTIFICATION = "pref_adjust_notification"; - public static final boolean DEFAULT_SHOW_HEADERS = true; + public static final boolean DEFAULT_SHOW_HEADERS = false; public static final boolean DEFAULT_ENABLE_AUTOMUTE = true; public static final boolean DEFAULT_ENABLE_SILENT_MODE = true; diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java b/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java index a03e7f7d50293..c06b63bd8f662 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenFooter.java @@ -139,9 +139,8 @@ public class ZenFooter extends LinearLayout { } public void onConfigurationChanged() { - mEndNowButton.setText(mContext.getString(R.string.volume_zen_end_now)); - mSpTexts.update(); Util.setText(mEndNowButton, mContext.getString(R.string.volume_zen_end_now)); + mSpTexts.update(); } }