diff options
author | Benno Lin <bennolin@google.com> | 2021-09-03 20:18:34 +0000 |
---|---|---|
committer | Benno Lin <bennolin@google.com> | 2022-02-15 01:48:45 +0000 |
commit | 7738cac4241df65685caf19af06a90d90643f1aa (patch) | |
tree | 1f145b6d44e8751dd051b15176f3b8a1354f57fe /src | |
parent | 40570799b336560d0ec5dafbfced1ff5c24f7382 (diff) | |
download | Launcher3-7738cac4241df65685caf19af06a90d90643f1aa.tar.gz |
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
Diffstat (limited to 'src')
5 files changed, 228 insertions, 6 deletions
diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 8ebfd62b69..2eae99ae90 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -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(); diff --git a/src/com/android/launcher3/testing/TestInformationProvider.java b/src/com/android/launcher3/testing/TestInformationProvider.java index 4f2619cc84..bcc7c2de4e 100644 --- a/src/com/android/launcher3/testing/TestInformationProvider.java +++ b/src/com/android/launcher3/testing/TestInformationProvider.java @@ -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; } diff --git a/src/com/android/launcher3/testing/TestInformationRequest.java b/src/com/android/launcher3/testing/TestInformationRequest.java new file mode 100644 index 0000000000..272ae56a30 --- /dev/null +++ b/src/com/android/launcher3/testing/TestInformationRequest.java @@ -0,0 +1,29 @@ +/* + * 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.testing; + +import android.os.Parcelable; + +/** + * A Request sent to TestInformationHandler can implement this interface to carry more information. + */ +public interface TestInformationRequest extends Parcelable { + /** + * The name for handler to dispatch request. + */ + String getRequestName(); +} diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 7c6ad9fe59..5156f56b77 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -68,6 +68,7 @@ public final class TestProtocol { } } + public static final String TEST_INFO_REQUEST_FIELD = "request"; public static final String TEST_INFO_RESPONSE_FIELD = "response"; public static final String REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT = @@ -104,6 +105,10 @@ public final class TestProtocol { public static final String REQUEST_GET_ACTIVITIES_CREATED_COUNT = "get-activities-created-count"; public static final String REQUEST_GET_ACTIVITIES = "get-activities"; + + public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; + public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center"; + public static final String REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET = "get-focused-task-height-for-tablet"; public static final String REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET = diff --git a/src/com/android/launcher3/testing/WorkspaceCellCenterRequest.java b/src/com/android/launcher3/testing/WorkspaceCellCenterRequest.java new file mode 100644 index 0000000000..71ab09f3f2 --- /dev/null +++ b/src/com/android/launcher3/testing/WorkspaceCellCenterRequest.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2022 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.testing; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Request object for querying a workspace cell region in Rect. + */ +public class WorkspaceCellCenterRequest implements TestInformationRequest { + public final int cellX; + public final int cellY; + public final int spanX; + public final int spanY; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(cellX); + dest.writeInt(cellY); + dest.writeInt(spanX); + dest.writeInt(spanY); + } + + public static final Parcelable.Creator<WorkspaceCellCenterRequest> CREATOR = + new Parcelable.Creator<WorkspaceCellCenterRequest>() { + + @Override + public WorkspaceCellCenterRequest createFromParcel(Parcel source) { + return new WorkspaceCellCenterRequest(source); + } + + @Override + public WorkspaceCellCenterRequest[] newArray(int size) { + return new WorkspaceCellCenterRequest[size]; + } + }; + + private WorkspaceCellCenterRequest(int cellX, int cellY, int spanX, int spanY) { + this.cellX = cellX; + this.cellY = cellY; + this.spanX = spanX; + this.spanY = spanY; + } + + private WorkspaceCellCenterRequest(Parcel in) { + this(in.readInt(), in.readInt(), in.readInt(), in.readInt()); + } + + /** + * Create a builder for WorkspaceCellRectRequest. + * + * @return WorkspaceCellRectRequest builder. + */ + public static WorkspaceCellCenterRequest.Builder builder() { + return new WorkspaceCellCenterRequest.Builder(); + } + + @Override + public String getRequestName() { + return TestProtocol.REQUEST_WORKSPACE_CELL_CENTER; + } + + /** + * WorkspaceCellRectRequest Builder. + */ + public static final class Builder { + private int mCellX; + private int mCellY; + private int mSpanX; + private int mSpanY; + + private Builder() { + this.mCellX = 0; + this.mCellY = 0; + this.mSpanX = 1; + this.mSpanY = 1; + } + + /** + * Set X coordinate of upper left corner expressed as a cell position + */ + public WorkspaceCellCenterRequest.Builder setCellX(int x) { + this.mCellX = x; + return this; + } + + /** + * Set Y coordinate of upper left corner expressed as a cell position + */ + public WorkspaceCellCenterRequest.Builder setCellY(int y) { + this.mCellY = y; + return this; + } + + /** + * Set span Width in cells + */ + public WorkspaceCellCenterRequest.Builder setSpanX(int x) { + this.mSpanX = x; + return this; + } + + /** + * Set span Height in cells + */ + public WorkspaceCellCenterRequest.Builder setSpanY(int y) { + this.mCellY = y; + return this; + } + + /** + * build the WorkspaceCellRectRequest. + */ + public WorkspaceCellCenterRequest build() { + return new WorkspaceCellCenterRequest(mCellX, mCellY, mSpanX, mSpanY); + } + } +} |