Fix widgets

This commit is contained in:
Victor Shcherb 2015-04-14 16:37:26 +03:00
parent ca263605fe
commit 9b364bf31b
13 changed files with 81 additions and 54 deletions

View file

@ -520,7 +520,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
recordControl = new TextInfoWidget(activity);
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
setRecordListener(recordControl, activity);
mapInfoLayer.registerSideWidget(recordControl, R.drawable.ic_action_micro_dark, R.drawable.widget_icon_av_inactive,
mapInfoLayer.registerSideWidget(recordControl, R.drawable.ic_action_micro_dark,
R.string.map_widget_av_notes, "audionotes", false, 22);
mapInfoLayer.recreateControls();
}
@ -539,13 +539,17 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
private void updateWidgetIcon(final TextInfoWidget recordPlaceControl) {
recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_inactive));
recordPlaceControl.setIcons(R.drawable.widget_icon_av_inactive_day,
R.drawable.widget_icon_av_inactive_night);
if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_VIDEO) {
recordPlaceControl.setImageDrawable(R.drawable.widget_icon_video);
recordPlaceControl.setIcons(R.drawable.widget_icon_video,
R.drawable.widget_icon_video);
} else if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_TAKEPICTURE) {
recordPlaceControl.setImageDrawable(R.drawable.widget_icon_photo);
recordPlaceControl.setIcons(R.drawable.widget_icon_video,
R.drawable.widget_icon_video);
} else if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_AUDIO) {
recordPlaceControl.setImageDrawable(R.drawable.widget_icon_audio);
recordPlaceControl.setIcons(R.drawable.widget_icon_audio,
R.drawable.widget_icon_audio);
}
}

View file

@ -65,7 +65,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
return true;
}
};
mapInfoLayer.registerSideWidget(fps, R.drawable.widget_no_icon, R.drawable.widget_no_icon,
mapInfoLayer.registerSideWidget(fps, R.drawable.widget_no_icon,
R.string.map_widget_fps_info, "fps", false, 30);
mapInfoLayer.recreateControls();
}
@ -78,7 +78,6 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
@Override
public int getLogoResourceId() {
// TODO
return R.drawable.ic_plugin_developer;
}

View file

@ -118,7 +118,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
if (mapInfoLayer != null ) {
distanceControl = createDistanceControl(activity);
mapInfoLayer.registerSideWidget(distanceControl,
R.drawable.ic_action_ruler_dark, R.drawable.widget_distance, R.string.map_widget_distancemeasurement, "distance.measurement", false, 21);
R.drawable.ic_action_ruler_dark, R.string.map_widget_distancemeasurement, "distance.measurement", false, 21);
mapInfoLayer.recreateControls();
updateText();
}
@ -390,7 +390,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
showDialog(activity);
}
});
distanceControl.setImageDrawable(R.drawable.widget_distance);
distanceControl.setIcons(R.drawable.widget_distance_day, R.drawable.widget_distance_night);
return distanceControl;
}

View file

@ -98,7 +98,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
monitoringControl = createMonitoringControl(activity);
layer.registerSideWidget(monitoringControl,
R.drawable.ic_action_play_dark, R.drawable.monitoring_rec_big, R.string.map_widget_monitoring, "monitoring", false, 18);
R.drawable.ic_action_play_dark, R.string.map_widget_monitoring, "monitoring", false, 18);
layer.recreateControls();
}

View file

@ -172,7 +172,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
MapInfoLayer layer = activity.getMapLayers().getMapInfoLayer();
osmoControl = createOsMoControl(activity);
layer.registerSideWidget(osmoControl,
R.drawable.ic_osmo_dark, R.drawable.mon_osmo_signal_inactive, R.string.osmo_control, "osmo_control", false, 18);
R.drawable.ic_osmo_dark, R.string.osmo_control, "osmo_control", false, 18);
layer.recreateControls();
if(olayer != null) {

View file

@ -191,7 +191,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
if (mapInfoLayer != null) {
parkingPlaceControl = createParkingPlaceInfoControl(activity);
mapInfoLayer.registerSideWidget(parkingPlaceControl,
R.drawable.ic_action_parking_dark, R.drawable.widget_parking, R.string.map_widget_parking, "parking", false, 8);
R.drawable.ic_action_parking_dark, R.string.map_widget_parking, "parking", false, 8);
mapInfoLayer.recreateControls();
}
}
@ -495,7 +495,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
}
});
parkingPlaceControl.setText(null, null);
parkingPlaceControl.setImageDrawable(R.drawable.widget_parking);
parkingPlaceControl.setIcons(R.drawable.widget_parking_day, R.drawable.widget_parking_night);
return parkingPlaceControl;
}

View file

@ -31,7 +31,6 @@ import net.osmand.util.MapUtils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.text.format.DateFormat;
import android.view.Gravity;
@ -201,7 +200,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
if (mapInfoLayer != null) {
routeStepsControl = createRouteStepsInfoControl(activity);
mapInfoLayer.registerSideWidget(routeStepsControl,
R.drawable.ic_action_signpost_dark, R.drawable.widget_signpost, R.string.map_widget_route_points, "route_steps", false, 8);
R.drawable.ic_action_signpost_dark, R.string.map_widget_route_points, "route_steps", false, 8);
mapInfoLayer.recreateControls();
}
}

View file

@ -82,9 +82,9 @@ public class MapInfoLayer extends OsmandMapLayer {
recreateControls();
}
public void registerSideWidget(TextInfoWidget widget, int drawableMenu, int drawableMap,
public void registerSideWidget(TextInfoWidget widget, int drawableMenu,
int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, drawableMenu, drawableMap, messageId, key, left, priorityOrder);
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, drawableMenu, messageId, key, left, priorityOrder);
updateReg(calculateTextState(), reg);
}
@ -105,29 +105,29 @@ public class MapInfoLayer extends OsmandMapLayer {
// register left stack
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn,"next_turn", true, 5);
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
registerSideWidget(smallInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn_small, "next_turn_small", true,
10);
NextTurnInfoWidget nextNextInfoControl = ric.createNextNextInfoControl(map, app, true);
registerSideWidget(nextNextInfoControl, R.drawable.ic_action_next_turn, R.drawable.widget_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
registerSideWidget(nextNextInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_next_turn, "next_next_turn",true, 15);
// right stack
TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map);
registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.drawable.widget_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 3);
TextInfoWidget dist = ric.createDistanceControl(map);
registerSideWidget(dist, R.drawable.ic_action_target, R.drawable.widget_target, R.string.map_widget_distance, "distance", false, 5);
registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, "distance", false, 5);
TextInfoWidget time = ric.createTimeControl(map);
registerSideWidget(time, R.drawable.ic_action_time, R.drawable.widget_time, R.string.map_widget_time, "time", false, 10);
registerSideWidget(time, R.drawable.ic_action_time, R.string.map_widget_time, "time", false, 10);
TextInfoWidget speed = ric.createSpeedControl(map);
registerSideWidget(speed, R.drawable.ic_action_speed, R.drawable.widget_speed, R.string.map_widget_speed, "speed", false, 15);
registerSideWidget(speed, R.drawable.ic_action_speed, R.string.map_widget_speed, "speed", false, 15);
TextInfoWidget gpsInfo = mic.createGPSInfoControl(map);
registerSideWidget(gpsInfo, R.drawable.ic_action_gps_info, R.drawable.widget_gps_info, R.string.map_widget_gps_info, "gps_info", false, 17);
registerSideWidget(gpsInfo, R.drawable.ic_action_gps_info, R.string.map_widget_gps_info, "gps_info", false, 17);
TextInfoWidget maxspeed = ric.createMaxSpeedControl(map);
registerSideWidget(maxspeed, R.drawable.ic_action_max_speed, R.drawable.widget_max_speed, R.string.map_widget_max_speed, "max_speed", false, 18);
registerSideWidget(maxspeed, R.drawable.ic_action_max_speed, R.string.map_widget_max_speed, "max_speed", false, 18);
TextInfoWidget alt = mic.createAltitudeControl(map);
registerSideWidget(alt, R.drawable.ic_action_altitude, R.drawable.widget_altitude, R.string.map_widget_altitude, "altitude", false, 20);
registerSideWidget(alt, R.drawable.ic_action_altitude, R.string.map_widget_altitude, "altitude", false, 20);
TextInfoWidget plainTime = ric.createPlainTimeControl(map);
registerSideWidget(plainTime, R.drawable.ic_action_time_to_distance, R.drawable.widget_time_to_distance, R.string.map_widget_plain_time, "plain_time", false, 25);
registerSideWidget(plainTime, R.drawable.ic_action_time_to_distance, R.string.map_widget_plain_time, "plain_time", false, 25);
}
@ -155,6 +155,7 @@ public class MapInfoLayer extends OsmandMapLayer {
private static class TextState {
boolean textBold ;
boolean night;
int textColor ;
int textShadowColor ;
int boxTop;
@ -202,6 +203,7 @@ public class MapInfoLayer extends OsmandMapLayer {
if(v != null) {
v.setBackgroundResource(reg.left ? ts.leftRes : ts.rightRes);
reg.widget.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
reg.widget.updateIconMode(ts.night);
}
}
@ -211,6 +213,7 @@ public class MapInfoLayer extends OsmandMapLayer {
boolean following = routeLayer.getHelper().isFollowingMode();
TextState ts = new TextState();
ts.textBold = following;
ts.night = nightMode;
ts.textColor = nightMode ? view.getResources().getColor(R.color.widgettext_night) : Color.BLACK;
// Night shadowColor always use widgettext_shadow_night, same as widget background color for non-transparent
// night skin (from box_night_free_simple.9.png)

View file

@ -105,19 +105,20 @@ public class PointLocationLayer extends OsmandMapLayer {
if (isLocationVisible(box, lastKnownLocation)) {
checkAppMode(view.getSettings().getApplicationMode());
boolean isBearing = lastKnownLocation.hasBearing();
if (!isBearing) {
canvas.drawBitmap(locationIcon, locationX - locationIcon.getWidth() / 2, locationY - locationIcon.getHeight() / 2,
locationPaint);
}
Float heading = locationProvider.getHeading();
if (heading != null && mapViewTrackingUtilities.isShowViewAngle()) {
canvas.drawArc(getHeadingRect(locationX, locationY), heading - HEADING_ANGLE / 2 - 90, HEADING_ANGLE, true, headingPaint);
canvas.drawArc(getHeadingRect(locationX, locationY), heading - HEADING_ANGLE / 2 - 90, HEADING_ANGLE,
true, headingPaint);
}
if (isBearing) {
float bearing = lastKnownLocation.getBearing();
canvas.rotate(bearing - 90, locationX, locationY);
canvas.drawBitmap(bearingIcon, locationX - bearingIcon.getWidth() / 2, locationY - bearingIcon.getHeight() / 2,
locationPaint);
canvas.drawBitmap(bearingIcon, locationX - bearingIcon.getWidth() / 2,
locationY - bearingIcon.getHeight() / 2, locationPaint);
} else {
canvas.drawBitmap(locationIcon, locationX - locationIcon.getWidth() / 2,
locationY - locationIcon.getHeight() / 2, locationPaint);
}
}

View file

@ -70,7 +70,7 @@ public class MapInfoWidgetsFactory {
}
};
altitudeControl.setText(null, null);
altitudeControl.setImageDrawable(R.drawable.widget_altitude);
altitudeControl.setIcons(R.drawable.widget_altitude_day, R.drawable.widget_altitude_night);
return altitudeControl;
}
@ -93,7 +93,7 @@ public class MapInfoWidgetsFactory {
return false;
}
};
gpsInfoControl.setImageDrawable(R.drawable.widget_gps_info);
gpsInfoControl.setIcons(R.drawable.widget_gps_info_day, R.drawable.widget_gps_info_night);
gpsInfoControl.setText(null, null);
gpsInfoControl.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -89,9 +89,9 @@ public class MapWidgetRegistry {
}
}
}
public MapWidgetRegInfo registerSideWidgetInternal(TextInfoWidget widget, int drawableMenu, int drawableMap,
public MapWidgetRegInfo registerSideWidgetInternal(TextInfoWidget widget, int drawableMenu,
int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo ii = new MapWidgetRegInfo(key, widget, drawableMenu, drawableMap,
MapWidgetRegInfo ii = new MapWidgetRegInfo(key, widget, drawableMenu,
messageId, priorityOrder, left);
for (ApplicationMode ms : ApplicationMode.values(settings)) {
boolean collapse = ms.isWidgetCollapsible(key);
@ -309,7 +309,6 @@ public class MapWidgetRegistry {
public static class MapWidgetRegInfo implements Comparable<MapWidgetRegInfo> {
public final TextInfoWidget widget;
public final int drawableMenu;
public final int drawableMap;
public final int messageId;
public final String key;
public final boolean left;
@ -319,12 +318,10 @@ public class MapWidgetRegistry {
private Runnable stateChangeListener = null;
public MapWidgetRegInfo(String key, TextInfoWidget widget, int drawableMenu,
int drawableMap, int messageId, int priorityOrder,
boolean left) {
int messageId, int priorityOrder, boolean left) {
this.key = key;
this.widget = widget;
this.drawableMenu = drawableMenu;
this.drawableMap = drawableMap;
this.messageId = messageId;
this.priorityOrder = priorityOrder;
this.left = left;

View file

@ -196,8 +196,10 @@ public class RouteInfoWidgetsFactory {
public TextInfoWidget createTimeControl(final MapActivity map){
final RoutingHelper routingHelper = map.getRoutingHelper();
final int time = R.drawable.widget_time;
final int timeToGo = R.drawable.widget_time_to_distance;
final int time = R.drawable.widget_time_day;
final int timeN = R.drawable.widget_time_night;
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 = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME;
final TextInfoWidget leftTimeControl = new TextInfoWidget(map) {
@ -248,13 +250,15 @@ public class RouteInfoWidgetsFactory {
@Override
public void onClick(View v) {
showArrival.set(!showArrival.get());
leftTimeControl.setImageDrawable(showArrival.get()? time : timeToGo);
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo,
showArrival.get() ? timeN : timeToGoN);
map.getMapView().refreshMap();
}
});
leftTimeControl.setText(null, null);
leftTimeControl.setImageDrawable(showArrival.get()? time : timeToGo);
leftTimeControl.setIcons(showArrival.get() ? time : timeToGo,
showArrival.get() ? timeN : timeToGoN);
return leftTimeControl;
}
@ -280,7 +284,7 @@ public class RouteInfoWidgetsFactory {
};
};
plainTimeControl.setText(null, null);
plainTimeControl.setImageDrawable(R.drawable.widget_time_to_distance);
plainTimeControl.setIcons(R.drawable.widget_time_to_distance_day, R.drawable.widget_time_to_distance_night);
return plainTimeControl;
}
@ -323,7 +327,7 @@ public class RouteInfoWidgetsFactory {
return false;
}
};
speedControl.setImageDrawable(R.drawable.widget_max_speed);
speedControl.setIcons(R.drawable.widget_max_speed_day, R.drawable.widget_max_speed_night);
speedControl.setText(null, null);
return speedControl;
}
@ -367,7 +371,7 @@ public class RouteInfoWidgetsFactory {
return false;
}
};
speedControl.setImageDrawable(R.drawable.widget_speed);
speedControl.setIcons(R.drawable.widget_speed_day, R.drawable.widget_speed_night);
speedControl.setText(null, null);
return speedControl;
}
@ -378,10 +382,10 @@ public class RouteInfoWidgetsFactory {
private float[] calculations = new float[1];
private int cachedMeters;
public DistanceToPointInfoControl(MapActivity ma, int res) {
public DistanceToPointInfoControl(MapActivity ma, int res, int resNight) {
super(ma);
this.view = ma.getMapView();
setImageDrawable(res);
setIcons(res, resNight);
setText(null, null);
setOnClickListener(new View.OnClickListener() {
@ -437,7 +441,8 @@ public class RouteInfoWidgetsFactory {
}
public TextInfoWidget createDistanceControl(final MapActivity map) {
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map,R.drawable.widget_target) {
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map,R.drawable.widget_target_day,
R.drawable.widget_target_night) {
@Override
public LatLon getPointToNavigate() {
TargetPoint p = map.getPointToNavigate();
@ -457,7 +462,8 @@ public class RouteInfoWidgetsFactory {
public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, R.drawable.widget_intermediate) {
DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, R.drawable.widget_intermediate_day,
R.drawable.widget_intermediate_night) {
@Override
protected void click(OsmandMapTileView view) {

View file

@ -23,6 +23,9 @@ public class TextInfoWidget {
private boolean explicitlyVisible;
private OsmandApplication app;
private int dayIcon;
private int nightIcon;
private boolean isNight;
public TextInfoWidget(Activity activity) {
@ -72,6 +75,12 @@ public class TextInfoWidget {
topImageView.invalidate();
}
public void setIcons(int widgetDayIcon, int widgetNightIcon) {
dayIcon = widgetDayIcon;
nightIcon = widgetNightIcon;
setImageDrawable(!isNight ? dayIcon : nightIcon);
}
@ -155,6 +164,13 @@ public class TextInfoWidget {
return explicitlyVisible;
}
public void updateIconMode(boolean night) {
isNight = night;
if(dayIcon != 0) {
setImageDrawable(!night? dayIcon : nightIcon);
}
}
public void updateTextColor(int textColor, int textShadowColor, boolean bold, int rad) {
updateTextColor(smallTextView, textColor, textShadowColor, bold, rad);
updateTextColor(textView, textColor, textShadowColor, bold, rad);
@ -169,4 +185,6 @@ public class TextInfoWidget {
}