Fix av notes

This commit is contained in:
Victor Shcherb 2015-06-01 01:44:49 +02:00
parent 310def51dc
commit 6e8d1c57c5
4 changed files with 95 additions and 22 deletions

View file

@ -133,6 +133,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
private MediaRecorder mediaRec; private MediaRecorder mediaRec;
private File lastTakingPhoto; private File lastTakingPhoto;
private final static char SPLIT_DESC = ' ';
public static class Recording { public static class Recording {
public Recording(File f) { public Recording(File f) {
this.file = f; this.file = f;
@ -174,18 +175,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public File getFile() { public File getFile() {
return file; return file;
} }
public boolean setName(String name) { public boolean setName(String name) {
File directory = file.getParentFile(); File directory = file.getParentFile();
String fileName = getFileName(); String fileName = getFileName();
final String hashAndExtension; File to = new File(directory, name + SPLIT_DESC + getOtherName(fileName));
int hashInd = fileName.lastIndexOf('_');
if (hashInd == -1 || hashInd < 8) {
hashAndExtension = "_" + fileName;
} else {
hashAndExtension = fileName.substring(hashInd, fileName.length());
}
File to = new File(directory, name+hashAndExtension);
if (file.renameTo(to)) { if (file.renameTo(to)) {
file = to; file = to;
return true; return true;
@ -196,13 +191,35 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
public String getFileName() { public String getFileName() {
return file.getName(); return file.getName();
} }
public String getDescriptionName(String fileName) {
int hashInd = fileName.lastIndexOf(SPLIT_DESC);
//backward compatibility
if( fileName.indexOf('.') - fileName.indexOf('_') > 12 &&
hashInd < fileName.indexOf('_')) {
hashInd = fileName.indexOf('_');
}
if(hashInd == -1) {
return null;
} else {
return fileName.substring(0, hashInd);
}
}
public String getOtherName(String fileName) {
String descriptionName = getDescriptionName(fileName);
if(descriptionName != null) {
return fileName.substring(descriptionName.length() + 1); // SPLIT_DESC
} else {
return fileName;
}
}
public String getName(Context ctx) { public String getName(Context ctx) {
String fileName = file.getName(); String fileName = file.getName();
String desc = getDescriptionName(fileName);
int hashInd = fileName.lastIndexOf('_'); if (desc != null) {
if (hashInd != -1 && hashInd < 8) { return desc;
return fileName.substring(0, hashInd);
} else if (this.isAudio()) { } else if (this.isAudio()) {
return ctx.getResources().getString(R.string.shared_string_audio); return ctx.getResources().getString(R.string.shared_string_audio);
} else if (this.isVideo()) { } else if (this.isVideo()) {
@ -605,7 +622,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
f.mkdirs(); f.mkdirs();
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;
} }
@ -990,17 +1007,14 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return false; return false;
} }
Recording r = new Recording(f); Recording r = new Recording(f);
String encodeName = f.getName(); String fileName = f.getName();
int i = encodeName.lastIndexOf('_'); String otherName = r.getOtherName(fileName);
if (i >= 8) { int i = otherName.indexOf('.');
encodeName = encodeName.substring(i + 1);
}
i = encodeName.indexOf('.');
if (i > 0) { if (i > 0) {
encodeName = encodeName.substring(0, i); otherName = otherName.substring(0, i);
} }
r.file = f; r.file = f;
GeoParsedPoint geo = MapUtils.decodeShortLinkString(encodeName); GeoParsedPoint geo = MapUtils.decodeShortLinkString(otherName);
r.lat = geo.getLatitude(); r.lat = geo.getLatitude();
r.lon = geo.getLongitude(); r.lon = geo.getLongitude();
Float heading = app.getLocationProvider().getHeading(); Float heading = app.getLocationProvider().getHeading();

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.osmand.skimapsPlugin"
android:versionCode="6"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="16" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true"
android:xlargeScreens="true" android:anyDensity="true" />
<application
android:icon="@drawable/icon"
android:label="OsmAnd Ski Maps" >
<activity
android:name="net.osmand.skimaps.SkiMapsActivity"
android:label="@string/app_name" >
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
</application>
</manifest>

View file

@ -0,0 +1,6 @@
/** Automatically generated file. DO NOT MODIFY */
package net.osmand.skimapsPlugin;
public final class BuildConfig {
public final static boolean DEBUG = true;
}

View file

@ -0,0 +1,27 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package net.osmand.skimapsPlugin;
public final class R {
public static final class attr {
}
public static final class drawable {
public static final int ic_launcher=0x7f020000;
public static final int icon=0x7f020001;
}
public static final class layout {
public static final int main=0x7f030000;
}
public static final class string {
public static final int app_name=0x7f040003;
public static final int osmand_app_not_found=0x7f040002;
public static final int parking_plugin_installed=0x7f040004;
public static final int shared_string_no=0x7f040000;
public static final int shared_string_yes=0x7f040001;
}
}