1
1
package com .mapbox .mapboxandroiddemo .examples .dds ;
2
2
3
- // #-code-snippet: animated-dash-line full-java
4
-
5
3
import android .graphics .Color ;
6
4
import android .os .Bundle ;
7
5
import android .os .Handler ;
@@ -36,9 +34,9 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
36
34
private MapView mapView ;
37
35
private MapboxMap mapboxMap ;
38
36
private Handler handler ;
39
- private String tag = "AnimatedDashLine" ;
37
+ private String TAG = "AnimatedDashLine" ;
40
38
private RefreshDashAndGapRunnable refreshDashAndGapRunnable ;
41
- private int animationSpeedMillseconds = 50 ;
39
+ private int animationSpeedMillseconds = 80 ;
42
40
43
41
@ Override
44
42
protected void onCreate (Bundle savedInstanceState ) {
@@ -61,11 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {
61
59
public void onMapReady (MapboxMap mapboxMap ) {
62
60
AnimatedDashLineActivity .this .mapboxMap = mapboxMap ;
63
61
initBikePathLayer ();
64
- Log .d (tag , "onMapReady: here 1" );
65
62
Runnable runnable = new RefreshDashAndGapRunnable ();
66
- Log .d (tag , "onMapReady: runnable made" );
67
63
handler .postDelayed (runnable , animationSpeedMillseconds );
68
- Log .d (tag , "onMapReady: here 2" );
69
64
}
70
65
71
66
private void initBikePathLayer () {
@@ -90,7 +85,7 @@ private void initBikePathLayer() {
90
85
private class RefreshDashAndGapRunnable implements Runnable {
91
86
92
87
private float valueOne , valueTwo , valueThree , valueFour , ValueFive ;
93
- private float dashLength = 1 ;
88
+ private float dashLength = 3 ;
94
89
private float gapLength = 3 ;
95
90
96
91
// We divide the animation up into 40 totalNumberOfSteps to make careful use of the finite space in
@@ -113,9 +108,11 @@ public void run() {
113
108
Log .d (TAG , "RefreshDashAndGapRunnable run: " );
114
109
currentStep = currentStep + 1 ;
115
110
if (currentStep >= totalNumberOfSteps ) {
111
+ Log .d (TAG , "run: currentStep >= totalNumberOfSteps" );
116
112
currentStep = 0 ;
117
113
}
118
114
if (currentStep < dashSteps ) {
115
+ Log .d (TAG , "run: currentStep < dashSteps" );
119
116
valueOne = currentStep / dashSteps ;
120
117
valueTwo = (1 - valueOne ) * dashLength ;
121
118
valueThree = gapLength ;
@@ -156,6 +153,7 @@ protected void onStart() {
156
153
protected void onStop () {
157
154
super .onStop ();
158
155
mapView .onStop ();
156
+ handler .removeCallbacks (refreshDashAndGapRunnable );
159
157
}
160
158
161
159
@ Override
@@ -174,7 +172,6 @@ public void onLowMemory() {
174
172
protected void onDestroy () {
175
173
super .onDestroy ();
176
174
mapView .onDestroy ();
177
- handler .removeCallbacks (refreshDashAndGapRunnable );
178
175
refreshDashAndGapRunnable = null ;
179
176
handler = null ;
180
177
}
@@ -184,5 +181,4 @@ protected void onSaveInstanceState(Bundle outState) {
184
181
super .onSaveInstanceState (outState );
185
182
mapView .onSaveInstanceState (outState );
186
183
}
187
- }
188
- // #-end-code-snippet: animated-dash-line full-java
184
+ }
0 commit comments