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

Commit 6ca06360 authored by Saumya Prakash's avatar Saumya Prakash
Browse files

Make shared ManageWindowsViewContainer more generic

This change adapts the container that both Launcher and Shell share to
allow the Launcher side to pass in bitmaps instead of TaskSnapshot which
Launcher doesn't have access to.

Bug: 315989246
Test: Manual
Flag: com.android.launcher3.enable_multi_instance_menu_taskbar
Change-Id: I15a733dff7302c010858d40b8be2978da6748b0c
parent 6e63bbbb
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -50,6 +50,22 @@ abstract class ManageWindowsViewContainer(
    fun createMenu(snapshotList: List<Pair<Int, TaskSnapshot>>,
             onIconClickListener: ((Int) -> Unit),
             onOutsideClickListener: (() -> Unit)): ManageWindowsView {
        val bitmapList = snapshotList.map { (index, snapshot) ->
            index to Bitmap.wrapHardwareBuffer(snapshot.hardwareBuffer, snapshot.colorSpace)
        }
        return createAndShowMenuView(
            bitmapList,
            onIconClickListener,
            onOutsideClickListener
        )
    }

    /** Creates the menu view with the given bitmaps, and displays it. */
    fun createAndShowMenuView(
        snapshotList: List<Pair<Int, Bitmap?>>,
        onIconClickListener: ((Int) -> Unit),
        onOutsideClickListener: (() -> Unit)
    ): ManageWindowsView {
        menuView = ManageWindowsView(context, menuBackgroundColor).apply {
            this.onOutsideClickListener = onOutsideClickListener
            this.onIconClickListener = onIconClickListener
@@ -120,7 +136,7 @@ abstract class ManageWindowsViewContainer(
        }

        fun generateIconViews(
            snapshotList: List<Pair<Int, TaskSnapshot>>
            snapshotList: List<Pair<Int, Bitmap?>>
        ) {
            menuWidth = 0
            menuHeight = 0
@@ -133,7 +149,7 @@ abstract class ManageWindowsViewContainer(
            // Add each icon to the menu, adding a new row when needed.
            for ((iconCount, taskInfoSnapshotPair) in snapshotList.withIndex()) {
                val taskId = taskInfoSnapshotPair.first
                val snapshot = taskInfoSnapshotPair.second
                val snapshotBitmap = taskInfoSnapshotPair.second
                // Once a row is filled, make a new row and increase the menu height.
                if (iconCount % MENU_MAX_ICONS_PER_ROW == 0) {
                    rowLayout = LinearLayout(context)
@@ -141,10 +157,7 @@ abstract class ManageWindowsViewContainer(
                    rootView.addView(rowLayout)
                    menuHeight += (instanceIconHeight + iconMargin).toInt()
                }
                val snapshotBitmap = Bitmap.wrapHardwareBuffer(
                    snapshot.hardwareBuffer,
                    snapshot.colorSpace
                )

                val croppedBitmap = snapshotBitmap?.let { cropBitmap(it) }
                val scaledSnapshotBitmap = croppedBitmap?.let {
                    Bitmap.createScaledBitmap(