StandOut
StandOut copied to clipboard
Can not to move, when has Button onClick.
When has Button onClick, can not to move.
Hope this is not too late. The window and the view (button) you try to add click listener are not exactly the same thing. What you need to do is the pass the touch event from button to the floating window. You may also want to detect the click from touch event instead of using click listener. Check the code below.
private static final int MAX_CLICK_DURATION = 600;
private static final int MAX_CLICK_DISTANCE = 5;
private long pressStartTime;
private float pressedX;
private float pressedY;
private boolean stayedWithinClickDistance;
someView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
onTouchHandleMove(SomeWindow.DEFAULT_ID, getWindow(SomeWindow.DEFAULT_ID), view, motionEvent);
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
pressStartTime = System.currentTimeMillis();
pressedX = motionEvent.getX();
pressedY = motionEvent.getY();
stayedWithinClickDistance = true;
break;
}
case MotionEvent.ACTION_MOVE: {
if (stayedWithinClickDistance && distance(pressedX, pressedY, motionEvent.getX(), motionEvent.getY()) > MAX_CLICK_DISTANCE) {
stayedWithinClickDistance = false;
}
break;
}
case MotionEvent.ACTION_UP: {
long pressDuration = System.currentTimeMillis() - pressStartTime;
if (pressDuration < MAX_CLICK_DURATION && stayedWithinClickDistance) {
// Click event has occurred
}
}
}
return true;
}
});
private float distance(float x1, float y1, float x2, float y2) {
float dx = x1 - x2;
float dy = y1 - y2;
float distanceInPx = (float) Math.sqrt(dx * dx + dy * dy);
return pxToDp(distanceInPx);
}
private float pxToDp(float px) {
return px / getResources().getDisplayMetrics().density;
}
Although the answer a little late, but still thank you for your answer, thank you!
Although the answer a little late, but still thank you for your answer, thank you!
On Tue, May 16, 2017 at 2:16 PM, Pengcheng Yin [email protected] wrote:
Hope this is not too late. The window and the view (button) you try to add click listener are not exactly the same thing. What you need to do is the pass the touch event from button to the floating window. You may also want to detect the click from touch event instead of using click listener. Check the code below.
private static final int MAX_CLICK_DURATION = 600; private static final int MAX_CLICK_DISTANCE = 5; private long pressStartTime; private float pressedX; private float pressedY; private boolean stayedWithinClickDistance; someView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { onTouchHandleMove(SomeWindow.DEFAULT_ID, getWindow(SomeWindow.DEFAULT_ID), view, motionEvent); switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: { pressStartTime = System.currentTimeMillis(); pressedX = motionEvent.getX(); pressedY = motionEvent.getY(); stayedWithinClickDistance = true; break; } case MotionEvent.ACTION_MOVE: { if (stayedWithinClickDistance && distance(pressedX, pressedY, motionEvent.getX(), motionEvent.getY()) > MAX_CLICK_DISTANCE) { stayedWithinClickDistance = false; } break; } case MotionEvent.ACTION_UP: { long pressDuration = System.currentTimeMillis() - pressStartTime; if (pressDuration < MAX_CLICK_DURATION && stayedWithinClickDistance) { // Click event has occurred } } } return true; } }); private float distance(float x1, float y1, float x2, float y2) { float dx = x1 - x2; float dy = y1 - y2; float distanceInPx = (float) Math.sqrt(dx * dx + dy * dy); return pxToDp(distanceInPx); } private float pxToDp(float px) { return px / getResources().getDisplayMetrics().density; }
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pingpongboss/StandOut/issues/29#issuecomment-301686035, or mute the thread https://github.com/notifications/unsubscribe-auth/ACszisj7XvwXHQZUdo23bDuZho6E00-Iks5r6T9VgaJpZM4EEOgB .