Search in sources :

Example 6 with GPXTrackAnalysis

use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.

the class AvailableGPXFragment method getGpxTrackAnalysis.

@Nullable
private static GPXTrackAnalysis getGpxTrackAnalysis(GpxInfo gpxInfo, OsmandApplication app) {
    SelectedGpxFile sgpx = getSelectedGpxFile(gpxInfo, app);
    GPXTrackAnalysis analysis = null;
    if (sgpx != null) {
        analysis = sgpx.getTrackAnalysis();
    } else if (gpxInfo.currentlyRecordingTrack) {
        analysis = app.getSavingTrackHelper().getCurrentTrack().getTrackAnalysis();
    } else {
        GpxDataItem dataItem = gpxInfo.file == null ? null : app.getGpxDatabase().getItem(gpxInfo.file);
        if (dataItem != null) {
            analysis = dataItem.getAnalysis();
        }
    }
    return analysis;
}
Also used : SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) Nullable(android.support.annotation.Nullable)

Example 7 with GPXTrackAnalysis

use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.

the class AvailableGPXFragment method updateGpxInfoView.

public static void updateGpxInfoView(View v, GpxInfo child, OsmandApplication app, boolean isDashItem) {
    TextView viewName = ((TextView) v.findViewById(R.id.name));
    if (!isDashItem) {
        v.findViewById(R.id.divider_list).setVisibility(View.VISIBLE);
        v.findViewById(R.id.divider_dash).setVisibility(View.GONE);
    } else {
        v.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
        v.findViewById(R.id.divider_list).setVisibility(View.GONE);
    }
    viewName.setText(child.getName());
    // ImageView icon = (ImageView) v.findViewById(!isDashItem? R.id.icon : R.id.show_on_map);
    ImageView icon = (ImageView) v.findViewById(R.id.icon);
    icon.setVisibility(View.VISIBLE);
    icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_polygom_dark));
    if (child.isCorrupted()) {
        viewName.setTypeface(Typeface.DEFAULT, Typeface.ITALIC);
    } else {
        viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    }
    if (getSelectedGpxFile(child, app) != null) {
        icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_polygom_dark, R.color.color_distance));
    }
    GPXTrackAnalysis analysis = getGpxTrackAnalysis(child, app);
    boolean sectionRead = analysis == null;
    if (sectionRead) {
        v.findViewById(R.id.read_section).setVisibility(View.GONE);
        v.findViewById(R.id.unknown_section).setVisibility(View.VISIBLE);
        String date = "";
        String size = "";
        if (child.getSize() >= 0) {
            if (child.getSize() > 100) {
                size = formatMb.format(new Object[] { (float) child.getSize() / (1 << 10) });
            } else {
                size = child.getSize() + " kB";
            }
        }
        DateFormat df = app.getResourceManager().getDateFormat();
        long fd = child.getFileDate();
        if (fd > 0) {
            date = (df.format(new Date(fd)));
        }
        TextView sizeText = (TextView) v.findViewById(R.id.date_and_size_details);
        sizeText.setText(date + " \u2022 " + size);
    } else {
        v.findViewById(R.id.read_section).setVisibility(View.VISIBLE);
        v.findViewById(R.id.unknown_section).setVisibility(View.GONE);
        ImageView distanceI = (ImageView) v.findViewById(R.id.distance_icon);
        distanceI.setVisibility(View.VISIBLE);
        distanceI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_distance));
        ImageView pointsI = (ImageView) v.findViewById(R.id.points_icon);
        pointsI.setVisibility(View.VISIBLE);
        pointsI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_point));
        ImageView timeI = (ImageView) v.findViewById(R.id.time_icon);
        timeI.setVisibility(View.VISIBLE);
        timeI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_time));
        TextView time = (TextView) v.findViewById(R.id.time);
        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 {
        distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
        if (analysis.isTimeSpecified()) {
            // if (analysis.isTimeMoving()) {
            // time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + "");
            // } else {
            time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000), app.accessibilityEnabled()) + "");
        // }
        } else {
            time.setText("");
        }
    }
    TextView descr = ((TextView) v.findViewById(R.id.description));
    descr.setVisibility(View.GONE);
    v.findViewById(R.id.check_item).setVisibility(View.GONE);
}
Also used : DateFormat(java.text.DateFormat) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Date(java.util.Date)

Example 8 with GPXTrackAnalysis

use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.

the class ShowRouteInfoDialogFragment method buildHeader.

private void buildHeader(View headerView) {
    OsmandApplication app = getMyApplication();
    final LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
    GpxUiHelper.setupGPXChart(app, mChart, 4);
    mChart.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            listView.requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
    GPXTrackAnalysis analysis = gpx.getAnalysis(0);
    if (analysis.hasElevationData) {
        List<ILineDataSet> dataSets = new ArrayList<>();
        elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis, GPXDataSetAxisType.DISTANCE, false, true);
        if (elevationDataSet != null) {
            dataSets.add(elevationDataSet);
        }
        slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis, GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true);
        if (slopeDataSet != null) {
            dataSets.add(slopeDataSet);
        }
        LineData data = new LineData(dataSets);
        mChart.setData(data);
        mChart.setOnChartGestureListener(new OnChartGestureListener() {

            float highlightDrawX = -1;

            @Override
            public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
                if (mChart.getHighlighted() != null && mChart.getHighlighted().length > 0) {
                    highlightDrawX = mChart.getHighlighted()[0].getDrawX();
                } else {
                    highlightDrawX = -1;
                }
            }

            @Override
            public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
                gpxItem.chartMatrix = new Matrix(mChart.getViewPortHandler().getMatrixTouch());
                Highlight[] highlights = mChart.getHighlighted();
                if (highlights != null && highlights.length > 0) {
                    gpxItem.chartHighlightPos = highlights[0].getX();
                } else {
                    gpxItem.chartHighlightPos = -1;
                }
            }

            @Override
            public void onChartLongPressed(MotionEvent me) {
            }

            @Override
            public void onChartDoubleTapped(MotionEvent me) {
            }

            @Override
            public void onChartSingleTapped(MotionEvent me) {
            }

            @Override
            public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
            }

            @Override
            public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
            }

            @Override
            public void onChartTranslate(MotionEvent me, float dX, float dY) {
                if (highlightDrawX != -1) {
                    Highlight h = mChart.getHighlightByTouchPoint(highlightDrawX, 0f);
                    if (h != null) {
                        mChart.highlightValue(h);
                    }
                }
            }
        });
        mChart.setVisibility(View.VISIBLE);
    } else {
        elevationDataSet = null;
        slopeDataSet = null;
        mChart.setVisibility(View.GONE);
    }
    ((TextView) headerView.findViewById(R.id.average_text)).setText(OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app));
    String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app);
    String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app);
    ((TextView) headerView.findViewById(R.id.range_text)).setText(min + " - " + max);
    String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
    String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
    ((TextView) headerView.findViewById(R.id.descent_text)).setText(desc);
    ((TextView) headerView.findViewById(R.id.ascent_text)).setText(asc);
    ((ImageView) headerView.findViewById(R.id.average_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average));
    ((ImageView) headerView.findViewById(R.id.range_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average));
    ((ImageView) headerView.findViewById(R.id.descent_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent));
    ((ImageView) headerView.findViewById(R.id.ascent_icon)).setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent));
    headerView.findViewById(R.id.details_view).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openDetails();
        }
    });
}
Also used : Highlight(com.github.mikephil.charting.highlight.Highlight) OsmandApplication(net.osmand.plus.OsmandApplication) OnChartGestureListener(com.github.mikephil.charting.listener.OnChartGestureListener) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) ArrayList(java.util.ArrayList) ChartTouchListener(com.github.mikephil.charting.listener.ChartTouchListener) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) MotionEvent(android.view.MotionEvent) LineData(com.github.mikephil.charting.data.LineData) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) Matrix(android.graphics.Matrix) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LineChart(com.github.mikephil.charting.charts.LineChart)

Example 9 with GPXTrackAnalysis

use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.

the class SavingTrackHelper method saveDataToGpx.

/**
 * @return warnings
 */
public synchronized List<String> saveDataToGpx(File dir) {
    List<String> warnings = new ArrayList<String>();
    dir.mkdirs();
    if (dir.getParentFile().canWrite()) {
        if (dir.exists()) {
            Map<String, GPXFile> data = collectRecordedData();
            // save file
            for (final String f : data.keySet()) {
                // $NON-NLS-1$
                File fout = new File(dir, f + ".gpx");
                if (!data.get(f).isEmpty()) {
                    WptPt pt = data.get(f).findPointToShow();
                    File targetDir = dir;
                    if (ctx.getSettings().STORE_TRACKS_IN_MONTHLY_DIRECTORIES.get()) {
                        SimpleDateFormat dateDirFormat = new SimpleDateFormat("yyyy-MM");
                        String dateDirName = dateDirFormat.format(new Date(pt.time));
                        File dateDir = new File(dir, dateDirName);
                        dateDir.mkdirs();
                        if (dateDir.exists()) {
                            targetDir = dateDir;
                        }
                    }
                    // $NON-NLS-1$
                    String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time));
                    // $NON-NLS-1$
                    fout = new File(targetDir, fileName + ".gpx");
                    int ind = 1;
                    while (fout.exists()) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        fout = new File(targetDir, fileName + "_" + (++ind) + ".gpx");
                    }
                }
                String warn = GPXUtilities.writeGpxFile(fout, data.get(f), ctx);
                if (warn != null) {
                    warnings.add(warn);
                    return warnings;
                }
                GPXFile gpx = data.get(f);
                GPXTrackAnalysis analysis = gpx.getAnalysis(fout.lastModified());
                GpxDataItem item = new GpxDataItem(fout, analysis);
                ctx.getGpxDatabase().add(item);
            }
        }
    }
    SQLiteDatabase db = getWritableDatabase();
    if (db != null && warnings.isEmpty() && db.isOpen()) {
        try {
            // remove all from db
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[] { System.currentTimeMillis() });
        // delete all
        // db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
        // db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$
        } finally {
            db.close();
        }
    }
    distance = 0;
    points = 0;
    duration = 0;
    ctx.getSelectedGpxHelper().clearPoints(currentTrack.getModifiableGpxFile());
    currentTrack.getModifiableGpxFile().tracks.clear();
    currentTrack.getModifiablePointsToDisplay().clear();
    currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
    prepareCurrentTrackForRecording();
    return warnings;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) ArrayList(java.util.ArrayList) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) Date(java.util.Date) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with GPXTrackAnalysis

use of net.osmand.plus.GPXUtilities.GPXTrackAnalysis in project Osmand by osmandapp.

the class GpxSelectionHelper method processGroupTrack.

private static void processGroupTrack(OsmandApplication app, GpxDisplayGroup group) {
    List<GpxDisplayItem> list = group.getModifiableList();
    String timeSpanClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_time_span_color));
    String speedClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_speed));
    String ascClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_asc));
    String descClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_altitude_desc));
    String distanceClr = Algorithms.colorToString(ContextCompat.getColor(app, R.color.gpx_distance_color));
    final float eleThreshold = 3;
    // int t = 1;
    for (TrkSegment r : group.track.segments) {
        if (r.points.size() == 0) {
            continue;
        }
        GPXTrackAnalysis[] as;
        boolean split = true;
        if (group.splitDistance > 0) {
            List<GPXTrackAnalysis> trackSegments = r.splitByDistance(group.splitDistance);
            as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]);
        } else if (group.splitTime > 0) {
            List<GPXTrackAnalysis> trackSegments = r.splitByTime(group.splitTime);
            as = trackSegments.toArray(new GPXTrackAnalysis[trackSegments.size()]);
        } else {
            split = false;
            as = new GPXTrackAnalysis[] { GPXTrackAnalysis.segment(0, r) };
        }
        for (GPXTrackAnalysis analysis : as) {
            GpxDisplayItem item = new GpxDisplayItem();
            item.group = group;
            if (split) {
                item.splitMetric = analysis.metricEnd;
                item.secondarySplitMetric = analysis.secondaryMetricEnd;
                item.splitName = formatSplitName(analysis.metricEnd, group, app);
                item.splitName += " (" + formatSecondarySplitName(analysis.secondaryMetricEnd, group, app) + ") ";
            }
            item.description = GpxUiHelper.getDescription(app, analysis, true);
            item.analysis = analysis;
            String name = "";
            // }
            if (!group.isSplitDistance()) {
                name += GpxUiHelper.getColorValue(distanceClr, OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
            }
            if ((analysis.timeSpan > 0 || analysis.timeMoving > 0) && !group.isSplitTime()) {
                long tm = analysis.timeMoving;
                if (tm == 0) {
                    tm = analysis.timeSpan;
                }
                if (name.length() != 0)
                    name += ", ";
                name += GpxUiHelper.getColorValue(timeSpanClr, Algorithms.formatDuration((int) (tm / 1000), app.accessibilityEnabled()));
            }
            if (analysis.isSpeedSpecified()) {
                if (name.length() != 0)
                    name += ", ";
                name += GpxUiHelper.getColorValue(speedClr, OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app));
            }
            // add min/max elevation data to split track analysis to facilitate easier track/segment identification
            if (analysis.isElevationSpecified()) {
                if (name.length() != 0)
                    name += ", ";
                name += GpxUiHelper.getColorValue(descClr, OsmAndFormatter.getFormattedAlt(analysis.minElevation, app));
                name += " - ";
                name += GpxUiHelper.getColorValue(ascClr, OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app));
            }
            if (analysis.isElevationSpecified() && (analysis.diffElevationUp > eleThreshold || analysis.diffElevationDown > eleThreshold)) {
                if (name.length() != 0)
                    name += ", ";
                if (analysis.diffElevationDown > eleThreshold) {
                    name += GpxUiHelper.getColorValue(descClr, " \u2193 " + OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app));
                }
                if (analysis.diffElevationUp > eleThreshold) {
                    name += GpxUiHelper.getColorValue(ascClr, " \u2191 " + OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app));
                }
            }
            item.name = name;
            item.locationStart = analysis.locationStart;
            item.locationEnd = analysis.locationEnd;
            list.add(item);
        }
    }
}
Also used : GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) ArrayList(java.util.ArrayList) List(java.util.List) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment)

Aggregations

GPXTrackAnalysis (net.osmand.plus.GPXUtilities.GPXTrackAnalysis)11 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 ArrayList (java.util.ArrayList)4 File (java.io.File)3 Date (java.util.Date)3 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)3 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)3 Matrix (android.graphics.Matrix)2 PopupMenu (android.support.v7.widget.PopupMenu)2 MenuItem (android.view.MenuItem)2 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2 LineChart (com.github.mikephil.charting.charts.LineChart)2 LineData (com.github.mikephil.charting.data.LineData)2 Highlight (com.github.mikephil.charting.highlight.Highlight)2 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)2 OnChartGestureListener (com.github.mikephil.charting.listener.OnChartGestureListener)2 DateFormat (java.text.DateFormat)2 GpxDataItem (net.osmand.plus.GPXDatabase.GpxDataItem)2