I am quite new to Android programming. What I need to do is calculate the degrees of an arrow after it has stopped moving. I am using the following code:
public boolean onTouch(View v, MotionEvent event) {
//double xValue, yValue;
xValue = event.getX();
yValue = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// reset the touched quadrants
for (int i = 0; i < quadrantTouched.length; i++) {
quadrantTouched[i] = false;
}
allowRotating = false;
startAngle = getAngle(event.getX(), event.getY());
break;
case MotionEvent.ACTION_MOVE:
double currentAngle = getAngle(event.getX(), event.getY());
rotateDialer((float) (startAngle - currentAngle));
startAngle = currentAngle;
break;
case MotionEvent.ACTION_UP:
allowRotating = true;
break;
}
Need to be able to use xValue and yValue
private double getAngle(double xTouch, double yTouch) {
double x = xTouch - (dialerWidth / 2d);
double y = dialerHeight - yTouch - (dialerHeight / 2d);
switch (getQuadrant(x, y)) {
case 1:
return Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
case 2:
case 3:
return 180 - (Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI);
case 4:
return 360 + Math.asin(y / Math.hypot(x, y)) * 180 / Math.PI;
default:
// ignore, does not happen
return 0;
}
}
Insert xValue and yValue into getAngle()
public void run() {
//double angleValue;
setCheck(velocity);
if (Math.abs(velocity) > 5 && allowRotating) {
rotateDialer(velocity / 75);
velocity /= 1.0666F;
// post this instance again
dialer.post(this);
}else{
/*Thread myThread = new Thread(new UpdateThread());
myThread.start();*/
}
}
And call getAngle() from else inside the run() method. The problem is that the xValue and yValue only get calculated during motion events. The image keeps on spinning after the motion event is over. So I need to get the newest values from the MotionEvent when the image velocity reaches 0. Any ideas would be appreciated.