In the Android Developers gesture design section, the term "swipe" is used.
In the developer section, the term "fling" is used.
Are these terms synonymous? From what I have found, I believe they are, but nowhere is it explicitly said one way or the other.
That said, if I want to implement functionality for a "swipe," should I implement onFling in GestureDetector?
Drag, swipe, or fling details
Swipe gesture activities vary based on context. The speed at which a gesture is performed is the primary distinction between Drag, Swipe, and Fling.
Drag: Fine gesture, slower, more controlled, typically has an on-screen target
Swipe: Gross gesture, faster, typically has no on-screen target
Fling: Gross gesture, with no on-screen target
Gesture velocity impacts whether the action is immediately reversible.
A swipe becomes a fling based on ending velocity and whether the affected element has crossed a threshold (or point past which an action can be undone).
A drag maintains contact with an element, so reversing the direction of the gesture will drag the element back across the threshold.
A fling moves at a faster speed and removes contact with the element while it crosses the threshold, preventing the action from being undone.
from https://www.google.com/design/spec/patterns/gestures.html
onFling() will get executed when a user makes a "fling" motion, and said motion has a velocity with it to determine the type of fling it was. However, if a user simply touches the device and moves slowly across the screen, that would not be considered a fling, but a swipe.
It comes down to what type of motion you expect the users to perform. The ideal case would be to implement the onFling() function to capture that motion, and also implement onDrag() and onDragFinished() to capture the more subtle motions that should still be considered a swipe.
Related
While I'm reading the source code of android.widget.Scoller, I found the property mMode probably has 2 available value which are SCROLL_MODE = 0; and FLING_MODE = 1; What are the differences between scroll and fling gesture? Can anyone help explain it?
"Scrolling" is a word that can take on different meanings in Android,
depending on the context.
Scrolling is the general process of moving the viewport (that is, the
'window' of content you're looking at). When scrolling is in both the
x and y axes, it's called panning. The sample application provided
with this class, InteractiveChart, illustrates two different types of
scrolling, dragging and flinging:
Dragging is the type of scrolling that occurs when a user drags her finger across the touch screen. Simple dragging is often
implemented by overriding onScroll() in GestureDetector.OnGestureListener. For more discussion of dragging,
see Dragging and Scaling.
Flinging is the type of scrolling that occurs when a user drags and lifts her finger quickly. After the user lifts her finger, you
generally want to keep scrolling (moving the viewport), but decelerate
until the viewport stops moving. Flinging can be implemented by
overriding onFling() in GestureDetector.OnGestureListener, and by
using a scroller object.
What is the difference between onScroll() and onFling() in the GestureDetector interface?
When I print out the events they are showing the exact same things. At least the last onScroll() and the onFling().
The only true difference I noticed is that onScroll() is called much more often, fling always just one time.
The difference between Scroll and fling
onFling: is that the user lifts his finger in the end of the movement (that is the reason for what onFling is called one time).
onScroll: is the general process of moving the viewport (that is, the 'window' of content you're looking at).
Understand Scrolling Terminology "Scrolling" is a word that can take on different meanings in Android, depending on the context.
Scrolling is the general process of moving the viewport (that is, the
'window' of content you're looking at). When scrolling is in both the
x and y axes, it's called panning. The sample application provided
with this class, InteractiveChart, illustrates two different types of
scrolling, dragging and flinging:
Dragging is the type of scrolling that occurs when a user drags her
finger across the touch screen. Simple dragging is often implemented
by overriding onScroll() in GestureDetector.OnGestureListener. For
more discussion of dragging, see Dragging and Scaling.
Flinging is the type of scrolling that occurs when a user drags and lifts her finger
quickly. After the user lifts her finger, you generally want to keep
scrolling (moving the viewport), but decelerate until the viewport
stops moving. Flinging can be implemented by overriding onFling() in
GestureDetector.OnGestureListener, and by using a scroller object.
The KitKat SDK supports a new type of scale gesture called quick scale. Instead of requiring two fingers to pinch zoom, the user can doubletap and swipe to scale a view. You can see this in action in the Chrome and Maps apps.
Both Chrome and Maps differentiate between a doubletap (which zooms into the relevant content area, as before) and a doubletap-swipe (which allows you to scale arbitrarily with one finger).
Under the hood, the ScaleGestureDetector uses a GestureDetector to detect doubletaps and start looking for the corresponding swipe.
My question is how to mimic Chrome and Maps, detecting both doubletaps and this doubletap-swipe gesture but not both at the same time. That is, I'd like to differentiate between a normal doubletap (no swipe) and a doubletap-swipe.
I have both a GestureDetector and a ScaleGestureDetector being fed all touch events on my view. Currently, both GestureListener.onDoubleTap() and ScaleGestureListener.onScaleBegin() fire when I do a doubletap-swipe. onDoubleTap() gets fired first, so there's no way cancel handling events in the ScaleGestureListener.
I see two possible solutions, neither of which is very clean:
Copy the ScaleGestureDetector from the Android source and add a new callback to the ScaleGestureListener interface for something like onDoubleTapConfirmed() (doubletap, no swipe).
Add a small delay to onDoubleTap() so we handle the event X milliseconds after it gets triggered. If onScaleBegin() gets fired before the delay is up, cancel handling the onDoubleTap() event and start handling the scale instead.
What's the best way to handle this?
A bit late to this party, but the quick scale is more like an unfinished double tap on which the second tap turns into a drag, something like:
tap down, tap up, tap down, move
It seems your interpretation of quick scale is:
tap down, tap up, tap down, tap up, tap down, move
Which makes your problem a lot easier if you only register a plain double tap on the second action down. When the second action up happens, you just need to figure out whether a drag has happened during the second tap cycle. In case the gesture recognizers don't work for you, you can do that manually by checking against getScaledTouchSlop.
Also, copying the ScaleGestureDetector is probably not as bad as you think - github is littered with "compat" projects that are basically backports of features in newer SDK versions.
I am an amateur (desktop) programmer but I want to get into phones. I have some ideas for apps but the touchscreen and it's inputs confuse me....
I know that touchscreens can accept multiple points of touch. For instance zooming in you take two fingers and you bring them closer.. and for zooming out you do the opposite.
Here is my problem though... I've never seen functionality with any phone app on any phone (I use windows phones and android phones) where.... the input on touch is multiple points but it doesn't begin at the same time.
For the sake of illustration I'll make an example. Suppose you have a mini browser on a phone... and it has a vertical scroll bar... and a horizontal one. What I want to do is be able to scroll down... and WHILE i am scrolling down also scroll the horizontal one so i can move the page left or right. So a few seconds after I touch the screen and begin moving the vertical scrollbar downwards or upwards... i want to use a different finger and touch the horizontal scrollbar and move it as well (at the same time).
Is this even possible? Are there certain hardware or software limitations preventing something like this?
You are mixing up gestures and touches. Gestures are touch behaviors, such as...
Two fingers placed at the same time that grow apart from each other means zoom-in.
Tap and hold means context popup.
Tap and drag equals scroll.
You can cancel these gestures when your app doesn't follow these conventions. For example, Angry birds doesn't scroll if you tap and drag on a bird, but it does if you do it elsewhere on the scene.
The default state of gestures is to not detect additional touches while you are performing a gesture. if you scroll and introduce a second finger to click on a button while still holding the scroll finger, nothing will happen. I'm not sure if you can override this behavior (and I don't think it's a good idea either).
Touches, on the other hand, allow a certain amount of simultaneous touches depending on the device. When a touch is not a gesture you can start a second or n number of touches after the first one starts.
You can try this out yourself at http://raphaeljs.com/touches.html.
Now, going back to your example: it depends on how it's implemented. If you are using the OS gestures (tap and drag anywhere) then no, you can't introduce a second finger to drag horizontally, you'd use the same finger used to scroll vertically (panning with a single finger). But, if you have actual scrollbars (like those in mouse interfaces) then yes, you can implement the kind of interface you are describing.
Yes its possible and it depends on the phone but since most android devices and all WP7 devices got multi touch it shouldn't be a problem
I am developing an Android application. I am novice in Touch enabled Android Application. I have read the article about onFling and onScroll events on:
http://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html
But I didn't get exactly what is the meaning and for what we can use onFling and onScroll events.
onScroll event is when user touches down the screen, moves finger in some direction and lift up. It is mostly used to scroll larger layouts over a smaller viewport. onFling is the same, but made faster and usually triggers an animation that keeps scrolling few moments more after finger lifted up.