Added setting for GPX notification
This commit is contained in:
parent
d91012491f
commit
e9ffb30e8f
8 changed files with 94 additions and 3 deletions
|
@ -717,6 +717,8 @@
|
|||
</service>
|
||||
|
||||
<receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver" />
|
||||
<receiver android:name="net.osmand.plus.notifications.NotificationDismissReceiver" />
|
||||
|
||||
<activity android:name="net.osmand.plus.activities.PrintDialogActivity" />
|
||||
|
||||
<receiver
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="trip_rec_notification_settings">Trip recording (no data)</string>
|
||||
<string name="trip_rec_notification_settings_desc">Show notification which allows to start trip recording by pressing Record button</string>
|
||||
<string name="shared_string_notifications">Notifications</string>
|
||||
<string name="shared_string_continue">Continue</string>
|
||||
<string name="shared_string_pause">Pause</string>
|
||||
<string name="shared_string_trip">Trip</string>
|
||||
|
|
|
@ -71,6 +71,23 @@ public class NotificationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void onNotificationDismissed(NotificationType notificationType) {
|
||||
switch (notificationType) {
|
||||
case NAVIGATION:
|
||||
navigationNotification.onNotificationDismissed();
|
||||
break;
|
||||
case GPX:
|
||||
gpxNotification.onNotificationDismissed();
|
||||
break;
|
||||
case OSMO:
|
||||
osMoNotification.onNotificationDismissed();
|
||||
break;
|
||||
case GPS:
|
||||
gpsWakeUpNotification.onNotificationDismissed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshNotifications() {
|
||||
boolean navNotificationVisible = navigationNotification.refreshNotification();
|
||||
gpxNotification.refreshNotification();
|
||||
|
|
|
@ -1076,6 +1076,8 @@ public class OsmandSettings {
|
|||
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 5);
|
||||
}
|
||||
|
||||
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeGlobal();
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
|||
|
||||
createLoggingSection(grp);
|
||||
createLiveSection(grp);
|
||||
createNotificationSection(grp);
|
||||
profileDialog();
|
||||
}
|
||||
|
||||
|
@ -132,6 +133,16 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
|||
MINUTES, 1000, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr));
|
||||
}
|
||||
|
||||
private void createNotificationSection(PreferenceScreen grp) {
|
||||
PreferenceCategory cat;
|
||||
cat = new PreferenceCategory(this);
|
||||
cat.setTitle(R.string.shared_string_notifications);
|
||||
grp.addPreference(cat);
|
||||
|
||||
final CheckBoxPreference tripRecording = createCheckBoxPreference(settings.SHOW_TRIP_REC_NOTIFICATION, R.string.trip_rec_notification_settings,
|
||||
R.string.trip_rec_notification_settings_desc);
|
||||
cat.addPreference(tripRecording);
|
||||
}
|
||||
|
||||
public void updateAllSettings() {
|
||||
super.updateAllSettings();
|
||||
|
|
|
@ -27,6 +27,8 @@ public class GpxNotification extends OsmandNotification {
|
|||
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";
|
||||
|
||||
private boolean wasDismissed;
|
||||
|
||||
public GpxNotification(OsmandApplication app) {
|
||||
super(app);
|
||||
}
|
||||
|
@ -92,6 +94,11 @@ public class GpxNotification extends OsmandNotification {
|
|||
return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationDismissed() {
|
||||
wasDismissed = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder buildNotification() {
|
||||
if (!isEnabled()) {
|
||||
|
@ -123,6 +130,10 @@ public class GpxNotification extends OsmandNotification {
|
|||
}
|
||||
}
|
||||
|
||||
if ((wasDismissed || !app.getSettings().SHOW_TRIP_REC_NOTIFICATION.get()) && !ongoing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Builder notificationBuilder = createBuilder()
|
||||
.setContentTitle(notificationTitle)
|
||||
.setStyle(new BigTextStyle().bigText(notificationText));
|
||||
|
@ -134,11 +145,14 @@ public class GpxNotification extends OsmandNotification {
|
|||
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_pause,
|
||||
app.getString(R.string.shared_string_pause), stopPendingIntent);
|
||||
notificationBuilder.addAction(R.drawable.ic_action_save, app.getString(R.string.shared_string_save),
|
||||
savePendingIntent);
|
||||
} else {
|
||||
notificationBuilder.addAction(R.drawable.ic_action_rec_stop,
|
||||
app.getString(R.string.shared_string_control_stop), stopPendingIntent);
|
||||
}
|
||||
} else {
|
||||
Intent startIntent = new Intent(OSMAND_START_GPX_SERVICE_ACTION);
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package net.osmand.plus.notifications;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import net.osmand.plus.NotificationHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class NotificationDismissReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String NOTIFICATION_TYPE_KEY_NAME = "net.osmand.plus.notifications.NotificationType";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final NotificationHelper helper = ((OsmandApplication) context.getApplicationContext()).getNotificationHelper();
|
||||
String notificationTypeStr = intent.getExtras().getString(NOTIFICATION_TYPE_KEY_NAME);
|
||||
if (!Algorithms.isEmpty(notificationTypeStr)) {
|
||||
try {
|
||||
NotificationType notificationType = NotificationType.valueOf(notificationTypeStr);
|
||||
helper.onNotificationDismissed(notificationType);
|
||||
} catch (Exception e) {
|
||||
//ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PendingIntent createIntent(Context context, NotificationType notificationType) {
|
||||
Intent intent = new Intent(context, NotificationDismissReceiver.class);
|
||||
intent.putExtra(NOTIFICATION_TYPE_KEY_NAME, notificationType.name());
|
||||
return PendingIntent.getBroadcast(context.getApplicationContext(),
|
||||
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.notifications;
|
|||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.NotificationCompat.Builder;
|
||||
|
@ -48,7 +49,8 @@ public abstract class OsmandNotification {
|
|||
.setVisibility(android.support.v7.app.NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setPriority(getPriority())
|
||||
.setOngoing(ongoing)
|
||||
.setContentIntent(contentPendingIntent);
|
||||
.setContentIntent(contentPendingIntent)
|
||||
.setDeleteIntent(NotificationDismissReceiver.createIntent(app, getType()));
|
||||
|
||||
if (color != 0) {
|
||||
builder.setColor(color);
|
||||
|
@ -73,6 +75,9 @@ public abstract class OsmandNotification {
|
|||
public void setupNotification(Notification notification) {
|
||||
}
|
||||
|
||||
public void onNotificationDismissed() {
|
||||
}
|
||||
|
||||
public boolean showNotification() {
|
||||
NotificationManager notificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (isEnabled()) {
|
||||
|
|
Loading…
Reference in a new issue