diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2019-04-30 12:04:37 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2019-05-02 10:59:28 -0700 |
commit | ae6e318711239601fdd11a14c3cf8c542b808f19 (patch) | |
tree | cc648803791d551f80202267b1c05ca6f1084517 /src/com/android/launcher3/CellLayout.java | |
parent | c2803ec5b272c902b6ab314d782afe852163b4ff (diff) | |
download | android_packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.tar.gz android_packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.tar.bz2 android_packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.zip |
Initial changes to creating a fake landscape Launcher UI
Workspace and hotseat are drawn in rotated UI giving the impression that the
device is in Portrait, even though it is in landscape
Bug: 131360075
Change-Id: I29c4068af25fd4dcf7039b9a45886e864a137977
Diffstat (limited to 'src/com/android/launcher3/CellLayout.java')
-rw-r--r-- | src/com/android/launcher3/CellLayout.java | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 9d9a639d8..fe6bbc08a 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -57,12 +57,14 @@ import com.android.launcher3.anim.PropertyListBuilder; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.folder.PreviewBackground; import com.android.launcher3.graphics.DragPreviewProvider; +import com.android.launcher3.graphics.RotationMode; import com.android.launcher3.util.CellAndSpan; import com.android.launcher3.util.GridOccupancy; import com.android.launcher3.util.ParcelableSparseArray; import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import com.android.launcher3.views.ActivityContext; +import com.android.launcher3.views.Transposable; import com.android.launcher3.widget.LauncherAppWidgetHostView; import java.lang.annotation.Retention; @@ -76,7 +78,7 @@ import java.util.Stack; import androidx.annotation.IntDef; import androidx.core.view.ViewCompat; -public class CellLayout extends ViewGroup { +public class CellLayout extends ViewGroup implements Transposable { public static final int WORKSPACE_ACCESSIBILITY_DRAG = 2; public static final int FOLDER_ACCESSIBILITY_DRAG = 1; @@ -182,6 +184,7 @@ public class CellLayout extends ViewGroup { // Related to accessible drag and drop private DragAndDropAccessibilityDelegate mTouchHelper; private boolean mUseTouchHelper = false; + private RotationMode mRotationMode = RotationMode.NORMAL; public CellLayout(Context context) { this(context, null); @@ -203,7 +206,7 @@ public class CellLayout extends ViewGroup { setClipToPadding(false); mActivity = ActivityContext.lookupContext(context); - DeviceProfile grid = mActivity.getDeviceProfile(); + DeviceProfile grid = mActivity.getWallpaperDeviceProfile(); mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; @@ -317,6 +320,24 @@ public class CellLayout extends ViewGroup { } } + public void setRotationMode(RotationMode mode) { + if (mRotationMode != mode) { + mRotationMode = mode; + requestLayout(); + } + } + + @Override + public RotationMode getRotationMode() { + return mRotationMode; + } + + @Override + public void setPadding(int left, int top, int right, int bottom) { + mRotationMode.mapRect(left, top, right, bottom, mTempRect); + super.setPadding(mTempRect.left, mTempRect.top, mTempRect.right, mTempRect.bottom); + } + @Override public boolean dispatchHoverEvent(MotionEvent event) { // Always attempt to dispatch hover events to accessibility first. @@ -745,6 +766,14 @@ public class CellLayout extends ViewGroup { int heightSize = MeasureSpec.getSize(heightMeasureSpec); int childWidthSize = widthSize - (getPaddingLeft() + getPaddingRight()); int childHeightSize = heightSize - (getPaddingTop() + getPaddingBottom()); + + mShortcutsAndWidgets.setRotation(mRotationMode.surfaceRotation); + if (mRotationMode.isTransposed) { + int tmp = childWidthSize; + childWidthSize = childHeightSize; + childHeightSize = tmp; + } + if (mFixedCellWidth < 0 || mFixedCellHeight < 0) { int cw = DeviceProfile.calculateCellWidth(childWidthSize, mCountX); int ch = DeviceProfile.calculateCellHeight(childHeightSize, mCountY); @@ -787,7 +816,6 @@ public class CellLayout extends ViewGroup { int top = getPaddingTop(); int bottom = b - t - getPaddingBottom(); - mShortcutsAndWidgets.layout(left, top, right, bottom); // Expand the background drawing bounds by the padding baked into the background drawable mBackground.getPadding(mTempRect); mBackground.setBounds( @@ -795,6 +823,16 @@ public class CellLayout extends ViewGroup { top - mTempRect.top - getPaddingTop(), right + mTempRect.right + getPaddingRight(), bottom + mTempRect.bottom + getPaddingBottom()); + + if (mRotationMode.isTransposed) { + int halfW = mShortcutsAndWidgets.getMeasuredWidth() / 2; + int halfH = mShortcutsAndWidgets.getMeasuredHeight() / 2; + int cX = (left + right) / 2; + int cY = (top + bottom) / 2; + mShortcutsAndWidgets.layout(cX - halfW, cY - halfH, cX + halfW, cY + halfH); + } else { + mShortcutsAndWidgets.layout(left, top, right, bottom); + } } /** @@ -929,7 +967,7 @@ public class CellLayout extends ViewGroup { if (resize) { cellToRect(cellX, cellY, spanX, spanY, r); if (v instanceof LauncherAppWidgetHostView) { - DeviceProfile profile = mActivity.getDeviceProfile(); + DeviceProfile profile = mActivity.getWallpaperDeviceProfile(); Utilities.shrinkRect(r, profile.appWidgetScale.x, profile.appWidgetScale.y); } } else { |