|
|
|
@ -23,6 +23,7 @@ import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.CheckBox;
|
|
|
|
@ -40,7 +41,6 @@ import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
|
|
import androidx.appcompat.view.ActionMode;
|
|
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
|
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
import androidx.core.view.MenuItemCompat;
|
|
|
|
@ -69,13 +69,13 @@ import net.osmand.plus.OsmAndFormatter;
|
|
|
|
|
import net.osmand.plus.OsmandApplication;
|
|
|
|
|
import net.osmand.plus.OsmandPlugin;
|
|
|
|
|
import net.osmand.plus.R;
|
|
|
|
|
import net.osmand.plus.SimplePopUpMenuItemAdapter;
|
|
|
|
|
import net.osmand.plus.UiUtilities;
|
|
|
|
|
import net.osmand.plus.activities.MapActivity;
|
|
|
|
|
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
|
|
|
|
import net.osmand.plus.activities.SavingTrackHelper;
|
|
|
|
|
import net.osmand.plus.activities.TrackActivity;
|
|
|
|
|
import net.osmand.plus.base.OsmandExpandableListFragment;
|
|
|
|
|
import net.osmand.plus.dialogs.DirectionsDialogs;
|
|
|
|
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
|
|
|
|
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
|
|
|
|
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
|
|
|
@ -1454,112 +1454,133 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
|
|
|
|
|
final List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
|
|
|
|
|
UiUtilities iconsCache = getMyApplication().getUIUtilities();
|
|
|
|
|
final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
|
|
|
|
|
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
|
|
|
|
|
|
|
|
|
|
MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_show_on_map));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
showGpxOnMap(gpxInfo);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.shared_string_show_on_map),
|
|
|
|
|
iconsCache.getThemedIcon(R.drawable.ic_show_on_map),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
showGpxOnMap(gpxInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
GPXTrackAnalysis analysis;
|
|
|
|
|
if ((analysis = getGpxTrackAnalysis(gpxInfo, app, null)) != null) {
|
|
|
|
|
if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
|
|
|
|
|
item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.analyze_on_map),
|
|
|
|
|
iconsCache.getThemedIcon(R.drawable.ic_action_info_dark),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item = optionsMenu.getMenu().add(R.string.shared_string_move).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
moveGpx(gpxInfo);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
item = optionsMenu.getMenu().add(R.string.shared_string_rename)
|
|
|
|
|
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
final SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxInfo.file.getPath());
|
|
|
|
|
FileUtils.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.shared_string_move),
|
|
|
|
|
iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void renamedTo(File file) {
|
|
|
|
|
asyncLoader = new LoadGpxTask();
|
|
|
|
|
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
|
|
|
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
|
|
|
|
|
selectedGpxFile.getGpxFile().path = file.getPath();
|
|
|
|
|
selectedGpxHelper.updateSelectedGpxFile(selectedGpxFile);
|
|
|
|
|
}
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
moveGpx(gpxInfo);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.shared_string_rename),
|
|
|
|
|
iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
final SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxInfo.file.getPath());
|
|
|
|
|
FileUtils.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {
|
|
|
|
|
@Override
|
|
|
|
|
public void renamedTo(File file) {
|
|
|
|
|
asyncLoader = new LoadGpxTask();
|
|
|
|
|
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
|
|
|
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
|
|
|
|
|
selectedGpxFile.getGpxFile().path = file.getPath();
|
|
|
|
|
selectedGpxHelper.updateSelectedGpxFile(selectedGpxFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Drawable shareIcon = iconsCache.getThemedIcon((R.drawable.ic_action_gshare_dark));
|
|
|
|
|
item = optionsMenu.getMenu().add(R.string.shared_string_share)
|
|
|
|
|
.setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
|
|
|
|
|
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
|
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
|
startActivity(sendIntent);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.shared_string_share),
|
|
|
|
|
AndroidUtils.getDrawableForDirection(app, shareIcon),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
final Uri fileUri = AndroidUtils.getUriForFile(getMyApplication(), gpxInfo.file);
|
|
|
|
|
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
|
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
|
startActivity(sendIntent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
|
|
|
|
|
if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
|
|
|
|
|
item = optionsMenu.getMenu().add(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.shared_string_export),
|
|
|
|
|
iconsCache.getThemedIcon(R.drawable.ic_action_export),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item = optionsMenu.getMenu().add(R.string.shared_string_delete)
|
|
|
|
|
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
|
builder.setMessage(R.string.recording_delete_confirm);
|
|
|
|
|
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
|
|
|
|
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
|
|
|
|
getString(R.string.shared_string_delete),
|
|
|
|
|
iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark),
|
|
|
|
|
new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
operationTask = new DeleteGpxTask();
|
|
|
|
|
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
|
builder.setMessage(R.string.recording_delete_confirm);
|
|
|
|
|
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
operationTask = new DeleteGpxTask();
|
|
|
|
|
operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
|
|
|
|
builder.show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
|
|
|
|
builder.show();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
optionsMenu.show();
|
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
UiUtilities.createListPopupWindow(
|
|
|
|
|
getContext(), v, v.getWidth(), items, new AdapterView.OnItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
|
if (position < items.size()) {
|
|
|
|
|
View.OnClickListener listener = items.get(position).getOnClickListener();
|
|
|
|
|
if (listener != null) {
|
|
|
|
|
listener.onClick(view);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DeleteGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
|
|
|
|
|