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

Commit 37920966 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Allowing the widgetBottomSheet to be dragged

even when the touch is started from outside the panel

Removing various instanceOf checks in onNewIntent and onBackPress
and moving all the corresponding logging in the FloatingView
This simplifies handling of panel specific log and avoids
missing a particular panel type in the if-else statement.

Bug: 64751884
Bug: 64751923
Change-Id: I98f5aae18560a64be73c9efcf495479740d49a00
parent 326403e9
Loading
Loading
Loading
Loading
+42 −37
Original line number Diff line number Diff line
@@ -23,6 +23,10 @@
    android:foregroundTint="?attr/workspaceTextColor"
    android:padding="0dp">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <!-- Left -->
        <ImageView
            android:layout_width="wrap_content"
@@ -59,4 +63,5 @@
            android:src="@drawable/ic_widget_resize_handle"
            android:tint="?attr/workspaceTextColor" />

    </FrameLayout>
</com.android.launcher3.AppWidgetResizeFrame>
 No newline at end of file
+18 −20
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.view.View;
import android.widget.LinearLayout;

import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.util.TouchController;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -32,18 +34,20 @@ import java.lang.annotation.RetentionPolicy;
/**
 * Base class for a View which shows a floating UI on top of the launcher UI.
 */
public abstract class AbstractFloatingView extends LinearLayout {
public abstract class AbstractFloatingView extends LinearLayout implements TouchController {

    @IntDef(flag = true, value = {
            TYPE_FOLDER,
            TYPE_POPUP_CONTAINER_WITH_ARROW,
            TYPE_WIDGETS_BOTTOM_SHEET
            TYPE_WIDGETS_BOTTOM_SHEET,
            TYPE_WIDGET_RESIZE_FRAME
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface FloatingViewType {}
    public static final int TYPE_FOLDER = 1 << 0;
    public static final int TYPE_POPUP_CONTAINER_WITH_ARROW = 1 << 1;
    public static final int TYPE_WIDGETS_BOTTOM_SHEET = 1 << 2;
    public static final int TYPE_WIDGET_RESIZE_FRAME = 1 << 3;

    protected boolean mIsOpen;

@@ -72,21 +76,7 @@ public abstract class AbstractFloatingView extends LinearLayout {

    protected abstract void handleClose(boolean animate);

    /**
     * If the view is current handling keyboard, return the active target, null otherwise
     */
    public ExtendedEditText getActiveTextView() {
        return null;
    }


    /**
     * Any additional view (outside of this container) where touch should be allowed while this
     * view is visible.
     */
    public View getExtendedTouchView() {
        return null;
    }
    public abstract void logActionCommand(int command);

    public final boolean isOpen() {
        return mIsOpen;
@@ -97,6 +87,16 @@ public abstract class AbstractFloatingView extends LinearLayout {

    protected abstract boolean isOfType(@FloatingViewType int type);

    public void onBackPressed() {
        logActionCommand(Action.Command.BACK);
        close(true);
    }

    @Override
    public boolean onControllerTouchEvent(MotionEvent ev) {
        return false;
    }

    protected static <T extends AbstractFloatingView> T getOpenView(
            Launcher launcher, @FloatingViewType int type) {
        DragLayer dragLayer = launcher.getDragLayer();
@@ -139,8 +139,6 @@ public abstract class AbstractFloatingView extends LinearLayout {

    public static AbstractFloatingView getTopOpenView(Launcher launcher) {
        return getOpenView(launcher, TYPE_FOLDER | TYPE_POPUP_CONTAINER_WITH_ARROW
                | TYPE_WIDGETS_BOTTOM_SHEET);
                | TYPE_WIDGETS_BOTTOM_SHEET | TYPE_WIDGET_RESIZE_FRAME);
    }

    public abstract int getLogContainerType();
}
+38 −8
Original line number Diff line number Diff line
@@ -14,15 +14,13 @@ import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.view.ViewGroup;

import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.util.FocusLogic;
import com.android.launcher3.util.TouchController;

public class AppWidgetResizeFrame extends FrameLayout
        implements View.OnKeyListener, TouchController {
public class AppWidgetResizeFrame extends AbstractFloatingView implements View.OnKeyListener {
    private static final int SNAP_DURATION = 150;
    private static final float DIMMED_HANDLE_ALPHA = 0f;
    private static final float RESIZE_THRESHOLD = 0.66f;
@@ -108,12 +106,28 @@ public class AppWidgetResizeFrame extends FrameLayout
    protected void onFinishInflate() {
        super.onFinishInflate();

        ViewGroup content = (ViewGroup) getChildAt(0);
        for (int i = 0; i < HANDLE_COUNT; i ++) {
            mDragHandles[i] = getChildAt(i);
            mDragHandles[i] = content.getChildAt(i);
        }
    }

    public void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout,
    public static void showForWidget(LauncherAppWidgetHostView widget, CellLayout cellLayout) {
        Launcher launcher = Launcher.getLauncher(cellLayout.getContext());
        AbstractFloatingView.closeAllOpenViews(launcher);

        DragLayer dl = launcher.getDragLayer();
        AppWidgetResizeFrame frame = (AppWidgetResizeFrame) launcher.getLayoutInflater()
                .inflate(R.layout.app_widget_resize_frame, dl, false);
        frame.setupForWidget(widget, cellLayout, dl);
        ((DragLayer.LayoutParams) frame.getLayoutParams()).customPosition = true;

        dl.addView(frame);
        frame.mIsOpen = true;
        frame.snapToWidget(false);
    }

    private void setupForWidget(LauncherAppWidgetHostView widgetView, CellLayout cellLayout,
            DragLayer dragLayer) {
        mCellLayout = cellLayout;
        mWidgetView = widgetView;
@@ -384,7 +398,7 @@ public class AppWidgetResizeFrame extends FrameLayout
        out.bottom = out.top + height;
    }

    public void snapToWidget(boolean animate) {
    private void snapToWidget(boolean animate) {
        getSnappedRectRelativeToDragLayer(sTmpRect);
        int newWidth = sTmpRect.width();
        int newHeight = sTmpRect.height();
@@ -448,7 +462,7 @@ public class AppWidgetResizeFrame extends FrameLayout
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // Clear the frame and give focus to the widget host view when a directional key is pressed.
        if (FocusLogic.shouldConsume(keyCode)) {
            mDragLayer.clearResizeFrame();
            close(false);
            mWidgetView.requestFocus();
            return true;
        }
@@ -498,9 +512,25 @@ public class AppWidgetResizeFrame extends FrameLayout
        if (ev.getAction() == MotionEvent.ACTION_DOWN && handleTouchDown(ev)) {
            return true;
        }
        close(false);
        return false;
    }

    @Override
    protected void handleClose(boolean animate) {
        mDragLayer.removeView(this);
    }

    @Override
    public void logActionCommand(int command) {
        // TODO: Log this case.
    }

    @Override
    protected boolean isOfType(int type) {
        return (type & TYPE_WIDGET_RESIZE_FRAME) != 0;
    }

    /**
     * A mutable class for describing the range of two int values.
     */
+3 −30
Original line number Diff line number Diff line
@@ -1091,9 +1091,6 @@ public class Launcher extends BaseActivity
                // Close any open floating view
                AbstractFloatingView.closeAllOpenViews(this);

                // Stop resizing any widgets
                mWorkspace.exitWidgetResizeMode();

                // Show the overview mode if we are on the workspace
                if (mState == State.WORKSPACE && !mWorkspace.isInOverviewMode() &&
                        !mWorkspace.isSwitchingState()) {
@@ -1411,8 +1408,6 @@ public class Launcher extends BaseActivity
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                mDragLayer.clearResizeFrame();

                // Reset AllApps to its initial state only if we are not in the middle of
                // processing a multi-step drop
                if (mAppsView != null && mWidgetsView != null && mPendingRequestArgs == null) {
@@ -1574,17 +1569,9 @@ public class Launcher extends BaseActivity
            // Note: There should be at most one log per method call. This is enforced implicitly
            // by using if-else statements.
            UserEventDispatcher ued = getUserEventDispatcher();

            // TODO: Log this case.
            mWorkspace.exitWidgetResizeMode();

            AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this);
            if (topOpenView instanceof PopupContainerWithArrow) {
                ued.logActionCommand(Action.Command.HOME_INTENT,
                        topOpenView.getExtendedTouchView(), ContainerType.DEEPSHORTCUTS);
            } else if (topOpenView instanceof Folder) {
                ued.logActionCommand(Action.Command.HOME_INTENT,
                            ((Folder) topOpenView).getFolderIcon(), ContainerType.FOLDER);
            if (topOpenView != null) {
                topOpenView.logActionCommand(Action.Command.HOME_INTENT);
            } else if (alreadyOnHome) {
                ued.logActionCommand(Action.Command.HOME_INTENT,
                        mWorkspace.getState().containerType, mWorkspace.getCurrentPage());
@@ -2062,18 +2049,7 @@ public class Launcher extends BaseActivity
        UserEventDispatcher ued = getUserEventDispatcher();
        AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this);
        if (topView != null) {
            if (topView.getActiveTextView() != null) {
                topView.getActiveTextView().dispatchBackKey();
            } else {
                if (topView instanceof PopupContainerWithArrow) {
                    ued.logActionCommand(Action.Command.BACK,
                            topView.getExtendedTouchView(), ContainerType.DEEPSHORTCUTS);
                } else if (topView instanceof Folder) {
                    ued.logActionCommand(Action.Command.BACK,
                            ((Folder) topView).getFolderIcon(), ContainerType.FOLDER);
                }
                topView.close(true);
            }
            topView.onBackPressed();
        } else if (isAppsViewVisible()) {
            ued.logActionCommand(Action.Command.BACK, ContainerType.ALLAPPS);
            showWorkspace(true);
@@ -2084,9 +2060,6 @@ public class Launcher extends BaseActivity
            ued.logActionCommand(Action.Command.BACK, ContainerType.OVERVIEW);
            showWorkspace(true);
        } else {
            // TODO: Log this case.
            mWorkspace.exitWidgetResizeMode();

            // Back button is a no-op here, but give at least some feedback for the button press
            mWorkspace.showOutlinesTemporarily();
        }
+1 −7
Original line number Diff line number Diff line
@@ -1593,11 +1593,6 @@ public class Workspace extends PagedView
        mOutlineProvider = outlineProvider;
    }

    public void exitWidgetResizeMode() {
        DragLayer dragLayer = mLauncher.getDragLayer();
        dragLayer.clearResizeFrame();
    }

    public void onStartReordering() {
        super.onStartReordering();
        // Reordering handles its own animations, disable the automatic ones.
@@ -2237,8 +2232,7 @@ public class Workspace extends PagedView
                            mDelayedResizeRunnable = new Runnable() {
                                public void run() {
                                    if (!isPageInTransition()) {
                                        DragLayer dragLayer = mLauncher.getDragLayer();
                                        dragLayer.addResizeFrame(hostView, cellLayout);
                                        AppWidgetResizeFrame.showForWidget(hostView, cellLayout);
                                    }
                                }
                            };
Loading