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.Point; 20 21 import com.android.launcher3.DropTarget; 22 23 /** 24 * Set of options to control the drag and drop behavior. 25 */ 26 public class DragOptions { 27 28 /** Whether or not an accessible drag operation is in progress. */ 29 public boolean isAccessibleDrag = false; 30 31 /** Whether or not the drag operation is controlled by keyboard. */ 32 public boolean isKeyboardDrag = false; 33 34 /** 35 * Specifies the start location for a simulated DnD (like system drag or accessibility drag), 36 * null when using internal DnD 37 */ 38 public Point simulatedDndStartPoint = null; 39 40 /** Determines when a pre-drag should transition to a drag. By default, this is immediate. */ 41 public PreDragCondition preDragCondition = null; 42 43 /** 44 * A drag scale that scales the original drag view size when the preDragCondition is met (or 45 * is ignored if preDragEndScale is 0). 46 */ 47 public float preDragEndScale; 48 49 /** Scale of the icons over the workspace icon size. */ 50 public float intrinsicIconScaleFactor = 1f; 51 52 public boolean isFlingToDelete; 53 54 /** 55 * Specifies a condition that must be met before DragListener#onDragStart() is called. 56 * By default, there is no condition and onDragStart() is called immediately following 57 * DragController#startDrag(). 58 * 59 * This condition can be overridden, and callbacks are provided for the following cases: 60 * - The pre-drag starts, but onDragStart() is deferred (onPreDragStart()). 61 * - The pre-drag ends before the condition is met (onPreDragEnd(false)). 62 * - The actual drag starts when the condition is met (onPreDragEnd(true)). 63 */ 64 public interface PreDragCondition { 65 shouldStartDrag(double distanceDragged)66 public boolean shouldStartDrag(double distanceDragged); 67 68 /** 69 * The pre-drag has started, but onDragStart() is 70 * deferred until shouldStartDrag() returns true. 71 */ onPreDragStart(DropTarget.DragObject dragObject)72 void onPreDragStart(DropTarget.DragObject dragObject); 73 74 /** 75 * The pre-drag has ended. This gets called at the same time as onDragStart() 76 * if the condition is met, otherwise at the same time as onDragEnd(). 77 * @param dragStarted Whether the pre-drag ended because the actual drag started. 78 * This will be true if the condition was met, otherwise false. 79 */ onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted)80 void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted); 81 82 /** 83 * The offset points that should be overridden to update the dragLayer. 84 */ getDragOffset()85 default Point getDragOffset() { 86 return new Point(0,0); 87 } 88 } 89 } 90