@@ -38,6 +38,7 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
38
38
private Handler handler ;
39
39
private String tag = "AnimatedDashLine" ;
40
40
private RefreshDashAndGapRunnable refreshDashAndGapRunnable ;
41
+ private int animationSpeedMillseconds = 50 ;
41
42
42
43
@ Override
43
44
protected void onCreate (Bundle savedInstanceState ) {
@@ -60,7 +61,11 @@ protected void onCreate(Bundle savedInstanceState) {
60
61
public void onMapReady (MapboxMap mapboxMap ) {
61
62
AnimatedDashLineActivity .this .mapboxMap = mapboxMap ;
62
63
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" );
64
69
}
65
70
66
71
private void initBikePathLayer () {
@@ -77,72 +82,60 @@ private void initBikePathLayer() {
77
82
lineJoin (LINE_JOIN_ROUND )
78
83
);
79
84
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" );
85
85
} catch (MalformedURLException malformedUrlException ) {
86
86
Log .d ("AnimatedDashLine" , "Check the URL: " + malformedUrlException .getMessage ());
87
87
}
88
88
}
89
89
90
- private static class RefreshDashAndGapRunnable implements Runnable {
90
+ private class RefreshDashAndGapRunnable implements Runnable {
91
91
92
92
private float valueOne , valueTwo , valueThree , valueFour , ValueFive ;
93
93
private float dashLength = 1 ;
94
94
private float gapLength = 3 ;
95
95
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
97
97
// LineAtlas
98
- private float steps = 40 ;
98
+ private float totalNumberOfSteps = 40 ;
99
99
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 );
102
102
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 ;
105
105
106
- // The current step #
107
- private int step = 0 ;
106
+ // The current currentStep #
107
+ private int currentStep = 0 ;
108
108
109
- private MapboxMap mapboxMap ;
110
- private Handler handler ;
111
109
private String TAG = "AnimatedDashLine" ;
112
110
113
- RefreshDashAndGapRunnable (MapboxMap mapboxMap , Handler handler ) {
114
- this .mapboxMap = mapboxMap ;
115
- this .handler = handler ;
116
- Log .d (TAG , "RefreshDashAndGapRunnable: finished" );
117
-
118
- }
119
-
120
111
@ Override
121
112
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 ;
126
117
}
127
- if (step < dashSteps ) {
128
- valueOne = step / dashSteps ;
118
+ if (currentStep < dashSteps ) {
119
+ valueOne = currentStep / dashSteps ;
129
120
valueTwo = (1 - valueOne ) * dashLength ;
130
121
valueThree = gapLength ;
131
122
valueFour = valueOne * dashLength ;
132
123
ValueFive = 0 ;
133
124
} else {
134
- valueOne = (step - dashSteps ) / (gapSteps );
125
+ valueOne = (currentStep - dashSteps ) / (gapSteps );
135
126
valueTwo = 0 ;
136
127
valueThree = (1 - valueOne ) * gapLength ;
137
128
valueFour = dashLength ;
138
129
ValueFive = valueOne * gapLength ;
139
130
}
140
- Log .d (TAG , "run: here" );
131
+ Log .d (TAG , "RefreshDashAndGapRunnable run: here" );
132
+
133
+ Float [] newFloatArray = new Float [] {valueTwo , valueThree , valueFour , ValueFive };
134
+
141
135
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 );
146
139
}
147
140
}
148
141
0 commit comments