Add icons for outdated location
This commit is contained in:
parent
45629ef87d
commit
0d1053ed6c
3 changed files with 59 additions and 17 deletions
|
@ -123,6 +123,8 @@ public class ApplicationMode {
|
|||
applicationMode.headingIconNight = R.drawable.map_car_location_view_angle_night;
|
||||
applicationMode.locationIconDay = R.drawable.map_car_location;
|
||||
applicationMode.locationIconNight = R.drawable.map_car_location_night;
|
||||
applicationMode.locationIconDayLost = R.drawable.map_car_location_lost;
|
||||
applicationMode.locationIconNightLost = R.drawable.map_car_location_lost_night;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -138,6 +140,8 @@ public class ApplicationMode {
|
|||
applicationMode.headingIconNight = R.drawable.map_bicycle_location_view_angle_night;
|
||||
applicationMode.locationIconDay = R.drawable.map_bicycle_location;
|
||||
applicationMode.locationIconNight = R.drawable.map_bicycle_location_night;
|
||||
applicationMode.locationIconDayLost = R.drawable.map_bicycle_location_lost;
|
||||
applicationMode.locationIconNightLost = R.drawable.map_bicycle_location_lost_night;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -148,6 +152,8 @@ public class ApplicationMode {
|
|||
applicationMode.headingIconNight = R.drawable.map_default_location_view_angle_night;
|
||||
applicationMode.locationIconDay = R.drawable.map_pedestrian_location;
|
||||
applicationMode.locationIconNight = R.drawable.map_pedestrian_location_night;
|
||||
applicationMode.locationIconDayLost = R.drawable.map_pedestrian_location_lost;
|
||||
applicationMode.locationIconNightLost = R.drawable.map_pedestrian_location_lost_night;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -304,6 +310,14 @@ public class ApplicationMode {
|
|||
return locationIconNight;
|
||||
}
|
||||
|
||||
public int getResourceLocationDayLost() {
|
||||
return locationIconDayLost;
|
||||
}
|
||||
|
||||
public int getResourceLocationNightLost() {
|
||||
return locationIconNightLost;
|
||||
}
|
||||
|
||||
public String getStringKey() {
|
||||
return stringKey;
|
||||
}
|
||||
|
@ -364,5 +378,7 @@ public class ApplicationMode {
|
|||
private int headingIconNight = R.drawable.map_pedestrian_location_view_angle_night;
|
||||
private int locationIconDay = R.drawable.map_pedestrian_location;
|
||||
private int locationIconNight = R.drawable.map_pedestrian_location_night;
|
||||
private int locationIconDayLost = R.drawable.map_pedestrian_location_lost;
|
||||
private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night;
|
||||
private static StateChangedListener<String> listener;
|
||||
}
|
|
@ -49,6 +49,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
public static final String SIMULATED_PROVIDER = "OsmAnd";
|
||||
|
||||
public static final long LOCATION_SHELF_LIFE = 1000 * 60 * 60; // 60 minutes
|
||||
public static final long LOCATION_SHELF_LIFE_FOR_ICON = 1000 * 60 * 5; // 5 minutes
|
||||
|
||||
public interface OsmAndLocationListener {
|
||||
void updateLocation(net.osmand.Location location);
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.Paint;
|
|||
import android.graphics.Paint.Style;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -32,7 +33,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
private Paint aroundArea;
|
||||
|
||||
private OsmandMapTileView view;
|
||||
|
||||
|
||||
private ApplicationMode appMode;
|
||||
private Bitmap bearingIcon;
|
||||
private Bitmap headingIcon;
|
||||
|
@ -40,7 +41,9 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
private OsmAndLocationProvider locationProvider;
|
||||
private MapViewTrackingUtilities mapViewTrackingUtilities;
|
||||
private boolean nm;
|
||||
|
||||
private int updatesCounter;
|
||||
private boolean locationOutdated;
|
||||
|
||||
public PointLocationLayer(MapViewTrackingUtilities mv) {
|
||||
this.mapViewTrackingUtilities = mv;
|
||||
}
|
||||
|
@ -53,30 +56,36 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
|
||||
area = new Paint();
|
||||
area.setColor(view.getResources().getColor(R.color.pos_area));
|
||||
|
||||
|
||||
aroundArea = new Paint();
|
||||
aroundArea.setColor(view.getResources().getColor(R.color.pos_around));
|
||||
aroundArea.setStyle(Style.STROKE);
|
||||
aroundArea.setStrokeWidth(1);
|
||||
aroundArea.setAntiAlias(true);
|
||||
|
||||
updateIcons(view.getSettings().getApplicationMode(), false);
|
||||
|
||||
locationProvider = view.getApplication().getLocationProvider();
|
||||
updateIcons(view.getSettings().getApplicationMode(), false, isLocationOutdated());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
initUI();
|
||||
}
|
||||
|
||||
private boolean isLocationOutdated() {
|
||||
if (locationProvider.getLastKnownLocation() != null) {
|
||||
return System.currentTimeMillis() - locationProvider.getLastKnownLocation().getTime() >
|
||||
OsmAndLocationProvider.LOCATION_SHELF_LIFE_FOR_ICON;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private RectF getHeadingRect(int locationX, int locationY){
|
||||
int rad = (int) (view.getDensity() * 60);
|
||||
return new RectF(locationX - rad, locationY - rad, locationX + rad, locationY + rad);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) {
|
||||
if(box.getZoom() < 3) {
|
||||
|
@ -84,7 +93,11 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
}
|
||||
// draw
|
||||
boolean nm = nightMode != null && nightMode.isNightMode();
|
||||
updateIcons(view.getSettings().getApplicationMode(), nm);
|
||||
if (updatesCounter == 0) {
|
||||
updateIcons(view.getSettings().getApplicationMode(), nm, isLocationOutdated());
|
||||
} else {
|
||||
updateIcons(view.getSettings().getApplicationMode(), nm, false);
|
||||
}
|
||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||
if(lastKnownLocation == null || view == null){
|
||||
return;
|
||||
|
@ -103,7 +116,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
|
||||
final double dist = box.getDistance(0, box.getPixHeight() / 2, box.getPixWidth(), box.getPixHeight() / 2);
|
||||
int radius = (int) (((double) box.getPixWidth()) / dist * lastKnownLocation.getAccuracy());
|
||||
|
||||
|
||||
if (radius > RADIUS * box.getDensity()) {
|
||||
int allowedRad = Math.min(box.getPixWidth() / 2, box.getPixHeight() / 2);
|
||||
canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), area);
|
||||
|
@ -134,21 +147,27 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
}
|
||||
|
||||
}
|
||||
if (updatesCounter == 20) {
|
||||
updatesCounter = 0;
|
||||
} else {
|
||||
updatesCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLocationVisible(RotatedTileBox tb, Location l) {
|
||||
return l != null && tb.containsLatLon(l.getLatitude(), l.getLongitude());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
||||
|
||||
}
|
||||
public void updateIcons(ApplicationMode appMode, boolean nighMode) {
|
||||
if (appMode != this.appMode || this.nm != nighMode) {
|
||||
public void updateIcons(ApplicationMode appMode, boolean nighMode, boolean locationOutdated) {
|
||||
if (appMode != this.appMode || this.nm != nighMode || this.locationOutdated != locationOutdated) {
|
||||
this.appMode = appMode;
|
||||
this.nm = nighMode;
|
||||
this.locationOutdated = locationOutdated;
|
||||
final int resourceBearingDay = appMode.getResourceBearingDay();
|
||||
final int resourceBearingNight = appMode.getResourceBearingNight();
|
||||
final int resourceBearing = nighMode ? resourceBearingNight : resourceBearingDay;
|
||||
|
@ -159,13 +178,19 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
|||
final int resourceHeading = nighMode ? resourceHeadingNight : resourceHeadingDay;
|
||||
headingIcon = BitmapFactory.decodeResource(view.getResources(), resourceHeading);
|
||||
|
||||
final int resourceLocationDay = appMode.getResourceLocationDay();
|
||||
final int resourceLocationNight = appMode.getResourceLocationNight();
|
||||
final int resourceLocationDay;
|
||||
final int resourceLocationNight;
|
||||
if (locationOutdated) {
|
||||
resourceLocationDay = appMode.getResourceLocationDayLost();
|
||||
resourceLocationNight = appMode.getResourceLocationNightLost();
|
||||
} else {
|
||||
resourceLocationDay = appMode.getResourceLocationDay();
|
||||
resourceLocationNight = appMode.getResourceLocationNight();
|
||||
}
|
||||
final int resourceLocation = nighMode ? resourceLocationNight : resourceLocationDay;
|
||||
locationIcon = BitmapFactory.decodeResource(view.getResources(), resourceLocation);
|
||||
area.setColor(view.getResources().getColor(!nm ? R.color.pos_area : R.color.pos_area_night));
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
|
|
Loading…
Reference in a new issue