Add recordings to local manager
This commit is contained in:
parent
971f12094b
commit
cc477ceb3b
8 changed files with 548 additions and 324 deletions
|
@ -9,6 +9,7 @@
|
||||||
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
1. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="local_indexes_cat_av">Audio/Video data</string>
|
||||||
<string name="stop_routing_confirm">Are you sure you want to stop the navigation?</string>
|
<string name="stop_routing_confirm">Are you sure you want to stop the navigation?</string>
|
||||||
<string name="clear_dest_confirm">Are you sure you want to clear your destination point?</string>
|
<string name="clear_dest_confirm">Are you sure you want to clear your destination point?</string>
|
||||||
<string name="precise_routing_mode_descr">Enable precise routing to calculate precise routes without glitches. It is very limited by distance and doesn\'t use native library.</string>
|
<string name="precise_routing_mode_descr">Enable precise routing to calculate precise routes without glitches. It is very limited by distance and doesn\'t use native library.</string>
|
||||||
|
|
|
@ -8,6 +8,9 @@ import java.util.Set;
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.LogUtil;
|
import net.osmand.LogUtil;
|
||||||
import net.osmand.access.AccessibilityPlugin;
|
import net.osmand.access.AccessibilityPlugin;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
|
@ -137,6 +140,14 @@ public abstract class OsmandPlugin {
|
||||||
|
|
||||||
public void registerOptionsMenuItems(MapActivity mapActivity, OptionsMenuHelper helper) {}
|
public void registerOptionsMenuItems(MapActivity mapActivity, OptionsMenuHelper helper) {}
|
||||||
|
|
||||||
|
public void loadLocalIndexes(List<LocalIndexInfo> result, LoadLocalIndexTask loadTask) {};
|
||||||
|
|
||||||
|
public void contextMenuLocalIndexes(LocalIndexesActivity la, LocalIndexInfo info, ContextMenuAdapter adapter) {};
|
||||||
|
|
||||||
|
public void updateLocalIndexDescription(LocalIndexInfo info) {}
|
||||||
|
|
||||||
|
public void optionsMenuLocalIndexes(LocalIndexesActivity localIndexesActivity, ContextMenuAdapter optionsMenuAdapter) {};
|
||||||
|
|
||||||
public List<String> indexingFiles(IProgress progress) { return null;}
|
public List<String> indexingFiles(IProgress progress) { return null;}
|
||||||
|
|
||||||
public void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) {
|
public void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
@ -252,6 +263,30 @@ public abstract class OsmandPlugin {
|
||||||
plugin.registerOptionsMenuItems(map, helper);
|
plugin.registerOptionsMenuItems(map, helper);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void onUpdateLocalIndexDescription(LocalIndexInfo info) {
|
||||||
|
for (OsmandPlugin plugin : activePlugins) {
|
||||||
|
plugin.updateLocalIndexDescription(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadLocalIndexes(List<LocalIndexInfo> result, LoadLocalIndexTask loadTask) {
|
||||||
|
for (OsmandPlugin plugin : activePlugins) {
|
||||||
|
plugin.loadLocalIndexes(result, loadTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onContextMenuLocalIndexes(LocalIndexesActivity la, LocalIndexInfo info, ContextMenuAdapter adapter) {
|
||||||
|
for (OsmandPlugin plugin : activePlugins) {
|
||||||
|
plugin.contextMenuLocalIndexes(la, info, adapter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void onOptionsMenuLocalIndexes(LocalIndexesActivity localIndexesActivity, ContextMenuAdapter optionsMenuAdapter) {
|
||||||
|
for (OsmandPlugin plugin : activePlugins) {
|
||||||
|
plugin.optionsMenuLocalIndexes(localIndexesActivity, optionsMenuAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean installPlugin(String packageInfo,
|
private static boolean installPlugin(String packageInfo,
|
||||||
String pluginId, OsmandApplication app, OsmandPlugin plugin) {
|
String pluginId, OsmandApplication app, OsmandPlugin plugin) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ import net.osmand.plus.GPXUtilities.TrkSegment;
|
||||||
import net.osmand.plus.GPXUtilities.WptPt;
|
import net.osmand.plus.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.SQLiteTileSource;
|
import net.osmand.plus.SQLiteTileSource;
|
||||||
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
||||||
|
@ -50,10 +51,6 @@ public class LocalIndexHelper {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LocalIndexInfo> getAllLocalIndexData(LoadLocalIndexTask loadTask){
|
|
||||||
return getLocalIndexData(null, loadTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInstalledDate(File f){
|
public String getInstalledDate(File f){
|
||||||
return getInstalledDate(f.lastModified());
|
return getInstalledDate(f.lastModified());
|
||||||
}
|
}
|
||||||
|
@ -100,9 +97,12 @@ public class LocalIndexHelper {
|
||||||
template.couldBeDownloadedFromInternet(), "");
|
template.couldBeDownloadedFromInternet(), "");
|
||||||
info.setDescription(descr);
|
info.setDescription(descr);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
OsmandPlugin.onUpdateLocalIndexDescription(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateGpxInfo(LocalIndexInfo info, File f) {
|
private void updateGpxInfo(LocalIndexInfo info, File f) {
|
||||||
if(info.getGpxFile() == null){
|
if(info.getGpxFile() == null){
|
||||||
info.setGpxFile(GPXUtilities.loadGPXFile(app, f, true));
|
info.setGpxFile(GPXUtilities.loadGPXFile(app, f, true));
|
||||||
|
@ -199,7 +199,7 @@ public class LocalIndexHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LocalIndexInfo> getLocalIndexData(LocalIndexType type, LoadLocalIndexTask loadTask){
|
public List<LocalIndexInfo> getLocalIndexData(LoadLocalIndexTask loadTask){
|
||||||
Map<String, String> loadedMaps = app.getResourceManager().getIndexFileNames();
|
Map<String, String> loadedMaps = app.getResourceManager().getIndexFileNames();
|
||||||
List<LocalIndexInfo> result = new ArrayList<LocalIndexInfo>();
|
List<LocalIndexInfo> result = new ArrayList<LocalIndexInfo>();
|
||||||
|
|
||||||
|
@ -211,13 +211,12 @@ public class LocalIndexHelper {
|
||||||
loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask);
|
loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask);
|
||||||
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, false, loadTask);
|
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, false, loadTask);
|
||||||
loadGPXData(app.getAppPath(IndexConstants.BACKUP_INDEX_DIR), result, true, loadTask);
|
loadGPXData(app.getAppPath(IndexConstants.BACKUP_INDEX_DIR), result, true, loadTask);
|
||||||
|
OsmandPlugin.onLoadLocalIndexes(result, loadTask);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
private void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
||||||
if (voiceDir.canRead()) {
|
if (voiceDir.canRead()) {
|
||||||
for (File voiceF : listFilesSorted(voiceDir)) {
|
for (File voiceF : listFilesSorted(voiceDir)) {
|
||||||
|
@ -278,7 +277,7 @@ public class LocalIndexHelper {
|
||||||
|
|
||||||
private void loadGPXData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
private void loadGPXData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
||||||
if (mapPath.canRead()) {
|
if (mapPath.canRead()) {
|
||||||
List<LocalIndexInfo> progress = new ArrayList<LocalIndexHelper.LocalIndexInfo>();
|
List<LocalIndexInfo> progress = new ArrayList<LocalIndexInfo>();
|
||||||
for (File gpxFile : listFilesSorted(mapPath)) {
|
for (File gpxFile : listFilesSorted(mapPath)) {
|
||||||
if (gpxFile.isFile() && gpxFile.getName().endsWith(".gpx")) {
|
if (gpxFile.isFile() && gpxFile.getName().endsWith(".gpx")) {
|
||||||
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.GPX_DATA, gpxFile, backup);
|
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.GPX_DATA, gpxFile, backup);
|
||||||
|
@ -297,6 +296,8 @@ public class LocalIndexHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private File[] listFilesSorted(File dir){
|
private File[] listFilesSorted(File dir){
|
||||||
File[] listFiles = dir.listFiles();
|
File[] listFiles = dir.listFiles();
|
||||||
Arrays.sort(listFiles);
|
Arrays.sort(listFiles);
|
||||||
|
@ -380,7 +381,8 @@ public class LocalIndexHelper {
|
||||||
TILES_DATA(R.string.local_indexes_cat_tile),
|
TILES_DATA(R.string.local_indexes_cat_tile),
|
||||||
VOICE_DATA(R.string.local_indexes_cat_voice),
|
VOICE_DATA(R.string.local_indexes_cat_voice),
|
||||||
TTS_VOICE_DATA(R.string.local_indexes_cat_tts),
|
TTS_VOICE_DATA(R.string.local_indexes_cat_tts),
|
||||||
GPX_DATA(R.string.local_indexes_cat_gpx);
|
GPX_DATA(R.string.local_indexes_cat_gpx),
|
||||||
|
AV_DATA(R.string.local_indexes_cat_av);;
|
||||||
|
|
||||||
private final int resId;
|
private final int resId;
|
||||||
|
|
||||||
|
@ -393,144 +395,7 @@ public class LocalIndexHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LocalIndexInfo {
|
|
||||||
|
|
||||||
private LocalIndexType type;
|
|
||||||
private String description = "";
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private boolean backupedData;
|
|
||||||
private boolean corrupted = false;
|
|
||||||
private boolean notSupported = false;
|
|
||||||
private boolean loaded;
|
|
||||||
private String pathToData;
|
|
||||||
private String fileName;
|
|
||||||
private boolean singleFile;
|
|
||||||
private int kbSize = -1;
|
|
||||||
|
|
||||||
// UI state expanded
|
|
||||||
private boolean expanded;
|
|
||||||
|
|
||||||
private GPXFile gpxFile;
|
|
||||||
|
|
||||||
public LocalIndexInfo(LocalIndexType type, File f, boolean backuped){
|
|
||||||
pathToData = f.getAbsolutePath();
|
|
||||||
fileName = f.getName();
|
|
||||||
name = formatName(f.getName());
|
|
||||||
this.type = type;
|
|
||||||
singleFile = !f.isDirectory();
|
|
||||||
if(singleFile){
|
|
||||||
kbSize = (int) (f.length() >> 10);
|
|
||||||
}
|
|
||||||
this.backupedData = backuped;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatName(String name) {
|
|
||||||
int ext = name.indexOf('.');
|
|
||||||
if(ext != -1){
|
|
||||||
name = name.substring(0, ext);
|
|
||||||
}
|
|
||||||
return name.replace('_', ' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Special domain object represents category
|
|
||||||
public LocalIndexInfo(LocalIndexType type, boolean backup){
|
|
||||||
this.type = type;
|
|
||||||
backupedData = backup;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCorrupted(boolean corrupted) {
|
|
||||||
this.corrupted = corrupted;
|
|
||||||
if(corrupted){
|
|
||||||
this.loaded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackupedData(boolean backupedData) {
|
|
||||||
this.backupedData = backupedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSize(int size) {
|
|
||||||
this.kbSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGpxFile(GPXFile gpxFile) {
|
|
||||||
this.gpxFile = gpxFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GPXFile getGpxFile() {
|
|
||||||
return gpxFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isExpanded() {
|
|
||||||
return expanded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setExpanded(boolean expanded) {
|
|
||||||
this.expanded = expanded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLoaded(boolean loaded) {
|
|
||||||
this.loaded = loaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotSupported(boolean notSupported) {
|
|
||||||
this.notSupported = notSupported;
|
|
||||||
if(notSupported){
|
|
||||||
this.loaded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSize() {
|
|
||||||
return kbSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNotSupported() {
|
|
||||||
return notSupported;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalIndexType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSingleFile() {
|
|
||||||
return singleFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isLoaded() {
|
|
||||||
return loaded;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCorrupted() {
|
|
||||||
return corrupted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBackupedData() {
|
|
||||||
return backupedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPathToData() {
|
|
||||||
return pathToData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileName() {
|
|
||||||
return fileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
144
OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java
Normal file
144
OsmAnd/src/net/osmand/plus/activities/LocalIndexInfo.java
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
|
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||||
|
|
||||||
|
public class LocalIndexInfo {
|
||||||
|
|
||||||
|
private LocalIndexType type;
|
||||||
|
private String description = "";
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private boolean backupedData;
|
||||||
|
private boolean corrupted = false;
|
||||||
|
private boolean notSupported = false;
|
||||||
|
private boolean loaded;
|
||||||
|
private String pathToData;
|
||||||
|
private String fileName;
|
||||||
|
private boolean singleFile;
|
||||||
|
private int kbSize = -1;
|
||||||
|
|
||||||
|
// UI state expanded
|
||||||
|
private boolean expanded;
|
||||||
|
|
||||||
|
private GPXFile gpxFile;
|
||||||
|
|
||||||
|
public LocalIndexInfo(LocalIndexType type, File f, boolean backuped) {
|
||||||
|
pathToData = f.getAbsolutePath();
|
||||||
|
fileName = f.getName();
|
||||||
|
name = formatName(f.getName());
|
||||||
|
this.type = type;
|
||||||
|
singleFile = !f.isDirectory();
|
||||||
|
if (singleFile) {
|
||||||
|
kbSize = (int) (f.length() >> 10);
|
||||||
|
}
|
||||||
|
this.backupedData = backuped;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatName(String name) {
|
||||||
|
int ext = name.indexOf('.');
|
||||||
|
if (ext != -1) {
|
||||||
|
name = name.substring(0, ext);
|
||||||
|
}
|
||||||
|
return name.replace('_', ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special domain object represents category
|
||||||
|
public LocalIndexInfo(LocalIndexType type, boolean backup) {
|
||||||
|
this.type = type;
|
||||||
|
backupedData = backup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCorrupted(boolean corrupted) {
|
||||||
|
this.corrupted = corrupted;
|
||||||
|
if (corrupted) {
|
||||||
|
this.loaded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackupedData(boolean backupedData) {
|
||||||
|
this.backupedData = backupedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(int size) {
|
||||||
|
this.kbSize = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGpxFile(GPXFile gpxFile) {
|
||||||
|
this.gpxFile = gpxFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GPXFile getGpxFile() {
|
||||||
|
return gpxFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExpanded() {
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpanded(boolean expanded) {
|
||||||
|
this.expanded = expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoaded(boolean loaded) {
|
||||||
|
this.loaded = loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotSupported(boolean notSupported) {
|
||||||
|
this.notSupported = notSupported;
|
||||||
|
if (notSupported) {
|
||||||
|
this.loaded = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return kbSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNotSupported() {
|
||||||
|
return notSupported;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalIndexType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSingleFile() {
|
||||||
|
return singleFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLoaded() {
|
||||||
|
return loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCorrupted() {
|
||||||
|
return corrupted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBackupedData() {
|
||||||
|
return backupedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPathToData() {
|
||||||
|
return pathToData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,19 +14,17 @@ import net.osmand.Algoritms;
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.data.IndexConstants;
|
import net.osmand.data.IndexConstants;
|
||||||
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
|
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||||
import net.osmand.plus.GPXUtilities.WptPt;
|
import net.osmand.plus.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.EnumAdapter.IEnumWithResource;
|
import net.osmand.plus.activities.EnumAdapter.IEnumWithResource;
|
||||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexInfo;
|
|
||||||
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||||
import net.osmand.plus.osmedit.OpenstreetmapRemoteUtil;
|
|
||||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
@ -52,7 +50,6 @@ import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ExpandableListView;
|
import android.widget.ExpandableListView;
|
||||||
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
|
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
|
||||||
import android.widget.Spinner;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -73,6 +70,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
|
|
||||||
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
||||||
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
|
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
|
||||||
|
private ContextMenuAdapter optionsMenuAdapter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,75 +138,38 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendGPXFiles(final LocalIndexInfo... info){
|
|
||||||
String name = settings.USER_NAME.get();
|
|
||||||
String pwd = settings.USER_PASSWORD.get();
|
|
||||||
if(Algoritms.isEmpty(name) || Algoritms.isEmpty(pwd)){
|
|
||||||
AccessibleToast.makeText(this, R.string.validate_gpx_upload_name_pwd, Toast.LENGTH_LONG).show();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Builder bldr = new AlertDialog.Builder(this);
|
|
||||||
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
final View view = inflater.inflate(R.layout.send_gpx_osm, null);
|
|
||||||
final EditText descr = (EditText) view.findViewById(R.id.DescriptionText);
|
|
||||||
if(info.length > 0 && info[0].getFileName() != null) {
|
|
||||||
int dt = info[0].getFileName().indexOf('.');
|
|
||||||
descr.setText(info[0].getFileName().substring(0, dt));
|
|
||||||
}
|
|
||||||
final EditText tags = (EditText) view.findViewById(R.id.TagsText);
|
|
||||||
final Spinner visibility = ((Spinner)view.findViewById(R.id.Visibility));
|
|
||||||
EnumAdapter<UploadVisibility> adapter = new EnumAdapter<UploadVisibility>(this, R.layout.my_spinner_text, UploadVisibility.values());
|
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
||||||
visibility.setAdapter(adapter);
|
|
||||||
visibility.setSelection(0);
|
|
||||||
|
|
||||||
bldr.setView(view);
|
|
||||||
bldr.setNegativeButton(R.string.default_buttons_no, null);
|
|
||||||
bldr.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
new UploadGPXFilesTask(descr.getText().toString(), tags.getText().toString(),
|
|
||||||
(UploadVisibility) visibility.getItemAtPosition(visibility.getSelectedItemPosition())
|
|
||||||
).execute(info);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
bldr.show();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void showContextMenu(final LocalIndexInfo info) {
|
private void showContextMenu(final LocalIndexInfo info) {
|
||||||
Builder builder = new AlertDialog.Builder(this);
|
Builder builder = new AlertDialog.Builder(this);
|
||||||
final List<Integer> menu = new ArrayList<Integer>();
|
final ContextMenuAdapter adapter = new ContextMenuAdapter(this);
|
||||||
if(info.getType() == LocalIndexType.GPX_DATA){
|
if (info.getType() == LocalIndexType.GPX_DATA) {
|
||||||
menu.add(R.string.show_gpx_route);
|
showGPXRouteAction(info, adapter);
|
||||||
if(OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
|
||||||
menu.add(R.string.local_index_mi_upload_gpx);
|
|
||||||
}
|
|
||||||
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
||||||
descriptionLoader.execute(info);
|
descriptionLoader.execute(info);
|
||||||
}
|
}
|
||||||
if(info.getType() == LocalIndexType.MAP_DATA){
|
basicFileOperation(info, adapter);
|
||||||
if(!info.isBackupedData()){
|
OsmandPlugin.onContextMenuLocalIndexes(this, info, adapter);
|
||||||
menu.add(R.string.local_index_mi_backup);
|
|
||||||
}
|
String[] values = adapter.getItemNames();
|
||||||
}
|
|
||||||
if(info.isBackupedData()){
|
|
||||||
menu.add(R.string.local_index_mi_restore);
|
|
||||||
}
|
|
||||||
menu.add(R.string.local_index_mi_rename);
|
|
||||||
menu.add(R.string.local_index_mi_delete);
|
|
||||||
if (!menu.isEmpty()) {
|
|
||||||
String[] values = new String[menu.size()];
|
|
||||||
for (int i = 0; i < values.length; i++) {
|
|
||||||
values[i] = getString(menu.get(i));
|
|
||||||
}
|
|
||||||
builder.setItems(values, new DialogInterface.OnClickListener() {
|
builder.setItems(values, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
int resId = menu.get(which);
|
OnContextMenuClick clk = adapter.getClickAdapter(which);
|
||||||
if (resId == R.string.show_gpx_route) {
|
if (clk != null) {
|
||||||
|
clk.onContextMenuClick(adapter.getItemId(which), which, false, dialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showGPXRouteAction(final LocalIndexInfo info, ContextMenuAdapter adapter) {
|
||||||
|
adapter.registerItem(R.string.show_gpx_route, 0, new OnContextMenuClick() {
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
if (info != null && info.getGpxFile() != null) {
|
if (info != null && info.getGpxFile() != null) {
|
||||||
WptPt loc = info.getGpxFile().findPointToShow();
|
WptPt loc = info.getGpxFile().findPointToShow();
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
|
@ -217,7 +178,16 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
getMyApplication().setGpxFileToDisplay(info.getGpxFile(), false);
|
getMyApplication().setGpxFileToDisplay(info.getGpxFile(), false);
|
||||||
MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this);
|
MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this);
|
||||||
}
|
}
|
||||||
} else if (resId == R.string.local_index_mi_rename) {
|
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void basicFileOperation(final LocalIndexInfo info, ContextMenuAdapter adapter) {
|
||||||
|
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int resId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
if (resId == R.string.local_index_mi_rename) {
|
||||||
renameFile(info);
|
renameFile(info);
|
||||||
} else if (resId == R.string.local_index_mi_restore) {
|
} else if (resId == R.string.local_index_mi_restore) {
|
||||||
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
|
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
|
||||||
|
@ -234,14 +204,20 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
confirm.show();
|
confirm.show();
|
||||||
} else if (resId == R.string.local_index_mi_backup) {
|
} else if (resId == R.string.local_index_mi_backup) {
|
||||||
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
|
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
|
||||||
} else if (resId == R.string.local_index_mi_upload_gpx) {
|
|
||||||
sendGPXFiles(info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
builder.show();
|
};
|
||||||
|
if(info.getType() == LocalIndexType.MAP_DATA){
|
||||||
|
if(!info.isBackupedData()){
|
||||||
|
adapter.registerItem(R.string.local_index_mi_backup, 0, listener, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(info.isBackupedData()){
|
||||||
|
adapter.registerItem(R.string.local_index_mi_restore, 0, listener, 2);
|
||||||
|
}
|
||||||
|
adapter.registerItem(R.string.local_index_mi_rename, 0, listener, 3);
|
||||||
|
adapter.registerItem(R.string.local_index_mi_delete, 0, listener, 4 );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renameFile(LocalIndexInfo info) {
|
private void renameFile(LocalIndexInfo info) {
|
||||||
|
@ -281,7 +257,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
@Override
|
@Override
|
||||||
protected List<LocalIndexInfo> doInBackground(Activity... params) {
|
protected List<LocalIndexInfo> doInBackground(Activity... params) {
|
||||||
LocalIndexHelper helper = new LocalIndexHelper(getMyApplication());
|
LocalIndexHelper helper = new LocalIndexHelper(getMyApplication());
|
||||||
return helper.getAllLocalIndexData(this);
|
return helper.getLocalIndexData(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFile(LocalIndexInfo... loaded) {
|
public void loadFile(LocalIndexInfo... loaded) {
|
||||||
|
@ -454,67 +430,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UploadGPXFilesTask extends AsyncTask<LocalIndexInfo, String, String> {
|
|
||||||
|
|
||||||
private final String visibility;
|
|
||||||
private final String description;
|
|
||||||
private final String tagstring;
|
|
||||||
|
|
||||||
public UploadGPXFilesTask(String description, String tagstring, UploadVisibility visibility){
|
|
||||||
this.description = description;
|
|
||||||
this.tagstring = tagstring;
|
|
||||||
this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.Private.asURLparam();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String doInBackground(LocalIndexInfo... params) {
|
|
||||||
int count = 0;
|
|
||||||
int total = 0;
|
|
||||||
for (LocalIndexInfo info : params) {
|
|
||||||
if (!isCancelled()) {
|
|
||||||
String warning = null;
|
|
||||||
File file = new File(info.getPathToData());
|
|
||||||
// TODO should be plugin functionality and do not use remote util directly
|
|
||||||
warning = new OpenstreetmapRemoteUtil(LocalIndexesActivity.this, null).uploadGPXFile(tagstring, description, visibility, file);
|
|
||||||
total++;
|
|
||||||
if (warning == null) {
|
|
||||||
count++;
|
|
||||||
} else {
|
|
||||||
publishProgress(warning);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getString(R.string.local_index_items_uploaded, count, total);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(String... values) {
|
|
||||||
if (values.length > 0) {
|
|
||||||
StringBuilder b = new StringBuilder();
|
|
||||||
for (int i=0; i<values.length; i++) {
|
|
||||||
if(i > 0){
|
|
||||||
b.append("\n");
|
|
||||||
}
|
|
||||||
b.append(values[i]);
|
|
||||||
}
|
|
||||||
AccessibleToast.makeText(LocalIndexesActivity.this, b.toString(), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
findViewById(R.id.ProgressBar).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(String result) {
|
|
||||||
findViewById(R.id.ProgressBar).setVisibility(View.GONE);
|
|
||||||
AccessibleToast.makeText(LocalIndexesActivity.this, result, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LoadLocalIndexDescriptionTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, LocalIndexInfo[]> {
|
public class LoadLocalIndexDescriptionTask extends AsyncTask<LocalIndexInfo, LocalIndexInfo, LocalIndexInfo[]> {
|
||||||
|
|
||||||
|
@ -558,6 +474,10 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<LocalIndexInfo> getSelectedItems() {
|
||||||
|
return selectedItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -587,12 +507,20 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
menu.add(0, R.string.local_index_mi_backup, 0, getString(R.string.local_index_mi_backup)+"...");
|
optionsMenuAdapter = new ContextMenuAdapter(this);
|
||||||
menu.add(0, R.string.local_index_mi_restore, 1, getString(R.string.local_index_mi_restore)+"...");
|
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||||
menu.add(0, R.string.local_index_mi_delete, 2, getString(R.string.local_index_mi_delete)+"...");
|
@Override
|
||||||
menu.add(0, R.string.local_index_mi_reload, 3, R.string.local_index_mi_reload);
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
if(OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
localOptionsMenu(itemId);
|
||||||
menu.add(0, R.string.local_index_mi_upload_gpx, 4, getString(R.string.local_index_mi_upload_gpx)+"...");
|
}
|
||||||
|
};
|
||||||
|
optionsMenuAdapter.registerItem(R.string.local_index_mi_backup, 0, listener, 0);
|
||||||
|
optionsMenuAdapter.registerItem(R.string.local_index_mi_restore, 0, listener, 1);
|
||||||
|
optionsMenuAdapter.registerItem(R.string.local_index_mi_delete, 0, listener, 2);
|
||||||
|
optionsMenuAdapter.registerItem(R.string.local_index_mi_reload, 0, listener, 3);
|
||||||
|
OsmandPlugin.onOptionsMenuLocalIndexes(this, optionsMenuAdapter);
|
||||||
|
for(int j = 0; j<optionsMenuAdapter.length(); j++){
|
||||||
|
menu.add(0, optionsMenuAdapter.getItemId(j), j + 1, optionsMenuAdapter.getItemName(j));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -614,9 +542,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
operationTask = new LocalIndexOperationTask(DELETE_OPERATION);
|
operationTask = new LocalIndexOperationTask(DELETE_OPERATION);
|
||||||
} else if(actionResId == R.string.local_index_mi_restore){
|
} else if(actionResId == R.string.local_index_mi_restore){
|
||||||
operationTask = new LocalIndexOperationTask(RESTORE_OPERATION);
|
operationTask = new LocalIndexOperationTask(RESTORE_OPERATION);
|
||||||
} else if(actionResId == R.string.local_index_mi_upload_gpx){
|
|
||||||
sendGPXFiles(selectedItems.toArray(new LocalIndexInfo[selectedItems.size()]));
|
|
||||||
operationTask = null;
|
|
||||||
} else {
|
} else {
|
||||||
operationTask = null;
|
operationTask = null;
|
||||||
}
|
}
|
||||||
|
@ -626,6 +551,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
closeSelectionMode();
|
closeSelectionMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void collapseAllGroups() {
|
private void collapseAllGroups() {
|
||||||
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
||||||
getExpandableListView().collapseGroup(i);
|
getExpandableListView().collapseGroup(i);
|
||||||
|
@ -744,24 +670,31 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if(item.getItemId() == R.string.local_index_mi_reload){
|
int itemId = item.getItemId();
|
||||||
|
for(int i =0; i <optionsMenuAdapter.length(); i++){
|
||||||
|
if(itemId == optionsMenuAdapter.getItemId(i)) {
|
||||||
|
optionsMenuAdapter.getClickAdapter(i).onContextMenuClick(itemId, i, false, null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void localOptionsMenu(int itemId ){
|
||||||
|
if(itemId == R.string.local_index_mi_reload){
|
||||||
reloadIndexes();
|
reloadIndexes();
|
||||||
} else if(item.getItemId() == R.string.local_index_mi_delete){
|
} else if(itemId == R.string.local_index_mi_delete){
|
||||||
openSelectionMode(R.string.local_index_mi_delete);
|
openSelectionMode(R.string.local_index_mi_delete);
|
||||||
} else if(item.getItemId() == R.string.local_index_mi_backup){
|
} else if(itemId == R.string.local_index_mi_backup){
|
||||||
listAdapter.filterCategories(false);
|
listAdapter.filterCategories(false);
|
||||||
listAdapter.filterCategories(LocalIndexType.MAP_DATA);
|
listAdapter.filterCategories(LocalIndexType.MAP_DATA);
|
||||||
openSelectionMode(R.string.local_index_mi_backup);
|
openSelectionMode(R.string.local_index_mi_backup);
|
||||||
} else if(item.getItemId() == R.string.local_index_mi_restore){
|
} else if(itemId == R.string.local_index_mi_restore){
|
||||||
listAdapter.filterCategories(true);
|
listAdapter.filterCategories(true);
|
||||||
openSelectionMode(R.string.local_index_mi_restore);
|
openSelectionMode(R.string.local_index_mi_restore);
|
||||||
} else if(item.getItemId() == R.string.local_index_mi_upload_gpx){
|
} else if(itemId == R.string.local_index_mi_upload_gpx){
|
||||||
listAdapter.filterCategories(LocalIndexType.GPX_DATA);
|
listAdapter.filterCategories(LocalIndexType.GPX_DATA);
|
||||||
openSelectionMode(R.string.local_index_mi_upload_gpx);
|
openSelectionMode(R.string.local_index_mi_upload_gpx);
|
||||||
} else {
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ package net.osmand.plus.audionotes;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -22,6 +25,10 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
import net.osmand.plus.views.MapInfoLayer;
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
|
@ -161,6 +168,21 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
||||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||||
}
|
}
|
||||||
updateInternalDescription();
|
updateInternalDescription();
|
||||||
|
return ctx.getString(R.string.recording_description, nm, getDuration(ctx),
|
||||||
|
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSmallDescription(Context ctx){
|
||||||
|
String nm = name == null? "" : name ;
|
||||||
|
if(isPhoto()){
|
||||||
|
return ctx.getString(R.string.recording_photo_description, nm,
|
||||||
|
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||||
|
}
|
||||||
|
return ctx.getString(R.string.recording_description, nm, "",
|
||||||
|
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
@ -176,9 +198,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
||||||
if(!available) {
|
if(!available) {
|
||||||
additional += "("+ctx.getString(R.string.recording_unavailable)+")";
|
additional += "("+ctx.getString(R.string.recording_unavailable)+")";
|
||||||
}
|
}
|
||||||
return ctx.getString(R.string.recording_description, nm, additional,
|
return additional;
|
||||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -608,4 +631,77 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RecordingLocalIndexInfo extends LocalIndexInfo {
|
||||||
|
|
||||||
|
private Recording rec;
|
||||||
|
|
||||||
|
public RecordingLocalIndexInfo(Recording r) {
|
||||||
|
super(LocalIndexType.AV_DATA, r.file, false);
|
||||||
|
this.rec = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return rec.getSmallDescription(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadLocalIndexes(List<LocalIndexInfo> result, LoadLocalIndexTask loadTask) {
|
||||||
|
List<LocalIndexInfo> progress = new ArrayList<LocalIndexInfo>();
|
||||||
|
for (Recording r : getRecordingsSorted()) {
|
||||||
|
LocalIndexInfo info = new RecordingLocalIndexInfo(r);
|
||||||
|
result.add(info);
|
||||||
|
progress.add(info);
|
||||||
|
if (progress.size() > 7) {
|
||||||
|
loadTask.loadFile(progress.toArray(new LocalIndexInfo[progress.size()]));
|
||||||
|
progress.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!progress.isEmpty()) {
|
||||||
|
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) {
|
||||||
|
final RecordingLocalIndexInfo ri = (RecordingLocalIndexInfo) info;
|
||||||
|
adapter.registerItem(R.string.show_location, 0, new OnContextMenuClick() {
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
app.getSettings().SHOW_RECORDINGS.set(true);
|
||||||
|
app.getSettings().setMapLocationToShow(ri.rec.lat, ri.rec.lon, app.getSettings().getLastKnownMapZoom());
|
||||||
|
MapActivity.launchMapActivityMoveToTop(la);
|
||||||
|
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Recording[] getRecordingsSorted() {
|
||||||
|
List<Recording> allObjects = recordings.getAllObjects();
|
||||||
|
Recording[] res = allObjects.toArray(new Recording[allObjects.size()]);
|
||||||
|
Arrays.sort(res, new Comparator<Recording>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Recording object1, Recording object2) {
|
||||||
|
long l1 = object1.file.lastModified();
|
||||||
|
long l2 = object1.file.lastModified();
|
||||||
|
return l1 < l2 ? 1 : -1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.plus.osmedit;
|
package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
|
import net.osmand.Algoritms;
|
||||||
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||||
|
@ -7,9 +9,16 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.EnumAdapter;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity.UploadVisibility;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.AlertDialog.Builder;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
|
@ -19,6 +28,11 @@ import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceCategory;
|
import android.preference.PreferenceCategory;
|
||||||
import android.preference.PreferenceScreen;
|
import android.preference.PreferenceScreen;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class OsmEditingPlugin extends OsmandPlugin {
|
public class OsmEditingPlugin extends OsmandPlugin {
|
||||||
private static final String ID = "osm.editing";
|
private static final String ID = "osm.editing";
|
||||||
|
@ -154,7 +168,6 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
||||||
if (itemId == R.string.layer_osm_bugs) {
|
if (itemId == R.string.layer_osm_bugs) {
|
||||||
settings.SHOW_OSM_BUGS.set(isChecked);
|
settings.SHOW_OSM_BUGS.set(isChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, 5);
|
}, 5);
|
||||||
|
|
||||||
|
@ -165,6 +178,67 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
||||||
return app.getString(R.string.osm_editing_plugin_description);
|
return app.getString(R.string.osm_editing_plugin_description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextMenuLocalIndexes(final LocalIndexesActivity la, final LocalIndexInfo info, ContextMenuAdapter adapter) {
|
||||||
|
adapter.registerItem(R.string.local_index_mi_upload_gpx, 0, new OnContextMenuClick() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
sendGPXFiles(la, info);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void optionsMenuLocalIndexes(final LocalIndexesActivity la, ContextMenuAdapter optionsMenuAdapter) {
|
||||||
|
optionsMenuAdapter.registerItem(R.string.local_index_mi_upload_gpx, 0, new OnContextMenuClick() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||||
|
sendGPXFiles(la, la.getSelectedItems().toArray(new LocalIndexInfo[la.getSelectedItems().size()]));
|
||||||
|
|
||||||
|
}
|
||||||
|
}, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean sendGPXFiles(final LocalIndexesActivity la, final LocalIndexInfo... info){
|
||||||
|
String name = settings.USER_NAME.get();
|
||||||
|
String pwd = settings.USER_PASSWORD.get();
|
||||||
|
if(Algoritms.isEmpty(name) || Algoritms.isEmpty(pwd)){
|
||||||
|
AccessibleToast.makeText(la, R.string.validate_gpx_upload_name_pwd, Toast.LENGTH_LONG).show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Builder bldr = new AlertDialog.Builder(la);
|
||||||
|
LayoutInflater inflater = (LayoutInflater)la.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
final View view = inflater.inflate(R.layout.send_gpx_osm, null);
|
||||||
|
final EditText descr = (EditText) view.findViewById(R.id.DescriptionText);
|
||||||
|
if(info.length > 0 && info[0].getFileName() != null) {
|
||||||
|
int dt = info[0].getFileName().indexOf('.');
|
||||||
|
descr.setText(info[0].getFileName().substring(0, dt));
|
||||||
|
}
|
||||||
|
final EditText tags = (EditText) view.findViewById(R.id.TagsText);
|
||||||
|
final Spinner visibility = ((Spinner)view.findViewById(R.id.Visibility));
|
||||||
|
EnumAdapter<UploadVisibility> adapter = new EnumAdapter<UploadVisibility>(la, R.layout.my_spinner_text, UploadVisibility.values());
|
||||||
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
visibility.setAdapter(adapter);
|
||||||
|
visibility.setSelection(0);
|
||||||
|
|
||||||
|
bldr.setView(view);
|
||||||
|
bldr.setNegativeButton(R.string.default_buttons_no, null);
|
||||||
|
bldr.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
new UploadGPXFilesTask(la, descr.getText().toString(), tags.getText().toString(),
|
||||||
|
(UploadVisibility) visibility.getItemAtPosition(visibility.getSelectedItemPosition())
|
||||||
|
).execute(info);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
bldr.show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return app.getString(R.string.osm_settings);
|
return app.getString(R.string.osm_settings);
|
||||||
|
|
76
OsmAnd/src/net/osmand/plus/osmedit/UploadGPXFilesTask.java
Normal file
76
OsmAnd/src/net/osmand/plus/osmedit/UploadGPXFilesTask.java
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
package net.osmand.plus.osmedit;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.osmand.access.AccessibleToast;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity;
|
||||||
|
import net.osmand.plus.activities.LocalIndexesActivity.UploadVisibility;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
public class UploadGPXFilesTask extends AsyncTask<LocalIndexInfo, String, String> {
|
||||||
|
|
||||||
|
private final String visibility;
|
||||||
|
private final String description;
|
||||||
|
private final String tagstring;
|
||||||
|
private LocalIndexesActivity la;
|
||||||
|
|
||||||
|
public UploadGPXFilesTask(LocalIndexesActivity la,
|
||||||
|
String description, String tagstring, UploadVisibility visibility) {
|
||||||
|
this.la = la;
|
||||||
|
this.description = description;
|
||||||
|
this.tagstring = tagstring;
|
||||||
|
this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.Private.asURLparam();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(LocalIndexInfo... params) {
|
||||||
|
int count = 0;
|
||||||
|
int total = 0;
|
||||||
|
for (LocalIndexInfo info : params) {
|
||||||
|
if (!isCancelled()) {
|
||||||
|
String warning = null;
|
||||||
|
File file = new File(info.getPathToData());
|
||||||
|
warning = new OpenstreetmapRemoteUtil(la, null).uploadGPXFile(tagstring, description, visibility,
|
||||||
|
file);
|
||||||
|
total++;
|
||||||
|
if (warning == null) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
publishProgress(warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return la.getString(R.string.local_index_items_uploaded, count, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(String... values) {
|
||||||
|
if (values.length > 0) {
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
for (int i = 0; i < values.length; i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
b.append("\n");
|
||||||
|
}
|
||||||
|
b.append(values[i]);
|
||||||
|
}
|
||||||
|
AccessibleToast.makeText(la, b.toString(), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
la.findViewById(R.id.ProgressBar).setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String result) {
|
||||||
|
la.findViewById(R.id.ProgressBar).setVisibility(View.GONE);
|
||||||
|
AccessibleToast.makeText(la, result, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue