Refactor code; use new icons

This commit is contained in:
Alex Sytnyk 2018-05-15 21:46:30 +03:00
parent 1be2bab0ed
commit 2b86db3b30
3 changed files with 31 additions and 24 deletions

View file

@ -992,13 +992,11 @@ public class RouteCalculationResult {
return time;
}
public int getLeftTimeToNextIntermediate(Location fromLoc){
if(nextIntermediate >= intermediatePoints.length ){
public int getLeftTimeToNextIntermediate(Location fromLoc) {
if (nextIntermediate >= intermediatePoints.length) {
return 0;
} else {
return getLeftTime(fromLoc) - directions.get(intermediatePoints[nextIntermediate]).afterLeftTime;
}
return getLeftTime(fromLoc) - directions.get(intermediatePoints[nextIntermediate]).afterLeftTime;
}

View file

@ -303,7 +303,7 @@ public class MapControlsLayer extends OsmandMapLayer {
});
ImageView waypointsButton = (ImageView) main.findViewById(R.id.map_waypoints_route_button);
waypointsButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.map_action_flag_dark, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light));
waypointsButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_intermediate_destination, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light));
waypointsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View file

@ -202,26 +202,27 @@ public class RouteInfoWidgetsFactory {
public TimeControlWidgetState(OsmandApplication ctx, boolean intermediate) {
super(ctx);
this.intermediate = intermediate;
if (intermediate) {
showArrival = ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
} else {
showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
}
this.intermediate = intermediate;
}
@Override
public int getMenuTitleId() {
if (intermediate) {
return showArrival.get() ? R.string.access_intermediate_arrival_time : R.string.map_widget_intermediate_time;
} else {
return showArrival.get() ? R.string.access_arrival_time : R.string.map_widget_time;
}
return showArrival.get() ? R.string.access_arrival_time : R.string.map_widget_time;
}
@Override
public int getMenuIconId() {
if (intermediate) {
return R.drawable.ic_action_intermediate_destination_time;
}
return showArrival.get() ? R.drawable.ic_action_time : R.drawable.ic_action_time_to_distance;
}
@ -234,13 +235,15 @@ public class RouteInfoWidgetsFactory {
public int[] getMenuTitleIds() {
if (intermediate) {
return new int[]{R.string.access_intermediate_arrival_time, R.string.map_widget_intermediate_time};
} else {
return new int[]{R.string.access_arrival_time, R.string.map_widget_time};
}
return new int[]{R.string.access_arrival_time, R.string.map_widget_time};
}
@Override
public int[] getMenuIconIds() {
if (intermediate) {
return new int[]{R.drawable.ic_action_intermediate_destination_time, R.drawable.ic_action_intermediate_destination_time};
}
return new int[]{R.drawable.ic_action_time, R.drawable.ic_action_time_to_distance};
}
@ -262,22 +265,20 @@ public class RouteInfoWidgetsFactory {
final int timeToGo = R.drawable.widget_time_to_distance_day;
final int timeToGoN = R.drawable.widget_time_to_distance_night;
final OsmandApplication ctx = map.getMyApplication();
final OsmandPreference<Boolean> showArrival = intermediate?ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME
:ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
final OsmandPreference<Boolean> showArrival = intermediate
? ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME
: ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
final TextInfoWidget leftTimeControl = new TextInfoWidget(map) {
private long cachedLeftTime = 0;
@Override
public boolean updateInfo(DrawSettings drawSettings) {
setIcons(showArrival.get() ? time : timeToGo, showArrival.get() ? timeN : timeToGoN);
setTimeControlIcons(this, showArrival.get(), intermediate);
int time = 0;
if (routingHelper != null && routingHelper.isRouteCalculated()) {
//boolean followingMode = routingHelper.isFollowingMode();
if (intermediate) {
time = routingHelper.getLeftTimeNextIntermediate();
} else {
time = routingHelper.getLeftTime();
}
time = intermediate ? routingHelper.getLeftTimeNextIntermediate() : routingHelper.getLeftTime();
if (time != 0) {
if (/*followingMode && */showArrival.get()) {
@ -318,17 +319,25 @@ public class RouteInfoWidgetsFactory {
@Override
public void onClick(View v) {
showArrival.set(!showArrival.get());
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo,
showArrival.get() ? timeN : timeToGoN);
setTimeControlIcons(leftTimeControl, showArrival.get(), intermediate);
map.getMapView().refreshMap();
}
});
leftTimeControl.setText(null, null);
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo,
showArrival.get() ? timeN : timeToGoN);
setTimeControlIcons(leftTimeControl, showArrival.get(), intermediate);
return leftTimeControl;
}
private void setTimeControlIcons(TextInfoWidget timeControl, boolean showArrival, boolean intermediate) {
int iconLight = intermediate
? R.drawable.widget_intermediate_time_day
: showArrival ? R.drawable.widget_time_day : R.drawable.widget_time_to_distance_day;
int iconDark = intermediate
? R.drawable.widget_intermediate_time_night
: showArrival ? R.drawable.widget_time_night : R.drawable.widget_time_to_distance_night;
timeControl.setIcons(iconLight, iconDark);
}
public TextInfoWidget createPlainTimeControl(final MapActivity map){