Search in sources :

Example 6 with GpxDataItem

use of net.osmand.plus.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class TrackSegmentFragment method drawTrack.

private void drawTrack(Canvas canvas, RotatedTileBox tileBox, SelectedGpxFile g) {
    GpxDataItem gpxDataItem = null;
    if (!g.isShowCurrentTrack()) {
        gpxDataItem = getGpxDataItem();
    }
    List<TrkSegment> segments = g.getPointsToDisplay();
    for (TrkSegment ts : segments) {
        int color = gpxDataItem != null ? gpxDataItem.getColor() : 0;
        if (g.isShowCurrentTrack()) {
            color = currentTrackColor;
        }
        if (color == 0) {
            color = ts.getColor(trackColor);
        }
        if (// only do once (CODE HERE NEEDS TO BE UI INSTEAD)
        ts.renders.isEmpty() && !ts.points.isEmpty()) {
            // hmmm. 0-point tracks happen, but.... how?
            if (g.isShowCurrentTrack()) {
                ts.renders.add(new Renderable.CurrentTrack(ts.points));
            } else {
                ts.renders.add(new Renderable.StandardTrack(ts.points, 17.2));
            }
        }
        paint.setColor(color == 0 ? trackColor : color);
        ts.drawRenderers(tileBox.getZoom(), paint, canvas, tileBox);
    }
}
Also used : Renderable(net.osmand.plus.views.Renderable) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) Paint(android.graphics.Paint)

Example 7 with GpxDataItem

use of net.osmand.plus.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class TrackSegmentFragment method updateHeader.

private void updateHeader() {
    imageView = (ImageView) headerView.findViewById(R.id.imageView);
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            GpxDataItem gpxDataItem = getGpxDataItem();
            GPXFile gpx = getGpx();
            WptPt pointToShow = gpx != null ? gpx.findPointToShow() : null;
            if (pointToShow != null) {
                LatLon location = new LatLon(pointToShow.getLatitude(), pointToShow.getLongitude());
                final OsmandSettings settings = app.getSettings();
                String trackName = "";
                if (gpx.showCurrentTrack) {
                    trackName = getString(R.string.shared_string_currently_recording_track);
                } else if (gpxDataItem != null) {
                    trackName = gpxDataItem.getFile().getName();
                } else {
                    trackName = gpx.path;
                }
                settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_WPT, trackName), false, getRect());
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }
    });
    final View splitColorView = headerView.findViewById(R.id.split_color_view);
    final View divider = headerView.findViewById(R.id.divider);
    final View splitIntervalView = headerView.findViewById(R.id.split_interval_view);
    final View colorView = headerView.findViewById(R.id.color_view);
    vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle);
    final ProgressBar progressBar = (ProgressBar) headerView.findViewById(R.id.mapLoadProgress);
    final boolean selected = getGpx() != null && ((getGpx().showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || (getGpx().path != null && app.getSelectedGpxHelper().getSelectedFileByPath(getGpx().path) != null));
    vis.setChecked(selected);
    vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (!isChecked) {
                selectedSplitInterval = 0;
            }
            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
            final List<GpxDisplayGroup> groups = getDisplayGroups();
            if (groups.size() > 0) {
                updateSplit(groups, vis.isChecked() ? sf : null);
                if (getGpxDataItem() != null) {
                    updateSplitInDatabase();
                }
            }
            updateSplitIntervalView(splitIntervalView);
            updateColorView(colorView);
        }
    });
    updateColorView(colorView);
    colorView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            colorListPopupWindow = new ListPopupWindow(getActivity());
            colorListPopupWindow.setAnchorView(colorView);
            colorListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            colorListPopupWindow.setModal(true);
            colorListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
            colorListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            colorListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(getActivity(), getGpx().getColor(0), GpxAppearanceAdapterType.TRACK_COLOR);
            colorListPopupWindow.setAdapter(gpxApprAdapter);
            colorListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    AppearanceListItem item = gpxApprAdapter.getItem(position);
                    if (item != null) {
                        if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
                            int clr = item.getColor();
                            if (vis.isChecked()) {
                                SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                                if (clr != 0 && sf.getModifiableGpxFile() != null) {
                                    sf.getModifiableGpxFile().setColor(clr);
                                    if (getGpxDataItem() != null) {
                                        app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                                    }
                                }
                            } else if (getGpxDataItem() != null) {
                                app.getGpxDatabase().updateColor(getGpxDataItem(), clr);
                            }
                            if (getGpx().showCurrentTrack) {
                                app.getSettings().CURRENT_TRACK_COLOR.set(clr);
                            }
                            refreshTrackBitmap();
                        }
                    }
                    colorListPopupWindow.dismiss();
                    updateColorView(colorView);
                }
            });
            colorListPopupWindow.show();
        }
    });
    boolean hasPath = getGpx() != null && (getGpx().tracks.size() > 0 || getGpx().routes.size() > 0);
    if (rotatedTileBox == null || mapBitmap == null || mapTrackBitmap == null) {
        QuadRect rect = getRect();
        if (rect.left != 0 && rect.top != 0) {
            progressBar.setVisibility(View.VISIBLE);
            double clat = rect.bottom / 2 + rect.top / 2;
            double clon = rect.left / 2 + rect.right / 2;
            WindowManager mgr = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics dm = new DisplayMetrics();
            mgr.getDefaultDisplay().getMetrics(dm);
            RotatedTileBoxBuilder boxBuilder = new RotatedTileBoxBuilder().setLocation(clat, clon).setZoom(15).density(dm.density).setPixelDimensions(dm.widthPixels, AndroidUtils.dpToPx(app, 152f), 0.5f, 0.5f);
            rotatedTileBox = boxBuilder.build();
            while (rotatedTileBox.getZoom() < 17 && rotatedTileBox.containsLatLon(rect.top, rect.left) && rotatedTileBox.containsLatLon(rect.bottom, rect.right)) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() + 1);
            }
            while (rotatedTileBox.getZoom() >= 7 && (!rotatedTileBox.containsLatLon(rect.top, rect.left) || !rotatedTileBox.containsLatLon(rect.bottom, rect.right))) {
                rotatedTileBox.setZoom(rotatedTileBox.getZoom() - 1);
            }
            final DrawSettings drawSettings = new DrawSettings(!app.getSettings().isLightContent(), true);
            final ResourceManager resourceManager = app.getResourceManager();
            final MapRenderRepositories renderer = resourceManager.getRenderer();
            if (resourceManager.updateRenderedMapNeeded(rotatedTileBox, drawSettings)) {
                resourceManager.updateRendererMap(rotatedTileBox, new AsyncLoadingThread.OnMapLoadedListener() {

                    @Override
                    public void onMapLoaded(boolean interrupted) {
                        app.runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                if (updateEnable) {
                                    mapBitmap = renderer.getBitmap();
                                    if (mapBitmap != null) {
                                        progressBar.setVisibility(View.GONE);
                                        refreshTrackBitmap();
                                    }
                                }
                            }
                        });
                    }
                });
            }
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }
    } else {
        refreshTrackBitmap();
    }
    if (hasPath) {
        if (getGpx() != null && !getGpx().showCurrentTrack && adapter.getCount() > 0) {
            prepareSplitIntervalAdapterData();
            setupSplitIntervalView(splitIntervalView);
            updateSplitIntervalView(splitIntervalView);
            splitIntervalView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    splitListPopupWindow = new ListPopupWindow(getActivity());
                    splitListPopupWindow.setAnchorView(splitIntervalView);
                    splitListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
                    splitListPopupWindow.setModal(true);
                    splitListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
                    splitListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
                    splitListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
                    splitListPopupWindow.setAdapter(new ArrayAdapter<>(getTrackActivity(), R.layout.popup_list_text_item, options));
                    splitListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            selectedSplitInterval = position;
                            SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(getGpx(), vis.isChecked(), false);
                            final List<GpxDisplayGroup> groups = getDisplayGroups();
                            if (groups.size() > 0) {
                                updateSplit(groups, vis.isChecked() ? sf : null);
                                if (getGpxDataItem() != null) {
                                    updateSplitInDatabase();
                                }
                            }
                            splitListPopupWindow.dismiss();
                            updateSplitIntervalView(splitIntervalView);
                        }
                    });
                    splitListPopupWindow.show();
                }
            });
            splitIntervalView.setVisibility(View.VISIBLE);
        } else {
            splitIntervalView.setVisibility(View.GONE);
        }
        splitColorView.setVisibility(View.VISIBLE);
        divider.setVisibility(View.VISIBLE);
    } else {
        splitColorView.setVisibility(View.GONE);
        divider.setVisibility(View.GONE);
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) QuadRect(net.osmand.data.QuadRect) DisplayMetrics(android.util.DisplayMetrics) WindowManager(android.view.WindowManager) AppearanceListItem(net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) GpxAppearanceAdapter(net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) MapRenderRepositories(net.osmand.plus.render.MapRenderRepositories) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ProgressBar(android.widget.ProgressBar) ResourceManager(net.osmand.plus.resources.ResourceManager) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OsmandSettings(net.osmand.plus.OsmandSettings) Paint(android.graphics.Paint) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) RotatedTileBoxBuilder(net.osmand.data.RotatedTileBox.RotatedTileBoxBuilder) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) PointDescription(net.osmand.data.PointDescription) AdapterView(android.widget.AdapterView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) AsyncLoadingThread(net.osmand.plus.resources.AsyncLoadingThread) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with GpxDataItem

use of net.osmand.plus.GPXDatabase.GpxDataItem 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 9 with GpxDataItem

use of net.osmand.plus.GPXDatabase.GpxDataItem 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 GpxDataItem

use of net.osmand.plus.GPXDatabase.GpxDataItem in project Osmand by osmandapp.

the class GpxSelectionHelper method processSplit.

public void processSplit() {
    List<GpxDataItem> items = app.getGpxDatabase().getItems();
    for (GpxDataItem dataItem : items) {
        if (dataItem.getSplitType() != 0) {
            SelectedGpxFile selectedGpxFile = getSelectedFileByPath(dataItem.getFile().getAbsolutePath());
            if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
                GPXFile gpxFile = selectedGpxFile.getGpxFile();
                List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
                if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) {
                    for (GpxDisplayGroup model : groups) {
                        model.noSplit(app);
                    }
                    selectedGpxFile.setDisplayGroups(groups);
                } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
                    for (GpxDisplayGroup model : groups) {
                        model.splitByDistance(app, dataItem.getSplitInterval());
                    }
                    selectedGpxFile.setDisplayGroups(groups);
                } else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
                    for (GpxDisplayGroup model : groups) {
                        model.splitByTime(app, (int) dataItem.getSplitInterval());
                    }
                    selectedGpxFile.setDisplayGroups(groups);
                }
            }
        }
    }
}
Also used : GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Aggregations

GpxDataItem (net.osmand.plus.GPXDatabase.GpxDataItem)12 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)9 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)9 File (java.io.File)7 Paint (android.graphics.Paint)5 ArrayList (java.util.ArrayList)3 ListPopupWindow (android.support.v7.widget.ListPopupWindow)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ArrayAdapter (android.widget.ArrayAdapter)2 CompoundButton (android.widget.CompoundButton)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 List (java.util.List)2 ASelectedGpxFile (net.osmand.aidl.gpx.ASelectedGpxFile)2 GPXTrackAnalysis (net.osmand.plus.GPXUtilities.GPXTrackAnalysis)2 WptPt (net.osmand.plus.GPXUtilities.WptPt)2 GpxDisplayGroup (net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup)2 OsmandSettings (net.osmand.plus.OsmandSettings)2 AppearanceListItem (net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem)2