From 003f7c1baf5a37891e20bca32c26cf76c5184e3a Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 15 Jan 2015 09:55:30 +0100 Subject: [PATCH] Add default action to media button click --- .../osmand/plus/audionotes/AudioVideoNotesPlugin.java | 11 ++++++++++- .../plus/audionotes/MediaRemoteControlReceiver.java | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 8e43a54e54..7e0132ed8a 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -507,7 +507,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - private void defaultAction(final MapActivity mapActivity) { + public void defaultAction(final MapActivity mapActivity) { final Location loc = app.getLocationProvider().getLastKnownLocation(); // double lat = mapActivity.getMapView().getLatitude(); // double lon = mapActivity.getMapView().getLongitude(); @@ -591,6 +591,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public void mapActivityPause(MapActivity activity) { stopRecording(activity); } + + @Override + public void mapActivityResume(MapActivity activity) { + this.activity = activity;; + } + + public MapActivity getActivity() { + return activity; + } public void recordVideo(final double lat, final double lon, final MapActivity mapActivity) { if (AV_EXTERNAL_RECORDER.get()) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java b/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java index ad0164c1dd..433ca0409c 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java @@ -11,9 +11,11 @@ public class MediaRemoteControlReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); - if(plugin != null && intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) != null) { + if(plugin != null && intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) != null && + plugin.getActivity() != null) { // System.out.println("OsmAnd AV Button pressed " + intent.getIntExtra(Intent.EXTRA_KEY_EVENT, 0)); // Toast.makeText(context, "Button pressed " + intent.getIntExtra(Intent.EXTRA_KEY_EVENT, 0), Toast.LENGTH_LONG).show(); + plugin.defaultAction(plugin.getActivity()); } } }