Detect swipe over view - java

I want a view to be able to detect whether the user swipes (or rather moves his/her finger) over it: Swipes should be detected no matter whether they begin inside or outside the view, same goes for the end of the touch event.
As far as I can see, adding an OnTouchListener on the view won't work for this kind of gesture, as onTouch isn't called given that the touch event starts outside the view.
Any help on that subject is highly appreciated.

Please take a look at this question, should have the answer for you:
Detect which view your finger is sliding over in Android

Related

Gesture Detection for Specific View

Added a spaceView that doesn't cover all of the layout. And I want gesture detection work for only that view.
Couldn't do much but here is my codes:
space = findViewById(R.id.space);
this.gDetector = new GestureDetectorCompat(this, this);
gDetector.setOnDoubleTapListener(this);
The onTouchEvent in Android lets you do so. You can add whatever you want to do in that event.
As per Android Studio's official site, onTouchEvent() is described as ...
When a user places one or more fingers on the screen, this triggers the callback onTouchEvent() on the View that received the touch events. For each sequence of touch events (position, pressure, size, addition of another finger, etc.) that is ultimately identified as a gesture, onTouchEvent() is fired several times.
Here's the official link to you for further help
Hope this helps...

Touch move from one view to another in android

How can i touch move from one view(Imageview/any layout) to another without lifting the finger from the screen for triggering the touch listener of the 2nd view, just like Pinterest menu or Facebook reaction selection view?
If I've understood you correctly, it sounds like you need to implement a ViewPager component which will allow you to navigate various views seamlessly.
You can read about it here on the Android developer page: https://developer.android.com/training/animation/screen-slide.html
Hope it helps.

How to get "onTouchEnd" event in Android?

What is the name of a event that is called once he user stops touching the screen for the View object?
onTouchEvent fires with a type of ACTION_UP.
You can check here to see all available events: http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_UP
The one for you is ACTION_UP.
Hope this helps!
Update:
Moreover when you move outside the View without moving up your finger, ACTION_CANCEL is called. So you should handle both.

Scrolling a View by code

I want to programatically scroll a View. So far, I have found two possibilities :
scrollTo(x,y) : the top left hand corner of the View corresponds to the point (x,y) of what must be drawn in the View. The problem is that, after the call, it is impossible to manually scroll the View to have it displays what is above y or what is at the left of x.
setScrollY(y) : seems to be the function I'm looking for. But it is only available for API above level 14. And my application is supposed to work with API level 8.
Is there another function which could do what I want to do?
Thanks in advance for the time you will spend trying to help me.
Is your View in a ScrollView? If not, you will need to handle events yourself to manually scroll the View after you use code to set the scroll location. It sounds like you want both manual and programmatic control, so you'll need to use a scrolling container or handle touch events yourself.

How to differentiate between sliding and clicking in android?

In pure Java there is MouseInputListener which I can use to work with those 2 events.
How do I do it with Android?
If I implement both events then only one is fired (onClickListener) and not the other.
Updated:
The question is not about detecting the finger movement.
I have a View (ImageView for example). I need to detect the click on this view which is onClickListener() and finger movement on this view (i.e. press, move then release the finger).
The problem here is that only onClickListener() is called and MotionEvent handler is not caught.
I need to be able to differentiate those 2 events as the main event should be finger movement and onClickListener() should just say "Don't click this view. Spin this view."
Hopefully this is more clear.
OnClickListener and OnTouchListener kinda obstruct each other, since they both consume the MotionEvents that get caught on the View.
Basically you can write a single OnTouchListener that checks for both things. You'll get supplied with the MotionEvent as an argument. Check it's action via MotionEvent.getAction(), e.g. if it equals MotionEvent.ACTION_DOWN (the user put the finger on the display). If the user releases the finger at approx. the same position (ACTION_UP), you may want to interpret that as a click. Otherwise interpret the positions that you get with the ACTION_MOVE event as a gesture.
But the framework already has some classes that do this interpreting work for you, check out the SimpleGestureDetector class and it's SimpleOnGestureListener. That has some callbacks for common events, e.g. onSingleTapConfirmed() and onFling(). All you need to do is supply the MotionEvents from your OnTouchListener to the GestureDetector.

Categories