Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
287 views
Welcome To Ask or Share your Answers For Others

1 Answer

Just use a while loop to stop your iterator logic.

while (iterator.hasNext()) {
    // wait
    while (!someBooleanConditionToWaitFor) { }

    // do your other stuff
    // when you're done your other stuff, set it back to false.
    someBooleanConditionToWaitFor = false;
}

When your animation has finished, set the condition to true so that it continues. When you're at the end of that iteration, set it back to false so it waits again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...