summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/graphics/DragPreviewProvider.java
diff options
context:
space:
mode:
authorJon Miranda <jonmiranda@google.com>2016-12-05 12:04:44 -0800
committerJon Miranda <jonmiranda@google.com>2016-12-08 10:28:51 -0800
commitf7ff3fe58a5daea94cbb641aa09a0eb4a5d2f8c3 (patch)
treefadaef625aca638e0ce01a7b7198c5d2cb528c6a /src/com/android/launcher3/graphics/DragPreviewProvider.java
parent4633be64e863a96c63f814a2386b23b02d43910b (diff)
downloadandroid_packages_apps_Trebuchet-f7ff3fe58a5daea94cbb641aa09a0eb4a5d2f8c3.tar.gz
android_packages_apps_Trebuchet-f7ff3fe58a5daea94cbb641aa09a0eb4a5d2f8c3.tar.bz2
android_packages_apps_Trebuchet-f7ff3fe58a5daea94cbb641aa09a0eb4a5d2f8c3.zip
Scale widgets when dragging and dropping in multi-window mode.
This change mimics the non-MW mode behavior when dragging and dropping widgets by taking the app widget scale into consideration. This ensures a consistant drag and drop experience between MW mode and non-MW mode. * Uses cell data (cell height/width, spanX/Y) to get the expected widget sizes. * Scales sizes when necessary. Bug: 32176631 Change-Id: Icdaf73ecd89a30e57fe7f405292d793f2d6a3ee8
Diffstat (limited to 'src/com/android/launcher3/graphics/DragPreviewProvider.java')
-rw-r--r--src/com/android/launcher3/graphics/DragPreviewProvider.java59
1 files changed, 49 insertions, 10 deletions
diff --git a/src/com/android/launcher3/graphics/DragPreviewProvider.java b/src/com/android/launcher3/graphics/DragPreviewProvider.java
index a7d4c63a1..e205c4211 100644
--- a/src/com/android/launcher3/graphics/DragPreviewProvider.java
+++ b/src/com/android/launcher3/graphics/DragPreviewProvider.java
@@ -24,7 +24,9 @@ import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;
+import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
+import com.android.launcher3.LauncherAppWidgetHostView;
import com.android.launcher3.PreloadIconDrawable;
import com.android.launcher3.Workspace;
import com.android.launcher3.config.ProviderConfig;
@@ -100,20 +102,31 @@ public class DragPreviewProvider {
* Responsibility for the bitmap is transferred to the caller.
*/
public Bitmap createDragBitmap(Canvas canvas) {
- Bitmap b;
+ float scale = 1f;
+ int width = mView.getWidth();
+ int height = mView.getHeight();
if (mView instanceof TextView) {
Drawable d = Workspace.getTextViewIcon((TextView) mView);
Rect bounds = getDrawableBounds(d);
- b = Bitmap.createBitmap(bounds.width() + DRAG_BITMAP_PADDING,
- bounds.height() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
- } else {
- b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
- mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ARGB_8888);
+ width = bounds.width();
+ height = bounds.height();
+ } else if (mView instanceof LauncherAppWidgetHostView) {
+ DeviceProfile profile = Launcher.getLauncher(mView.getContext()).getDeviceProfile();
+ scale = Math.min(profile.appWidgetScale.x, profile.appWidgetScale.y);
+ width = (int) (mView.getWidth() * scale);
+ height = (int) (mView.getHeight() * scale);
}
+ Bitmap b = Bitmap.createBitmap(width + DRAG_BITMAP_PADDING, height + DRAG_BITMAP_PADDING,
+ Bitmap.Config.ARGB_8888);
canvas.setBitmap(b);
+
+ canvas.save();
+ canvas.scale(scale, scale);
drawDragView(canvas);
+ canvas.restore();
+
canvas.setBitmap(null);
return b;
@@ -132,12 +145,29 @@ public class DragPreviewProvider {
* Responsibility for the bitmap is transferred to the caller.
*/
public Bitmap createDragOutline(Canvas canvas) {
- final Bitmap b = Bitmap.createBitmap(mView.getWidth() + DRAG_BITMAP_PADDING,
- mView.getHeight() + DRAG_BITMAP_PADDING, Bitmap.Config.ALPHA_8);
+ float scale = 1f;
+ int width = mView.getWidth();
+ int height = mView.getHeight();
+
+ if (mView instanceof LauncherAppWidgetHostView) {
+ DeviceProfile profile = Launcher.getLauncher(mView.getContext()).getDeviceProfile();
+ scale = Math.min(profile.appWidgetScale.x, profile.appWidgetScale.y);
+ width = (int) Math.floor(mView.getWidth() * scale);
+ height = (int) Math.floor(mView.getHeight() * scale);
+ }
+
+ Bitmap b = Bitmap.createBitmap(width + DRAG_BITMAP_PADDING, height + DRAG_BITMAP_PADDING,
+ Bitmap.Config.ALPHA_8);
canvas.setBitmap(b);
+
+ canvas.save();
+ canvas.scale(scale, scale);
drawDragView(canvas);
+ canvas.restore();
+
HolographicOutlineHelper.getInstance(mView.getContext())
.applyExpensiveOutlineWithBlur(b, canvas);
+
canvas.setBitmap(null);
return b;
}
@@ -160,8 +190,17 @@ public class DragPreviewProvider {
public float getScaleAndPosition(Bitmap preview, int[] outPos) {
float scale = Launcher.getLauncher(mView.getContext())
.getDragLayer().getLocationInDragLayer(mView, outPos);
- outPos[0] = Math.round(outPos[0] - (preview.getWidth() - scale * mView.getWidth()) / 2);
- outPos[1] = Math.round(outPos[1] - (1 - scale) * preview.getHeight() / 2 - previewPadding / 2);
+ DeviceProfile profile = Launcher.getLauncher(mView.getContext()).getDeviceProfile();
+ if (mView instanceof LauncherAppWidgetHostView) {
+ // App widgets are technically scaled, but are drawn at their expected size -- so the
+ // app widget scale should not affect the scale of the preview.
+ scale /= Math.min(profile.appWidgetScale.x, profile.appWidgetScale.y);
+ }
+
+ outPos[0] = Math.round(outPos[0] -
+ (preview.getWidth() - scale * mView.getWidth() * mView.getScaleX()) / 2);
+ outPos[1] = Math.round(outPos[1] - (1 - scale) * preview.getHeight() / 2
+ - previewPadding / 2);
return scale;
}
}