Add recordings to local manager
This commit is contained in:
parent
ac54d2ea1e
commit
bfa8ea4519
5 changed files with 102 additions and 1 deletions
|
@ -40,7 +40,18 @@
|
|||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
</intent-filter>
|
||||
<receiver android:name="net.osmand.plus.audionotes.MediaRemoteControlReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CAMERA_BUTTON" />
|
||||
<action android:name="android.intent.action.MEDIA_BUTTON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</activity>
|
||||
<receiver android:name="net.osmand.plus.audionotes.MediaRemoteControlReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MEDIA_BUTTON" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<activity android:name="net.osmand.plus.activities.SettingsActivity" android:label="@string/settings_activity" android:configChanges="keyboardHidden|orientation"></activity>
|
||||
<activity android:name="net.osmand.plus.activities.search.SearchActivity" android:label="@string/search_activity" ></activity>
|
||||
<activity android:name="net.osmand.plus.activities.NavigatePointActivity"></activity>
|
||||
|
|
|
@ -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,9 +259,17 @@ 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) {
|
||||
this.activity = activity;
|
||||
|
@ -249,6 +282,34 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
|
||||
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) {
|
||||
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,10 +12,12 @@
|
|||
<activity
|
||||
android:name=".ParkingPluginActivity"
|
||||
android:label="@string/app_name" >
|
||||
<!--
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
-->
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
|
|
@ -12,10 +12,11 @@
|
|||
<activity
|
||||
android:name="net.osmand.srtmPlugin.SRTMPluginActivity"
|
||||
android:label="@string/app_name" >
|
||||
<!--
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</intent-filter> -->
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
|
Loading…
Reference in a new issue