Gesture Detection for Specific View - java

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...

Related

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.

Detect swipe over view

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

Google Map's callout view

For my Android App I'm using MapBox. Tapping a marker shows a calloutview in the shape of a balloon like expected. Google maps uses a different type of callout view. A view appears on the bottom and when tapped, the view scrolls over the map showing more information about the marker. Is there a specific name for this view? Or maybe a library which does the same thing? Or is it completely custom?
If so is this accomplished by adding a new fragment on top of the MapView? Any help would be much appreciated.
Added some screenshots to clarify what I mean.
Please don't mind the volume bar as it's ridiculously hard to take a screenshots without my device registering a single volume down push -_-
This is not really a view affiliated with the map, so it wouldn't be similar to a Tooltip or callout - you would listen for a touch event on a marker, and then rearrange the view surrounding the MapView, transitioning a separate detail view up and transitioning the map to a different centerpoint.

capture movements or keystrokes of a game like (Angry Bird) using touch screen of an Android

I basically need to find out if there is a way to capture movements or keystrokes of a game such as "Angry Birds" etc using the touch screen of an Android and save them to a file on the device.
I'm sure these phones have security issues and don't want native "keystroke logging", but if it's a layer that sits over the other game, it should be ok
Please let me is there any way to achieve the same. Your help would be appreciated. Thanks In Advance
You can cover the screen using a System Overlay, as shown in this answer.
However, keep in mind that either you can consume all the touch events, or you can let them through. You cannot first take the touch events, and then pass them onto the app or View below you.
Additionally, if the device has on screen system navigation buttons (home, back and recent apps) the overlay will not cover these.

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