Fix opening gpx files

This commit is contained in:
Vitaliy 2021-01-26 15:57:23 +02:00
parent 34ecacb9fc
commit 5503a32c99
15 changed files with 150 additions and 109 deletions

View file

@ -153,12 +153,12 @@ public class GpxSelectionHelper {
return followTrackListener;
}
private static class GpxFileLoaderTask extends AsyncTask<Void, Void, GPXFile> {
public static class GpxFileLoaderTask extends AsyncTask<Void, Void, GPXFile> {
private File fileToLoad;
private CallbackWithObject<GPXFile> callback;
GpxFileLoaderTask(File fileToLoad, CallbackWithObject<GPXFile> callback) {
public GpxFileLoaderTask(File fileToLoad, CallbackWithObject<GPXFile> callback) {
this.fileToLoad = fileToLoad;
this.callback = callback;
}

View file

@ -1628,8 +1628,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
launchMapActivityMoveToTop(activity, null);
}
public static void launchMapActivityMoveToTop(Context activity, Bundle intentParams) {
launchMapActivityMoveToTop(activity, intentParams, null, null);
public static void launchMapActivityMoveToTop(Context activity, Bundle prevIntentParams) {
launchMapActivityMoveToTop(activity, prevIntentParams, null, null);
}
public static void clearPrevActivityIntent() {

View file

@ -29,7 +29,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
@ -37,6 +36,7 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms;
@ -66,7 +66,6 @@ import static net.osmand.IndexConstants.SQLITE_CHART_FILE_EXT;
import static net.osmand.IndexConstants.SQLITE_EXT;
import static net.osmand.IndexConstants.WPT_CHART_FILE_EXT;
import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import static net.osmand.plus.settings.backend.backup.SettingsHelper.REPLACE_KEY;
@ -597,7 +596,7 @@ public class ImportHelper {
private void showGpxInDetailsActivity(String gpxFilePath) {
if (!Algorithms.isEmpty(gpxFilePath)) {
openTrack(activity, new File(gpxFilePath));
TrackMenuFragment.openTrack(activity, new File(gpxFilePath), null);
}
}

View file

@ -20,6 +20,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.CollapsableView;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.views.layers.POIMapLayer;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms;
@ -29,8 +30,6 @@ import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
public class WptPtMenuBuilder extends MenuBuilder {
private final WptPt wpt;
@ -180,7 +179,7 @@ public class WptPtMenuBuilder extends MenuBuilder {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openTrack(mapActivity, new File(gpxFile.path));
TrackMenuFragment.openTrack(mapActivity, new File(gpxFile.path), null);
}
});
view.addView(button);

View file

@ -5,7 +5,6 @@ import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
@ -66,7 +65,6 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
@ -78,6 +76,8 @@ import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DMS;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.widgets.EditTextEx;
import net.osmand.util.Algorithms;
import net.osmand.util.LocationParser;
@ -92,7 +92,6 @@ import java.util.Locale;
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
import static android.content.Context.CLIPBOARD_SERVICE;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
@ -1098,7 +1097,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
.setAction(R.string.shared_string_show, new View.OnClickListener() {
@Override
public void onClick(View view) {
openTrack(app, new File(getGpx().path));
TrackMenuFragment.openTrack(app, new File(getGpx().path), null);
}
});
UiUtilities.setupSnackbar(snackbar, !lightTheme);

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapmarkers;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
@ -29,18 +28,18 @@ import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.LockableViewPager;
import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkersSortByDef;
import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnPointsSavedListener;
import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener;
import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkersSortByDef;
import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
import net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener;
import net.osmand.plus.track.TrackMenuFragment;
import java.io.File;
import java.util.ArrayList;
@ -49,7 +48,6 @@ import java.util.List;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.GROUPS_MARKERS_MENU;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.HISTORY_MARKERS_MENU;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
public class MapMarkersDialogFragment extends DialogFragment implements OnGroupSyncedListener {
@ -169,7 +167,7 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS
viewPager.setAdapter(adapter);
progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);
TextView toolbarTitle = mainView.findViewById(R.id.map_markers_toolbar_title);
bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation);
toolbarTitle.setTextColor(ContextCompat.getColor(getContext(), lightTheme ? R.color.active_buttons_and_links_text_light : R.color.text_color_primary_dark));
@ -488,7 +486,7 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS
.setAction(R.string.shared_string_show, new View.OnClickListener() {
@Override
public void onClick(View view) {
openTrack(mapActivity, new File(gpxPath));
TrackMenuFragment.openTrack(mapActivity, new File(gpxPath), null);
}
});
UiUtilities.setupSnackbar(snackbar, !lightTheme);

View file

@ -47,7 +47,6 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.ContextMenuFragment.MenuState;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -76,6 +75,7 @@ import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.views.layers.MapControlsLayer.MapControlsThemeInfoProvider;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
@ -104,7 +104,6 @@ import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCo
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.AFTER;
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.ALL;
import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCommandMode.BEFORE;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener,
@ -1915,7 +1914,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
GpxData gpxData = editingCtx.getGpxData();
GPXFile gpx = gpxData != null ? gpxData.getGpxFile() : null;
if (gpx != null) {
openTrack(mapActivity, new File(gpx.path));
TrackMenuFragment.openTrack(mapActivity, new File(gpx.path), null);
}
}
editingCtx.resetRouteSettingsListener();

View file

@ -1,7 +1,6 @@
package net.osmand.plus.measurementtool;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
@ -10,22 +9,19 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemButton;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.util.Algorithms;
import java.io.File;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
public class SavedTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = SavedTrackBottomSheetDialogFragment.class.getSimpleName();
@ -62,7 +58,7 @@ public class SavedTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFr
public void onClick(View v) {
FragmentActivity activity = getActivity();
if (activity != null && !Algorithms.isEmpty(fileName)) {
openTrack(activity, new File(fileName));
TrackMenuFragment.openTrack(activity, new File(fileName), null);
}
dismiss();
}

View file

@ -13,16 +13,14 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.IndexConstants;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.IndexConstants;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
@ -33,6 +31,9 @@ import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.TrackMenuFragment;
import java.io.File;
import java.util.ArrayList;
@ -153,7 +154,7 @@ public class DashTrackFragment extends DashBaseFragment {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AvailableGPXFragment.openTrack(getActivity(), null);
TrackMenuFragment.openTrack(getActivity(), null, null);
}
});
view.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
@ -172,7 +173,7 @@ public class DashTrackFragment extends DashBaseFragment {
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AvailableGPXFragment.openTrack(getActivity(), f);
TrackMenuFragment.openTrack(getActivity(), f, null);
}
});
ImageButton showOnMap = ((ImageButton) v.findViewById(R.id.show_on_map));

View file

@ -29,6 +29,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.util.Algorithms;
@ -167,7 +168,7 @@ public class SaveGPXBottomSheetFragment extends MenuBottomSheetDialogFragment {
}
FragmentActivity activity = getActivity();
if (openTrack && activity != null) {
AvailableGPXFragment.openTrack(activity, file);
TrackMenuFragment.openTrack(activity, file, null);
}
}
}

View file

@ -72,7 +72,6 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
@ -104,7 +103,7 @@ import java.util.Set;
import static net.osmand.plus.GpxSelectionHelper.CURRENT_TRACK;
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import static net.osmand.plus.track.TrackMenuFragment.OPEN_TRACK_MENU;
import static net.osmand.plus.track.TrackMenuFragment.openTrack;
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
import static net.osmand.util.Algorithms.formatDuration;
import static net.osmand.util.Algorithms.objectEquals;
@ -345,7 +344,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
public void onClick(View v) {
FragmentActivity activity = getActivity();
if (activity != null) {
openTrack(activity, null);
openTrack(activity, null, storeState());
}
}
});
@ -414,17 +413,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
updateCurrentTrack();
}
public static void openTrack(Context context, File file) {
Bundle bundle = new Bundle();
bundle.putBoolean(OPEN_TRACK_MENU, true);
if (file == null) {
bundle.putBoolean(TrackActivity.CURRENT_RECORDING, true);
} else {
bundle.putString(TrackActivity.TRACK_FILE_NAME, file.getAbsolutePath());
}
MapActivity.launchMapActivityMoveToTop(context, null, null, bundle);
}
public void reloadTracks() {
asyncLoader = new LoadGpxTask();
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
@ -834,7 +822,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
app.showToastMessage(R.string.file_can_not_be_moved);
}
}
public void renamedTo(File file) {
reloadTracks();
}
@ -1609,7 +1597,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
GpxInfo item = allGpxAdapter.getChild(groupPosition, childPosition);
if (!selectionMode) {
openTrack(getActivity(), item.file);
openTrack(getActivity(), item.file, storeState());
} else {
if (!selectedItems.contains(item)) {
selectedItems.add(item);

View file

@ -24,11 +24,13 @@ import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.myplaces.SegmentActionsListener;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
@ -93,38 +95,43 @@ public class OverviewCard extends BaseCard {
}
void initStatBlocks() {
GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
GPXTrackAnalysis analysis = gpxItem.analysis;
boolean joinSegments = displayHelper.isJoinSegments();
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
List<GpxDisplayGroup> groups = displayHelper.getOriginalGroups(filterTypes);
if (!Algorithms.isEmpty(groups)) {
GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(groups).get(0);
GPXTrackAnalysis analysis = gpxItem.analysis;
boolean joinSegments = displayHelper.isJoinSegments();
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
StatBlock sDistance = new StatBlock(app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app),
R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED);
StatBlock sAscent = new StatBlock(app.getString(R.string.altitude_ascent), asc,
R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null);
StatBlock sDescent = new StatBlock(app.getString(R.string.altitude_descent), desc,
R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE);
StatBlock sAvSpeed = new StatBlock(app.getString(R.string.average_speed), avg,
R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
StatBlock sMaxSpeed = new StatBlock(app.getString(R.string.max_speed), max,
R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
StatBlock sTimeSpan = new StatBlock(app.getString(R.string.shared_string_time_span),
Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()),
R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
StatBlock sDistance = new StatBlock(app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app),
R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED);
StatBlock sAscent = new StatBlock(app.getString(R.string.altitude_ascent), asc,
R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null);
StatBlock sDescent = new StatBlock(app.getString(R.string.altitude_descent), desc,
R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE);
StatBlock sAvSpeed = new StatBlock(app.getString(R.string.average_speed), avg,
R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
StatBlock sMaxSpeed = new StatBlock(app.getString(R.string.max_speed), max,
R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
StatBlock sTimeSpan = new StatBlock(app.getString(R.string.shared_string_time_span),
Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()),
R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
LinearLayoutManager llManager = new LinearLayoutManager(app);
llManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rvOverview.setLayoutManager(llManager);
rvOverview.setItemAnimator(new DefaultItemAnimator());
List<StatBlock> items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan);
final StatBlockAdapter siAdapter = new StatBlockAdapter(items);
rvOverview.setAdapter(siAdapter);
rvOverview.addItemDecoration(new HorizontalDividerDecoration(app));
LinearLayoutManager llManager = new LinearLayoutManager(app);
llManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rvOverview.setLayoutManager(llManager);
rvOverview.setItemAnimator(new DefaultItemAnimator());
List<StatBlock> items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan);
final StatBlockAdapter siAdapter = new StatBlockAdapter(items);
rvOverview.setAdapter(siAdapter);
rvOverview.addItemDecoration(new HorizontalDividerDecoration(app));
} else {
AndroidUiHelper.updateVisibility(rvOverview, false);
}
}
private void initShowButton(final int iconColorDef, final int iconColorPres) {

View file

@ -2,6 +2,8 @@ package net.osmand.plus.track;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.os.AsyncTask;
@ -22,6 +24,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
@ -32,6 +35,7 @@ import androidx.fragment.app.FragmentManager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.FileUtils;
import net.osmand.FileUtils.RenameCallback;
import net.osmand.GPXUtilities.GPXFile;
@ -42,10 +46,10 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.GpxFileLoaderTask;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
@ -56,6 +60,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityActions;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.base.ContextMenuFragment;
import net.osmand.plus.base.ContextMenuScrollFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -86,6 +91,7 @@ import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.List;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
@ -201,36 +207,42 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
@Override
public void onCreate(Bundle savedInstanceState) {//
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = requireMyApplication();
GpxDbHelper gpxDbHelper = app.getGpxDbHelper();
displayHelper = new TrackDisplayHelper(app);
updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
Bundle arguments = getArguments();
if (arguments != null) {
String gpxFilePath = arguments.getString(TRACK_FILE_NAME);
boolean currentRecording = arguments.getBoolean(CURRENT_RECORDING, false);
if (currentRecording) {
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
File file = new File(gpxFilePath);
displayHelper.setFile(file);
displayHelper.setGpxDataItem(gpxDbHelper.getItem(file));
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
}
displayHelper.setGpx(selectedGpxFile.getGpxFile());
String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
gpxTitle = GpxUiHelper.getGpxTitle(fileName);
if (!selectedGpxFile.isShowCurrentTrack()) {
File file = new File(selectedGpxFile.getGpxFile().path);
displayHelper.setFile(file);
displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
}
displayHelper.setGpx(selectedGpxFile.getGpxFile());
String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
gpxTitle = GpxUiHelper.getGpxTitle(fileName);
toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
FragmentActivity activity = requireMyActivity();
activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
public void handleOnBackPressed() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.launchPrevActivityIntent();
}
dismiss();
}
});
}
public GPXFile getGpx() {
return displayHelper.getGpx();
}
public void setSelectedGpxFile(SelectedGpxFile selectedGpxFile) {
this.selectedGpxFile = selectedGpxFile;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
@ -998,7 +1010,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override
public void gpxSavingFinished(Exception errorMessage) {
if (selectedGpxFile != null) {
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT});
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT});
selectedGpxFile.setDisplayGroups(groups, app);
selectedGpxFile.processPoints(app);
}
@ -1031,16 +1043,60 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}
}
public static boolean showInstance(@NonNull MapActivity mapActivity, String path, boolean showCurrentTrack) {
public static void openTrack(@NonNull Context context, @Nullable File file, Bundle prevIntentParams) {
Bundle bundle = new Bundle();
bundle.putBoolean(OPEN_TRACK_MENU, true);
if (file == null) {
bundle.putBoolean(TrackActivity.CURRENT_RECORDING, true);
} else {
bundle.putString(TrackActivity.TRACK_FILE_NAME, file.getAbsolutePath());
}
MapActivity.launchMapActivityMoveToTop(context, prevIntentParams, null, bundle);
}
public static void showInstance(@NonNull final MapActivity mapActivity, @Nullable String path, boolean showCurrentTrack) {
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile;
if (showCurrentTrack) {
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path);
}
if (selectedGpxFile != null) {
showInstance(mapActivity, selectedGpxFile);
} else if (!Algorithms.isEmpty(path)) {
String title = app.getString(R.string.loading_smth, "");
final ProgressDialog progress = ProgressDialog.show(mapActivity, title, app.getString(R.string.loading_data));
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
GpxFileLoaderTask gpxFileLoaderTask = new GpxFileLoaderTask(new File(path), new CallbackWithObject<GPXFile>() {
@Override
public boolean processResult(GPXFile result) {
MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false);
showInstance(mapActivity, selectedGpxFile);
}
if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
progress.dismiss();
}
return true;
}
});
gpxFileLoaderTask.execute();
}
}
public static boolean showInstance(@NonNull MapActivity mapActivity, SelectedGpxFile selectedGpxFile) {
try {
Bundle args = new Bundle();
args.putString(TRACK_FILE_NAME, path);
args.putBoolean(CURRENT_RECORDING, showCurrentTrack);
args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY);
TrackMenuFragment fragment = new TrackMenuFragment();
fragment.setArguments(args);
fragment.setRetainInstance(true);
fragment.setSelectedGpxFile(selectedGpxFile);
mapActivity.getSupportFragmentManager()
.beginTransaction()

View file

@ -22,8 +22,6 @@ import net.osmand.plus.views.layers.ContextMenuLayer;
import java.io.File;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
public class AddGpxPointBottomSheetHelper implements OnDismissListener {
private final View view;
private final TextView title;
@ -151,7 +149,7 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener {
if (fragment != null) {
fragment.show();
} else {
openTrack(mapActivity, new File(newGpxPoint.getGpx().path));
TrackMenuFragment.openTrack(mapActivity, new File(newGpxPoint.getGpx().path), null);
}
}

View file

@ -51,7 +51,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import static net.osmand.plus.myplaces.AvailableGPXFragment.openTrack;
import static net.osmand.plus.track.TrackMenuFragment.openTrack;
import static net.osmand.plus.wikipedia.WikiArticleShowImages.OFF;
@ -151,7 +151,7 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
}
TravelHelper travelHelper = getMyApplication().getTravelHelper();
File file = travelHelper.createGpxFile(article);
openTrack(activity, new File(file.getAbsolutePath()));
openTrack(activity, new File(file.getAbsolutePath()), null);
}
});