[go: nahoru, domu]

blob: 714bd829ec045798862e069b9d78de5954aae43d [file] [log] [blame]
shepshapardf8860d22019-01-31 11:09:48 -08001/*
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
17package androidx.ui.core.gesture
18
19import androidx.ui.core.Duration
20import androidx.ui.core.dp
21import androidx.ui.core.milliseconds
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 */
32val PressTimeout: Duration = 100.milliseconds
33
34/**
35 * Maximum length of time between a tap down and a tap up for the gesture to be
36 * considered a tap. (Currently not honored by the TapGestureRecognizer.)
37 */
38// TODO(shepshapard): Remove this, or implement a hover-tap gesture recognizer which
39// uses this.
40val HoverTapTimeout: Duration = 150.milliseconds
41
42/**
43 * Maximum distance between the down and up pointers for a tap. (Currently not
44 * honored by the [TapGestureRecognizer]; [PrimaryPointerGestureRecognizer],
45 * which TapGestureRecognizer inherits from, uses [kTouchSlop].)
46 */
47// TODO(shepshapard): Remove this or implement it correctly.
48val HoverTapSlop = 20.dp
49
50/** The time before a long press gesture attempts to win. */
51val LongPressTimeout: Duration = 500.milliseconds
52
53/**
54 * The maximum time from the start of the first tap to the start of the second
55 * tap in a double-tap gesture.
56 */
57// TODO(shepshapard): In Android, this is actually the time from the first's up event
58// to the second's down event, according to the ViewConfiguration docs.
59val DoubleTapTimeout: Duration = 300.milliseconds
60
61/**
62 * The minimum time from the end of the first tap to the start of the second
63 * tap in a double-tap gesture. (Currently not honored by the
64 * DoubleTapGestureRecognizer.)
65 */
66// TODO(shepshapard): Either implement this or remove the constant.
67val DoubleTapMinTime: Duration = 40.milliseconds
68
69/**
70 * The distance a touch has to travel for the framework to be confident that
71 * the gesture is a scroll gesture, or, inversely, the maximum distance that a
72 * touch can travel before the framework becomes confident that it is not a
73 * tap.
74 */
75// This value was empirically derived. We started at 8.0 and increased it to
76// 18.0 after getting complaints that it was too difficult to hit targets.
77val TouchSlop = 18.dp
78
79/**
80 * The maximum distance that the first touch in a double-tap gesture can travel
81 * before deciding that it is not part of a double-tap gesture.
82 * DoubleTapGestureRecognizer also restricts the second touch to this distance.
83 */
84val DoubleTapTouchSlop = TouchSlop
85
86/**
87 * Distance between the initial position of the first touch and the start
88 * position of a potential second touch for the second touch to be considered
89 * the second touch of a double-tap gesture.
90 */
91val DoubleTapSlop = 100.dp
92
93/**
94 * The time for which zoom controls (e.g. in a map interface) are to be
95 * displayed on the screen, from the moment they were last requested.
96 */
97val ZoomControlsTimeout: Duration = 3000.milliseconds
98
99/**
100 * The distance a touch has to travel for the framework to be confident that
101 * the gesture is a paging gesture. (Currently not used, because paging uses a
102 * regular drag gesture, which uses kTouchSlop.)
103 */
104// TODO(shepshapard): Create variants of HorizontalDragGestureRecognizer et al for
105// paging, which use this constant.
106val PagingTouchSlop = TouchSlop * 2.dp
107
108/**
109 * The distance a touch has to travel for the framework to be confident that
110 * the gesture is a panning gesture.
111 */
112val PanSlop = TouchSlop * 2.dp
113
114/**
115 * The distance a touch has to travel for the framework to be confident that
116 * the gesture is a scale gesture.
117 */
118val ScaleSlop = TouchSlop
119
120/**
121 * The margin around a dialog, popup menu, or other window-like widget inside
122 * which we do not consider a tap to dismiss the widget. (Not currently used.)
123 */
124// TODO(shepshapard): Make ModalBarrier support this.
125val WindowTouchSlop = 16.dp
126
127/**
128 * The minimum velocity for a touch to consider that touch to trigger a fling
129 * gesture.
130 */
131// TODO(shepshapard): Make sure nobody has their own version of this.
132val MinFlingVelocity = 50.dp // Logical pixels / second
133
134/** Drag gesture fling velocities are clipped to this value. */
135// TODO(shepshapard): Make sure nobody has their own version of this.
136val MaxFlingVelocity = 8000.dp // Logical pixels / second
137
138/**
139 * The maximum time from the start of the first tap to the start of the second
140 * tap in a jump-tap gesture.
141 */
142// TODO(shepshapard): Implement jump-tap gestures.
143val JumpTapTimeout: Duration = 500.milliseconds