protected Runnable mCompassViewUpdater = new Runnable() {
@Override
public void run() {
final float MAX_ROTATE_DEGREE = 1.0f;
if (mPointer != null && !mStopDrawing) {
if (mDirection != mTargetDirection) {
/** Calculate the short routine */
float to = mTargetDirection;
if (to - mDirection > 180) {
to -= 360;
} else if (to - mDirection < -180) {
to += 360;
}
/** Limit max speed to MAX_ROTATE_DEGREE */
float distance = to - mDirection;
if (Math.abs(distance) > MAX_ROTATE_DEGREE) {
distance = distance > 0 ? MAX_ROTATE_DEGREE : (-1.0f * MAX_ROTATE_DEGREE);
}
/** Slow down if the distance is short */
mDirection = normalizeDegree(mDirection
+ ((to - mDirection)
* mInterpolator.getInterpolation(Math.abs(distance) > MAX_ROTATE_DEGREE ? 0.4f : 0.3f)));
mPointer.updateDirection(mDirection);
}
}
}
};
private float normalizeDegree(float degrees) {
return (degrees + 720) % 360;
}