Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 8c64b17

Browse files
committed
refactoring
1 parent 5c13702 commit 8c64b17

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/AnimatedDashLineActivity.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mapbox.mapboxandroiddemo.examples.dds;
22

3-
// #-code-snippet: animated-dash-line full-java
4-
53
import android.graphics.Color;
64
import android.os.Bundle;
75
import android.os.Handler;
@@ -36,9 +34,9 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
3634
private MapView mapView;
3735
private MapboxMap mapboxMap;
3836
private Handler handler;
39-
private String tag = "AnimatedDashLine";
37+
private String TAG = "AnimatedDashLine";
4038
private RefreshDashAndGapRunnable refreshDashAndGapRunnable;
41-
private int animationSpeedMillseconds = 50;
39+
private int animationSpeedMillseconds = 80;
4240

4341
@Override
4442
protected void onCreate(Bundle savedInstanceState) {
@@ -61,11 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {
6159
public void onMapReady(MapboxMap mapboxMap) {
6260
AnimatedDashLineActivity.this.mapboxMap = mapboxMap;
6361
initBikePathLayer();
64-
Log.d(tag, "onMapReady: here 1");
6562
Runnable runnable = new RefreshDashAndGapRunnable();
66-
Log.d(tag, "onMapReady: runnable made");
6763
handler.postDelayed(runnable, animationSpeedMillseconds);
68-
Log.d(tag, "onMapReady: here 2");
6964
}
7065

7166
private void initBikePathLayer() {
@@ -90,7 +85,7 @@ private void initBikePathLayer() {
9085
private class RefreshDashAndGapRunnable implements Runnable {
9186

9287
private float valueOne, valueTwo, valueThree, valueFour, ValueFive;
93-
private float dashLength = 1;
88+
private float dashLength = 3;
9489
private float gapLength = 3;
9590

9691
// We divide the animation up into 40 totalNumberOfSteps to make careful use of the finite space in
@@ -113,9 +108,11 @@ public void run() {
113108
Log.d(TAG, "RefreshDashAndGapRunnable run: ");
114109
currentStep = currentStep + 1;
115110
if (currentStep >= totalNumberOfSteps) {
111+
Log.d(TAG, "run: currentStep >= totalNumberOfSteps");
116112
currentStep = 0;
117113
}
118114
if (currentStep < dashSteps) {
115+
Log.d(TAG, "run: currentStep < dashSteps");
119116
valueOne = currentStep / dashSteps;
120117
valueTwo = (1 - valueOne) * dashLength;
121118
valueThree = gapLength;
@@ -156,6 +153,7 @@ protected void onStart() {
156153
protected void onStop() {
157154
super.onStop();
158155
mapView.onStop();
156+
handler.removeCallbacks(refreshDashAndGapRunnable);
159157
}
160158

161159
@Override
@@ -174,7 +172,6 @@ public void onLowMemory() {
174172
protected void onDestroy() {
175173
super.onDestroy();
176174
mapView.onDestroy();
177-
handler.removeCallbacks(refreshDashAndGapRunnable);
178175
refreshDashAndGapRunnable = null;
179176
handler = null;
180177
}
@@ -184,5 +181,4 @@ protected void onSaveInstanceState(Bundle outState) {
184181
super.onSaveInstanceState(outState);
185182
mapView.onSaveInstanceState(outState);
186183
}
187-
}
188-
// #-end-code-snippet: animated-dash-line full-java
184+
}

0 commit comments

Comments
 (0)