@@ -38,6 +38,7 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
3838 private Handler handler ;
3939 private String tag = "AnimatedDashLine" ;
4040 private RefreshDashAndGapRunnable refreshDashAndGapRunnable ;
41+ private int animationSpeedMillseconds = 50 ;
4142
4243 @ Override
4344 protected void onCreate (Bundle savedInstanceState ) {
@@ -60,7 +61,11 @@ protected void onCreate(Bundle savedInstanceState) {
6061 public void onMapReady (MapboxMap mapboxMap ) {
6162 AnimatedDashLineActivity .this .mapboxMap = mapboxMap ;
6263 initBikePathLayer ();
63- Log .d (tag , "onMapReady: " );
64+ Log .d (tag , "onMapReady: here 1" );
65+ Runnable runnable = new RefreshDashAndGapRunnable ();
66+ Log .d (tag , "onMapReady: runnable made" );
67+ handler .postDelayed (runnable , animationSpeedMillseconds );
68+ Log .d (tag , "onMapReady: here 2" );
6469 }
6570
6671 private void initBikePathLayer () {
@@ -77,72 +82,60 @@ private void initBikePathLayer() {
7782 lineJoin (LINE_JOIN_ROUND )
7883 );
7984 mapboxMap .addLayer (animatedDashBikeLineLayer );
80- Log .d (tag , "initBikePathLayer: here" );
81- Runnable runnable = new RefreshDashAndGapRunnable (this .mapboxMap , handler );
82- Log .d (tag , "initBikePathLayer: runnable made" );
83- handler .postDelayed (runnable , 25 );
84- Log .d (tag , "initBikePathLayer: postDelayed" );
8585 } catch (MalformedURLException malformedUrlException ) {
8686 Log .d ("AnimatedDashLine" , "Check the URL: " + malformedUrlException .getMessage ());
8787 }
8888 }
8989
90- private static class RefreshDashAndGapRunnable implements Runnable {
90+ private class RefreshDashAndGapRunnable implements Runnable {
9191
9292 private float valueOne , valueTwo , valueThree , valueFour , ValueFive ;
9393 private float dashLength = 1 ;
9494 private float gapLength = 3 ;
9595
96- // We divide the animation up into 40 steps to make careful use of the finite space in
96+ // We divide the animation up into 40 totalNumberOfSteps to make careful use of the finite space in
9797 // LineAtlas
98- private float steps = 40 ;
98+ private float totalNumberOfSteps = 40 ;
9999
100- // A # of steps proportional to the dashLength are devoted to manipulating the dash
101- private float dashSteps = steps * dashLength / (gapLength + dashLength );
100+ // A # of totalNumberOfSteps proportional to the dashLength are devoted to manipulating the dash
101+ private float dashSteps = totalNumberOfSteps * dashLength / (gapLength + dashLength );
102102
103- // A # of steps proportional to the gapLength are devoted to manipulating the gap
104- private float gapSteps = steps - dashSteps ;
103+ // A # of totalNumberOfSteps proportional to the gapLength are devoted to manipulating the gap
104+ private float gapSteps = totalNumberOfSteps - dashSteps ;
105105
106- // The current step #
107- private int step = 0 ;
106+ // The current currentStep #
107+ private int currentStep = 0 ;
108108
109- private MapboxMap mapboxMap ;
110- private Handler handler ;
111109 private String TAG = "AnimatedDashLine" ;
112110
113- RefreshDashAndGapRunnable (MapboxMap mapboxMap , Handler handler ) {
114- this .mapboxMap = mapboxMap ;
115- this .handler = handler ;
116- Log .d (TAG , "RefreshDashAndGapRunnable: finished" );
117-
118- }
119-
120111 @ Override
121112 public void run () {
122- Log .d (TAG , "run: " );
123- step = step + 1 ;
124- if (step >= steps ) {
125- step = 0 ;
113+ Log .d (TAG , "RefreshDashAndGapRunnable run: " );
114+ currentStep = currentStep + 1 ;
115+ if (currentStep >= totalNumberOfSteps ) {
116+ currentStep = 0 ;
126117 }
127- if (step < dashSteps ) {
128- valueOne = step / dashSteps ;
118+ if (currentStep < dashSteps ) {
119+ valueOne = currentStep / dashSteps ;
129120 valueTwo = (1 - valueOne ) * dashLength ;
130121 valueThree = gapLength ;
131122 valueFour = valueOne * dashLength ;
132123 ValueFive = 0 ;
133124 } else {
134- valueOne = (step - dashSteps ) / (gapSteps );
125+ valueOne = (currentStep - dashSteps ) / (gapSteps );
135126 valueTwo = 0 ;
136127 valueThree = (1 - valueOne ) * gapLength ;
137128 valueFour = dashLength ;
138129 ValueFive = valueOne * gapLength ;
139130 }
140- Log .d (TAG , "run: here" );
131+ Log .d (TAG , "RefreshDashAndGapRunnable run: here" );
132+
133+ Float [] newFloatArray = new Float [] {valueTwo , valueThree , valueFour , ValueFive };
134+
141135 mapboxMap .getLayer ("animated_line_layer_id" ).setProperties (
142- lineDasharray (new Float [] {valueTwo , valueThree , valueFour , ValueFive })
143- );
144- Log .d (TAG , "run: layer done being gotten" );
145- handler .postDelayed (this , 25 );
136+ lineDasharray (newFloatArray ));
137+ Log .d (TAG , "RefreshDashAndGapRunnable run: layer done being gotten" );
138+ handler .postDelayed (this , animationSpeedMillseconds );
146139 }
147140 }
148141
0 commit comments