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

Commit ccb17341 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Update taskbar drag and drop treatment" into sc-v2-dev am: da86c0e6

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/16134100

Change-Id: I0964f7f4aa1ef9c12758d4cdda22f171279b84ac
parents 3a5e6199 da86c0e6
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ import com.android.launcher3.util.ViewCache;
import com.android.launcher3.views.ActivityContext;
import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.SysUINavigationMode.Mode;
import com.android.quickstep.SystemUiProxy;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.WindowManagerWrapper;
@@ -158,7 +157,8 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ
                new TaskbarKeyguardController(this),
                new StashedHandleViewController(this, stashedHandleView),
                new TaskbarStashController(this),
                new TaskbarEduController(this));
                new TaskbarEduController(this),
                new TaskbarAutohideSuspendController(this));
    }

    public void init(TaskbarSharedState sharedState) {
@@ -375,7 +375,8 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ
     * Updates the TaskbarContainer to MATCH_PARENT vs original Taskbar size.
     */
    public void setTaskbarWindowFullscreen(boolean fullscreen) {
        SystemUiProxy.INSTANCE.getNoCreate().notifyTaskbarAutohideSuspend(fullscreen);
        mControllers.taskbarAutohideSuspendController.updateFlag(
                TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_FULLSCREEN, fullscreen);
        mIsFullscreen = fullscreen;
        setTaskbarWindowHeight(fullscreen ? MATCH_PARENT : mLastRequestedNonFullscreenHeight);
    }
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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;

import androidx.annotation.IntDef;

import com.android.quickstep.SystemUiProxy;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Normally Taskbar will auto-hide when entering immersive (fullscreen) apps. This controller allows
 * us to suspend that behavior in certain cases (e.g. opening a Folder or dragging an icon).
 */
public class TaskbarAutohideSuspendController {

    public static final int FLAG_AUTOHIDE_SUSPEND_FULLSCREEN = 1 << 0;
    public static final int FLAG_AUTOHIDE_SUSPEND_DRAGGING = 1 << 1;
    @IntDef(flag = true, value = {
            FLAG_AUTOHIDE_SUSPEND_FULLSCREEN,
            FLAG_AUTOHIDE_SUSPEND_DRAGGING,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface AutohideSuspendFlag {}

    private final SystemUiProxy mSystemUiProxy;

    private @AutohideSuspendFlag int mAutohideSuspendFlags = 0;

    public TaskbarAutohideSuspendController(TaskbarActivityContext activity) {
        mSystemUiProxy = SystemUiProxy.INSTANCE.get(activity);
    }

    public void onDestroy() {
        mSystemUiProxy.notifyTaskbarAutohideSuspend(false);
    }

    /**
     * Adds or removes the given flag, then notifies system UI proxy whether to suspend auto-hide.
     */
    public void updateFlag(@AutohideSuspendFlag int flag, boolean enabled) {
        if (enabled) {
            mAutohideSuspendFlags |= flag;
        } else {
            mAutohideSuspendFlags &= ~flag;
        }
        mSystemUiProxy.notifyTaskbarAutohideSuspend(mAutohideSuspendFlags != 0);
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ public class TaskbarControllers {
    public final StashedHandleViewController stashedHandleViewController;
    public final TaskbarStashController taskbarStashController;
    public final TaskbarEduController taskbarEduController;
    public final TaskbarAutohideSuspendController taskbarAutohideSuspendController;

    /** Do not store this controller, as it may change at runtime. */
    @NonNull public TaskbarUIController uiController = TaskbarUIController.DEFAULT;
@@ -53,7 +54,8 @@ public class TaskbarControllers {
            TaskbarKeyguardController taskbarKeyguardController,
            StashedHandleViewController stashedHandleViewController,
            TaskbarStashController taskbarStashController,
            TaskbarEduController taskbarEduController) {
            TaskbarEduController taskbarEduController,
            TaskbarAutohideSuspendController taskbarAutoHideSuspendController) {
        this.taskbarActivityContext = taskbarActivityContext;
        this.taskbarDragController = taskbarDragController;
        this.navButtonController = navButtonController;
@@ -67,6 +69,7 @@ public class TaskbarControllers {
        this.stashedHandleViewController = stashedHandleViewController;
        this.taskbarStashController = taskbarStashController;
        this.taskbarEduController = taskbarEduController;
        this.taskbarAutohideSuspendController = taskbarAutoHideSuspendController;
    }

    /**
@@ -75,6 +78,7 @@ public class TaskbarControllers {
     * in constructors for now, as some controllers may still be waiting for init().
     */
    public void init(TaskbarSharedState sharedState) {
        taskbarDragController.init(this);
        navbarButtonsViewController.init(this, sharedState);
        if (taskbarActivityContext.isThreeButtonNav()) {
            rotationButtonController.init();
@@ -101,5 +105,6 @@ public class TaskbarControllers {
        taskbarUnfoldAnimationController.onDestroy();
        taskbarViewController.onDestroy();
        stashedHandleViewController.onDestroy();
        taskbarAutohideSuspendController.onDestroy();
    }
}
+20 −16
Original line number Diff line number Diff line
@@ -15,9 +15,6 @@
 */
package com.android.launcher3.taskbar;

import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

import android.content.ClipData;
import android.content.ClipDescription;
import android.content.Intent;
@@ -49,7 +46,6 @@ import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dragndrop.DraggableView;
import com.android.launcher3.graphics.DragPreviewProvider;
import com.android.launcher3.icons.FastBitmapDrawable;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -65,6 +61,9 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext
    private final int mDragIconSize;
    private final int[] mTempXY = new int[2];

    // Initialized in init.
    TaskbarControllers mControllers;

    // Where the initial touch was relative to the dragged icon.
    private int mRegistrationX;
    private int mRegistrationY;
@@ -77,6 +76,10 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext
        mDragIconSize = resources.getDimensionPixelSize(R.dimen.taskbar_icon_drag_icon_size);
    }

    public void init(TaskbarControllers controllers) {
        mControllers = controllers;
    }

    /**
     * Attempts to start a system drag and drop operation for the given View, using its tag to
     * generate the ClipDescription and Intent.
@@ -90,19 +93,17 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext
        BubbleTextView btv = (BubbleTextView) view;

        mActivity.setTaskbarWindowFullscreen(true);
        view.post(() -> {
        btv.post(() -> {
            startInternalDrag(btv);
            btv.setVisibility(INVISIBLE);
            btv.getIcon().setIsDisabled(true);
            mControllers.taskbarAutohideSuspendController.updateFlag(
                    TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING, true);
        });
        return true;
    }

    private void startInternalDrag(BubbleTextView btv) {
        float iconScale = 1f;
        Drawable icon = btv.getIcon();
        if (icon instanceof FastBitmapDrawable) {
            iconScale = ((FastBitmapDrawable) icon).getAnimatedScale();
        }
        float iconScale = btv.getIcon().getAnimatedScale();

        // Clear the pressed state if necessary
        btv.clearFocus();
@@ -239,16 +240,17 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext
                shadowSize.set(mDragIconSize, mDragIconSize);
                // The registration point was taken before the icon scaled to mDragIconSize, so
                // offset the registration to where the touch is on the new size.
                int offset = (mDragIconSize - btv.getIconSize()) / 2;
                shadowTouchPoint.set(mRegistrationX + offset, mRegistrationY + offset);
                int offsetX = (mDragIconSize - mDragObject.dragView.getDragRegionWidth()) / 2;
                int offsetY = (mDragIconSize - mDragObject.dragView.getDragRegionHeight()) / 2;
                shadowTouchPoint.set(mRegistrationX + offsetX, mRegistrationY + offsetY);
            }

            @Override
            public void onDrawShadow(Canvas canvas) {
                canvas.save();
                float scale = (float) mDragIconSize / btv.getIconSize();
                float scale = mDragObject.dragView.getScaleX();
                canvas.scale(scale, scale);
                btv.getIcon().draw(canvas);
                mDragObject.dragView.draw(canvas);
                canvas.restore();
            }
        };
@@ -330,7 +332,9 @@ public class TaskbarDragController extends DragController<TaskbarActivityContext

    private void maybeOnDragEnd() {
        if (!isDragging()) {
            ((View) mDragObject.originalView).setVisibility(VISIBLE);
            ((BubbleTextView) mDragObject.originalView).getIcon().setIsDisabled(false);
            mControllers.taskbarAutohideSuspendController.updateFlag(
                    TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING, false);
        }
    }