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

Commit 1eb1124d authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing back-button alpha animation code

Back button is only animation in 2-button UI which is not supported anymore

Bug: 246006580
Test: Presubmit
Change-Id: I7385b07272e44c1f9f0488c158e1b4ee67060120
parent b64894b0
Loading
Loading
Loading
Loading
+0 −64
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.statehandlers;

import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.util.NavigationMode.TWO_BUTTONS;
import static com.android.quickstep.AnimatedFloat.VALUE;

import com.android.launcher3.LauncherState;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.statemanager.StateManager.StateHandler;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.UiThreadHelper;
import com.android.quickstep.AnimatedFloat;
import com.android.quickstep.SystemUiProxy;

/**
 * State handler for animating back button alpha in two-button nav mode.
 */
public class BackButtonAlphaHandler implements StateHandler<LauncherState> {

    private final QuickstepLauncher mLauncher;
    private final AnimatedFloat mBackAlpha = new AnimatedFloat(this::updateBackAlpha);

    public BackButtonAlphaHandler(QuickstepLauncher launcher) {
        mLauncher = launcher;
    }

    @Override
    public void setState(LauncherState state) { }

    @Override
    public void setStateWithAnimation(LauncherState toState, StateAnimationConfig config,
            PendingAnimation animation) {
        if (DisplayController.getNavigationMode(mLauncher) != TWO_BUTTONS) {
            return;
        }

        mBackAlpha.value = SystemUiProxy.INSTANCE.get(mLauncher).getLastNavButtonAlpha();
        animation.setFloat(mBackAlpha, VALUE,
                mLauncher.shouldBackButtonBeHidden(toState) ? 0 : 1, LINEAR);
    }

    private void updateBackAlpha() {
        UiThreadHelper.setBackButtonAlphaAsync(mLauncher,
                QuickstepLauncher.SET_BACK_BUTTON_ALPHA, mBackAlpha.value, false /* animate */);
    }
}
+0 −51
Original line number Diff line number Diff line
@@ -17,14 +17,11 @@ package com.android.launcher3.uioverrides;

import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED;

import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.FLAG_HIDE_BACK_BUTTON;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.NO_OFFSET;
import static com.android.launcher3.LauncherState.OVERVIEW;
@@ -47,7 +44,6 @@ import static com.android.launcher3.util.DisplayController.CHANGE_ACTIVE_SCREEN;
import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
import static com.android.launcher3.util.Executors.THREAD_POOL_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.NavigationMode.TWO_BUTTONS;
import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY;

import android.animation.AnimatorSet;
@@ -72,7 +68,6 @@ import android.window.SplashScreen;

import androidx.annotation.Nullable;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherSettings.Favorites;
@@ -96,7 +91,6 @@ import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.proxy.ProxyActivityStarter;
import com.android.launcher3.proxy.StartActivityParams;
import com.android.launcher3.statehandlers.BackButtonAlphaHandler;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.statemanager.StateManager.AtomicAnimationFactory;
import com.android.launcher3.statemanager.StateManager.StateHandler;
@@ -171,12 +165,6 @@ public class QuickstepLauncher extends Launcher {
     */
    public static final AsyncCommand SET_SHELF_HEIGHT = (context, arg1, arg2) ->
            SystemUiProxy.INSTANCE.get(context).setShelfHeight(arg1 != 0, arg2);
    /**
     * Reusable command for applying the back button alpha on the background thread.
     */
    public static final AsyncCommand SET_BACK_BUTTON_ALPHA =
            (context, arg1, arg2) -> SystemUiProxy.INSTANCE.get(context).setNavBarButtonAlpha(
                    Float.intBitsToFloat(arg1), arg2 != 0);

    private FixedContainerItems mAllAppsPredictions;
    private HotseatPredictionController mHotseatPredictionController;
@@ -299,11 +287,6 @@ public class QuickstepLauncher extends Launcher {

    @Override
    protected void onActivityFlagsChanged(int changeBits) {
        if ((changeBits
                & (ACTIVITY_STATE_WINDOW_FOCUSED | ACTIVITY_STATE_TRANSITION_ACTIVE)) != 0) {
            onLauncherStateOrFocusChanged();
        }

        if ((changeBits & ACTIVITY_STATE_STARTED) != 0) {
            mDepthController.setActivityStarted(isStarted());
        }
@@ -729,7 +712,6 @@ public class QuickstepLauncher extends Launcher {
        super.collectStateHandlers(out);
        out.add(getDepthController());
        out.add(new RecentsViewStateController(this));
        out.add(new BackButtonAlphaHandler(this));
    }

    public DepthController getDepthController() {
@@ -787,39 +769,6 @@ public class QuickstepLauncher extends Launcher {
                ? new float[] {1, 1} : new float[] {1.1f, NO_OFFSET};
    }

    @Override
    public void onDragLayerHierarchyChanged() {
        onLauncherStateOrFocusChanged();
    }

    public boolean shouldBackButtonBeHidden(LauncherState toState) {
        NavigationMode mode = DisplayController.getNavigationMode(this);
        boolean shouldBackButtonBeHidden = mode.hasGestures
                && toState.hasFlag(FLAG_HIDE_BACK_BUTTON)
                && hasWindowFocus()
                && (getActivityFlags() & ACTIVITY_STATE_TRANSITION_ACTIVE) == 0;
        if (shouldBackButtonBeHidden) {
            // Show the back button if there is a floating view visible.
            shouldBackButtonBeHidden = AbstractFloatingView.getTopOpenViewWithType(this,
                    TYPE_ALL & ~TYPE_HIDE_BACK_BUTTON) == null;
        }
        return shouldBackButtonBeHidden;
    }

    /**
     * Sets the back button visibility based on the current state/window focus.
     */
    private void onLauncherStateOrFocusChanged() {
        boolean shouldBackButtonBeHidden = shouldBackButtonBeHidden(getStateManager().getState());
        if (DisplayController.getNavigationMode(this) == TWO_BUTTONS) {
            UiThreadHelper.setBackButtonAlphaAsync(this, SET_BACK_BUTTON_ALPHA,
                    shouldBackButtonBeHidden ? 0f : 1f, true /* animate */);
        }
        if (getDragLayer() != null) {
            getRootView().setDisallowBackGesture(shouldBackButtonBeHidden);
        }
    }

    @Override
    public void finishBindingItems(IntSet pagesBoundFirst) {
        super.finishBindingItems(pagesBoundFirst);
+2 −49
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package com.android.quickstep;

import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;

import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import android.app.ActivityManager;
@@ -43,8 +42,6 @@ import android.view.RemoteAnimationTarget;
import android.view.SurfaceControl;
import android.window.IOnBackInvokedCallback;

import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.systemui.shared.recents.ISystemUiProxy;
@@ -72,7 +69,7 @@ import java.util.Arrays;
/**
 * Holds the reference to SystemUI.
 */
public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayInfoChangeListener {
public class SystemUiProxy implements ISystemUiProxy {
    private static final String TAG = SystemUiProxy.class.getSimpleName();

    public static final MainThreadInitializedObject<SystemUiProxy> INSTANCE =
@@ -106,28 +103,15 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI
    // Used to dedupe calls to SystemUI
    private int mLastShelfHeight;
    private boolean mLastShelfVisible;
    private float mLastNavButtonAlpha;
    private boolean mLastNavButtonAnimate;
    private boolean mHasNavButtonAlphaBeenSet = false;
    private Runnable mPendingSetNavButtonAlpha = null;
    private Context mContext;

    // TODO(141886704): Find a way to remove this
    private int mLastSystemUiStateFlags;

    public SystemUiProxy(Context context) {
        DisplayController.INSTANCE.get(context).addChangeListener(this);
        mContext = context;
    }

    @Override
    public void onDisplayInfoChanged(Context context, Info info, int flags) {
        if ((flags & CHANGE_NAVIGATION_MODE) != 0) {
            // Whenever the nav mode changes, force reset the nav button alpha
            setNavBarButtonAlpha(1f, false);
        }
    }

    @Override
    public void onBackPressed() {
        if (mSystemUiProxy != null) {
@@ -205,11 +189,6 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI
        if (mBackAnimation != null && mBackToLauncherCallback != null) {
            setBackToLauncherCallback(mBackToLauncherCallback);
        }

        if (mPendingSetNavButtonAlpha != null) {
            mPendingSetNavButtonAlpha.run();
            mPendingSetNavButtonAlpha = null;
        }
    }

    public void clearProxy() {
@@ -272,31 +251,6 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI
        }
    }

    public float getLastNavButtonAlpha() {
        return mLastNavButtonAlpha;
    }

    @Override
    public void setNavBarButtonAlpha(float alpha, boolean animate) {
        boolean changed = Float.compare(alpha, mLastNavButtonAlpha) != 0
                || animate != mLastNavButtonAnimate
                || !mHasNavButtonAlphaBeenSet;
        if (changed) {
            if (mSystemUiProxy == null) {
                mPendingSetNavButtonAlpha = () -> setNavBarButtonAlpha(alpha, animate);
            } else {
                mLastNavButtonAlpha = alpha;
                mLastNavButtonAnimate = animate;
                mHasNavButtonAlphaBeenSet = true;
                try {
                    mSystemUiProxy.setNavBarButtonAlpha(alpha, animate);
                } catch (RemoteException e) {
                    Log.w(TAG, "Failed call setNavBarButtonAlpha", e);
                }
            }
        }
    }

    @Override
    public void onStatusBarMotionEvent(MotionEvent event) {
        if (mSystemUiProxy != null) {
@@ -895,8 +849,7 @@ public class SystemUiProxy implements ISystemUiProxy, DisplayController.DisplayI
        if (mRecentTasks != null
                && mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_PC)) {
            try {
                return new ArrayList<ActivityManager.RunningTaskInfo>(
                        Arrays.asList(mRecentTasks.getRunningTasks(numTasks)));
                return new ArrayList<>(Arrays.asList(mRecentTasks.getRunningTasks(numTasks)));
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call getRunningTasks", e);
            }
+0 −4
Original line number Diff line number Diff line
@@ -109,10 +109,6 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch
            | TYPE_ALL_APPS_EDU | TYPE_ICON_SURFACE | TYPE_WIDGETS_EDUCATION_DIALOG
            | TYPE_TASKBAR_EDUCATION_DIALOG | TYPE_TASKBAR_ALL_APPS | TYPE_OPTIONS_POPUP_DIALOG;

    // Usually we show the back button when a floating view is open. Instead, hide for these types.
    public static final int TYPE_HIDE_BACK_BUTTON = TYPE_ON_BOARD_POPUP | TYPE_DISCOVERY_BOUNCE
            | TYPE_SNACKBAR | TYPE_WIDGET_RESIZE_FRAME | TYPE_LISTENER;

    public static final int TYPE_ACCESSIBLE = TYPE_ALL & ~TYPE_DISCOVERY_BOUNCE & ~TYPE_LISTENER
            & ~TYPE_ALL_APPS_EDU;

+13 −1
Original line number Diff line number Diff line
@@ -1123,6 +1123,7 @@ public class Launcher extends StatefulActivity<LauncherState>
                        .log(getAllAppsEntryEvent().get());
            }
        }
        updateDisallowBack();
    }

    /**
@@ -3133,7 +3134,18 @@ public class Launcher extends StatefulActivity<LauncherState>

    public void useFadeOutAnimationForLauncherStart(CancellationSignal signal) { }

    public void onDragLayerHierarchyChanged() { }
    public void onDragLayerHierarchyChanged() {
        updateDisallowBack();
    }

    private void updateDisallowBack() {
        LauncherRootView rv = getRootView();
        if (rv != null) {
            boolean disableBack = getStateManager().getState() == NORMAL
                    && AbstractFloatingView.getTopOpenView(this) == null;
            rv.setDisallowBackGesture(disableBack);
        }
    }

    @Override
    public void returnToHomescreen() {
Loading