Share location for av notes

This commit is contained in:
Victor Shcherb 2015-08-31 01:27:19 +02:00
parent 88aa84ecae
commit f3607fb5b9
3 changed files with 56 additions and 15 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. 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="av_locations_descr">Gpx file with note locations</string>
<string name="av_locations">Locations</string>
<string name="plugin_settings">Plugins</string> <string name="plugin_settings">Plugins</string>
<string name="routing_attr_avoid_shuttle_train_name">Avoid shuttle train</string> <string name="routing_attr_avoid_shuttle_train_name">Avoid shuttle train</string>
<string name="routing_attr_avoid_shuttle_train_description">Avoid shuttle train</string> <string name="routing_attr_avoid_shuttle_train_description">Avoid shuttle train</string>

View file

@ -1,10 +1,15 @@
package net.osmand.plus.audionotes; package net.osmand.plus.audionotes;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
@ -17,12 +22,6 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OpenstreetmapRemoteUtil;
import net.osmand.plus.osmedit.OsmBugsRemoteUtil;
import net.osmand.plus.osmedit.OsmNotesPoint;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.OsmEditsFragment.BackupOpenstreetmapPointAsyncTask;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -33,7 +32,6 @@ import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.view.ActionMode; import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -67,6 +65,7 @@ public class NotesFragment extends OsmAndListFragment {
private ActionMode actionMode; private ActionMode actionMode;
private ArrayList<AudioVideoNotesPlugin.Recording> selected = new ArrayList<>(); private ArrayList<AudioVideoNotesPlugin.Recording> selected = new ArrayList<>();
Recording shareLocationFile = new Recording(new File("."));
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -218,21 +217,54 @@ public class NotesFragment extends OsmAndListFragment {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND_MULTIPLE); intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.setType("image/*"); /* This example is sharing jpeg images. */ intent.setType("image/*"); /* This example is sharing jpeg images. */
ArrayList<Uri> files = new ArrayList<Uri>(); ArrayList<Uri> files = new ArrayList<Uri>();
for(Recording path : selected) { for(Recording path : selected) {
if(path == shareLocationFile) {
File fl = generateGPXForRecordings(selected);
if(fl != null) {
files.add(Uri.fromFile(fl));
}
} else {
files.add(Uri.fromFile(path.getFile())); files.add(Uri.fromFile(path.getFile()));
} }
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent, getString(R.string.share_note))); startActivity(Intent.createChooser(intent, getString(R.string.share_note)));
} }
private File generateGPXForRecordings(ArrayList<Recording> selected) {
File cacheDir = getActivity().getCacheDir();
File tmpFile = new File(cacheDir, "noteLocations.gpx");
GPXFile file = new GPXFile();
for(Recording r : selected) {
if(r != shareLocationFile) {
String desc = r.getDescriptionName(r.getFileName());
if(desc == null) {
desc = r.getFileName();
}
WptPt wpt = new WptPt();
wpt.lat = r.getLatitude();
wpt.lon = r.getLongitude();
wpt.name = desc;
wpt.link = r.getFileName();
wpt.time = r.getFile().lastModified();
wpt.category = r.getSearchHistoryType();
file.points.add(wpt);
}
}
GPXUtilities.writeGpxFile(tmpFile, file, getMyApplication());
return tmpFile;
}
private void enterDeleteMode(final int type) { private void enterDeleteMode(final int type) {
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() { actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override @Override
public boolean onCreateActionMode(final ActionMode mode, Menu menu) { public boolean onCreateActionMode(final ActionMode mode, Menu menu) {
if(type == MODE_SHARE) {
listAdapter.insert(shareLocationFile, 0);
}
enableSelectionMode(true); enableSelectionMode(true);
MenuItem item; MenuItem item;
if(type == MODE_DELETE) { if(type == MODE_DELETE) {
@ -271,6 +303,9 @@ public class NotesFragment extends OsmAndListFragment {
@Override @Override
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
if(type == MODE_SHARE) {
listAdapter.remove(shareLocationFile);
}
enableSelectionMode(false); enableSelectionMode(false);
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
} }
@ -307,10 +342,14 @@ public class NotesFragment extends OsmAndListFragment {
} }
final AudioVideoNotesPlugin.Recording recording = getItem(position); final AudioVideoNotesPlugin.Recording recording = getItem(position);
Drawable icon = DashAudioVideoNotesFragment.getNoteView(recording, row, getMyApplication()); if (recording == shareLocationFile) {
icon.setColorFilter(getResources().getColor(R.color.color_distance), Mode.MULTIPLY); ((TextView) row.findViewById(R.id.name)).setText(R.string.av_locations);
((ImageView) row.findViewById(R.id.play)).setImageDrawable(getMyApplication().getIconsCache() ((TextView) row.findViewById(R.id.descr)).setText(R.string.av_locations_descr);
.getContentIcon(R.drawable.ic_play_dark)); } else {
DashAudioVideoNotesFragment.getNoteView(recording, row, getMyApplication());
}
// ((ImageView) row.findViewById(R.id.play)).setImageDrawable(getMyApplication().getIconsCache()
// .getContentIcon(R.drawable.ic_play_dark));
row.findViewById(R.id.play).setVisibility(View.GONE); row.findViewById(R.id.play).setVisibility(View.GONE);