Skip to content

Commit

Permalink
Improve move vs click accuracy (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorcha committed Nov 10, 2017
1 parent 25c50b2 commit 6047c9f
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mikekorcha.mediabuttonoverlay.listeners;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
Expand All @@ -21,6 +22,7 @@ protected OnMediaButtonTouchListener(WindowManager.LayoutParams params) {
}

public boolean onTouch(View view, MotionEvent motionEvent) {
int[] coords = getCoords(motionEvent);
switch(motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
initialX = layoutParams.x;
Expand All @@ -30,20 +32,18 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
return true;

case MotionEvent.ACTION_MOVE:
if(Math.abs(motionEvent.getX()) < view.getWidth() ||
Math.abs(motionEvent.getY()) < view.getHeight()) {
if(coords[0] < initialX || coords[0] > initialX + view.getWidth()
|| coords[1] < initialY || coords[1] > initialY + view.getHeight()) {
isMoving = true;

int[] coords = getCoords(motionEvent);
onDrag(view, motionEvent, coords[0], coords[1]);
}
return true;

case MotionEvent.ACTION_UP:
if(isMoving) {
isMoving = false;

int[] coords = getCoords(motionEvent);
onDrop(view, motionEvent, coords[0], coords[1]);
}
else {
Expand Down

0 comments on commit 6047c9f

Please sign in to comment.