How to flick an object - android

Is there documentation or an API that allows for an object to be flicked in a certain direction, such as a button? I've tried using 'drag & drop' to try and emulate this feature but not with the same results.
Here is an example: http://youtu.be/J-83lssy5kA?t=1m47s
Basically, you can see the guy flick the chat-head towards the close icon to close the chat. The same features are found in android launchers where you can flick to remove an icon fromthe home screen. Are those gestures custom built or is it an API, thanks.

The flick that you are talking about is called fling officially. Yes, you can handle fling events using the Android API by having your activity implement the GestureDetector.OnGestureListener interface. This interface will let you handle all the common gestures like scroll, long press, fling and so on. In your case, the onFling() method will be called.
However, in your case you only want the fling gesture in which case you will have to subclass GestureDetector.SimpleOnGestureListener and override methods selectively.
For more, please refer the docs: http://developer.android.com/training/gestures/detector.html

Yes I noticed this.
I recently tried to find a coding for the same but never could and lost interest. But this is what I feel is the solution:-
In a quick time interval find 2 points cordinates of that flicking action( drag)
Then project a third point according to the slope of this line equation.
Keep updating the position of the view you flicked while you make it travel slowly from point2 to projected point3 via may be a slow loop or timer
For slope you have
(y1-y2)/(x1-x2)

Related

swipe gesture! android in lazy swipe app

the lazy swipe app opens when user swipes from bottom left corner of the screen diagonally. how is this done? how lazy swipe app is only seen as an arc, and not on the whole screen? I want to make an app like that? please tell me how should I start to make that kind of swipe gesture?
I donw know the app, but there are serval ways to do that.
basically you have to override onInterceptTouchEvent() and onTouchEvent() for your View
or
you can override Activity.onTouchEvent() to let the activity intercept all touch events.
Have a look here:
https://developer.android.com/training/gestures/viewgroup.html
Update:
After reviewing LazySwipe: Lazy Swipe is using the same mechanism / android api as Facebook chats heads. It's not an activity. Basically its a Service. Here is a discussion and implementation. There are also libraries on Github (I have never used that one).
But as you see it's not an Activiy, hence you can not use Activity.onTouch(). However, you can display and interact any regular View or ViewGroup. Therefore, overriding ViewGoroup.onInterceptTouchEvent() and ViewGorup.onTouchEvent() is possible. So yes, you can detect Swipe gestures.
There are alredy some gesture detectors build in on Android that you can use. Have a look here: https://developer.android.com/training/gestures/scroll.html

Slide remove view Gmail-like for API 7+

I don't want to reinvent the wheel and this has been obviously already been done by Google in the Gmail app. I want to achieve effect identical to the finger slide message remove from gmail. It's also achieved in notofication bar in (you can remove notification by sliding it left or right)
I was wondering if I could get pointed in the right direction. Maybe this is described somewhere in google developers site.
What's most important I need it for API 7+.
You'll have to implement two different principles:
is the capture all the motion events to translate your view with the finger
use a Gesture Detector to detect the onFling(), check if the fling is in the right direction, and if yes, apply whatever action you need.
Unfortunately I've never implemented such, so I can't show you any code. But hopefully that points you to the right direction.

Multi-touch two fingers taps

I have to implement a two fingers tap.
For example I have a listView with multiple items, which already have a click listener for each row and touch listener. Now I have to do something if the user put two fingers on a row.
How can I do this?
Any suggestion is appreciated.
I believe just the gesture API only support single touch.
You basically have to override `onTouchEvent, and play with e.getPointerCount() and check the time between the ACTION_POINTER_DOWN and ACTION_POINTER_UP. You will probably also think about the case where the two touches actually do not come at the exact same time or leave the screen at the exact same time either.
Try this
Android multi-touch support
Or
http://www.rbgrn.net/content/367-source-code-to-multitouch-visible-test
android imageView: setting drag and pinch zoom parameters
This may help you.
Not sure what you mean by 2 fingers tap. If you mean a double tap (one finger, 2 taps) , I recommend this:
http://mobile.tutsplus.com/tutorials/android/android-gesture/
But if you are referring to 2 different fingers tapping once, would not recommend doing that a 2 finger tap because it goes against the Android design guidelines. If anything it is recommended to do a long press, which can easily be implemented overriding the onLongClick() method.
But if you really do not want to listen to me because you think I am stupid. You would essentially need to implement your own multi touch gesture. Here is one example:
http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2-part-2-building-the-touch-example/1763
FYI, please be aware of what android version you want to support.

Touch more one button at once

Hello i make appliction like Drum Studio. I need make support for touch more one button at once. For example: User touch button1(AND HOLD IT!) it play sound, but user still hold its, user click another button and it play sound too. How make it programmatically? By default onTouch or onClick use, if 1 button pressed, another buttons not react before button isn't released.
Use the onKeyDown() events to trigger each response and onKeyUp() events to finish them.
http://developer.android.com/reference/android/view/KeyEvent.html
http://developer.android.com/reference/android/view/KeyEvent.Callback.html
For touchs, you can use the OnTouchListener
http://developer.android.com/reference/android/view/View.OnTouchListener.html
and determine the kind of touch by the MotionEvent:
http://developer.android.com/reference/android/view/MotionEvent.html
To clarify my response: To make a sound while holding one button, you can start the sound when the ACTION_DOWN action in the MotionEvent event is triggered and stop it with the ACTION_UP action of the same event.
Create a class extending View where you're holding all your buttons.
Override the onTouchEvent vor that class.
Switch between the different actions.
Use event.getX() and event.getY() to figure out where the touch event was originated.
Check which button is located at that position
Play the sound accordingly.
You cannot touch two separate Views at the same time, even if multi-touch is supported on your device. If you touch Button1 first, all subsequent MotionEvents (including ones with separate pointer IDs) are bound to that View.
Unless you're using a dedicated game engine like AndEngine that has this sort of functionality built in, your only option is to capture all the MotionEvents yourself (most easily with an empty ImageView covering your entire screen) and route them to the appropriate Views based on their screen coordinates. This can get tricky, especially with multiple touch pointers, but the Android UI framework does not natively support the kind of multi-touch you require.
You definitely want to be using Android 2.0 or higher - previous versions don't support multitouch.
Check the pid in your onTouch - 0 is a single touch, 1 is the second.

How to implement SimpleOnGestureListener in Activity

This is primarily a design question. I've implemented SimpleOnGestureListener on an ItemizedOverlay because I wanted to catch the onLongPress event as well as the onDown and onTap events. Everything is working okay but now I need to transition to a new activity on a specific onLongPress event. In this particular case an alert dialog is insufficient for my needs. Problem is transitioning from the overlay to an activity and back to the overlay. Usually, its from one activity to another and maybe back again. In addition, the code in my overlay class is getting quite long (about 450 lines) so it needs refactored and a bit more SRP. I can't see any way to attach the SimpleOnGestureListener to the Overlay from within the activity which references it, nor the MapView. Most examples I've looked at are noddy 'make a Toast' examples.
I'm not quite sure if I getting your question right, but you can have inter-view transition, e.g. with ViewFlipper or FrameLayout with a fling detector.
You can look how the stock calculator manage its transition.

Categories

Resources