Updated current tracks
This commit is contained in:
parent
d6f4f3ecab
commit
ae33cac5bd
3 changed files with 135 additions and 56 deletions
|
@ -20,6 +20,8 @@ import net.osmand.plus.GPXUtilities;
|
|||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmAndTaskManager;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -30,6 +32,7 @@ import net.osmand.plus.helpers.ScreenOrientationHelper;
|
|||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
|
@ -130,15 +133,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
if (v == null) {
|
||||
return;
|
||||
}
|
||||
OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
||||
|
||||
if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
GpxSelectionHelper.SelectedGpxFile currentTrack = savingTrackHelper.getCurrentTrack();
|
||||
if (plugin != null && savingTrackHelper.getCurrentGpx() != null) {
|
||||
v.findViewById(R.id.current_track).setVisibility(View.VISIBLE);
|
||||
String description = GpxUiHelper.getDescription(getMyApplication(), currentTrack.getGpxFile(), null, true);
|
||||
int startindex = description.indexOf(">");
|
||||
int endindex = description.indexOf("</font>");
|
||||
String distance = description.substring(startindex + 1, endindex);
|
||||
String points = String.valueOf(currentTrack.getGpxFile().points.size());
|
||||
((TextView) v.findViewById(R.id.points_count)).setText(points);
|
||||
((TextView) v.findViewById(R.id.distance)).setText(distance);
|
||||
} else {
|
||||
v.findViewById(R.id.current_track).setVisibility(View.GONE);
|
||||
|
@ -156,26 +160,68 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
((TextView) v.findViewById(R.id.name)).setText(R.string.currently_recording_track);
|
||||
v.findViewById(R.id.time_icon).setVisibility(View.GONE);
|
||||
|
||||
Drawable icon = getResources().getDrawable(R.drawable.ic_action_rec_stop);
|
||||
createCurrentTrackView(v, getMyApplication());
|
||||
|
||||
v.findViewById(R.id.map_btn).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void createCurrentTrackView(View v, final OsmandApplication app) {
|
||||
Drawable icon = app.getResources().getDrawable(R.drawable.ic_action_rec_stop);
|
||||
icon.mutate();
|
||||
boolean light = getMyApplication().getSettings().isLightContent();
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
if (light) {
|
||||
icon.setColorFilter(0xff727272, PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
ImageButton stop = ((ImageButton) v.findViewById(R.id.stop));
|
||||
stop.setImageDrawable(icon);
|
||||
stop.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
||||
plugin.stopRecording();
|
||||
}
|
||||
};
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
stop.setVisibility(View.VISIBLE);
|
||||
|
||||
icon = getResources().getDrawable(R.drawable.ic_action_gsave_dark);
|
||||
icon = app.getResources().getDrawable(R.drawable.ic_action_gsave_dark);
|
||||
icon.mutate();
|
||||
if (light) {
|
||||
icon.setColorFilter(0xff727272, PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
ImageButton save = ((ImageButton) v.findViewById(R.id.show_on_map));
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
save.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Runnable run = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class);
|
||||
plugin.saveCurrentTrack();
|
||||
}
|
||||
};
|
||||
run.run();
|
||||
}
|
||||
});
|
||||
v.findViewById(R.id.divider).setVisibility(View.GONE);
|
||||
save.setImageDrawable(icon);
|
||||
updateCurrentTrack(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,7 +272,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
|
||||
|
||||
|
||||
optionsMenuAdapter = new ContextMenuAdapter(getActivity());
|
||||
OnContextMenuClick listener = new OnContextMenuClick() {
|
||||
@Override
|
||||
|
|
|
@ -8,10 +8,13 @@ import net.osmand.access.AccessibleToast;
|
|||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.AvailableGPXFragment;
|
||||
import net.osmand.plus.activities.FavoritesActivity;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.dashboard.DashBaseFragment;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
|
@ -87,6 +90,28 @@ public class DashTrackFragment extends DashBaseFragment {
|
|||
}
|
||||
}
|
||||
|
||||
OsmandApplication app = getMyApplication();
|
||||
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
|
||||
if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
list.remove(2);
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
View view = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
|
||||
|
||||
AvailableGPXFragment.createCurrentTrackView(view, app);
|
||||
|
||||
GpxSelectionHelper.SelectedGpxFile currentTrack = savingTrackHelper.getCurrentTrack();
|
||||
((TextView)view.findViewById(R.id.name)).setText(R.string.currently_recording_track);
|
||||
String description = GpxUiHelper.getDescription(getMyApplication(), currentTrack.getGpxFile(), null, true);
|
||||
int startindex = description.indexOf(">");
|
||||
int endindex = description.indexOf("</font>");
|
||||
String distance = description.substring(startindex + 1, endindex);
|
||||
String points = String.valueOf(currentTrack.getGpxFile().points.size());
|
||||
|
||||
((TextView) view.findViewById(R.id.points_count)).setText(points);
|
||||
((TextView)view.findViewById(R.id.distance)).setText(distance);
|
||||
tracks.addView(view);
|
||||
}
|
||||
|
||||
for (String filename : list) {
|
||||
final File f = new File(dir, filename);
|
||||
final GPXUtilities.GPXFile res = GPXUtilities.loadGPXFile(getMyApplication(), f);
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.osmand.plus.ContextMenuAdapter;
|
|||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||
import net.osmand.plus.NavigationService;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndTaskManager;
|
||||
import net.osmand.plus.OsmAndTaskManager.OsmAndTaskRunnable;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
|
@ -256,29 +257,11 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
|
|||
int which = holder[0];
|
||||
int item = items.get(which);
|
||||
if(item == R.string.save_current_track){
|
||||
app.getTaskManager().runInBackground(new OsmAndTaskRunnable<Void, Void, Void>() {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
isSaving = true;
|
||||
try {
|
||||
SavingTrackHelper helper = app.getSavingTrackHelper();
|
||||
helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
|
||||
helper.close();
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}, (Void) null);
|
||||
saveCurrentTrack();
|
||||
} else if(item == R.string.gpx_monitoring_start) {
|
||||
startGPXMonitoring(map);
|
||||
} else if(item == R.string.gpx_monitoring_stop) {
|
||||
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false);
|
||||
if (app.getNavigationService() != null) {
|
||||
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_GPX);
|
||||
}
|
||||
stopRecording();
|
||||
} else if(item == R.string.gpx_start_new_segment) {
|
||||
app.getSavingTrackHelper().startNewSegment();
|
||||
} else if(item == R.string.live_monitoring_stop) {
|
||||
|
@ -313,6 +296,32 @@ public class OsmandMonitoringPlugin extends OsmandPlugin implements MonitoringIn
|
|||
}
|
||||
}
|
||||
|
||||
public void saveCurrentTrack() {
|
||||
app.getTaskManager().runInBackground(new OsmAndTaskRunnable<Void, Void, Void>() {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
isSaving = true;
|
||||
try {
|
||||
SavingTrackHelper helper = app.getSavingTrackHelper();
|
||||
helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
|
||||
helper.close();
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}, (Void) null);
|
||||
}
|
||||
|
||||
public void stopRecording(){
|
||||
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false);
|
||||
if (app.getNavigationService() != null) {
|
||||
app.getNavigationService().stopIfNeeded(app, NavigationService.USED_BY_GPX);
|
||||
}
|
||||
}
|
||||
|
||||
private void startGPXMonitoring(MapActivity map) {
|
||||
app.getSavingTrackHelper().startNewSegment();
|
||||
final ValueHolder<Integer> vs = new ValueHolder<Integer>();
|
||||
|
|
Loading…
Reference in a new issue