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"
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" />

View file

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

View file

@ -111,6 +111,9 @@
<color name="map_widget_blue">#536dfe</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="tool_bar_color_dark">#CC080B0D</color>

View file

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

View file

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

View file

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

View file

@ -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();

View file

@ -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();

View file

@ -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();
}

View file

@ -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<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,
int start, int end, double epsillon) {
double dmax = Double.NEGATIVE_INFINITY;