Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fae91d5e authored by Alex Chau's avatar Alex Chau
Browse files

Include DigitalWelllBeing banner in task XML to avoid addView during animation

- Also simplified DigitalWellBeingToast to be an actual View that is a children of TaskView
- Split out getDwbLayoutTranslations into 2 methods
  - One that update layout will be called earlier during TaskView.updateTaskSize. It now takes calcualted split snaphsot size and layoutParams sizes instead of using measured sizes so it can run before onMeasure. Also make sure updateLayoutParams is called.
  - One that calulate translations only can be called more frequently without causing jank during animation
- TaskView.updateTaskSize now always set the exact sizes as layoutParams instead of MATCH_PARENT, so we can use the values for updateDwbBannerLayout
- Simplified outline and splitOffsetTranslation calculations

Fix: 345789862
Fix: 362435532
Test: Presubmit and manually testing DWB banner in variaous configuration single/split real/fake portrait/landscape/fake
Flag: EXEMPT bugfix
Change-Id: Ibde877c5f983689e0ef8104ba344b5947d0e3948
parent 09623dd5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<TextView
<com.android.quickstep.views.DigitalWellBeingToast
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    style="@style/TextTitle"
+4 −0
Original line number Diff line number Diff line
@@ -47,4 +47,8 @@
        android:inflatedId="@id/icon"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

    <include layout="@layout/digital_wellbeing_toast"
        android:id="@+id/digital_wellbeing_toast"
        android:visibility="invisible"/>
</com.android.quickstep.views.TaskView>
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -73,4 +73,12 @@
        android:inflatedId="@id/bottomRight_icon"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content" />

    <include layout="@layout/digital_wellbeing_toast"
        android:id="@+id/digital_wellbeing_toast"
        android:visibility="invisible"/>

    <include layout="@layout/digital_wellbeing_toast"
        android:id="@+id/bottomRight_digital_wellbeing_toast"
        android:visibility="invisible"/>
</com.android.quickstep.views.GroupedTaskView>
 No newline at end of file
+40 −29
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.widget.LinearLayout
import androidx.annotation.VisibleForTesting
import androidx.core.util.component1
import androidx.core.util.component2
import androidx.core.view.updateLayoutParams
import com.android.launcher3.DeviceProfile
import com.android.launcher3.Flags
import com.android.launcher3.LauncherAnimUtils
@@ -242,7 +243,30 @@ open class LandscapePagedViewHandler : RecentsPagedOrientationHandler {
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT
    }

    override fun getDwbLayoutTranslations(
    override fun updateDwbBannerLayout(
        taskViewWidth: Int,
        taskViewHeight: Int,
        isGroupedTaskView: Boolean,
        deviceProfile: DeviceProfile,
        snapshotViewWidth: Int,
        snapshotViewHeight: Int,
        banner: View
    ) {
        banner.pivotX = 0f
        banner.pivotY = 0f
        banner.rotation = degreesRotated
        banner.updateLayoutParams<FrameLayout.LayoutParams> {
            gravity = Gravity.TOP or if (banner.isLayoutRtl) Gravity.END else Gravity.START
            width =
                if (isGroupedTaskView) {
                    snapshotViewHeight
                } else {
                    taskViewHeight - deviceProfile.overviewTaskThumbnailTopMarginPx
                }
        }
    }

    override fun getDwbBannerTranslations(
        taskViewWidth: Int,
        taskViewHeight: Int,
        splitBounds: SplitBounds?,
@@ -252,28 +276,14 @@ open class LandscapePagedViewHandler : RecentsPagedOrientationHandler {
        banner: View
    ): Pair<Float, Float> {
        val snapshotParams = thumbnailViews[0].layoutParams as FrameLayout.LayoutParams
        val isRtl = banner.layoutDirection == View.LAYOUT_DIRECTION_RTL
        val translationX = banner.height.toFloat()

        val bannerParams = banner.layoutParams as FrameLayout.LayoutParams
        bannerParams.gravity = Gravity.TOP or if (isRtl) Gravity.END else Gravity.START
        banner.pivotX = 0f
        banner.pivotY = 0f
        banner.rotation = degreesRotated

        if (splitBounds == null) {
            // Single, fullscreen case
            bannerParams.width = taskViewHeight - snapshotParams.topMargin
            return Pair(translationX, snapshotParams.topMargin.toFloat())
        }

        // Set correct width and translations
        val translationY: Float
        if (splitBounds == null) {
            translationY = snapshotParams.topMargin.toFloat()
        } else {
            if (desiredTaskId == splitBounds.leftTopTaskId) {
            bannerParams.width = thumbnailViews[0].measuredHeight
                translationY = snapshotParams.topMargin.toFloat()
            } else {
            bannerParams.width = thumbnailViews[1].measuredHeight
                val topLeftTaskPlusDividerPercent =
                    if (splitBounds.appsStackedVertically) {
                        splitBounds.topTaskPercent + splitBounds.dividerHeightPercent
@@ -284,7 +294,7 @@ open class LandscapePagedViewHandler : RecentsPagedOrientationHandler {
                    snapshotParams.topMargin +
                        (taskViewHeight - snapshotParams.topMargin) * topLeftTaskPlusDividerPercent
            }

        }
        return Pair(translationX, translationY)
    }

@@ -300,6 +310,7 @@ open class LandscapePagedViewHandler : RecentsPagedOrientationHandler {
        if (isRtl) displacement < 0 else displacement > 0

    override fun getTaskDragDisplacementFactor(isRtl: Boolean): Int = if (isRtl) 1 else -1

    /* -------------------- */

    override fun getChildBounds(
+40 −40
Original line number Diff line number Diff line
@@ -243,33 +243,32 @@ public class PortraitPagedViewHandler extends DefaultPagedViewHandler implements
    }

    @Override
    public Pair<Float, Float> getDwbLayoutTranslations(int taskViewWidth,
            int taskViewHeight, SplitBounds splitBounds, DeviceProfile deviceProfile,
            View[] thumbnailViews, int desiredTaskId, View banner) {
        float translationX = 0;
        float translationY = 0;
    public void updateDwbBannerLayout(int taskViewWidth, int taskViewHeight,
            boolean isGroupedTaskView, @NonNull DeviceProfile deviceProfile,
            int snapshotViewWidth, int snapshotViewHeight, @NonNull View banner) {
        FrameLayout.LayoutParams bannerParams = (FrameLayout.LayoutParams) banner.getLayoutParams();
        banner.setPivotX(0);
        banner.setPivotY(0);
        banner.setRotation(getDegreesRotated());
        if (splitBounds == null) {
            // Single, fullscreen case
            bannerParams.width = MATCH_PARENT;
            bannerParams.gravity = BOTTOM | CENTER_HORIZONTAL;
            return new Pair<>(translationX, translationY);
        }

        if (isGroupedTaskView) {
            bannerParams.gravity =
                    BOTTOM | (deviceProfile.isLeftRightSplit ? START : CENTER_HORIZONTAL);

        // Set correct width
        if (desiredTaskId == splitBounds.leftTopTaskId) {
            bannerParams.width = thumbnailViews[0].getMeasuredWidth();
            bannerParams.width = snapshotViewWidth;
        } else {
            bannerParams.width = thumbnailViews[1].getMeasuredWidth();
            bannerParams.width = MATCH_PARENT;
            bannerParams.gravity = BOTTOM | CENTER_HORIZONTAL;
        }
        banner.setLayoutParams(bannerParams);
    }

        // Set translations
    @NonNull
    @Override
    public Pair<Float, Float> getDwbBannerTranslations(int taskViewWidth,
            int taskViewHeight, SplitBounds splitBounds, @NonNull DeviceProfile deviceProfile,
            @NonNull View[] thumbnailViews, int desiredTaskId, @NonNull View banner) {
        float translationX = 0;
        float translationY = 0;
        if (splitBounds != null) {
            if (deviceProfile.isLeftRightSplit) {
                if (desiredTaskId == splitBounds.rightBottomTaskId) {
                    float leftTopTaskPercent = splitBounds.appsStackedVertically
@@ -293,6 +292,7 @@ public class PortraitPagedViewHandler extends DefaultPagedViewHandler implements
                            * bottomRightTaskPlusDividerPercent);
                }
            }
        }
        return new Pair<>(translationX, translationY);
    }

Loading