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

Commit bdfc07f1 authored by Thales Lima's avatar Thales Lima Committed by Android (Google) Code Review
Browse files

Merge "Check kotlin format before uploading" into tm-qpr-dev

parents d23cd428 03ac377a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
[Hook Scripts]
checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --config_xml tools/checkstyle.xml --sha ${PREUPLOAD_COMMIT}

ktfmt_hook = ${REPO_ROOT}/external/ktfmt/ktfmt.py --check ${PREUPLOAD_FILES}
 No newline at end of file
+15 −15
Original line number Diff line number Diff line
@@ -16,20 +16,17 @@

package com.android.launcher3.taskbar

import com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound
import com.android.launcher3.Utilities.mapToRange

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import com.android.launcher3.R
import com.android.launcher3.Utilities.mapToRange
import com.android.launcher3.anim.Interpolators
import com.android.launcher3.icons.GraphicsUtils.setColorAlphaBound
import com.android.launcher3.util.DisplayController

/**
 * Helps draw the taskbar background, made up of a rectangle plus two inverted rounded corners.
 */
/** Helps draw the taskbar background, made up of a rectangle plus two inverted rounded corners. */
class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {

    val paint: Paint = Paint()
@@ -39,7 +36,7 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
    private var maxBackgroundHeight = context.deviceProfile.taskbarSize.toFloat()
    private val transientBackgroundBounds = context.transientTaskbarBounds

    private val isTransientTaskbar = DisplayController.isTransientTaskbar(context);
    private val isTransientTaskbar = DisplayController.isTransientTaskbar(context)

    private var shadowBlur = 0f
    private var keyShadowDistance = 0f
@@ -98,9 +95,7 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
        invertedRightCornerPath.op(square, circle, Path.Op.DIFFERENCE)
    }

    /**
     * Draws the background with the given paint and height, on the provided canvas.
     */
    /** Draws the background with the given paint and height, on the provided canvas. */
    fun draw(canvas: Canvas) {
        canvas.save()
        canvas.translate(0f, canvas.height - backgroundHeight - bottomMargin)
@@ -124,21 +119,26 @@ class TaskbarBackgroundRenderer(context: TaskbarActivityContext) {
            canvas.translate(0f, bottomMargin * ((1f - scaleFactor) / 2f))

            // Draw shadow.
            val shadowAlpha = mapToRange(paint.alpha.toFloat(), 0f, 255f, 0f, 25f,
                Interpolators.LINEAR)
            paint.setShadowLayer(shadowBlur, 0f, keyShadowDistance,
            val shadowAlpha =
                mapToRange(paint.alpha.toFloat(), 0f, 255f, 0f, 25f, Interpolators.LINEAR)
            paint.setShadowLayer(
                shadowBlur,
                0f,
                keyShadowDistance,
                setColorAlphaBound(Color.BLACK, Math.round(shadowAlpha))
            )

            // Draw background.
            val radius = backgroundHeight / 2f;
            val radius = backgroundHeight / 2f

            canvas.drawRoundRect(
                transientBackgroundBounds.left + (delta / 2f),
                translationYForSwipe,
                transientBackgroundBounds.right - (delta / 2f),
                backgroundHeight + translationYForSwipe,
                radius, radius, paint
                radius,
                radius,
                paint
            )
        }

+45 −35
Original line number Diff line number Diff line
@@ -36,9 +36,7 @@ import com.android.launcher3.anim.AlphaUpdateListener
import com.android.launcher3.taskbar.TaskbarControllers.LoggableTaskbarController
import java.io.PrintWriter

/**
 * Handles the insets that Taskbar provides to underlying apps and the IME.
 */
/** Handles the insets that Taskbar provides to underlying apps and the IME. */
class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTaskbarController {

    /** The bottom insets taskbar provides to the IME when IME is visible. */
@@ -77,13 +75,19 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask

    fun onTaskbarWindowHeightOrInsetsChanged() {
        val touchableHeight = controllers.taskbarStashController.touchableHeight
        touchableRegion.set(0, windowLayoutParams.height - touchableHeight,
            context.deviceProfile.widthPx, windowLayoutParams.height)
        touchableRegion.set(
            0,
            windowLayoutParams.height - touchableHeight,
            context.deviceProfile.widthPx,
            windowLayoutParams.height
        )
        val contentHeight = controllers.taskbarStashController.contentHeightToReportToApps
        val tappableHeight = controllers.taskbarStashController.tappableHeightToReportToApps
        for (provider in windowLayoutParams.providedInsets) {
            if (provider.type == ITYPE_EXTRA_NAVIGATION_BAR
                    || provider.type == ITYPE_BOTTOM_MANDATORY_GESTURES) {
            if (
                provider.type == ITYPE_EXTRA_NAVIGATION_BAR ||
                    provider.type == ITYPE_BOTTOM_MANDATORY_GESTURES
            ) {
                provider.insetsSize = getInsetsByNavMode(contentHeight)
            } else if (provider.type == ITYPE_BOTTOM_TAPPABLE_ELEMENT) {
                provider.insetsSize = getInsetsByNavMode(tappableHeight)
@@ -91,19 +95,15 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
        }

        val imeInsetsSize = getInsetsByNavMode(taskbarHeightForIme)
        val insetsSizeOverride = arrayOf(
            InsetsFrameProvider.InsetsSizeOverride(
                TYPE_INPUT_METHOD,
                imeInsetsSize
            ),
        val insetsSizeOverride =
            arrayOf(
                InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
            )
        // Use 0 tappableElement insets for the VoiceInteractionWindow when gesture nav is enabled.
        val visInsetsSizeForGestureNavTappableElement = getInsetsByNavMode(0)
        val insetsSizeOverrideForGestureNavTappableElement = arrayOf(
            InsetsFrameProvider.InsetsSizeOverride(
                TYPE_INPUT_METHOD,
                imeInsetsSize
            ),
        val insetsSizeOverrideForGestureNavTappableElement =
            arrayOf(
                InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
                InsetsFrameProvider.InsetsSizeOverride(
                    TYPE_VOICE_INTERACTION,
                    visInsetsSizeForGestureNavTappableElement
@@ -120,7 +120,9 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask

    /**
     * @return [Insets] where the [bottomInset] is either used as a bottom inset or
     * ```
     *         right/left inset if using 3 button nav
     * ```
     */
    private fun getInsetsByNavMode(bottomInset: Int): Insets {
        val devicePortrait = !context.deviceProfile.isLandscape
@@ -139,9 +141,9 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
     * @param providesInsetsTypes The inset types we would like this layout params to provide.
     */
    fun setProvidesInsetsTypes(params: WindowManager.LayoutParams, providesInsetsTypes: IntArray) {
        params.providedInsets = arrayOfNulls<InsetsFrameProvider>(providesInsetsTypes.size);
        params.providedInsets = arrayOfNulls<InsetsFrameProvider>(providesInsetsTypes.size)
        for (i in providesInsetsTypes.indices) {
            params.providedInsets[i] = InsetsFrameProvider(providesInsetsTypes[i]);
            params.providedInsets[i] = InsetsFrameProvider(providesInsetsTypes[i])
        }
    }

@@ -153,14 +155,17 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
        insetsInfo.touchableRegion.setEmpty()
        // Always have nav buttons be touchable
        controllers.navbarButtonsViewController.addVisibleButtonsRegion(
            context.dragLayer, insetsInfo.touchableRegion
            context.dragLayer,
            insetsInfo.touchableRegion
        )
        var insetsIsTouchableRegion = true
        if (context.dragLayer.alpha < AlphaUpdateListener.ALPHA_CUTOFF_THRESHOLD) {
            // Let touches pass through us.
            insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION)
        } else if (controllers.navbarButtonsViewController.isImeVisible
                && controllers.taskbarStashController.isStashed()) {
        } else if (
            controllers.navbarButtonsViewController.isImeVisible &&
                controllers.taskbarStashController.isStashed()
        ) {
            insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION)
        } else if (!controllers.uiController.isTaskbarTouchable) {
            // Let touches pass through us.
@@ -174,9 +179,10 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
                insetsInfo.touchableRegion.set(touchableRegion)
            }
            insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION)
        } else if (controllers.taskbarViewController.areIconsVisible()
            || AbstractFloatingView.hasOpenView(context, AbstractFloatingView.TYPE_ALL)
            || context.isNavBarKidsModeActive
        } else if (
            controllers.taskbarViewController.areIconsVisible() ||
                AbstractFloatingView.hasOpenView(context, AbstractFloatingView.TYPE_ALL) ||
                context.isNavBarKidsModeActive
        ) {
            // Taskbar has some touchable elements, take over the full taskbar area
            insetsInfo.setTouchableInsets(
@@ -198,8 +204,12 @@ class TaskbarInsetsController(val context: TaskbarActivityContext): LoggableTask
        pw.println(prefix + "TaskbarInsetsController:")
        pw.println("$prefix\twindowHeight=${windowLayoutParams.height}")
        for (provider in windowLayoutParams.providedInsets) {
            pw.print("$prefix\tprovidedInsets: (type=" + InsetsState.typeToString(provider.type)
                    + " insetsSize=" + provider.insetsSize)
            pw.print(
                "$prefix\tprovidedInsets: (type=" +
                    InsetsState.typeToString(provider.type) +
                    " insetsSize=" +
                    provider.insetsSize
            )
            if (provider.insetsSizeOverrides != null) {
                pw.print(" insetsSizeOverrides={")
                for ((i, overrideSize) in provider.insetsSizeOverrides.withIndex()) {
+38 −30
Original line number Diff line number Diff line
@@ -10,12 +10,9 @@ import java.io.PrintWriter
private const val TASKBAR_ICONS_FADE_DURATION = 300L
private const val STASHED_HANDLE_FADE_DURATION = 180L

/**
 * Controls Taskbar behavior while Voice Interaction Window (assistant) is showing.
 */
class VoiceInteractionWindowController(val context: TaskbarActivityContext)
    : TaskbarControllers.LoggableTaskbarController,
        TaskbarControllers.BackgroundRendererController {
/** Controls Taskbar behavior while Voice Interaction Window (assistant) is showing. */
class VoiceInteractionWindowController(val context: TaskbarActivityContext) :
    TaskbarControllers.LoggableTaskbarController, TaskbarControllers.BackgroundRendererController {

    private val taskbarBackgroundRenderer = TaskbarBackgroundRenderer(context)

@@ -37,8 +34,10 @@ class VoiceInteractionWindowController(val context: TaskbarActivityContext)

                override fun draw(canvas: Canvas) {
                    super.draw(canvas)
                    if (this@VoiceInteractionWindowController.context.isGestureNav
                        && controllers.taskbarStashController.isInAppAndNotStashed) {
                    if (
                        this@VoiceInteractionWindowController.context.isGestureNav &&
                            controllers.taskbarStashController.isInAppAndNotStashed
                    ) {
                        taskbarBackgroundRenderer.draw(canvas)
                    }
                }
@@ -46,8 +45,8 @@ class VoiceInteractionWindowController(val context: TaskbarActivityContext)
        separateWindowForTaskbarBackground.recreateControllers()
        separateWindowForTaskbarBackground.setWillNotDraw(false)

        separateWindowLayoutParams = context.createDefaultWindowLayoutParams(
            TYPE_APPLICATION_OVERLAY)
        separateWindowLayoutParams =
            context.createDefaultWindowLayoutParams(TYPE_APPLICATION_OVERLAY)
        separateWindowLayoutParams.isSystemApplicationOverlay = true
    }

@@ -63,11 +62,13 @@ class VoiceInteractionWindowController(val context: TaskbarActivityContext)

        // Fade out taskbar icons and stashed handle.
        val taskbarIconAlpha = if (isVoiceInteractionWindowVisible) 0f else 1f
        val fadeTaskbarIcons = controllers.taskbarViewController.taskbarIconAlpha
        val fadeTaskbarIcons =
            controllers.taskbarViewController.taskbarIconAlpha
                .get(TaskbarViewController.ALPHA_INDEX_ASSISTANT_INVOKED)
                .animateToValue(taskbarIconAlpha)
                .setDuration(TASKBAR_ICONS_FADE_DURATION)
        val fadeStashedHandle = controllers.stashedHandleViewController.stashedHandleAlpha
        val fadeStashedHandle =
            controllers.stashedHandleViewController.stashedHandleAlpha
                .get(StashedHandleViewController.ALPHA_INDEX_ASSISTANT_INVOKED)
                .animateToValue(taskbarIconAlpha)
                .setDuration(STASHED_HANDLE_FADE_DURATION)
@@ -83,17 +84,24 @@ class VoiceInteractionWindowController(val context: TaskbarActivityContext)

    /**
     * Either:
     *
     * Hides the TaskbarDragLayer background and creates a new window to draw just that background.
     *
     * OR
     *
     * Removes the temporary window and show the TaskbarDragLayer background again.
     */
    private fun moveTaskbarBackgroundToAppropriateLayer(skipAnim: Boolean) {
        val taskbarBackgroundOverride = controllers.taskbarDragLayerController
            .overrideBackgroundAlpha
        val taskbarBackgroundOverride =
            controllers.taskbarDragLayerController.overrideBackgroundAlpha
        val moveToLowerLayer = isVoiceInteractionWindowVisible
        val onWindowsSynchronized = if (moveToLowerLayer) {
        val onWindowsSynchronized =
            if (moveToLowerLayer) {
                // First add the temporary window, then hide the overlapping taskbar background.
            context.addWindowView(separateWindowForTaskbarBackground, separateWindowLayoutParams);
                context.addWindowView(
                    separateWindowForTaskbarBackground,
                    separateWindowLayoutParams
                );
                { taskbarBackgroundOverride.updateValue(0f) }
            } else {
                // First reapply the original taskbar background, then remove the temporary window.
+9 −12
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonL
 * [navButtonContainer]
 *
 * @property navButtonContainer ViewGroup that holds the 3 navigation buttons.
 * @property endContextualContainer ViewGroup that holds the end contextual button (ex, IME dismiss).
 * @property endContextualContainer ViewGroup that holds the end contextual button (ex, IME
 * dismiss).
 * @property startContextualContainer ViewGroup that holds the start contextual button (ex, A11y).
 */
abstract class AbstractNavButtonLayoutter(
@@ -39,11 +40,7 @@ abstract class AbstractNavButtonLayoutter(
    protected val endContextualContainer: ViewGroup,
    protected val startContextualContainer: ViewGroup
) : NavButtonLayoutter {
    protected val homeButton: ImageView = navButtonContainer
            .findViewById(R.id.home)
    protected val recentsButton: ImageView = navButtonContainer
            .findViewById(R.id.recent_apps)
    protected val backButton: ImageView = navButtonContainer
            .findViewById(R.id.back)
    protected val homeButton: ImageView = navButtonContainer.findViewById(R.id.home)
    protected val recentsButton: ImageView = navButtonContainer.findViewById(R.id.recent_apps)
    protected val backButton: ImageView = navButtonContainer.findViewById(R.id.back)
}
Loading