Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Implements exit button in navigation notification #7953

Merged
merged 2 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/src/main/java/app/organicmaps/MwmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ protected void onStop()
Framework.nativeRemovePlacePageActivationListener(this);
BookmarkManager.INSTANCE.removeLoadingListener(this);
LocationHelper.from(this).removeListener(this);
if (mDisplayManager.isDeviceDisplayUsed())
if (mDisplayManager.isDeviceDisplayUsed() && !RoutingController.get().isNavigating())
{
LocationState.nativeRemoveListener();
RoutingController.get().detach();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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;
Expand Down Expand Up @@ -138,6 +139,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);
rtsisyk marked this conversation as resolved.
Show resolved Hide resolved

mNotificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setCategory(NotificationCompat.CATEGORY_NAVIGATION)
.setPriority(NotificationManager.IMPORTANCE_LOW)
Expand All @@ -147,6 +153,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));

Expand Down Expand Up @@ -185,6 +192,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))
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be on the previous line..

RoutingController.get().cancel();
stopSelf();
return START_NOT_STICKY;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late comment, but it looks like that we forgot return START_NOT_STICKY; // The service will be stopped by stopSelf(). here. Please 6 lines below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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
Expand Down