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

Commit a34340ef authored by Yunfan Chen's avatar Yunfan Chen
Browse files

Modify the way of providing insets per WM change

The WM provides a new way to provide insets, modified the code to
reflect that change.

Bug: 161689946
Test: m
Merged-In: I31bd26a5ce4c3e47f8961d4fe528f3a97ec063f8
Change-Id: I31bd26a5ce4c3e47f8961d4fe528f3a97ec063f8
parent 37d39619
Loading
Loading
Loading
Loading
+23 −37
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.taskbar
import android.graphics.Insets
import android.graphics.Region
import android.view.InsetsState.ITYPE_BOTTOM_MANDATORY_GESTURES
import android.view.InsetsState
import android.view.WindowManager
import com.android.launcher3.AbstractFloatingView
import com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_ALL_APPS
@@ -61,9 +62,6 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
            )
        )

        windowLayoutParams.providedInternalInsets = arrayOfNulls<Insets>(ITYPE_SIZE)
        windowLayoutParams.providedInternalImeInsets = arrayOfNulls<Insets>(ITYPE_SIZE)

        onTaskbarWindowHeightOrInsetsChanged()

        windowLayoutParams.insetsRoundedCornerFrame = true
@@ -75,32 +73,23 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
    }

    fun onTaskbarWindowHeightOrInsetsChanged() {
        var reducingSize = getReducingInsetsForTaskbarInsetsHeight(
            controllers.taskbarStashController.contentHeightToReportToApps)

        contentRegion.set(0, reducingSize.top,
        var contentHeight = controllers.taskbarStashController.contentHeightToReportToApps
        contentRegion.set(0, windowLayoutParams.height - contentHeight,
            context.deviceProfile.widthPx, windowLayoutParams.height)
        windowLayoutParams.providedInternalInsets[ITYPE_EXTRA_NAVIGATION_BAR] = reducingSize
        windowLayoutParams.providedInternalInsets[ITYPE_BOTTOM_MANDATORY_GESTURES] = reducingSize
        reducingSize = getReducingInsetsForTaskbarInsetsHeight(
            controllers.taskbarStashController.tappableHeightToReportToApps)
        windowLayoutParams.providedInternalInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT] = reducingSize
        windowLayoutParams.providedInternalInsets[ITYPE_BOTTOM_MANDATORY_GESTURES] = reducingSize

        reducingSize = getReducingInsetsForTaskbarInsetsHeight(taskbarHeightForIme)
        windowLayoutParams.providedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR] = reducingSize
        windowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT] = reducingSize
        windowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_MANDATORY_GESTURES] = reducingSize
        var tappableHeight = controllers.taskbarStashController.tappableHeightToReportToApps
        for (provider in windowLayoutParams.providedInsets) {
            if (provider.type == ITYPE_EXTRA_NAVIGATION_BAR) {
                provider.insetsSize = Insets.of(0, 0, 0, contentHeight)
            } else if (provider.type == ITYPE_BOTTOM_TAPPABLE_ELEMENT
                      || provider.type == ITYPE_BOTTOM_MANDATORY_GESTURES) {
                provider.insetsSize = Insets.of(0, 0, 0, tappableHeight)
            }
        }

    /**
     * WindowLayoutParams.providedInternal*Insets expects Insets that subtract from the window frame
     * height (i.e. WindowLayoutParams#height). So for Taskbar to report bottom insets to apps, it
     * actually provides insets from the top of its window frame.
     * @param height The number of pixels from the bottom of the screen that Taskbar insets.
     */
    private fun getReducingInsetsForTaskbarInsetsHeight(height: Int): Insets {
        return Insets.of(0, windowLayoutParams.height - height, 0, 0)
        var imeInsetsSize = Insets.of(0, 0, 0, taskbarHeightForIme)
        for (provider in windowLayoutParams.providedInsets) {
            provider.imeInsetsSize = imeInsetsSize
        }
    }

    /**
@@ -151,13 +140,10 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
    override fun dumpLogs(prefix: String, pw: PrintWriter) {
        pw.println(prefix + "TaskbarInsetsController:")
        pw.println("$prefix\twindowHeight=${windowLayoutParams.height}")
        pw.println("$prefix\tprovidedInternalInsets[ITYPE_EXTRA_NAVIGATION_BAR]=" +
                "${windowLayoutParams.providedInternalInsets[ITYPE_EXTRA_NAVIGATION_BAR]}")
        pw.println("$prefix\tprovidedInternalInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT]=" +
                "${windowLayoutParams.providedInternalInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT]}")
        pw.println("$prefix\tprovidedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR]=" +
                "${windowLayoutParams.providedInternalImeInsets[ITYPE_EXTRA_NAVIGATION_BAR]}")
        pw.println("$prefix\tprovidedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT]=" +
                "${windowLayoutParams.providedInternalImeInsets[ITYPE_BOTTOM_TAPPABLE_ELEMENT]}")
        for (provider in windowLayoutParams.providedInsets) {
            pw.println("$prefix\tprovidedInsets: (type=" + InsetsState.typeToString(provider.type)
                    + " insetsSize=" + provider.insetsSize
                    + " imeInsetsSize=" + provider.imeInsetsSize + ")")
        }
    }
}