There is this https://github.com/03uk/RippleDrawable
beautiful implementation to create a Ripple Effect on non L devices.
As you can see it is a Drawable that implements OnTouchListener.
The problem is that the Drawable intercepts ALL touch events, and therefore cannot be used in ListViews and similar.
How to avoid it?
I think the problem is in here https://github.com/03uk/RippleDrawable/blob/master/app/src/main/java/dreamers/graphics/RippleDrawable.java
and specifically here:
#Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
switch (action){
case MotionEvent.ACTION_DOWN:
onFingerDown(v, event.getX(), event.getY());
v.onTouchEvent(event); // Fix for views, to handle clicks
return true; // fix for scroll, when ACTION_UP & ACTION_CANCEL not come
case MotionEvent.ACTION_MOVE:
onFingerMove(event.getX(), event.getY());
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
onFingerUp();
break;
}
return false;
}
Related
As per android MotionEvent documents: A change has happened during a press gesture (between ACTION_DOWN and ACTION_UP). The motion contains the most recent point, as well as any intermediate points since the last down or move event.
ACTION_MOVE Android doc
so when i apply a setOnTouchListene on my view is perfectly works, It give me ACTION_DOWN, ACTION_UP, and ACTION_MOVE
but my problem is i just want to ignore a ACTION_DOWN events exactly before ACTION_MOVE. Because ACTION_MOVE event occur only after the ACTION_DOWN event as per its documents.
my coding:
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.e("Mouse: ", "Click");
break;
case MotionEvent.ACTION_MOVE:
Log.e("Mouse: ", "Move");
break;
}
return false;
}
});
So, there is any why to ignore ACTION_DOWN event. Because user only want to move not want to click, and ACTION_MOVE is also occur ACTION_DOWN before it execute it self.
Thanks...
According to your comment - you can play with counter. For example:
private static int counter = 0;
...
button.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
Log.e("Mouse: ", "Click");
break;
case MotionEvent.ACTION_MOVE:
counter++; //check how long the button is pressed
if(counter>10){
Log.e("Mouse: ", "Move");
}
break;
case MotionEvent.ACTION_UP:
if(counter<10){
//this is just onClick, handle it(10 is example, try different numbers)
}else{
//it's a move
}
counter = 0;
break;
}
return false;
}
});
Im using view.startDrag() to start dragging operation. While dragging, events are received in OnDragListener. Also im using DragShadowBuilder to show the last image of View B while dragging.
Is there a way to stop or cancel or abort dragging from some external events or operation? for example, there are 2 view, View A and View B, i'm dragging View B over View A. While dragging, due to some external event or operation, i want to cancel dragging operations or cancel OnDragListener (without removing my finger from the view B).
Code Snippet for DragShadowBuilder:
DragShadowBuilder shadowBuilder = new DragShadowBuilder(view) {
#Override
public void onDrawShadow(Canvas canvas) {
canvas.drawBitmap(b, 0, 0, new Paint());
super.onDrawShadow(canvas);
}
};
boolean dragSuccess = false;
dragSuccess = view.startDrag(null, shadowBuilder, view, 0);
Code Snippet for OnDragListener:
private final class ViewDragListener implements OnDragListener {
#Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
log("ACTION_DRAG_STARTED");
break;
case DragEvent.ACTION_DRAG_ENTERED:
log("ACTION_DRAG_ENTERED");
break;
case DragEvent.ACTION_DRAG_EXITED:
log("ACTION_DRAG_EXITED");
case DragEvent.ACTION_DROP:
log("ACTION_DROP");
mX = (int) event.getX();
mY = (int)event.getY();
break;
case DragEvent.ACTION_DRAG_ENDED:
log("ACTION_DRAG_ENDED");
//Doing some cleanup operations.
break;
case DragEvent.ACTION_DRAG_LOCATION:
log("ACTION_DRAG_LOCATION");
break;
default:
break;
}
return true;
}
}
I couldn't find any trick for this. I tried sending a motion event of ACTION_UP and it did nothing. As long as the user's finger is held down, there's no interrupting the event hierarchy, it seems. I found nothing to help with a google search.
I just set a global and waited until the drag ended, then proceeded.
I want to get activity or any control element's touch counts.
Like Android 4.2 on nexus Developer options Enable while touching 7 times.
What is the suitable event to handle it ?
You are getting 2 count's because the touch event are called every time a touch event is snet, like tump down and tump up (for example)
#Override
public boolean onTouchEvent(MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch (action) {
case MotionEvent.ACTION_DOWN:
//add here the counter if you want when screen pressed
break;
case MotionEvent.ACTION_UP:
//add here the counter if you want when touch released
break;
default:
return super.onTouchEvent(event);
}
}
You can use a View.OnTouchListener, overriding the onTouch method :
#Override
public boolean onTouch(final View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// increment counter
break;
}
}
i'am using imageview on touch listener in this motion event not working why this happen any one have idea regarding this help me.
here is my code
img_View11.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.i("img_View11", "img_View11 _1");
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
Log.i("img_View11", "img_View11 _2");
break;
case MotionEvent.ACTION_MOVE:
Log.i("img_View11", "img_View11 _3");
break;
case MotionEvent.ACTION_UP:
Log.i("img_View11", "img_View11 _4");
break;
}
return false;
}
});
here my out put show like this img_View11_1 and two img_View11_2
Log.i("img_View11", "img_View11 _1");
Log.i("img_View11", "img_View11 _2");
Question: Why MotionEvent.ACTION_MOVE and MotionEvent.ACTION_UP not working ?
Change "return false;" to "return true;" so that it will continue to receive calls.
I'm trying to use multitouch as a method to press 2 things simultaneously.
Here's my Code:
TouchHandle.setOnTouchListener(new OnTouchListener () {
public boolean onTouch(View view, MotionEvent event) {
int actions = event.getActionMasked();
switch (actions)
{
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
SendKeyCode(Server, "keydec.down");
case MotionEvent.ACTION_POINTER_UP:
SendKeyCode(Server, "keydec.up");
case MotionEvent.ACTION_UP:
}
return true;
}
});
The problem is that when I touch the screen, the server is retrieving "keydec.down" and "keydec.up" even thought I haven't removed my finger yet from the touchscreen. So the View TouchHandle is detecting an ACTION_POINTER_DOWN and ACTION_POINTER_UP when my finger touches the screen even if I haven't pulled my finger up yet. Any thoughts?
int actions = event.getAction();
switch (actions)
{
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_POINTER_DOWN:
SendKeyCode(Server, "keydec.down");
break;
case MotionEvent.ACTION_POINTER_UP:
SendKeyCode(Server, "keydec.up");
break;
case MotionEvent.ACTION_UP:
break;
}
You should use breaks between cases. And i also think that these MotionEvent constants might work with event.getAction() try that one.