1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.testing.shared; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Request object for querying a workspace cell region in Rect. 24 */ 25 public class WorkspaceCellCenterRequest implements TestInformationRequest { 26 public final int cellX; 27 public final int cellY; 28 public final int spanX; 29 public final int spanY; 30 31 @Override describeContents()32 public int describeContents() { 33 return 0; 34 } 35 36 @Override writeToParcel(Parcel dest, int flags)37 public void writeToParcel(Parcel dest, int flags) { 38 dest.writeInt(cellX); 39 dest.writeInt(cellY); 40 dest.writeInt(spanX); 41 dest.writeInt(spanY); 42 } 43 44 public static final Parcelable.Creator<WorkspaceCellCenterRequest> CREATOR = 45 new Parcelable.Creator<WorkspaceCellCenterRequest>() { 46 47 @Override 48 public WorkspaceCellCenterRequest createFromParcel(Parcel source) { 49 return new WorkspaceCellCenterRequest(source); 50 } 51 52 @Override 53 public WorkspaceCellCenterRequest[] newArray(int size) { 54 return new WorkspaceCellCenterRequest[size]; 55 } 56 }; 57 WorkspaceCellCenterRequest(int cellX, int cellY, int spanX, int spanY)58 private WorkspaceCellCenterRequest(int cellX, int cellY, int spanX, int spanY) { 59 this.cellX = cellX; 60 this.cellY = cellY; 61 this.spanX = spanX; 62 this.spanY = spanY; 63 } 64 WorkspaceCellCenterRequest(Parcel in)65 private WorkspaceCellCenterRequest(Parcel in) { 66 this(in.readInt(), in.readInt(), in.readInt(), in.readInt()); 67 } 68 69 /** 70 * Create a builder for WorkspaceCellRectRequest. 71 * 72 * @return WorkspaceCellRectRequest builder. 73 */ builder()74 public static WorkspaceCellCenterRequest.Builder builder() { 75 return new WorkspaceCellCenterRequest.Builder(); 76 } 77 78 @Override getRequestName()79 public String getRequestName() { 80 return TestProtocol.REQUEST_WORKSPACE_CELL_CENTER; 81 } 82 83 /** 84 * WorkspaceCellRectRequest Builder. 85 */ 86 public static final class Builder { 87 private int mCellX; 88 private int mCellY; 89 private int mSpanX; 90 private int mSpanY; 91 Builder()92 private Builder() { 93 this.mCellX = 0; 94 this.mCellY = 0; 95 this.mSpanX = 1; 96 this.mSpanY = 1; 97 } 98 99 /** 100 * Set X coordinate of upper left corner expressed as a cell position 101 */ setCellX(int x)102 public WorkspaceCellCenterRequest.Builder setCellX(int x) { 103 this.mCellX = x; 104 return this; 105 } 106 107 /** 108 * Set Y coordinate of upper left corner expressed as a cell position 109 */ setCellY(int y)110 public WorkspaceCellCenterRequest.Builder setCellY(int y) { 111 this.mCellY = y; 112 return this; 113 } 114 115 /** 116 * Set span Width in cells 117 */ setSpanX(int x)118 public WorkspaceCellCenterRequest.Builder setSpanX(int x) { 119 this.mSpanX = x; 120 return this; 121 } 122 123 /** 124 * Set span Height in cells 125 */ setSpanY(int y)126 public WorkspaceCellCenterRequest.Builder setSpanY(int y) { 127 this.mSpanY = y; 128 return this; 129 } 130 131 /** 132 * build the WorkspaceCellRectRequest. 133 */ build()134 public WorkspaceCellCenterRequest build() { 135 return new WorkspaceCellCenterRequest(mCellX, mCellY, mSpanX, mSpanY); 136 } 137 } 138 } 139