Revert "Adjust edit state drop targets, workspace scaling, and m..."

Test: manual

Revert submission 17004675-edit-state

Reason for revert: b/226274309
Reverted Changes:
Ib50509b6f:Adjust edit state drop targets per device type and...
Id1817cd3c:Adjust edit state drop targets, workspace scaling,...

Change-Id: I22863d7735f49f6a040a17cf56cc66f20a3e0986
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index 73289fb..9fb14f6 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -17,6 +17,8 @@
 package com.android.launcher3;
 
 import static com.android.launcher3.ButtonDropTarget.TOOLTIP_DEFAULT;
+import static com.android.launcher3.ButtonDropTarget.TOOLTIP_LEFT;
+import static com.android.launcher3.ButtonDropTarget.TOOLTIP_RIGHT;
 import static com.android.launcher3.anim.AlphaUpdateListener.updateVisibility;
 
 import android.animation.TimeInterpolator;
@@ -39,8 +41,6 @@
 import com.android.launcher3.dragndrop.DragOptions;
 import com.android.launcher3.testing.TestProtocol;
 
-import java.util.Arrays;
-
 /*
  * The top bar containing various drop targets: Delete/App Info/Uninstall.
  */
@@ -94,28 +94,30 @@
         lp.rightMargin = insets.right;
         int tooltipLocation = TOOLTIP_DEFAULT;
 
-        int horizontalMargin;
-        if (grid.isTablet) {
-            // XXX: If the icon size changes across orientations, we will have to take
-            //      that into account here too.
-            horizontalMargin = ((grid.widthPx - 2 * grid.edgeMarginPx
-                    - (grid.inv.numColumns * grid.cellWidthPx))
-                    / (2 * (grid.inv.numColumns + 1)))
-                    + grid.edgeMarginPx;
+        if (grid.isVerticalBarLayout()) {
+            lp.width = grid.dropTargetBarSizePx;
+            lp.height = grid.availableHeightPx - 2 * grid.edgeMarginPx;
+            lp.gravity = grid.isSeascape() ? Gravity.RIGHT : Gravity.LEFT;
+            tooltipLocation = grid.isSeascape() ? TOOLTIP_LEFT : TOOLTIP_RIGHT;
         } else {
-            horizontalMargin = getContext().getResources()
-                    .getDimensionPixelSize(R.dimen.drop_target_bar_margin_horizontal);
-        }
-        lp.topMargin += grid.dropTargetBarTopMarginPx;
-        lp.bottomMargin += grid.dropTargetBarBottomMarginPx;
-        lp.width = grid.availableWidthPx - 2 * horizontalMargin;
-        if (mIsVertical) {
-            lp.leftMargin = (grid.widthPx - lp.width) / 2;
-            lp.rightMargin = (grid.widthPx - lp.width) / 2;
-        }
-        lp.height = grid.dropTargetBarSizePx;
-        lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
+            int gap;
+            if (grid.isTablet) {
+                // XXX: If the icon size changes across orientations, we will have to take
+                //      that into account here too.
+                gap = ((grid.widthPx - 2 * grid.edgeMarginPx
+                        - (grid.inv.numColumns * grid.cellWidthPx))
+                        / (2 * (grid.inv.numColumns + 1)))
+                        + grid.edgeMarginPx;
+            } else {
+                gap = getContext().getResources()
+                        .getDimensionPixelSize(R.dimen.drop_target_bar_margin_horizontal);
+            }
+            lp.width = grid.availableWidthPx - 2 * gap;
 
+            lp.topMargin += grid.edgeMarginPx;
+            lp.height = grid.dropTargetBarSizePx;
+            lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
+        }
         setLayoutParams(lp);
         for (ButtonDropTarget button : mDropTargets) {
             button.setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.dropTargetTextSizePx);
@@ -137,7 +139,19 @@
         int height = MeasureSpec.getSize(heightMeasureSpec);
 
         int visibleCount = getVisibleButtonsCount();
-        if (visibleCount > 0) {
+        if (visibleCount == 0) {
+            // do nothing
+        } else if (mIsVertical) {
+            int widthSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY);
+            int heightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
+
+            for (ButtonDropTarget button : mDropTargets) {
+                if (button.getVisibility() != GONE) {
+                    button.setTextVisible(false);
+                    button.measure(widthSpec, heightSpec);
+                }
+            }
+        } else {
             int availableWidth = width / visibleCount;
             boolean textVisible = true;
             for (ButtonDropTarget buttons : mDropTargets) {
@@ -162,91 +176,31 @@
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
         int visibleCount = getVisibleButtonsCount();
         if (visibleCount == 0) {
-            return;
-        }
+            // do nothing
+        } else if (mIsVertical) {
+            int gap = getResources().getDimensionPixelSize(R.dimen.drop_target_vertical_gap);
+            int start = gap;
+            int end;
 
-        Launcher launcher = Launcher.getLauncher(getContext());
-        Workspace workspace = launcher.getWorkspace();
-        DeviceProfile dp = launcher.getDeviceProfile();
-        int buttonHorizontalPadding = dp.dropTargetHorizontalPaddingPx;
-        int buttonVerticalPadding = dp.dropTargetVerticalPaddingPx;
-        int barCenter = (right - left) / 2;
-
-        ButtonDropTarget[] visibleButtons = Arrays.stream(mDropTargets)
-                .filter(b -> b.getVisibility() != GONE)
-                .toArray(ButtonDropTarget[]::new);
-        Arrays.stream(visibleButtons).forEach(
-                b -> b.setPadding(buttonHorizontalPadding, buttonVerticalPadding,
-                        buttonHorizontalPadding, buttonVerticalPadding));
-
-        if (visibleCount == 1) {
-            ButtonDropTarget button = visibleButtons[0];
-            button.layout(barCenter - (button.getMeasuredWidth() / 2), 0,
-                    barCenter + (button.getMeasuredWidth() / 2), button.getMeasuredHeight());
-        } else if (visibleCount == 2) {
-            int buttonGap = dp.dropTargetGapPx;
-
-            if (dp.isTwoPanels) {
-                ButtonDropTarget leftButton = visibleButtons[0];
-                leftButton.layout(barCenter - leftButton.getMeasuredWidth() - (buttonGap / 2), 0,
-                        barCenter - (buttonGap / 2), leftButton.getMeasuredHeight());
-
-                ButtonDropTarget rightButton = visibleButtons[1];
-                rightButton.layout(barCenter + (buttonGap / 2), 0,
-                        barCenter + rightButton.getMeasuredWidth() + (buttonGap / 2),
-                        rightButton.getMeasuredHeight());
-            } else if (dp.isTablet) {
-                int numberOfMargins = visibleCount - 1;
-                int buttonWidths = Arrays.stream(mDropTargets)
-                        .filter(b -> b.getVisibility() != GONE)
-                        .mapToInt(ButtonDropTarget::getMeasuredWidth)
-                        .sum();
-                int totalWidth = buttonWidths + (numberOfMargins * buttonGap);
-                int buttonsStartMargin = barCenter - (totalWidth / 2);
-
-                int start = buttonsStartMargin;
-                for (ButtonDropTarget button : visibleButtons) {
-                    int margin = (start != buttonsStartMargin) ? buttonGap : 0;
-                    button.layout(start + margin, 0, start + margin + button.getMeasuredWidth(),
-                            button.getMeasuredHeight());
-                    start += button.getMeasuredWidth() + margin;
+            for (ButtonDropTarget button : mDropTargets) {
+                if (button.getVisibility() != GONE) {
+                    end = start + button.getMeasuredHeight();
+                    button.layout(0, start, button.getMeasuredWidth(), end);
+                    start = end + gap;
                 }
-            } else if (mIsVertical) {
-                // Center buttons over workspace, not screen.
-                int verticalCenter = (workspace.getRight() - workspace.getLeft()) / 2;
-                ButtonDropTarget leftButton = visibleButtons[0];
-                leftButton.layout(verticalCenter - leftButton.getMeasuredWidth() - (buttonGap / 2),
-                        0, verticalCenter - (buttonGap / 2), leftButton.getMeasuredHeight());
+            }
+        } else {
+            int frameSize = (right - left) / visibleCount;
 
-                ButtonDropTarget rightButton = visibleButtons[1];
-                rightButton.layout(verticalCenter + (buttonGap / 2), 0,
-                        verticalCenter + rightButton.getMeasuredWidth() + (buttonGap / 2),
-                        rightButton.getMeasuredHeight());
-            } else if (dp.isPhone) {
-                // Buttons aligned to outer edges of scaled workspace.
-                float shrunkTop = dp.getWorkspaceSpringLoadShrunkTop();
-                float shrunkBottom = dp.getWorkspaceSpringLoadShrunkBottom();
-                float scale =
-                        (shrunkBottom - shrunkTop) / launcher.getWorkspace().getNormalChildHeight();
-                int workspaceWidth = (int) (launcher.getWorkspace().getNormalChildWidth() * scale);
-                int start = barCenter - (workspaceWidth / 2);
-                int end = barCenter + (workspaceWidth / 2);
-
-                ButtonDropTarget leftButton = visibleButtons[0];
-                ButtonDropTarget rightButton = visibleButtons[1];
-
-                // If the text within the buttons is too long, the buttons can overlap
-                int overlap = start + leftButton.getMeasuredWidth() + rightButton.getMeasuredWidth()
-                        - end;
-                if (overlap > 0) {
-                    start -= overlap / 2;
-                    end += overlap / 2;
+            int start = frameSize / 2;
+            int halfWidth;
+            for (ButtonDropTarget button : mDropTargets) {
+                if (button.getVisibility() != GONE) {
+                    halfWidth = button.getMeasuredWidth() / 2;
+                    button.layout(start - halfWidth, 0,
+                            start + halfWidth, button.getMeasuredHeight());
+                    start = start + frameSize;
                 }
-
-                leftButton.layout(start, 0, start + leftButton.getMeasuredWidth(),
-                        leftButton.getMeasuredHeight());
-                rightButton.layout(end - rightButton.getMeasuredWidth(), 0, end,
-                        rightButton.getMeasuredHeight());
             }
         }
     }