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

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

Merge "Add support for taskbar phone 3 button seascape" into udc-qpr-dev

parents 781077dd 15a9feb6
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ import com.android.launcher3.taskbar.TaskbarNavButtonController.TaskbarButton;
import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory;
import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonLayoutter;
import com.android.launcher3.util.DimensionUtils;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.MultiPropertyFactory.MultiProperty;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.util.TouchController;
@@ -197,6 +198,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
            this::onComputeInsetsForSeparateWindow;
    private final RecentsHitboxExtender mHitboxExtender = new RecentsHitboxExtender();
    private ImageView mRecentsButton;
    private DisplayController mDisplayController;

    public NavbarButtonsViewController(TaskbarActivityContext context, FrameLayout navButtonsView) {
        mContext = context;
@@ -226,6 +228,8 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
                        TaskbarManager.isPhoneMode(deviceProfile));
        mNavButtonsView.getLayoutParams().height = p.y;

        mDisplayController = DisplayController.INSTANCE.get(mContext);

        mIsImeRenderingNavButtons =
                InputMethodService.canImeRenderGesturalNavButtons() && mContext.imeDrawsImeNavBar();
        if (!mIsImeRenderingNavButtons) {
@@ -727,14 +731,10 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
        boolean isInKidsMode = mContext.isNavBarKidsModeActive();

        if (TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW) {
            if (!isThreeButtonNav) {
                return;
            }

            NavButtonLayoutter navButtonLayoutter =
                    NavButtonLayoutFactory.Companion.getUiLayoutter(
                            dp, mNavButtonsView, res, isInKidsMode, isInSetup, isThreeButtonNav,
                            TaskbarManager.isPhoneMode(dp));
                            TaskbarManager.isPhoneMode(dp), mDisplayController.getInfo().rotation);
            navButtonLayoutter.layoutButtons(dp, isContextualButtonShowing());
            return;
        }
+63 −13
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.RoundedCorner;
import android.view.Surface;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
@@ -295,8 +296,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {

    public void init(@NonNull TaskbarSharedState sharedState) {
        mLastRequestedNonFullscreenHeight = getDefaultTaskbarWindowHeight();
        mWindowLayoutParams =
                createDefaultWindowLayoutParams(TYPE_NAVIGATION_BAR_PANEL, WINDOW_TITLE);
        mWindowLayoutParams = createAllWindowParams();

        // Initialize controllers after all are constructed.
        mControllers.init(sharedState);
@@ -360,11 +360,6 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
     * @param title The window title to pass to the created WindowManager.LayoutParams.
     */
    public WindowManager.LayoutParams createDefaultWindowLayoutParams(int type, String title) {
        DeviceProfile deviceProfile = getDeviceProfile();
        // Taskbar is on the logical bottom of the screen
        boolean isVerticalBarLayout = TaskbarManager.isPhoneButtonNavMode(this) &&
                deviceProfile.isLandscape;

        int windowFlags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_SLIPPERY
                | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
@@ -373,17 +368,14 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                    | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
        }
        WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(
                isVerticalBarLayout ? mLastRequestedNonFullscreenHeight : MATCH_PARENT,
                isVerticalBarLayout ? MATCH_PARENT : mLastRequestedNonFullscreenHeight,
                MATCH_PARENT,
                mLastRequestedNonFullscreenHeight,
                type,
                windowFlags,
                PixelFormat.TRANSLUCENT);
        windowLayoutParams.setTitle(title);
        windowLayoutParams.packageName = getPackageName();
        windowLayoutParams.gravity = !isVerticalBarLayout ?
                Gravity.BOTTOM :
                Gravity.END; // TODO(b/230394142): seascape

        windowLayoutParams.gravity = Gravity.BOTTOM;
        windowLayoutParams.setFitInsetsTypes(0);
        windowLayoutParams.receiveInsetsIgnoringZOrder = true;
        windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
@@ -394,6 +386,64 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                TaskbarManager.isPhoneMode(mDeviceProfile)
                        ? R.string.taskbar_phone_a11y_title
                        : R.string.taskbar_a11y_title);

        return windowLayoutParams;
    }

    /**
     * Creates {@link WindowManager.LayoutParams} for Taskbar, and also sets LP.paramsForRotation
     * for taskbar showing as navigation bar
     */
    private WindowManager.LayoutParams createAllWindowParams() {
        WindowManager.LayoutParams windowLayoutParams =
                createDefaultWindowLayoutParams(TYPE_NAVIGATION_BAR_PANEL,
                        TaskbarActivityContext.WINDOW_TITLE);
        boolean isPhoneNavMode = TaskbarManager.isPhoneButtonNavMode(this);
        if (!isPhoneNavMode) {
            return windowLayoutParams;
        }

        // Provide WM layout params for all rotations to cache, see NavigationBar#getBarLayoutParams
        int width = WindowManager.LayoutParams.MATCH_PARENT;
        int height = WindowManager.LayoutParams.MATCH_PARENT;
        int gravity = Gravity.BOTTOM;
        windowLayoutParams.paramsForRotation = new WindowManager.LayoutParams[4];
        for (int rot = Surface.ROTATION_0; rot <= Surface.ROTATION_270; rot++) {
            WindowManager.LayoutParams lp =
                    createDefaultWindowLayoutParams(TYPE_NAVIGATION_BAR_PANEL,
                            TaskbarActivityContext.WINDOW_TITLE);
            switch (rot) {
                case Surface.ROTATION_0, Surface.ROTATION_180 -> {
                    // Defaults are fine
                    width = WindowManager.LayoutParams.MATCH_PARENT;
                    height = mLastRequestedNonFullscreenHeight;
                    gravity = Gravity.BOTTOM;
                }
                case Surface.ROTATION_90 -> {
                    width = mLastRequestedNonFullscreenHeight;
                    height = WindowManager.LayoutParams.MATCH_PARENT;
                    gravity = Gravity.END;
                }
                case Surface.ROTATION_270 -> {
                    width = mLastRequestedNonFullscreenHeight;
                    height = WindowManager.LayoutParams.MATCH_PARENT;
                    gravity = Gravity.START;
                }

            }
            lp.width = width;
            lp.height = height;
            lp.gravity = gravity;
            windowLayoutParams.paramsForRotation[rot] = lp;
        }

        // Override current layout params
        WindowManager.LayoutParams currentParams =
                windowLayoutParams.paramsForRotation[getDisplay().getRotation()];
        windowLayoutParams.width = currentParams.width;
        windowLayoutParams.height = currentParams.height;
        windowLayoutParams.gravity = currentParams.gravity;

        return windowLayoutParams;
    }

+80 −59
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.graphics.Insets
import android.graphics.Region
import android.os.Binder
import android.os.IBinder
import android.view.Gravity
import android.view.InsetsFrameProvider
import android.view.InsetsFrameProvider.SOURCE_DISPLAY
import android.view.InsetsSource.FLAG_INSETS_ROUNDED_CORNER
@@ -109,16 +110,12 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
                        .setSource(SOURCE_DISPLAY)
                )
        } else {
            windowLayoutParams.providedInsets =
                arrayOf(
                    InsetsFrameProvider(insetsOwner, 0, navigationBars())
                        .setFlags(
                            insetsRoundedCornerFlag,
                            (FLAG_SUPPRESS_SCRIM or FLAG_INSETS_ROUNDED_CORNER)
                        ),
                    InsetsFrameProvider(insetsOwner, 0, tappableElement()),
                    InsetsFrameProvider(insetsOwner, 0, mandatorySystemGestures())
                )
            windowLayoutParams.providedInsets = getButtonNavInsets(insetsRoundedCornerFlag)
            if (windowLayoutParams.paramsForRotation != null) {
                for (layoutParams in windowLayoutParams.paramsForRotation) {
                    layoutParams.providedInsets = getButtonNavInsets(insetsRoundedCornerFlag)
                }
            }
        }

        val taskbarTouchableHeight = controllers.taskbarStashController.touchableHeight
@@ -150,13 +147,43 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
                windowLayoutParams.height
            )
        }

        val gravity = windowLayoutParams.gravity
        for (provider in windowLayoutParams.providedInsets) {
            setProviderInsets(provider, gravity)
        }

        if (windowLayoutParams.paramsForRotation != null) {
            // Add insets for navbar rotated params
            for (layoutParams in windowLayoutParams.paramsForRotation) {
                for (provider in layoutParams.providedInsets) {
                    setProviderInsets(provider, layoutParams.gravity)
                }
            }
        }

        context.notifyUpdateLayoutParams()
    }

    private fun getButtonNavInsets(insetsRoundedCornerFlag: Int): Array<InsetsFrameProvider> {
        return arrayOf(
                    InsetsFrameProvider(insetsOwner, 0, navigationBars())
                        .setFlags(
                            insetsRoundedCornerFlag,
                            (FLAG_SUPPRESS_SCRIM or FLAG_INSETS_ROUNDED_CORNER)
                        ),
                    InsetsFrameProvider(insetsOwner, 0, tappableElement()),
                    InsetsFrameProvider(insetsOwner, 0, mandatorySystemGestures()))
    }

    private fun setProviderInsets(provider: InsetsFrameProvider, gravity: Int) {
        val contentHeight = controllers.taskbarStashController.contentHeightToReportToApps
        val tappableHeight = controllers.taskbarStashController.tappableHeightToReportToApps
        val res = context.resources
        for (provider in windowLayoutParams.providedInsets) {
        if (provider.type == navigationBars() || provider.type == mandatorySystemGestures()) {
                provider.insetsSize = getInsetsByNavMode(contentHeight)
            provider.insetsSize = getInsetsByNavMode(contentHeight, gravity)
        } else if (provider.type == tappableElement()) {
                provider.insetsSize = getInsetsByNavMode(tappableHeight)
            provider.insetsSize = getInsetsByNavMode(tappableHeight, gravity)
        } else if (provider.type == systemGestures() && provider.index == INDEX_LEFT) {
            provider.insetsSize =
                    Insets.of(
@@ -174,15 +201,14 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
                            0
                    )
        }
        }

        val imeInsetsSize = getInsetsByNavMode(taskbarHeightForIme)
        val imeInsetsSize = getInsetsByNavMode(taskbarHeightForIme, gravity)
        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 visInsetsSizeForGestureNavTappableElement = getInsetsByNavMode(0, gravity)
        val insetsSizeOverrideForGestureNavTappableElement =
                arrayOf(
                        InsetsFrameProvider.InsetsSizeOverride(TYPE_INPUT_METHOD, imeInsetsSize),
@@ -191,7 +217,6 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
                                visInsetsSizeForGestureNavTappableElement
                        ),
                )
        for (provider in windowLayoutParams.providedInsets) {
        if (context.isGestureNav && provider.type == tappableElement()) {
            provider.insetsSizeOverrides = insetsSizeOverrideForGestureNavTappableElement
        } else if (provider.type != systemGestures()) {
@@ -200,25 +225,21 @@ class TaskbarInsetsController(val context: TaskbarActivityContext) : LoggableTas
        }
    }

        context.notifyUpdateLayoutParams()
    }

    /**
     * @return [Insets] where the [bottomInset] 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
     * ```
     */
    private fun getInsetsByNavMode(bottomInset: Int): Insets {
        val devicePortrait = !context.deviceProfile.isLandscape
        if (!TaskbarManager.isPhoneButtonNavMode(context) || devicePortrait) {
    private fun getInsetsByNavMode(inset: Int, gravity: Int): Insets {
        if ((gravity and Gravity.BOTTOM) != 0) {
            // Taskbar or portrait phone mode
            return Insets.of(0, 0, 0, bottomInset)
            return Insets.of(0, 0, 0, inset)
        }

        // TODO(b/230394142): seascape
        return Insets.of(0, 0, bottomInset, 0)
        val isSeascape = (gravity and Gravity.START) != 0
        val leftInset = if (isSeascape) inset else 0
        val rightInset = if (isSeascape) 0 else inset
        return Insets.of(leftInset , 0, rightInset, 0)
    }

    /**
+8 −1
Original line number Diff line number Diff line
@@ -206,8 +206,15 @@ public class TaskbarManager {
                        destroyExistingTaskbar();
                    } else {
                        if (dp != null && isTaskbarPresent(dp)) {
                            if (FLAG_HIDE_NAVBAR_WINDOW) {
                                // Re-initialize for screen size change? Should this be done
                                // by looking at screen-size change flag in configDiff in the
                                // block above?
                                recreateTaskbar();
                            } else {
                                mTaskbarActivityContext.updateDeviceProfile(dp);
                            }
                        }
                        mTaskbarActivityContext.onConfigurationChanged(configDiff);
                    }
                }
+14 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.launcher3.Utilities.squaredHypot;
import static com.android.launcher3.anim.AnimatedFloat.VALUE;
import static com.android.launcher3.anim.AnimatorListeners.forEndCallback;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_ALLAPPS_BUTTON_TAP;
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneButtonNavMode;
import static com.android.launcher3.taskbar.TaskbarManager.isPhoneMode;
import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_TASKBAR_ALIGNMENT_ANIM;
@@ -171,6 +172,13 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
                .getTaskbarNavButtonTranslationYForInAppDisplay();

        mActivity.addOnDeviceProfileChangeListener(mDeviceProfileChangeListener);

        if (TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW) {
            // This gets modified in NavbarButtonsViewController, but the initial value it reads
            // may be incorrect since it's state gets destroyed on taskbar recreate, so reset here
            mTaskbarIconAlpha.get(ALPHA_INDEX_SMALL_SCREEN)
                    .animateToValue(isPhoneButtonNavMode(mActivity) ? 0 : 1).start();
        }
    }

    /**
@@ -444,8 +452,13 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
     * Creates an animation for aligning the Taskbar icons with the provided Launcher device profile
     */
    private AnimatorPlaybackController createIconAlignmentController(DeviceProfile launcherDp) {
        mOnControllerPreCreateCallback.run();
        PendingAnimation setter = new PendingAnimation(100);
        if (TaskbarManager.isPhoneButtonNavMode(mActivity)) {
            // No animation for icons in small-screen
            return setter.createPlaybackController();
        }

        mOnControllerPreCreateCallback.run();
        DeviceProfile taskbarDp = mActivity.getDeviceProfile();
        Rect hotseatPadding = launcherDp.getHotseatLayoutPadding(mActivity);
        float scaleUp = ((float) launcherDp.iconSizePx) / taskbarDp.taskbarIconSize;
Loading