Notification with buttons
This commit is contained in:
parent
ab2ba708c2
commit
0e9d1ca771
2 changed files with 157 additions and 136 deletions
|
@ -1,10 +1,6 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
|
||||||
import net.osmand.access.AccessibleToast;
|
|
||||||
import net.osmand.plus.osmo.OsMoPlugin;
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.Notification;
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
@ -27,14 +23,22 @@ import android.support.v7.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.access.AccessibleToast;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||||
|
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 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// global id don't conflict with others
|
// global id don't conflict with others
|
||||||
private final static int NOTIFICATION_SERVICE_ID = 5;
|
private 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_SERVICE_ACTION = "OSMAND_STOP_SERVICE_ACTION"; //$NON-NLS-1$
|
||||||
|
public final static String OSMAND_SAVE_SERVICE_ACTION = "OSMAND_SAVE_SERVICE_ACTION";
|
||||||
public static int USED_BY_NAVIGATION = 1;
|
public static int USED_BY_NAVIGATION = 1;
|
||||||
public static int USED_BY_GPX = 2;
|
public static int USED_BY_GPX = 2;
|
||||||
public static int USED_BY_LIVE = 4;
|
public static int USED_BY_LIVE = 4;
|
||||||
|
@ -54,6 +58,7 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
private static WakeLock lockStatic;
|
private static WakeLock lockStatic;
|
||||||
private PendingIntent pendingIntent;
|
private PendingIntent pendingIntent;
|
||||||
private BroadcastReceiver broadcastReceiver;
|
private BroadcastReceiver broadcastReceiver;
|
||||||
|
private BroadcastReceiver saveBroadcastReceiver;
|
||||||
private int usedBy = 0;
|
private int usedBy = 0;
|
||||||
private OsmAndLocationProvider locationProvider;
|
private OsmAndLocationProvider locationProvider;
|
||||||
|
|
||||||
|
@ -182,9 +187,15 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
|
|
||||||
};
|
};
|
||||||
registerReceiver(broadcastReceiver, new IntentFilter(OSMAND_STOP_SERVICE_ACTION));
|
registerReceiver(broadcastReceiver, new IntentFilter(OSMAND_STOP_SERVICE_ACTION));
|
||||||
|
saveBroadcastReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
Intent notificationIntent = new Intent(OSMAND_STOP_SERVICE_ACTION);
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
final OsmandMonitoringPlugin plugin = OsmandPlugin
|
||||||
|
.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
||||||
|
plugin.saveCurrentTrack();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
registerReceiver(saveBroadcastReceiver, new IntentFilter(OSMAND_SAVE_SERVICE_ACTION));
|
||||||
|
|
||||||
//Show currently active wake-up interval
|
//Show currently active wake-up interval
|
||||||
int soi = settings.SERVICE_OFF_INTERVAL.get();
|
int soi = settings.SERVICE_OFF_INTERVAL.get();
|
||||||
|
@ -196,7 +207,6 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
} else {
|
} else {
|
||||||
nt = nt + Integer.toString(soi / 1000 / 60) + " " + getString(R.string.int_min);
|
nt = nt + Integer.toString(soi / 1000 / 60) + " " + getString(R.string.int_min);
|
||||||
}
|
}
|
||||||
PendingIntent broadcast = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
// Notification notification = new Notification(R.drawable.bgs_icon, "", //$NON-NLS-1$
|
// Notification notification = new Notification(R.drawable.bgs_icon, "", //$NON-NLS-1$
|
||||||
// System.currentTimeMillis());
|
// System.currentTimeMillis());
|
||||||
//
|
//
|
||||||
|
@ -205,12 +215,28 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
// notification.flags = Notification.FLAG_NO_CLEAR;
|
// notification.flags = Notification.FLAG_NO_CLEAR;
|
||||||
// startForeground(NOTIFICATION_SERVICE_ID, notification);
|
// startForeground(NOTIFICATION_SERVICE_ID, notification);
|
||||||
|
|
||||||
final Builder noti = new NotificationCompat.Builder(
|
String stop = getResources().getString(R.string.shared_string_control_stop);
|
||||||
|
Intent stopIntent = new Intent(OSMAND_STOP_SERVICE_ACTION);
|
||||||
|
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
String pause = getResources().getString(R.string.shared_string_save);
|
||||||
|
Intent saveIntent = new Intent(OSMAND_SAVE_SERVICE_ACTION);
|
||||||
|
PendingIntent savePendingIntent = PendingIntent.getBroadcast(this, 0, saveIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
Intent contentIntent = new Intent(this, MapActivity.class);
|
||||||
|
PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0, contentIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
|
final Builder notificationBuilder = new NotificationCompat.Builder(
|
||||||
this).setContentTitle(Version.getAppName(cl))
|
this).setContentTitle(Version.getAppName(cl))
|
||||||
.setContentText(getString(R.string.osmand_service)).setSmallIcon(R.drawable.bgs_icon)
|
.setContentText(getString(R.string.osmand_service))
|
||||||
|
.setSmallIcon(R.drawable.bgs_icon)
|
||||||
// .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext()))
|
// .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext()))
|
||||||
.setContentIntent(broadcast).setOngoing(true);
|
.setContentIntent(contentPendingIntent)
|
||||||
startForeground(NOTIFICATION_SERVICE_ID, noti.build());
|
.setOngoing(true)
|
||||||
|
.addAction(R.drawable.ic_action_rec_stop, stop, stopPendingIntent)
|
||||||
|
.addAction(R.drawable.ic_action_save, pause, savePendingIntent);
|
||||||
|
startForeground(NOTIFICATION_SERVICE_ID, notificationBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -253,6 +279,10 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
unregisterReceiver(broadcastReceiver);
|
unregisterReceiver(broadcastReceiver);
|
||||||
broadcastReceiver = null;
|
broadcastReceiver = null;
|
||||||
}
|
}
|
||||||
|
if (saveBroadcastReceiver != null) {
|
||||||
|
unregisterReceiver(saveBroadcastReceiver);
|
||||||
|
saveBroadcastReceiver = null;
|
||||||
|
}
|
||||||
|
|
||||||
stopForeground(Boolean.TRUE);
|
stopForeground(Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
@ -281,13 +311,11 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider) {
|
public void onProviderEnabled(String provider) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||||
}
|
}
|
||||||
|
@ -305,6 +333,4 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
NavigationService.this.stopSelf();
|
NavigationService.this.stopSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,47 +1,5 @@
|
||||||
package net.osmand.plus.myplaces;
|
package net.osmand.plus.myplaces;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.text.Collator;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.MessageFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
|
||||||
import net.osmand.access.AccessibleToast;
|
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
|
||||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
|
||||||
import net.osmand.plus.GPXUtilities;
|
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
|
||||||
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
|
||||||
import net.osmand.plus.GPXUtilities.WptPt;
|
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
|
||||||
import net.osmand.plus.IconsCache;
|
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
|
||||||
import net.osmand.plus.OsmandPlugin;
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
|
||||||
import net.osmand.plus.R;
|
|
||||||
import net.osmand.plus.activities.MapActivity;
|
|
||||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
|
||||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
|
||||||
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
|
||||||
import net.osmand.plus.activities.SavingTrackHelper;
|
|
||||||
import net.osmand.plus.activities.TrackActivity;
|
|
||||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
|
||||||
import net.osmand.plus.download.LocalIndexesFragment;
|
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
|
||||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
|
||||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
|
||||||
import net.osmand.util.Algorithms;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
@ -75,6 +33,49 @@ import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.access.AccessibleToast;
|
||||||
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
|
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||||
|
import net.osmand.plus.GPXUtilities;
|
||||||
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
|
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
||||||
|
import net.osmand.plus.GPXUtilities.WptPt;
|
||||||
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
|
import net.osmand.plus.IconsCache;
|
||||||
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||||
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||||
|
import net.osmand.plus.activities.OsmandExpandableListFragment;
|
||||||
|
import net.osmand.plus.activities.SavingTrackHelper;
|
||||||
|
import net.osmand.plus.activities.TrackActivity;
|
||||||
|
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||||
|
import net.osmand.plus.download.LocalIndexesFragment;
|
||||||
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||||
|
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.Collator;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
|
|
||||||
public static final int SEARCH_ID = -1;
|
public static final int SEARCH_ID = -1;
|
||||||
|
@ -210,16 +211,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
save.setOnClickListener(new View.OnClickListener() {
|
save.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Runnable run = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final OsmandMonitoringPlugin plugin = OsmandPlugin
|
final OsmandMonitoringPlugin plugin = OsmandPlugin
|
||||||
.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
||||||
plugin.saveCurrentTrack();
|
plugin.saveCurrentTrack();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
run.run();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (sth.getPoints() > 0 || sth.getDistance() > 0) {
|
if (sth.getPoints() > 0 || sth.getDistance() > 0) {
|
||||||
save.setVisibility(View.VISIBLE);
|
save.setVisibility(View.VISIBLE);
|
||||||
|
|
Loading…
Reference in a new issue