From 3e7fa49c8772441a6309cf1cffa12cd7bf492c0e Mon Sep 17 00:00:00 2001 From: Jacqueline Bronger Date: Thu, 15 Dec 2022 17:24:21 +0100 Subject: [PATCH] Position TV volume UI based on layout orientation. Previously, the volume UI has been positioned statically on the center right, however since we don't generally have volume buttons on the right side like on mobile, we will prioritise reducing content overlap like we do with other floating windows/panels. Bug: 246537363 Test: manual, on TV: change volume in LTR -> there should be no change, switch to an RTL language -> volume dialog should be positioned on the left and the animation should also have its origin on the left Change-Id: I64970c50bc58666f99d7fad8f69e9bf6a4bf2936 --- .../res/values-television/integers.xml | 5 +++-- .../systemui/volume/VolumeDialogImpl.java | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/res/values-television/integers.xml b/packages/SystemUI/res/values-television/integers.xml index b265d7812229c..02f5d0d827f8e 100644 --- a/packages/SystemUI/res/values-television/integers.xml +++ b/packages/SystemUI/res/values-television/integers.xml @@ -18,8 +18,9 @@ - 21 + Value 21 corresponds to RIGHT|CENTER_VERTICAL. + Value 8388629 corresponds to END|CENTER_VERTICAL --> + 8388629 300 diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java index fa3c73a26f7be..1d640db8652d1 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogImpl.java @@ -288,6 +288,8 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, private boolean mSeparateNotification; + private int mWindowGravity; + @VisibleForTesting int mVolumeRingerIconDrawableId; @VisibleForTesting @@ -514,7 +516,12 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, lp.format = PixelFormat.TRANSLUCENT; lp.setTitle(VolumeDialogImpl.class.getSimpleName()); lp.windowAnimations = -1; - lp.gravity = mContext.getResources().getInteger(R.integer.volume_dialog_gravity); + + mWindowGravity = Gravity.getAbsoluteGravity( + mContext.getResources().getInteger(R.integer.volume_dialog_gravity), + mContext.getResources().getConfiguration().getLayoutDirection()); + lp.gravity = mWindowGravity; + mWindow.setAttributes(lp); mWindow.setLayout(WRAP_CONTENT, WRAP_CONTENT); @@ -525,7 +532,8 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, mDialog.setOnShowListener(dialog -> { mDialogView.getViewTreeObserver().addOnComputeInternalInsetsListener(this); if (!shouldSlideInVolumeTray()) { - mDialogView.setTranslationX(mDialogView.getWidth() / 2.0f); + mDialogView.setTranslationX( + (isWindowGravityLeft() ? -1 : 1) * mDialogView.getWidth() / 2.0f); } mDialogView.setAlpha(0); mDialogView.animate() @@ -696,6 +704,10 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, initODICaptionsH(); } + private boolean isWindowGravityLeft() { + return (mWindowGravity & Gravity.LEFT) == Gravity.LEFT; + } + private void initDimens() { mDialogWidth = mContext.getResources().getDimensionPixelSize( R.dimen.volume_dialog_panel_width); @@ -1495,7 +1507,10 @@ public class VolumeDialogImpl implements VolumeDialog, Dumpable, hideRingerDrawer(); }, 50)); - if (!shouldSlideInVolumeTray()) animator.translationX(mDialogView.getWidth() / 2.0f); + if (!shouldSlideInVolumeTray()) { + animator.translationX( + (isWindowGravityLeft() ? -1 : 1) * mDialogView.getWidth() / 2.0f); + } animator.setListener(getJankListener(getDialogView(), TYPE_DISMISS, mDialogHideAnimationDurationMs)).start(); checkODICaptionsTooltip(true);