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
g_*.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_timemoving">\nZeit in Bewegung: %1$d:%2$02d:%3$02d</string>
<string name="context_menu_item_destination_point">Als Ziel wählen</string>

View file

@ -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;
@ -127,8 +127,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public final OsmandPreference<Boolean> SHOW_RECORDINGS;
private DataTileManager<Recording> recordings = new DataTileManager<AudioVideoNotesPlugin.Recording>(14);
private Map<String, Recording> recordingByFileName = new LinkedHashMap<String, Recording>();
private AudioNotesLayer audioNotesLayer;
@ -140,6 +138,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public Recording(File f) {
this.file = f;
}
public File file;
public String name;
@ -206,16 +205,19 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
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 } );
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; }
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);
@ -227,8 +229,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
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();
@ -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) {
@ -274,22 +274,19 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
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();
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();
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) {
@ -304,19 +301,16 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return additional;
}
}
private static void initializeRemoteControlRegistrationMethods() {
try {
if (mRegisterMediaButtonEventReceiver == null) {
mRegisterMediaButtonEventReceiver = AudioManager.class.getMethod(
"registerMediaButtonEventReceiver",
mRegisterMediaButtonEventReceiver = AudioManager.class.getMethod("registerMediaButtonEventReceiver",
new Class[] { ComponentName.class });
}
if (mUnregisterMediaButtonEventReceiver == null) {
mUnregisterMediaButtonEventReceiver = AudioManager.class.getMethod(
"unregisterMediaButtonEventReceiver",
mUnregisterMediaButtonEventReceiver = AudioManager.class.getMethod("unregisterMediaButtonEventReceiver",
new Class[] { ComponentName.class });
}
/* success, this device will take advantage of better remote */
@ -327,7 +321,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
}
@Override
public String getId() {
return ID;
@ -368,9 +361,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return true;
}
@Override
public void registerLayers(MapActivity activity) {
this.activity = activity;
@ -382,17 +372,14 @@ 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);
mRegisterMediaButtonEventReceiver.invoke(am, receiver);
} catch (Exception ite) {
log.error(ite.getMessage(), ite);
}
@ -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() {
@ -428,26 +414,26 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
@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() {
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() {
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() {
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);
@ -469,16 +455,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
}
private void registerWidget(MapActivity activity) {
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
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();
}
@ -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) {
@ -526,18 +509,16 @@ 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),
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() {
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);
int action = which == 0 ? AV_DEFAULT_ACTION_AUDIO : (which == 1 ? AV_DEFAULT_ACTION_VIDEO
: AV_DEFAULT_ACTION_TAKEPICTURE);
takeAction(mapActivity, lon, lat, action);
}
@ -545,7 +526,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
ab.show();
}
private void takeAction(final MapActivity mapActivity, double lon, double lat, int action) {
if (action == AV_DEFAULT_ACTION_VIDEO) {
recordVideo(lat, lon, mapActivity);
@ -556,7 +536,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
}
private File getBaseFileName(double lat, double lon, OsmandApplication app, String ext) {
String basename = MapUtils.createShortLocString(lat, lon, 15);
int k = 1;
@ -697,7 +676,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
}
public void recordAudio(double lat, double lon, final MapActivity mapActivity) {
MediaRecorder mr = new MediaRecorder();
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) {
try {
final Dialog dlg = new Dialog(mapActivity);
@ -820,8 +797,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
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);
@ -956,10 +930,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override
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);
if (avPath.canRead()) {
if (!reIndexAndKeepOld) {
@ -969,10 +943,21 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
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, ""));
}
}
}
}
}
}
@ -980,7 +965,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return null;
}
public DataTileManager<Recording> getRecordings() {
return recordings;
}
@ -996,7 +980,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
}
public void deleteRecording(Recording r) {
recordings.unregisterObject(r.lat, r.lon, r);
recordingByFileName.remove(r.file.getName());
@ -1005,7 +988,6 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
activity.getMapView().refreshMap();
}
@Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
Preference grp = new Preference(activity);
@ -1025,7 +1007,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
@Override
public void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 205) {
indexingFiles(null, true);
indexingFiles(null, true, true);
}
}
@ -1089,14 +1071,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
}
};
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();
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() {
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);
@ -1128,7 +1110,6 @@ 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);
@ -1226,21 +1207,18 @@ 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)
{
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
{
} else {
log.error("can not play sound on shot - not init SoundPool or not loaded sound");
}
}