From eed866a9b6bf32cb81e62fc94b94cd3242895c76 Mon Sep 17 00:00:00 2001 From: yueg Date: Thu, 14 Jun 2018 15:28:12 -0700 Subject: Fix drag and drop crash. Test: manual PiperOrigin-RevId: 200629297 Change-Id: I6346fb2eb8742902949b2627a12956f0adca78ed --- .../dialer/app/list/PhoneFavoriteTileView.java | 36 ++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'java/com') diff --git a/java/com/android/dialer/app/list/PhoneFavoriteTileView.java b/java/com/android/dialer/app/list/PhoneFavoriteTileView.java index 30b8464ed..f9f8e0e5e 100644 --- a/java/com/android/dialer/app/list/PhoneFavoriteTileView.java +++ b/java/com/android/dialer/app/list/PhoneFavoriteTileView.java @@ -18,6 +18,8 @@ package com.android.dialer.app.list; import android.content.ClipData; import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Point; import android.net.Uri; import android.provider.ContactsContract.PinnedPositions; import android.text.TextUtils; @@ -77,15 +79,12 @@ public abstract class PhoneFavoriteTileView extends ContactTileView { shadowOverlay = findViewById(R.id.shadow_overlay); setOnLongClickListener( - new OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - final PhoneFavoriteTileView view = (PhoneFavoriteTileView) v; - // NOTE The drag shadow is handled in the ListView. - view.startDrag( - EMPTY_CLIP_DATA, new View.DragShadowBuilder(), DRAG_PHONE_FAVORITE_TILE, 0); - return true; - } + (v) -> { + final PhoneFavoriteTileView view = (PhoneFavoriteTileView) v; + // NOTE The drag shadow is handled in the ListView. + view.startDragAndDrop( + EMPTY_CLIP_DATA, new EmptyDragShadowBuilder(), DRAG_PHONE_FAVORITE_TILE, 0); + return true; }); } @@ -207,4 +206,23 @@ public abstract class PhoneFavoriteTileView extends ContactTileView { loader.registerListener(0, (loader1, contact) -> loader.reset()); loader.startLoading(); } + + /** + * A {@link View.DragShadowBuilder} that doesn't draw anything. An object of this class should be + * passed to {@link View#startDragAndDrop} to prevent the framework from drawing a drag shadow. + */ + public static class EmptyDragShadowBuilder extends View.DragShadowBuilder { + + @Override + public void onProvideShadowMetrics(Point size, Point touch) { + // A workaround for P+ not accepting non-positive drag shadow sizes. + size.set(1, 1); + touch.set(0, 0); + } + + @Override + public void onDrawShadow(Canvas canvas) { + // Don't draw anything + } + } } -- cgit v1.2.3