Search in sources :

Example 1 with TrackDrawInfo

use of net.osmand.plus.track.TrackDrawInfo in project Osmand by osmandapp.

the class TrackAppearanceFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = requireMyApplication();
    settings = app.getSettings();
    gpxDbHelper = app.getGpxDbHelper();
    if (savedInstanceState != null) {
        trackDrawInfo = new TrackDrawInfo(savedInstanceState);
        if (selectedGpxFile == null) {
            restoreSelectedGpxFile(trackDrawInfo.getFilePath(), trackDrawInfo.isCurrentRecording());
        }
        if (!trackDrawInfo.isCurrentRecording()) {
            gpxDataItem = gpxDbHelper.getItem(new File(trackDrawInfo.getFilePath()));
        }
        showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, settings.SHOW_START_FINISH_ICONS.get());
    } else {
        showStartFinishIconsInitialValue = settings.SHOW_START_FINISH_ICONS.get();
        if (selectedGpxFile.isShowCurrentTrack()) {
            trackDrawInfo = new TrackDrawInfo(app, true);
        } else {
            GpxDataItemCallback callback = new GpxDataItemCallback() {

                @Override
                public boolean isCancelled() {
                    return false;
                }

                @Override
                public void onGpxDataItemReady(GpxDataItem item) {
                    if (item != null) {
                        gpxDataItem = item;
                        trackDrawInfo.updateParams(item);
                    }
                    if (view != null) {
                        initContent();
                    }
                }
            };
            String filePath = selectedGpxFile.getGpxFile().path;
            gpxDataItem = gpxDbHelper.getItem(new File(filePath), callback);
            trackDrawInfo = new TrackDrawInfo(filePath, gpxDataItem, false);
        }
    }
    requireMyActivity().getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {

        public void handleOnBackPressed() {
            dismiss();
        }
    });
}
Also used : TrackDrawInfo(net.osmand.plus.track.TrackDrawInfo) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) GpxDataItemCallback(net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) File(java.io.File)

Aggregations

OnBackPressedCallback (androidx.activity.OnBackPressedCallback)1 File (java.io.File)1 GPXFile (net.osmand.GPXUtilities.GPXFile)1 TrackDrawInfo (net.osmand.plus.track.TrackDrawInfo)1 GpxDataItem (net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem)1 GpxDataItemCallback (net.osmand.plus.track.helpers.GpxDbHelper.GpxDataItemCallback)1 SelectedGpxFile (net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile)1