From 1ef07093b344a71adafa0f02775afc130439b457 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 18 Jul 2013 23:30:42 +0200 Subject: [PATCH] Fix issue 1945 --- .gitignore | 1 + OsmAnd/res/drawable-hdpi/mx_natural_peak.png | Bin 1134 -> 384 bytes .../res/drawable-hdpi/mx_railway_station.png | Bin 1356 -> 216 bytes OsmAnd/res/drawable-mdpi/mx_natural_peak.png | Bin 750 -> 279 bytes .../res/drawable-mdpi/mx_railway_station.png | Bin 892 -> 186 bytes OsmAnd/res/drawable-xhdpi/mx_natural_peak.png | Bin 1558 -> 483 bytes .../res/drawable-xhdpi/mx_railway_station.png | Bin 1821 -> 252 bytes OsmAnd/res/values-de/strings.xml | 3 +- .../audionotes/AudioVideoNotesPlugin.java | 600 +++++++++--------- 9 files changed, 292 insertions(+), 312 deletions(-) diff --git a/.gitignore b/.gitignore index 9f6379075e..5f0f2adb6c 100755 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ countries.reginfo h_*.png g_*.png mm_*.png +mx_*.png diff --git a/OsmAnd/res/drawable-hdpi/mx_natural_peak.png b/OsmAnd/res/drawable-hdpi/mx_natural_peak.png index bbba9d39398d773817ea8e31676922feb328a41d..dade24e4a55f440dc3762e915d820796c92ea828 100644 GIT binary patch delta 340 zcmV-a0jvJ*2!I2SHGcs$Nkl%TeZZ` zZvaz3H}QLtIRTp15rbL*UVvv{*|;TI9k>8K+|Eh=a~-NJzJKHWHcg8n%mB9(54ZuQ z4ZDIJP>lE6H|z?s2s}`JKo?jrs|#>OdA#4LSzU!S;GOCN-hfr3#!_QIo9cMKw)@V= z*daXLZ`-7_k2#=2`~e+c)}XiGi1>KFLxbL5mVhS)Kj6_l!%VABRP0*WtDOy?7Z6yr z9TZiLZr5$AfhW9LrAS%DrAv}7LlTYR*)iSFfJq}G=XH^ zJudP_Cd179`7@JiSV zBum2P=H?uL?y<44Y^yl;&A{mBXeY_z0HCU`wu*P(40LyQUn=R><(zw_6}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^W%@ z0Am0?0XX8EJ1*&~bM7pFZzT6Ls?A0TVHh3*aOsypBqSlrvICMPNG>5+o_!a9ZvX~8 z&pR#Y%IN6mv3m6zt$+b=u{tOTv&Qc|&&w*zF>4M0Pk#XvNgirsP*>L4=OouT=Pr|c z2cW|_ca>xTz#{-38%$u5#KbJlO)|I zdDuBO0^m%ooVr_(B*{I^=wwrF^>u^f(l88ST+;U@IUY+I^nL#h zfZlR&?j*F=-Z{6lMlBz}+FB-( rR`|Z(S*veya&j|(@xP*9)PJX+r}P&_(?tNb00000NkvXXu0mjf;8IB} diff --git a/OsmAnd/res/drawable-mdpi/mx_railway_station.png b/OsmAnd/res/drawable-mdpi/mx_railway_station.png index 84b5a303ebb5b033eb0a127f842d3dd3e121f330..ac115ea7bc867e2a5c93787e137a0814c2ff1608 100644 GIT binary patch delta 141 zcmV;80CNBQ2D$-|HGcqaNklXE=qfiPEUSB v0SZun0{Ba49`uDXr~Ux&gJ&cnGTaSXffpqmCdj}50000NyIR3 zA_xKl38KpsYMmx^C1gopcg}VWMv%}&7ez6Ypy*0OA{{2BSZ8N*QzAu9lk#G%^XL6` z@jJ);Iqsa_kF6{H-u&Kw&-;Ad-}}4|4?NKQE~^{KTzv~Fdw#co&x43tGx}hx+6)P zF9NWg1b$(#`+ruV9i%VsUYEl29G%#h#5{_DUd)Wz*P3{`13CvxEE;c{2NRIJgmE5t zilA>89{Ymq9k1VCCK5UnAIF zeEBg#>Qm6;nB7F-37p#{;sAYQollsTl;KmdOVna9cSEuJ7E=Q@OJ zgi`5REf18VJg}m2hz%eJ6e)!>z$&C^WPJd%wSUjn^1$TM`>cSBR$w#G1-1oeM=*@? zY)=H>ThgHG|0~3NNe=-Y=lopWJwEj`<>F^i9B75|LL*tg*>j6ZvZ)Sy>F``V=nBBM z^|owBp?6vS9e0@h=ffxnv%jvV(%Oki?Ld02PSRy$^#Futu~@GKj7h|Kuu+08;_MIF z+D&h=ziS3+2}7xaSlCxz2Wtza3yDt`Wxo-ua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^e~) zGkjYR{JEm=6x`O|-`_cz&!hraYxg5q^8t*i>ejllY%Zrr9u3+OymhKdRRPlJ^vwY7 zEA&LWMJXJ3;an03$(LT-V)E&40e40G{Wq z5|Q(zXH^Zow6q$M#ar{LFI3Bx#1<`D)HQwj^if`Cb4U%8kdw#KgqJ#Kc^d Z`~%ihRp^J}z-<5k002ovPDHLkV1nIY@)Q67 diff --git a/OsmAnd/res/drawable-xhdpi/mx_railway_station.png b/OsmAnd/res/drawable-xhdpi/mx_railway_station.png index 7ad47cf5f673a2b3c5c4396a29db41e30290765a..d1a1a675cde1f1fd43cde55d014b1b90d70583b3 100644 GIT binary patch delta 207 zcmbQs_lI$UX+6V6PZ!6KiaBp@ZscTg6lr-_e^gA*U>oDz^fC14YZ%a4{`d&%OTp+N$ek8}`LD zxQ8aaWjOHt7Y(m)oNwa&1dlWa6G@3ve9&i>G#unLihnj8IZI3Qn`_kSG eZ0)2aCujyKq{}b1qz{6q~M}fJX^B6300$pR*~AOty)ovAe2;5RRO9Hj|Mrh zcWpTlh)0Qt8o(RdJ9GFjj%Ri~`-peO7_+}GJG1xB{ogrr=YQOD?j2~;rcIkRZQ6WT zk)~?xJiMB+wE;ssRCR}GjJ(J|?}<>`Jq;QgAX~f%oE;z~1PxbS4PsI#hY@Ehne^k~ zw%?fg2G}wBX^cDtbVS?_1*SmnWgvY=#99@Yx}_p_fz+=P4gw@WZYN*7dJ*(0goDYB z_kw*0AqGqWD}TaQmq}Es+kJ(^iFN#N<4ov!0mNz-l?M^AXGg$c692z6)J_cz$5|bF z5u_jggAnOrYSs6Ey`gEslG%B}+{zQg0OyjT(I9c((J0gZqZEl8Y zkzfO)%=bZU_e91R>^TsL`p5eo0STA_rJLN?m62#xQGd(9-3GD}co(=kGWE@3gZ`H4 zQ2;3nKZ{J)$9x0iMn40rbx#z^$-hS012ump$Qi5lkRAJaq}l|I0J#Pw226pqhg&~U zinIrVJw$(|;|I=gIU>L@7Rp>Z2e|KuHqhR`R3$QAtFi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1$d:%2$02d:%3$02d Als Ziel wählen diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 0c85836e70..d2c1e30a77 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -1,6 +1,5 @@ package net.osmand.plus.audionotes; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -23,6 +22,7 @@ import net.osmand.PlatformUtil; import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleToast; import net.osmand.data.DataTileManager; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; 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.LoadLocalIndexTask; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -67,7 +68,6 @@ import android.media.MediaPlayer; import android.media.MediaPlayer.OnPreparedListener; import android.media.MediaRecorder; import android.media.SoundPool; -import android.media.SoundPool.OnLoadCompleteListener; import android.net.Uri; import android.os.Build; import android.preference.Preference; @@ -89,22 +89,22 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public static final String ID = "osmand.audionotes"; public static final String THREEGP_EXTENSION = "3gp"; - public static final String MPEG4_EXTENSION = "mp4"; - public static final String IMG_EXTENSION = "jpg"; + public static final String MPEG4_EXTENSION = "mp4"; + public static final String IMG_EXTENSION = "jpg"; private static final Log log = PlatformUtil.getLog(AudioVideoNotesPlugin.class); private static Method mRegisterMediaButtonEventReceiver; private static Method mUnregisterMediaButtonEventReceiver; private OsmandApplication app; private TextInfoWidget recordControl; - - public final CommonPreference AV_EXTERNAL_RECORDER ; - public final CommonPreference AV_EXTERNAL_PHOTO_CAM ; - public final CommonPreference AV_PHOTO_PLAY_SOUND ; - + + public final CommonPreference AV_EXTERNAL_RECORDER; + public final CommonPreference AV_EXTERNAL_PHOTO_CAM; + public final CommonPreference AV_PHOTO_PLAY_SOUND; + public static final int VIDEO_OUTPUT_MP4 = 0; public static final int VIDEO_OUTPUT_3GP = 1; public final CommonPreference AV_VIDEO_FORMAT; - + public static final int AV_DEFAULT_ACTION_AUDIO = 0; public static final int AV_DEFAULT_ACTION_VIDEO = 1; public static final int AV_DEFAULT_ACTION_TAKEPICTURE = 2; @@ -112,51 +112,50 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // camera focus type public static final int AV_CAMERA_FOCUS_AUTO = 0; - public static final int AV_CAMERA_FOCUS_HIPERFOCAL = 1; - public static final int AV_CAMERA_FOCUS_EDOF = 2; - public static final int AV_CAMERA_FOCUS_INFINITY = 3; - public static final int AV_CAMERA_FOCUS_MACRO = 4; - public static final int AV_CAMERA_FOCUS_CONTINUOUS = 5; + public static final int AV_CAMERA_FOCUS_HIPERFOCAL = 1; + public static final int AV_CAMERA_FOCUS_EDOF = 2; + public static final int AV_CAMERA_FOCUS_INFINITY = 3; + public static final int AV_CAMERA_FOCUS_MACRO = 4; + public static final int AV_CAMERA_FOCUS_CONTINUOUS = 5; // shoto shot: private static int shotId = 0; private SoundPool sp = null; public final CommonPreference AV_CAMERA_FOCUS_TYPE; - - public final CommonPreference AV_DEFAULT_ACTION; - - public final OsmandPreference SHOW_RECORDINGS ; - - + public final CommonPreference AV_DEFAULT_ACTION; + + public final OsmandPreference SHOW_RECORDINGS; + private DataTileManager recordings = new DataTileManager(14); private Map recordingByFileName = new LinkedHashMap(); private AudioNotesLayer audioNotesLayer; private MapActivity activity; private MediaRecorder mediaRec; private File lastTakingPhoto; - + public static class Recording { public Recording(File f) { this.file = f; } + public File file; public String name; - + private double lat; private double lon; private long duration = -1; private boolean available = true; - - public double getLatitude(){ + + public double getLatitude() { return lat; } - - public double getLongitude(){ + + public double getLongitude() { return lon; } - - private void updateInternalDescription(){ + + private void updateInternalDescription() { if (duration == -1) { duration = 0; if (!isPhoto()) { @@ -177,65 +176,67 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { public boolean isPhoto() { return file.getName().endsWith(IMG_EXTENSION); } - + public boolean isVideo() { return file.getName().endsWith(MPEG4_EXTENSION) || file.getName().endsWith(THREEGP_EXTENSION); } - + public boolean isAudio() { return file.getName().endsWith(MPEG4_EXTENSION) || file.getName().endsWith(THREEGP_EXTENSION); } private String convertDegToExifRational(double l) { - if(l < 0){ + if (l < 0) { l = -l; } - String s = ((int) l) + "/1,"; //degrees + String s = ((int) l) + "/1,"; // degrees l = (l - ((int) l)) * 60.0; - s+= (int) l + "/1,"; //minutes + s += (int) l + "/1,"; // minutes l = (l - ((int) l)) * 60000.0; - s+= (int) l + "/1000"; //seconds - //log.info("deg rational: " + s); + s += (int) l + "/1000"; // seconds + // log.info("deg rational: " + s); return s; } - + @SuppressWarnings("rawtypes") public void updatePhotoInformation(double lat, double lon, Location loc, double rot) throws IOException { try { Class exClass = Class.forName("android.media.ExifInterface"); - + Constructor c = exClass.getConstructor(new Class[] { String.class }); Object exInstance = c.newInstance(file.getAbsolutePath()); - Method setAttribute = exClass.getMethod("setAttribute", - new Class[] { String.class, String.class } ); - setAttribute.invoke(exInstance,"GPSLatitude", convertDegToExifRational(lat)); - setAttribute.invoke(exInstance,"GPSLatitudeRef", lat > 0 ?"N" :"S"); - setAttribute.invoke(exInstance,"GPSLongitude", convertDegToExifRational(lon)); - setAttribute.invoke(exInstance,"GPSLongitudeRef", lon > 0?"E" : "W"); - if(!Double.isNaN(rot)){ - setAttribute.invoke(exInstance,"GPSImgDirectionRef", "T"); - while(rot < 0) { rot += 360; } - while(rot > 360) { rot -= 360; } + Method setAttribute = exClass.getMethod("setAttribute", new Class[] { String.class, String.class }); + setAttribute.invoke(exInstance, "GPSLatitude", convertDegToExifRational(lat)); + setAttribute.invoke(exInstance, "GPSLatitudeRef", lat > 0 ? "N" : "S"); + setAttribute.invoke(exInstance, "GPSLongitude", convertDegToExifRational(lon)); + setAttribute.invoke(exInstance, "GPSLongitudeRef", lon > 0 ? "E" : "W"); + if (!Double.isNaN(rot)) { + setAttribute.invoke(exInstance, "GPSImgDirectionRef", "T"); + while (rot < 0) { + rot += 360; + } + while (rot > 360) { + rot -= 360; + } int abs = (int) (Math.abs(rot) * 100.0); - String rotString = abs/100f+""; - setAttribute.invoke(exInstance,"GPSImgDirection", rotString); + String rotString = abs / 100f + ""; + setAttribute.invoke(exInstance, "GPSImgDirection", rotString); } - if(loc != null && loc.hasAltitude()){ + if (loc != null && loc.hasAltitude()) { double alt = loc.getAltitude(); String altString = (int) (Math.abs(alt) * 100.0) + "/100"; System.err.println(altString); - setAttribute.invoke(exInstance,"GPSAltitude", altString); - setAttribute.invoke(exInstance,"GPSAltitudeRef", alt < 0 ? "1" : "0"); + setAttribute.invoke(exInstance, "GPSAltitude", altString); + setAttribute.invoke(exInstance, "GPSAltitudeRef", alt < 0 ? "1" : "0"); } - Method saveAttributes = exClass.getMethod("saveAttributes", - new Class[] {} ); + Method saveAttributes = exClass.getMethod("saveAttributes", new Class[] {}); saveAttributes.invoke(exInstance); } catch (Exception e) { e.printStackTrace(); log.error(e); } } - + @SuppressWarnings("rawtypes") private int getExifOrientation() { int orientation = 0; @@ -244,8 +245,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { Constructor c = exClass.getConstructor(new Class[] { String.class }); Object exInstance = c.newInstance(file.getAbsolutePath()); - Method getAttributeInt = exClass.getMethod("getAttributeInt", - new Class[] { String.class, Integer.TYPE} ); + Method getAttributeInt = exClass.getMethod("getAttributeInt", new Class[] { String.class, Integer.TYPE }); Integer it = (Integer) getAttributeInt.invoke(exInstance, "Orientation", new Integer(1)); orientation = it.intValue(); } catch (Exception e) { @@ -254,7 +254,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } return orientation; } - + public int getBitmapRotation() { int rotation = 0; switch (getExifOrientation()) { @@ -270,64 +270,57 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } return rotation; } - - public String getDescription(Context ctx){ - String nm = name == null? "" : name ; - if(isPhoto()){ - return ctx.getString(R.string.recording_photo_description, nm, - Algorithms.formatDateTime(file.lastModified())).trim(); + + public String getDescription(Context ctx) { + String nm = name == null ? "" : name; + if (isPhoto()) { + return ctx.getString(R.string.recording_photo_description, nm, Algorithms.formatDateTime(file.lastModified())).trim(); } updateInternalDescription(); - return ctx.getString(R.string.recording_description, nm, getDuration(ctx), - Algorithms.formatDateTime(file.lastModified())).trim(); + return ctx.getString(R.string.recording_description, nm, getDuration(ctx), Algorithms.formatDateTime(file.lastModified())) + .trim(); } - - public String getSmallDescription(Context ctx){ - String nm = name == null? "" : name ; - if(isPhoto()){ - return ctx.getString(R.string.recording_photo_description, nm, - Algorithms.formatDateTime(file.lastModified())).trim(); + + public String getSmallDescription(Context ctx) { + String nm = name == null ? "" : name; + if (isPhoto()) { + return ctx.getString(R.string.recording_photo_description, nm, Algorithms.formatDateTime(file.lastModified())).trim(); } - return ctx.getString(R.string.recording_description, nm, "", - Algorithms.formatDateTime(file.lastModified())).trim(); + return ctx.getString(R.string.recording_description, nm, "", Algorithms.formatDateTime(file.lastModified())).trim(); } private String getDuration(Context ctx) { String additional = ""; - if(duration > 0) { + if (duration > 0) { int d = (int) (duration / 1000); additional += Algorithms.formatDuration(d); } - if(!available) { - additional += "("+ctx.getString(R.string.recording_unavailable)+")"; + if (!available) { + additional += "(" + ctx.getString(R.string.recording_unavailable) + ")"; } return additional; } - } - - 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! */ - } - } - + 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; @@ -339,9 +332,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { AV_EXTERNAL_RECORDER = settings.registerBooleanPreference("av_external_recorder", false).makeGlobal(); AV_EXTERNAL_PHOTO_CAM = settings.registerBooleanPreference("av_external_cam", true).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: - 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: 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) { initializeRemoteControlRegistrationMethods(); AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); - if(am != null){ + if (am != null) { registerMediaListener(am); } return true; } - - - @Override public void registerLayers(MapActivity activity) { this.activity = activity; - if(audioNotesLayer != null) { + if (audioNotesLayer != null) { activity.getMapView().removeLayer(audioNotesLayer); } audioNotesLayer = new AudioNotesLayer(activity, this); @@ -382,22 +372,19 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { registerWidget(activity); } - private void registerMediaListener(AudioManager am) { - - ComponentName receiver = new ComponentName(app.getPackageName(), - MediaRemoteControlReceiver.class.getName()); + + 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); - } + 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 { @@ -410,7 +397,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - @Override public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { OnContextMenuClick listener = new OnContextMenuClick() { @@ -423,62 +409,60 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } }; - 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(); + 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(); } - - @Override - public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, 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) . - listen(new OnContextMenuClick() { - - @Override - public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { - recordAudio(latitude, longitude, mapActivity); - } - }).position(6).reg(); - adapter.item(R.string.recording_context_menu_vrecord).icons(R.drawable.ic_action_video_dark, R.drawable.ic_action_video_light). - listen(new OnContextMenuClick() { - - @Override - public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { - recordVideo(latitude, longitude, mapActivity); - } - }).position(7).reg(); - adapter.item(R.string.recording_context_menu_precord).icons(R.drawable.ic_action_photo_dark, R.drawable.ic_action_photo_light). - listen(new OnContextMenuClick() { - @Override - public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { - takePhoto(latitude, longitude, mapActivity); - } - }).position(8).reg(); + @Override + public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, + 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) + .listen(new OnContextMenuClick() { + + @Override + public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { + recordAudio(latitude, longitude, mapActivity); + } + }).position(6).reg(); + adapter.item(R.string.recording_context_menu_vrecord).icons(R.drawable.ic_action_video_dark, R.drawable.ic_action_video_light) + .listen(new OnContextMenuClick() { + + @Override + public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { + recordVideo(latitude, longitude, mapActivity); + } + }).position(7).reg(); + adapter.item(R.string.recording_context_menu_precord).icons(R.drawable.ic_action_photo_dark, R.drawable.ic_action_photo_light) + .listen(new OnContextMenuClick() { + @Override + public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { + takePhoto(latitude, longitude, mapActivity); + } + + }).position(8).reg(); } - + @Override public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { - if(SHOW_RECORDINGS.get()) { - if(audioNotesLayer == null) { + if (SHOW_RECORDINGS.get()) { + if (audioNotesLayer == null) { registerLayers(activity); - } else if(!mapView.getLayers().contains(audioNotesLayer)) { + } else if (!mapView.getLayers().contains(audioNotesLayer)) { mapView.addLayer(audioNotesLayer, 3.5f); } - } else if(audioNotesLayer != null){ + } else if (audioNotesLayer != null) { mapView.removeLayer(audioNotesLayer); } } - - + private void registerWidget(MapActivity activity) { MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer(); - if (mapInfoLayer != null ) { + if (mapInfoLayer != null) { recordControl = new TextInfoWidget(activity, 0, mapInfoLayer.getPaintText(), mapInfoLayer.getPaintSubText()); recordControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.monitoring_rec_inactive)); setRecordListener(recordControl, activity); - mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, - R.drawable.widget_icon_av_inactive, R.string.map_widget_av_notes, "audionotes", false, - EnumSet.allOf(ApplicationMode.class), + mapInfoLayer.getMapInfoControls().registerSideWidget(recordControl, R.drawable.widget_icon_av_inactive, + R.string.map_widget_av_notes, "audionotes", false, EnumSet.allOf(ApplicationMode.class), EnumSet.noneOf(ApplicationMode.class), 22); mapInfoLayer.recreateControls(); } @@ -488,7 +472,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { recordPlaceControl.setText(app.getString(R.string.av_control_start), ""); updateWidgetIcon(recordPlaceControl); recordPlaceControl.setOnClickListener(new View.OnClickListener() { - + @Override public void onClick(View v) { defaultAction(mapActivity); @@ -496,7 +480,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { }); } - private void updateWidgetIcon(final TextInfoWidget recordPlaceControl) { recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_av_inactive)); if (AV_DEFAULT_ACTION.get() == AV_DEFAULT_ACTION_VIDEO) { @@ -507,7 +490,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { recordPlaceControl.setImageDrawable(activity.getResources().getDrawable(R.drawable.widget_icon_audio)); } } - + private void defaultAction(final MapActivity mapActivity) { final Location loc = app.getLocationProvider().getLastKnownLocation(); // double lat = mapActivity.getMapView().getLatitude(); @@ -526,26 +509,23 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - private void chooseDefaultAction(final double lat, final double lon, final MapActivity mapActivity) { AccessibleAlertBuilder ab = new AccessibleAlertBuilder(mapActivity); - ab.setItems(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_precord), - }, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - int action = which == 0 ? AV_DEFAULT_ACTION_AUDIO : - (which == 1 ? AV_DEFAULT_ACTION_VIDEO:AV_DEFAULT_ACTION_TAKEPICTURE); - takeAction(mapActivity, lon, lat, action); - - } - }); + ab.setItems( + 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_precord), }, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + int action = which == 0 ? AV_DEFAULT_ACTION_AUDIO : (which == 1 ? AV_DEFAULT_ACTION_VIDEO + : AV_DEFAULT_ACTION_TAKEPICTURE); + takeAction(mapActivity, lon, lat, action); + + } + }); ab.show(); } - private void takeAction(final MapActivity mapActivity, double lon, double lat, int action) { if (action == AV_DEFAULT_ACTION_VIDEO) { recordVideo(lat, lon, mapActivity); @@ -555,8 +535,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { recordAudio(lat, lon, mapActivity); } } - - + private File getBaseFileName(double lat, double lon, OsmandApplication app, String ext) { String basename = MapUtils.createShortLocString(lat, lon, 15); int k = 1; @@ -565,73 +544,73 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { File fl; do { fl = new File(f, basename + "-" + (k++) + "." + ext); - } while(fl.exists()); + } while (fl.exists()); return fl; } - + public void captureImage(double lat, double lon, final MapActivity mapActivity) { - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - Uri fileUri = Uri.fromFile(getBaseFileName(lat, lon, app, IMG_EXTENSION)); - intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name - // start the image capture Intent - mapActivity.startActivityForResult(intent, 105); + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + Uri fileUri = Uri.fromFile(getBaseFileName(lat, lon, app, IMG_EXTENSION)); + intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name + // start the image capture Intent + mapActivity.startActivityForResult(intent, 105); } - + public void captureVideoExternal(double lat, double lon, final MapActivity mapActivity) { Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); String ext = MPEG4_EXTENSION; - if(AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP ){ + if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) { ext = THREEGP_EXTENSION; } Uri fileUri = Uri.fromFile(getBaseFileName(lat, lon, app, ext)); - intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name + intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name - intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high - // start the video capture Intent - mapActivity.startActivityForResult(intent, 205); + intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high + // start the video capture Intent + mapActivity.startActivityForResult(intent, 205); } - + @Override public void mapActivityPause(MapActivity activity) { stopRecording(activity); } - + 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); } else { recordVideoCamera(lat, lon, mapActivity); } } - + public void recordVideoCamera(final double lat, final double lon, final MapActivity mapActivity) { final Dialog dlg = new Dialog(mapActivity); SurfaceView view = new SurfaceView(dlg.getContext()); view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); view.getHolder().addCallback(new Callback() { - + @Override public void surfaceDestroyed(SurfaceHolder holder) { } - + @Override public void surfaceCreated(SurfaceHolder holder) { MediaRecorder mr = new MediaRecorder(); String ext = MPEG4_EXTENSION; - if(AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP ){ + if (AV_VIDEO_FORMAT.get() == VIDEO_OUTPUT_3GP) { 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.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); } else { mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); } - + giveMediaRecorderHintRotatedScreen(mapActivity, mr); mr.setPreviewDisplay(holder.getSurface()); mr.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); @@ -644,7 +623,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { return; } } - + @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @@ -652,7 +631,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { dlg.setContentView(view); dlg.show(); } - + private void giveMediaRecorderHintRotatedScreen(final MapActivity mapActivity, final MediaRecorder mr) { if (Build.VERSION.SDK_INT >= 9) { try { @@ -670,7 +649,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } } - + private void logErr(Exception e) { log.error("Error starting recorder ", e); AccessibleToast.makeText(app, app.getString(R.string.recording_error) + " : " + e.getMessage(), Toast.LENGTH_LONG).show(); @@ -680,12 +659,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { protected Camera openCamera() { try { return Camera.open(); - } catch (Exception e ){ + } catch (Exception e) { logErr(e); return null; } } - + private void stopRecording(final MapActivity mapActivity) { if (mediaRec != null) { mediaRec.stop(); @@ -696,8 +675,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { setRecordListener(recordControl, mapActivity); } } - - + public void recordAudio(double lat, double lon, final MapActivity mapActivity) { MediaRecorder mr = new MediaRecorder(); final File f = getBaseFileName(lat, lon, app, THREEGP_EXTENSION); @@ -711,9 +689,9 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { log.error("Error starting audio recorder ", e); AccessibleToast.makeText(app, app.getString(R.string.recording_error) + " : " + e.getMessage(), Toast.LENGTH_LONG).show(); } - + } - + public void takePhoto(final double lat, final double lon, final MapActivity mapActivity) { if (AV_EXTERNAL_PHOTO_CAM.get()) { takeIntentPhoto(lat, lon, mapActivity); @@ -727,7 +705,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - private void takePhotoWithCamera(final double lat, final double lon, final MapActivity mapActivity, final Camera cam) { try { final Dialog dlg = new Dialog(mapActivity); @@ -736,11 +713,11 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { SurfaceView view = new SurfaceView(dlg.getContext()); view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); view.getHolder().addCallback(new Callback() { - + @Override public void surfaceDestroyed(SurfaceHolder holder) { } - + public void setCameraDisplayOrientation(android.hardware.Camera camera, Parameters parameters) { // android.hardware.Camera.CameraInfo info = // new android.hardware.Camera.CameraInfo(); @@ -748,16 +725,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { int rotation = mapActivity.getWindowManager().getDefaultDisplay().getRotation(); int degrees = 0; switch (rotation) { - case /*Surface.ROTATION_0*/ 0: + case /* Surface.ROTATION_0 */0: degrees = 0; break; - case /*Surface.ROTATION_90*/ 1: + case /* Surface.ROTATION_90 */1: degrees = 90; break; - case /*Surface.ROTATION_180*/ 2: + case /* Surface.ROTATION_180 */2: degrees = 180; break; - case /*Surface.ROTATION_270*/ 3: + case /* Surface.ROTATION_270 */3: degrees = 270; break; } @@ -772,7 +749,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // camera.setDisplayOrientation((90 + 360 - degrees) % 360); parameters.set("rotation", (90 + 360 - degrees) % 360); } - + @Override public void surfaceCreated(SurfaceHolder holder) { try { @@ -780,10 +757,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { // camera focus type: 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.setGpsLongitude(lon); - switch( AV_CAMERA_FOCUS_TYPE.get() ) { + switch (AV_CAMERA_FOCUS_TYPE.get()) { case AV_CAMERA_FOCUS_HIPERFOCAL: parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); autofocus = false; @@ -812,16 +789,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { log.info("Osmand:AudioNotes set camera FOCUS_MODE_AUTO"); break; } -// parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); -// parameters.set("auto-exposure-lock", "true"); - //} + // parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED); + // parameters.set("auto-exposure-lock", "true"); + // } // load sound befor shot: if (AV_PHOTO_PLAY_SOUND.get()) { - if(sp==null) + if (sp == null) sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); log.info("Play sound on photo"); - if(shotId==0) - { + if (shotId == 0) { shotId = sp.load(app.getAssets().openFd("sounds/camera_click.ogg"), 1); log.debug("loaded file sound ID: " + shotId); } @@ -853,8 +829,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } private void printCamParams(Parameters parameters, boolean autoExposure) { - log.info("Cam params auto exposure=" + autoExposure + - " focus_distances="+parameters.get("focus-distances")); + log.info("Cam params auto exposure=" + autoExposure + " focus_distances=" + parameters.get("focus-distances")); } @Override @@ -869,7 +844,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - private void takeIntentPhoto(double lat, double lon, final MapActivity mapActivity) { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); final File f = getBaseFileName(lat, lon, app, IMG_EXTENSION); @@ -882,7 +856,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { AccessibleToast.makeText(app, app.getString(R.string.recording_error) + " : " + e.getMessage(), Toast.LENGTH_LONG).show(); } } - + private void runMediaRecorder(final MapActivity mapActivity, MediaRecorder mr, final File f) throws IOException { mr.prepare(); mr.start(); @@ -892,7 +866,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { final MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer(); final StackWidgetView par = mil.getRightStack(); final boolean contains = par.getAllViews().contains(recordControl); - if(!contains) { + if (!contains) { par.addStackView(recordControl); mapActivity.getMapView().refreshMap(true); } @@ -900,7 +874,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { recordControl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if(!contains) { + if (!contains) { par.removeView(recordControl); } stopRecording(mapActivity); @@ -911,20 +885,20 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } }); } - - public void indexFile(File f){ + + public void indexFile(File f) { boolean oldFileExist = recordingByFileName.containsKey(f.getName()); - if(oldFileExist){ + if (oldFileExist) { return; } Recording r = new Recording(f); String encodeName = f.getName(); int i = encodeName.indexOf('-'); - if(i > 0) { + if (i > 0) { encodeName = encodeName.substring(0, i); } i = encodeName.indexOf('.'); - if(i > 0) { + if (i > 0) { encodeName = encodeName.substring(0, i); } r.file = f; @@ -933,7 +907,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { r.lon = l.getLongitude(); Float heading = app.getLocationProvider().getHeading(); 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(); try { r.updatePhotoInformation(r.lat, r.lon, loc, rot == 0 ? Double.NaN : rot); @@ -949,53 +923,62 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { @Override public void disable(OsmandApplication app) { AudioManager am = (AudioManager) app.getSystemService(Context.AUDIO_SERVICE); - if(am != null){ + if (am != null) { unregisterMediaListener(am); } } - + @Override public List indexingFiles(IProgress progress) { - return indexingFiles(progress, true); + return indexingFiles(progress, true, false); } - - public List indexingFiles(IProgress progress, boolean reIndexAndKeepOld) { + + public List indexingFiles(IProgress progress, boolean reIndexAndKeepOld, boolean registerNew) { File avPath = app.getAppPath(IndexConstants.AV_INDEX_DIR); if (avPath.canRead()) { - if(!reIndexAndKeepOld) { + if (!reIndexAndKeepOld) { recordings.clear(); recordingByFileName.clear(); } File[] files = avPath.listFiles(); if (files != null) { for (File f : files) { - if(f.getName().endsWith(THREEGP_EXTENSION) - || f.getName().endsWith(MPEG4_EXTENSION) + if (f.getName().endsWith(THREEGP_EXTENSION) || f.getName().endsWith(MPEG4_EXTENSION) || f.getName().endsWith(IMG_EXTENSION)) { 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, "")); + } + } + } + } } } } return null; } - public DataTileManager getRecordings() { return recordings; } - - private void checkRecordings(){ + + private void checkRecordings() { Iterator it = recordingByFileName.values().iterator(); - while(it.hasNext()){ + while (it.hasNext()) { Recording r = it.next(); - if(!r.file.exists()) { + if (!r.file.exists()) { it.remove(); recordings.unregisterObject(r.lat, r.lon, r); } } } - public void deleteRecording(Recording r) { recordings.unregisterObject(r.lat, r.lon, r); @@ -1004,7 +987,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { activity.getMapLayers().getContextMenuLayer().setLocation(null, ""); activity.getMapView().refreshMap(); } - @Override public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) { @@ -1012,7 +994,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { grp.setTitle(R.string.av_settings); grp.setSummary(R.string.av_settings_descr); grp.setOnPreferenceClickListener(new OnPreferenceClickListener() { - + @Override public boolean onPreferenceClick(Preference preference) { activity.startActivity(new Intent(activity, SettingsAudioVideoActivity.class)); @@ -1021,22 +1003,22 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { }); screen.addPreference(grp); } - + @Override public void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) { - if(requestCode == 205) { - indexingFiles(null, true); + if (requestCode == 205) { + indexingFiles(null, true, true); } } - - public boolean onMapActivityKeyEvent(KeyEvent key){ - if(KeyEvent.KEYCODE_CAMERA == key.getKeyCode()) { + + public boolean onMapActivityKeyEvent(KeyEvent key) { + if (KeyEvent.KEYCODE_CAMERA == key.getKeyCode()) { defaultAction(activity); return true; } return false; } - + public class RecordingLocalIndexInfo extends LocalIndexInfo { private Recording rec; @@ -1045,14 +1027,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { super(LocalIndexType.AV_DATA, r.file, false); this.rec = r; } - + @Override public String getName() { return rec.getSmallDescription(app); } - + } - + @Override public void loadLocalIndexes(List result, LoadLocalIndexTask loadTask) { List progress = new ArrayList(); @@ -1070,14 +1052,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { loadTask.loadFile(progress.toArray(new LocalIndexInfo[progress.size()])); } } - + @Override public void updateLocalIndexDescription(LocalIndexInfo info) { if (info instanceof RecordingLocalIndexInfo) { info.setDescription(((RecordingLocalIndexInfo) info).rec.getDescription(app)); } } - + @Override public void contextMenuLocalIndexes(final LocalIndexesActivity la, LocalIndexInfo info, ContextMenuAdapter adapter) { if (info.getType() == LocalIndexType.AV_DATA) { @@ -1088,30 +1070,30 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { playRecording(la, ri.rec); } }; - if(ri.rec.isPhoto()) { - adapter.item(R.string.recording_context_menu_show).icons( - R.drawable.ic_action_eye_dark, R.drawable.ic_action_eye_light).listen(listener).reg(); + if (ri.rec.isPhoto()) { + adapter.item(R.string.recording_context_menu_show).icons(R.drawable.ic_action_eye_dark, R.drawable.ic_action_eye_light) + .listen(listener).reg(); } else { - adapter.item(R.string.recording_context_menu_play).icons( - R.drawable.ic_action_play_dark, R.drawable.ic_action_play_light).listen(listener).reg(); + adapter.item(R.string.recording_context_menu_play).icons(R.drawable.ic_action_play_dark, R.drawable.ic_action_play_light) + .listen(listener).reg(); } - adapter.item(R.string.show_location).icons(R.drawable.ic_action_marker_dark, R.drawable.ic_action_marker_light). - listen(new OnContextMenuClick() { - @Override - public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { - SHOW_RECORDINGS.set(true); - app.getSettings().setMapLocationToShow(ri.rec.lat, ri.rec.lon, app.getSettings().getLastKnownMapZoom()); - MapActivity.launchMapActivityMoveToTop(la); + adapter.item(R.string.show_location).icons(R.drawable.ic_action_marker_dark, R.drawable.ic_action_marker_light) + .listen(new OnContextMenuClick() { + @Override + public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { + SHOW_RECORDINGS.set(true); + app.getSettings().setMapLocationToShow(ri.rec.lat, ri.rec.lon, app.getSettings().getLastKnownMapZoom()); + MapActivity.launchMapActivityMoveToTop(la); - } - }).reg(); + } + }).reg(); } } - - public Collection getAllRecordings(){ + + public Collection getAllRecordings() { return recordingByFileName.values(); } - + private Recording[] getRecordingsSorted() { checkRecordings(); Collection allObjects = getAllRecordings(); @@ -1127,16 +1109,15 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { }); return res; } - - + public void playRecording(final Context ctx, final Recording r) { final MediaPlayer player = r.isPhoto() ? null : new MediaPlayer(); final AccessibleAlertBuilder dlg = new AccessibleAlertBuilder(ctx); dlg.setPositiveButton(R.string.recording_open_external_player, new OnClickListener() { - + @Override public void onClick(DialogInterface v, int w) { - if(player == null) { + if (player == null) { Intent vint = new Intent(Intent.ACTION_VIEW); vint.setDataAndType(Uri.fromFile(r.file), "image/*"); vint.setFlags(0x10000000); @@ -1156,16 +1137,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } }); - dlg.setNegativeButton(R.string.default_buttons_cancel, new OnClickListener(){ + dlg.setNegativeButton(R.string.default_buttons_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(player != null && player.isPlaying()) { + if (player != null && player.isPlaying()) { player.stop(); - } - + } + } - + }); try { if (r.isPhoto()) { @@ -1201,7 +1182,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { AccessibleToast.makeText(ctx, R.string.recording_can_not_be_played, Toast.LENGTH_SHORT).show(); } } - + @Override public boolean mapActivityKeyUp(MapActivity mapActivity, int keyCode) { if (keyCode == KeyEvent.KEYCODE_CAMERA) { @@ -1210,7 +1191,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } return false; } - + public class AudioVideoPhotoHandler implements PictureCallback { private File pictureFile; private Dialog dlg; @@ -1226,25 +1207,22 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); fos.close(); - indexingFiles(null, true); + indexingFiles(null, true, true); dlg.dismiss(); // play sound after photo - sound file must be loaded at this time: if (AV_PHOTO_PLAY_SOUND.get()) { - if(sp!=null && shotId!=0) - { - int ret=sp.play(shotId, 0.7f, 0.7f, 0, 0, 1); + if (sp != null && shotId != 0) { + int ret = sp.play(shotId, 0.7f, 0.7f, 0, 0, 1); log.debug("play sound shot success!"); - log.debug("sp.play()="+ret); - // sp.release(); - // sp=null; - // shotId=0 - } - else - { + log.debug("sp.play()=" + ret); + // sp.release(); + // sp=null; + // shotId=0 + } else { log.error("can not play sound on shot - not init SoundPool or not loaded sound"); } } - + } catch (Exception error) { logErr(error); } finally { @@ -1252,6 +1230,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { } } - } + } }