Android Rotate Animation -


i working on simple compass app. using rotate animation rotate image when rotate around 0 360 degrees image flips around start on @ 0 degrees. how stop image rotating backwards 0 degrees.

float[] mgravity; float[] mgeomagnetic; public void onsensorchanged(sensorevent event) {     if (event.sensor.gettype() == sensor.type_accelerometer)         mgravity = lowpass(event.values, mgravity);     if (event.sensor.gettype() == sensor.type_magnetic_field)         mgeomagnetic = lowpass(event.values, mgeomagnetic);     if (mgravity != null && mgeomagnetic != null) {         float r[] = new float[9];         float i[] = new float[9];         boolean success = sensormanager.getrotationmatrix(r, i, mgravity, mgeomagnetic);         if (success) {             float orientation[] = new float[3];             sensormanager.getorientation(r, orientation);              //convert azimuth degrees             float azimuthindegrees = (float) (math.todegrees(orientation[0])+360)%360;               //show coord name             string coordnames[] = {"n","nne", "ne","ene","e", "ese","se","sse", "s","ssw", "sw","wsw", "w","wnw", "nw","nnw", "n"};             double directionid = math.round(azimuthindegrees / 22.5);             // no of array contain 360/16=22.5             if (directionid < 0) {                 directionid = directionid + 16;                 //no. of contains in array             }             string compasloc = coordnames[(int) directionid];              tvheading.settext("heading: " + float.tostring(math.round(azimuthindegrees)) + " " + compasloc);              // create rotation animation (reverse turn degree degrees)             rotateanimation ra = new rotateanimation(                     currentdegree,                     -azimuthindegrees,                     animation.relative_to_self, 0.5f,                     animation.relative_to_self,                     0.5f);              // how long animation take place             ra.setduration(210);             // set animation after end of reservation status             ra.setfillafter(true);             // start animation             image.startanimation(ra);             currentdegree = -azimuthindegrees;         }     } } 

i test animation code static todegrees value

rotateanimation ra = new rotateanimation(     15,     -30, // static vaule     animation.relative_to_self,     0.5f,     animation.relative_to_self,     0.5f); 

and image rotate right degree, code snippet works normally. should add log debug how startanimation invoked. maybe onsensorchanged(sensorevent event) invoked again , cause image rotate backwards.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -