Skip to content

Commit

Permalink
Fix tests broken from updated fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
danesfeder committed Apr 19, 2018
1 parent 52234b7 commit 8d04e83
Show file tree
Hide file tree
Showing 16 changed files with 503 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class InstructionModel {
private InstructionStepResources stepResources;
private RouteProgress progress;
private Locale locale;
private @NavigationUnitType.UnitType int unitType;
@NavigationUnitType.UnitType
private int unitType;

public InstructionModel(Context context, RouteProgress progress,
Locale locale, @NavigationUnitType.UnitType int unitType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,9 @@ public void onClick(View instructionLayoutText) {
* @param model provides maneuver modifier / type
*/
private void updateManeuverView(InstructionModel model) {
upcomingManeuverView.setManeuverModifier(model.getStepResources().getManeuverViewModifier());
upcomingManeuverView.setManeuverType(model.getStepResources().getManeuverViewType());
String maneuverViewType = model.getStepResources().getManeuverViewType();
String maneuverViewModifier = model.getStepResources().getManeuverViewModifier();
upcomingManeuverView.setManeuverTypeAndModifier(maneuverViewType, maneuverViewModifier);
if (model.getRoundaboutAngle() != null) {
upcomingManeuverView.setRoundaboutAngle(model.getRoundaboutAngle());
}
Expand Down Expand Up @@ -742,8 +743,9 @@ private void hideTurnLanes() {
*/
private void updateThenStep(InstructionModel model) {
if (shouldShowThenStep(model)) {
thenManeuverView.setManeuverType(model.getStepResources().getThenStepManeuverType());
thenManeuverView.setManeuverModifier(model.getStepResources().getThenStepManeuverModifier());
String thenStepManeuverType = model.getStepResources().getThenStepManeuverType();
String thenStepManeuverModifier = model.getStepResources().getThenStepManeuverModifier();
thenManeuverView.setManeuverTypeAndModifier(thenStepManeuverType, thenStepManeuverModifier);
thenStepText.setText(model.getThenBannerText().text());
showThenStepLayout();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.support.annotation.Nullable;
import android.support.v4.util.Pair;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;

import com.mapbox.services.android.navigation.ui.v5.R;
import com.mapbox.services.android.navigation.ui.v5.ThemeSwitcher;
import com.mapbox.services.android.navigation.v5.navigation.NavigationConstants;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.ManeuverModifier;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.ManeuverType;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_LEFT;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_RIGHT;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_LEFT;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_SHARP_RIGHT;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_LEFT;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_MODIFIER_UTURN;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_TYPE_ARRIVE;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_TYPE_EXIT_ROTARY;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_TYPE_FORK;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_TYPE_OFF_RAMP;
import static com.mapbox.services.android.navigation.v5.navigation.NavigationConstants.STEP_MANEUVER_TYPE_ROTARY;
Expand All @@ -35,14 +37,39 @@
*/
public class ManeuverView extends View {

private static final Map<Pair<String, String>, ManeuverViewUpdate> MANEUVER_VIEW_UPDATE_MAP = new ManeuverViewMap();
private static final Set<String> SHOULD_FLIP_MODIFIERS = new HashSet<String>() {
{
add(STEP_MANEUVER_MODIFIER_SLIGHT_LEFT);
add(STEP_MANEUVER_MODIFIER_LEFT);
add(STEP_MANEUVER_MODIFIER_SHARP_LEFT);
}
};
private static final Set<String> ROUNDABOUT_MANEUVER_TYPES = new HashSet<String>() {
{
add(STEP_MANEUVER_TYPE_ROTARY);
add(STEP_MANEUVER_TYPE_ROUNDABOUT);
add(STEP_MANEUVER_TYPE_ROUNDABOUT_TURN);
}
};
private static final Set<String> MANEUVER_TYPES_WITH_NULL_MODIFIERS = new HashSet<String>() {
{
add(STEP_MANEUVER_TYPE_OFF_RAMP);
add(STEP_MANEUVER_TYPE_FORK);
add(STEP_MANEUVER_TYPE_ROUNDABOUT);
add(STEP_MANEUVER_TYPE_ROUNDABOUT_TURN);
add(STEP_MANEUVER_TYPE_ROTARY);
add(STEP_MANEUVER_TYPE_EXIT_ROTARY);
}
};

@ManeuverType
String maneuverType = "";
private String maneuverType = null;
@ManeuverModifier
String maneuverModifier = "";

private String maneuverModifier = null;
private Pair<String, String> maneuverTypeAndModifier = new Pair<>(null, null);
private int primaryColor;
private int secondaryColor;

private float roundaboutAngle;
private PointF size;

Expand All @@ -65,29 +92,21 @@ protected void onFinishInflate() {
initManeuverColor();
}

private void initManeuverColor() {
this.primaryColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewBannerManeuverPrimary);
this.secondaryColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewBannerManeuverSecondary);
}

public void setManeuverType(String maneuverType) {
if (!TextUtils.equals(this.maneuverType, maneuverType)) {
public void setManeuverTypeAndModifier(String maneuverType, String maneuverModifier) {
if (isNewTypeOrModifier(maneuverType, maneuverModifier)) {
this.maneuverType = maneuverType;
invalidate();
}
}

public void setManeuverModifier(String maneuverModifier) {
if (!TextUtils.equals(this.maneuverModifier, maneuverModifier)) {
this.maneuverModifier = maneuverModifier;
if (checkManeuverTypeWithNullModifier(maneuverType)) {
return;
}
maneuverType = checkManeuverModifier(maneuverType, maneuverModifier);
maneuverTypeAndModifier = new Pair<>(maneuverType, maneuverModifier);
invalidate();
}
}

public void setRoundaboutAngle(float roundaboutAngle) {
if (isRoundabout() && this.roundaboutAngle != roundaboutAngle) {
if (ROUNDABOUT_MANEUVER_TYPES.contains(maneuverType) && this.roundaboutAngle != roundaboutAngle) {
this.roundaboutAngle = roundaboutAngle;
invalidate();
}
Expand All @@ -114,108 +133,40 @@ protected void onDraw(Canvas canvas) {
return;
}

boolean flip = false;

switch (maneuverType) {
case NavigationConstants.STEP_MANEUVER_TYPE_MERGE:
ManeuversStyleKit.drawMerge(canvas, primaryColor, secondaryColor, size);
flip = shouldFlip(maneuverModifier);
break;

case STEP_MANEUVER_TYPE_OFF_RAMP:
ManeuversStyleKit.drawOffRamp(canvas, primaryColor, secondaryColor, size);
flip = shouldFlip(maneuverModifier);
break;

case STEP_MANEUVER_TYPE_FORK:
ManeuversStyleKit.drawFork(canvas, primaryColor, secondaryColor, size);
flip = shouldFlip(maneuverModifier);
break;

case STEP_MANEUVER_TYPE_ROUNDABOUT:
case STEP_MANEUVER_TYPE_ROUNDABOUT_TURN:
case STEP_MANEUVER_TYPE_ROTARY:
ManeuversStyleKit.drawRoundabout(canvas, primaryColor, secondaryColor, size, roundaboutAngle);
break;

case STEP_MANEUVER_TYPE_ARRIVE:
if (maneuverModifier != null) {
switch (maneuverModifier) {
case STEP_MANEUVER_MODIFIER_RIGHT:
ManeuversStyleKit.drawArriveRight(canvas, primaryColor, size);
flip = false;
break;

case STEP_MANEUVER_MODIFIER_LEFT:
ManeuversStyleKit.drawArriveRight(canvas, primaryColor, size);
flip = true;
break;

default:
ManeuversStyleKit.drawArrive(canvas, primaryColor, size);
}
} else {
ManeuversStyleKit.drawArrive(canvas, primaryColor, size);
}
break;

default:
if (maneuverModifier != null) {
switch (maneuverModifier) {
case STEP_MANEUVER_MODIFIER_SLIGHT_RIGHT:
ManeuversStyleKit.drawArrowSlightRight(canvas, primaryColor, size);
flip = false;
break;

case STEP_MANEUVER_MODIFIER_RIGHT:
ManeuversStyleKit.drawArrowRight(canvas, primaryColor, size);
flip = false;
break;

case STEP_MANEUVER_MODIFIER_SHARP_RIGHT:
ManeuversStyleKit.drawArrowSharpRight(canvas, primaryColor, size);
flip = false;
break;

case STEP_MANEUVER_MODIFIER_SLIGHT_LEFT:
ManeuversStyleKit.drawArrowSlightRight(canvas, primaryColor, size);
flip = true;
break;

case STEP_MANEUVER_MODIFIER_LEFT:
ManeuversStyleKit.drawArrowRight(canvas, primaryColor, size);
flip = true;
break;

case STEP_MANEUVER_MODIFIER_SHARP_LEFT:
ManeuversStyleKit.drawArrowSharpRight(canvas, primaryColor, size);
flip = true;
break;

case STEP_MANEUVER_MODIFIER_UTURN:
ManeuversStyleKit.drawArrow180Right(canvas, primaryColor, size);
flip = true;
break;

default:
ManeuversStyleKit.drawArrowStraight(canvas, primaryColor, size);
}
} else {
ManeuversStyleKit.drawArrowStraight(canvas, primaryColor, size);
}
ManeuverViewUpdate maneuverViewUpdate = MANEUVER_VIEW_UPDATE_MAP.get(maneuverTypeAndModifier);
if (maneuverViewUpdate != null) {
maneuverViewUpdate.updateManeuverView(canvas, primaryColor, secondaryColor, size, roundaboutAngle);
}
boolean flip = SHOULD_FLIP_MODIFIERS.contains(maneuverModifier);
setScaleX(flip ? -1 : 1);
}

private boolean shouldFlip(String modifier) {
return modifier.contains(STEP_MANEUVER_MODIFIER_SLIGHT_LEFT)
|| modifier.contains(STEP_MANEUVER_MODIFIER_LEFT)
|| modifier.contains(STEP_MANEUVER_MODIFIER_SHARP_LEFT);
private void initManeuverColor() {
this.primaryColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewBannerManeuverPrimary);
this.secondaryColor = ThemeSwitcher.retrieveNavigationViewThemeColor(getContext(),
R.attr.navigationViewBannerManeuverSecondary);
}

private boolean isRoundabout() {
return maneuverType.equals(NavigationConstants.STEP_MANEUVER_TYPE_ROTARY)
|| maneuverType.equals(NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT)
|| maneuverType.equals(NavigationConstants.STEP_MANEUVER_TYPE_ROUNDABOUT_TURN);
private boolean isNewTypeOrModifier(String maneuverType, String maneuverModifier) {
return !TextUtils.equals(this.maneuverType, maneuverType)
|| !TextUtils.equals(this.maneuverModifier, maneuverModifier);
}

private boolean checkManeuverTypeWithNullModifier(String maneuverType) {
if (MANEUVER_TYPES_WITH_NULL_MODIFIERS.contains(maneuverType)) {
maneuverTypeAndModifier = new Pair<>(maneuverType, null);
invalidate();
return true;
}
return false;
}

@Nullable
private String checkManeuverModifier(String maneuverType, String maneuverModifier) {
if (!maneuverType.contentEquals(STEP_MANEUVER_TYPE_ARRIVE) && maneuverModifier != null) {
maneuverType = null;
}
return maneuverType;
}
}
Loading

0 comments on commit 8d04e83

Please sign in to comment.