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

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
langsmith committed Mar 29, 2019
1 parent 5c13702 commit 8c64b17
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.mapbox.mapboxandroiddemo.examples.dds;

// #-code-snippet: animated-dash-line full-java

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
Expand Down Expand Up @@ -36,9 +34,9 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
private MapView mapView;
private MapboxMap mapboxMap;
private Handler handler;
private String tag = "AnimatedDashLine";
private String TAG = "AnimatedDashLine";
private RefreshDashAndGapRunnable refreshDashAndGapRunnable;
private int animationSpeedMillseconds = 50;
private int animationSpeedMillseconds = 80;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -61,11 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {
public void onMapReady(MapboxMap mapboxMap) {
AnimatedDashLineActivity.this.mapboxMap = mapboxMap;
initBikePathLayer();
Log.d(tag, "onMapReady: here 1");
Runnable runnable = new RefreshDashAndGapRunnable();
Log.d(tag, "onMapReady: runnable made");
handler.postDelayed(runnable, animationSpeedMillseconds);
Log.d(tag, "onMapReady: here 2");
}

private void initBikePathLayer() {
Expand All @@ -90,7 +85,7 @@ private void initBikePathLayer() {
private class RefreshDashAndGapRunnable implements Runnable {

private float valueOne, valueTwo, valueThree, valueFour, ValueFive;
private float dashLength = 1;
private float dashLength = 3;
private float gapLength = 3;

// We divide the animation up into 40 totalNumberOfSteps to make careful use of the finite space in
Expand All @@ -113,9 +108,11 @@ public void run() {
Log.d(TAG, "RefreshDashAndGapRunnable run: ");
currentStep = currentStep + 1;
if (currentStep >= totalNumberOfSteps) {
Log.d(TAG, "run: currentStep >= totalNumberOfSteps");
currentStep = 0;
}
if (currentStep < dashSteps) {
Log.d(TAG, "run: currentStep < dashSteps");
valueOne = currentStep / dashSteps;
valueTwo = (1 - valueOne) * dashLength;
valueThree = gapLength;
Expand Down Expand Up @@ -156,6 +153,7 @@ protected void onStart() {
protected void onStop() {
super.onStop();
mapView.onStop();
handler.removeCallbacks(refreshDashAndGapRunnable);
}

@Override
Expand All @@ -174,7 +172,6 @@ public void onLowMemory() {
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
handler.removeCallbacks(refreshDashAndGapRunnable);
refreshDashAndGapRunnable = null;
handler = null;
}
Expand All @@ -184,5 +181,4 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}
// #-end-code-snippet: animated-dash-line full-java
}

0 comments on commit 8c64b17

Please sign in to comment.