diff options
5 files changed, 107 insertions, 131 deletions
diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml index 90761994cde6..18ffd0fac417 100644 --- a/packages/SystemUI/res/layout/volume_dialog.xml +++ b/packages/SystemUI/res/layout/volume_dialog.xml @@ -16,12 +16,12 @@ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/volume_dialog" - android:layout_width="@dimen/volume_dialog_panel_width" + android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/volume_dialog_margin_bottom" - android:layout_gravity="center_vertical|end" + android:background="@drawable/volume_dialog_background" android:paddingTop="@dimen/volume_dialog_padding_top" - android:translationZ="8dp" > + android:translationZ="4dp" > <LinearLayout android:id="@+id/volume_dialog_content" @@ -57,7 +57,6 @@ android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="1" - android:visibility="gone" android:textAppearance="@style/TextAppearance.Volume.Header" /> <com.android.keyguard.AlphaOptimizedImageButton xmlns:android="http://schemas.android.com/apk/res/android" diff --git a/packages/SystemUI/res/layout/volume_dialog_wrapped.xml b/packages/SystemUI/res/layout/volume_dialog_wrapped.xml deleted file mode 100644 index 57489fd5f8d1..000000000000 --- a/packages/SystemUI/res/layout/volume_dialog_wrapped.xml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<com.android.systemui.HardwareUiLayout - xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="@dimen/top_padding" - android:layout_marginBottom="@dimen/bottom_padding"> - - <include layout="@layout/volume_dialog"/> - -</com.android.systemui.HardwareUiLayout> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index fc9e585400c6..e3a84d3d216a 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -216,6 +216,8 @@ <!-- The width of the panel that holds the quick settings. --> <dimen name="qs_panel_width">@dimen/notification_panel_width</dimen> + <dimen name="volume_dialog_panel_width">@dimen/standard_notification_panel_width</dimen> + <!-- Gravity for the notification panel --> <integer name="notification_panel_layout_gravity">0x31</integer><!-- center_horizontal|top --> @@ -800,7 +802,6 @@ <dimen name="hwui_edge_margin">16dp</dimen> - <dimen name="volume_dialog_panel_width">315dp</dimen> <dimen name="global_actions_panel_width">125dp</dimen> <dimen name="global_actions_top_padding">100dp</dimen> diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java index 1d3b533b6d8f..e11b23ea0efd 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java @@ -18,7 +18,6 @@ package com.android.systemui.volume; import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_ALL_MASK; import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_GENERIC; -import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import android.accessibilityservice.AccessibilityServiceInfo; import android.animation.ObjectAnimator; @@ -62,7 +61,6 @@ import android.view.View.OnAttachStateChangeListener; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.view.ViewGroup; -import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.MarginLayoutParams; import android.view.Window; import android.view.WindowManager; @@ -77,7 +75,6 @@ import android.widget.TextView; import com.android.settingslib.Utils; import com.android.systemui.Dependency; -import com.android.systemui.HardwareUiLayout; import com.android.systemui.Interpolators; import com.android.systemui.R; import com.android.systemui.plugins.VolumeDialogController; @@ -103,8 +100,7 @@ import java.util.List; * * Methods ending in "H" must be called on the (ui) handler. */ -public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, - ColorExtractor.OnColorsChangedListener { +public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable { private static final String TAG = Util.logTag(VolumeDialogImpl.class); public static final String SHOW_FULL_ZEN = "sysui_show_full_zen"; @@ -114,8 +110,6 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, private final Context mContext; private final H mHandler = new H(); - private final GradientDrawable mGradientDrawable; - private final ColorExtractor mColorExtractor; private VolumeDialogController mController; private Window mWindow; @@ -170,9 +164,6 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); mActiveSliderTint = ColorStateList.valueOf(Utils.getColorAccent(mContext)); mInactiveSliderTint = loadColorStateList(R.color.volume_slider_inactive); - mGradientDrawable = new GradientDrawable(mContext); - mGradientDrawable.setAlpha((int) (ScrimController.GRADIENT_SCRIM_ALPHA * 255)); - mColorExtractor = Dependency.get(ColorExtractor.class); } public void init(int windowType, Callback callback) { @@ -194,7 +185,6 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, @Override public void destroy() { mController.removeCallback(mControllerCallbackH); - mColorExtractor.removeOnColorsChangedListener(this); } private void initDialog() { @@ -205,7 +195,7 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, mShowing = false; mWindow = mDialog.getWindow(); mWindow.requestFeature(Window.FEATURE_NO_TITLE); - mWindow.setBackgroundDrawable(mGradientDrawable); + mWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); mWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN @@ -213,49 +203,55 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); - Point displaySize = new Point(); - mContext.getDisplay().getRealSize(displaySize); mDialog.setCanceledOnTouchOutside(true); final Resources res = mContext.getResources(); + final WindowManager.LayoutParams lp = mWindow.getAttributes(); + lp.type = mWindowType; + lp.format = PixelFormat.TRANSLUCENT; + lp.setTitle(VolumeDialogImpl.class.getSimpleName()); + lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; + lp.y = res.getDimensionPixelSize(R.dimen.volume_offset_top); + lp.gravity = Gravity.TOP; + lp.windowAnimations = -1; + mWindow.setAttributes(lp); mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); - mDialog.setContentView(R.layout.volume_dialog_wrapped); - mDialogView = mDialog.findViewById(R.id.volume_dialog); - mDialogView.setOnHoverListener((v, event) -> { - int action = event.getActionMasked(); - mHovering = (action == MotionEvent.ACTION_HOVER_ENTER) - || (action == MotionEvent.ACTION_HOVER_MOVE); - rescheduleTimeoutH(); - return true; + mDialog.setContentView(R.layout.volume_dialog); + mDialogView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog); + mDialogView.setOnHoverListener(new View.OnHoverListener() { + @Override + public boolean onHover(View v, MotionEvent event) { + int action = event.getActionMasked(); + mHovering = (action == MotionEvent.ACTION_HOVER_ENTER) + || (action == MotionEvent.ACTION_HOVER_MOVE); + rescheduleTimeoutH(); + return true; + } }); - - mColorExtractor.addOnColorsChangedListener(this); - mGradientDrawable.setScreenSize(displaySize.x, displaySize.y); - ColorExtractor.GradientColors colors = mColorExtractor.getColors( - mKeyguard.isKeyguardLocked() ? WallpaperManager.FLAG_LOCK - : WallpaperManager.FLAG_SYSTEM); - mGradientDrawable.setColors(colors, false); - - mDialogContentView = mDialog.findViewById(R.id.volume_dialog_content); - mDialogRowsView = mDialogContentView.findViewById(R.id.volume_dialog_rows); + mDialogContentView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog_content); + mDialogRowsView = (ViewGroup) mDialogContentView.findViewById(R.id.volume_dialog_rows); mExpanded = false; - mExpandButton = mDialogView.findViewById(R.id.volume_expand_button); + mExpandButton = (ImageButton) mDialogView.findViewById(R.id.volume_expand_button); mExpandButton.setOnClickListener(mClickExpand); mExpandButton.setVisibility( AudioSystem.isSingleVolume(mContext) ? View.GONE : View.VISIBLE); + updateWindowWidthH(); updateExpandButtonH(); - mMotion = new VolumeDialogMotion(mDialog, (View) mDialogView.getParent(), - mDialogContentView, mExpandButton, mGradientDrawable, animating -> { - if (animating) return; - if (mPendingStateChanged) { - mHandler.sendEmptyMessage(H.STATE_CHANGED); - mPendingStateChanged = false; - } - if (mPendingRecheckAll) { - mHandler.sendEmptyMessage(H.RECHECK_ALL); - mPendingRecheckAll = false; + 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; + } } }); @@ -280,20 +276,11 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, addExistingRows(); } mExpandButtonAnimationDuration = res.getInteger(R.integer.volume_expand_animation_duration); - mZenFooter = mDialog.findViewById(R.id.volume_zen_footer); + mZenFooter = (ZenFooter) mDialog.findViewById(R.id.volume_zen_footer); mZenFooter.init(mZenModeController); - mZenPanel = mDialog.findViewById(R.id.tuner_zen_mode_panel); + mZenPanel = (TunerZenModePanel) mDialog.findViewById(R.id.tuner_zen_mode_panel); mZenPanel.init(mZenModeController); mZenPanel.setCallback(mZenPanelCallback); - - final WindowManager.LayoutParams lp = mWindow.getAttributes(); - lp.width = MATCH_PARENT; - lp.height = MATCH_PARENT; - lp.type = mWindowType; - lp.format = PixelFormat.TRANSLUCENT; - lp.setTitle(VolumeDialogImpl.class.getSimpleName()); - lp.windowAnimations = -1; - mWindow.setAttributes(lp); } @Override @@ -307,6 +294,20 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, return ColorStateList.valueOf(mContext.getColor(colorResId)); } + private void updateWindowWidthH() { + final ViewGroup.LayoutParams lp = mDialogView.getLayoutParams(); + final DisplayMetrics dm = mContext.getResources().getDisplayMetrics(); + if (D.BUG) Log.d(TAG, "updateWindowWidth dm.w=" + dm.widthPixels); + int w = dm.widthPixels; + final int max = mContext.getResources() + .getDimensionPixelSize(R.dimen.volume_dialog_panel_width); + if (w > max) { + w = max; + } + lp.width = w; + mDialogView.setLayoutParams(lp); + } + public void setStreamImportant(int stream, boolean important) { mHandler.obtainMessage(H.SET_STREAM_IMPORTANT, stream, important ? 1 : 0).sendToTarget(); } @@ -547,8 +548,10 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, } private void updateDialogBottomMarginH() { + final long diff = System.currentTimeMillis() - mCollapseTime; + final boolean collapsing = mCollapseTime != 0 && diff < getConservativeCollapseDuration(); final ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) mDialogView.getLayoutParams(); - final int bottomMargin = + final int bottomMargin = collapsing ? mDialogContentView.getHeight() : mContext.getResources().getDimensionPixelSize(R.dimen.volume_dialog_margin_bottom); if (bottomMargin != mlp.bottomMargin) { if (D.BUG) Log.d(TAG, "bottomMargin " + mlp.bottomMargin + " -> " + bottomMargin); @@ -578,7 +581,7 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, TransitionManager.endTransitions(mDialogView); final VolumeRow activeRow = getActiveRow(); if (!dismissing) { - mWindow.setLayout(mWindow.getAttributes().width, MATCH_PARENT); + mWindow.setLayout(mWindow.getAttributes().width, ViewGroup.LayoutParams.MATCH_PARENT); TransitionManager.beginDelayedTransition(mDialogView, getTransistion()); } updateRowsH(activeRow); @@ -640,7 +643,7 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, final boolean isActive = row == activeRow; final boolean shouldBeVisible = shouldBeVisibleH(row, isActive); Util.setVisOrGone(row.view, shouldBeVisible); - Util.setVisOrGone(row.header, shouldBeVisible && mExpanded); + Util.setVisOrGone(row.header, shouldBeVisible); if (row.view.isShown()) { updateVolumeRowSliderTintH(row, isActive); } @@ -697,18 +700,12 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, final boolean visible = mState.zenMode != Global.ZEN_MODE_OFF && (mAudioManager.isStreamAffectedByRingerMode(mActiveStream) || mExpanded) && !mZenPanel.isEditing(); - - if (wasVisible != visible) { - mZenFooter.update(); - if (visible) { - HardwareUiLayout.get(mZenFooter).setDivisionView(mZenFooter); - } else { - mHandler.postDelayed(() -> - HardwareUiLayout.get(mZenFooter).setDivisionView(mZenFooter), - mExpandButtonAnimationDuration); - } - Util.setVisOrGone(mZenFooter, visible); + TransitionManager.beginDelayedTransition(mDialogView, getTransistion()); + if (wasVisible != visible && !visible) { + prepareForCollapse(); } + Util.setVisOrGone(mZenFooter, visible); + mZenFooter.update(); final boolean fullWasVisible = mZenPanel.getVisibility() == View.VISIBLE; final boolean fullVisible = mShowFullZen && !visible; @@ -968,7 +965,8 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, @Override public void onTransitionEnd(Transition transition) { - mWindow.setLayout(MATCH_PARENT, MATCH_PARENT); + mWindow.setLayout( + mWindow.getAttributes().width, ViewGroup.LayoutParams.WRAP_CONTENT); } @Override @@ -977,7 +975,8 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, @Override public void onTransitionPause(Transition transition) { - mWindow.setLayout(MATCH_PARENT, MATCH_PARENT); + mWindow.setLayout( + mWindow.getAttributes().width, ViewGroup.LayoutParams.WRAP_CONTENT); } @Override @@ -1029,6 +1028,7 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, initDialog(); mDensity = density; } + updateWindowWidthH(); mConfigurableTexts.update(); mZenFooter.onConfigurationChanged(); } @@ -1084,26 +1084,10 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, if (mExpandButtonAnimationRunning) return; final boolean newExpand = !mExpanded; Events.writeEvent(mContext, Events.EVENT_EXPAND, newExpand); - if (!newExpand) { - HardwareUiLayout.get(mDialogContentView).setCollapse(); - } updateExpandedH(newExpand, false /* dismissing */); } }; - @Override - public void onColorsChanged(ColorExtractor extractor, int which) { - if (mKeyguard.isKeyguardLocked()) { - if ((WallpaperManager.FLAG_LOCK & which) != 0) { - mGradientDrawable.setColors(extractor.getColors(WallpaperManager.FLAG_LOCK)); - } - } else { - if ((WallpaperManager.FLAG_SYSTEM & which) != 0) { - mGradientDrawable.setColors(extractor.getColors(WallpaperManager.FLAG_SYSTEM)); - } - } - } - private final class H extends Handler { private static final int SHOW = 1; private static final int DISMISS = 2; @@ -1175,8 +1159,8 @@ public class VolumeDialogImpl implements VolumeDialog, TunerService.Tunable, event.setPackageName(mContext.getPackageName()); ViewGroup.LayoutParams params = getWindow().getAttributes(); - boolean isFullScreen = (params.width == MATCH_PARENT) && - (params.height == MATCH_PARENT); + boolean isFullScreen = (params.width == ViewGroup.LayoutParams.MATCH_PARENT) && + (params.height == ViewGroup.LayoutParams.MATCH_PARENT); event.setFullScreen(isFullScreen); if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogMotion.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogMotion.java index 2df222764dcc..01d31e2a9852 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogMotion.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogMotion.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.android.systemui.volume; import android.animation.Animator; @@ -41,10 +42,8 @@ public class VolumeDialogMotion { private final View mDialogView; private final ViewGroup mContents; // volume rows + zen footer private final View mChevron; - private final Drawable mBackground; private final Handler mHandler = new Handler(); private final Callback mCallback; - private final int mBackgroundTargetAlpha; private boolean mAnimating; // show or dismiss animation is running private boolean mShowing; // show animation is running @@ -53,14 +52,12 @@ public class VolumeDialogMotion { private ValueAnimator mContentsPositionAnimator; public VolumeDialogMotion(Dialog dialog, View dialogView, ViewGroup contents, View chevron, - Drawable background, Callback callback) { + Callback callback) { mDialog = dialog; mDialogView = dialogView; mContents = contents; mChevron = chevron; mCallback = callback; - mBackground = background; - mBackgroundTargetAlpha = mBackground.getAlpha(); mDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { @@ -71,9 +68,8 @@ public class VolumeDialogMotion { @Override public void onShow(DialogInterface dialog) { if (D.BUG) Log.d(TAG, "mDialog.onShow"); - final int w = mDialogView.getWidth() / 4; - mDialogView.setTranslationX(w); - mBackground.setAlpha(0); + final int h = mDialogView.getHeight(); + mDialogView.setTranslationY(-h); startShowAnimation(); } }); @@ -122,7 +118,7 @@ public class VolumeDialogMotion { } private int chevronDistance() { - return 0; + return mChevron.getHeight() / 6; } private int chevronPosY() { @@ -133,29 +129,26 @@ public class VolumeDialogMotion { private void startShowAnimation() { if (D.BUG) Log.d(TAG, "startShowAnimation"); mDialogView.animate() - .translationX(0) .translationY(0) - .alpha(1) .setDuration(scaledDuration(300)) .setInterpolator(new LogDecelerateInterpolator()) .setListener(null) .setUpdateListener(animation -> { - mBackground.setAlpha( - (int) (animation.getAnimatedFraction() * mBackgroundTargetAlpha)); if (mChevronPositionAnimator != null) { final float v = (Float) mChevronPositionAnimator.getAnimatedValue(); if (mChevronPositionAnimator == null) return; // reposition chevron final int posY = chevronPosY(); + mChevron.setTranslationY(posY + v + -mDialogView.getTranslationY()); } }) .withEndAction(new Runnable() { @Override public void run() { - mBackground.setAlpha(mBackgroundTargetAlpha); if (mChevronPositionAnimator == null) return; // reposition chevron final int posY = chevronPosY(); + mChevron.setTranslationY(posY + -mDialogView.getTranslationY()); } }) .start(); @@ -171,13 +164,19 @@ public class VolumeDialogMotion { if (D.BUG) Log.d(TAG, "show.onAnimationEnd"); setShowing(false); } - @Override public void onAnimationCancel(Animator animation) { if (D.BUG) Log.d(TAG, "show.onAnimationCancel"); mCancelled = true; } }); + mContentsPositionAnimator.addUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + float v = (Float) animation.getAnimatedValue(); + mContents.setTranslationY(v + -mDialogView.getTranslationY()); + } + }); mContentsPositionAnimator.setInterpolator(new LogDecelerateInterpolator()); mContentsPositionAnimator.start(); @@ -219,30 +218,34 @@ public class VolumeDialogMotion { setShowing(false); } mDialogView.animate() - .translationX(mDialogView.getWidth() / 4) - .alpha(0) + .translationY(-mDialogView.getHeight()) .setDuration(scaledDuration(250)) .setInterpolator(new LogAccelerateInterpolator()) - .setUpdateListener(animation -> { - final float v = 1 - mChevronPositionAnimator.getAnimatedFraction(); - mBackground.setAlpha((int) (v * mBackgroundTargetAlpha)); + .setUpdateListener(new AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + mContents.setTranslationY(-mDialogView.getTranslationY()); + final int posY = chevronPosY(); + mChevron.setTranslationY(posY + -mDialogView.getTranslationY()); + } }) .setListener(new AnimatorListenerAdapter() { private boolean mCancelled; - @Override public void onAnimationEnd(Animator animation) { if (mCancelled) return; if (D.BUG) Log.d(TAG, "dismiss.onAnimationEnd"); - mHandler.postDelayed(() -> { - if (D.BUG) Log.d(TAG, "mDialog.dismiss()"); - mDialog.dismiss(); - onComplete.run(); - setDismissing(false); + mHandler.postDelayed(new Runnable() { + @Override + public void run() { + if (D.BUG) Log.d(TAG, "mDialog.dismiss()"); + mDialog.dismiss(); + onComplete.run(); + setDismissing(false); + } }, PRE_DISMISS_DELAY); } - @Override public void onAnimationCancel(Animator animation) { if (D.BUG) Log.d(TAG, "dismiss.onAnimationCancel"); |