summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/dragndrop/DragLayer.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2019-04-30 12:04:37 -0700
committerSunny Goyal <sunnygoyal@google.com>2019-05-02 10:59:28 -0700
commitae6e318711239601fdd11a14c3cf8c542b808f19 (patch)
treecc648803791d551f80202267b1c05ca6f1084517 /src/com/android/launcher3/dragndrop/DragLayer.java
parentc2803ec5b272c902b6ab314d782afe852163b4ff (diff)
downloadpackages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.tar.gz
packages_apps_Trebuchet-ae6e318711239601fdd11a14c3cf8c542b808f19.tar.bz2
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/dragndrop/DragLayer.java')
-rw-r--r--src/com/android/launcher3/dragndrop/DragLayer.java173
1 files changed, 168 insertions, 5 deletions
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 6950a1fad..8de2f57ee 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -17,6 +17,10 @@
package com.android.launcher3.dragndrop;
+import static android.view.View.MeasureSpec.EXACTLY;
+import static android.view.View.MeasureSpec.getMode;
+import static android.view.View.MeasureSpec.getSize;
+
import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustomAccessibilityEvent;
import android.animation.Animator;
@@ -29,12 +33,14 @@ import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
+import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.Interpolator;
+import android.widget.FrameLayout;
import android.widget.TextView;
import com.android.launcher3.AbstractFloatingView;
@@ -42,6 +48,7 @@ import com.android.launcher3.CellLayout;
import com.android.launcher3.DropTargetBar;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
+import com.android.launcher3.graphics.RotationMode;
import com.android.launcher3.ShortcutAndWidgetContainer;
import com.android.launcher3.Workspace;
import com.android.launcher3.anim.Interpolators;
@@ -52,6 +59,7 @@ import com.android.launcher3.keyboard.ViewGroupFocusHelper;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.views.BaseDragLayer;
+import com.android.launcher3.views.Transposable;
import java.util.ArrayList;
@@ -260,10 +268,10 @@ public class DragLayer extends BaseDragLayer<Launcher> {
Rect r = new Rect();
getViewRectRelativeToSelf(dragView, r);
- int coord[] = new int[2];
+ float coord[] = new float[2];
float childScale = child.getScaleX();
- coord[0] = lp.x + (int) (child.getMeasuredWidth() * (1 - childScale) / 2);
- coord[1] = lp.y + (int) (child.getMeasuredHeight() * (1 - childScale) / 2);
+ coord[0] = lp.x + (child.getMeasuredWidth() * (1 - childScale) / 2);
+ coord[1] = lp.y + (child.getMeasuredHeight() * (1 - childScale) / 2);
// Since the child hasn't necessarily been laid out, we force the lp to be updated with
// the correct coordinates (above) and use these to determine the final location
@@ -271,8 +279,8 @@ public class DragLayer extends BaseDragLayer<Launcher> {
// We need to account for the scale of the child itself, as the above only accounts for
// for the scale in parents.
scale *= childScale;
- int toX = coord[0];
- int toY = coord[1];
+ int toX = Math.round(coord[0]);
+ int toY = Math.round(coord[1]);
float toScale = scale;
if (child instanceof TextView) {
TextView tv = (TextView) child;
@@ -551,4 +559,159 @@ public class DragLayer extends BaseDragLayer<Launcher> {
public WorkspaceAndHotseatScrim getScrim() {
return mScrim;
}
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ RotationMode rotation = mActivity.getRotationMode();
+ int count = getChildCount();
+
+ if (!rotation.isTransposed
+ || getMode(widthMeasureSpec) != EXACTLY
+ || getMode(heightMeasureSpec) != EXACTLY) {
+
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+ child.setRotation(rotation.surfaceRotation);
+ }
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ } else {
+
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+ if (child.getVisibility() == GONE) {
+ continue;
+ }
+ if (!(child instanceof Transposable)) {
+ measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
+ } else {
+ measureChildWithMargins(child, heightMeasureSpec, 0, widthMeasureSpec, 0);
+
+ child.setPivotX(child.getMeasuredWidth() / 2);
+ child.setPivotY(child.getMeasuredHeight() / 2);
+ child.setRotation(rotation.surfaceRotation);
+ }
+ }
+ setMeasuredDimension(getSize(widthMeasureSpec), getSize(heightMeasureSpec));
+ }
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ RotationMode rotation = mActivity.getRotationMode();
+ if (!rotation.isTransposed) {
+ super.onLayout(changed, left, top, right, bottom);
+ return;
+ }
+
+ final int count = getChildCount();
+
+ final int parentWidth = right - left;
+ final int parentHeight = bottom - top;
+
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+ if (child.getVisibility() == GONE) {
+ continue;
+ }
+
+ final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
+
+ if (lp instanceof LayoutParams) {
+ final LayoutParams dlp = (LayoutParams) lp;
+ if (dlp.customPosition) {
+ child.layout(dlp.x, dlp.y, dlp.x + dlp.width, dlp.y + dlp.height);
+ continue;
+ }
+ }
+
+ final int width = child.getMeasuredWidth();
+ final int height = child.getMeasuredHeight();
+
+ int childLeft;
+ int childTop;
+
+ int gravity = lp.gravity;
+ if (gravity == -1) {
+ gravity = Gravity.TOP | Gravity.START;
+ }
+
+ final int layoutDirection = getLayoutDirection();
+
+ int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
+ int horizontalGravity = absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
+ int verticalGravity = absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK;
+
+ if (child instanceof Transposable) {
+ if (rotation == RotationMode.SEASCAPE) {
+ if (horizontalGravity == Gravity.RIGHT) {
+ horizontalGravity = Gravity.LEFT;
+ } else if (horizontalGravity == Gravity.LEFT) {
+ horizontalGravity = Gravity.RIGHT;
+ }
+
+ if (verticalGravity == Gravity.TOP) {
+ verticalGravity = Gravity.BOTTOM;
+ } else if (verticalGravity == Gravity.BOTTOM) {
+ verticalGravity = Gravity.TOP;
+ }
+ }
+
+ switch (horizontalGravity) {
+ case Gravity.CENTER_HORIZONTAL:
+ childTop = (parentHeight - height) / 2 +
+ lp.topMargin - lp.bottomMargin;
+ break;
+ case Gravity.RIGHT:
+ childTop = width / 2 + lp.rightMargin - height / 2;
+ break;
+ case Gravity.LEFT:
+ default:
+ childTop = parentHeight - lp.leftMargin - width / 2 - height / 2;
+ }
+
+ switch (verticalGravity) {
+ case Gravity.CENTER_VERTICAL:
+ childLeft = (parentWidth - width) / 2 +
+ lp.leftMargin - lp.rightMargin;
+ break;
+ case Gravity.BOTTOM:
+ childLeft = parentWidth - width / 2 - height / 2 - lp.bottomMargin;
+ break;
+ case Gravity.TOP:
+ default:
+ childLeft = height / 2 - width / 2 + lp.topMargin;
+ }
+ } else {
+ switch (horizontalGravity) {
+ case Gravity.CENTER_HORIZONTAL:
+ childLeft = (parentWidth - width) / 2 +
+ lp.leftMargin - lp.rightMargin;
+ break;
+ case Gravity.RIGHT:
+ childLeft = parentWidth - width - lp.rightMargin;
+ break;
+ case Gravity.LEFT:
+ default:
+ childLeft = lp.leftMargin;
+ }
+
+ switch (verticalGravity) {
+ case Gravity.TOP:
+ childTop = lp.topMargin;
+ break;
+ case Gravity.CENTER_VERTICAL:
+ childTop = (parentHeight - height) / 2 +
+ lp.topMargin - lp.bottomMargin;
+ break;
+ case Gravity.BOTTOM:
+ childTop = parentHeight - height - lp.bottomMargin;
+ break;
+ default:
+ childTop = lp.topMargin;
+ }
+ }
+
+ child.layout(childLeft, childTop, childLeft + width, childTop + height);
+ }
+ }
}