private float calculateSmoothAzimuth(float newAzimuth) { // hacky version of a ringbuffer if (azimuthBuffer.size() <= bufferCounter) { azimuthBuffer.add((double) newAzimuth); } else { azimuthBuffer.set(bufferCounter, (double) newAzimuth); } bufferCounter = (bufferCounter + 1) % azimuthBufferSize; return (float) CircleUtils.getMeanAngle(azimuthBuffer); }
@Override public void onAzimuthChange(float newAzimuth) { azimuth = newAzimuth; smoothAzimuth = calculateSmoothAzimuth(newAzimuth); if (measureFragment != null) { measureFragment.rotateView(360 - (float) CircleUtils.radiansToDegree(smoothAzimuth)); } if (currentFragment == resultFragment) { resultFragment.onSmoothAzimuthChange(smoothAzimuth); } }