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 Aug 1, 2018
1 parent d25e016 commit 83f600e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
2 changes: 1 addition & 1 deletion MapboxAndroidDemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@
</activity>
<activity
android:name=".examples.dds.AnimatedDashLineActivity"
android:label="@string/activity_styles_dds_animated_dash_line_title">
android:label="@string/activity_dds_animated_dash_line_title">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,10 @@ private void listItems(int id) {
R.string.activity_dds_time_lapse_rainfall_url, false, BuildConfig.MIN_SDK_VERSION));

exampleItemModels.add(new ExampleItemModel(
R.string.activity_styles_dds_animated_dash_line_title,
R.string.activity_styles_dds_animated_dash_line_description,
R.string.activity_dds_animated_dash_line_title,
R.string.activity_dds_animated_dash_line_description,
new Intent(MainActivity.this, AnimatedDashLineActivity.class),
R.string.activity_styles_dds_animated_dash_line_url, false, BuildConfig.MIN_SDK_VERSION));
R.string.activity_dds_animated_dash_line_url, false, BuildConfig.MIN_SDK_VERSION));

currentCategory = R.id.nav_dds;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
private Handler handler;
private String tag = "AnimatedDashLine";
private RefreshDashAndGapRunnable refreshDashAndGapRunnable;
private int animationSpeedMillseconds = 50;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -60,7 +61,11 @@ protected void onCreate(Bundle savedInstanceState) {
public void onMapReady(MapboxMap mapboxMap) {
AnimatedDashLineActivity.this.mapboxMap = mapboxMap;
initBikePathLayer();
Log.d(tag, "onMapReady: ");
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 @@ -77,72 +82,60 @@ private void initBikePathLayer() {
lineJoin(LINE_JOIN_ROUND)
);
mapboxMap.addLayer(animatedDashBikeLineLayer);
Log.d(tag, "initBikePathLayer: here");
Runnable runnable = new RefreshDashAndGapRunnable(this.mapboxMap, handler);
Log.d(tag, "initBikePathLayer: runnable made");
handler.postDelayed(runnable, 25);
Log.d(tag, "initBikePathLayer: postDelayed");
} catch (MalformedURLException malformedUrlException) {
Log.d("AnimatedDashLine", "Check the URL: " + malformedUrlException.getMessage());
}
}

private static class RefreshDashAndGapRunnable implements Runnable {
private class RefreshDashAndGapRunnable implements Runnable {

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

// We divide the animation up into 40 steps to make careful use of the finite space in
// We divide the animation up into 40 totalNumberOfSteps to make careful use of the finite space in
// LineAtlas
private float steps = 40;
private float totalNumberOfSteps = 40;

// A # of steps proportional to the dashLength are devoted to manipulating the dash
private float dashSteps = steps * dashLength / (gapLength + dashLength);
// A # of totalNumberOfSteps proportional to the dashLength are devoted to manipulating the dash
private float dashSteps = totalNumberOfSteps * dashLength / (gapLength + dashLength);

// A # of steps proportional to the gapLength are devoted to manipulating the gap
private float gapSteps = steps - dashSteps;
// A # of totalNumberOfSteps proportional to the gapLength are devoted to manipulating the gap
private float gapSteps = totalNumberOfSteps - dashSteps;

// The current step #
private int step = 0;
// The current currentStep #
private int currentStep = 0;

private MapboxMap mapboxMap;
private Handler handler;
private String TAG = "AnimatedDashLine";

RefreshDashAndGapRunnable(MapboxMap mapboxMap, Handler handler) {
this.mapboxMap = mapboxMap;
this.handler = handler;
Log.d(TAG, "RefreshDashAndGapRunnable: finished");

}

@Override
public void run() {
Log.d(TAG, "run: ");
step = step + 1;
if (step >= steps) {
step = 0;
Log.d(TAG, "RefreshDashAndGapRunnable run: ");
currentStep = currentStep + 1;
if (currentStep >= totalNumberOfSteps) {
currentStep = 0;
}
if (step < dashSteps) {
valueOne = step / dashSteps;
if (currentStep < dashSteps) {
valueOne = currentStep / dashSteps;
valueTwo = (1 - valueOne) * dashLength;
valueThree = gapLength;
valueFour = valueOne * dashLength;
ValueFive = 0;
} else {
valueOne = (step - dashSteps) / (gapSteps);
valueOne = (currentStep - dashSteps) / (gapSteps);
valueTwo = 0;
valueThree = (1 - valueOne) * gapLength;
valueFour = dashLength;
ValueFive = valueOne * gapLength;
}
Log.d(TAG, "run: here");
Log.d(TAG, "RefreshDashAndGapRunnable run: here");

Float[] newFloatArray = new Float[] {valueTwo, valueThree, valueFour, ValueFive};

mapboxMap.getLayer("animated_line_layer_id").setProperties(
lineDasharray(new Float[] {valueTwo, valueThree, valueFour, ValueFive})
);
Log.d(TAG, "run: layer done being gotten");
handler.postDelayed(this, 25);
lineDasharray(newFloatArray));
Log.d(TAG, "RefreshDashAndGapRunnable run: layer done being gotten");
handler.postDelayed(this, animationSpeedMillseconds);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<string name="activity_dds_multiple_geometries_description">Filter and draw multiple geometries from a single GeoJSON file.</string>
<string name="activity_dds_bathymetry_description">Use data-driven styling to show bathymetry (water depth) data</string>
<string name="activity_dds_info_window_symbol_layer_description">Use SymbolLayer and icons to show data in a BubbleLayout "info window".</string>
<string name="activity_styles_dds_animated_dash_line_description">Animated the gap size of a LineLayer for the appearance of moving lines.</string>
<string name="activity_dds_animated_dash_line_description">Animated the gap size of a LineLayer for the appearance of moving lines.</string>
<string name="activity_annotation_marker_description">Create a default marker with an InfoWindow.</string>
<string name="activity_annotation_custom_marker_description">Create a marker with a custom icon using the Mapbox Maps SDK.</string>
<string name="activity_annotation_geojson_line_description">Draw a polyline by parsing a GeoJSON file with the Mapbox Maps SDK.</string>
Expand Down
2 changes: 1 addition & 1 deletion MapboxAndroidDemo/src/main/res/values/titles_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<string name="activity_dds_bathymetry_title">Display water depth</string>
<string name="activity_dds_info_window_symbol_layer_title">Symbol layer info window</string>
<string name="activity_dds_image_clustering_title">SymbolLayer clustering</string>
<string name="activity_styles_dds_animated_dash_line_title">Animated line layer</string>
<string name="activity_dds_animated_dash_line_title">Animated line layer</string>
<string name="activity_annotation_marker_title">Draw a marker</string>
<string name="activity_annotation_custom_marker_title">Draw a custom marker icon</string>
<string name="activity_annotation_geojson_line_title">Draw a GeoJSON line</string>
Expand Down
2 changes: 1 addition & 1 deletion MapboxAndroidDemo/src/main/res/values/urls_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<string name="activity_dds_bathymetry_url" translatable="false">https://i.imgur.com/mwhOcIR.png</string>
<string name="activity_dds_info_window_symbol_layer_url" translatable="false">https://i.imgur.com/qYoqgDk.png</string>
<string name="activity_dds_image_clustering_url" translatable="false">https://i.imgur.com/KjgNcS0.png</string>
<string name="activity_styles_dds_animated_dash_line_url" translatable="false">https://i.imgur.com/KjgNcS0.png</string>
<string name="activity_dds_animated_dash_line_url" translatable="false">https://i.imgur.com/9JTOUQL.png</string>
<string name="activity_annotation_marker_url" translatable="false">http://i.imgur.com/X59UoaY.png</string>
<string name="activity_annotation_custom_marker_url" translatable="false">http://i.imgur.com/BIHtPwJ.png</string>
<string name="activity_annotation_geojson_line_url" translatable="false">http://i.imgur.com/rIFjsrH.png</string>
Expand Down

0 comments on commit 83f600e

Please sign in to comment.