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

Commit 5d9015be authored by Arthur Hung's avatar Arthur Hung Committed by Android (Google) Code Review
Browse files

Merge "Handling statusbar color when back navigation (1/2)" into udc-dev

parents 356277f8 0a6ab4fe
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -52,4 +52,10 @@ public interface BackAnimation {
     * @param progressThreshold the max threshold to keep progressing back animation.
     */
    void setSwipeThresholds(float triggerThreshold, float progressThreshold);

    /**
     * Sets the system bar listener to control the system bar color.
     * @param customizer the controller to control system bar color.
     */
    void setStatusBarCustomizer(StatusBarCustomizer customizer);
}
+52 −1
Original line number Diff line number Diff line
@@ -17,11 +17,17 @@
package com.android.wm.shell.back;

import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;

import static com.android.wm.shell.back.BackAnimationConstants.UPDATE_SYSUI_FLAGS_THRESHOLD;

import android.annotation.NonNull;
import android.graphics.Color;
import android.graphics.Rect;
import android.view.SurfaceControl;

import com.android.internal.graphics.ColorUtils;
import com.android.internal.view.AppearanceRegion;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;

/**
@@ -29,18 +35,35 @@ import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
 */
public class BackAnimationBackground {
    private static final int BACKGROUND_LAYER = -1;

    private static final int NO_APPEARANCE = 0;

    private final RootTaskDisplayAreaOrganizer mRootTaskDisplayAreaOrganizer;
    private SurfaceControl mBackgroundSurface;

    private StatusBarCustomizer mCustomizer;
    private boolean mIsRequestingStatusBarAppearance;
    private boolean mBackgroundIsDark;
    private Rect mStartBounds;

    public BackAnimationBackground(RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
        mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
    }

    void ensureBackground(int color, @NonNull SurfaceControl.Transaction transaction) {
    /**
     * Ensures the back animation background color layer is present.
     * @param startRect The start bounds of the closing target.
     * @param color The background color.
     * @param transaction The animation transaction.
     */
    void ensureBackground(Rect startRect, int color,
            @NonNull SurfaceControl.Transaction transaction) {
        if (mBackgroundSurface != null) {
            return;
        }

        mBackgroundIsDark = ColorUtils.calculateLuminance(color) < 0.5f;

        final float[] colorComponents = new float[] { Color.red(color) / 255.f,
                Color.green(color) / 255.f, Color.blue(color) / 255.f };

@@ -54,6 +77,8 @@ public class BackAnimationBackground {
        transaction.setColor(mBackgroundSurface, colorComponents)
                .setLayer(mBackgroundSurface, BACKGROUND_LAYER)
                .show(mBackgroundSurface);
        mStartBounds = startRect;
        mIsRequestingStatusBarAppearance = false;
    }

    void removeBackground(@NonNull SurfaceControl.Transaction transaction) {
@@ -65,5 +90,31 @@ public class BackAnimationBackground {
            transaction.remove(mBackgroundSurface);
        }
        mBackgroundSurface = null;
        mIsRequestingStatusBarAppearance = false;
    }

    void setStatusBarCustomizer(StatusBarCustomizer customizer) {
        mCustomizer = customizer;
    }

    void onBackProgressed(float progress) {
        if (mCustomizer == null || mStartBounds.isEmpty()) {
            return;
        }

        final boolean shouldCustomizeSystemBar = progress > UPDATE_SYSUI_FLAGS_THRESHOLD;
        if (shouldCustomizeSystemBar == mIsRequestingStatusBarAppearance) {
            return;
        }

        mIsRequestingStatusBarAppearance = shouldCustomizeSystemBar;
        if (mIsRequestingStatusBarAppearance) {
            final AppearanceRegion region = new AppearanceRegion(!mBackgroundIsDark
                    ? APPEARANCE_LIGHT_STATUS_BARS : NO_APPEARANCE,
                    mStartBounds);
            mCustomizer.customizeStatusBarAppearance(region);
        } else {
            mCustomizer.customizeStatusBarAppearance(null);
        }
    }
}
+25 −0
Original line number 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.wm.shell.back;

/**
 * The common constant values used in back animators.
 */
class BackAnimationConstants {
    static final float UPDATE_SYSUI_FLAGS_THRESHOLD = 0.20f;
    static final float PROGRESS_COMMIT_THRESHOLD = 0.1f;
}
+19 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.window.IOnBackInvokedCallback;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.common.ProtoLog;
import com.android.internal.view.AppearanceRegion;
import com.android.wm.shell.common.ExternalInterfaceBinder;
import com.android.wm.shell.common.RemoteCallable;
import com.android.wm.shell.common.ShellExecutor;
@@ -142,6 +143,7 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            });

    private final BackAnimationBackground mAnimationBackground;
    private StatusBarCustomizer mCustomizer;

    public BackAnimationController(
            @NonNull ShellInit shellInit,
@@ -268,6 +270,12 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            mShellExecutor.execute(() -> BackAnimationController.this.setSwipeThresholds(
                    triggerThreshold, progressThreshold));
        }

        @Override
        public void setStatusBarCustomizer(StatusBarCustomizer customizer) {
            mCustomizer = customizer;
            mAnimationBackground.setStatusBarCustomizer(customizer);
        }
    }

    private static class IBackAnimationImpl extends IBackAnimation.Stub
@@ -294,12 +302,23 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
                            BackNavigationInfo.TYPE_RETURN_TO_HOME));
        }

        public void customizeStatusBarAppearance(AppearanceRegion appearance) {
            executeRemoteCallWithTaskPermission(mController, "useLauncherSysBarFlags",
                    (controller) -> controller.customizeStatusBarAppearance(appearance));
        }

        @Override
        public void invalidate() {
            mController = null;
        }
    }

    private void customizeStatusBarAppearance(AppearanceRegion appearance) {
        if (mCustomizer != null) {
            mCustomizer.customizeStatusBarAppearance(appearance);
        }
    }

    void registerAnimation(@BackNavigationInfo.BackTargetType int type,
            @NonNull BackAnimationRunner runner) {
        mAnimationDefinition.set(type, runner);
+3 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.back;
import static android.view.RemoteAnimationTarget.MODE_CLOSING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;

import static com.android.wm.shell.back.BackAnimationConstants.PROGRESS_COMMIT_THRESHOLD;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;

import android.animation.Animator;
@@ -89,7 +90,6 @@ class CrossActivityAnimation {
    private static final float WINDOW_X_SHIFT_DP = 96;
    private static final int SCALE_FACTOR = 100;
    // TODO(b/264710590): Use the progress commit threshold from ViewConfiguration once it exists.
    private static final float PROGRESS_COMMIT_THRESHOLD = 0.1f;
    private static final float TARGET_COMMIT_PROGRESS = 0.5f;
    private static final float ENTER_ALPHA_THRESHOLD = 0.22f;

@@ -184,7 +184,7 @@ class CrossActivityAnimation {
        mStartTaskRect.offsetTo(0, 0);

        // Draw background with task background color.
        mBackground.ensureBackground(
        mBackground.ensureBackground(mClosingTarget.windowConfiguration.getBounds(),
                mEnteringTarget.taskInfo.taskDescription.getBackgroundColor(), mTransaction);
    }

@@ -244,6 +244,7 @@ class CrossActivityAnimation {
                : mapLinear(progress, 0, 1f, 0, TARGET_COMMIT_PROGRESS)) * SCALE_FACTOR;
        mLeavingProgressSpring.animateToFinalPosition(springProgress);
        mEnteringProgressSpring.animateToFinalPosition(springProgress);
        mBackground.onBackProgressed(progress);
    }

    private void onGestureCommitted() {
Loading