Add big turn info

This commit is contained in:
Victor Shcherb 2015-03-15 12:42:31 +01:00
parent 994e4e48fc
commit c3c5d9d055
9 changed files with 233 additions and 221 deletions

View file

@ -7,9 +7,9 @@
android:background="@drawable/btn_left_round" android:background="@drawable/btn_left_round"
android:orientation="vertical"> android:orientation="vertical">
<ImageButton <ImageView
android:id="@+id/widget_top_icon" android:id="@+id/widget_top_icon"
android:layout_width="wrap_content" android:layout_width="@dimen/map_widget_image"
android:layout_height="@dimen/map_widget_image" android:layout_height="@dimen/map_widget_image"
android:layout_gravity="center" android:layout_gravity="center"
android:src="@drawable/ic_action_close_light" android:src="@drawable/ic_action_close_light"

View file

@ -50,8 +50,8 @@
<dimen name="osmo_header_height">56dp</dimen> <dimen name="osmo_header_height">56dp</dimen>
<!-- map buttons --> <!-- map buttons -->
<dimen name="map_trans_seek_size">80dp</dimen> <dimen name="map_trans_seek_size">80dp</dimen>
<dimen name="map_widget_text_size">20sp</dimen> <dimen name="map_widget_text_size">23sp</dimen>
<dimen name="map_widget_text_size_small">14sp</dimen> <dimen name="map_widget_text_size_small">15sp</dimen>
<dimen name="map_widget_text_bottom_margin">1sp</dimen> <dimen name="map_widget_text_bottom_margin">1sp</dimen>
<dimen name="map_button_text_size">18sp</dimen> <dimen name="map_button_text_size">18sp</dimen>
<dimen name="map_route_buttons_width">60dp</dimen> <dimen name="map_route_buttons_width">60dp</dimen>

View file

@ -154,7 +154,6 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
setImageDrawable(monitoringBig); setImageDrawable(monitoringBig);
return true; return true;
} }
boolean visible = true;
String txt = map.getString(R.string.monitoring_control_start); String txt = map.getString(R.string.monitoring_control_start);
String subtxt = null; String subtxt = null;
Drawable d = monitoringInactive; Drawable d = monitoringInactive;
@ -203,7 +202,6 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
} }
}, 500); }, 500);
} }
updateVisibility(visible);
return true; return true;
} }
}; };

View file

@ -215,7 +215,6 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
private Drawable blinkImg; private Drawable blinkImg;
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
boolean visible = true;
String txt = "OsMo"; String txt = "OsMo";
String subtxt = ""; String subtxt = "";
SessionInfo si = getService().getCurrentSessionInfo(); SessionInfo si = getService().getCurrentSessionInfo();
@ -258,7 +257,6 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
blink(big, small); blink(big, small);
} }
updateVisibility(visible);
return true; return true;
} }

View file

@ -15,9 +15,10 @@ import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.views.mapwidgets.BaseMapWidget; import net.osmand.plus.views.mapwidgets.BaseMapWidget;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget;
import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.RouteInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
@ -96,17 +97,13 @@ public class MapInfoLayer extends OsmandMapLayer {
alarmControl = ric.createAlarmInfoControl(app, map); alarmControl = ric.createAlarmInfoControl(app, map);
// register left stack // register left stack
// FIXME TODO LEFT STACK NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
// RoutingHelper routingHelper = app.getRoutingHelper(); mapInfoControls.registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
// NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), false); NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
// mapInfoControls.registerSideWidget(bigInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5); mapInfoControls.registerSideWidget(smallInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
// NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(routingHelper, app, view.getSettings(), 10);
// paintSmallText, paintSmallSubText, true); NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true);
// mapInfoControls.registerSideWidget(smallInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true, mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
// 10);
// NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(routingHelper, app, view.getSettings(),
// paintSmallText, paintSmallSubText, true);
// mapInfoControls.registerSideWidget(nextNextInfoControl, R.drawable.widget_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
// right stack // right stack
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map); TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map);
registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3); registerSideWidget(intermediateDist, R.drawable.widget_intermediate, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);

View file

@ -258,8 +258,10 @@ public class MapWidgetRegistry {
public void addControls(MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) { public void addControls(MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) {
cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(mil, cm, right, mode); addControls(mil, cm, right, mode);
if(mode != ApplicationMode.DEFAULT) {
cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControls(mil, cm, left, mode); addControls(mil, cm, left, mode);
}
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg(); cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
addControlsAppearance(mil, cm, mode); addControlsAppearance(mil, cm, mode);
} }

View file

@ -3,52 +3,116 @@ package net.osmand.plus.views.mapwidgets;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
public class NextTurnInfoWidget extends BaseMapWidget { public class NextTurnInfoWidget extends TextInfoWidget {
private final float scaleCoefficient;
private float width;
private float height ;
private static final float miniCoeff = 2.5f;
protected double deviatedPath = 0;
protected Path pathForTurn = new Path();
protected TurnType turnType = null;
protected String exitOut = null;
protected int nextTurnDirection = 0;
protected Paint textPaint;
protected Paint subtextPaint;
private Paint paintBlack;
private Paint paintRouteDirection;
protected boolean deviatedFromRoute;
protected int turnImminent;
protected boolean horisontalMini; protected boolean horisontalMini;
public NextTurnInfoWidget(Context ctx, Paint textPaint, Paint subtextPaint, boolean horisontalMini, protected int deviatedPath = 0;
protected int nextTurnDistance = 0;
private TurnDrawable turnDrawable;
private OsmandApplication app;
public NextTurnInfoWidget(Activity activity, OsmandApplication app, boolean horisontalMini,
float scaleCoefficient) { float scaleCoefficient) {
super(ctx); super(activity);
this.textPaint = textPaint; this.app = app;
this.subtextPaint = subtextPaint; this.horisontalMini = horisontalMini;
this.scaleCoefficient = scaleCoefficient; turnDrawable = new TurnDrawable(activity);
if(horisontalMini) {
setImageDrawable(turnDrawable);
} else {
setTopImageDrawable(turnDrawable);
}
}
public TurnType getTurnType() {
return turnDrawable.turnType;
}
public void setTurnType(TurnType turnType) {
if (!Algorithms.objectEquals(getTurnType(), turnType)) {
turnDrawable.setTurnType(turnType);
invalidateImageViews();
}
updateVisibility(turnType != null);
}
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
if(turnDrawable.turnImminent != turnImminent || turnDrawable.deviatedFromRoute != deviatedFromRoute) {
turnDrawable.setTurnImminent(turnImminent, deviatedFromRoute);
updateDistance();
}
}
public void setDeviatePath(int deviatePath) {
if (RouteInfoWidgetsFactory.distChanged(deviatePath, this.deviatedPath)) {
this.deviatedPath = deviatePath;
updateDistance();
}
}
public void setTurnDistance(int nextTurnDistance) {
if (RouteInfoWidgetsFactory.distChanged(nextTurnDistance, this.nextTurnDistance)) {
this.nextTurnDistance = nextTurnDistance;
updateDistance();
}
}
private void updateDistance() {
int deviatePath = turnDrawable.deviatedFromRoute ? deviatedPath : nextTurnDistance;
String ds = OsmAndFormatter.getFormattedDistance(deviatePath, app);
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
}
public void setExitOut(int exit) {
// TODO exit
// if(turnDrawable.exitOut != exit) {
// turnDrawable.e
// }
// TODO;
}
@Override
public boolean updateInfo(DrawSettings drawSettings) {
return false;
}
public static class TurnDrawable extends Drawable {
protected Paint paintBlack;
protected Paint paintRouteDirection;
protected Path pathForTurn = new Path();
protected TurnType turnType = null;
protected int turnImminent;
protected boolean deviatedFromRoute;
private Context ctx;
public TurnDrawable(Context ctx) {
this.ctx = ctx;
paintBlack = new Paint(); paintBlack = new Paint();
paintBlack.setStyle(Style.STROKE); paintBlack.setStyle(Style.STROKE);
paintBlack.setColor(Color.BLACK); paintBlack.setColor(Color.BLACK);
@ -57,100 +121,66 @@ public class NextTurnInfoWidget extends BaseMapWidget {
paintRouteDirection = new Paint(); paintRouteDirection = new Paint();
paintRouteDirection.setStyle(Style.FILL); paintRouteDirection.setStyle(Style.FILL);
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow)); paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow));
paintRouteDirection.setAntiAlias(true); paintRouteDirection.setAntiAlias(true);
pathTransform = new Matrix();
updateHorisontalMini(horisontalMini);
}
protected void updateHorisontalMini(boolean horisontalMini) {
this.horisontalMini = horisontalMini;
if (horisontalMini) {
pathTransform.postScale(scaleCoefficient / miniCoeff, scaleCoefficient / miniCoeff);
width = 72 * scaleCoefficient / miniCoeff;
height = 72 * scaleCoefficient / miniCoeff;
} else {
pathTransform.postScale(scaleCoefficient, scaleCoefficient);
width = 72 * scaleCoefficient;
height = 72 * scaleCoefficient;
}
requestLayout();
}
protected Matrix pathTransform = new Matrix();
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int h = 0;
int w = 0;
if (!horisontalMini) {
h = (int) (8 * scaleCoefficient + Math.max(textPaint.getTextSize(), subtextPaint.getTextSize()));
} else {
h = (int) (7 * scaleCoefficient);
w = (int) textPaint.measureText(OsmAndFormatter.getFormattedDistance(nextTurnDirection, getClientContext()));
}
setWDimensions((int) width + w, (int) height + h);
} }
@Override @Override
protected void onDraw(Canvas canvas) { protected void onBoundsChange(Rect bounds) {
super.onDraw(canvas);
if (pathForTurn != null) { if (pathForTurn != null) {
//if user deviates from route that we should draw grey arrow Matrix m = new Matrix();
if (deviatedFromRoute){ m.setScale(bounds.width() / 72f, bounds.height() / 72f);
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant)); pathForTurn.transform(m, pathForTurn);
} else if (turnImminent > 0) {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow));
} else if (turnImminent == 0) {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_imminent));
} else {
paintRouteDirection.setColor(getResources().getColor(R.color.nav_arrow_distant));
} }
// small indent }
canvas.translate(0, 3 * scaleCoefficient);
public void setTurnImminent(int turnImminent, boolean deviatedFromRoute) {
//if user deviates from route that we should draw grey arrow
this.turnImminent = turnImminent;
this.deviatedFromRoute = deviatedFromRoute;
if (deviatedFromRoute){
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
} else if (turnImminent > 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow));
} else if (turnImminent == 0) {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_imminent));
} else {
paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
}
}
@Override
public void draw(Canvas canvas) {
/// small indent
// canvas.translate(0, 3 * scaleCoefficient);
canvas.drawPath(pathForTurn, paintRouteDirection); canvas.drawPath(pathForTurn, paintRouteDirection);
canvas.drawPath(pathForTurn, paintBlack); canvas.drawPath(pathForTurn, paintBlack);
if (exitOut != null && !horisontalMini && !deviatedFromRoute) {
drawShadowText(canvas, exitOut, width / 2 - 7 * scaleCoefficient,
height / 2 + textPaint.getTextSize() / 2 - 3 * scaleCoefficient, textPaint);
}
String text = OsmAndFormatter.getFormattedDistance(nextTurnDirection, getClientContext());
String subtext = null;
if (deviatedFromRoute) {
text = OsmAndFormatter.getFormattedDistance((float) deviatedPath, (OsmandApplication)getContext().getApplicationContext());
}
int ls = text.lastIndexOf(' ');
float st = 0;
if (ls != -1) {
subtext = text.substring(ls + 1);
text = text.substring(0, ls);
st = textPaint.measureText(subtext);
}
float mt = textPaint.measureText(text);
if (!horisontalMini) {
float startX = Math.max((getWWidth() - st - mt) / 2, 2 * scaleCoefficient);
drawShadowText(canvas, text, startX, getWHeight() - 5 * scaleCoefficient, textPaint);
if (subtext != null) {
drawShadowText(canvas, subtext, startX + 2 * scaleCoefficient + mt, getWHeight() - 5 * scaleCoefficient, subtextPaint);
}
} else {
drawShadowText(canvas, text, 72 * scaleCoefficient / miniCoeff + 2 * scaleCoefficient,
height / 2 + 7 * scaleCoefficient, textPaint);
if (subtext != null) {
drawShadowText(canvas, subtext, 72 * scaleCoefficient / miniCoeff + mt
+ 2 * scaleCoefficient, height / 2 + 7 * scaleCoefficient, subtextPaint);
}
}
}
} }
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public void setAlpha(int alpha) {
return false; paintRouteDirection.setAlpha(alpha);
}
@Override
public void setColorFilter(ColorFilter cf) {
paintRouteDirection.setColorFilter(cf);
}
@Override
public int getOpacity() {
return 0;
}
public void setTurnType(TurnType turnType) {
this.turnType = turnType;
if(turnType != null) {
TurnPathHelper.calcTurnPath(pathForTurn, turnType, null);
onBoundsChange(getBounds());
}
}
} }
} }

View file

@ -31,7 +31,7 @@ import net.osmand.plus.views.TurnPathHelper;
import net.osmand.plus.views.controls.MapRouteInfoControl; import net.osmand.plus.views.controls.MapRouteInfoControl;
import net.osmand.router.RouteResultPreparation; import net.osmand.router.RouteResultPreparation;
import net.osmand.router.TurnType; import net.osmand.router.TurnType;
import net.osmand.util.Algorithms; import android.app.Activity;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -53,59 +53,40 @@ public class RouteInfoWidgetsFactory {
this.scaleCoefficient = scaleCoefficient; this.scaleCoefficient = scaleCoefficient;
} }
public NextTurnInfoWidget createNextInfoControl(final RoutingHelper routingHelper, final OsmandApplication ctx, public NextTurnInfoWidget createNextInfoControl(final Activity activity,
final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { final OsmandApplication app, boolean horisontalMini) {
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini, scaleCoefficient) { final OsmandSettings settings = app.getSettings();
final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini, scaleCoefficient) {
NextDirectionInfo calc1 = new NextDirectionInfo(); NextDirectionInfo calc1 = new NextDirectionInfo();
TurnType straight = TurnType.straight();
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
boolean visible = false; boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
boolean followingMode = routingHelper.isFollowingMode() || ctx.getLocationProvider().getLocationSimulation().isRouteAnimating(); TurnType turnType = null;
boolean deviatedFromRoute = false;
int turnImminent = 0;
int nextTurnDistance = 0;
if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) { if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute() ; deviatedFromRoute = routingHelper.isDeviatedFromRoute() ;
if (deviatedFromRoute) { if (deviatedFromRoute) {
visible = true;
turnImminent = 0; turnImminent = 0;
turnType = TurnType.valueOf(TurnType.OFFR, settings.DRIVING_REGION.get().leftHandDriving); turnType = TurnType.valueOf(TurnType.OFFR, settings.DRIVING_REGION.get().leftHandDriving);
TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform); setDeviatePath((int) routingHelper.getRouteDeviation());
deviatedPath = routingHelper.getRouteDeviation();
invalidate();
} else { } else {
boolean showStraight = false;
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true); NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (r != null && r.distanceTo > 0) { if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
visible = true; turnType = r.directionInfo.getTurnType();
if (r.directionInfo == null) { setExitOut(turnType.getExitOut());
if (turnType != null) { nextTurnDistance = r.distanceTo;
turnType = null;
invalidate();
}
} else if (!Algorithms.objectEquals(turnType, showStraight ? straight : r.directionInfo.getTurnType())) {
turnType = showStraight ? straight : r.directionInfo.getTurnType();
TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform);
if (turnType.getExitOut() > 0) {
exitOut = turnType.getExitOut() + ""; //$NON-NLS-1$
} else {
exitOut = null;
}
requestLayout();
invalidate();
}
if (distChanged(r.distanceTo, nextTurnDirection)) {
invalidate();
requestLayout();
nextTurnDirection = r.distanceTo;
}
if (turnImminent != r.imminent) {
turnImminent = r.imminent; turnImminent = r.imminent;
invalidate();
} }
} }
} }
} setTurnType(turnType);
updateVisibility(visible); setTurnImminent(turnImminent, deviatedFromRoute);
setTurnDistance(nextTurnDistance);
return true; return true;
} }
}; };
@ -130,31 +111,31 @@ public class RouteInfoWidgetsFactory {
// nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3; // nextTurnInfo.turnImminent = (nextTurnInfo.turnImminent + 1) % 3;
// nextTurnInfo.nextTurnDirection = 580; // nextTurnInfo.nextTurnDirection = 580;
// TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nextTurnInfo.turnType,nextTurnInfo.pathTransform); // TurnPathHelper.calcTurnPath(nextTurnInfo.pathForTurn, nextTurnInfo.turnType,nextTurnInfo.pathTransform);
// showMiniMap = true;
if(routingHelper.isRouteCalculated()) { if(routingHelper.isRouteCalculated()) {
routingHelper.getVoiceRouter().announceCurrentDirection(null); routingHelper.getVoiceRouter().announceCurrentDirection(null);
} }
nextTurnInfo.requestLayout();
nextTurnInfo.invalidate();
} }
}); });
// initial state // initial state
nextTurnInfo.setVisibility(View.GONE);
return nextTurnInfo; return nextTurnInfo;
} }
public NextTurnInfoWidget createNextNextInfoControl(final RoutingHelper routingHelper, final OsmandApplication ctx, public NextTurnInfoWidget createNextNextInfoControl(final Activity activity,
final OsmandSettings settings, Paint textPaint, Paint subtextPaint, boolean horisontalMini) { final OsmandApplication app, boolean horisontalMini) {
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(ctx, textPaint, subtextPaint, horisontalMini, scaleCoefficient) { final RoutingHelper routingHelper = app.getRoutingHelper();
final NextTurnInfoWidget nextTurnInfo = new NextTurnInfoWidget(activity, app, horisontalMini, scaleCoefficient) {
NextDirectionInfo calc1 = new NextDirectionInfo(); NextDirectionInfo calc1 = new NextDirectionInfo();
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
boolean visible = false; boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
boolean followingMode = routingHelper.isFollowingMode() || ctx.getLocationProvider().getLocationSimulation().isRouteAnimating(); TurnType turnType = null;
boolean deviatedFromRoute = false;
int turnImminent = 0;
int nextTurnDistance = 0;
if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) { if (routingHelper != null && routingHelper.isRouteCalculated() && followingMode) {
boolean devitedFromRoute = routingHelper.isDeviatedFromRoute() ; deviatedFromRoute = routingHelper.isDeviatedFromRoute() ;
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true); NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (!devitedFromRoute) { if (!deviatedFromRoute) {
if (r != null) { if (r != null) {
// next turn is very close (show next next with false to speak) // next turn is very close (show next next with false to speak)
// if (r.imminent >= 0 && r.imminent < 2) { // if (r.imminent >= 0 && r.imminent < 2) {
@ -167,33 +148,15 @@ public class RouteInfoWidgetsFactory {
// } // }
} }
} }
if (r != null && r.distanceTo > 0) { if (r != null && r.distanceTo > 0&& r.directionInfo != null) {
visible = true;
if (r == null || r.directionInfo == null) {
if (turnType != null) {
turnType = null;
invalidate();
}
} else if (!Algorithms.objectEquals(turnType, r.directionInfo.getTurnType())) {
turnType = r.directionInfo.getTurnType(); turnType = r.directionInfo.getTurnType();
TurnPathHelper.calcTurnPath(pathForTurn, turnType, pathTransform); turnImminent = r.imminent;
invalidate(); nextTurnDistance = r.distanceTo;
requestLayout();
}
if (distChanged(r.distanceTo, nextTurnDirection)) {
invalidate();
requestLayout();
nextTurnDirection = r.distanceTo;
}
int imminent = r.imminent;
if (turnImminent != imminent) {
turnImminent = imminent;
invalidate();
} }
} }
} setTurnType(turnType);
updateVisibility(visible); setTurnImminent(turnImminent, deviatedFromRoute);
setTurnDistance(nextTurnDistance);
return true; return true;
} }
}; };
@ -221,10 +184,14 @@ public class RouteInfoWidgetsFactory {
} }
}); });
// initial state // initial state
nextTurnInfo.setVisibility(View.GONE);
return nextTurnInfo; return nextTurnInfo;
} }
public TextInfoWidget createTimeControl(final MapActivity map){ public TextInfoWidget createTimeControl(final MapActivity map){
final RoutingHelper routingHelper = map.getRoutingHelper(); final RoutingHelper routingHelper = map.getRoutingHelper();
final Drawable time = map.getResources().getDrawable(R.drawable.widget_time); final Drawable time = map.getResources().getDrawable(R.drawable.widget_time);

View file

@ -17,11 +17,14 @@ public class TextInfoWidget {
private ImageView imageView; private ImageView imageView;
private TextView textView; private TextView textView;
private TextView smallTextView; private TextView smallTextView;
private ImageView topImageView;
private boolean explicitlyVisible; private boolean explicitlyVisible;
public TextInfoWidget(Activity activity) { public TextInfoWidget(Activity activity) {
view = activity.getLayoutInflater().inflate(R.layout.map_hud_widget, null); view = activity.getLayoutInflater().inflate(R.layout.map_hud_widget, null);
topImageView = (ImageView) view.findViewById(R.id.widget_top_icon);
imageView = (ImageView) view.findViewById(R.id.widget_icon); imageView = (ImageView) view.findViewById(R.id.widget_icon);
textView = (TextView) view.findViewById(R.id.widget_text); textView = (TextView) view.findViewById(R.id.widget_text);
smallTextView = (TextView) view.findViewById(R.id.widget_text_small); smallTextView = (TextView) view.findViewById(R.id.widget_text_small);
@ -41,6 +44,23 @@ public class TextInfoWidget {
imageView.invalidate(); imageView.invalidate();
} }
public void setTopImageDrawable(Drawable imageDrawable) {
if(imageDrawable != null) {
topImageView.setImageDrawable(imageDrawable);
topImageView.setVisibility(View.VISIBLE);
} else {
topImageView.setVisibility(View.INVISIBLE);
}
topImageView.invalidate();
}
protected void invalidateImageViews() {
topImageView.invalidate();
imageView.invalidate();
}
public void setContentDescription(CharSequence text) { public void setContentDescription(CharSequence text) {
if (contentTitle != null) { if (contentTitle != null) {
view.setContentDescription(contentTitle + " " + text); //$NON-NLS-1$ view.setContentDescription(contentTitle + " " + text); //$NON-NLS-1$