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));
}
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());
}
}
}
}
}
}
}
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);
}
});
}
}
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;
}
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;
}
Aggregations