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

Commit 3adfa419 authored by Vinit Nayak's avatar Vinit Nayak Committed by Android (Google) Code Review
Browse files

Merge "Ensure matching insets for taskbar gesture and 3 button nav" into udc-qpr-dev

parents 42b3ff1c 1fd1b688
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -146,7 +146,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
    private int mLastRequestedNonFullscreenHeight;
    private int mLastRequestedNonFullscreenHeight;


    private NavigationMode mNavMode;
    private NavigationMode mNavMode;
    private final boolean mImeDrawsImeNavBar;
    private boolean mImeDrawsImeNavBar;
    private final ViewCache mViewCache = new ViewCache();
    private final ViewCache mViewCache = new ViewCache();


    private final boolean mIsSafeModeEnabled;
    private final boolean mIsSafeModeEnabled;
@@ -299,6 +299,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {




    public void init(@NonNull TaskbarSharedState sharedState) {
    public void init(@NonNull TaskbarSharedState sharedState) {
        mImeDrawsImeNavBar = getBoolByName(IME_DRAWS_IME_NAV_BAR_RES_NAME, getResources(), false);
        mLastRequestedNonFullscreenHeight = getDefaultTaskbarWindowHeight();
        mLastRequestedNonFullscreenHeight = getDefaultTaskbarWindowHeight();
        mWindowLayoutParams = createAllWindowParams();
        mWindowLayoutParams = createAllWindowParams();


+48 −51
Original line number Original line Diff line number Diff line
@@ -94,26 +94,12 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
            } else {
            } else {
                0
                0
            }
            }
        if (context.isGestureNav) {

            windowLayoutParams.providedInsets =
        windowLayoutParams.providedInsets = getProvidedInsets(insetsRoundedCornerFlag)
                arrayOf(
        if (!context.isGestureNav) {
                    InsetsFrameProvider(insetsOwner, 0, navigationBars())
                        .setFlags(
                            FLAG_SUPPRESS_SCRIM or insetsRoundedCornerFlag,
                            FLAG_SUPPRESS_SCRIM or FLAG_INSETS_ROUNDED_CORNER
                        ),
                    InsetsFrameProvider(insetsOwner, 0, tappableElement()),
                    InsetsFrameProvider(insetsOwner, 0, mandatorySystemGestures()),
                    InsetsFrameProvider(insetsOwner, INDEX_LEFT, systemGestures())
                        .setSource(SOURCE_DISPLAY),
                    InsetsFrameProvider(insetsOwner, INDEX_RIGHT, systemGestures())
                        .setSource(SOURCE_DISPLAY)
                )
        } else {
            windowLayoutParams.providedInsets = getButtonNavInsets(insetsRoundedCornerFlag)
            if (windowLayoutParams.paramsForRotation != null) {
            if (windowLayoutParams.paramsForRotation != null) {
                for (layoutParams in windowLayoutParams.paramsForRotation) {
                for (layoutParams in windowLayoutParams.paramsForRotation) {
                    layoutParams.providedInsets = getButtonNavInsets(insetsRoundedCornerFlag)
                    layoutParams.providedInsets = getProvidedInsets(insetsRoundedCornerFlag)
                }
                }
            }
            }
        }
        }
@@ -165,15 +151,28 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
        context.notifyUpdateLayoutParams()
        context.notifyUpdateLayoutParams()
    }
    }


    private fun getButtonNavInsets(insetsRoundedCornerFlag: Int): Array<InsetsFrameProvider> {
    /**
     * The inset types and number of insets provided have to match for both gesture nav and button
     * nav. The values and the order of the elements in array are allowed to differ.
     * Reason being WM does not allow types and number of insets changing for a given window once it
     * is added into the hierarchy for performance reasons.
     */
    private fun getProvidedInsets(insetsRoundedCornerFlag: Int): Array<InsetsFrameProvider> {
        val navBarsFlag =
                (if (context.isGestureNav) FLAG_SUPPRESS_SCRIM else 0) or insetsRoundedCornerFlag
        return arrayOf(
        return arrayOf(
                InsetsFrameProvider(insetsOwner, 0, navigationBars())
                InsetsFrameProvider(insetsOwner, 0, navigationBars())
                        .setFlags(
                        .setFlags(
                            insetsRoundedCornerFlag,
                                navBarsFlag,
                            (FLAG_SUPPRESS_SCRIM or FLAG_INSETS_ROUNDED_CORNER)
                                FLAG_SUPPRESS_SCRIM or FLAG_INSETS_ROUNDED_CORNER
                        ),
                        ),
                InsetsFrameProvider(insetsOwner, 0, tappableElement()),
                InsetsFrameProvider(insetsOwner, 0, tappableElement()),
                    InsetsFrameProvider(insetsOwner, 0, mandatorySystemGestures()))
                InsetsFrameProvider(insetsOwner, 0, mandatorySystemGestures()),
                InsetsFrameProvider(insetsOwner, INDEX_LEFT, systemGestures())
                        .setSource(SOURCE_DISPLAY),
                InsetsFrameProvider(insetsOwner, INDEX_RIGHT, systemGestures())
                        .setSource(SOURCE_DISPLAY)
        )
    }
    }


    private fun setProviderInsets(provider: InsetsFrameProvider, gravity: Int) {
    private fun setProviderInsets(provider: InsetsFrameProvider, gravity: Int) {
@@ -181,47 +180,45 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
        val tappableHeight = controllers.taskbarStashController.tappableHeightToReportToApps
        val tappableHeight = controllers.taskbarStashController.tappableHeightToReportToApps
        val res = context.resources
        val res = context.resources
        if (provider.type == navigationBars() || provider.type == mandatorySystemGestures()) {
        if (provider.type == navigationBars() || provider.type == mandatorySystemGestures()) {
            provider.insetsSize = getInsetsByNavMode(contentHeight, gravity)
            provider.insetsSize = getInsetsForGravity(contentHeight, gravity)
        } else if (provider.type == tappableElement()) {
        } else if (provider.type == tappableElement()) {
            provider.insetsSize = getInsetsByNavMode(tappableHeight, gravity)
            provider.insetsSize = getInsetsForGravity(tappableHeight, gravity)
        } else if (provider.type == systemGestures() && provider.index == INDEX_LEFT) {
        } else if (provider.type == systemGestures() && provider.index == INDEX_LEFT) {
            provider.insetsSize =
            val leftIndexInset =
                    Insets.of(
                    if (context.isThreeButtonNav) 0
                            gestureNavSettingsObserver.getLeftSensitivityForCallingUser(res),
                    else gestureNavSettingsObserver.getLeftSensitivityForCallingUser(res)
                            0,
            provider.insetsSize = Insets.of(leftIndexInset, 0, 0, 0)
                            0,
                            0
                    )
        } else if (provider.type == systemGestures() && provider.index == INDEX_RIGHT) {
        } else if (provider.type == systemGestures() && provider.index == INDEX_RIGHT) {
            provider.insetsSize =
            val rightIndexInset =
                    Insets.of(
                    if (context.isThreeButtonNav) 0
                            0,
                    else gestureNavSettingsObserver.getRightSensitivityForCallingUser(res)
                            0,
            provider.insetsSize = Insets.of(0, 0, rightIndexInset, 0)
                            gestureNavSettingsObserver.getRightSensitivityForCallingUser(res),
                            0
                    )
        }
        }


        val imeInsetsSize = getInsetsByNavMode(taskbarHeightForIme, gravity)

        val insetsSizeOverride =
        val imeInsetsSize = getInsetsForGravity(taskbarHeightForIme, gravity)
        val imeInsetsSizeOverride =
                arrayOf(
                arrayOf(
                        InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
                        InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
                )
                )
        // Use 0 tappableElement insets for the VoiceInteractionWindow when gesture nav is enabled.
        // Use 0 tappableElement insets for the VoiceInteractionWindow when gesture nav is enabled.
        val visInsetsSizeForGestureNavTappableElement = getInsetsByNavMode(0, gravity)
        val visInsetsSizeForTappableElement =
        val insetsSizeOverrideForGestureNavTappableElement =
                if (context.isGestureNav) getInsetsForGravity(0, gravity)
                else getInsetsForGravity(tappableHeight, gravity)
        val insetsSizeOverrideForTappableElement =
                arrayOf(
                arrayOf(
                        InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
                        InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
                        InsetsFrameProvider.InsetsSizeOverride(
                        InsetsFrameProvider.InsetsSizeOverride(
                                TYPE_VOICE_INTERACTION,
                                TYPE_VOICE_INTERACTION,
                                visInsetsSizeForGestureNavTappableElement
                                visInsetsSizeForTappableElement
                        ),
                        ),
                )
                )
        if (context.isGestureNav && provider.type == tappableElement()) {
        if ((context.isGestureNav || TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW)
            provider.insetsSizeOverrides = insetsSizeOverrideForGestureNavTappableElement
                && provider.type == tappableElement()) {
            provider.insetsSizeOverrides = insetsSizeOverrideForTappableElement
        } else if (provider.type != systemGestures()) {
        } else if (provider.type != systemGestures()) {
            // We only override insets at the bottom of the screen
            // We only override insets at the bottom of the screen
            provider.insetsSizeOverrides = insetsSizeOverride
            provider.insetsSizeOverrides = imeInsetsSizeOverride
        }
        }
    }
    }


@@ -229,14 +226,14 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
     * @return [Insets] where the [inset] is either used as a bottom inset or
     * @return [Insets] where the [inset] is either used as a bottom inset or
     * right/left inset if using 3 button nav
     * right/left inset if using 3 button nav
     */
     */
    private fun getInsetsByNavMode(inset: Int, gravity: Int): Insets {
    private fun getInsetsForGravity(inset: Int, gravity: Int): Insets {
        if ((gravity and Gravity.BOTTOM) != 0) {
        if ((gravity and Gravity.BOTTOM) == Gravity.BOTTOM) {
            // Taskbar or portrait phone mode
            // Taskbar or portrait phone mode
            return Insets.of(0, 0, 0, inset)
            return Insets.of(0, 0, 0, inset)
        }
        }


        // TODO(b/230394142): seascape
        // TODO(b/230394142): seascape
        val isSeascape = (gravity and Gravity.START) != 0
        val isSeascape = (gravity and Gravity.START) == Gravity.START
        val leftInset = if (isSeascape) inset else 0
        val leftInset = if (isSeascape) inset else 0
        val rightInset = if (isSeascape) 0 else inset
        val rightInset = if (isSeascape) 0 else inset
        return Insets.of(leftInset , 0, rightInset, 0)
        return Insets.of(leftInset , 0, rightInset, 0)
+4 −2
Original line number Original line Diff line number Diff line
@@ -338,7 +338,6 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
        // us that we're paused until a bit later. This avoids flickering upon recreating taskbar.
        // us that we're paused until a bit later. This avoids flickering upon recreating taskbar.
        updateStateForFlag(FLAG_IN_APP, true);
        updateStateForFlag(FLAG_IN_APP, true);
        applyState(/* duration = */ 0);
        applyState(/* duration = */ 0);

        notifyStashChange(/* visible */ false, /* stashed */ isStashedInApp());
        notifyStashChange(/* visible */ false, /* stashed */ isStashedInApp());
    }
    }


@@ -675,7 +674,10 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
                    .setDuration(duration));
                    .setDuration(duration));
            mAnimator.play(mTaskbarImeBgAlpha.animateToValue(
            mAnimator.play(mTaskbarImeBgAlpha.animateToValue(
                    hasAnyFlag(FLAG_STASHED_IN_APP_IME) ? 0 : 1).setDuration(duration));
                    hasAnyFlag(FLAG_STASHED_IN_APP_IME) ? 0 : 1).setDuration(duration));
            mAnimator.addListener(AnimatorListeners.forEndCallback(() -> mAnimator = null));
            mAnimator.addListener(AnimatorListeners.forEndCallback(() -> {
                mAnimator = null;
                mIsStashed = isStashed;
            }));
            return;
            return;
        }
        }


+9 −0
Original line number Original line Diff line number Diff line
@@ -67,6 +67,7 @@ class NavButtonLayoutFactory {
            val startContextualContainer =
            val startContextualContainer =
                navButtonsView.findViewById<ViewGroup>(ID_START_CONTEXTUAL_BUTTONS)
                navButtonsView.findViewById<ViewGroup>(ID_START_CONTEXTUAL_BUTTONS)
            val isPhoneNavMode = phoneMode && isThreeButtonNav
            val isPhoneNavMode = phoneMode && isThreeButtonNav
            val isPhoneGestureMode = phoneMode && !isThreeButtonNav
            return when {
            return when {
                isPhoneNavMode -> {
                isPhoneNavMode -> {
                    if (!deviceProfile.isLandscape) {
                    if (!deviceProfile.isLandscape) {
@@ -92,6 +93,14 @@ class NavButtonLayoutFactory {
                        )
                        )
                    }
                    }
                }
                }
                isPhoneGestureMode ->{
                    PhoneGestureLayoutter(
                            resources,
                            navButtonContainer,
                            endContextualContainer,
                            startContextualContainer
                    )
                }
                deviceProfile.isTaskbarPresent -> {
                deviceProfile.isTaskbarPresent -> {
                    return when {
                    return when {
                        isInSetup -> {
                        isInSetup -> {
+41 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 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
 */

package com.android.launcher3.taskbar.navbutton

import android.content.res.Resources
import android.view.ViewGroup
import android.widget.LinearLayout
import com.android.launcher3.DeviceProfile

/** Layoutter for showing gesture navigation on phone screen. No buttons here, no-op container */
class PhoneGestureLayoutter(
        resources: Resources,
        navBarContainer: LinearLayout,
        endContextualContainer: ViewGroup,
        startContextualContainer: ViewGroup
) :
        AbstractNavButtonLayoutter(
                resources,
                navBarContainer,
                endContextualContainer,
                startContextualContainer
        ) {

    override fun layoutButtons(dp: DeviceProfile, isContextualButtonShowing: Boolean) {
        // no-op
    }
}