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

Commit 7738cac4 authored by Benno Lin's avatar Benno Lin
Browse files

Implemnet methods to drag a icon to given Workspace cell

The CL implements public methods to drag an Icon from AllApps to a
given cell in the workspace.

Bug: 199120092
Test: Launcher3Tests:com.android.launcher3.ui.TaplTestsLauncher3#testDragAppIconToWorkspaceCell
Test: https://android-build.googleplex.com/builds/abtd/run/L89300000953052361
Test: https://android-build.googleplex.com/builds/abtd/run/L44500000953013792
Change-Id: Ife16d1f1b55b809763dd40f5afee6711049a4729
parent 40570799
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ android_library {
        "tests/tapl/**/*.java",
        "src/com/android/launcher3/ResourceUtils.java",
        "src/com/android/launcher3/testing/TestProtocol.java",
        "src/com/android/launcher3/testing/*Request.java",
    ],
    resource_dirs: [ ],
    manifest: "tests/tapl/AndroidManifest.xml",
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.system.Os;
import android.view.View;

import androidx.annotation.Keep;
import androidx.annotation.Nullable;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
@@ -124,7 +125,7 @@ public class DebugTestInformationHandler extends TestInformationHandler {
    }

    @Override
    public Bundle call(String method, String arg) {
    public Bundle call(String method, String arg, @Nullable Bundle extras) {
        final Bundle response = new Bundle();
        switch (method) {
            case TestProtocol.REQUEST_APP_LIST_FREEZE_FLAGS: {
@@ -219,7 +220,7 @@ public class DebugTestInformationHandler extends TestInformationHandler {
            }

            default:
                return super.call(method, arg);
                return super.call(method, arg, extras);
        }
    }
}
+4 −2
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.android.launcher3.LauncherState;
import com.android.launcher3.testing.TestInformationHandler;
import com.android.launcher3.testing.TestProtocol;
@@ -21,7 +23,7 @@ public class QuickstepTestInformationHandler extends TestInformationHandler {
    }

    @Override
    public Bundle call(String method, String arg) {
    public Bundle call(String method, String arg, @Nullable Bundle extras) {
        final Bundle response = new Bundle();
        switch (method) {
            case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: {
@@ -82,7 +84,7 @@ public class QuickstepTestInformationHandler extends TestInformationHandler {
            }
        }

        return super.call(method, arg);
        return super.call(method, arg, extras);
    }

    @Override
+55 −5
Original line number Diff line number Diff line
@@ -23,16 +23,23 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.view.WindowInsets;

import androidx.annotation.Nullable;

import com.android.launcher3.CellLayout;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.util.ResourceBasedOverride;
import com.android.launcher3.widget.picker.WidgetsFullSheet;

@@ -62,12 +69,18 @@ public class TestInformationHandler implements ResourceBasedOverride {
        mLauncherAppState = LauncherAppState.getInstanceNoCreate();
    }

    public Bundle call(String method) {
        return call(method, /*arg=*/ null);
    }

    public Bundle call(String method, String arg) {
    /**
     * handle a request and return result Bundle.
     *
     * @param method request name.
     * @param arg    optional single string argument.
     * @param extra  extra request payload.
     */
    public Bundle call(String method, String arg, @Nullable Bundle extra) {
        final Bundle response = new Bundle();
        if (extra != null && extra.getClassLoader() == null) {
            extra.setClassLoader(getClass().getClassLoader());
        }
        switch (method) {
            case TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT: {
                return getLauncherUIProperty(Bundle::putInt, l -> {
@@ -163,11 +176,48 @@ public class TestInformationHandler implements ResourceBasedOverride {
                                .forceAllowRotationForTesting(Boolean.parseBoolean(arg)));
                return null;

            case TestProtocol.REQUEST_WORKSPACE_CELL_LAYOUT_SIZE:
                return getLauncherUIProperty(Bundle::putIntArray, launcher -> {
                    final Workspace workspace = launcher.getWorkspace();
                    final int screenId = workspace.getScreenIdForPageIndex(
                            workspace.getCurrentPage());
                    final CellLayout cellLayout = workspace.getScreenWithId(screenId);
                    return new int[]{cellLayout.getCountX(), cellLayout.getCountY()};
                });

            case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER:
                final WorkspaceCellCenterRequest request = extra.getParcelable(
                        TestProtocol.TEST_INFO_REQUEST_FIELD);
                return getLauncherUIProperty(Bundle::putParcelable, launcher -> {
                    final Workspace workspace = launcher.getWorkspace();
                    // TODO(b/216387249): allow caller selecting different pages.
                    CellLayout cellLayout = (CellLayout) workspace.getPageAt(
                            workspace.getCurrentPage());
                    final Rect cellRect = getDescendantRectRelativeToDragLayerForCell(launcher,
                            cellLayout, request.cellX, request.cellY, request.spanX, request.spanY);
                    return new Point(cellRect.centerX(), cellRect.centerY());
                });

            default:
                return null;
        }
    }

    private static Rect getDescendantRectRelativeToDragLayerForCell(Launcher launcher,
            CellLayout cellLayout, int cellX, int cellY, int spanX, int spanY) {
        final DragLayer dragLayer = launcher.getDragLayer();
        final Rect target = new Rect();

        cellLayout.cellToRect(cellX, cellY, spanX, spanY, target);
        int[] leftTop = {target.left, target.top};
        int[] rightBottom = {target.right, target.bottom};
        dragLayer.getDescendantCoordRelativeToSelf(cellLayout, leftTop);
        dragLayer.getDescendantCoordRelativeToSelf(cellLayout, rightBottom);

        target.set(leftTop[0], leftTop[1], rightBottom[0], rightBottom[1]);
        return target;
    }

    protected boolean isLauncherInitialized() {
        return Launcher.ACTIVITY_TRACKER.getCreatedActivity() == null
                || LauncherAppState.getInstance(mContext).getModel().isModelLoaded();
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public class TestInformationProvider extends ContentProvider {
        if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
            TestInformationHandler handler = TestInformationHandler.newInstance(getContext());
            handler.init(getContext());
            return handler.call(method, arg);
            return handler.call(method, arg, extras);
        }
        return null;
    }
Loading