diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index b58a294857..023d3cf9a2 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -40,7 +40,18 @@ + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 74bdb4402e..6ce486dab9 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -40,6 +40,7 @@ import net.osmand.plus.views.TextInfoControl; import org.apache.commons.logging.Log; import android.app.Dialog; +import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -49,6 +50,7 @@ import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.graphics.BitmapFactory.Options; import android.hardware.Camera; +import android.media.AudioManager; import android.media.ExifInterface; import android.media.MediaPlayer; import android.media.MediaRecorder; @@ -78,6 +80,8 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { private static final String MPEG4_EXTENSION = "mp4"; private static final String IMG_EXTENSION = "jpg"; private static final Log log = LogUtil.getLog(AudioVideoNotesPlugin.class); + private static Method mRegisterMediaButtonEventReceiver; + private static Method mUnregisterMediaButtonEventReceiver; private OsmandApplication app; private TextInfoControl recordControl; @@ -212,6 +216,27 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } + private static void initializeRemoteControlRegistrationMethods() { + try { + if (mRegisterMediaButtonEventReceiver == null) { + mRegisterMediaButtonEventReceiver = AudioManager.class.getMethod( + "registerMediaButtonEventReceiver", + new Class[] { ComponentName.class } ); + } + if (mUnregisterMediaButtonEventReceiver == null) { + mUnregisterMediaButtonEventReceiver = AudioManager.class.getMethod( + "unregisterMediaButtonEventReceiver", + new Class[] { ComponentName.class } ); + } + /* success, this device will take advantage of better remote */ + /* control event handling */ + } catch (NoSuchMethodException nsme) { + /* failure, still using the legacy behavior, but this app */ + /* is future-proof! */ + } + } + + @Override public String getId() { return ID; @@ -234,8 +259,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public boolean init(final OsmandApplication app) { + initializeRemoteControlRegistrationMethods(); + AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); + if(am != null){ + registerMediaListener(am); + } return true; } + + + @Override public void registerLayers(MapActivity activity) { @@ -247,7 +280,35 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { activity.getMapView().addLayer(audioNotesLayer, 3.5f); registerWidget(activity); } + + + private void registerMediaListener(AudioManager am) { + + ComponentName receiver = new ComponentName(app.getPackageName(), + MediaRemoteControlReceiver.class.getName()); + try { + if (mRegisterMediaButtonEventReceiver == null) { + return; + } + mRegisterMediaButtonEventReceiver.invoke(am, + receiver); + } catch (Exception ite) { + log.error(ite.getMessage(), ite); + } + } + private void unregisterMediaListener(AudioManager am) { + ComponentName receiver = new ComponentName(app.getPackageName(), MediaRemoteControlReceiver.class.getName()); + try { + if (mUnregisterMediaButtonEventReceiver == null) { + return; + } + mUnregisterMediaButtonEventReceiver.invoke(am, receiver); + } catch (Exception ite) { + log.error(ite.getMessage(), ite); + } + } + @Override public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { @@ -562,6 +623,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public void disable(OsmandApplication app) { + AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); + if(am != null){ + unregisterMediaListener(am); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java b/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java new file mode 100644 index 0000000000..70d1c9b05a --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/audionotes/MediaRemoteControlReceiver.java @@ -0,0 +1,22 @@ +package net.osmand.plus.audionotes; + +import net.osmand.plus.OsmandPlugin; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.widget.Toast; + +public class MediaRemoteControlReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + Toast.makeText(context, "Intent sent", Toast.LENGTH_LONG).show(); + if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { + AudioVideoNotesPlugin plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); + if(plugin != null && intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) != 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(); + } + } + } +} \ No newline at end of file diff --git a/plugins/Osmand-ParkingPlugin/AndroidManifest.xml b/plugins/Osmand-ParkingPlugin/AndroidManifest.xml index e8f12d2886..106dca1983 100644 --- a/plugins/Osmand-ParkingPlugin/AndroidManifest.xml +++ b/plugins/Osmand-ParkingPlugin/AndroidManifest.xml @@ -12,10 +12,12 @@ + diff --git a/plugins/Osmand-SRTMPlugin/AndroidManifest.xml b/plugins/Osmand-SRTMPlugin/AndroidManifest.xml index ec4c7d0ba5..4364b72560 100644 --- a/plugins/Osmand-SRTMPlugin/AndroidManifest.xml +++ b/plugins/Osmand-SRTMPlugin/AndroidManifest.xml @@ -12,10 +12,11 @@ +