diff options
| author | 2025-01-07 16:54:01 +0000 | |
|---|---|---|
| committer | 2025-01-07 15:47:12 -0800 | |
| commit | 0a211eb34c0b0967aa01dac95b6feb1e72e0e25c (patch) | |
| tree | 3ffedb74ffc977d863a3843e12a5382982b7d9a3 | |
| parent | 8dd5e4289d61bb249355c9b8995701a66d7e8270 (diff) | |
Fix volume dialog size on the landscape phone
This change makes sure that the volume dialog fits the size of the screen when the vertical space is limited. For example, when the phone is in the landscape
Flag: com.android.systemui.volume_redesign
Bug: 369993959
Test: manual on the phone. Open the Volume Dialog when the phone is in
the landscape orientation and observe
Change-Id: I80586a9ac858451030e452908fed4c53e154cb08
6 files changed, 48 insertions, 35 deletions
diff --git a/packages/SystemUI/res/layout/volume_dialog.xml b/packages/SystemUI/res/layout/volume_dialog.xml index 0b624e1687a6..58f2d3ccc6a8 100644 --- a/packages/SystemUI/res/layout/volume_dialog.xml +++ b/packages/SystemUI/res/layout/volume_dialog.xml @@ -44,7 +44,7 @@ app:layout_constraintBottom_toTopOf="@id/volume_dialog_main_slider_container" app:layout_constraintEnd_toEndOf="@id/volume_dialog_main_slider_container" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"/> + app:layout_constraintTop_toTopOf="parent" /> <include android:id="@+id/volume_dialog_main_slider_container" diff --git a/packages/SystemUI/res/layout/volume_dialog_slider.xml b/packages/SystemUI/res/layout/volume_dialog_slider.xml index 967cb3fd68de..6eb7b730e105 100644 --- a/packages/SystemUI/res/layout/volume_dialog_slider.xml +++ b/packages/SystemUI/res/layout/volume_dialog_slider.xml @@ -14,8 +14,9 @@ limitations under the License. --> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="@dimen/volume_dialog_slider_width" - android:layout_height="@dimen/volume_dialog_slider_height"> + android:layout_width="0dp" + android:layout_height="0dp" + android:maxHeight="@dimen/volume_dialog_slider_height"> <com.google.android.material.slider.Slider android:id="@+id/volume_dialog_slider" diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 8bf4e373a6e0..1f7889214bd5 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -2116,6 +2116,11 @@ <dimen name="volume_dialog_button_size">40dp</dimen> <dimen name="volume_dialog_slider_width">52dp</dimen> <dimen name="volume_dialog_slider_height">254dp</dimen> + <!-- + A primary goal of this margin is to vertically constraint slider height in the landscape + orientation when the vertical space is limited + --> + <dimen name="volume_dialog_slider_vertical_margin">124dp</dimen> <fraction name="volume_dialog_half_opened_bias">0.2</fraction> diff --git a/packages/SystemUI/res/xml/volume_dialog_constraint_set.xml b/packages/SystemUI/res/xml/volume_dialog_constraint_set.xml index 9018e5b7ed92..a8f616c2427d 100644 --- a/packages/SystemUI/res/xml/volume_dialog_constraint_set.xml +++ b/packages/SystemUI/res/xml/volume_dialog_constraint_set.xml @@ -6,10 +6,13 @@ <Constraint android:id="@id/volume_dialog_main_slider_container" android:layout_width="@dimen/volume_dialog_slider_width" - android:layout_height="@dimen/volume_dialog_slider_height" + android:layout_height="0dp" + android:layout_marginTop="@dimen/volume_dialog_slider_vertical_margin" android:layout_marginEnd="@dimen/volume_dialog_components_spacing" + android:layout_marginBottom="@dimen/volume_dialog_slider_vertical_margin" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHeight_max="@dimen/volume_dialog_slider_height" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.5" /> </ConstraintSet>
\ No newline at end of file diff --git a/packages/SystemUI/res/xml/volume_dialog_half_folded_constraint_set.xml b/packages/SystemUI/res/xml/volume_dialog_half_folded_constraint_set.xml index 297c38873164..b4d8ae791f36 100644 --- a/packages/SystemUI/res/xml/volume_dialog_half_folded_constraint_set.xml +++ b/packages/SystemUI/res/xml/volume_dialog_half_folded_constraint_set.xml @@ -6,10 +6,13 @@ <Constraint android:id="@id/volume_dialog_main_slider_container" android:layout_width="@dimen/volume_dialog_slider_width" - android:layout_height="@dimen/volume_dialog_slider_height" + android:layout_height="0dp" + android:layout_marginTop="@dimen/volume_dialog_slider_vertical_margin" android:layout_marginEnd="@dimen/volume_dialog_components_spacing" + android:layout_marginBottom="@dimen/volume_dialog_slider_vertical_margin" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHeight_max="@dimen/volume_dialog_slider_height" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="@fraction/volume_dialog_half_opened_bias" /> </ConstraintSet>
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/volume/dialog/ui/binder/VolumeDialogViewBinder.kt b/packages/SystemUI/src/com/android/systemui/volume/dialog/ui/binder/VolumeDialogViewBinder.kt index 1da2491c68b6..46d7d5f680ce 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/dialog/ui/binder/VolumeDialogViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/volume/dialog/ui/binder/VolumeDialogViewBinder.kt @@ -24,11 +24,15 @@ import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver import android.view.ViewTreeObserver.InternalInsetsInfo +import android.view.WindowInsets import androidx.constraintlayout.motion.widget.MotionLayout +import androidx.core.view.updatePadding import com.android.internal.view.RotationPolicy +import com.android.systemui.common.ui.view.onApplyWindowInsets import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.res.R import com.android.systemui.util.children +import com.android.systemui.util.kotlin.awaitCancellationThenDispose import com.android.systemui.volume.SystemUIInterpolators import com.android.systemui.volume.dialog.dagger.scope.VolumeDialogScope import com.android.systemui.volume.dialog.ringer.ui.binder.VolumeDialogRingerViewBinder @@ -43,6 +47,7 @@ import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onEach @@ -71,6 +76,8 @@ constructor( resources.getInteger(R.integer.config_dialogHideAnimationDurationMs).toLong() fun CoroutineScope.bind(dialog: Dialog) { + val insets: MutableStateFlow<WindowInsets> = + MutableStateFlow(WindowInsets.Builder().build()) // Root view of the Volume Dialog. val root: MotionLayout = dialog.requireViewById(R.id.volume_dialog_root) root.alpha = 0f @@ -88,6 +95,22 @@ constructor( launch { root.viewTreeObserver.computeInternalInsetsListener(root) } + launch { + root + .onApplyWindowInsets { v, newInsets -> + val insetsValues = newInsets.getInsets(WindowInsets.Type.displayCutout()) + v.updatePadding( + left = insetsValues.left, + top = insetsValues.top, + right = insetsValues.right, + bottom = insetsValues.bottom, + ) + insets.value = newInsets + WindowInsets.CONSUMED + } + .awaitCancellationThenDispose() + } + with(volumeDialogRingerViewBinder) { bind(root) } with(slidersViewBinder) { bind(root) } with(settingsButtonViewBinder) { bind(root) } @@ -103,8 +126,10 @@ constructor( when (it) { is VolumeDialogVisibilityModel.Visible -> { tracer.traceVisibilityEnd(it) - calculateTranslationX(view)?.let(view::setTranslationX) - view.animateShow(dialogShowAnimationDurationMs) + view.animateShow( + duration = dialogShowAnimationDurationMs, + translationX = calculateTranslationX(view), + ) } is VolumeDialogVisibilityModel.Dismissed -> { tracer.traceVisibilityEnd(it) @@ -134,24 +159,15 @@ constructor( } } - private suspend fun View.animateShow(duration: Long) { + private suspend fun View.animateShow(duration: Long, translationX: Float?) { + translationX?.let { setTranslationX(translationX) } + alpha = 0f animate() .alpha(1f) .translationX(0f) .setDuration(duration) .setInterpolator(SystemUIInterpolators.LogDecelerateInterpolator()) .suspendAnimate(jankListenerFactory.show(this, duration)) - /* TODO(b/369993851) - .withEndAction(Runnable { - if (!Prefs.getBoolean(mContext, Prefs.Key.TOUCHED_RINGER_TOGGLE, false)) { - if (mRingerIcon != null) { - mRingerIcon.postOnAnimationDelayed( - getSinglePressFor(mRingerIcon), 1500 - ) - } - } - }) - */ } private suspend fun View.animateHide(duration: Long, translationX: Float?) { @@ -160,22 +176,7 @@ constructor( .alpha(0f) .setDuration(duration) .setInterpolator(SystemUIInterpolators.LogAccelerateInterpolator()) - /* TODO(b/369993851) - .withEndAction( - Runnable { - mHandler.postDelayed( - Runnable { - hideRingerDrawer() - - }, - 50 - ) - } - ) - */ - if (translationX != null) { - animator.translationX(translationX) - } + translationX?.let { animator.translationX(it) } animator.suspendAnimate(jankListenerFactory.dismiss(this, duration)) } |