Create custom progress drawable for routing progress bar

This commit is contained in:
Alex Sytnyk 2018-05-30 17:29:50 +03:00
parent 74d887a755
commit b936a052e1
10 changed files with 108 additions and 36 deletions

View file

@ -198,9 +198,8 @@
style="?android:attr/progressBarStyleHorizontal" style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_height="wrap_content" android:layout_height="4dp"
android:max="100" android:max="100"
android:minHeight="0dp"
android:visibility="gone" android:visibility="gone"
tools:progress="60" tools:progress="60"
tools:visibility="visible" /> tools:visibility="visible" />

View file

@ -236,10 +236,9 @@
android:id="@+id/map_horizontal_progress" android:id="@+id/map_horizontal_progress"
style="?android:attr/progressBarStyleHorizontal" style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="4dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:max="100" android:max="100"
android:minHeight="0dp"
android:visibility="gone" android:visibility="gone"
tools:progress="60" tools:progress="60"
tools:visibility="visible" /> tools:visibility="visible" />

View file

@ -111,6 +111,9 @@
<color name="map_widget_blue">#536dfe</color> <color name="map_widget_blue">#536dfe</color>
<color name="map_widget_blue_pressed">#485dd9</color> <color name="map_widget_blue_pressed">#485dd9</color>
<color name="map_progress_bar_bg_light">#f0f0f0</color>
<color name="map_progress_bar_bg_dark">#1b1d1f</color>
<color name="actionbar_dark_color">#39464d</color> <color name="actionbar_dark_color">#39464d</color>
<color name="tool_bar_color_dark">#CC080B0D</color> <color name="tool_bar_color_dark">#CC080B0D</color>

View file

@ -10,7 +10,10 @@ import android.content.res.Resources;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.StateListDrawable; import android.graphics.drawable.StateListDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -31,6 +34,7 @@ import android.text.style.ImageSpan;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewParent; import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
@ -251,6 +255,24 @@ public class AndroidUtils {
return res; 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) { public static void setSnackbarTextColor(Snackbar snackbar, @ColorRes int colorId) {
View view = snackbar.getView(); View view = snackbar.getView();
TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_action); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_action);

View file

@ -281,8 +281,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
}; };
app.getResourceManager().getMapTileDownloader().addDownloaderCallback(downloaderCallback); app.getResourceManager().getMapTileDownloader().addDownloaderCallback(downloaderCallback);
createProgressBarForRouting();
mapLayers.createLayers(mapView); mapLayers.createLayers(mapView);
createProgressBarForRouting();
updateStatusBarColor(); updateStatusBarColor();
// This situtation could be when navigation suddenly crashed and after restarting // This situtation could be when navigation suddenly crashed and after restarting
// it tries to continue the last route // it tries to continue the last route
@ -433,6 +433,15 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
app.getRoutingHelper().setProgressBar(new RouteCalculationProgressCallback() { 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 @Override
public void updateProgress(int progress) { public void updateProgress(int progress) {
mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateRouteCalculationProgress(progress); mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateRouteCalculationProgress(progress);

View file

@ -568,6 +568,10 @@ public class MapActivityLayers {
return activity.getString(resId); return activity.getString(resId);
} }
public RouteLayer getRouteLayer() {
return routeLayer;
}
public PointNavigationLayer getNavigationLayer() { public PointNavigationLayer getNavigationLayer() {
return navigationLayer; return navigationLayer;
} }

View file

@ -218,6 +218,12 @@ public class MarkersPlanRouteContext {
params.ctx = app; params.ctx = app;
params.calculationProgress = calculationProgress = new RouteCalculationProgress(); params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() { params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
@Override
public void start() {
}
@Override @Override
public void updateProgress(int progress) { public void updateProgress(int progress) {
int pairs = calculatedPairs + snapToRoadPairsToCalculate.size(); int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();

View file

@ -284,6 +284,12 @@ public class MeasurementEditingContext {
params.ctx = application; params.ctx = application;
params.calculationProgress = calculationProgress = new RouteCalculationProgress(); params.calculationProgress = calculationProgress = new RouteCalculationProgress();
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() { params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
@Override
public void start() {
}
@Override @Override
public void updateProgress(int progress) { public void updateProgress(int progress) {
int pairs = calculatedPairs + snapToRoadPairsToCalculate.size(); int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();

View file

@ -983,6 +983,7 @@ public class RoutingHelper {
"Calculating route", params, paramsChanged); //$NON-NLS-1$ "Calculating route", params, paramsChanged); //$NON-NLS-1$
currentRunningJob = newThread; currentRunningJob = newThread;
if (updateProgress) { if (updateProgress) {
startProgress(params);
updateProgress(params); updateProgress(params);
} }
if (prevRunningJob != null) { 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) { private void updateProgress(final RouteCalculationParams params) {
final RouteCalculationProgressCallback progressRoute; final RouteCalculationProgressCallback progressRoute;
if (params.calculationProgressCallback != null) { if (params.calculationProgressCallback != null) {
@ -1041,10 +1050,13 @@ public class RoutingHelper {
public interface RouteCalculationProgressCallback { public interface RouteCalculationProgressCallback {
// set visibility void start();
public void updateProgress(int progress);
public void requestPrivateAccessRouting(); void updateProgress(int progress);
public void finish();
void requestPrivateAccessRouting();
void finish();
} }

View file

@ -1,13 +1,17 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import gnu.trove.list.array.TByteArrayList; import android.graphics.Bitmap;
import gnu.trove.list.array.TIntArrayList; import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import java.util.ArrayList; import android.graphics.Color;
import java.util.Collections; import android.graphics.Matrix;
import java.util.Iterator; import android.graphics.Paint;
import java.util.List; import android.graphics.Paint.Cap;
import java.util.TreeMap; 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.Location;
import net.osmand.data.LatLon; 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.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import java.util.ArrayList;
import android.graphics.Canvas; import java.util.Collections;
import android.graphics.Color; import java.util.Iterator;
import android.graphics.Matrix; import java.util.List;
import android.graphics.Paint; import java.util.TreeMap;
import android.graphics.Paint.Cap;
import android.graphics.Path; import gnu.trove.list.array.TByteArrayList;
import android.graphics.PointF; import gnu.trove.list.array.TIntArrayList;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
public class RouteLayer extends OsmandMapLayer { public class RouteLayer extends OsmandMapLayer {
@ -118,13 +120,7 @@ public class RouteLayer extends OsmandMapLayer {
@Override @Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) { if (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) {
boolean updatePaints = attrs.updatePaints(view, settings, tileBox); updateAttrs(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));
}
if(coloredArrowUp == null) { if(coloredArrowUp == null) {
Bitmap originalArrowUp = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_route_direction_arrow, 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) { private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds(); QuadRect latLonBounds = tileBox.getLatLonBounds();
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints(); List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
@ -243,6 +249,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<Location> points, private void cullRamerDouglasPeucker(TByteArrayList survivor, List<Location> points,
int start, int end, double epsillon) { int start, int end, double epsillon) {
double dmax = Double.NEGATIVE_INFINITY; double dmax = Double.NEGATIVE_INFINITY;