Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-10-23 18:56:31 +02:00
commit 69b8f26fcf
14 changed files with 874 additions and 206 deletions

View file

@ -1,9 +1,7 @@
package net.osmand.plus; package net.osmand.plus;
import net.osmand.PlatformUtil;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmo.OsMoPlugin;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Notification;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
@ -22,6 +20,10 @@ import android.support.v4.app.NotificationCompat.Builder;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.plus.notifications.OsmandNotification;
import net.osmand.plus.osmo.OsMoPlugin;
public class NavigationService extends Service implements LocationListener { public class NavigationService extends Service implements LocationListener {
public static class NavigationServiceBinder extends Binder { public static class NavigationServiceBinder extends Binder {
@ -99,6 +101,8 @@ public class NavigationService extends Service implements LocationListener {
if (usedBy == 0) { if (usedBy == 0) {
final Intent serviceIntent = new Intent(ctx, NavigationService.class); final Intent serviceIntent = new Intent(ctx, NavigationService.class);
ctx.stopService(serviceIntent); ctx.stopService(serviceIntent);
} else {
((OsmandApplication) getApplication()).getNotificationHelper().refreshNotifications();
} }
} }
@ -147,9 +151,14 @@ public class NavigationService extends Service implements LocationListener {
// registering icon at top level // registering icon at top level
// Leave icon visible even for navigation for proper display // Leave icon visible even for navigation for proper display
Builder ntf = app.getNotificationHelper().buildNotificationInStatusBar(); OsmandNotification osmandNotification = app.getNotificationHelper().getTopNotification();
if (ntf != null) { if (osmandNotification != null) {
startForeground(NotificationHelper.NOTIFICATION_SERVICE_ID, ntf.build()); Builder notification = osmandNotification.buildNotification();
if (notification != null) {
Notification n = notification.build();
osmandNotification.setupNotification(n);
startForeground(osmandNotification.getUniqueId(), n);
}
} }
return START_REDELIVER_INTENT; return START_REDELIVER_INTENT;
} }
@ -170,7 +179,8 @@ public class NavigationService extends Service implements LocationListener {
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
((OsmandApplication) getApplication()).setNavigationService(null); final OsmandApplication app = (OsmandApplication) getApplication();
app.setNavigationService(null);
usedBy = 0; usedBy = 0;
// remove updates // remove updates
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
@ -190,8 +200,13 @@ public class NavigationService extends Service implements LocationListener {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent); alarmManager.cancel(pendingIntent);
// remove notification // remove notification
((OsmandApplication) getApplication()).getNotificationHelper().removeServiceNotification();
stopForeground(Boolean.TRUE); stopForeground(Boolean.TRUE);
app.runInUIThread(new Runnable() {
@Override
public void run() {
app.getNotificationHelper().refreshNotifications();
}
}, 500);
} }
@Override @Override
@ -242,7 +257,7 @@ public class NavigationService extends Service implements LocationListener {
plugin.getTracker().disableTracker(); plugin.getTracker().disableTracker();
} }
} }
app.getNotificationHelper().removeServiceNotificationCompletely(); //app.getNotificationHelper().removeNotifications();
NavigationService.this.stopSelf(); NavigationService.this.stopSelf();
} }
} }

View file

@ -1,180 +1,91 @@
package net.osmand.plus; package net.osmand.plus;
import android.app.NotificationManager; import net.osmand.plus.notifications.GpsWakeUpNotification;
import android.app.PendingIntent; import net.osmand.plus.notifications.GpxNotification;
import android.content.BroadcastReceiver; import net.osmand.plus.notifications.NavigationNotification;
import android.content.Context; import net.osmand.plus.notifications.OsMoNotification;
import android.content.Intent; import net.osmand.plus.notifications.OsmandNotification;
import android.content.IntentFilter; import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v7.app.NotificationCompat;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
public class NotificationHelper { public class NotificationHelper {
public final static int NOTIFICATION_SERVICE_ID = 5;
public final static String OSMAND_STOP_SERVICE_ACTION = "OSMAND_STOP_SERVICE_ACTION"; //$NON-NLS-1$
public final static String OSMAND_STOP_GPX_SERVICE_ACTION = "OSMAND_STOP_GPX_SERVICE_ACTION"; //$NON-NLS-1$
public final static String OSMAND_START_GPX_SERVICE_ACTION = "OSMAND_START_GPX_SERVICE_ACTION"; //$NON-NLS-1$
public final static String OSMAND_SAVE_GPX_SERVICE_ACTION = "OSMAND_SAVE_GPX_SERVICE_ACTION"; //$NON-NLS-1$
private OsmandApplication app; private OsmandApplication app;
private BroadcastReceiver saveBroadcastReceiver;
private BroadcastReceiver stopBroadcastReceiver; private NavigationNotification navigationNotification;
private BroadcastReceiver startBroadcastReceiver; private GpxNotification gpxNotification;
private OsMoNotification osMoNotification;
private GpsWakeUpNotification gpsWakeUpNotification;
public NotificationHelper(OsmandApplication app) { public NotificationHelper(OsmandApplication app) {
this.app = app; this.app = app;
init(); init();
} }
public GpsWakeUpNotification getGpsWakeUpNotification() {
return gpsWakeUpNotification;
}
private void init() { private void init() {
saveBroadcastReceiver = new BroadcastReceiver() { navigationNotification = new NavigationNotification(app);
gpxNotification = new GpxNotification(app);
@Override osMoNotification = new OsMoNotification(app);
public void onReceive(Context context, Intent intent) { gpsWakeUpNotification = new GpsWakeUpNotification(app);
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.saveCurrentTrack();
}
}
};
app.registerReceiver(saveBroadcastReceiver, new IntentFilter(OSMAND_SAVE_GPX_SERVICE_ACTION));
startBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.startGPXMonitoring(null);
}
}
};
app.registerReceiver(startBroadcastReceiver, new IntentFilter(OSMAND_START_GPX_SERVICE_ACTION));
stopBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.stopRecording();
}
}
};
app.registerReceiver(stopBroadcastReceiver, new IntentFilter(OSMAND_STOP_GPX_SERVICE_ACTION));
} }
public Builder buildNotificationInStatusBar() { public OsmandNotification getTopNotification() {
NavigationService service = app.getNavigationService(); if (navigationNotification.isEnabled()) {
String notificationText = ""; return navigationNotification;
int icon = R.drawable.bgs_icon; } else if (gpxNotification.isEnabled() && gpxNotification.isActive()) {
OsmandMonitoringPlugin monitoringPlugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); return gpxNotification;
if (service != null) { } else if (gpsWakeUpNotification.isEnabled()) {
int soi = service.getServiceOffInterval(); return gpsWakeUpNotification;
notificationText = app.getString(R.string.osmand_running_in_background); } else if (osMoNotification.isEnabled()) {
String s = ""; return osMoNotification;
if ((service.getUsedBy() & NavigationService.USED_BY_NAVIGATION) != 0) { }
if (s.length() > 0) { return null;
s += ", "; }
}
s += app.getString(R.string.shared_string_navigation).toLowerCase(); public void showNotifications() {
} boolean navNotificationVisible = navigationNotification.showNotification();
if ((service.getUsedBy() & NavigationService.USED_BY_GPX) != 0) { gpxNotification.showNotification();
if (s.length() > 0) { osMoNotification.showNotification();
s += ", "; if (!navNotificationVisible && !gpxNotification.isActive()) {
} gpsWakeUpNotification.showNotification();
s += app.getString(R.string.shared_string_trip_recording).toLowerCase() }
+ ": " + OsmAndFormatter.getFormattedDistance(app.getSavingTrackHelper().getDistance(), app); }
}
if ((service.getUsedBy() & NavigationService.USED_BY_LIVE) != 0) { public void refreshNotification(NotificationType notificationType) {
if (s.length() > 0) { switch (notificationType) {
s += ", "; case NAVIGATION:
} navigationNotification.refreshNotification();
s += app.getString(R.string.osmo); break;
} case GPX:
if(s.length() > 0) { gpxNotification.refreshNotification();
notificationText += " (" + s + "). "; break;
} case OSMO:
notificationText += app.getString(R.string.gps_wake_up_timer) + ": "; osMoNotification.refreshNotification();
if (soi == 0) { break;
notificationText = notificationText + app.getString(R.string.int_continuosly); case GPS:
} else if (soi <= 90000) { gpsWakeUpNotification.refreshNotification();
notificationText = notificationText + Integer.toString(soi / 1000) + " " + app.getString(R.string.int_seconds); break;
} else { }
notificationText = notificationText + Integer.toString(soi / 1000 / 60) + " " + app.getString(R.string.int_min); }
}
//} else if(monitoringPlugin == null) { public void refreshNotifications() {
// return null; boolean navNotificationVisible = navigationNotification.refreshNotification();
//} else if(app.getSavingTrackHelper().getDistance() > 0f){ gpxNotification.refreshNotification();
//This produces system notification if unsaved GPX track exists, displaying recorded distance. But only while OsmAnd is in the foreground and while recording has been stopped (otherwise background notification caries this info anyway) osMoNotification.refreshNotification();
//Purpose is doubtful, we have widget for that. If we re-instate, we need to implement notification refresh upon track saved, maybe also work on notification wording to clarify meaning. if (!navNotificationVisible && !gpxNotification.isActive()) {
// notificationText = app.getString(R.string.shared_string_trip_recording); gpsWakeUpNotification.refreshNotification();
// float dst = app.getSavingTrackHelper().getDistance();
// notificationText += ": "+OsmAndFormatter.getFormattedDistance(dst, app);
// icon = R.drawable.ic_action_polygom_dark;
} else { } else {
return null; gpsWakeUpNotification.removeNotification();
}
Intent contentIntent = new Intent(app, MapActivity.class);
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
final Builder notificationBuilder = new NotificationCompat.Builder(app)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(Version.getAppName(app)).setContentText(notificationText).setSmallIcon(icon)
.setContentIntent(contentPendingIntent).setOngoing(service != null);
if (monitoringPlugin != null) {
Intent saveIntent = new Intent(OSMAND_SAVE_GPX_SERVICE_ACTION);
PendingIntent savePendingIntent = PendingIntent.getBroadcast(app, 0, saveIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
if(service != null && (service.getUsedBy()&2)!=0) {
//checks if service.getUsedBy() includes NavigationService.USED_BY_GPX
Intent stopIntent = new Intent(OSMAND_STOP_GPX_SERVICE_ACTION);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_rec_stop,
app.getString(R.string.gpx_monitoring_stop), stopPendingIntent);
notificationBuilder.addAction(R.drawable.ic_action_save, app.getString(R.string.shared_string_save),
savePendingIntent);
// } else if(service == null) {
} else {
Intent startIntent = new Intent(OSMAND_START_GPX_SERVICE_ACTION);
PendingIntent startPendingIntent = PendingIntent.getBroadcast(app, 0, startIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_rec_start,
app.getString(R.string.gpx_monitoring_start), startPendingIntent);
notificationBuilder.addAction(R.drawable.ic_action_save, app.getString(R.string.shared_string_save),
savePendingIntent);
}
}
return notificationBuilder;
}
public void showNotification() {
NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
Builder newNotification = buildNotificationInStatusBar();
if(newNotification != null) {
mNotificationManager.notify(NOTIFICATION_SERVICE_ID, newNotification.build());
} }
} }
public void removeServiceNotification() { public void removeNotifications() {
NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE); navigationNotification.removeNotification();
mNotificationManager.cancel( NOTIFICATION_SERVICE_ID); gpxNotification.removeNotification();
Builder newNotification = buildNotificationInStatusBar(); osMoNotification.removeNotification();
if(newNotification != null) { gpsWakeUpNotification.removeNotification();
mNotificationManager.notify(NOTIFICATION_SERVICE_ID, newNotification.build());
}
}
public void removeServiceNotificationCompletely() {
NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel( NOTIFICATION_SERVICE_ID);
} }
} }

View file

@ -179,7 +179,7 @@ public class OsmAndLocationSimulation {
return directions.isEmpty() ? 20.0f : Math.max(20.0f, current.distanceTo(directions.get(0)) / 2 ); return directions.isEmpty() ? 20.0f : Math.max(20.0f, current.distanceTo(directions.get(0)) / 2 );
} }
private void stop() { public void stop() {
routeAnimation = null; routeAnimation = null;
} }

View file

@ -25,6 +25,7 @@ import android.widget.Toast;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibilityPlugin;
import net.osmand.data.LatLon;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.AppInitializeListener;
@ -56,6 +57,7 @@ import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.Thread.UncaughtExceptionHandler; import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import btools.routingapp.BRouterServiceConnection; import btools.routingapp.BRouterServiceConnection;
@ -196,7 +198,7 @@ public class OsmandApplication extends MultiDexApplication {
if(RateUsBottomSheetDialog.shouldShow(this)) { if(RateUsBottomSheetDialog.shouldShow(this)) {
osmandSettings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED); osmandSettings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
} }
getNotificationHelper().removeServiceNotification(); getNotificationHelper().removeNotifications();
} }
public RendererRegistry getRendererRegistry() { public RendererRegistry getRendererRegistry() {
@ -430,6 +432,19 @@ public class OsmandApplication extends MultiDexApplication {
this.navigationService = navigationService; this.navigationService = navigationService;
} }
public void stopNavigation() {
if (locationProvider.getLocationSimulation().isRouteAnimating()) {
locationProvider.getLocationSimulation().stop();
}
routingHelper.getVoiceRouter().interruptRouteCommands();
routingHelper.clearCurrentRoute(null, new ArrayList<LatLon>());
routingHelper.setRoutePlanningMode(false);
osmandSettings.LAST_ROUTING_APPLICATION_MODE = osmandSettings.APPLICATION_MODE.get();
osmandSettings.APPLICATION_MODE.set(osmandSettings.DEFAULT_APPLICATION_MODE.get());
if (osmandSettings.USE_MAP_MARKERS.get()) {
targetPointsHelper.removeAllWayPoints(false, false);
}
}
private void fullExit() { private void fullExit() {
// http://stackoverflow.com/questions/2092951/how-to-close-android-application // http://stackoverflow.com/questions/2092951/how-to-close-android-application
@ -745,7 +760,7 @@ public class OsmandApplication extends MultiDexApplication {
serviceIntent.putExtra(NavigationService.USAGE_INTENT, intent); serviceIntent.putExtra(NavigationService.USAGE_INTENT, intent);
serviceIntent.putExtra(NavigationService.USAGE_OFF_INTERVAL, interval); serviceIntent.putExtra(NavigationService.USAGE_OFF_INTERVAL, interval);
startService(serviceIntent); startService(serviceIntent);
getNotificationHelper().showNotification(); //getNotificationHelper().showNotifications();
} }

View file

@ -874,7 +874,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
wakeLockHelper.onStart(this); wakeLockHelper.onStart(this);
getMyApplication().getNotificationHelper().showNotification(); getMyApplication().getNotificationHelper().showNotifications();
} }
protected void setProgressDlg(Dialog progressDlg) { protected void setProgressDlg(Dialog progressDlg) {
@ -894,15 +894,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
// } // }
// } // }
wakeLockHelper.onStop(this); wakeLockHelper.onStop(this);
if (getMyApplication().getNavigationService() == null) { getMyApplication().getNotificationHelper().refreshNotifications();
getMyApplication().getNotificationHelper().removeServiceNotificationCompletely();
}
super.onStop(); super.onStop();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
getMyApplication().getNotificationHelper().removeNotifications();
unregisterReceiver(screenOffReceiver); unregisterReceiver(screenOffReceiver);
FailSafeFuntions.quitRouteRestoreDialog(); FailSafeFuntions.quitRouteRestoreDialog();
OsmandPlugin.onMapActivityDestroy(this); OsmandPlugin.onMapActivityDestroy(this);

View file

@ -796,17 +796,7 @@ public class MapActivityActions implements DialogProvider {
} }
public void stopNavigationWithoutConfirm() { public void stopNavigationWithoutConfirm() {
if (getMyApplication().getLocationProvider().getLocationSimulation().isRouteAnimating()) { getMyApplication().stopNavigation();
getMyApplication().getLocationProvider().getLocationSimulation().startStopRouteAnimation(mapActivity);
}
routingHelper.getVoiceRouter().interruptRouteCommands();
routingHelper.clearCurrentRoute(null, new ArrayList<LatLon>());
routingHelper.setRoutePlanningMode(false);
settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get();
settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
if (settings.USE_MAP_MARKERS.get()) {
getMyApplication().getTargetPointsHelper().removeAllWayPoints(false, false);
}
mapActivity.updateApplicationModeSettings(); mapActivity.updateApplicationModeSettings();
mapActivity.getDashboard().clearDeletedPoints(); mapActivity.getDashboard().clearDeletedPoints();
} }

View file

@ -18,6 +18,8 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.notifications.OsmandNotification;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -63,6 +65,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private LatLon lastPoint; private LatLon lastPoint;
private float distance = 0; private float distance = 0;
private long duration = 0;
private SelectedGpxFile currentTrack; private SelectedGpxFile currentTrack;
private int points; private int points;
@ -227,6 +230,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
} }
distance = 0; distance = 0;
points = 0; points = 0;
duration = 0;
currentTrack.getModifiableGpxFile().points.clear(); currentTrack.getModifiableGpxFile().points.clear();
currentTrack.getModifiableGpxFile().tracks.clear(); currentTrack.getModifiableGpxFile().tracks.clear();
currentTrack.getModifiablePointsToDisplay().clear(); currentTrack.getModifiablePointsToDisplay().clear();
@ -383,7 +387,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
if (record) { if (record) {
insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(), insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
location.getAccuracy(), locationTime, settings); location.getAccuracy(), locationTime, settings);
ctx.getNotificationHelper().showNotification(); ctx.getNotificationHelper().refreshNotification(NotificationType.GPX);
} }
} }
@ -400,6 +404,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
float[] lastInterval = new float[1]; float[] lastInterval = new float[1];
net.osmand.Location.distanceBetween(lat, lon, lastPoint.getLatitude(), lastPoint.getLongitude(), net.osmand.Location.distanceBetween(lat, lon, lastPoint.getLatitude(), lastPoint.getLongitude(),
lastInterval); lastInterval);
if (lastTimeUpdated > 0 && time > lastTimeUpdated) {
duration += time - lastTimeUpdated;
}
distance += lastInterval[0]; distance += lastInterval[0];
lastPoint = new LatLon(lat, lon); lastPoint = new LatLon(lat, lon);
} }
@ -573,6 +580,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis()); GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis());
distance = analysis.totalDistance; distance = analysis.totalDistance;
points = analysis.wptPoints; points = analysis.wptPoints;
duration = analysis.timeSpan;
} }
private void prepareCurrentTrackForRecording() { private void prepareCurrentTrackForRecording() {
@ -598,7 +606,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
public float getDistance() { public float getDistance() {
return distance; return distance;
} }
public long getDuration() {
return duration;
}
public int getPoints() { public int getPoints() {
return points; return points;
} }

View file

@ -59,7 +59,13 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
ApplicationMode.regWidgetVisibility("monitoring", am.toArray(new ApplicationMode[am.size()])); ApplicationMode.regWidgetVisibility("monitoring", am.toArray(new ApplicationMode[am.size()]));
settings = app.getSettings(); settings = app.getSettings();
} }
@Override
public void disable(OsmandApplication app) {
super.disable(app);
app.getNotificationHelper().refreshNotifications();
}
@Override @Override
public void updateLocation(Location location) { public void updateLocation(Location location) {
liveMonitoringHelper.updateLocation(location); liveMonitoringHelper.updateLocation(location);
@ -334,9 +340,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
isSaving = true; isSaving = true;
if (monitoringControl != null) { updateControl();
monitoringControl.updateInfo(null);
}
} }
@Override @Override
@ -346,7 +350,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
helper.saveDataToGpx(app.getAppCustomization().getTracksDir()); helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
helper.close(); helper.close();
} finally { } finally {
app.getNotificationHelper().showNotification(); app.getNotificationHelper().showNotifications();
} }
return null; return null;
} }
@ -354,18 +358,21 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
isSaving = false; isSaving = false;
if (monitoringControl != null) { updateControl();
monitoringControl.updateInfo(null);
}
} }
}, (Void) null); }, (Void) null);
} }
public void updateControl() {
if (monitoringControl != null) {
monitoringControl.updateInfo(null);
}
}
public void stopRecording(){ public void stopRecording(){
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false); settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false);
if (app.getNavigationService() != null) { if (app.getNavigationService() != null) {
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_GPX); app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_GPX);
app.getNotificationHelper().showNotification();
} }
} }

View file

@ -0,0 +1,100 @@
package net.osmand.plus.notifications;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v7.app.NotificationCompat;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import static net.osmand.plus.NavigationService.USED_BY_WAKE_UP;
public class GpsWakeUpNotification extends OsmandNotification {
public final static String OSMAND_STOP_GPS_WAKE_UP_SERVICE_ACTION = "OSMAND_STOP_GPS_WAKE_UP_SERVICE_ACTION";
public GpsWakeUpNotification(OsmandApplication app) {
super(app);
}
@Override
public void init() {
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent(app, NavigationService.class);
app.stopService(serviceIntent);
}
}, new IntentFilter(OSMAND_STOP_GPS_WAKE_UP_SERVICE_ACTION));
}
@Override
public NotificationType getType() {
return NotificationType.GPS;
}
@Override
public int getPriority() {
return NotificationCompat.PRIORITY_HIGH;
}
@Override
public boolean isActive() {
return isEnabled();
}
@Override
public boolean isEnabled() {
NavigationService service = app.getNavigationService();
return service != null && (service.getUsedBy() & USED_BY_WAKE_UP) != 0;
}
@Override
public Builder buildNotification() {
NavigationService service = app.getNavigationService();
String notificationTitle;
String notificationText;
color = 0;
icon = R.drawable.bgs_icon;
if (service != null && (service.getUsedBy() & USED_BY_WAKE_UP) != 0) {
int soi = service.getServiceOffInterval();
color = app.getResources().getColor(R.color.osmand_orange);
notificationTitle = Version.getAppName(app);
notificationText = app.getString(R.string.gps_wake_up_timer) + ": ";
if (soi == 0) {
notificationText = notificationText + app.getString(R.string.int_continuosly);
} else if (soi <= 90000) {
notificationText = notificationText + Integer.toString(soi / 1000) + " " + app.getString(R.string.int_seconds);
} else {
notificationText = notificationText + Integer.toString(soi / 1000 / 60) + " " + app.getString(R.string.int_min);
}
} else {
return null;
}
final Builder notificationBuilder = createBuilder()
.setContentTitle(notificationTitle)
.setStyle(new BigTextStyle().bigText(notificationText));
Intent wakeUpIntent = new Intent(OSMAND_STOP_GPS_WAKE_UP_SERVICE_ACTION);
PendingIntent stopWakeUpPendingIntent = PendingIntent.getBroadcast(app, 0, wakeUpIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_rec_stop,
app.getString(R.string.stop_navigation_service), stopWakeUpPendingIntent);
return notificationBuilder;
}
@Override
public int getUniqueId() {
return GPS_WAKE_UP_NOTIFICATION_SERVICE_ID;
}
}

View file

@ -0,0 +1,165 @@
package net.osmand.plus.notifications;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v7.app.NotificationCompat;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.util.Algorithms;
import static net.osmand.plus.NavigationService.USED_BY_GPX;
import static net.osmand.plus.NavigationService.USED_BY_NAVIGATION;
public class GpxNotification extends OsmandNotification {
public final static String OSMAND_SAVE_GPX_SERVICE_ACTION = "OSMAND_SAVE_GPX_SERVICE_ACTION";
public final static String OSMAND_START_GPX_SERVICE_ACTION = "OSMAND_START_GPX_SERVICE_ACTION";
public final static String OSMAND_STOP_GPX_SERVICE_ACTION = "OSMAND_STOP_GPX_SERVICE_ACTION";
public GpxNotification(OsmandApplication app) {
super(app);
}
@Override
public void init() {
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.saveCurrentTrack();
}
}
}, new IntentFilter(OSMAND_SAVE_GPX_SERVICE_ACTION));
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.startGPXMonitoring(null);
plugin.updateControl();
}
}
}, new IntentFilter(OSMAND_START_GPX_SERVICE_ACTION));
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
if (plugin != null) {
plugin.stopRecording();
plugin.updateControl();
}
}
}, new IntentFilter(OSMAND_STOP_GPX_SERVICE_ACTION));
}
@Override
public NotificationType getType() {
return NotificationType.GPX;
}
@Override
public int getPriority() {
return NotificationCompat.PRIORITY_DEFAULT;
}
@Override
public boolean isActive() {
NavigationService service = app.getNavigationService();
return isEnabled()
&& service != null
&& (service.getUsedBy() & USED_BY_GPX) != 0;
}
@Override
public boolean isEnabled() {
return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
}
@Override
public Builder buildNotification() {
if (!isEnabled()) {
return null;
}
String notificationTitle;
String notificationText;
color = 0;
icon = R.drawable.ic_action_polygom_dark;
boolean isGpxRecording = app.getSavingTrackHelper().getIsRecording();
float recordedDistane = app.getSavingTrackHelper().getDistance();
ongoing = true;
if (isGpxRecording) {
color = app.getResources().getColor(R.color.osmand_orange);
notificationTitle = app.getString(R.string.shared_string_trip) + ""
+ Algorithms.formatDuration((int) (app.getSavingTrackHelper().getDuration() / 1000), true);
notificationText = app.getString(R.string.shared_string_recorded)
+ ": " + OsmAndFormatter.getFormattedDistance(recordedDistane, app);
} else {
if (recordedDistane > 0) {
notificationTitle = app.getString(R.string.shared_string_pause) + ""
+ Algorithms.formatDuration((int) (app.getSavingTrackHelper().getDuration() / 1000), true);
notificationText = app.getString(R.string.shared_string_recorded)
+ ": " + OsmAndFormatter.getFormattedDistance(recordedDistane, app);
} else {
ongoing = false;
notificationTitle = app.getString(R.string.shared_string_trip_recording);
notificationText = app.getString(R.string.gpx_logging_no_data);
}
}
final Builder notificationBuilder = createBuilder()
.setContentTitle(notificationTitle)
.setStyle(new BigTextStyle().bigText(notificationText));
Intent saveIntent = new Intent(OSMAND_SAVE_GPX_SERVICE_ACTION);
PendingIntent savePendingIntent = PendingIntent.getBroadcast(app, 0, saveIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
if (isGpxRecording) {
Intent stopIntent = new Intent(OSMAND_STOP_GPX_SERVICE_ACTION);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_pause,
app.getString(R.string.shared_string_pause), stopPendingIntent);
if (app.getSavingTrackHelper().getDistance() > 0) {
notificationBuilder.addAction(R.drawable.ic_action_save, app.getString(R.string.shared_string_save),
savePendingIntent);
}
} else {
Intent startIntent = new Intent(OSMAND_START_GPX_SERVICE_ACTION);
PendingIntent startPendingIntent = PendingIntent.getBroadcast(app, 0, startIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
if (recordedDistane > 0) {
notificationBuilder.addAction(R.drawable.ic_action_rec_start,
app.getString(R.string.shared_string_continue), startPendingIntent);
notificationBuilder.addAction(R.drawable.ic_action_save, app.getString(R.string.shared_string_save),
savePendingIntent);
} else {
notificationBuilder.addAction(R.drawable.ic_action_rec_start,
app.getString(R.string.shared_string_record), startPendingIntent);
}
}
return notificationBuilder;
}
@Override
public int getUniqueId() {
return GPX_NOTIFICATION_SERVICE_ID;
}
}

View file

@ -0,0 +1,242 @@
package net.osmand.plus.notifications;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationCompat.Builder;
import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.TurnPathHelper;
import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable;
import net.osmand.router.TurnType;
import net.osmand.util.Algorithms;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static net.osmand.plus.NavigationService.USED_BY_NAVIGATION;
public class NavigationNotification extends OsmandNotification {
public final static String OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION = "OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION";
public final static String OSMAND_RESUME_NAVIGATION_SERVICE_ACTION = "OSMAND_RESUME_NAVIGATION_SERVICE_ACTION";
public final static String OSMAND_STOP_NAVIGATION_SERVICE_ACTION = "OSMAND_STOP_NAVIGATION_SERVICE_ACTION";
private Map<TurnPathHelper.TurnResource, Bitmap> bitmapCache = new HashMap<>();
private Bitmap turnBitmap;
private boolean leftSide;
public NavigationNotification(OsmandApplication app) {
super(app);
}
@Override
public void init() {
leftSide = app.getSettings().DRIVING_REGION.get().leftHandDriving;
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = app.getRoutingHelper();
routingHelper.setRoutePlanningMode(true);
routingHelper.setFollowingMode(false);
routingHelper.setPauseNaviation(true);
}
}, new IntentFilter(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION));
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
RoutingHelper routingHelper = app.getRoutingHelper();
routingHelper.setRoutePlanningMode(false);
routingHelper.setFollowingMode(true);
}
}, new IntentFilter(OSMAND_RESUME_NAVIGATION_SERVICE_ACTION));
app.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
app.stopNavigation();
}
}, new IntentFilter(OSMAND_STOP_NAVIGATION_SERVICE_ACTION));
}
@Override
public NotificationType getType() {
return NotificationType.NAVIGATION;
}
@Override
public int getPriority() {
return NotificationCompat.PRIORITY_HIGH;
}
@Override
public boolean isActive() {
return isEnabled();
}
@Override
public boolean isEnabled() {
NavigationService service = app.getNavigationService();
return service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0;
}
@Override
public Builder buildNotification() {
NavigationService service = app.getNavigationService();
String notificationTitle;
StringBuilder notificationText = new StringBuilder();
color = 0;
icon = R.drawable.ic_action_start_navigation;
turnBitmap = null;
RoutingHelper routingHelper = app.getRoutingHelper();
boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) {
color = app.getResources().getColor(R.color.osmand_orange);
String distanceStr = app.getString(R.string.route_distance) + OsmAndFormatter.getFormattedDistance(app.getRoutingHelper().getLeftDistance(), app);
String durationStr = app.getString(R.string.access_arrival_time) + ": " + SimpleDateFormat.getTimeInstance(DateFormat.SHORT)
.format(new Date(System.currentTimeMillis() + app.getRoutingHelper().getLeftTime() * 1000));
TurnType turnType = null;
boolean deviatedFromRoute;
int turnImminent = 0;
int nextTurnDistance = 0;
RouteDirectionInfo ri = null;
if (routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute();
if (deviatedFromRoute) {
turnImminent = 0;
turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
nextTurnDistance = (int) routingHelper.getRouteDeviation();
} else {
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
ri = r.directionInfo;
turnType = r.directionInfo.getTurnType();
nextTurnDistance = r.distanceTo;
turnImminent = r.imminent;
}
}
TurnDrawable drawable = new TurnDrawable(app, false);
int height = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_width);
drawable.setBounds(0, 0, width, height);
drawable.setTurnType(turnType);
drawable.setTurnImminent(turnImminent, deviatedFromRoute);
turnBitmap = drawableToBitmap(drawable);
notificationTitle = OsmAndFormatter.getFormattedDistance(nextTurnDistance, app) + "" + RouteCalculationResult.toString(turnType, app);
if (ri != null && !Algorithms.isEmpty(ri.getDescriptionRoutePart())) {
notificationText.append(ri.getDescriptionRoutePart());
notificationText.append("\n");
}
notificationText.append(distanceStr).append("").append(durationStr);
} else {
notificationTitle = app.getString(R.string.shared_string_navigation);
String error = routingHelper.getLastRouteCalcErrorShort();
if (Algorithms.isEmpty(error)) {
notificationText.append("Route calculation...");
} else {
notificationText.append(error);
}
}
} else {
return null;
}
final Builder notificationBuilder = createBuilder()
.setContentTitle(notificationTitle)
.setStyle(new BigTextStyle().bigText(notificationText))
.setLargeIcon(turnBitmap);
Intent stopIntent = new Intent(OSMAND_STOP_NAVIGATION_SERVICE_ACTION);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_remove_dark,
app.getString(R.string.shared_string_control_stop), stopPendingIntent);
if (routingHelper.isRouteCalculated() && followingMode) {
Intent pauseIntent = new Intent(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION);
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(app, 0, pauseIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_pause,
app.getString(R.string.shared_string_pause), pausePendingIntent);
} else {
Intent resumeIntent = new Intent(OSMAND_STOP_NAVIGATION_SERVICE_ACTION);
PendingIntent resumePendingIntent = PendingIntent.getBroadcast(app, 0, resumeIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_play_dark,
app.getString(R.string.shared_string_continue), resumePendingIntent);
}
return notificationBuilder;
}
@Override
public void setupNotification(Notification notification) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int smallIconViewId = app.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
if (smallIconViewId != 0) {
if (notification.contentIntent != null)
notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notification.headsUpContentView != null)
notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
if (notification.bigContentView != null)
notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
}
}
}
public Bitmap drawableToBitmap(Drawable drawable) {
int height = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_width);
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
@Override
public int getUniqueId() {
return NAVIGATION_NOTIFICATION_SERVICE_ID;
}
}

View file

@ -0,0 +1,73 @@
package net.osmand.plus.notifications;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigTextStyle;
import android.support.v4.app.NotificationCompat.Builder;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmo.OsMoPlugin;
import static android.support.v7.app.NotificationCompat.*;
import static net.osmand.plus.NavigationService.USED_BY_GPX;
import static net.osmand.plus.NavigationService.USED_BY_LIVE;
public class OsMoNotification extends OsmandNotification {
public OsMoNotification(OsmandApplication app) {
super(app);
}
@Override
public NotificationType getType() {
return NotificationType.OSMO;
}
@Override
public int getPriority() {
return NotificationCompat.PRIORITY_DEFAULT;
}
@Override
public boolean isActive() {
NavigationService service = app.getNavigationService();
return isEnabled()
&& service != null
&& (service.getUsedBy() & USED_BY_LIVE) != 0;
}
@Override
public boolean isEnabled() {
return OsmandPlugin.getEnabledPlugin(OsMoPlugin.class) != null;
}
@Override
public Builder buildNotification() {
String notificationTitle;
String notificationText;
color = 0;
icon = R.drawable.ic_osmo_dark;
color = app.getResources().getColor(R.color.osmand_orange);
notificationTitle = Version.getAppName(app);
notificationText = app.getString(R.string.osmo);
final Builder notificationBuilder = createBuilder()
.setContentTitle(notificationTitle)
.setStyle(new BigTextStyle().bigText(notificationText));
return notificationBuilder;
}
@Override
public int getUniqueId() {
return OSMO_NOTIFICATION_SERVICE_ID;
}
}

View file

@ -0,0 +1,116 @@
package net.osmand.plus.notifications;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat.Builder;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
public abstract class OsmandNotification {
public final static int NAVIGATION_NOTIFICATION_SERVICE_ID = 5;
public final static int GPX_NOTIFICATION_SERVICE_ID = 6;
public final static int OSMO_NOTIFICATION_SERVICE_ID = 7;
public final static int GPS_WAKE_UP_NOTIFICATION_SERVICE_ID = 8;
protected OsmandApplication app;
protected boolean ongoing = true;
protected int color;
protected int icon;
public enum NotificationType {
NAVIGATION,
GPX,
OSMO,
GPS
}
public OsmandNotification(OsmandApplication app) {
this.app = app;
init();
}
public void init() {
}
public abstract NotificationType getType();
protected Builder createBuilder() {
Intent contentIntent = new Intent(app, MapActivity.class);
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Builder builder = new Builder(app)
.setVisibility(android.support.v7.app.NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(getPriority())
.setOngoing(ongoing)
.setContentIntent(contentPendingIntent);
if (color != 0) {
builder.setColor(color);
}
if (icon != 0) {
builder.setSmallIcon(icon);
}
return builder;
}
public abstract Builder buildNotification();
public abstract int getUniqueId();
public abstract int getPriority();
public abstract boolean isActive();
public abstract boolean isEnabled();
public void setupNotification(Notification notification) {
}
public boolean showNotification() {
NotificationManager notificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
if (isEnabled()) {
Builder newNotification = buildNotification();
if (newNotification != null) {
Notification notification = newNotification.build();
setupNotification(notification);
notificationManager.notify(getUniqueId(), notification);
return true;
}
}
return false;
}
public boolean refreshNotification() {
NotificationManager notificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
if (isEnabled()) {
Builder newNotification = buildNotification();
if (newNotification != null) {
Notification notification = newNotification.build();
setupNotification(notification);
notificationManager.notify(getUniqueId(), notification);
return true;
}
} else {
notificationManager.cancel(getUniqueId());
}
return false;
}
public void removeNotification() {
NotificationManager notificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(getUniqueId());
}
public void closeSystemDialogs(Context context) {
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
context.sendBroadcast(it);
}
}

View file

@ -15,6 +15,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
@ -29,6 +30,8 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION;
public class RoutingHelper { public class RoutingHelper {
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RoutingHelper.class); private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RoutingHelper.class);
@ -66,6 +69,8 @@ public class RoutingHelper {
private static final int RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL = 120000; private static final int RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL = 120000;
private Thread currentRunningJob; private Thread currentRunningJob;
private long lastTimeEvaluatedRoute = 0; private long lastTimeEvaluatedRoute = 0;
private String lastRouteCalcError;
private String lastRouteCalcErrorShort;
private long recalculateCountInInterval = 0; private long recalculateCountInInterval = 0;
private int evalWaitInterval = 0; private int evalWaitInterval = 0;
@ -105,7 +110,15 @@ public class RoutingHelper {
public OsmandApplication getApplication() { public OsmandApplication getApplication() {
return app; return app;
} }
public String getLastRouteCalcError() {
return lastRouteCalcError;
}
public String getLastRouteCalcErrorShort() {
return lastRouteCalcErrorShort;
}
public void setPauseNaviation(boolean b) { public void setPauseNaviation(boolean b) {
this.isPauseNavigation = b; this.isPauseNavigation = b;
if (b) { if (b) {
@ -472,6 +485,7 @@ public class RoutingHelper {
// that node already passed // that node already passed
route.updateCurrentRoute(newCurrentRoute + 1); route.updateCurrentRoute(newCurrentRoute + 1);
currentRoute = newCurrentRoute + 1; currentRoute = newCurrentRoute + 1;
app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
} else { } else {
break; break;
} }
@ -830,7 +844,9 @@ public class RoutingHelper {
synchronized (RoutingHelper.this) { synchronized (RoutingHelper.this) {
currentRunningJob = this; currentRunningJob = this;
} }
} }
lastRouteCalcError = null;
lastRouteCalcErrorShort = null;
RouteCalculationResult res = provider.calculateRouteImpl(params); RouteCalculationResult res = provider.calculateRouteImpl(params);
if (params.calculationProgress.isCancelled) { if (params.calculationProgress.isCancelled) {
synchronized (RoutingHelper.this) { synchronized (RoutingHelper.this) {
@ -856,17 +872,24 @@ public class RoutingHelper {
} }
if(res.isCalculated()){ if(res.isCalculated()){
setNewRoute(prev, res, params.start); setNewRoute(prev, res, params.start);
} else if (onlineSourceWithoutInternet) { } else if (onlineSourceWithoutInternet) {
showMessage(app.getString(R.string.error_calculating_route) lastRouteCalcError = app.getString(R.string.error_calculating_route)
+ ":\n" + app.getString(R.string.internet_connection_required_for_online_route)); //$NON-NLS-1$ + ":\n" + app.getString(R.string.internet_connection_required_for_online_route);
lastRouteCalcErrorShort = app.getString(R.string.error_calculating_route);
showMessage(lastRouteCalcError); //$NON-NLS-1$
} else { } else {
if (res.getErrorMessage() != null) { if (res.getErrorMessage() != null) {
showMessage(app.getString(R.string.error_calculating_route) + ":\n" + res.getErrorMessage()); //$NON-NLS-1$ lastRouteCalcError = app.getString(R.string.error_calculating_route) + ":\n" + res.getErrorMessage();
lastRouteCalcErrorShort = app.getString(R.string.error_calculating_route);
showMessage(lastRouteCalcError); //$NON-NLS-1$
} else { } else {
showMessage(app.getString(R.string.empty_route_calculated)); lastRouteCalcError = app.getString(R.string.empty_route_calculated);
lastRouteCalcErrorShort = app.getString(R.string.empty_route_calculated);
showMessage(lastRouteCalcError);
} }
} }
app.getNotificationHelper().refreshNotification(NAVIGATION);
lastTimeEvaluatedRoute = System.currentTimeMillis(); lastTimeEvaluatedRoute = System.currentTimeMillis();
} }