Defining separate layouts for horizontal and vertical drop target bars
instead of chaning the layouts in DeviceProfile

Bug: 27721989
Change-Id: I9a22c21e643f4fd0058c9be5e9d705aaf7649204
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java
index d882683..af1ebde 100644
--- a/src/com/android/launcher3/ButtonDropTarget.java
+++ b/src/com/android/launcher3/ButtonDropTarget.java
@@ -24,11 +24,13 @@
 import android.annotation.TargetApi;
 import android.content.Context;
 import android.content.res.ColorStateList;
+import android.content.res.TypedArray;
 import android.graphics.ColorMatrix;
 import android.graphics.ColorMatrixColorFilter;
 import android.graphics.PointF;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.InsetDrawable;
 import android.os.Build;
 import android.util.AttributeSet;
 import android.view.View;
@@ -52,6 +54,8 @@
 
     private static final int DRAG_VIEW_DROP_DURATION = 285;
 
+    private final boolean mHideParentOnDisable;
+
     protected Launcher mLauncher;
     private int mBottomDragPadding;
     protected BaseDropTargetBar mDropTargetBar;
@@ -65,12 +69,9 @@
     protected ColorStateList mOriginalTextColor;
     protected Drawable mDrawable;
 
-    protected DeviceProfile mDeviceProfile;
-
     private AnimatorSet mCurrentColorAnim;
     @Thunk ColorMatrix mSrcFilter, mDstFilter, mCurrentFilter;
 
-
     public ButtonDropTarget(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
@@ -78,18 +79,17 @@
     public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         mBottomDragPadding = getResources().getDimensionPixelSize(R.dimen.drop_target_drag_padding);
+
+        TypedArray a = context.obtainStyledAttributes(attrs,
+                R.styleable.ButtonDropTarget, defStyle, 0);
+        mHideParentOnDisable = a.getBoolean(R.styleable.ButtonDropTarget_hideParentOnDisable, false);
+        a.recycle();
     }
 
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
         mOriginalTextColor = getTextColors();
-
-        // Remove the text in the Phone UI in landscape
-        mDeviceProfile = ((Launcher) getContext()).getDeviceProfile();
-        if (mDeviceProfile.isVerticalBarLayout()) {
-            setText("");
-        }
     }
 
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@@ -203,7 +203,8 @@
             mCurrentColorAnim = null;
         }
         setTextColor(mOriginalTextColor);
-        ((ViewGroup) getParent()).setVisibility(mActive ? View.VISIBLE : View.GONE);
+        (mHideParentOnDisable ? ((ViewGroup) getParent()) : this)
+                .setVisibility(mActive ? View.VISIBLE : View.GONE);
     }
 
     @Override
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index 997ded2..f24e00b 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -19,6 +19,7 @@
 import android.animation.TimeInterpolator;
 import android.content.Context;
 import android.graphics.PointF;
+import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.animation.AnimationUtils;
@@ -69,7 +70,7 @@
      * Set the drop target's text to either "Remove" or "Cancel" depending on the drag source.
      */
     public void setTextBasedOnDragSource(DragSource dragSource) {
-        if (!mDeviceProfile.isVerticalBarLayout()) {
+        if (!TextUtils.isEmpty(getText())) {
             setText(dragSource.supportsDeleteDropTarget() ? R.string.remove_drop_target_label
                     : android.R.string.cancel);
         }
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 5bfa716..7c6f39e 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -31,7 +31,6 @@
 import android.view.ViewGroup.LayoutParams;
 import android.view.ViewGroup.MarginLayoutParams;
 import android.widget.FrameLayout;
-import android.widget.LinearLayout;
 
 import com.android.launcher3.config.FeatureFlags;
 
@@ -469,7 +468,7 @@
         // Layout the search bar space
         Rect searchBarBounds = getSearchBarBounds(isLayoutRtl);
         View searchBar = launcher.getSearchDropTargetBar();
-        lp = getDropTargetBarLayoutParams(hasVerticalBarLayout, searchBar, Gravity.TOP);
+        lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams();
         lp.width = searchBarBounds.width();
         lp.height = searchBarBounds.height();
         lp.topMargin = searchBarTopExtraPaddingPx;
@@ -477,7 +476,7 @@
 
         // Layout the app info bar space
         View appInfoBar = launcher.getAppInfoDropTargetBar();
-        lp = getDropTargetBarLayoutParams(hasVerticalBarLayout, appInfoBar, Gravity.BOTTOM);
+        lp = (FrameLayout.LayoutParams) appInfoBar.getLayoutParams();
         lp.bottomMargin = hotseatBarHeightPx;
         appInfoBar.setLayoutParams(lp);
 
@@ -584,28 +583,6 @@
         }
     }
 
-    private FrameLayout.LayoutParams getDropTargetBarLayoutParams(boolean hasVerticalBarLayout,
-            View dropTargetBar, int verticalGravity) {
-        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) dropTargetBar.getLayoutParams();
-        if (hasVerticalBarLayout) {
-            // Vertical drop target bar space -- The drop target bar is fixed in the layout to be on
-            //                                   the left of the screen regardless of RTL
-            lp.gravity = Gravity.LEFT;
-            lp.width = normalSearchBarSpaceHeightPx;
-
-            LinearLayout targets = (LinearLayout) dropTargetBar.findViewById(R.id.drag_target_bar);
-            targets.setOrientation(LinearLayout.VERTICAL);
-            FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams();
-            targetsLp.gravity = verticalGravity;
-            targetsLp.height = LayoutParams.WRAP_CONTENT;
-        } else {
-            // Horizontal drop target bar space
-            lp.gravity = verticalGravity | Gravity.CENTER_HORIZONTAL;
-            lp.height = searchBarSpaceHeightPx;
-        }
-        return lp;
-    }
-
     private int getCurrentWidth() {
         return isLandscape
                 ? Math.max(widthPx, heightPx)