1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.dragndrop; 18 19 import android.graphics.Bitmap; 20 import android.graphics.Canvas; 21 import android.graphics.Color; 22 import android.graphics.Paint; 23 import android.graphics.Rect; 24 25 import com.android.launcher3.DeviceProfile; 26 import com.android.launcher3.HolographicOutlineHelper; 27 import com.android.launcher3.ItemInfo; 28 import com.android.launcher3.Launcher; 29 import com.android.launcher3.graphics.DragPreviewProvider; 30 31 /** 32 * Extension of {@link DragPreviewProvider} which provides a dummy outline when drag starts from 33 * a different window. 34 * It just draws an empty circle to a placeholder outline. 35 */ 36 public class ExternalDragPreviewProvider extends DragPreviewProvider { 37 38 private final Launcher mLauncher; 39 private final ItemInfo mAddInfo; 40 41 private final int[] mOutlineSize; 42 ExternalDragPreviewProvider(Launcher launcher, ItemInfo addInfo)43 public ExternalDragPreviewProvider(Launcher launcher, ItemInfo addInfo) { 44 super(null); 45 mLauncher = launcher; 46 mAddInfo = addInfo; 47 48 mOutlineSize = mLauncher.getWorkspace().estimateItemSize(mAddInfo, false); 49 } 50 getPreviewBounds()51 public Rect getPreviewBounds() { 52 Rect rect = new Rect(); 53 DeviceProfile dp = mLauncher.getDeviceProfile(); 54 rect.left = DRAG_BITMAP_PADDING / 2; 55 rect.top = (mOutlineSize[1] - dp.cellHeightPx) / 2; 56 rect.right = rect.left + dp.iconSizePx; 57 rect.bottom = rect.top + dp.iconSizePx; 58 return rect; 59 } 60 61 @Override createDragOutline(Canvas canvas)62 public Bitmap createDragOutline(Canvas canvas) { 63 final Bitmap b = Bitmap.createBitmap(mOutlineSize[0], mOutlineSize[1], Bitmap.Config.ALPHA_8); 64 canvas.setBitmap(b); 65 66 Paint paint = new Paint(); 67 paint.setColor(Color.WHITE); 68 paint.setStyle(Paint.Style.FILL); 69 70 // Use 0.9f times the radius for the actual circle to account for icon normalization. 71 float radius = getPreviewBounds().width() * 0.5f; 72 canvas.drawCircle(DRAG_BITMAP_PADDING / 2 + radius, 73 DRAG_BITMAP_PADDING / 2 + radius, radius * 0.9f, paint); 74 75 HolographicOutlineHelper.obtain(mLauncher).applyExpensiveOutlineWithBlur(b, canvas); 76 canvas.setBitmap(null); 77 return b; 78 } 79 } 80