Search in sources :

Example 1 with RenameCallback

use of net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback in project Osmand by osmandapp.

the class AvailableGPXFragment method openPopUpMenu.

private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
    IconsCache iconsCache = getMyApplication().getIconsCache();
    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;
        }
    });
    GPXTrackAnalysis analysis;
    if ((analysis = getGpxTrackAnalysis(gpxInfo, app)) != 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;
                }
            });
        }
    }
    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) {
            LocalIndexesFragment.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {

                @Override
                public void renamedTo(File file) {
                    app.getGpxDatabase().rename(gpxInfo.file, file);
                    asyncLoader = new LoadGpxTask();
                    asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
                }
            });
            return true;
        }
    });
    item = optionsMenu.getMenu().add(R.string.shared_string_share).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final Uri fileUri = Uri.fromFile(gpxInfo.file);
            final Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
            sendIntent.setType("application/gpx+xml");
            startActivity(sendIntent);
            return true;
        }
    });
    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;
            }
        });
    }
    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() {

                @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();
            return true;
        }
    });
    optionsMenu.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) Intent(android.content.Intent) Uri(android.net.Uri) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) RenameCallback(net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback) IconsCache(net.osmand.plus.IconsCache) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Aggregations

DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 PopupMenu (android.support.v7.widget.PopupMenu)1 MenuItem (android.view.MenuItem)1 File (java.io.File)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)1 GPXTrackAnalysis (net.osmand.plus.GPXUtilities.GPXTrackAnalysis)1 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)1 IconsCache (net.osmand.plus.IconsCache)1 RenameCallback (net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback)1 OsmEditingPlugin (net.osmand.plus.osmedit.OsmEditingPlugin)1