shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 androidx.ui.core.gesture |
| 18 | |
George Mount | 842c8c1 | 2020-01-08 16:03:42 -0800 | [diff] [blame] | 19 | import androidx.ui.unit.Duration |
| 20 | import androidx.ui.unit.dp |
| 21 | import androidx.ui.unit.milliseconds |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Modeled after Android's ViewConfiguration: |
| 25 | * https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * The time that must elapse before a tap gesture sends onTapDown, if there's |
| 30 | * any doubt that the gesture is a tap. |
| 31 | */ |
| 32 | val PressTimeout: Duration = 100.milliseconds |
| 33 | |
| 34 | /** |
| 35 | * Maximum length of time between a tap down and a tap up for the gesture to be |
Shep Shapard | ad4e815 | 2020-04-03 13:22:08 -0700 | [diff] [blame] | 36 | * considered a tap. (Currently not honored by the TapGestureFilter.) |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 37 | */ |
Shep Shapard | ad4e815 | 2020-04-03 13:22:08 -0700 | [diff] [blame] | 38 | // TODO(shepshapard): Remove this, or implement a hover-tap gesture filter which |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 39 | // uses this. |
| 40 | val HoverTapTimeout: Duration = 150.milliseconds |
| 41 | |
| 42 | /** |
| 43 | * Maximum distance between the down and up pointers for a tap. (Currently not |
Shep Shapard | ad4e815 | 2020-04-03 13:22:08 -0700 | [diff] [blame] | 44 | * honored by the [TapGestureFilter]. |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 45 | */ |
| 46 | // TODO(shepshapard): Remove this or implement it correctly. |
| 47 | val HoverTapSlop = 20.dp |
| 48 | |
| 49 | /** The time before a long press gesture attempts to win. */ |
| 50 | val LongPressTimeout: Duration = 500.milliseconds |
| 51 | |
| 52 | /** |
| 53 | * The maximum time from the start of the first tap to the start of the second |
| 54 | * tap in a double-tap gesture. |
| 55 | */ |
| 56 | // TODO(shepshapard): In Android, this is actually the time from the first's up event |
| 57 | // to the second's down event, according to the ViewConfiguration docs. |
| 58 | val DoubleTapTimeout: Duration = 300.milliseconds |
| 59 | |
| 60 | /** |
| 61 | * The minimum time from the end of the first tap to the start of the second |
| 62 | * tap in a double-tap gesture. (Currently not honored by the |
Shep Shapard | ad4e815 | 2020-04-03 13:22:08 -0700 | [diff] [blame] | 63 | * DoubleTapGestureFilter.) |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 64 | */ |
| 65 | // TODO(shepshapard): Either implement this or remove the constant. |
| 66 | val DoubleTapMinTime: Duration = 40.milliseconds |
| 67 | |
| 68 | /** |
| 69 | * The distance a touch has to travel for the framework to be confident that |
| 70 | * the gesture is a scroll gesture, or, inversely, the maximum distance that a |
| 71 | * touch can travel before the framework becomes confident that it is not a |
| 72 | * tap. |
| 73 | */ |
| 74 | // This value was empirically derived. We started at 8.0 and increased it to |
| 75 | // 18.0 after getting complaints that it was too difficult to hit targets. |
| 76 | val TouchSlop = 18.dp |
| 77 | |
| 78 | /** |
| 79 | * The maximum distance that the first touch in a double-tap gesture can travel |
| 80 | * before deciding that it is not part of a double-tap gesture. |
Shep Shapard | ad4e815 | 2020-04-03 13:22:08 -0700 | [diff] [blame] | 81 | * DoubleTapGestureFilter also restricts the second touch to this distance. |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 82 | */ |
| 83 | val DoubleTapTouchSlop = TouchSlop |
| 84 | |
| 85 | /** |
| 86 | * Distance between the initial position of the first touch and the start |
| 87 | * position of a potential second touch for the second touch to be considered |
| 88 | * the second touch of a double-tap gesture. |
| 89 | */ |
| 90 | val DoubleTapSlop = 100.dp |
| 91 | |
| 92 | /** |
| 93 | * The time for which zoom controls (e.g. in a map interface) are to be |
| 94 | * displayed on the screen, from the moment they were last requested. |
| 95 | */ |
| 96 | val ZoomControlsTimeout: Duration = 3000.milliseconds |
| 97 | |
| 98 | /** |
| 99 | * The distance a touch has to travel for the framework to be confident that |
| 100 | * the gesture is a paging gesture. (Currently not used, because paging uses a |
| 101 | * regular drag gesture, which uses kTouchSlop.) |
| 102 | */ |
Shep Shapard | ad4e815 | 2020-04-03 13:22:08 -0700 | [diff] [blame] | 103 | // TODO(shepshapard): Create variants of HorizontalDragGestureFilter et al for |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 104 | // paging, which use this constant. |
| 105 | val PagingTouchSlop = TouchSlop * 2.dp |
| 106 | |
| 107 | /** |
| 108 | * The distance a touch has to travel for the framework to be confident that |
| 109 | * the gesture is a panning gesture. |
| 110 | */ |
| 111 | val PanSlop = TouchSlop * 2.dp |
| 112 | |
| 113 | /** |
shepshapard | b14d643 | 2019-08-05 17:13:22 -0700 | [diff] [blame] | 114 | * The absolute cumulative average change in distance of all pointers from the |
| 115 | * average pointer over time that must be surpassed to indicate the user is trying to scale. |
| 116 | * |
| 117 | * For example, if [ScaleSlop] is 5 DP and 2 pointers were 1 DP away from each |
| 118 | * other and now are 11.00001 DP away from each other, the gesture will be interpreted to include |
| 119 | * scaling (both pointers are slightly more than 5 pixels away from the average of the pointers |
| 120 | * than they were). |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 121 | */ |
| 122 | val ScaleSlop = TouchSlop |
| 123 | |
| 124 | /** |
Louis Pullen-Freilich | 5da28bd | 2019-10-15 17:05:07 +0100 | [diff] [blame] | 125 | * The margin around a dialog, popup menu, or other window-like composable inside |
| 126 | * which we do not consider a tap to dismiss the composable. (Not currently used.) |
shepshapard | f8860d2 | 2019-01-31 11:09:48 -0800 | [diff] [blame] | 127 | */ |
| 128 | // TODO(shepshapard): Make ModalBarrier support this. |
| 129 | val WindowTouchSlop = 16.dp |
| 130 | |
| 131 | /** |
| 132 | * The minimum velocity for a touch to consider that touch to trigger a fling |
| 133 | * gesture. |
| 134 | */ |
| 135 | // TODO(shepshapard): Make sure nobody has their own version of this. |
| 136 | val MinFlingVelocity = 50.dp // Logical pixels / second |
| 137 | |
| 138 | /** Drag gesture fling velocities are clipped to this value. */ |
| 139 | // TODO(shepshapard): Make sure nobody has their own version of this. |
| 140 | val MaxFlingVelocity = 8000.dp // Logical pixels / second |
| 141 | |
| 142 | /** |
| 143 | * The maximum time from the start of the first tap to the start of the second |
| 144 | * tap in a jump-tap gesture. |
| 145 | */ |
| 146 | // TODO(shepshapard): Implement jump-tap gestures. |
| 147 | val JumpTapTimeout: Duration = 500.milliseconds |