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

Commit 7db37b3d authored by Vinit Nayak's avatar Vinit Nayak
Browse files

Use Taskbar window for phones (only works on gesture nav) with flag

* Try to avoid re-creating TaskbarActivityContext to
avoid re-inflating taskbar views
* Toggle via Flipper App (key 1101)
OR adb shell setprop persist.wm.debug.hide_navbar_window 1 && adb reboot
TODOs
* Only works for gesture nav, not 3 button
* Sampling on phone doesn't always work.

Bug: 219035565
Change-Id: I2a015f99d5f1fe86d7261eec9fd898bd4480ff9f
parent 4eec22f8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@
    <dimen name="taskbar_contextual_buttons_size">35dp</dimen>
    <dimen name="taskbar_stashed_size">24dp</dimen>
    <dimen name="taskbar_stashed_handle_width">220dp</dimen>
    <dimen name="taskbar_stashed_small_screen">108dp</dimen>
    <dimen name="taskbar_unstash_input_area">316dp</dimen>
    <dimen name="taskbar_stashed_handle_height">4dp</dimen>
    <dimen name="taskbar_edu_wave_anim_trans_y">25dp</dimen>
+42 −19
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.launcher3.taskbar;

import static com.android.launcher3.taskbar.TaskbarManager.isPhoneMode;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
@@ -25,6 +27,7 @@ import android.graphics.Rect;
import android.view.View;
import android.view.ViewOutlineProvider;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.RevealOutlineAnimation;
@@ -55,9 +58,9 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
    private final TaskbarActivityContext mActivity;
    private final SharedPreferences mPrefs;
    private final StashedHandleView mStashedHandleView;
    private final int mStashedHandleWidth;
    private int mStashedHandleWidth;
    private final int mStashedHandleHeight;
    private final RegionSamplingHelper mRegionSamplingHelper;
    private RegionSamplingHelper mRegionSamplingHelper;
    private final MultiValueAlpha mTaskbarStashedHandleAlpha;
    private final AnimatedFloat mTaskbarStashedHandleHintScale = new AnimatedFloat(
            this::updateStashedHandleHintScale);
@@ -85,30 +88,27 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
                mPrefs.getBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY, false),
                false /* animate */);
        final Resources resources = mActivity.getResources();
        mStashedHandleWidth = resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width);
        mStashedHandleHeight = resources.getDimensionPixelSize(
                R.dimen.taskbar_stashed_handle_height);
        mRegionSamplingHelper = new RegionSamplingHelper(mStashedHandleView,
                new RegionSamplingHelper.SamplingCallback() {
                    @Override
                    public void onRegionDarknessChanged(boolean isRegionDark) {
                        mStashedHandleView.updateHandleColor(isRegionDark, true /* animate */);
                        mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY,
                                isRegionDark).apply();
                    }

                    @Override
                    public Rect getSampledRegion(View sampledView) {
                        return mStashedHandleView.getSampledRegion();
                    }
                }, Executors.UI_HELPER_EXECUTOR);
    }

    public void init(TaskbarControllers controllers) {
        mControllers = controllers;
        mStashedHandleView.getLayoutParams().height = mActivity.getDeviceProfile().taskbarSize;
        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
        Resources resources = mActivity.getResources();
        if (isPhoneMode(mActivity.getDeviceProfile())) {
            mStashedHandleView.getLayoutParams().height =
                    resources.getDimensionPixelSize(R.dimen.taskbar_size);
            mStashedHandleWidth =
                    resources.getDimensionPixelSize(R.dimen.taskbar_stashed_small_screen);
        } else {
            mStashedHandleView.getLayoutParams().height = deviceProfile.taskbarSize;
            mStashedHandleWidth =
                    resources.getDimensionPixelSize(R.dimen.taskbar_stashed_handle_width);
        }

        mTaskbarStashedHandleAlpha.getProperty(ALPHA_INDEX_STASHED).setValue(0);
        mTaskbarStashedHandleAlpha.getProperty(ALPHA_INDEX_STASHED).setValue(
                isPhoneMode(deviceProfile) ? 1 : 0);
        mTaskbarStashedHandleHintScale.updateValue(1f);

        final int stashedTaskbarHeight = mControllers.taskbarStashController.getStashedHeight();
@@ -135,10 +135,33 @@ public class StashedHandleViewController implements TaskbarControllers.LoggableT
            view.setPivotX(stashedCenterX);
            view.setPivotY(stashedCenterY);
        });
        initRegionSampler();
        if (isPhoneMode(deviceProfile)) {
            onIsStashedChanged(true);
        }
    }

    private void initRegionSampler() {
        mRegionSamplingHelper = new RegionSamplingHelper(mStashedHandleView,
                new RegionSamplingHelper.SamplingCallback() {
                    @Override
                    public void onRegionDarknessChanged(boolean isRegionDark) {
                        mStashedHandleView.updateHandleColor(isRegionDark, true /* animate */);
                        mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_HANDLE_REGION_DARK_KEY,
                                isRegionDark).apply();
                    }

                    @Override
                    public Rect getSampledRegion(View sampledView) {
                        return mStashedHandleView.getSampledRegion();
                    }
                }, Executors.UI_HELPER_EXECUTOR);
    }


    public void onDestroy() {
        mRegionSamplingHelper.stopAndDestroy();
        mRegionSamplingHelper = null;
    }

    public MultiValueAlpha getStashedHandleAlpha() {
+16 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_OPEN;
import static com.android.launcher3.taskbar.TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW;
import static com.android.launcher3.testing.shared.ResourceUtils.getBoolByName;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
@@ -130,6 +131,8 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
    // The flag to know if the window is excluded from magnification region computation.
    private boolean mIsExcludeFromMagnificationRegion = false;
    private boolean mBindingItems = false;
    private boolean mAddedWindow = false;


    private final TaskbarShortcutMenuAccessibilityDelegate mAccessibilityDelegate;

@@ -218,7 +221,12 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        mControllers.init(sharedState);
        updateSysuiStateFlags(sharedState.sysuiStateFlags, true /* fromInit */);

        if (!mAddedWindow) {
            mWindowManager.addView(mDragLayer, mWindowLayoutParams);
            mAddedWindow = true;
        } else {
            mWindowManager.updateViewLayout(mDragLayer, mWindowLayoutParams);
        }
    }

    @Override
@@ -461,7 +469,10 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
        mIsDestroyed = true;
        setUIController(TaskbarUIController.DEFAULT);
        mControllers.onDestroy();
        if (!FLAG_HIDE_NAVBAR_WINDOW) {
            mWindowManager.removeViewImmediate(mDragLayer);
            mAddedWindow = false;
        }
    }

    public void updateSysuiStateFlags(int systemUiStateFlags, boolean fromInit) {
@@ -596,6 +607,9 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
     * Returns the default height of the window, including the static corner radii above taskbar.
     */
    public int getDefaultTaskbarWindowHeight() {
        if (FLAG_HIDE_NAVBAR_WINDOW && mDeviceProfile.isPhone) {
            return getResources().getDimensionPixelSize(R.dimen.taskbar_stashed_size);
        }
        return mDeviceProfile.taskbarSize + Math.max(getLeftCornerRadius(), getRightCornerRadius());
    }

+8 −2
Original line number Diff line number Diff line
@@ -86,9 +86,15 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
        }
    }

    protected void onDestroy() {
    protected void onDestroy(boolean forceDestroy) {
        if (forceDestroy) {
            ViewTreeObserverWrapper.removeOnComputeInsetsListener(mTaskbarInsetsComputer);
        }
    }

    protected void onDestroy() {
        onDestroy(!TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW);
    }

    @Override
    protected void onAttachedToWindow() {
@@ -101,7 +107,7 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();

        onDestroy();
        onDestroy(true);
    }

    @Override
+38 −11
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.res.Configuration;
import android.hardware.display.DisplayManager;
import android.net.Uri;
import android.os.Handler;
import android.os.SystemProperties;
import android.provider.Settings;
import android.view.Display;

@@ -58,6 +59,9 @@ import java.io.PrintWriter;
 */
public class TaskbarManager {

    public static final boolean FLAG_HIDE_NAVBAR_WINDOW =
            SystemProperties.getBoolean("persist.wm.debug.hide_navbar_window", false);

    private static final Uri USER_SETUP_COMPLETE_URI = Settings.Secure.getUriFor(
            Settings.Secure.USER_SETUP_COMPLETE);

@@ -147,7 +151,7 @@ public class TaskbarManager {
                } else {
                    // Config change might be handled without re-creating the taskbar
                    if (mTaskbarActivityContext != null) {
                        if (dp != null && dp.isTaskbarPresent) {
                        if (dp != null && isTaskbarPresent(dp)) {
                            mTaskbarActivityContext.updateDeviceProfile(dp);
                        }
                        mTaskbarActivityContext.onConfigurationChanged(configDiff);
@@ -159,7 +163,8 @@ public class TaskbarManager {
            @Override
            public void onLowMemory() { }
        };
        mShutdownReceiver = new SimpleBroadcastReceiver(i -> destroyExistingTaskbar());
        mShutdownReceiver = new SimpleBroadcastReceiver(i ->
                destroyExistingTaskbar());
        mDispInfoChangeListener = (context, info, flags) -> {
            if ((flags & CHANGE_FLAGS) != 0) {
                recreateTaskbar();
@@ -179,9 +184,11 @@ public class TaskbarManager {
    private void destroyExistingTaskbar() {
        if (mTaskbarActivityContext != null) {
            mTaskbarActivityContext.onDestroy();
            if (!FLAG_HIDE_NAVBAR_WINDOW) {
                mTaskbarActivityContext = null;
            }
        }
    }

    /**
     * Displays a frame of the first Launcher reveal animation.
@@ -260,24 +267,32 @@ public class TaskbarManager {
        }
    }

    /**
     * This method is called multiple times (ex. initial init, then when user unlocks) in which case
     * we fully want to destroy an existing taskbar and create a new one.
     * In other case (folding/unfolding) we don't need to remove and add window.
     */
    private void recreateTaskbar() {
        destroyExistingTaskbar();
        DeviceProfile dp = mUserUnlocked ?
                LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;

        DeviceProfile dp =
                mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;

        boolean isTaskBarEnabled = dp != null && dp.isTaskbarPresent;
        destroyExistingTaskbar();

        boolean isTaskBarEnabled = dp != null && isTaskbarPresent(dp);
        if (!isTaskBarEnabled) {
            SystemUiProxy.INSTANCE.get(mContext)
                    .notifyTaskbarStatus(/* visible */ false, /* stashed */ false);
            return;
        }

        if (mTaskbarActivityContext == null) {
            mTaskbarActivityContext = new TaskbarActivityContext(mContext, dp, mNavButtonController,
                    mUnfoldProgressProvider);

        } else {
            mTaskbarActivityContext.updateDeviceProfile(dp);
        }
        mTaskbarActivityContext.init(mSharedState);

        if (mActivity != null) {
            mTaskbarActivityContext.setUIController(
                    createTaskbarUIControllerForActivity(mActivity));
@@ -301,6 +316,18 @@ public class TaskbarManager {
        }
    }

    /**
     * @return {@code true} if provided device profile isn't a large screen profile
     *                      and we are using a single window for taskbar and navbar.
     */
    public static boolean isPhoneMode(DeviceProfile deviceProfile) {
        return TaskbarManager.FLAG_HIDE_NAVBAR_WINDOW && deviceProfile.isPhone;
    }

    private boolean isTaskbarPresent(DeviceProfile deviceProfile) {
        return FLAG_HIDE_NAVBAR_WINDOW || deviceProfile.isTaskbarPresent;
    }

    public void onRotationProposal(int rotation, boolean isValid) {
        if (mTaskbarActivityContext != null) {
            mTaskbarActivityContext.onRotationProposal(rotation, isValid);
Loading