java - How to determin the final position or angle of a rotated Image -


i have imageview of wheel spinning on fling. how can detect final position of wheel when rotation complete? , similar wheel of fortune wheel, result depends on wheel stopped enter image description here

is there way detect when fling/rotation finished , final angle? want associate angle 1 of 4 quadrants in circle , set result that. thanks, of code below //////////////////////////gesture detect /////////////////

private class mywheelontouchlistener implements ontouchlistener {   private double startangle;   @override  public boolean ontouch(view v, motionevent event) {       switch (event.getaction()) {           case motionevent.action_down:              rotateanim(); // test             // reset touched quadrants              (int = 0; < 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;      }      // set touched quadrant true      quadranttouched[getquadrant(event.getx() - (wheelwidth / 2), wheelheight - event.gety() - (wheelheight / 2))] = true;       wheeldetector.ontouchevent(event);       return true;  } }  /** * simple implementation of {@link simpleongesturelistener} detecting fling event. */ private class mywheelgesturedetector extends simpleongesturelistener {     private double endangle;  @override  public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) {      // quadrant of start , end of fling      int q1 = getquadrant(e1.getx() - (wheelwidth / 2), wheelheight - e1.gety() - (wheelheight / 2));      int q2 = getquadrant(e2.getx() - (wheelwidth / 2), wheelheight - e2.gety() - (wheelheight / 2));       // inversed rotations      if ((q1 == 2 && q2 == 2 && math.abs(velocityx) < math.abs(velocityy))              || (q1 == 3 && q2 == 3)              || (q1 == 1 && q2 == 3)              || (q1 == 4 && q2 == 4 && math.abs(velocityx) > math.abs(velocityy))              || ((q1 == 2 && q2 == 3) || (q1 == 3 && q2 == 2))              || ((q1 == 3 && q2 == 4) || (q1 == 4 && q2 == 3))              || (q1 == 2 && q2 == 4 && quadranttouched[3])              || (q1 == 4 && q2 == 2 && quadranttouched[3])) {           wheel.post(new flingwheelrunnable(-1 * (velocityx + velocityy)));      } else {          // normal rotation          wheel.post(new flingwheelrunnable(velocityx + velocityy));      }      endangle = getangle(e1.getx(), e2.gety());        return true;  } }  /** * {@link runnable} animating the dialer's fling. */ private class flingwheelrunnable implements runnable {   private float velocity;   public flingwheelrunnable(float velocity) {      this.velocity = velocity;  }   @override  public void run() {      if (math.abs(velocity) > 5) { // original = 5          rotatedialer(velocity / 100); // original = 75          velocity /= 1.0666f; // original = 1.0666f          wheel.getrotation()); <-- maybe this, not working??          // post instance again          wheel.post(this);      }   } }  /**  * @return angle of unit circle image view's center  */ private double getangle(double xtouch, double ytouch) {     double x = xtouch - (wheelwidth / 2d);     double y = wheelheight - ytouch - (wheelheight / 2d);      switch (getquadrant(x, y)) {         case 1:             return math.atan(y / x) * 180 / math.pi;         case 2:             return 180 - math.atan(y / x) * 180 / math.pi;         case 3:             return 180 + (-1 * math.atan(y / (x)) * 180 / math.pi);         case 4:             return 360 + math.atan(y / (x)) * 180 / math.pi;         default:             return 0;     } }  /**  * @return selected quadrant.  */ private static int getquadrant(double x, double y) {     if (x >= 0) {         return y >= 0 ? 1 : 4;     } else {         return y >= 0 ? 2 : 3;     } }   /**  * rotate wheel.  *  * @param degrees degrees, dialer should rotated.  */ private void rotatedialer(float degrees) {     matrix.postrotate(degrees, wheelwidth / 2, wheelheight / 2);     wheel.setimagematrix(matrix);     } 

i'm not sure compatible current implementation, have tried detecting color of final wheel? need load bitmapfactory:

bitmap slice = bitmapfactory.decodefile();  // go through documentation  // find easiest, you, way load 

then take out pixel:

int slicepixel = slice.getpixel(0, 0); 

and detect color:

int red = color.red(slicepixel); int blue = color.blue(slicepixel); int green = color.green(slicepixel); 

hopefully helpful.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -