Home | History | Annotate | Download | only in dragndrop
      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 import android.support.annotation.CallSuper;
     21 import android.view.View;
     22 
     23 import com.android.launcher3.DropTarget;
     24 
     25 /**
     26  * Set of options to control the drag and drop behavior.
     27  */
     28 public class DragOptions {
     29 
     30     /** Whether or not an accessible drag operation is in progress. */
     31     public boolean isAccessibleDrag = false;
     32 
     33     /** Specifies the start location for the system DnD, null when using internal DnD */
     34     public Point systemDndStartPoint = null;
     35 
     36     /** Determines when a pre-drag should transition to a drag. By default, this is immediate. */
     37     public PreDragCondition preDragCondition = null;
     38 
     39     /**
     40      * Specifies a condition that must be met before DragListener#onDragStart() is called.
     41      * By default, there is no condition and onDragStart() is called immediately following
     42      * DragController#startDrag().
     43      *
     44      * This condition can be overridden, and callbacks are provided for the following cases:
     45      * - The pre-drag starts, but onDragStart() is deferred (onPreDragStart()).
     46      * - The pre-drag ends before the condition is met (onPreDragEnd(false)).
     47      * - The actual drag starts when the condition is met (onPreDragEnd(true)).
     48      */
     49     public interface PreDragCondition {
     50 
     51         public boolean shouldStartDrag(double distanceDragged);
     52 
     53         /**
     54          * The pre-drag has started, but onDragStart() is
     55          * deferred until shouldStartDrag() returns true.
     56          */
     57         void onPreDragStart(DropTarget.DragObject dragObject);
     58 
     59         /**
     60          * The pre-drag has ended. This gets called at the same time as onDragStart()
     61          * if the condition is met, otherwise at the same time as onDragEnd().
     62          * @param dragStarted Whether the pre-drag ended because the actual drag started.
     63          *                    This will be true if the condition was met, otherwise false.
     64          */
     65         void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted);
     66     }
     67 }
     68