Fix issue 1945

This commit is contained in:
Victor Shcherb 2013-07-18 23:30:42 +02:00
parent b9812ceef5
commit 1ef07093b3
9 changed files with 292 additions and 312 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@ countries.reginfo
h_*.png h_*.png
g_*.png g_*.png
mm_*.png mm_*.png
mx_*.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 750 B

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 892 B

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 252 B

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?><resources> <?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="local_index_gpx_timespan">\nZeitspanne: %1$d:%2$02d:%3$02d</string> <string name="local_index_gpx_timespan">\nZeitspanne: %1$d:%2$02d:%3$02d</string>
<string name="local_index_gpx_timemoving">\nZeit in Bewegung: %1$d:%2$02d:%3$02d</string> <string name="local_index_gpx_timemoving">\nZeit in Bewegung: %1$d:%2$02d:%3$02d</string>
<string name="context_menu_item_destination_point">Als Ziel wählen</string> <string name="context_menu_item_destination_point">Als Ziel wählen</string>

View file

@ -1,6 +1,5 @@
package net.osmand.plus.audionotes; package net.osmand.plus.audionotes;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -23,6 +22,7 @@ import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.DataTileManager; import net.osmand.data.DataTileManager;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
@ -38,6 +38,7 @@ import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.activities.LocalIndexesActivity; import net.osmand.plus.activities.LocalIndexesActivity;
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask; import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
@ -67,7 +68,6 @@ import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener; import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaRecorder; import android.media.MediaRecorder;
import android.media.SoundPool; import android.media.SoundPool;
import android.media.SoundPool.OnLoadCompleteListener;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.preference.Preference; import android.preference.Preference;
@ -97,9 +97,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private OsmandApplication app; private OsmandApplication app;
private TextInfoWidget recordControl; private TextInfoWidget recordControl;
public final CommonPreference<Boolean> AV_EXTERNAL_RECORDER ; public final CommonPreference<Boolean> AV_EXTERNAL_RECORDER;
public final CommonPreference<Boolean> AV_EXTERNAL_PHOTO_CAM ; public final CommonPreference<Boolean> AV_EXTERNAL_PHOTO_CAM;
public final CommonPreference<Boolean> AV_PHOTO_PLAY_SOUND ; public final CommonPreference<Boolean> AV_PHOTO_PLAY_SOUND;
public static final int VIDEO_OUTPUT_MP4 = 0; public static final int VIDEO_OUTPUT_MP4 = 0;
public static final int VIDEO_OUTPUT_3GP = 1; public static final int VIDEO_OUTPUT_3GP = 1;
@ -125,9 +125,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public final CommonPreference<Integer> AV_DEFAULT_ACTION; public final CommonPreference<Integer> AV_DEFAULT_ACTION;
public final OsmandPreference<Boolean> SHOW_RECORDINGS ; public final OsmandPreference<Boolean> SHOW_RECORDINGS;
private DataTileManager<Recording> recordings = new DataTileManager<AudioVideoNotesPlugin.Recording>(14); private DataTileManager<Recording> recordings = new DataTileManager<AudioVideoNotesPlugin.Recording>(14);
private Map<String, Recording> recordingByFileName = new LinkedHashMap<String, Recording>(); private Map<String, Recording> recordingByFileName = new LinkedHashMap<String, Recording>();
@ -140,6 +138,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public Recording(File f) { public Recording(File f) {
this.file = f; this.file = f;
} }
public File file; public File file;
public String name; public String name;
@ -148,15 +147,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private long duration = -1; private long duration = -1;
private boolean available = true; private boolean available = true;
public double getLatitude(){ public double getLatitude() {
return lat; return lat;
} }
public double getLongitude(){ public double getLongitude() {
return lon; return lon;
} }
private void updateInternalDescription(){ private void updateInternalDescription() {
if (duration == -1) { if (duration == -1) {
duration = 0; duration = 0;
if (!isPhoto()) { if (!isPhoto()) {
@ -187,15 +186,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
private String convertDegToExifRational(double l) { private String convertDegToExifRational(double l) {
if(l < 0){ if (l < 0) {
l = -l; l = -l;
} }
String s = ((int) l) + "/1,"; //degrees String s = ((int) l) + "/1,"; // degrees
l = (l - ((int) l)) * 60.0; l = (l - ((int) l)) * 60.0;
s+= (int) l + "/1,"; //minutes s += (int) l + "/1,"; // minutes
l = (l - ((int) l)) * 60000.0; l = (l - ((int) l)) * 60000.0;
s+= (int) l + "/1000"; //seconds s += (int) l + "/1000"; // seconds
//log.info("deg rational: " + s); // log.info("deg rational: " + s);
return s; return s;
} }
@ -206,29 +205,31 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
Constructor c = exClass.getConstructor(new Class[] { String.class }); Constructor c = exClass.getConstructor(new Class[] { String.class });
Object exInstance = c.newInstance(file.getAbsolutePath()); Object exInstance = c.newInstance(file.getAbsolutePath());
Method setAttribute = exClass.getMethod("setAttribute", Method setAttribute = exClass.getMethod("setAttribute", new Class[] { String.class, String.class });
new Class[] { String.class, String.class } ); setAttribute.invoke(exInstance, "GPSLatitude", convertDegToExifRational(lat));
setAttribute.invoke(exInstance,"GPSLatitude", convertDegToExifRational(lat)); setAttribute.invoke(exInstance, "GPSLatitudeRef", lat > 0 ? "N" : "S");
setAttribute.invoke(exInstance,"GPSLatitudeRef", lat > 0 ?"N" :"S"); setAttribute.invoke(exInstance, "GPSLongitude", convertDegToExifRational(lon));
setAttribute.invoke(exInstance,"GPSLongitude", convertDegToExifRational(lon)); setAttribute.invoke(exInstance, "GPSLongitudeRef", lon > 0 ? "E" : "W");
setAttribute.invoke(exInstance,"GPSLongitudeRef", lon > 0?"E" : "W"); if (!Double.isNaN(rot)) {
if(!Double.isNaN(rot)){ setAttribute.invoke(exInstance, "GPSImgDirectionRef", "T");
setAttribute.invoke(exInstance,"GPSImgDirectionRef", "T"); while (rot < 0) {
while(rot < 0) { rot += 360; } rot += 360;
while(rot > 360) { rot -= 360; }
int abs = (int) (Math.abs(rot) * 100.0);
String rotString = abs/100f+"";
setAttribute.invoke(exInstance,"GPSImgDirection", rotString);
} }
if(loc != null && loc.hasAltitude()){ while (rot > 360) {
rot -= 360;
}
int abs = (int) (Math.abs(rot) * 100.0);
String rotString = abs / 100f + "";
setAttribute.invoke(exInstance, "GPSImgDirection", rotString);
}
if (loc != null && loc.hasAltitude()) {
double alt = loc.getAltitude(); double alt = loc.getAltitude();
String altString = (int) (Math.abs(alt) * 100.0) + "/100"; String altString = (int) (Math.abs(alt) * 100.0) + "/100";
System.err.println(altString); System.err.println(altString);
setAttribute.invoke(exInstance,"GPSAltitude", altString); setAttribute.invoke(exInstance, "GPSAltitude", altString);
setAttribute.invoke(exInstance,"GPSAltitudeRef", alt < 0 ? "1" : "0"); setAttribute.invoke(exInstance, "GPSAltitudeRef", alt < 0 ? "1" : "0");
} }
Method saveAttributes = exClass.getMethod("saveAttributes", Method saveAttributes = exClass.getMethod("saveAttributes", new Class[] {});
new Class[] {} );
saveAttributes.invoke(exInstance); saveAttributes.invoke(exInstance);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -244,8 +245,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
Constructor c = exClass.getConstructor(new Class[] { String.class }); Constructor c = exClass.getConstructor(new Class[] { String.class });
Object exInstance = c.newInstance(file.getAbsolutePath()); Object exInstance = c.newInstance(file.getAbsolutePath());
Method getAttributeInt = exClass.getMethod("getAttributeInt", Method getAttributeInt = exClass.getMethod("getAttributeInt", new Class[] { String.class, Integer.TYPE });
new Class[] { String.class, Integer.TYPE} );
Integer it = (Integer) getAttributeInt.invoke(exInstance, "Orientation", new Integer(1)); Integer it = (Integer) getAttributeInt.invoke(exInstance, "Orientation", new Integer(1));
orientation = it.intValue(); orientation = it.intValue();
} catch (Exception e) { } catch (Exception e) {
@ -271,53 +271,47 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return rotation; return rotation;
} }
public String getDescription(Context ctx){ public String getDescription(Context ctx) {
String nm = name == null? "" : name ; String nm = name == null ? "" : name;
if(isPhoto()){ if (isPhoto()) {
return ctx.getString(R.string.recording_photo_description, nm, return ctx.getString(R.string.recording_photo_description, nm, Algorithms.formatDateTime(file.lastModified())).trim();
Algorithms.formatDateTime(file.lastModified())).trim();
} }
updateInternalDescription(); updateInternalDescription();
return ctx.getString(R.string.recording_description, nm, getDuration(ctx), return ctx.getString(R.string.recording_description, nm, getDuration(ctx), Algorithms.formatDateTime(file.lastModified()))
Algorithms.formatDateTime(file.lastModified())).trim(); .trim();
} }
public String getSmallDescription(Context ctx){ public String getSmallDescription(Context ctx) {
String nm = name == null? "" : name ; String nm = name == null ? "" : name;
if(isPhoto()){ if (isPhoto()) {
return ctx.getString(R.string.recording_photo_description, nm, return ctx.getString(R.string.recording_photo_description, nm, Algorithms.formatDateTime(file.lastModified())).trim();
Algorithms.formatDateTime(file.lastModified())).trim();
} }
return ctx.getString(R.string.recording_description, nm, "", return ctx.getString(R.string.recording_description, nm, "", Algorithms.formatDateTime(file.lastModified())).trim();
Algorithms.formatDateTime(file.lastModified())).trim();
} }
private String getDuration(Context ctx) { private String getDuration(Context ctx) {
String additional = ""; String additional = "";
if(duration > 0) { if (duration > 0) {
int d = (int) (duration / 1000); int d = (int) (duration / 1000);
additional += Algorithms.formatDuration(d); additional += Algorithms.formatDuration(d);
} }
if(!available) { if (!available) {
additional += "("+ctx.getString(R.string.recording_unavailable)+")"; additional += "(" + ctx.getString(R.string.recording_unavailable) + ")";
} }
return additional; return additional;
} }
} }
private static void initializeRemoteControlRegistrationMethods() { private static void initializeRemoteControlRegistrationMethods() {
try { try {
if (mRegisterMediaButtonEventReceiver == null) { if (mRegisterMediaButtonEventReceiver == null) {
mRegisterMediaButtonEventReceiver = AudioManager.class.getMethod( mRegisterMediaButtonEventReceiver = AudioManager.class.getMethod("registerMediaButtonEventReceiver",
"registerMediaButtonEventReceiver", new Class[] { ComponentName.class });
new Class[] { ComponentName.class } );
} }
if (mUnregisterMediaButtonEventReceiver == null) { if (mUnregisterMediaButtonEventReceiver == null) {
mUnregisterMediaButtonEventReceiver = AudioManager.class.getMethod( mUnregisterMediaButtonEventReceiver = AudioManager.class.getMethod("unregisterMediaButtonEventReceiver",
"unregisterMediaButtonEventReceiver", new Class[] { ComponentName.class });
new Class[] { ComponentName.class } );
} }
/* success, this device will take advantage of better remote */ /* success, this device will take advantage of better remote */
/* control event handling */ /* control event handling */
@ -327,7 +321,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
@Override @Override
public String getId() { public String getId() {
return ID; return ID;
@ -341,7 +334,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
AV_VIDEO_FORMAT = settings.registerIntPreference("av_video_format", VIDEO_OUTPUT_MP4).makeGlobal(); AV_VIDEO_FORMAT = settings.registerIntPreference("av_video_format", VIDEO_OUTPUT_MP4).makeGlobal();
AV_DEFAULT_ACTION = settings.registerIntPreference("av_default_action", AV_DEFAULT_ACTION_CHOOSE).makeGlobal(); AV_DEFAULT_ACTION = settings.registerIntPreference("av_default_action", AV_DEFAULT_ACTION_CHOOSE).makeGlobal();
// camera focus type: // camera focus type:
AV_CAMERA_FOCUS_TYPE = settings.registerIntPreference("av_camera_focus_type",AV_CAMERA_FOCUS_AUTO).makeGlobal(); AV_CAMERA_FOCUS_TYPE = settings.registerIntPreference("av_camera_focus_type", AV_CAMERA_FOCUS_AUTO).makeGlobal();
// camera sound: // camera sound:
AV_PHOTO_PLAY_SOUND = settings.registerBooleanPreference("av_photo_play_sound", true).makeGlobal(); AV_PHOTO_PLAY_SOUND = settings.registerBooleanPreference("av_photo_play_sound", true).makeGlobal();
@ -362,19 +355,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public boolean init(final OsmandApplication app) { public boolean init(final OsmandApplication app) {
initializeRemoteControlRegistrationMethods(); initializeRemoteControlRegistrationMethods();
AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE);
if(am != null){ if (am != null) {
registerMediaListener(am); registerMediaListener(am);
} }
return true; return true;
} }
@Override @Override
public void registerLayers(MapActivity activity) { public void registerLayers(MapActivity activity) {
this.activity = activity; this.activity = activity;
if(audioNotesLayer != null) { if (audioNotesLayer != null) {
activity.getMapView().removeLayer(audioNotesLayer); activity.getMapView().removeLayer(audioNotesLayer);
} }
audioNotesLayer = new AudioNotesLayer(activity, this); audioNotesLayer = new AudioNotesLayer(activity, this);
@ -382,17 +372,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
registerWidget(activity); registerWidget(activity);
} }
private void registerMediaListener(AudioManager am) { private void registerMediaListener(AudioManager am) {
ComponentName receiver = new ComponentName(app.getPackageName(), ComponentName receiver = new ComponentName(app.getPackageName(), MediaRemoteControlReceiver.class.getName());
MediaRemoteControlReceiver.class.getName());
try { try {
if (mRegisterMediaButtonEventReceiver == null) { if (mRegisterMediaButtonEventReceiver == null) {
return; return;
} }
mRegisterMediaButtonEventReceiver.invoke(am, mRegisterMediaButtonEventReceiver.invoke(am, receiver);
receiver);
} catch (Exception ite) { } catch (Exception ite) {
log.error(ite.getMessage(), ite); log.error(ite.getMessage(), ite);
} }
@ -410,7 +397,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
@Override @Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
OnContextMenuClick listener = new OnContextMenuClick() { OnContextMenuClick listener = new OnContextMenuClick() {
@ -423,31 +409,31 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
}; };
adapter.item(R.string.layer_recordings).selected(SHOW_RECORDINGS.get()? 1 : 0) adapter.item(R.string.layer_recordings).selected(SHOW_RECORDINGS.get() ? 1 : 0)
.icons(R.drawable.ic_action_audio_dark, R.drawable.ic_action_audio_light).listen(listener).position(6).reg(); .icons(R.drawable.ic_action_audio_dark, R.drawable.ic_action_audio_light).listen(listener).position(6).reg();
} }
@Override @Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude,
Object selectedObj) { ContextMenuAdapter adapter, Object selectedObj) {
adapter.item(R.string.recording_context_menu_arecord).icons(R.drawable.ic_action_micro_dark, R.drawable.ic_action_micro_light) . adapter.item(R.string.recording_context_menu_arecord).icons(R.drawable.ic_action_micro_dark, R.drawable.ic_action_micro_light)
listen(new OnContextMenuClick() { .listen(new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
recordAudio(latitude, longitude, mapActivity); recordAudio(latitude, longitude, mapActivity);
} }
}).position(6).reg(); }).position(6).reg();
adapter.item(R.string.recording_context_menu_vrecord).icons(R.drawable.ic_action_video_dark, R.drawable.ic_action_video_light). adapter.item(R.string.recording_context_menu_vrecord).icons(R.drawable.ic_action_video_dark, R.drawable.ic_action_video_light)
listen(new OnContextMenuClick() { .listen(new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
recordVideo(latitude, longitude, mapActivity); recordVideo(latitude, longitude, mapActivity);
} }
}).position(7).reg(); }).position(7).reg();
adapter.item(R.string.recording_context_menu_precord).icons(R.drawable.ic_action_photo_dark, R.drawable.ic_action_photo_light). adapter.item(R.string.recording_context_menu_precord).icons(R.drawable.ic_action_photo_dark, R.drawable.ic_action_photo_light)
listen(new OnContextMenuClick() { .listen(new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
takePhoto(latitude, longitude, mapActivity); takePhoto(latitude, longitude, mapActivity);
@ -458,27 +444,25 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
if(SHOW_RECORDINGS.get()) { if (SHOW_RECORDINGS.get()) {
if(audioNotesLayer == null) { if (audioNotesLayer == null) {
registerLayers(activity); registerLayers(activity);
} else if(!mapView.getLayers().contains(audioNotesLayer)) { } else if (!mapView.getLayers().contains(audioNotesLayer)) {
mapView.addLayer(audioNotesLayer, 3.5f); mapView.addLayer(audioNotesLayer, 3.5f);
} }
} else if(audioNotesLayer != null){ } else if (audioNotesLayer != null) {
mapView.removeLayer(audioNotesLayer); mapView.removeLayer(audioNotesLayer);
} }
} }
private void registerWidget(MapActivity activity) { private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null ) { if (mapInfoLayer != null) {
recordControl = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText()); recordControl = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText());
recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive)); recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive));
setRecordListener(recordControl, activity); setRecordListener(recordControl, activity);
mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, R.drawable.widget_icon_av_inactive,
R.drawable.widget_icon_av_inactive, R.string.map_widget_av_notes, "audionotes", false, R.string.map_widget_av_notes, "audionotes", false, EnumSet.allOf(ApplicationMode.class),
EnumSet.allOf(ApplicationMode.class),
EnumSet.noneOf(ApplicationMode.class), 22); EnumSet.noneOf(ApplicationMode.class), 22);
mapInfoLayer.recreateControls(); mapInfoLayer.recreateControls();
} }
@ -496,7 +480,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}); });
} }
private void updateWidgetIcon(final TextInfoWidget recordPlaceControl) { private void updateWidgetIcon(final TextInfoWidget recordPlaceControl) {
recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_inactive)); recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_inactive));
if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_VIDEO) { if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_VIDEO) {
@ -526,18 +509,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
private void chooseDefaultAction(final double lat, final double lon, final MapActivity mapActivity) { private void chooseDefaultAction(final double lat, final double lon, final MapActivity mapActivity) {
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(mapActivity); AccessibleAlertBuilder ab = new AccessibleAlertBuilder(mapActivity);
ab.setItems(new String[] { ab.setItems(
mapActivity.getString(R.string.recording_context_menu_arecord), new String[] { mapActivity.getString(R.string.recording_context_menu_arecord),
mapActivity.getString(R.string.recording_context_menu_vrecord), mapActivity.getString(R.string.recording_context_menu_vrecord),
mapActivity.getString(R.string.recording_context_menu_precord), mapActivity.getString(R.string.recording_context_menu_precord), }, new OnClickListener() {
}, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
int action = which == 0 ? AV_DEFAULT_ACTION_AUDIO : int action = which == 0 ? AV_DEFAULT_ACTION_AUDIO : (which == 1 ? AV_DEFAULT_ACTION_VIDEO
(which == 1 ? AV_DEFAULT_ACTION_VIDEO:AV_DEFAULT_ACTION_TAKEPICTURE); : AV_DEFAULT_ACTION_TAKEPICTURE);
takeAction(mapActivity, lon, lat, action); takeAction(mapActivity, lon, lat, action);
} }
@ -545,7 +526,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
ab.show(); ab.show();
} }
private void takeAction(final MapActivity mapActivity, double lon, double lat, int action) { private void takeAction(final MapActivity mapActivity, double lon, double lat, int action) {
if (action == AV_DEFAULT_ACTION_VIDEO) { if (action == AV_DEFAULT_ACTION_VIDEO) {
recordVideo(lat, lon, mapActivity); recordVideo(lat, lon, mapActivity);
@ -556,7 +536,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
private File getBaseFileName(double lat, double lon, OsmandApplication app, String ext) { private File getBaseFileName(double lat, double lon, OsmandApplication app, String ext) {
String basename = MapUtils.createShortLocString(lat, lon, 15); String basename = MapUtils.createShortLocString(lat, lon, 15);
int k = 1; int k = 1;
@ -565,7 +544,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
File fl; File fl;
do { do {
fl = new File(f, basename + "-" + (k++) + "." + ext); fl = new File(f, basename + "-" + (k++) + "." + ext);
} while(fl.exists()); } while (fl.exists());
return fl; return fl;
} }
@ -581,7 +560,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
String ext = MPEG4_EXTENSION; String ext = MPEG4_EXTENSION;
if(AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP ){ if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) {
ext = THREEGP_EXTENSION; ext = THREEGP_EXTENSION;
} }
Uri fileUri = Uri.fromFile(getBaseFileName(lat, lon, app, ext)); Uri fileUri = Uri.fromFile(getBaseFileName(lat, lon, app, ext));
@ -598,7 +577,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
public void recordVideo(final double lat, final double lon, final MapActivity mapActivity) { public void recordVideo(final double lat, final double lon, final MapActivity mapActivity) {
if(AV_EXTERNAL_RECORDER.get()) { if (AV_EXTERNAL_RECORDER.get()) {
captureVideoExternal(lat, lon, mapActivity); captureVideoExternal(lat, lon, mapActivity);
} else { } else {
recordVideoCamera(lat, lon, mapActivity); recordVideoCamera(lat, lon, mapActivity);
@ -619,14 +598,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
MediaRecorder mr = new MediaRecorder(); MediaRecorder mr = new MediaRecorder();
String ext = MPEG4_EXTENSION; String ext = MPEG4_EXTENSION;
if(AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP ){ if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) {
ext = THREEGP_EXTENSION; ext = THREEGP_EXTENSION;
} }
final File f = getBaseFileName(lat, lon, app,ext ); final File f = getBaseFileName(lat, lon, app, ext);
mr.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mr.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mr.setVideoSource(MediaRecorder.VideoSource.CAMERA); mr.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if(AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP ){ if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) {
mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
} else { } else {
mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
@ -680,7 +659,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
protected Camera openCamera() { protected Camera openCamera() {
try { try {
return Camera.open(); return Camera.open();
} catch (Exception e ){ } catch (Exception e) {
logErr(e); logErr(e);
return null; return null;
} }
@ -697,7 +676,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
public void recordAudio(double lat, double lon, final MapActivity mapActivity) { public void recordAudio(double lat, double lon, final MapActivity mapActivity) {
MediaRecorder mr = new MediaRecorder(); MediaRecorder mr = new MediaRecorder();
final File f = getBaseFileName(lat, lon, app, THREEGP_EXTENSION); final File f = getBaseFileName(lat, lon, app, THREEGP_EXTENSION);
@ -727,7 +705,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
private void takePhotoWithCamera(final double lat, final double lon, final MapActivity mapActivity, final Camera cam) { private void takePhotoWithCamera(final double lat, final double lon, final MapActivity mapActivity, final Camera cam) {
try { try {
final Dialog dlg = new Dialog(mapActivity); final Dialog dlg = new Dialog(mapActivity);
@ -748,16 +725,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
int rotation = mapActivity.getWindowManager().getDefaultDisplay().getRotation(); int rotation = mapActivity.getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0; int degrees = 0;
switch (rotation) { switch (rotation) {
case /*Surface.ROTATION_0*/ 0: case /* Surface.ROTATION_0 */0:
degrees = 0; degrees = 0;
break; break;
case /*Surface.ROTATION_90*/ 1: case /* Surface.ROTATION_90 */1:
degrees = 90; degrees = 90;
break; break;
case /*Surface.ROTATION_180*/ 2: case /* Surface.ROTATION_180 */2:
degrees = 180; degrees = 180;
break; break;
case /*Surface.ROTATION_270*/ 3: case /* Surface.ROTATION_270 */3:
degrees = 270; degrees = 270;
break; break;
} }
@ -780,10 +757,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
// camera focus type: // camera focus type:
boolean autofocus = true; boolean autofocus = true;
// boolean autofocus = !Boolean.parseBoolean(parameters.get("auto-exposure-lock-supported")); // boolean autofocus = !Boolean.parseBoolean(parameters.get("auto-exposure-lock-supported"));
parameters.setGpsLatitude(lat); parameters.setGpsLatitude(lat);
parameters.setGpsLongitude(lon); parameters.setGpsLongitude(lon);
switch( AV_CAMERA_FOCUS_TYPE.get() ) { switch (AV_CAMERA_FOCUS_TYPE.get()) {
case AV_CAMERA_FOCUS_HIPERFOCAL: case AV_CAMERA_FOCUS_HIPERFOCAL:
parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
autofocus = false; autofocus = false;
@ -812,16 +789,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
log.info("Osmand:AudioNotes set camera FOCUS_MODE_AUTO"); log.info("Osmand:AudioNotes set camera FOCUS_MODE_AUTO");
break; break;
} }
// parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); // parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
// parameters.set("auto-exposure-lock", "true"); // parameters.set("auto-exposure-lock", "true");
//} // }
// load sound befor shot: // load sound befor shot:
if (AV_PHOTO_PLAY_SOUND.get()) { if (AV_PHOTO_PLAY_SOUND.get()) {
if(sp==null) if (sp == null)
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
log.info("Play sound on photo"); log.info("Play sound on photo");
if(shotId==0) if (shotId == 0) {
{
shotId = sp.load(app.getAssets().openFd("sounds/camera_click.ogg"), 1); shotId = sp.load(app.getAssets().openFd("sounds/camera_click.ogg"), 1);
log.debug("loaded file sound ID: " + shotId); log.debug("loaded file sound ID: " + shotId);
} }
@ -853,8 +829,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
private void printCamParams(Parameters parameters, boolean autoExposure) { private void printCamParams(Parameters parameters, boolean autoExposure) {
log.info("Cam params auto exposure=" + autoExposure + log.info("Cam params auto exposure=" + autoExposure + " focus_distances=" + parameters.get("focus-distances"));
" focus_distances="+parameters.get("focus-distances"));
} }
@Override @Override
@ -869,7 +844,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
private void takeIntentPhoto(double lat, double lon, final MapActivity mapActivity) { private void takeIntentPhoto(double lat, double lon, final MapActivity mapActivity) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
final File f = getBaseFileName(lat, lon, app, IMG_EXTENSION); final File f = getBaseFileName(lat, lon, app, IMG_EXTENSION);
@ -892,7 +866,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
final MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer(); final MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
final StackWidgetView par = mil.getRightStack(); final StackWidgetView par = mil.getRightStack();
final boolean contains = par.getAllViews().contains(recordControl); final boolean contains = par.getAllViews().contains(recordControl);
if(!contains) { if (!contains) {
par.addStackView(recordControl); par.addStackView(recordControl);
mapActivity.getMapView().refreshMap(true); mapActivity.getMapView().refreshMap(true);
} }
@ -900,7 +874,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
recordControl.setOnClickListener(new View.OnClickListener() { recordControl.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(!contains) { if (!contains) {
par.removeView(recordControl); par.removeView(recordControl);
} }
stopRecording(mapActivity); stopRecording(mapActivity);
@ -912,19 +886,19 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}); });
} }
public void indexFile(File f){ public void indexFile(File f) {
boolean oldFileExist = recordingByFileName.containsKey(f.getName()); boolean oldFileExist = recordingByFileName.containsKey(f.getName());
if(oldFileExist){ if (oldFileExist) {
return; return;
} }
Recording r = new Recording(f); Recording r = new Recording(f);
String encodeName = f.getName(); String encodeName = f.getName();
int i = encodeName.indexOf('-'); int i = encodeName.indexOf('-');
if(i > 0) { if (i > 0) {
encodeName = encodeName.substring(0, i); encodeName = encodeName.substring(0, i);
} }
i = encodeName.indexOf('.'); i = encodeName.indexOf('.');
if(i > 0) { if (i > 0) {
encodeName = encodeName.substring(0, i); encodeName = encodeName.substring(0, i);
} }
r.file = f; r.file = f;
@ -933,7 +907,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
r.lon = l.getLongitude(); r.lon = l.getLongitude();
Float heading = app.getLocationProvider().getHeading(); Float heading = app.getLocationProvider().getHeading();
Location loc = app.getLocationProvider().getLastKnownLocation(); Location loc = app.getLocationProvider().getLastKnownLocation();
if(lastTakingPhoto != null && lastTakingPhoto.getName().equals(f.getName()) && heading != null) { if (lastTakingPhoto != null && lastTakingPhoto.getName().equals(f.getName()) && heading != null) {
float rot = heading.floatValue(); float rot = heading.floatValue();
try { try {
r.updatePhotoInformation(r.lat, r.lon, loc, rot == 0 ? Double.NaN : rot); r.updatePhotoInformation(r.lat, r.lon, loc, rot == 0 ? Double.NaN : rot);
@ -949,30 +923,41 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void disable(OsmandApplication app) { public void disable(OsmandApplication app) {
AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE);
if(am != null){ if (am != null) {
unregisterMediaListener(am); unregisterMediaListener(am);
} }
} }
@Override @Override
public List<String> indexingFiles(IProgress progress) { public List<String> indexingFiles(IProgress progress) {
return indexingFiles(progress, true); return indexingFiles(progress, true, false);
} }
public List<String> indexingFiles(IProgress progress, boolean reIndexAndKeepOld) { public List<String> indexingFiles(IProgress progress, boolean reIndexAndKeepOld, boolean registerNew) {
File avPath = app.getAppPath(IndexConstants.AV_INDEX_DIR); File avPath = app.getAppPath(IndexConstants.AV_INDEX_DIR);
if (avPath.canRead()) { if (avPath.canRead()) {
if(!reIndexAndKeepOld) { if (!reIndexAndKeepOld) {
recordings.clear(); recordings.clear();
recordingByFileName.clear(); recordingByFileName.clear();
} }
File[] files = avPath.listFiles(); File[] files = avPath.listFiles();
if (files != null) { if (files != null) {
for (File f : files) { for (File f : files) {
if(f.getName().endsWith(THREEGP_EXTENSION) if (f.getName().endsWith(THREEGP_EXTENSION) || f.getName().endsWith(MPEG4_EXTENSION)
|| f.getName().endsWith(MPEG4_EXTENSION)
|| f.getName().endsWith(IMG_EXTENSION)) { || f.getName().endsWith(IMG_EXTENSION)) {
indexFile(f); indexFile(f);
if (registerNew) {
Recording rec = recordingByFileName.get(f.getName());
if (rec != null) {
String name = f.getName();
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
savingTrackHelper.insertPointData(rec.lat, rec.lon, System.currentTimeMillis(), name);
if (app.getSettings().SHOW_CURRENT_GPX_TRACK.get()) {
app.getFavorites().addFavoritePointToGPXFile(new FavouritePoint(rec.lat, rec.lon, name, ""));
}
}
}
} }
} }
} }
@ -980,23 +965,21 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return null; return null;
} }
public DataTileManager<Recording> getRecordings() { public DataTileManager<Recording> getRecordings() {
return recordings; return recordings;
} }
private void checkRecordings(){ private void checkRecordings() {
Iterator<Recording> it = recordingByFileName.values().iterator(); Iterator<Recording> it = recordingByFileName.values().iterator();
while(it.hasNext()){ while (it.hasNext()) {
Recording r = it.next(); Recording r = it.next();
if(!r.file.exists()) { if (!r.file.exists()) {
it.remove(); it.remove();
recordings.unregisterObject(r.lat, r.lon, r); recordings.unregisterObject(r.lat, r.lon, r);
} }
} }
} }
public void deleteRecording(Recording r) { public void deleteRecording(Recording r) {
recordings.unregisterObject(r.lat, r.lon, r); recordings.unregisterObject(r.lat, r.lon, r);
recordingByFileName.remove(r.file.getName()); recordingByFileName.remove(r.file.getName());
@ -1005,7 +988,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
activity.getMapView().refreshMap(); activity.getMapView().refreshMap();
} }
@Override @Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) { public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
Preference grp = new Preference(activity); Preference grp = new Preference(activity);
@ -1024,13 +1006,13 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) { public void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 205) { if (requestCode == 205) {
indexingFiles(null, true); indexingFiles(null, true, true);
} }
} }
public boolean onMapActivityKeyEvent(KeyEvent key){ public boolean onMapActivityKeyEvent(KeyEvent key) {
if(KeyEvent.KEYCODE_CAMERA == key.getKeyCode()) { if (KeyEvent.KEYCODE_CAMERA == key.getKeyCode()) {
defaultAction(activity); defaultAction(activity);
return true; return true;
} }
@ -1088,15 +1070,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
playRecording(la, ri.rec); playRecording(la, ri.rec);
} }
}; };
if(ri.rec.isPhoto()) { if (ri.rec.isPhoto()) {
adapter.item(R.string.recording_context_menu_show).icons( adapter.item(R.string.recording_context_menu_show).icons(R.drawable.ic_action_eye_dark, R.drawable.ic_action_eye_light)
R.drawable.ic_action_eye_dark, R.drawable.ic_action_eye_light).listen(listener).reg(); .listen(listener).reg();
} else { } else {
adapter.item(R.string.recording_context_menu_play).icons( adapter.item(R.string.recording_context_menu_play).icons(R.drawable.ic_action_play_dark, R.drawable.ic_action_play_light)
R.drawable.ic_action_play_dark, R.drawable.ic_action_play_light).listen(listener).reg(); .listen(listener).reg();
} }
adapter.item(R.string.show_location).icons(R.drawable.ic_action_marker_dark, R.drawable.ic_action_marker_light). adapter.item(R.string.show_location).icons(R.drawable.ic_action_marker_dark, R.drawable.ic_action_marker_light)
listen(new OnContextMenuClick() { .listen(new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
SHOW_RECORDINGS.set(true); SHOW_RECORDINGS.set(true);
@ -1108,7 +1090,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
public Collection<Recording> getAllRecordings(){ public Collection<Recording> getAllRecordings() {
return recordingByFileName.values(); return recordingByFileName.values();
} }
@ -1128,7 +1110,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return res; return res;
} }
public void playRecording(final Context ctx, final Recording r) { public void playRecording(final Context ctx, final Recording r) {
final MediaPlayer player = r.isPhoto() ? null : new MediaPlayer(); final MediaPlayer player = r.isPhoto() ? null : new MediaPlayer();
final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(ctx); final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(ctx);
@ -1136,7 +1117,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override @Override
public void onClick(DialogInterface v, int w) { public void onClick(DialogInterface v, int w) {
if(player == null) { if (player == null) {
Intent vint = new Intent(Intent.ACTION_VIEW); Intent vint = new Intent(Intent.ACTION_VIEW);
vint.setDataAndType(Uri.fromFile(r.file), "image/*"); vint.setDataAndType(Uri.fromFile(r.file), "image/*");
vint.setFlags(0x10000000); vint.setFlags(0x10000000);
@ -1156,11 +1137,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
} }
} }
}); });
dlg.setNegativeButton(R.string.default_buttons_cancel, new OnClickListener(){ dlg.setNegativeButton(R.string.default_buttons_cancel, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if(player != null && player.isPlaying()) { if (player != null && player.isPlaying()) {
player.stop(); player.stop();
} }
@ -1226,21 +1207,18 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
FileOutputStream fos = new FileOutputStream(pictureFile); FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data); fos.write(data);
fos.close(); fos.close();
indexingFiles(null, true); indexingFiles(null, true, true);
dlg.dismiss(); dlg.dismiss();
// play sound after photo - sound file must be loaded at this time: // play sound after photo - sound file must be loaded at this time:
if (AV_PHOTO_PLAY_SOUND.get()) { if (AV_PHOTO_PLAY_SOUND.get()) {
if(sp!=null && shotId!=0) if (sp != null && shotId != 0) {
{ int ret = sp.play(shotId, 0.7f, 0.7f, 0, 0, 1);
int ret=sp.play(shotId, 0.7f, 0.7f, 0, 0, 1);
log.debug("play sound shot success!"); log.debug("play sound shot success!");
log.debug("sp.play()="+ret); log.debug("sp.play()=" + ret);
// sp.release(); // sp.release();
// sp=null; // sp=null;
// shotId=0 // shotId=0
} } else {
else
{
log.error("can not play sound on shot - not init SoundPool or not loaded sound"); log.error("can not play sound on shot - not init SoundPool or not loaded sound");
} }
} }