Add icons for outdated location

This commit is contained in:
Alexander Sytnyk 2017-07-20 18:31:20 +03:00
parent 45629ef87d
commit 0d1053ed6c
3 changed files with 59 additions and 17 deletions

View file

@ -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;
}

View file

@ -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);

View file

@ -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;
@ -40,6 +41,8 @@ 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;
@ -60,8 +63,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
aroundArea.setStrokeWidth(1);
aroundArea.setAntiAlias(true);
updateIcons(view.getSettings().getApplicationMode(), false);
locationProvider = view.getApplication().getLocationProvider();
updateIcons(view.getSettings().getApplicationMode(), false, isLocationOutdated());
}
@Override
@ -70,7 +73,13 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
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);
@ -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;
@ -134,6 +147,11 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
}
}
if (updatesCounter == 20) {
updatesCounter = 0;
} else {
updatesCounter++;
}
}
public boolean isLocationVisible(RotatedTileBox tb, Location l) {
@ -145,10 +163,11 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
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() {