Search in sources :

Example 1 with SavingTrackHelper

use of net.osmand.plus.track.helpers.SavingTrackHelper in project Osmand by osmandapp.

the class DashTrackFragment method updateCurrentTrack.

public static void updateCurrentTrack(View v, final Activity ctx, final OsmandApplication app) {
    final OsmandMonitoringPlugin plugin = OsmandPlugin.getActivePlugin(OsmandMonitoringPlugin.class);
    if (v == null || ctx == null || app == null || plugin == null) {
        return;
    }
    final boolean isRecording = app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get();
    ImageButton stop = ((ImageButton) v.findViewById(R.id.stop));
    if (isRecording) {
        stop.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_rec_stop));
        stop.setContentDescription(app.getString(R.string.gpx_monitoring_stop));
    } else {
        stop.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_rec_start));
        stop.setContentDescription(app.getString(R.string.gpx_monitoring_start));
    }
    stop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isRecording) {
                plugin.stopRecording();
            } else if (app.getLocationProvider().checkGPSEnabled(ctx)) {
                plugin.startGPXMonitoring(ctx);
            }
        }
    });
    SavingTrackHelper sth = app.getSavingTrackHelper();
    ImageButton save = ((ImageButton) v.findViewById(R.id.show_on_map));
    save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            plugin.saveCurrentTrack();
        }
    });
    if (sth.getPoints() > 0 || sth.getDistance() > 0) {
        save.setVisibility(View.VISIBLE);
    } else {
        save.setVisibility(View.GONE);
    }
    save.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_gsave_dark));
    save.setContentDescription(app.getString(R.string.save_current_track));
    ((TextView) v.findViewById(R.id.points_count)).setText(String.valueOf(sth.getPoints()));
    ((TextView) v.findViewById(R.id.distance)).setText(OsmAndFormatter.getFormattedDistance(sth.getDistance(), app));
    v.findViewById(R.id.points_icon).setVisibility(View.VISIBLE);
    ImageView distance = (ImageView) v.findViewById(R.id.distance_icon);
    distance.setVisibility(View.VISIBLE);
    distance.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_distance_16));
    ImageView pointsCount = (ImageView) v.findViewById(R.id.points_icon);
    pointsCount.setVisibility(View.VISIBLE);
    pointsCount.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_waypoint_16));
}
Also used : ImageButton(android.widget.ImageButton) TextView(android.widget.TextView) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 2 with SavingTrackHelper

use of net.osmand.plus.track.helpers.SavingTrackHelper in project Osmand by osmandapp.

the class UpdateGpxCategoryTask method onPreExecute.

@Override
protected void onPreExecute() {
    FragmentActivity activity = activityRef.get();
    if (activity != null) {
        progressDialog = new ProgressDialog(activity);
        progressDialog.setTitle(EditTrackGroupDialogFragment.getCategoryName(app, group.getName()));
        progressDialog.setMessage(newCategory != null ? "Changing name" : "Changing color");
        progressDialog.setCancelable(false);
        progressDialog.show();
        GPXFile gpxFile = group.getGpx();
        if (gpxFile != null) {
            SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
            List<GpxDisplayItem> items = group.getModifiableList();
            String prevCategory = group.getName();
            boolean emptyCategory = TextUtils.isEmpty(prevCategory);
            for (GpxDisplayItem item : items) {
                WptPt wpt = item.locationStart;
                if (wpt != null) {
                    boolean update = false;
                    if (emptyCategory) {
                        if (TextUtils.isEmpty(wpt.category)) {
                            update = true;
                        }
                    } else if (prevCategory.equals(wpt.category)) {
                        update = true;
                    }
                    if (update) {
                        wasUpdated = true;
                        String category = newCategory != null ? newCategory : wpt.category;
                        int color = newColor != null ? newColor : wpt.colourARGB;
                        if (gpxFile.showCurrentTrack) {
                            savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), wpt.desc, wpt.name, category, color);
                        } else {
                            gpxFile.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), wpt.desc, wpt.name, category, color, wpt.getIconName(), wpt.getBackgroundType());
                        }
                    }
                }
            }
        }
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) WptPt(net.osmand.GPXUtilities.WptPt) GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) ProgressDialog(android.app.ProgressDialog) GPXFile(net.osmand.GPXUtilities.GPXFile)

Example 3 with SavingTrackHelper

use of net.osmand.plus.track.helpers.SavingTrackHelper in project Osmand by osmandapp.

the class AvailableGPXFragment method updateCurrentTrack.

public void updateCurrentTrack() {
    final OsmandMonitoringPlugin plugin = OsmandPlugin.getActivePlugin(OsmandMonitoringPlugin.class);
    if (currentGpxView == null || plugin == null) {
        return;
    }
    final boolean isRecording = app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get();
    ImageView icon = currentGpxView.findViewById(R.id.icon);
    icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.monitoring_rec_big));
    icon.setVisibility(selectionMode && showOnMapMode ? View.GONE : View.VISIBLE);
    SavingTrackHelper sth = app.getSavingTrackHelper();
    int activeColorId = ColorUtilities.getActiveColorId(nightMode);
    Button stop = currentGpxView.findViewById(R.id.action_button);
    if (isRecording) {
        currentGpxView.findViewById(R.id.segment_time_div).setVisibility(View.VISIBLE);
        TextView segmentTime = currentGpxView.findViewById(R.id.segment_time);
        segmentTime.setText(OsmAndFormatter.getFormattedDurationShort((int) (sth.getDuration() / 1000)));
        segmentTime.setVisibility(View.VISIBLE);
        Drawable stopIcon = app.getUIUtilities().getIcon(R.drawable.ic_action_rec_stop, activeColorId);
        stop.setCompoundDrawablesWithIntrinsicBounds(stopIcon, null, null, null);
        stop.setText(app.getString(R.string.shared_string_control_stop));
        stop.setContentDescription(app.getString(R.string.gpx_monitoring_stop));
    } else {
        currentGpxView.findViewById(R.id.segment_time_div).setVisibility(View.GONE);
        currentGpxView.findViewById(R.id.segment_time).setVisibility(View.GONE);
        Drawable stopIcon = app.getUIUtilities().getIcon(R.drawable.ic_action_rec_start, activeColorId);
        stop.setCompoundDrawablesWithIntrinsicBounds(stopIcon, null, null, null);
        stop.setText(app.getString(R.string.shared_string_record));
        stop.setContentDescription(app.getString(R.string.gpx_monitoring_start));
    }
    stop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (isRecording) {
                plugin.stopRecording();
                updateCurrentTrack();
            } else if (app.getLocationProvider().checkGPSEnabled(getActivity())) {
                plugin.startGPXMonitoring(getActivity());
                updateCurrentTrack();
            }
        }
    });
    Button save = currentGpxView.findViewById(R.id.save_button);
    Drawable saveIcon = app.getUIUtilities().getIcon(R.drawable.ic_action_gsave_dark, activeColorId);
    save.setCompoundDrawablesWithIntrinsicBounds(saveIcon, null, null, null);
    save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            plugin.saveCurrentTrack(new Runnable() {

                @Override
                public void run() {
                    if (isResumed()) {
                        reloadTracks();
                    }
                }
            });
            updateCurrentTrack();
        }
    });
    if (sth.getPoints() > 0 || sth.getDistance() > 0) {
        save.setVisibility(View.VISIBLE);
    } else {
        save.setVisibility(View.GONE);
    }
    save.setContentDescription(app.getString(R.string.save_current_track));
    ((TextView) currentGpxView.findViewById(R.id.points_count)).setText(String.valueOf(sth.getPoints()));
    ((TextView) currentGpxView.findViewById(R.id.distance)).setText(OsmAndFormatter.getFormattedDistance(sth.getDistance(), app));
    final CheckBox checkbox = currentGpxView.findViewById(R.id.check_local_index);
    checkbox.setVisibility(selectionMode && showOnMapMode ? View.VISIBLE : View.GONE);
    if (selectionMode && showOnMapMode) {
        checkbox.setChecked(selectedItems.contains(currentRecording));
        checkbox.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (checkbox.isChecked()) {
                    selectedItems.add(currentRecording);
                } else {
                    selectedItems.remove(currentRecording);
                }
                updateSelectionMode(actionMode);
            }
        });
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) ImageView(android.widget.ImageView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) OsmandMonitoringPlugin(net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin) ImageButton(android.widget.ImageButton) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 4 with SavingTrackHelper

use of net.osmand.plus.track.helpers.SavingTrackHelper in project Osmand by osmandapp.

the class SaveCurrentTrackTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
    Map<String, GPXUtilities.GPXFile> files = savingTrackHelper.collectRecordedData();
    File dir;
    boolean shouldClearPath = false;
    if (gpx.path.isEmpty()) {
        dir = app.getCacheDir();
        shouldClearPath = true;
    } else {
        dir = app.getAppCustomization().getTracksDir();
    }
    if (!dir.exists()) {
        dir.mkdir();
    }
    for (final String f : files.keySet()) {
        File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
        Exception exception = GPXUtilities.writeGpxFile(fout, gpx);
        if (exception == null) {
            app.getSavingTrackHelper().setLastTimeFileSaved(fout.lastModified());
        }
    }
    return shouldClearPath;
}
Also used : SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Example 5 with SavingTrackHelper

use of net.osmand.plus.track.helpers.SavingTrackHelper in project Osmand by osmandapp.

the class DeletePointsTask method doInBackground.

@Override
protected Void doInBackground(Void... params) {
    SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
    if (gpx != null) {
        for (GpxDisplayItem item : selectedItems) {
            if (gpx.showCurrentTrack) {
                savingTrackHelper.deletePointData(item.locationStart);
            } else {
                if (item.group.getType() == GpxDisplayItemType.TRACK_POINTS) {
                    gpx.deleteWptPt(item.locationStart);
                } else if (item.group.getType() == GpxDisplayItemType.TRACK_ROUTE_POINTS) {
                    gpx.deleteRtePt(item.locationStart);
                }
            }
        }
        if (!gpx.showCurrentTrack) {
            GPXUtilities.writeGpxFile(new File(gpx.path), gpx);
            boolean selected = app.getSelectedGpxHelper().getSelectedFileByPath(gpx.path) != null;
            if (selected) {
                app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
            }
        }
        syncGpx(gpx);
    }
    return null;
}
Also used : GpxDisplayItem(net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File)

Aggregations

SavingTrackHelper (net.osmand.plus.track.helpers.SavingTrackHelper)11 GPXFile (net.osmand.GPXUtilities.GPXFile)6 WptPt (net.osmand.GPXUtilities.WptPt)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 GpxSelectionHelper (net.osmand.plus.track.helpers.GpxSelectionHelper)3 DialogInterface (android.content.DialogInterface)2 ImageButton (android.widget.ImageButton)2 TextView (android.widget.TextView)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 File (java.io.File)2 GpxDisplayItem (net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItem)2 AlertDialog (android.app.AlertDialog)1 ProgressDialog (android.app.ProgressDialog)1 Drawable (android.graphics.drawable.Drawable)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1