DragOptions.java revision 6e74e899d314663415f54895227bb79a51fd734b
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
17package com.android.launcher3.dragndrop;
18
19import android.graphics.Point;
20
21/**
22 * Set of options to control the drag and drop behavior.
23 */
24public class DragOptions {
25
26    /** Whether or not an accessible drag operation is in progress. */
27    public boolean isAccessibleDrag = false;
28
29    /** Specifies the start location for the system DnD, null when using internal DnD */
30    public Point systemDndStartPoint = null;
31
32    /** Determines when a deferred drag should start. By default, drags aren't deferred at all. */
33    public DeferDragCondition deferDragCondition = new DeferDragCondition();
34
35    /**
36     * Specifies a condition that must be met before DragListener#onDragStart() is called.
37     * By default, there is no condition and onDragStart() is called immediately following
38     * DragController#startDrag().
39     *
40     * This condition can be overridden, and callbacks are provided for the following cases:
41     * - The drag starts, but onDragStart() is deferred (onDeferredDragStart()).
42     * - The drag ends before the condition is met (onDropBeforeDeferredDrag()).
43     * - The condition is met (onDragStart()).
44     */
45    public static class DeferDragCondition {
46        public boolean shouldStartDeferredDrag(double distanceDragged) {
47            return true;
48        }
49
50        /**
51         * The drag has started, but onDragStart() is deferred.
52         * This happens when shouldStartDeferredDrag() returns true.
53         */
54        public void onDeferredDragStart() {
55            // Do nothing.
56        }
57
58        /**
59         * User dropped before the deferred condition was met,
60         * i.e. before shouldStartDeferredDrag() returned true.
61         */
62        public void onDropBeforeDeferredDrag() {
63            // Do nothing
64        }
65
66        /** onDragStart() has been called, now we are in a normal drag. */
67        public void onDragStart() {
68            // Do nothing
69        }
70    }
71}
72