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

Commit 10631bff authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Create drop target bounds for bubbles

Bug: 393172431
Flag: EXEMPT not wired
Test: treehugger
Change-Id: I343be888d4ad622d517c4fd5af98c20eaf82c7a8
parent b04e0f11
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2025 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.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
    <item android:alpha="0.35" android:color="@androidprv:color/materialColorPrimaryContainer" />
</selector>
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2025 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.
  -->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    android:shape="rectangle">
    <corners android:radius="28dp" />
    <solid android:color="@color/bubble_drop_target_background_color" />
    <stroke
        android:width="1dp"
        android:color="@androidprv:color/materialColorPrimaryContainer" />
</shape>
+9 −0
Original line number Diff line number Diff line
@@ -36,4 +36,13 @@
    <dimen name="drag_zone_v_split_from_expanded_view_height_tablet">285dp</dimen>
    <dimen name="drag_zone_v_split_from_expanded_view_height_fold_tall">150dp</dimen>
    <dimen name="drag_zone_v_split_from_expanded_view_height_fold_short">100dp</dimen>

    <!-- Bubble drop target dimensions -->
    <dimen name="drop_target_full_screen_padding">20dp</dimen>
    <dimen name="drop_target_desktop_window_padding_small">100dp</dimen>
    <dimen name="drop_target_desktop_window_padding_large">130dp</dimen>
    <dimen name="drop_target_expanded_view_width">364</dimen>
    <dimen name="drop_target_expanded_view_height">578</dimen>
    <dimen name="drop_target_expanded_view_padding_bottom">108</dimen>
    <dimen name="drop_target_expanded_view_padding_horizontal">24</dimen>
</resources>
 No newline at end of file
+83 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.wm.shell.shared.bubbles

import android.content.Context
import android.graphics.Rect
import android.util.TypedValue
import androidx.annotation.DimenRes
import com.android.wm.shell.shared.R
import com.android.wm.shell.shared.bubbles.DragZoneFactory.SplitScreenModeChecker.SplitScreenMode
@@ -50,6 +51,60 @@ class DragZoneFactory(
    private var vSplitFromExpandedViewDragZoneHeightFoldTall = 0
    private var vSplitFromExpandedViewDragZoneHeightFoldShort = 0

    private var fullScreenDropTargetPadding = 0
    private var desktopWindowDropTargetPaddingSmall = 0
    private var desktopWindowDropTargetPaddingLarge = 0
    private var expandedViewDropTargetWidth = 0
    private var expandedViewDropTargetHeight = 0
    private var expandedViewDropTargetPaddingBottom = 0
    private var expandedViewDropTargetPaddingHorizontal = 0

    private val fullScreenDropTarget: Rect
        get() =
            Rect(windowBounds).apply {
                inset(fullScreenDropTargetPadding, fullScreenDropTargetPadding)
            }

    private val desktopWindowDropTarget: Rect
        get() =
            Rect(windowBounds).apply {
                if (deviceConfig.isLandscape) {
                    inset(
                        /* dx= */ desktopWindowDropTargetPaddingLarge,
                        /* dy= */ desktopWindowDropTargetPaddingSmall
                    )
                } else {
                    inset(
                        /* dx= */ desktopWindowDropTargetPaddingSmall,
                        /* dy= */ desktopWindowDropTargetPaddingLarge
                    )
                }
            }

    private val expandedViewDropTargetLeft: Rect
        get() =
            Rect(
                expandedViewDropTargetPaddingHorizontal,
                windowBounds.bottom -
                    expandedViewDropTargetPaddingBottom -
                    expandedViewDropTargetHeight,
                expandedViewDropTargetWidth + expandedViewDropTargetPaddingHorizontal,
                windowBounds.bottom - expandedViewDropTargetPaddingBottom
            )

    private val expandedViewDropTargetRight: Rect
        get() =
            Rect(
                windowBounds.right -
                    expandedViewDropTargetPaddingHorizontal -
                    expandedViewDropTargetWidth,
                windowBounds.bottom -
                    expandedViewDropTargetPaddingBottom -
                    expandedViewDropTargetHeight,
                windowBounds.right - expandedViewDropTargetPaddingHorizontal,
                windowBounds.bottom - expandedViewDropTargetPaddingBottom
            )

    init {
        onConfigurationUpdated()
    }
@@ -88,11 +143,32 @@ class DragZoneFactory(
            context.resolveDimension(R.dimen.drag_zone_v_split_from_expanded_view_height_fold_tall)
        vSplitFromExpandedViewDragZoneHeightFoldShort =
            context.resolveDimension(R.dimen.drag_zone_v_split_from_expanded_view_height_fold_short)
        fullScreenDropTargetPadding =
            context.resolveDimension(R.dimen.drop_target_full_screen_padding)
        desktopWindowDropTargetPaddingSmall =
            context.resolveDimension(R.dimen.drop_target_desktop_window_padding_small)
        desktopWindowDropTargetPaddingLarge =
            context.resolveDimension(R.dimen.drop_target_desktop_window_padding_large)

        // TODO b/393172431: Use the shared xml resources once we can easily access them from
        //  launcher
        expandedViewDropTargetWidth = 364.dpToPx()
        expandedViewDropTargetHeight = 578.dpToPx()
        expandedViewDropTargetPaddingBottom = 108.dpToPx()
        expandedViewDropTargetPaddingHorizontal = 24.dpToPx()
    }

    private fun Context.resolveDimension(@DimenRes dimension: Int) =
        resources.getDimensionPixelSize(dimension)

    private fun Int.dpToPx() =
        TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP,
                this.toFloat(),
                context.resources.displayMetrics
            )
            .toInt()

    /**
     * Creates the list of drag zones for the dragged object.
     *
@@ -155,7 +231,7 @@ class DragZoneFactory(
            DragZone.Bubble.Left(
                bounds =
                    Rect(0, windowBounds.bottom - dragZoneSize, dragZoneSize, windowBounds.bottom),
                dropTarget = Rect(0, 0, 0, 0),
                dropTarget = expandedViewDropTargetLeft,
            ),
            DragZone.Bubble.Right(
                bounds =
@@ -165,7 +241,7 @@ class DragZoneFactory(
                        windowBounds.right,
                        windowBounds.bottom,
                    ),
                dropTarget = Rect(0, 0, 0, 0),
                dropTarget = expandedViewDropTargetRight,
            )
        )
    }
@@ -174,7 +250,7 @@ class DragZoneFactory(
        return listOf(
            DragZone.Bubble.Left(
                bounds = Rect(0, 0, windowBounds.right / 2, windowBounds.bottom),
                dropTarget = Rect(0, 0, 0, 0),
                dropTarget = expandedViewDropTargetLeft,
            ),
            DragZone.Bubble.Right(
                bounds =
@@ -184,7 +260,7 @@ class DragZoneFactory(
                        windowBounds.right,
                        windowBounds.bottom,
                    ),
                dropTarget = Rect(0, 0, 0, 0),
                dropTarget = expandedViewDropTargetRight,
            )
        )
    }
@@ -198,7 +274,7 @@ class DragZoneFactory(
                    windowBounds.right / 2 + fullScreenDragZoneWidth / 2,
                    fullScreenDragZoneHeight
                ),
            dropTarget = Rect(0, 0, 0, 0)
            dropTarget = fullScreenDropTarget
        )
    }

@@ -223,7 +299,7 @@ class DragZoneFactory(
                        windowBounds.bottom / 2 + desktopWindowDragZoneHeight / 2
                    )
                },
            dropTarget = Rect(0, 0, 0, 0)
            dropTarget = desktopWindowDropTarget
        )
    }

@@ -236,7 +312,7 @@ class DragZoneFactory(
                    windowBounds.right / 2 + desktopWindowFromExpandedViewDragZoneWidth / 2,
                    windowBounds.bottom / 2 + desktopWindowFromExpandedViewDragZoneHeight / 2
                ),
            dropTarget = Rect(0, 0, 0, 0)
            dropTarget = desktopWindowDropTarget
        )
    }