From b936a052e1b9d090b059cd8c61dec3dfb15712de Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Wed, 30 May 2018 17:29:50 +0300 Subject: [PATCH] Create custom progress drawable for routing progress bar --- OsmAnd/res/layout-land/map_hud_bottom.xml | 3 +- OsmAnd/res/layout/map_hud_bottom.xml | 5 +- OsmAnd/res/values/colors.xml | 3 + OsmAnd/src/net/osmand/AndroidUtils.java | 22 +++++++ .../osmand/plus/activities/MapActivity.java | 11 +++- .../plus/activities/MapActivityLayers.java | 4 ++ .../mapmarkers/MarkersPlanRouteContext.java | 6 ++ .../MeasurementEditingContext.java | 6 ++ .../osmand/plus/routing/RoutingHelper.java | 20 ++++-- .../src/net/osmand/plus/views/RouteLayer.java | 64 +++++++++++-------- 10 files changed, 108 insertions(+), 36 deletions(-) diff --git a/OsmAnd/res/layout-land/map_hud_bottom.xml b/OsmAnd/res/layout-land/map_hud_bottom.xml index 135b403225..680be73185 100644 --- a/OsmAnd/res/layout-land/map_hud_bottom.xml +++ b/OsmAnd/res/layout-land/map_hud_bottom.xml @@ -198,9 +198,8 @@ style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_gravity="bottom" - android:layout_height="wrap_content" + android:layout_height="4dp" android:max="100" - android:minHeight="0dp" android:visibility="gone" tools:progress="60" tools:visibility="visible" /> diff --git a/OsmAnd/res/layout/map_hud_bottom.xml b/OsmAnd/res/layout/map_hud_bottom.xml index 0e6e1229e5..143794a913 100644 --- a/OsmAnd/res/layout/map_hud_bottom.xml +++ b/OsmAnd/res/layout/map_hud_bottom.xml @@ -231,15 +231,14 @@ tools:src="@drawable/ic_action_test_light"/> - + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index e822e91cf3..d678640ada 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -111,6 +111,9 @@ #536dfe #485dd9 + #f0f0f0 + #1b1d1f + #39464d #CC080B0D diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index f1b05985e4..3ef7cd913f 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -10,7 +10,10 @@ import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; +import android.graphics.drawable.ClipDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; +import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.StateListDrawable; import android.net.Uri; import android.os.Build; @@ -31,6 +34,7 @@ import android.text.style.ImageSpan; import android.text.style.URLSpan; import android.util.DisplayMetrics; import android.util.TypedValue; +import android.view.Gravity; import android.view.View; import android.view.ViewParent; import android.view.inputmethod.InputMethodManager; @@ -251,6 +255,24 @@ public class AndroidUtils { return res; } + public static LayerDrawable createProgressDrawable(@ColorInt int bgColor, @ColorInt int progressColor) { + ShapeDrawable bg = new ShapeDrawable(); + bg.getPaint().setColor(bgColor); + + ShapeDrawable progress = new ShapeDrawable(); + progress.getPaint().setColor(progressColor); + + LayerDrawable res = new LayerDrawable(new Drawable[]{ + bg, + new ClipDrawable(progress, Gravity.START, ClipDrawable.HORIZONTAL) + }); + + res.setId(0, android.R.id.background); + res.setId(1, android.R.id.progress); + + return res; + } + public static void setSnackbarTextColor(Snackbar snackbar, @ColorRes int colorId) { View view = snackbar.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_action); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 55dc81013b..1338099cdd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -281,8 +281,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } }; app.getResourceManager().getMapTileDownloader().addDownloaderCallback(downloaderCallback); - createProgressBarForRouting(); mapLayers.createLayers(mapView); + createProgressBarForRouting(); updateStatusBarColor(); // This situtation could be when navigation suddenly crashed and after restarting // it tries to continue the last route @@ -433,6 +433,15 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven app.getRoutingHelper().setProgressBar(new RouteCalculationProgressCallback() { + @Override + public void start() { + boolean night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + int bgColor = ContextCompat.getColor(app, night + ? R.color.map_progress_bar_bg_dark : R.color.map_progress_bar_bg_light); + pb.setProgressDrawable(AndroidUtils + .createProgressDrawable(bgColor, mapLayers.getRouteLayer().getRouteLineColor(night))); + } + @Override public void updateProgress(int progress) { mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateRouteCalculationProgress(progress); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 3a44bbaf61..27ae09febe 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -568,6 +568,10 @@ public class MapActivityLayers { return activity.getString(resId); } + public RouteLayer getRouteLayer() { + return routeLayer; + } + public PointNavigationLayer getNavigationLayer() { return navigationLayer; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java index 1b77f6f079..361586f311 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java @@ -218,6 +218,12 @@ public class MarkersPlanRouteContext { params.ctx = app; params.calculationProgress = calculationProgress = new RouteCalculationProgress(); params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() { + + @Override + public void start() { + + } + @Override public void updateProgress(int progress) { int pairs = calculatedPairs + snapToRoadPairsToCalculate.size(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index 34dd0b1e5a..fb61e0c3e2 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -284,6 +284,12 @@ public class MeasurementEditingContext { params.ctx = application; params.calculationProgress = calculationProgress = new RouteCalculationProgress(); params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() { + + @Override + public void start() { + + } + @Override public void updateProgress(int progress) { int pairs = calculatedPairs + snapToRoadPairsToCalculate.size(); diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 2b86ec6b35..689777d5b3 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -983,6 +983,7 @@ public class RoutingHelper { "Calculating route", params, paramsChanged); //$NON-NLS-1$ currentRunningJob = newThread; if (updateProgress) { + startProgress(params); updateProgress(params); } if (prevRunningJob != null) { @@ -992,6 +993,14 @@ public class RoutingHelper { } } + private void startProgress(final RouteCalculationParams params) { + if (params.calculationProgressCallback != null) { + params.calculationProgressCallback.start(); + } else if (progressRoute != null) { + progressRoute.start(); + } + } + private void updateProgress(final RouteCalculationParams params) { final RouteCalculationProgressCallback progressRoute; if (params.calculationProgressCallback != null) { @@ -1041,10 +1050,13 @@ public class RoutingHelper { public interface RouteCalculationProgressCallback { - // set visibility - public void updateProgress(int progress); - public void requestPrivateAccessRouting(); - public void finish(); + void start(); + + void updateProgress(int progress); + + void requestPrivateAccessRouting(); + + void finish(); } diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index ce9cf273b4..dd7349b754 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -1,13 +1,17 @@ package net.osmand.plus.views; -import gnu.trove.list.array.TByteArrayList; -import gnu.trove.list.array.TIntArrayList; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.TreeMap; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Paint.Cap; +import android.graphics.Path; +import android.graphics.PointF; +import android.graphics.PorterDuff.Mode; +import android.graphics.PorterDuffColorFilter; +import android.support.annotation.ColorInt; import net.osmand.Location; import net.osmand.data.LatLon; @@ -21,17 +25,15 @@ import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.util.MapUtils; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.Paint.Cap; -import android.graphics.Path; -import android.graphics.PointF; -import android.graphics.PorterDuff.Mode; -import android.graphics.PorterDuffColorFilter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.TreeMap; + +import gnu.trove.list.array.TByteArrayList; +import gnu.trove.list.array.TIntArrayList; public class RouteLayer extends OsmandMapLayer { @@ -118,13 +120,7 @@ public class RouteLayer extends OsmandMapLayer { @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) { - boolean updatePaints = attrs.updatePaints(view, settings, tileBox); - attrs.isPaint3 = false; - attrs.isPaint2 = false; - if(updatePaints) { - paintIconAction.setColorFilter(new PorterDuffColorFilter(attrs.paint3.getColor(), Mode.MULTIPLY)); - paintIcon.setColorFilter(new PorterDuffColorFilter(attrs.paint2.getColor(), Mode.MULTIPLY)); - } + updateAttrs(settings, tileBox); if(coloredArrowUp == null) { Bitmap originalArrowUp = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_route_direction_arrow, null); @@ -174,6 +170,16 @@ public class RouteLayer extends OsmandMapLayer { } + private void updateAttrs(DrawSettings settings, RotatedTileBox tileBox) { + boolean updatePaints = attrs.updatePaints(view, settings, tileBox); + attrs.isPaint3 = false; + attrs.isPaint2 = false; + if(updatePaints) { + paintIconAction.setColorFilter(new PorterDuffColorFilter(attrs.paint3.getColor(), Mode.MULTIPLY)); + paintIcon.setColorFilter(new PorterDuffColorFilter(attrs.paint2.getColor(), Mode.MULTIPLY)); + } + } + private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { QuadRect latLonBounds = tileBox.getLatLonBounds(); List xAxisPoints = trackChartPoints.getXAxisPoints(); @@ -242,6 +248,12 @@ public class RouteLayer extends OsmandMapLayer { } } } + + @ColorInt + public int getRouteLineColor(boolean night) { + updateAttrs(new DrawSettings(night), view.getCurrentRotatedTileBox()); + return attrs.paint.getColor(); + } private void cullRamerDouglasPeucker(TByteArrayList survivor, List points, int start, int end, double epsillon) {