Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45837711 authored by James Cook's avatar James Cook
Browse files

Fix dragging between icons in the app shelf

Convert the icon margin into internal padding. This ensures
that DRAG_ENTERED events are created when the icon is visually
dragged between the icons.

Also change the drag shadow size computation to force it to be
square, because the icon ImageView is no longer square.

Bug: 22603558
Change-Id: I469df043448e562269b764245135fbf898f004ea
parent 4dc07b4d
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -19,11 +19,12 @@
    used to compute the size of the drag shadow.
-->
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="48dp"
    android:layout_width="64dp"
    android:layout_height="48dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:padding="6dp"
    android:paddingLeft="14dp"
    android:paddingRight="14dp"
    android:paddingTop="6dp"
    android:paddingBottom="6dp"
    android:layout_gravity="center"
    android:scaleType="centerInside"
    />
+7 −7
Original line number Diff line number Diff line
@@ -27,22 +27,22 @@ import android.widget.ImageView;
class AppIconDragShadowBuilder extends View.DragShadowBuilder {
    private final static int ICON_SCALE = 2;
    final Drawable mDrawable;
    final int mWidth;
    final int mHeight;
    final int mIconSize;  // Height and width in device-pixels.

    public AppIconDragShadowBuilder(ImageView icon) {
        mDrawable = icon.getDrawable();
        // The Drawable may not be the same size as the ImageView, so use the ImageView size.
        mWidth = icon.getWidth() * ICON_SCALE;
        mHeight = icon.getHeight() * ICON_SCALE;
        // The ImageView is not square because it has additional left and right padding to create
        // a wider drop target, so use the height to create a square drag shadow.
        mIconSize = icon.getHeight() * ICON_SCALE;
    }

    @Override
    public void onProvideShadowMetrics(Point size, Point touch) {
        size.set(mWidth, mHeight);
        size.set(mIconSize, mIconSize);
        // Shift the drag shadow up slightly because the apps are at the bottom edge of the
        // screen.
        touch.set(mWidth / 2, mHeight * 2 / 3);
        touch.set(mIconSize / 2, mIconSize * 2 / 3);
    }

    @Override
@@ -50,7 +50,7 @@ class AppIconDragShadowBuilder extends View.DragShadowBuilder {
        // The Drawable's native bounds may be different than the source ImageView. Force it
        // to the correct size.
        Rect oldBounds = mDrawable.copyBounds();
        mDrawable.setBounds(0, 0, mWidth, mHeight);
        mDrawable.setBounds(0, 0, mIconSize, mIconSize);
        mDrawable.draw(canvas);
        mDrawable.setBounds(oldBounds);
    }