I am trying to implement an animation of Markers on a Google Map. The issue I am running into is an Animation being started while another Animation is still happening for a specific Marker.
Is there a way to stop the iteration of a loop, and continue only when
a certain criteria is met?
Get LatLng - Start Animation - Callback Fires (Animation Finished) - Get LatLng.. Etc.
public void animateMarker(final String key, final List<LatLng> latlngList) {
Log.e(TAG, "------------- MARKER " + key + "-------------");
Handler mHandler = new Handler();
mHandler.post(new Runnable() {
final AnimateCarObj animateCarObj = animateCarObjMap.get(key);
final Marker marker = markersHashMap.get(key);
Boolean isAnimationRunning = false;
@Override
public void run() {
final Iterator<LatLng> iterator = latlngList.iterator();
while (iterator.hasNext()) {
if (!(isAnimationRunning)) {
Log.e(TAG, "START -- " + key + ": " + iterator.next().toString());
try {
isAnimationRunning = true;
LatLngInterpolator latlonInter = new LinearFixed();
latlonInter.interpolate(1, marker.getPosition(), iterator.next());
MarkerAnimation.animateMarker(new RunningCallback() {
@Override
public void onFinish() {
Log.e(TAG, "FINISH -- " + key + ": " + iterator.next().toString());
isAnimationRunning = false;
}
}, latlngList.size(), marker, iterator.next(), latlonInter);
} catch (Exception e) {
Log.e(TAG, "EXCEPTION: " + e.getMessage());
e.printStackTrace();
}
}
}
}
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…