From 83f600ef2a2652d3247e74d57a437b1076a785d9 Mon Sep 17 00:00:00 2001 From: langsmith Date: Wed, 1 Aug 2018 11:41:30 -0700 Subject: [PATCH] refactoring --- .../src/main/AndroidManifest.xml | 2 +- .../mapboxandroiddemo/MainActivity.java | 6 +- .../dds/AnimatedDashLineActivity.java | 65 +++++++++---------- .../main/res/values/descriptions_strings.xml | 2 +- .../src/main/res/values/titles_strings.xml | 2 +- .../src/main/res/values/urls_strings.xml | 2 +- 6 files changed, 36 insertions(+), 43 deletions(-) diff --git a/MapboxAndroidDemo/src/main/AndroidManifest.xml b/MapboxAndroidDemo/src/main/AndroidManifest.xml index 0d0f69f84..69dd18e13 100644 --- a/MapboxAndroidDemo/src/main/AndroidManifest.xml +++ b/MapboxAndroidDemo/src/main/AndroidManifest.xml @@ -482,7 +482,7 @@ + android:label="@string/activity_dds_animated_dash_line_title"> diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java index 587aa6581..ce13e595a 100644 --- a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/MainActivity.java @@ -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; diff --git a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/AnimatedDashLineActivity.java b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/AnimatedDashLineActivity.java index ccbebdaeb..9685c7458 100644 --- a/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/AnimatedDashLineActivity.java +++ b/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/AnimatedDashLineActivity.java @@ -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) { @@ -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() { @@ -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); } } diff --git a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml index 198b36d13..df524a93b 100644 --- a/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/descriptions_strings.xml @@ -43,7 +43,7 @@ Filter and draw multiple geometries from a single GeoJSON file. Use data-driven styling to show bathymetry (water depth) data Use SymbolLayer and icons to show data in a BubbleLayout "info window". - Animated the gap size of a LineLayer for the appearance of moving lines. + Animated the gap size of a LineLayer for the appearance of moving lines. Create a default marker with an InfoWindow. Create a marker with a custom icon using the Mapbox Maps SDK. Draw a polyline by parsing a GeoJSON file with the Mapbox Maps SDK. diff --git a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml index b3e3b0633..b961b0259 100644 --- a/MapboxAndroidDemo/src/main/res/values/titles_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/titles_strings.xml @@ -43,7 +43,7 @@ Display water depth Symbol layer info window SymbolLayer clustering - Animated line layer + Animated line layer Draw a marker Draw a custom marker icon Draw a GeoJSON line diff --git a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml index 440862c3f..42b68a5b6 100644 --- a/MapboxAndroidDemo/src/main/res/values/urls_strings.xml +++ b/MapboxAndroidDemo/src/main/res/values/urls_strings.xml @@ -44,7 +44,7 @@ https://i.imgur.com/mwhOcIR.png https://i.imgur.com/qYoqgDk.png https://i.imgur.com/KjgNcS0.png - https://i.imgur.com/KjgNcS0.png + https://i.imgur.com/9JTOUQL.png http://i.imgur.com/X59UoaY.png http://i.imgur.com/BIHtPwJ.png http://i.imgur.com/rIFjsrH.png