From 5b119e6c8069d9b37d80c7f994a04a9c23ac265a Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Tue, 30 Mar 2021 13:27:24 -0400 Subject: [PATCH] Enforce height override by QSAnimator If an animation is going on, enforce the animated height instead of the layout one. Test: manual Fixes: 183763542 Change-Id: I2b02511711849b11e87dc15fe4943596c0f315f8 --- .../com/android/systemui/qs/QSAnimator.java | 19 ++++++++---- .../qs/tileimpl/HeightOverrideable.kt | 29 +++++++++++++++++++ .../qs/tileimpl/QSTileViewHorizontal.kt | 10 ++++++- 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 packages/SystemUI/src/com/android/systemui/qs/tileimpl/HeightOverrideable.kt diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java index ee0b0c28b0c5a..2659a1f04a3f9 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java @@ -31,6 +31,7 @@ import com.android.systemui.qs.QSPanel.QSTileLayout; import com.android.systemui.qs.TouchAnimator.Builder; import com.android.systemui.qs.TouchAnimator.Listener; import com.android.systemui.qs.dagger.QSScope; +import com.android.systemui.qs.tileimpl.HeightOverrideable; import com.android.systemui.statusbar.FeatureFlags; import com.android.systemui.tuner.TunerService; import com.android.systemui.tuner.TunerService.Tunable; @@ -586,6 +587,15 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float t = valueAnimator.getAnimatedFraction(); + final int viewCount = mViews.size(); + int height = (Integer) valueAnimator.getAnimatedValue(); + for (int i = 0; i < viewCount; i++) { + View v = mViews.get(i); + v.setBottom(v.getTop() + height); + if (v instanceof HeightOverrideable) { + ((HeightOverrideable) v).setHeightOverride(height); + } + } if (t == 0f) { mListener.onAnimationAtStart(); } else if (t == 1f) { @@ -594,12 +604,6 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha mListener.onAnimationStarted(); } mLastT = t; - final int viewCount = mViews.size(); - int height = (Integer) valueAnimator.getAnimatedValue(); - for (int i = 0; i < viewCount; i++) { - View v = mViews.get(i); - v.setBottom(v.getTop() + height); - } } }; @@ -628,6 +632,9 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha for (int i = 0; i < viewsCount; i++) { View v = mViews.get(i); v.setBottom(v.getTop() + v.getMeasuredHeight()); + if (v instanceof HeightOverrideable) { + ((HeightOverrideable) v).resetOverride(); + } } } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/HeightOverrideable.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/HeightOverrideable.kt new file mode 100644 index 0000000000000..866fa097d6fdf --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/HeightOverrideable.kt @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 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. + */ + +package com.android.systemui.qs.tileimpl + +interface HeightOverrideable { + companion object { + const val NO_OVERRIDE = -1 + } + + var heightOverride: Int + + fun resetOverride() { + heightOverride = NO_OVERRIDE + } +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt index 32285cf797e45..188e89edd89a0 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tileimpl/QSTileViewHorizontal.kt @@ -35,12 +35,13 @@ open class QSTileViewHorizontal( context: Context, icon: QSIconView, collapsed: Boolean -) : QSTileView(context, icon, collapsed) { +) : QSTileView(context, icon, collapsed), HeightOverrideable { protected var colorBackgroundDrawable: Drawable? = null private var paintColor = Color.WHITE private var paintAnimator: ValueAnimator? = null private var labelAnimator: ValueAnimator? = null + override var heightOverride: Int = HeightOverrideable.NO_OVERRIDE init { orientation = HORIZONTAL @@ -58,6 +59,13 @@ open class QSTileViewHorizontal( mColorLabelActive = ColorStateList.valueOf(getColorForState(getContext(), STATE_ACTIVE)) } + override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { + super.onLayout(changed, l, t, r, b) + if (heightOverride != HeightOverrideable.NO_OVERRIDE) { + bottom = top + heightOverride + } + } + override fun createLabel() { super.createLabel() findViewById(R.id.label_group)?.apply {