Finish tracks

This commit is contained in:
Victor Shcherb 2015-03-07 16:10:58 +01:00
parent c059a28c89
commit 5043d5b76c
11 changed files with 169 additions and 262 deletions

View file

@ -7,7 +7,7 @@
android:minHeight="@dimen/list_item_height"
android:orientation="vertical"
android:paddingLeft="@dimen/list_content_padding"
android:layout_marginTop="5dp"
android:paddingTop="10dp"
android:paddingRight="@dimen/list_content_padding" >
<LinearLayout
@ -43,7 +43,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingTop="2dp"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/dashFavNameTextSize"
tools:text="@string/lorem_ipsum" />

View file

@ -427,7 +427,7 @@ public class AppInitializer implements IProgress {
private void saveGPXTracks() {
if (app.savingTrackHelper.hasDataToSave()) {
long timeUpdated = app.savingTrackHelper.getLastTrackPointTime();
if (System.currentTimeMillis() - timeUpdated >= 45000) {
if (System.currentTimeMillis() - timeUpdated >= 1000 * 60 * 30) {
startTask(app.getString(R.string.saving_gpx_tracks), -1);
try {
warnings.addAll(app.savingTrackHelper.saveDataToGpx(app.getAppCustomization().getTracksDir()));

View file

@ -31,6 +31,7 @@ import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -482,6 +483,7 @@ public class GPXUtilities {
public String warning = null;
public String path = "";
public boolean showCurrentTrack;
public long modifiedTime = 0;
public boolean isCloudmadeRouteFile() {
return "cloudmade".equalsIgnoreCase(author);
@ -506,29 +508,6 @@ public class GPXUtilities {
}
public List<GPXTrackAnalysis> splitByDistance(int meters) {
return split(getDistanceMetric(), meters);
}
public List<GPXTrackAnalysis> splitByTime(int seconds) {
return split(getTimeSplit(), seconds);
}
public List<GPXTrackAnalysis> split(SplitMetric metric, int metricLimit) {
List<SplitSegment> splitSegments = new ArrayList<GPXUtilities.SplitSegment>();
for(int i = 0; i< tracks.size() ; i++){
Track subtrack = tracks.get(i);
for (int j = 0; j < subtrack.segments.size(); j++) {
TrkSegment segment = subtrack.segments.get(j);
splitSegment(metric, metricLimit, splitSegments, segment);
}
}
return convert(splitSegments);
}
public boolean hasRtePt() {
for(Route r : routes) {
if(r.points.size() > 0) {
@ -538,6 +517,10 @@ public class GPXUtilities {
return false;
}
public boolean hasWptPt() {
return points.size() > 0;
}
public boolean hasTrkpt() {
for(Track t : tracks) {
for (TrkSegment ts : t.segments) {
@ -617,6 +600,7 @@ public class GPXUtilities {
return points.isEmpty() && routes.isEmpty();
}
}
public static String asString(GPXFile file, OsmandApplication ctx) {

View file

@ -11,6 +11,7 @@ import net.osmand.plus.GPXUtilities.Route;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.helpers.GpxUiHelper;
@ -55,21 +56,8 @@ public class GpxSelectionHelper {
return app.getString(resId, formatArgs);
}
public List<GpxDisplayGroup> getDisplayGroups() {
public List<GpxDisplayGroup> collectDisplayGroups(GPXFile g) {
List<GpxDisplayGroup> dg = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
for(SelectedGpxFile s : selectedGPXFiles) {
if(s.displayGroups == null) {
s.displayGroups = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
GPXFile g = s.getGpxFile();
collectDisplayGroups(s.displayGroups, g);
}
dg.addAll(s.displayGroups);
}
return dg;
}
public void collectDisplayGroups(List<GpxDisplayGroup> dg, GPXFile g) {
String name = g.path;
if(g.showCurrentTrack){
name = getString(R.string.gpx_available_current_track);
@ -160,6 +148,7 @@ public class GpxSelectionHelper {
list.add(item);
}
}
return dg;
}
private static void processGroupTrack(OsmandApplication app, GpxDisplayGroup group) {
@ -357,7 +346,7 @@ public class GpxSelectionHelper {
app.getSettings().SELECTED_GPX.set(ar.toString());
}
private void selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
boolean displayed = false;
SelectedGpxFile sf ;
if(gpx != null && gpx.showCurrentTrack) {
@ -380,11 +369,13 @@ public class GpxSelectionHelper {
selectedGPXFiles.remove(sf);
}
}
return sf;
}
public void selectGpxFile(GPXFile gpx, boolean show, boolean showNavigationDialog) {
selectGpxFileImpl(gpx, show, showNavigationDialog);
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean showNavigationDialog) {
SelectedGpxFile sf = selectGpxFileImpl(gpx, show, showNavigationDialog);
saveCurrentSelections();
return sf;
}
@ -395,24 +386,37 @@ public class GpxSelectionHelper {
private GPXFile gpxFile;
private int color;
private GPXTrackAnalysis trackAnalysis;
private long modifiedTime = -1;
private List<List<WptPt>> processedPointsToDisplay = new ArrayList<List<WptPt>>();
private List<GpxDisplayGroup> displayGroups = null;
private boolean routePoints;
private List<GpxDisplayGroup> displayGroups;
public void setGpxFile(GPXFile gpxFile) {
this.gpxFile = gpxFile;
if(gpxFile.tracks.size() > 0) {
this.color = gpxFile.tracks.get(0).getColor(0);
}
trackAnalysis = gpxFile.getAnalysis(new File(gpxFile.path).lastModified());
processPoints();
}
public GPXTrackAnalysis getTrackAnalysis() {
if(modifiedTime != gpxFile.modifiedTime) {
update();
}
return trackAnalysis;
}
private void update() {
modifiedTime = gpxFile.modifiedTime;
trackAnalysis = gpxFile.getAnalysis(
Algorithms.isEmpty(gpxFile.path) ? System.currentTimeMillis() :
new File(gpxFile.path).lastModified());
displayGroups = null;
}
public void processPoints() {
update();
this.processedPointsToDisplay = gpxFile.proccessPoints();
if(this.processedPointsToDisplay.isEmpty()) {
this.processedPointsToDisplay = gpxFile.processRoutePoints();
@ -432,10 +436,6 @@ public class GpxSelectionHelper {
return processedPointsToDisplay;
}
public List<GpxDisplayGroup> getDisplayGroups() {
return displayGroups;
}
public GPXFile getGpxFile() {
return gpxFile;
}
@ -457,6 +457,21 @@ public class GpxSelectionHelper {
return color;
}
public List<GpxDisplayGroup> getDisplayGroups() {
if(modifiedTime != gpxFile.modifiedTime) {
update();
}
return displayGroups;
}
public void setDisplayGroups(List<GpxDisplayGroup> displayGroups) {
if(modifiedTime != gpxFile.modifiedTime) {
update();
}
this.displayGroups = displayGroups;
}
}
public enum GpxDisplayItemType {

View file

@ -269,7 +269,7 @@ public class EditPOIFilterActivity extends OsmandListActivity {
helper.editPoiFilter(filter);
ListView lv = EditPOIFilterActivity.this.getListView();
AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter();
la.notifyDataSetInvalidated();
la.notifyDataSetChanged();
lv.setSelectionFromTop(index, top);
}
});

View file

@ -12,6 +12,7 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXUtilities.Track;
import net.osmand.plus.GPXUtilities.TrkSegment;
import net.osmand.plus.GPXUtilities.WptPt;
@ -311,7 +312,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
lastTimeUpdated = 0;
lastPoint = null;
execWithClose(updateScript, new Object[] { 0, 0, 0, 0, 0, System.currentTimeMillis()});
addTrackPoint( null, true);
addTrackPoint( null, true, System.currentTimeMillis());
}
public void updateLocation(net.osmand.Location location) {
@ -369,10 +370,10 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
}
lastTimeUpdated = time;
WptPt pt = new GPXUtilities.WptPt(lat, lon, time, alt, speed, hdop);
addTrackPoint(pt, newSegment);
addTrackPoint(pt, newSegment, time);
}
private void addTrackPoint(WptPt pt, boolean newSegment) {
private void addTrackPoint(WptPt pt, boolean newSegment, long time) {
List<List<WptPt>> points = currentTrack.getModifiablePointsToDisplay();
Track track = currentTrack.getGpxFile().tracks.get(0);
assert track.segments.size() == points.size();
@ -389,12 +390,14 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
TrkSegment lt = track.segments.get(track.segments.size() - 1);
lt.points.add(pt);
}
currentTrack.getModifiableGpxFile().modifiedTime = time;
}
public void insertPointData(double lat, double lon, long time, String description) {
final WptPt pt = new WptPt(lat, lon, time, Double.NaN, 0, Double.NaN);
pt.name = description;
currentTrack.getModifiableGpxFile().points.add(pt);
currentTrack.getModifiableGpxFile().modifiedTime = time;
points++;
execWithClose(updatePointsScript, new Object[] { lat, lon, time, description });
}
@ -419,6 +422,9 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
currentTrack.getModifiableGpxFile().tracks.addAll(entry.getValue().tracks);
}
currentTrack.processPoints();
GPXTrackAnalysis analysis = currentTrack.getModifiableGpxFile().getAnalysis(System.currentTimeMillis());
distance = analysis.totalDistance;
points = analysis.wptPoints;
}
public boolean getIsRecording() {

View file

@ -11,6 +11,8 @@ import java.util.List;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.myplaces.TrackPointFragment;
@ -20,7 +22,6 @@ import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
@ -40,6 +41,8 @@ public class TrackActivity extends TabActivity {
private File file = null;
private GPXFile result;
ViewPager mViewPager;
private long modifiedTime = -1;
private List<GpxDisplayGroup> displayGroups;
@Override
public void onCreate(Bundle icicle) {
@ -86,10 +89,10 @@ public class TrackActivity extends TabActivity {
protected void onPostExecute(GPXFile result) {
setSupportProgressBarIndeterminateVisibility(false);
setResult(result);
setGpx(result);
((OsmandFragmentPagerAdapter) mViewPager.getAdapter()).addTab(
getTabIndicator(R.string.track_segments, TrackSegmentFragment.class));
if (isHavingTrackPoints()){
if (isHavingWayPoints()){
((OsmandFragmentPagerAdapter) mViewPager.getAdapter()).addTab(
getTabIndicator(R.string.track_points, TrackPointFragment.class));
}
@ -103,12 +106,26 @@ public class TrackActivity extends TabActivity {
}
protected void setResult(GPXFile result) {
protected void setGpx(GPXFile result) {
this.result = result;
if(file == null) {
result = getMyApplication().getSavingTrackHelper().getCurrentGpx();
}
}
public GPXFile getResult() {
return result;
public List<GpxSelectionHelper.GpxDisplayGroup> getResult() {
if (result.modifiedTime != modifiedTime) {
modifiedTime = result.modifiedTime;
GpxSelectionHelper selectedGpxHelper = ((OsmandApplication) getApplication()).getSelectedGpxHelper();
displayGroups = selectedGpxHelper.collectDisplayGroups(result);
if (file != null) {
SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(result.path);
if (sf != null && file != null && sf.getDisplayGroups() != null) {
displayGroups = sf.getDisplayGroups();
}
}
}
return displayGroups;
}
@Override
@ -153,38 +170,16 @@ public class TrackActivity extends TabActivity {
return false;
}
public List<GpxSelectionHelper.GpxDisplayGroup> getContent() {
GpxSelectionHelper selectedGpxHelper = getMyApplication().getSelectedGpxHelper();
List<GpxSelectionHelper.GpxDisplayGroup> displayGrous = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
selectedGpxHelper.collectDisplayGroups(displayGrous, getResult());
return displayGrous;
}
boolean isHavingTrackPoints(){
List<GpxSelectionHelper.GpxDisplayGroup> groups = getContent();
for (GpxSelectionHelper.GpxDisplayGroup group : groups){
GpxSelectionHelper.GpxDisplayItemType type = group.getType();
if (type == GpxSelectionHelper.GpxDisplayItemType.TRACK_POINTS &&
!group.getModifiableList().isEmpty()){
return true;
}
}
return false;
boolean isHavingWayPoints(){
return getGpx().hasWptPt();
}
boolean isHavingRoutePoints(){
List<GpxSelectionHelper.GpxDisplayGroup> groups = getContent();
for (GpxSelectionHelper.GpxDisplayGroup group : groups){
GpxSelectionHelper.GpxDisplayItemType type = group.getType();
if (type == GpxSelectionHelper.GpxDisplayItemType.TRACK_ROUTE_POINTS &&
!group.getModifiableList().isEmpty()){
return true;
return getGpx().hasRtePt();
}
public GPXFile getGpx() {
return result;
}
}
return false;
}
}

View file

@ -133,6 +133,12 @@ public class DashTrackFragment extends DashBaseFragment {
AvailableGPXFragment.createCurrentTrackView(view, app);
((TextView) view.findViewById(R.id.name)).setText(R.string.currently_recording_track);
AvailableGPXFragment.updateCurrentTrack(view, getActivity(), app);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AvailableGPXFragment.openTrack(getActivity(), null);
}
});
view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
tracks.addView(view);
startHandler(view);

View file

@ -36,7 +36,6 @@ import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.download.LocalIndexesFragment;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.ScreenOrientationHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
@ -60,8 +59,6 @@ import android.support.v7.app.ActionBarActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.SearchView;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -91,13 +88,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private LoadGpxTask asyncLoader;
private GpxIndexesAdapter allGpxAdapter;
private static MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US);
private LoadLocalIndexDescriptionTask descriptionLoader;
private ContextMenuAdapter optionsMenuAdapter;
private AsyncTask<GpxInfo, ?, ?> operationTask;
private GpxSelectionHelper selectedGpxHelper;
private SavingTrackHelper savingTrackHelper;
private OsmandApplication app;
private boolean updateEnable;
private GpxInfo currentRecording;
private boolean showOnMapMode;
@Override
public void onAttach(Activity activity) {
@ -105,9 +102,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
this.app = (OsmandApplication) getActivity().getApplication();
final Collator collator = Collator.getInstance();
collator.setStrength(Collator.SECONDARY);
currentRecording = new GpxInfo(getMyApplication().getSavingTrackHelper().getCurrentGpx(), getString(R.string.currently_recording_track));
currentRecording.currentlyRecordingTrack = true;
asyncLoader = new LoadGpxTask();
selectedGpxHelper = ((OsmandApplication) activity.getApplication()).getSelectedGpxHelper();
savingTrackHelper = ((OsmandApplication) activity.getApplication()).getSavingTrackHelper();
allGpxAdapter = new GpxIndexesAdapter(getActivity());
setAdapter(allGpxAdapter);
}
@ -120,7 +118,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (getView() != null && updateEnable) {
updateCurrentTrack(getView(), getActivity(), app);
if(selectedGpxHelper.getSelectedCurrentRecordingTrack() != null) {
allGpxAdapter.notifyDataSetInvalidated();
allGpxAdapter.notifyDataSetChanged();
}
startHandler();
}
@ -142,8 +140,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
allGpxAdapter.refreshSelected();
allGpxAdapter.notifyDataSetChanged();
}
updateCurrentTrack();
updateCurrentTrack(getView(), getActivity(), app);
updateEnable = true;
startHandler();
}
@ -157,6 +155,28 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
}
public void updateCurrentTrack() {
updateCurrentTrack(getView(), getActivity(), app);
final CheckBox checkbox = (CheckBox) getView().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);
}
});
}
}
public static void updateCurrentTrack(View v, final Activity ctx, OsmandApplication app) {
if (v == null) {
return;
@ -227,7 +247,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
public void onClick(View v) {
openTrack(getActivity(), null);
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
}
@ -403,11 +422,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private void openShowOnMapMode() {
enableSelectionMode(true);
showOnMapMode = true;
selectedItems.clear();
final Set<GpxInfo> originalSelectedItems = allGpxAdapter.getSelectedGpx();
selectedItems.addAll(originalSelectedItems);
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
enableSelectionMode(true);
@ -416,6 +437,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
it.setIcon(R.drawable.ic_action_done);
MenuItemCompat.setShowAsAction(it, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
| MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
updateCurrentTrack();
return true;
}
@ -427,6 +449,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
runSelection(false);
updateCurrentTrack();
actionMode.finish();
allGpxAdapter.refreshSelected();
allGpxAdapter.notifyDataSetChanged();
@ -441,6 +464,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
public void onDestroyActionMode(ActionMode mode) {
updateCurrentTrack();
showOnMapMode = false;
enableSelectionMode(false);
allGpxAdapter.notifyDataSetChanged();
}
@ -552,7 +577,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
private void showGpxOnMap(GpxInfo info) {
info.updateGpxInfo(getMyApplication());
info.setGpx(GPXUtilities.loadGPXFile(app, info.file));
boolean e = true;
if (info != null && info.gpx != null) {
WptPt loc = info.gpx.findPointToShow();
@ -576,10 +601,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
protected List<GpxInfo> doInBackground(Activity... params) {
List<GpxInfo> result = new ArrayList<GpxInfo>();
if (!savingTrackHelper.getCurrentGpx().isEmpty()) {
loadFile(new GpxInfo(savingTrackHelper.getCurrentGpx(),
app.getString(R.string.gpx_available_current_track)));
}
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, this);
return result;
}
@ -701,9 +722,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
SelectedGpxFile track = selectedGpxHelper.getSelectedCurrentRecordingTrack();
if (track != null && track.getGpxFile() != null) {
if (track.getGpxFile().showCurrentTrack) {
GpxInfo g = new GpxInfo(track.getGpxFile(), getString(R.string.currently_recording_track));
g.currentlyRecordingTrack = true;
originalSelectedItems.add(g);
originalSelectedItems.add(currentRecording);
}
}
for (List<GpxInfo> l : data.values()) {
@ -1046,35 +1065,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
public class LoadLocalIndexDescriptionTask extends AsyncTask<GpxInfo, GpxInfo, GpxInfo[]> {
@Override
protected GpxInfo[] doInBackground(GpxInfo... params) {
for (GpxInfo i : params) {
i.updateGpxInfo(getMyApplication());
}
return params;
}
@Override
protected void onPreExecute() {
showProgressBar();
}
@Override
protected void onProgressUpdate(GpxInfo... values) {
allGpxAdapter.notifyDataSetChanged();
}
@Override
protected void onPostExecute(GpxInfo[] result) {
hideProgressBar();
allGpxAdapter.notifyDataSetChanged();
}
}
public class DeleteGpxTask extends AsyncTask<GpxInfo, GpxInfo, String> {
@Override
@ -1128,7 +1118,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
protected String doInBackground(GpxInfo... params) {
for (GpxInfo info : params) {
if (!isCancelled()) {
info.updateGpxInfo(getMyApplication());
if(!info.currentlyRecordingTrack) {
info.setGpx(GPXUtilities.loadGPXFile(app, info.file));
}
publishProgress(info);
}
}
@ -1165,42 +1157,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
}
}
private void loadGpxAsync(GpxInfo info, boolean isSelected) {
final boolean selected = isSelected;
new AsyncTask<GpxInfo, Void, Void>() {
GpxInfo info;
@Override
protected Void doInBackground(GpxInfo... params) {
if (params == null) {
return null;
}
info = params[0];
params[0].updateGpxInfo(getMyApplication());
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
}
@Override
protected void onPreExecute() {
getActivity().setProgressBarIndeterminateVisibility(true);
}
@Override
protected void onPostExecute(Void result) {
if (getActivity() != null) {
getActivity().setProgressBarIndeterminateVisibility(false);
}
if (info.gpx != null) {
getMyApplication().getSelectedGpxHelper().selectGpxFile(info.gpx, selected, true);
allGpxAdapter.notifyDataSetChanged();
}
}
}.execute(info);
}
private class SearchFilter extends Filter {
@ -1212,7 +1168,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
results.values = raw;
results.count = 1;
} else {
String cs = constraint.toString().toLowerCase();
String cs = constraint.toString();
List<GpxInfo> res = new ArrayList<>();
for (GpxInfo r : raw) {
if (r.getName().toLowerCase().indexOf(cs) != -1) {
@ -1248,9 +1204,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
public void onDestroy() {
super.onDestroy();
if (descriptionLoader != null) {
descriptionLoader.cancel(true);
}
if (asyncLoader != null) {
asyncLoader.cancel(true);
}
@ -1296,11 +1249,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private String name = null;
private int sz = -1;
private String fileName = null;
private String description;
private boolean corrupted;
private boolean expanded;
private Spanned htmlDescription;
private GPXUtilities.GPXTrackAnalysis analysis;
public GpxInfo() {
}
@ -1339,21 +1288,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
return sz;
}
public boolean isExpanded() {
return expanded;
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
public CharSequence getDescription() {
if (description == null) {
return "";
}
return description;
}
public long getFileDate() {
if (file == null) {
return 0;
@ -1361,42 +1295,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
return file.lastModified();
}
public Spanned getHtmlDescription() {
if (htmlDescription != null) {
return htmlDescription;
}
htmlDescription = Html.fromHtml(getDescription().toString().replace("\n", "<br/>"));
return htmlDescription;
}
public GPXUtilities.GPXTrackAnalysis getAnalysis() {
return analysis;
}
public void setAnalysis(GPXUtilities.GPXTrackAnalysis analysis) {
this.analysis = analysis;
}
public void setGpx(GPXFile gpx) {
this.gpx = gpx;
}
public void updateGpxInfo(OsmandApplication app) {
if (gpx == null) {
gpx = GPXUtilities.loadGPXFile(app, file);
}
if (gpx.warning != null) {
corrupted = true;
description = gpx.warning;
analysis = null;
} else {
// 'Long-press for options' message
analysis = gpx.getAnalysis(file.lastModified());
description = GpxUiHelper.getDescription(app, analysis, true);
}
htmlDescription = null;
getHtmlDescription();
}
public String getFileName() {
if (fileName != null) {
@ -1465,30 +1367,25 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
TextView distance = (TextView) v.findViewById(R.id.distance);
TextView pointsCount = (TextView) v.findViewById(R.id.points_count);
pointsCount.setText(analysis.wptPoints + "");
if (analysis.totalDistanceMoving != 0) {
distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app));
} else {
// if (analysis.totalDistanceMoving != 0) {
// distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app));
// } else {
distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
}
// }
if (analysis.isTimeSpecified()) {
if (analysis.isTimeMoving()) {
time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + "");
} else {
// if (analysis.isTimeMoving()) {
// time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + "");
// } else {
time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000)) + "");
}
// }
} else {
time.setText("");
}
}
TextView descr = ((TextView) v.findViewById(R.id.description));
if (child.isExpanded()) {
descr.setVisibility(View.VISIBLE);
descr.setText(child.getHtmlDescription());
} else {
descr.setVisibility(View.GONE);
}
v.findViewById(R.id.check_item).setVisibility(View.GONE);
}

View file

@ -20,6 +20,7 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -90,7 +91,8 @@ public class SelectedGPXFragment extends ListFragment {
@Override
public void run() {
if (updateEnable) {
adapter.notifyDataSetInvalidated();
updateContent();
adapter.notifyDataSetChanged();
startHandler();
}
}
@ -121,14 +123,11 @@ public class SelectedGPXFragment extends ListFragment {
private GPXFile getGpx() {
return ((TrackActivity) getActivity()).getResult();
}
protected List<GpxDisplayGroup> filterGroups(GpxDisplayItemType type) {
List<GpxDisplayGroup> result = ((TrackActivity)getActivity()).getResult();
List<GpxDisplayGroup> groups = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
for(GpxDisplayGroup group : ((TrackActivity) getActivity()).getContent()) {
for (GpxDisplayGroup group : result) {
boolean add = group.getType() == type || type == null;
if (isArgumentTrue(ARG_TO_FILTER_SHORT_TRACKS)) {
Iterator<GpxDisplayItem> item = group.getModifiableList().iterator();
@ -161,6 +160,7 @@ public class SelectedGPXFragment extends ListFragment {
adapter.clear();
List<GpxSelectionHelper.GpxDisplayGroup> groups = filterGroups(filterType());
adapter.addAll(flatten(groups));
adapter.notifyDataSetChanged();
}
protected GpxDisplayItemType filterType() {
@ -276,7 +276,7 @@ public class SelectedGPXFragment extends ListFragment {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
((TrackActivity) getActivity()).getClearToolbar(false);
if (getGpx().path != null) {
if (getGpx().path != null && !getGpx().showCurrentTrack) {
MenuItem item = menu.add(R.string.share_fav).setIcon(R.drawable.ic_action_gshare_dark)
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
@ -294,6 +294,10 @@ public class SelectedGPXFragment extends ListFragment {
}
protected GPXFile getGpx() {
return ((TrackActivity)getActivity()).getGpx();
}
protected void selectSplitDistance() {
final List<GpxDisplayGroup> groups = filterGroups(GpxDisplayItemType.TRACK_SEGMENT);
if(groups.size() == 0) {
@ -343,8 +347,9 @@ public class SelectedGPXFragment extends ListFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
app.getSelectedGpxHelper().selectGpxFile(groups.get(0).getGpx(), vis.isChecked(), true);
updateSplit(groups, distanceSplit, timeSplit, sp.getSelectedItemPosition() );
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(groups.get(0).getGpx(), vis.isChecked(), true);
updateSplit(groups, distanceSplit, timeSplit, sp.getSelectedItemPosition(),
vis.isChecked() ? sf : null);
}
});
@ -353,12 +358,14 @@ public class SelectedGPXFragment extends ListFragment {
}
private void updateSplit(final List<GpxDisplayGroup> groups, final List<Double> distanceSplit,
final TIntArrayList timeSplit, final int which) {
final TIntArrayList timeSplit, final int which, final SelectedGpxFile sf) {
new AsyncTask<Void, Void, Void>() {
protected void onPostExecute(Void result) {
if(sf != null) {
sf.setDisplayGroups(filterGroups(null));
}
updateContent();
adapter.notifyDataSetChanged();
(getActivity()).setProgressBarIndeterminateVisibility(false);
}
@ -377,6 +384,7 @@ public class SelectedGPXFragment extends ListFragment {
model.splitByTime(app, timeSplit.get(which));
}
}
return null;
}
}.execute((Void)null);

View file

@ -40,9 +40,6 @@ public class SkiMapsPlugin extends OsmandPlugin {
@Override
public boolean init(final OsmandApplication app, final Activity activity) {
if(true) {
throw new IllegalStateException("Don't enable plugin!");
}
if(activity != null) {
// called from UI
previousRenderer = app.getSettings().RENDERER.get();