From 97ff27880c88891ed139cb2c6013b14b4a4f519f Mon Sep 17 00:00:00 2001 From: kavikhalique Date: Sat, 13 Apr 2024 15:13:31 +0530 Subject: [PATCH] [android] Implements exit button in navigation notification Signed-off-by: kavikhalique --- .../main/java/app/organicmaps/MwmActivity.java | 6 ++++-- .../organicmaps/routing/NavigationService.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/MwmActivity.java b/android/app/src/main/java/app/organicmaps/MwmActivity.java index 3800406e4023e..0bcf2f8e4c36f 100644 --- a/android/app/src/main/java/app/organicmaps/MwmActivity.java +++ b/android/app/src/main/java/app/organicmaps/MwmActivity.java @@ -1119,9 +1119,11 @@ protected void onStop() Framework.nativeRemovePlacePageActivationListener(this); BookmarkManager.INSTANCE.removeLoadingListener(this); LocationHelper.from(this).removeListener(this); - LocationState.nativeRemoveListener(); - if (mDisplayManager.isDeviceDisplayUsed()) + if (mDisplayManager.isDeviceDisplayUsed() && !RoutingController.get().isNavigating()) + { + LocationState.nativeRemoveListener(); RoutingController.get().detach(); + } IsolinesManager.from(getApplicationContext()).detach(); mSearchController.detach(); Utils.keepScreenOn(false, getWindow()); diff --git a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java index b013197b5ed47..a46fee6e0407b 100644 --- a/android/app/src/main/java/app/organicmaps/routing/NavigationService.java +++ b/android/app/src/main/java/app/organicmaps/routing/NavigationService.java @@ -43,6 +43,7 @@ public class NavigationService extends Service implements LocationListener { private static final String TAG = NavigationService.class.getSimpleName(); + private static final String STOP_NAVIGATION = "STOP_NAVIGATION"; private static final String CHANNEL_ID = "NAVIGATION"; private static final int NOTIFICATION_ID = 12345678; @@ -137,6 +138,11 @@ public static NotificationCompat.Builder getNotificationBuilder(@NonNull Context final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_CANCEL_CURRENT | FLAG_IMMUTABLE); + final Intent exitIntent = new Intent(context, NavigationService.class); + exitIntent.setAction(STOP_NAVIGATION); + final PendingIntent exitPendingIntent = PendingIntent.getService(context, 0, exitIntent, + PendingIntent.FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE); + mNotificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID) .setCategory(NotificationCompat.CATEGORY_NAVIGATION) .setPriority(NotificationManager.IMPORTANCE_LOW) @@ -146,6 +152,7 @@ public static NotificationCompat.Builder getNotificationBuilder(@NonNull Context .setOnlyAlertOnce(true) .setSmallIcon(R.drawable.ic_splash) .setContentIntent(pendingIntent) + .addAction(0, context.getString(R.string.core_exit), exitPendingIntent) .setColorized(isColorizedSupported()) .setColor(ContextCompat.getColor(context, R.color.notification)); @@ -184,6 +191,14 @@ public void onLowMemory() @Override public int onStartCommand(@NonNull Intent intent, int flags, int startId) { + final String action = intent.getAction(); + if (action != null && action.equals(STOP_NAVIGATION)) + { + RoutingController.get().cancel(); + stopSelf(); + return START_NOT_STICKY; + } + if (!MwmApplication.from(this).arePlatformAndCoreInitialized()) { // The system restarts the service if the app's process has crashed or been stopped. It would be nice to