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

Commit 83f600e

Browse files
committed
refactoring
1 parent d25e016 commit 83f600e

File tree

6 files changed

+36
-43
lines changed

6 files changed

+36
-43
lines changed

MapboxAndroidDemo/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@
482482
</activity>
483483
<activity
484484
android:name=".examples.dds.AnimatedDashLineActivity"
485-
android:label="@string/activity_styles_dds_animated_dash_line_title">
485+
android:label="@string/activity_dds_animated_dash_line_title">
486486
<meta-data
487487
android:name="android.support.PARENT_ACTIVITY"
488488
android:value="com.mapbox.mapboxandroiddemo.MainActivity" />

MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,10 @@ private void listItems(int id) {
787787
R.string.activity_dds_time_lapse_rainfall_url, false, BuildConfig.MIN_SDK_VERSION));
788788

789789
exampleItemModels.add(new ExampleItemModel(
790-
R.string.activity_styles_dds_animated_dash_line_title,
791-
R.string.activity_styles_dds_animated_dash_line_description,
790+
R.string.activity_dds_animated_dash_line_title,
791+
R.string.activity_dds_animated_dash_line_description,
792792
new Intent(MainActivity.this, AnimatedDashLineActivity.class),
793-
R.string.activity_styles_dds_animated_dash_line_url, false, BuildConfig.MIN_SDK_VERSION));
793+
R.string.activity_dds_animated_dash_line_url, false, BuildConfig.MIN_SDK_VERSION));
794794

795795
currentCategory = R.id.nav_dds;
796796
break;

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

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
3838
private Handler handler;
3939
private String tag = "AnimatedDashLine";
4040
private RefreshDashAndGapRunnable refreshDashAndGapRunnable;
41+
private int animationSpeedMillseconds = 50;
4142

4243
@Override
4344
protected void onCreate(Bundle savedInstanceState) {
@@ -60,7 +61,11 @@ protected void onCreate(Bundle savedInstanceState) {
6061
public void onMapReady(MapboxMap mapboxMap) {
6162
AnimatedDashLineActivity.this.mapboxMap = mapboxMap;
6263
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");
6469
}
6570

6671
private void initBikePathLayer() {
@@ -77,72 +82,60 @@ private void initBikePathLayer() {
7782
lineJoin(LINE_JOIN_ROUND)
7883
);
7984
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");
8585
} catch (MalformedURLException malformedUrlException) {
8686
Log.d("AnimatedDashLine", "Check the URL: " + malformedUrlException.getMessage());
8787
}
8888
}
8989

90-
private static class RefreshDashAndGapRunnable implements Runnable {
90+
private class RefreshDashAndGapRunnable implements Runnable {
9191

9292
private float valueOne, valueTwo, valueThree, valueFour, ValueFive;
9393
private float dashLength = 1;
9494
private float gapLength = 3;
9595

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
9797
// LineAtlas
98-
private float steps = 40;
98+
private float totalNumberOfSteps = 40;
9999

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);
102102

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;
105105

106-
// The current step #
107-
private int step = 0;
106+
// The current currentStep #
107+
private int currentStep = 0;
108108

109-
private MapboxMap mapboxMap;
110-
private Handler handler;
111109
private String TAG = "AnimatedDashLine";
112110

113-
RefreshDashAndGapRunnable(MapboxMap mapboxMap, Handler handler) {
114-
this.mapboxMap = mapboxMap;
115-
this.handler = handler;
116-
Log.d(TAG, "RefreshDashAndGapRunnable: finished");
117-
118-
}
119-
120111
@Override
121112
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;
126117
}
127-
if (step < dashSteps) {
128-
valueOne = step / dashSteps;
118+
if (currentStep < dashSteps) {
119+
valueOne = currentStep / dashSteps;
129120
valueTwo = (1 - valueOne) * dashLength;
130121
valueThree = gapLength;
131122
valueFour = valueOne * dashLength;
132123
ValueFive = 0;
133124
} else {
134-
valueOne = (step - dashSteps) / (gapSteps);
125+
valueOne = (currentStep - dashSteps) / (gapSteps);
135126
valueTwo = 0;
136127
valueThree = (1 - valueOne) * gapLength;
137128
valueFour = dashLength;
138129
ValueFive = valueOne * gapLength;
139130
}
140-
Log.d(TAG, "run: here");
131+
Log.d(TAG, "RefreshDashAndGapRunnable run: here");
132+
133+
Float[] newFloatArray = new Float[] {valueTwo, valueThree, valueFour, ValueFive};
134+
141135
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);
146139
}
147140
}
148141

MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<string name="activity_dds_multiple_geometries_description">Filter and draw multiple geometries from a single GeoJSON file.</string>
4444
<string name="activity_dds_bathymetry_description">Use data-driven styling to show bathymetry (water depth) data</string>
4545
<string name="activity_dds_info_window_symbol_layer_description">Use SymbolLayer and icons to show data in a BubbleLayout "info window".</string>
46-
<string name="activity_styles_dds_animated_dash_line_description">Animated the gap size of a LineLayer for the appearance of moving lines.</string>
46+
<string name="activity_dds_animated_dash_line_description">Animated the gap size of a LineLayer for the appearance of moving lines.</string>
4747
<string name="activity_annotation_marker_description">Create a default marker with an InfoWindow.</string>
4848
<string name="activity_annotation_custom_marker_description">Create a marker with a custom icon using the Mapbox Maps SDK.</string>
4949
<string name="activity_annotation_geojson_line_description">Draw a polyline by parsing a GeoJSON file with the Mapbox Maps SDK.</string>

MapboxAndroidDemo/src/main/res/values/titles_strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<string name="activity_dds_bathymetry_title">Display water depth</string>
4444
<string name="activity_dds_info_window_symbol_layer_title">Symbol layer info window</string>
4545
<string name="activity_dds_image_clustering_title">SymbolLayer clustering</string>
46-
<string name="activity_styles_dds_animated_dash_line_title">Animated line layer</string>
46+
<string name="activity_dds_animated_dash_line_title">Animated line layer</string>
4747
<string name="activity_annotation_marker_title">Draw a marker</string>
4848
<string name="activity_annotation_custom_marker_title">Draw a custom marker icon</string>
4949
<string name="activity_annotation_geojson_line_title">Draw a GeoJSON line</string>

MapboxAndroidDemo/src/main/res/values/urls_strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<string name="activity_dds_bathymetry_url" translatable="false">https://i.imgur.com/mwhOcIR.png</string>
4545
<string name="activity_dds_info_window_symbol_layer_url" translatable="false">https://i.imgur.com/qYoqgDk.png</string>
4646
<string name="activity_dds_image_clustering_url" translatable="false">https://i.imgur.com/KjgNcS0.png</string>
47-
<string name="activity_styles_dds_animated_dash_line_url" translatable="false">https://i.imgur.com/KjgNcS0.png</string>
47+
<string name="activity_dds_animated_dash_line_url" translatable="false">https://i.imgur.com/9JTOUQL.png</string>
4848
<string name="activity_annotation_marker_url" translatable="false">http://i.imgur.com/X59UoaY.png</string>
4949
<string name="activity_annotation_custom_marker_url" translatable="false">http://i.imgur.com/BIHtPwJ.png</string>
5050
<string name="activity_annotation_geojson_line_url" translatable="false">http://i.imgur.com/rIFjsrH.png</string>

0 commit comments

Comments
 (0)