I created a simple video recorder app (The typical Camera API and Media Recorder) that has a Draggable Floating View which in my case is a Button.
The problem is, when it's not recording, The floating button follows my finger in correct manner, however if I start the recording and try to drag the button, the view changed location , before I even drag it. Its like as if the Button flees from my finger or my finger pushes the view on touch.
My OnTouchListener Class which is from: https://stackoverflow.com/a/56920148/13196984 but just converted in java. I also tried this, but still same issue. https://stackoverflow.com/a/57957226/13196984
public class CustomTouchHelper implements View.OnTouchListener{
private int screenWidth;
private int screenHeight;
private float dX = 0f;
private float dY = 0f;
public CustomTouchHelper(int screenWidth, int screenHeight) {
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
}
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
float newX;
float newY;
switch (motionEvent.getAction()){
case MotionEvent.ACTION_DOWN:
initialX = view.getX();
initialY = view.getY();
dX = view.getX() - motionEvent.getRawX();
dY = view.getY() - motionEvent.getRawY();
System.out.println(" DOWN X " + view.getX());
System.out.println("DOWN Y " + view.getY());
break;
case MotionEvent.ACTION_MOVE:
newX = motionEvent.getRawX() + dX;
newY = motionEvent.getRawY() + dY;
System.out.println(" MOVED X " + view.getX());
System.out.println("MOVED Y " + view.getY());
if((newX <= 0) || newX >= screenWidth - view.getWidth()
|| (newY <= 0 ||
newY >= screenHeight
- view.getHeight())){
return true;
}
view.animate().x(newX).y(newY).setDuration(0).start();
break;
case ACTION_UP:
System.out.println(" UP X " + view.getX());
System.out.println("UP Y " + view.getY());
if((Math.abs(view.getX() - initialX) <=10)&& (Math.abs(view.getY() - initialY) <=10)){
view.performClick();
}
}
return true;
}
}
I tried printing out on what ACTION on TouchListener changes the view location, here's what i got
A simple click to the Floating Button when NOT recording
2020-11-20 20:43:35.806 20552-20552/com.xxxx .xxxx I/System.out: DOWN X 456.57724
2020-11-20 20:43:35.806 20552-20552/com.xxxx .xxxx I/System.out: DOWN Y 845.5596
2020-11-20 20:43:35.825 20552-20552/com.xxxx .xxxx I/System.out: MOVED X 456.57724
2020-11-20 20:43:35.825 20552-20552/com.xxxx .xxxx I/System.out: MOVED Y 845.5596
2020-11-20 20:43:35.842 20552-20552/com.xxxx .xxxx I/System.out: MOVED X 456.57724
2020-11-20 20:43:35.843 20552-20552/com.xxxx .xxxx I/System.out: MOVED Y 845.5596
2020-11-20 20:43:35.859 20552-20552/com.xxxx .xxxx I/System.out: MOVED X 456.57724
2020-11-20 20:43:35.859 20552-20552/com.xxxx .xxxx I/System.out: MOVED Y 845.5596
2020-11-20 20:43:35.876 20552-20552/com.xxxx .xxxx I/System.out: MOVED X 456.57724
2020-11-20 20:43:35.876 20552-20552/com.xxxx .xxxx I/System.out: MOVED Y 845.5596
2020-11-20 20:43:35.893 20552-20552/com.xxxx .xxxx I/System.out: MOVED X 456.57724
2020-11-20 20:43:35.893 20552-20552/com.xxxx .xxxx I/System.out: MOVED Y 845.5596
2020-11-20 20:43:35.905 20552-20552/com.xxxx .xxxx I/System.out: MOVED X 456.57724
2020-11-20 20:43:35.905 20552-20552/com.xxxx .xxxx I/System.out: MOVED Y 845.5596
2020-11-20 20:43:35.907 20552-20552/com.xxxx .xxxx I/System.out: UP X 456.57724
2020-11-20 20:43:35.907 20552-20552/com.xxxx .xxxx I/System.out: UP Y 845.5596
A simple button click DURING recording
2020-11-20 20:46:24.113 20552-20552/com.xxxx.xxxxI/System.out: DOWN X 456.57724
2020-11-20 20:46:24.113 20552-20552/com.xxxx.xxxxI/System.out: DOWN Y 845.5596
2020-11-20 20:46:24.115 20552-20552/com.xxxx.xxxxI/System.out: MOVED X 456.57724
2020-11-20 20:46:24.115 20552-20552/com.xxxx.xxxxI/System.out: MOVED Y 845.5596
2020-11-20 20:46:24.126 20552-20552/com.xxxx.xxxxI/System.out: MOVED X 456.57724
2020-11-20 20:46:24.127 20552-20552/com.xxxx.xxxxI/System.out: MOVED Y 845.5596
2020-11-20 20:46:24.142 20552-20552/com.xxxx.xxxxI/System.out: MOVED X 545.49493 ***X Changed
2020-11-20 20:46:24.142 20552-20552/com.xxxx.xxxxI/System.out: MOVED Y 921.52 ***Y Changed
2020-11-20 20:46:24.155 20552-20552/com.xxxx.xxxxI/System.out: MOVED X 545.49493
2020-11-20 20:46:24.155 20552-20552/com.xxxx.xxxxI/System.out: MOVED Y 921.52
2020-11-20 20:46:24.157 20552-20552/com.xxxx.xxxxI/System.out: UP X 545.49493
2020-11-20 20:46:24.157 20552-20552/com.xxxx.xxxxI/System.out: UP Y 921.52
Hope you can help me. :)