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).
|
||||
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="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>
|
||||
|
|
|
@ -8,6 +8,9 @@ import java.util.Set;
|
|||
import net.osmand.IProgress;
|
||||
import net.osmand.LogUtil;
|
||||
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.SettingsActivity;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
|
@ -137,6 +140,14 @@ public abstract class OsmandPlugin {
|
|||
|
||||
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 void onMapActivityExternalResult(int requestCode, int resultCode, Intent data) {
|
||||
|
@ -252,6 +263,30 @@ public abstract class OsmandPlugin {
|
|||
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,
|
||||
String pluginId, OsmandApplication app, OsmandPlugin plugin) {
|
||||
|
@ -271,6 +306,6 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.osmand.plus.GPXUtilities.TrkSegment;
|
|||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.activities.LocalIndexesActivity.LoadLocalIndexTask;
|
||||
|
@ -50,10 +51,6 @@ public class LocalIndexHelper {
|
|||
this.app = app;
|
||||
}
|
||||
|
||||
public List<LocalIndexInfo> getAllLocalIndexData(LoadLocalIndexTask loadTask){
|
||||
return getLocalIndexData(null, loadTask);
|
||||
}
|
||||
|
||||
public String getInstalledDate(File f){
|
||||
return getInstalledDate(f.lastModified());
|
||||
}
|
||||
|
@ -100,9 +97,12 @@ public class LocalIndexHelper {
|
|||
template.couldBeDownloadedFromInternet(), "");
|
||||
info.setDescription(descr);
|
||||
}
|
||||
} else {
|
||||
OsmandPlugin.onUpdateLocalIndexDescription(info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateGpxInfo(LocalIndexInfo info, File f) {
|
||||
if(info.getGpxFile() == null){
|
||||
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();
|
||||
List<LocalIndexInfo> result = new ArrayList<LocalIndexInfo>();
|
||||
|
||||
|
@ -211,12 +211,11 @@ public class LocalIndexHelper {
|
|||
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.BACKUP_INDEX_DIR), result, true, loadTask);
|
||||
|
||||
OsmandPlugin.onLoadLocalIndexes(result, loadTask);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void loadVoiceData(File voiceDir, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
||||
if (voiceDir.canRead()) {
|
||||
|
@ -278,7 +277,7 @@ public class LocalIndexHelper {
|
|||
|
||||
private void loadGPXData(File mapPath, List<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask) {
|
||||
if (mapPath.canRead()) {
|
||||
List<LocalIndexInfo> progress = new ArrayList<LocalIndexHelper.LocalIndexInfo>();
|
||||
List<LocalIndexInfo> progress = new ArrayList<LocalIndexInfo>();
|
||||
for (File gpxFile : listFilesSorted(mapPath)) {
|
||||
if (gpxFile.isFile() && gpxFile.getName().endsWith(".gpx")) {
|
||||
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.GPX_DATA, gpxFile, backup);
|
||||
|
@ -297,6 +296,8 @@ public class LocalIndexHelper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private File[] listFilesSorted(File dir){
|
||||
File[] listFiles = dir.listFiles();
|
||||
Arrays.sort(listFiles);
|
||||
|
@ -380,7 +381,8 @@ public class LocalIndexHelper {
|
|||
TILES_DATA(R.string.local_indexes_cat_tile),
|
||||
VOICE_DATA(R.string.local_indexes_cat_voice),
|
||||
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;
|
||||
|
||||
|
@ -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.access.AccessibleToast;
|
||||
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.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
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.osmedit.OpenstreetmapRemoteUtil;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
|
@ -52,7 +50,6 @@ import android.widget.CheckBox;
|
|||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -73,6 +70,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
|
||||
MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
|
||||
MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US);
|
||||
private ContextMenuAdapter optionsMenuAdapter;
|
||||
|
||||
|
||||
|
||||
|
@ -140,108 +138,86 @@ 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) {
|
||||
Builder builder = new AlertDialog.Builder(this);
|
||||
final List<Integer> menu = new ArrayList<Integer>();
|
||||
if(info.getType() == LocalIndexType.GPX_DATA){
|
||||
menu.add(R.string.show_gpx_route);
|
||||
if(OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||
menu.add(R.string.local_index_mi_upload_gpx);
|
||||
}
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter(this);
|
||||
if (info.getType() == LocalIndexType.GPX_DATA) {
|
||||
showGPXRouteAction(info, adapter);
|
||||
descriptionLoader = new LoadLocalIndexDescriptionTask();
|
||||
descriptionLoader.execute(info);
|
||||
}
|
||||
basicFileOperation(info, adapter);
|
||||
OsmandPlugin.onContextMenuLocalIndexes(this, info, adapter);
|
||||
|
||||
String[] values = adapter.getItemNames();
|
||||
builder.setItems(values, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
OnContextMenuClick clk = adapter.getClickAdapter(which);
|
||||
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) {
|
||||
WptPt loc = info.getGpxFile().findPointToShow();
|
||||
if (loc != null) {
|
||||
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
|
||||
}
|
||||
getMyApplication().setGpxFileToDisplay(info.getGpxFile(), false);
|
||||
MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this);
|
||||
}
|
||||
|
||||
}
|
||||
}, 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);
|
||||
} else if (resId == R.string.local_index_mi_restore) {
|
||||
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
|
||||
} else if (resId == R.string.local_index_mi_delete) {
|
||||
Builder confirm = new AlertDialog.Builder(LocalIndexesActivity.this);
|
||||
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new LocalIndexOperationTask(DELETE_OPERATION).execute(info);
|
||||
}
|
||||
});
|
||||
confirm.setNegativeButton(R.string.default_buttons_no, null);
|
||||
confirm.setMessage(getString(R.string.delete_confirmation_msg, info.getFileName()));
|
||||
confirm.show();
|
||||
} else if (resId == R.string.local_index_mi_backup) {
|
||||
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
if(info.getType() == LocalIndexType.MAP_DATA){
|
||||
if(!info.isBackupedData()){
|
||||
menu.add(R.string.local_index_mi_backup);
|
||||
adapter.registerItem(R.string.local_index_mi_backup, 0, listener, 1);
|
||||
}
|
||||
}
|
||||
if(info.isBackupedData()){
|
||||
menu.add(R.string.local_index_mi_restore);
|
||||
adapter.registerItem(R.string.local_index_mi_restore, 0, listener, 2);
|
||||
}
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int resId = menu.get(which);
|
||||
if (resId == R.string.show_gpx_route) {
|
||||
if (info != null && info.getGpxFile() != null) {
|
||||
WptPt loc = info.getGpxFile().findPointToShow();
|
||||
if (loc != null) {
|
||||
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
|
||||
}
|
||||
getMyApplication().setGpxFileToDisplay(info.getGpxFile(), false);
|
||||
MapActivity.launchMapActivityMoveToTop(LocalIndexesActivity.this);
|
||||
}
|
||||
} else if (resId == R.string.local_index_mi_rename) {
|
||||
renameFile(info);
|
||||
} else if (resId == R.string.local_index_mi_restore) {
|
||||
new LocalIndexOperationTask(RESTORE_OPERATION).execute(info);
|
||||
} else if (resId == R.string.local_index_mi_delete) {
|
||||
Builder confirm = new AlertDialog.Builder(LocalIndexesActivity.this);
|
||||
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new LocalIndexOperationTask(DELETE_OPERATION).execute(info);
|
||||
}
|
||||
});
|
||||
confirm.setNegativeButton(R.string.default_buttons_no, null);
|
||||
confirm.setMessage(getString(R.string.delete_confirmation_msg, info.getFileName()));
|
||||
confirm.show();
|
||||
} else if (resId == R.string.local_index_mi_backup) {
|
||||
new LocalIndexOperationTask(BACKUP_OPERATION).execute(info);
|
||||
} else if (resId == R.string.local_index_mi_upload_gpx) {
|
||||
sendGPXFiles(info);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
builder.show();
|
||||
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) {
|
||||
|
@ -281,7 +257,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
@Override
|
||||
protected List<LocalIndexInfo> doInBackground(Activity... params) {
|
||||
LocalIndexHelper helper = new LocalIndexHelper(getMyApplication());
|
||||
return helper.getAllLocalIndexData(this);
|
||||
return helper.getLocalIndexData(this);
|
||||
}
|
||||
|
||||
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[]> {
|
||||
|
||||
|
@ -558,6 +474,10 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
public Set<LocalIndexInfo> getSelectedItems() {
|
||||
return selectedItems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -587,12 +507,20 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(0, R.string.local_index_mi_backup, 0, getString(R.string.local_index_mi_backup)+"...");
|
||||
menu.add(0, R.string.local_index_mi_restore, 1, getString(R.string.local_index_mi_restore)+"...");
|
||||
menu.add(0, R.string.local_index_mi_delete, 2, getString(R.string.local_index_mi_delete)+"...");
|
||||
menu.add(0, R.string.local_index_mi_reload, 3, R.string.local_index_mi_reload);
|
||||
if(OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||
menu.add(0, R.string.local_index_mi_upload_gpx, 4, getString(R.string.local_index_mi_upload_gpx)+"...");
|
||||
optionsMenuAdapter = new ContextMenuAdapter(this);
|
||||
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||
@Override
|
||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||
localOptionsMenu(itemId);
|
||||
}
|
||||
};
|
||||
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;
|
||||
}
|
||||
|
@ -614,9 +542,6 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
operationTask = new LocalIndexOperationTask(DELETE_OPERATION);
|
||||
} else if(actionResId == R.string.local_index_mi_restore){
|
||||
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 {
|
||||
operationTask = null;
|
||||
}
|
||||
|
@ -626,6 +551,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
closeSelectionMode();
|
||||
}
|
||||
|
||||
|
||||
private void collapseAllGroups() {
|
||||
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
|
||||
getExpandableListView().collapseGroup(i);
|
||||
|
@ -744,24 +670,31 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity {
|
|||
|
||||
@Override
|
||||
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();
|
||||
} 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);
|
||||
} else if(item.getItemId() == R.string.local_index_mi_backup){
|
||||
} else if(itemId == R.string.local_index_mi_backup){
|
||||
listAdapter.filterCategories(false);
|
||||
listAdapter.filterCategories(LocalIndexType.MAP_DATA);
|
||||
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);
|
||||
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);
|
||||
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.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,6 +25,10 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
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.SettingsActivity;
|
||||
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();
|
||||
}
|
||||
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 = "";
|
||||
if(duration > 0) {
|
||||
int d = (int) (duration / 1000);
|
||||
|
@ -176,9 +198,10 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
if(!available) {
|
||||
additional += "("+ctx.getString(R.string.recording_unavailable)+")";
|
||||
}
|
||||
return ctx.getString(R.string.recording_description, nm, additional,
|
||||
DateFormat.format("dd.MM.yyyy kk:mm", file.lastModified())).trim();
|
||||
return additional;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -607,5 +630,78 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
}
|
||||
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;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
|
@ -7,9 +9,16 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
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.SettingsActivity;
|
||||
import net.osmand.plus.activities.LocalIndexesActivity.UploadVisibility;
|
||||
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.Intent;
|
||||
import android.preference.CheckBoxPreference;
|
||||
|
@ -19,6 +28,11 @@ import android.preference.Preference.OnPreferenceClickListener;
|
|||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
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 {
|
||||
private static final String ID = "osm.editing";
|
||||
|
@ -154,7 +168,6 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
if (itemId == R.string.layer_osm_bugs) {
|
||||
settings.SHOW_OSM_BUGS.set(isChecked);
|
||||
}
|
||||
|
||||
}
|
||||
}, 5);
|
||||
|
||||
|
@ -164,6 +177,67 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
public String getDescription() {
|
||||
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
|
||||
public String getName() {
|
||||
|
|
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