diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java index 663c9ea384..54464afc32 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutePlannerFrontEnd.java @@ -549,8 +549,10 @@ public class RoutePlannerFrontEnd { if (start != null && start.pnt == null) { gctx.routePointsSearched++; RouteSegmentPoint rsp = findRouteSegment(start.loc.getLatitude(), start.loc.getLongitude(), gctx.ctx, null, false); - if (MapUtils.getDistance(rsp.getPreciseLatLon(), start.loc) < distThreshold) { - start.pnt = rsp; + if (rsp != null) { + if (MapUtils.getDistance(rsp.getPreciseLatLon(), start.loc) < distThreshold) { + start.pnt = rsp; + } } } if (start != null && start.pnt != null) { diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index 2aad93fd77..089de43fcd 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -328,7 +328,7 @@ public class RouteSegmentResult implements StringExternalizable for (int i = 0; i < length; i++) { Location location = resources.getLocation(index); if (location == null) { - break; + continue; } double dist = 0; if (prevLocation != null) { diff --git a/OsmAnd/res/layout/follow_track_options.xml b/OsmAnd/res/layout/follow_track_options.xml index 69f0c467c3..123a7699e9 100644 --- a/OsmAnd/res/layout/follow_track_options.xml +++ b/OsmAnd/res/layout/follow_track_options.xml @@ -18,7 +18,7 @@ android:id="@+id/route_menu_top_shadow_all" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/card_and_list_background_basic" + android:background="?attr/bg_color" android:minHeight="@dimen/bottom_sheet_title_height" android:orientation="vertical"> diff --git a/OsmAnd/res/layout/import_track_card.xml b/OsmAnd/res/layout/import_track_card.xml index 3f3ccf7d64..24ead3b9a6 100644 --- a/OsmAnd/res/layout/import_track_card.xml +++ b/OsmAnd/res/layout/import_track_card.xml @@ -4,7 +4,7 @@ android:id="@+id/import_track_card" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/card_and_list_background_basic" + android:background="?attr/bg_color" android:orientation="vertical"> diff --git a/OsmAnd/res/layout/track_appearance.xml b/OsmAnd/res/layout/track_appearance.xml index 0be92d2bb0..ca9b03d589 100644 --- a/OsmAnd/res/layout/track_appearance.xml +++ b/OsmAnd/res/layout/track_appearance.xml @@ -18,7 +18,7 @@ android:id="@+id/route_menu_top_shadow_all" android:layout_width="match_parent" android:layout_height="wrap_content" - android:background="?attr/card_and_list_background_basic" + android:background="?attr/bg_color" android:minHeight="@dimen/bottom_sheet_title_height" android:orientation="vertical" android:paddingLeft="@dimen/content_padding" diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 35f24529e1..e52dbdfd56 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -551,11 +551,11 @@ @null - - diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index e1436bb400..06ea4dbef9 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -47,10 +47,12 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.SingleTapConfirm; +import net.osmand.plus.views.layers.MapControlsLayer; import static net.osmand.plus.mapcontextmenu.MapContextMenuFragment.CURRENT_Y_UNDEFINED; -public abstract class ContextMenuFragment extends BaseOsmAndFragment { +public abstract class ContextMenuFragment extends BaseOsmAndFragment + implements MapControlsLayer.MapControlsThemeInfoProvider { public static class MenuState { public static final int HEADER_ONLY = 1; @@ -174,10 +176,19 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { return topView; } + @Override + public boolean isNightModeForMapControls() { + return nightMode; + } + public boolean isNightMode() { return nightMode; } + protected String getThemeInfoProviderTag() { + return null; + } + public void updateNightMode() { OsmandApplication app = getMyApplication(); if (app != null) { @@ -597,6 +608,10 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { if (!wasDrawerDisabled) { mapActivity.disableDrawer(); } + String tag = getThemeInfoProviderTag(); + if (tag != null) { + mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(tag); + } } } @@ -611,8 +626,14 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { } } MapActivity mapActivity = getMapActivity(); - if (!wasDrawerDisabled && mapActivity != null) { - mapActivity.enableDrawer(); + if (mapActivity != null) { + if (!wasDrawerDisabled) { + mapActivity.enableDrawer(); + } + String tag = getThemeInfoProviderTag(); + if (tag != null) { + mapActivity.getMapLayers().getMapControlsLayer().removeThemeInfoProviderTag(tag); + } } } diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index ef5d5790c9..7625e5de20 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -3,7 +3,9 @@ package net.osmand.plus.base; import android.app.Activity; import android.app.Dialog; import android.content.Context; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.os.Build; import android.os.Bundle; import android.view.ContextThemeWrapper; @@ -207,12 +209,12 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra // 8dp is the shadow height boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(activity, 8); if (AndroidUiHelper.isOrientationPortrait(activity)) { - mainView.setBackgroundResource(showTopShadow ? getPortraitBgResId() : getBgColorId()); + AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity)); if (!showTopShadow) { mainView.setPadding(0, 0, 0, 0); } } else { - mainView.setBackgroundResource(showTopShadow ? getLandscapeTopsidesBgResId() : getLandscapeSidesBgResId()); + AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity)); } } }); @@ -304,19 +306,27 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light; } - @DrawableRes - protected int getPortraitBgResId() { - return nightMode ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_menu_light; + protected Drawable getColoredBg(@NonNull Context ctx) { + int bgColor = ContextCompat.getColor(ctx, getBgColorId()); + return new ColorDrawable(bgColor); } - @DrawableRes - protected int getLandscapeTopsidesBgResId() { - return nightMode ? R.drawable.bg_bottom_sheet_topsides_landscape_dark : R.drawable.bg_bottom_sheet_topsides_landscape_light; + protected Drawable getPortraitBg(@NonNull Context ctx) { + return createBackgroundDrawable(ctx, R.drawable.bg_contextmenu_shadow_top_light); } - @DrawableRes - protected int getLandscapeSidesBgResId() { - return nightMode ? R.drawable.bg_bottom_sheet_sides_landscape_dark : R.drawable.bg_bottom_sheet_sides_landscape_light; + protected Drawable getLandscapeTopsidesBg(@NonNull Context ctx) { + return createBackgroundDrawable(ctx, R.drawable.bg_shadow_bottomsheet_topsides); + } + + protected Drawable getLandscapeSidesBg(@NonNull Context ctx) { + return createBackgroundDrawable(ctx, R.drawable.bg_shadow_bottomsheet_sides); + } + + private LayerDrawable createBackgroundDrawable(@NonNull Context ctx, @DrawableRes int shadowDrawableResId) { + Drawable shadowDrawable = ContextCompat.getDrawable(ctx, shadowDrawableResId); + Drawable[] layers = new Drawable[]{shadowDrawable, getColoredBg(ctx)}; + return new LayerDrawable(layers); } protected boolean isNightMode(@NonNull OsmandApplication app) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java index 2b8f7a07f5..fe3f6d5580 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/AddWaypointBottomSheetDialogFragment.java @@ -140,26 +140,6 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF return getIcon(id, nightMode ? R.color.ctx_menu_direction_color_dark : R.color.map_widget_blue); } - @Override - protected int getBgColorId() { - return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light; - } - - @Override - protected int getPortraitBgResId() { - return nightMode ? R.drawable.bg_additional_menu_dark : R.drawable.bg_bottom_menu_light; - } - - @Override - protected int getLandscapeTopsidesBgResId() { - return nightMode ? R.drawable.bg_additional_menu_topsides_dark : R.drawable.bg_bottom_sheet_topsides_landscape_light; - } - - @Override - protected int getLandscapeSidesBgResId() { - return nightMode ? R.drawable.bg_additional_menu_sides_dark : R.drawable.bg_bottom_sheet_sides_landscape_light; - } - private Drawable getBackgroundIcon(@DrawableRes int resId) { return getIcon(resId, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxTrackAdapter.java b/OsmAnd/src/net/osmand/plus/helpers/GpxTrackAdapter.java index 01caa18083..00bb1e218b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxTrackAdapter.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxTrackAdapter.java @@ -34,14 +34,17 @@ public class GpxTrackAdapter extends RecyclerView.Adapter gpxInfoList; - private boolean showCurrentGpx; private OnItemClickListener onItemClickListener; - public GpxTrackAdapter(Context ctx, List gpxInfoList, boolean showCurrentGpx) { + private boolean showFolderName; + private boolean showCurrentGpx; + + public GpxTrackAdapter(Context ctx, List gpxInfoList, boolean showCurrentGpx, boolean showFolderName) { app = (OsmandApplication) ctx.getApplicationContext(); themedInflater = UiUtilities.getInflater(ctx, app.getDaynightHelper().isNightModeForMapControls()); iconsCache = app.getUIUtilities(); this.gpxInfoList = gpxInfoList; + this.showFolderName = showFolderName; this.showCurrentGpx = showCurrentGpx; } @@ -57,6 +60,10 @@ public class GpxTrackAdapter extends RecyclerView.Adapter segments = new ArrayList<>(); for (RouteSegmentResult seg : rp1.routeToTarget) { segments.add(seg); - if (seg.isForwardDirection()) { - for (int ik = seg.getStartPointIndex(); ik <= seg.getEndPointIndex(); ik++) { - LatLon l = seg.getPoint(ik); - WptPt pt = new WptPt(); - pt.lat = l.getLatitude(); - pt.lon = l.getLongitude(); - points.add(pt); - } - } else { - for (int ik = seg.getEndPointIndex(); ik >= seg.getStartPointIndex(); ik--) { - LatLon l = seg.getPoint(ik); - WptPt pt = new WptPt(); - pt.lat = l.getLatitude(); - pt.lon = l.getLongitude(); - points.add(pt); + int ind = seg.getStartPointIndex(); + boolean plus = seg.isForwardDirection(); + float[] pf = seg.getObject().calculateHeightArray(); + while (ind != seg.getEndPointIndex()) { + LatLon l = seg.getPoint(ind); + WptPt pt = new WptPt(); + if (pf != null && pf.length > ind * 2 + 1) { + pt.ele = pf[ind * 2 + 1]; + } + pt.lat = l.getLatitude(); + pt.lon = l.getLongitude(); + points.add(pt); + ind = plus ? ind + 1 : ind - 1; } } roadSegmentData.put(pair, new RoadSegmentData(appMode, pair.first, pair.second, points, segments)); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index e2e4d79531..8c6693a8b6 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -78,6 +78,7 @@ import net.osmand.plus.measurementtool.command.ReversePointsCommand; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; +import net.osmand.plus.views.layers.MapControlsLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; @@ -107,7 +108,7 @@ import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCo public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener, - SaveAsNewTrackFragmentListener { + SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider { public static final String TAG = MeasurementToolFragment.class.getSimpleName(); public static final String TAPS_DISABLED_KEY = "taps_disabled_key"; @@ -137,6 +138,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route private boolean pointsListOpened; private boolean planRouteMode = false; private boolean directionMode = false; + private boolean approximationApplied = false; private boolean portrait; private boolean nightMode; private int cachedMapPosition; @@ -317,9 +319,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route mainView.findViewById(R.id.options_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { + boolean trackSnappedToRoad = editingCtx.isTrackSnappedToRoad() || editingCtx.isNewData() || approximationApplied; OptionsBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), MeasurementToolFragment.this, - editingCtx.isTrackSnappedToRoad() || editingCtx.isNewData(), + trackSnappedToRoad, editingCtx.getAppMode().getStringKey() ); } @@ -529,6 +532,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route super.onResume(); MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { + mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(TAG); mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden(); cachedMapPosition = mapActivity.getMapView().getMapPosition(); setDefaultMapPosition(); @@ -539,6 +543,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onPause() { super.onPause(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapLayers().getMapControlsLayer().removeThemeInfoProviderTag(TAG); + } setMapPosition(cachedMapPosition); } @@ -1119,7 +1127,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route final ApplicationMode appMode = editingCtx.getAppMode(); if (mapActivity != null) { Drawable icon; - if (editingCtx.isTrackSnappedToRoad() || editingCtx.isNewData()) { + if (editingCtx.isTrackSnappedToRoad() || editingCtx.isNewData() || approximationApplied) { if (appMode == MeasurementEditingContext.DEFAULT_APP_MODE) { icon = getActiveIcon(R.drawable.ic_action_split_interval); } else { @@ -1954,12 +1962,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route setupDoneButton(view); View shadow = view.getShadowView(); if (shadow != null) { - shadow.setVisibility(View.GONE); + AndroidUiHelper.updateVisibility(shadow, false); } } private void setupDoneButton(TopToolbarView view) { TextView done = view.getSaveView(); + AndroidUiHelper.updateVisibility(done, isVisible()); + Context ctx = done.getContext(); done.setAllCaps(false); ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) done.getLayoutParams(); @@ -1996,8 +2006,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route @Override public void onApplyGpxApproximation() { + approximationApplied = true; exitApproximationMode(); doAddOrMovePointCommonStuff(); + updateSnapToRoadControls(); if (directionMode) { directionMode = false; MapActivity mapActivity = getMapActivity(); @@ -2052,4 +2064,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route AndroidUiHelper.setVisibility(mapActivity, View.VISIBLE, R.id.map_ruler_container); } } + + public boolean isNightModeForMapControls() { + return nightMode; + } } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index fdb8dc8887..23a69002f8 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -182,13 +182,6 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL if (inMeasurementMode) { lineAttrs.updatePaints(view.getApplication(), settings, tb); - TrkSegment before = editingCtx.getBeforeTrkSegmentLine(); - new Renderable.StandardTrack(new ArrayList<>(before.points), 17.2). - drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb); - - TrkSegment after = editingCtx.getAfterTrkSegmentLine(); - new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2). - drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb); if (editingCtx.isInApproximationMode()) { List originalTrackPointList = editingCtx.getOriginalTrackPointList(); if (originalTrackPointList != null) { @@ -198,6 +191,15 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL drawSegment(view.getZoom(), lineAttrs.customColorPaint, canvas, tb); } } + + TrkSegment before = editingCtx.getBeforeTrkSegmentLine(); + new Renderable.StandardTrack(new ArrayList<>(before.points), 17.2). + drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb); + + TrkSegment after = editingCtx.getAfterTrkSegmentLine(); + new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2). + drawSegment(view.getZoom(), lineAttrs.paint, canvas, tb); + drawPoints(canvas, tb); } } @@ -206,7 +208,9 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { if (inMeasurementMode) { lineAttrs.updatePaints(view.getApplication(), settings, tb); - drawBeforeAfterPath(canvas, tb); + if (!editingCtx.isInApproximationMode()) { + drawBeforeAfterPath(canvas, tb); + } if (editingCtx.getSelectedPointPosition() == -1) { drawCenterIcon(canvas, tb, settings.isNightMode()); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 40877bf8dc..07c447f3d1 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -68,6 +68,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial if (app == null) { return; } + + int highlightColorId = nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light; if (savedInstanceState != null) { showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_KEY); simplifiedTrack = savedInstanceState.getBoolean(SIMPLIFIED_TRACK_KEY); @@ -85,7 +87,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial View editNameView = View.inflate(UiUtilities.getThemedContext(app, nightMode), R.layout.track_name_edit_text, null); nameTextBox = editNameView.findViewById(R.id.name_text_box); - nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg); + nameTextBox.setBoxBackgroundColorResource(highlightColorId); nameTextBox.setHint(app.getString(R.string.ltr_or_rtl_combine_via_colon, app.getString(R.string.shared_string_file_name), "").trim()); ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat @@ -190,14 +192,16 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline); if (background != null) { - int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode), - R.attr.activity_background_color); + int highlightColor = ContextCompat.getColor(app,nightMode ? + R.color.list_background_color_dark : R.color.activity_background_color_light); + int strokedColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode), + R.attr.stroked_buttons_and_links_outline); background = (GradientDrawable) background.mutate(); if (checked) { background.setStroke(0, Color.TRANSPARENT); - background.setColor(backgroundColor); + background.setColor(highlightColor); } else { - background.setStroke(app.getResources().getDimensionPixelSize(R.dimen.map_button_stroke), backgroundColor); + background.setStroke(app.getResources().getDimensionPixelSize(R.dimen.map_button_stroke), strokedColor); } } return background; @@ -328,6 +332,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial return false; } + @Override + protected int getBgColorId() { + return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light; + } + public interface SaveAsNewTrackFragmentListener { void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java index c82bc1e9d5..2bb0c2e7c5 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java @@ -64,6 +64,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment { private Map> gpxInfoMap; private Mode fragmentMode; private String selectedFolder; + private String allFilesFolder; public void setFragmentMode(Mode fragmentMode) { this.fragmentMode = fragmentMode; @@ -91,7 +92,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment { final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); collectDirs(gpxDir, dirs); List dirItems = new ArrayList<>(); - String allFilesFolder = context.getString(R.string.shared_string_all); + allFilesFolder = context.getString(R.string.shared_string_all); if (savedInstanceState == null) { selectedFolder = allFilesFolder; } @@ -116,7 +117,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment { gpxList.add(gpxInfo); } - adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx()); + adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx(), showFoldersName()); adapter.setAdapterListener(new OnItemClickListener() { @Override public void onItemClick(int position) { @@ -157,11 +158,16 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment { private void updateFileList(String folderName, HorizontalSelectionAdapter folderAdapter) { List gpxInfoList = gpxInfoMap.get(folderName); + adapter.setShowFolderName(showFoldersName()); adapter.setGpxInfoList(gpxInfoList != null ? gpxInfoList : new ArrayList()); adapter.notifyDataSetChanged(); folderAdapter.notifyDataSetChanged(); } + private boolean showFoldersName() { + return allFilesFolder.equals(selectedFolder); + } + private boolean isShowCurrentGpx() { return fragmentMode == Mode.ADD_TO_TRACK; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningFragment.java index 49e1fa3d65..f6835b963a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapTrackWarningFragment.java @@ -148,7 +148,7 @@ public class SnapTrackWarningFragment extends BaseOsmAndFragment { } }); UiUtilities.setupDialogButton(nightMode, cancelButton, SECONDARY, R.string.shared_string_cancel); - UiUtilities.setupDialogButton(nightMode, applyButton, PRIMARY, R.string.shared_string_apply); + UiUtilities.setupDialogButton(nightMode, applyButton, PRIMARY, R.string.shared_string_continue); AndroidUiHelper.updateVisibility(applyButton, true); AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java b/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java index 666fe4f0a6..b81b015f32 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java @@ -128,7 +128,7 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen } }); final List gpxTopList = gpxList.subList(0, Math.min(5, gpxList.size())); - adapter = new GpxTrackAdapter(requireContext(), gpxTopList, false); + adapter = new GpxTrackAdapter(requireContext(), gpxTopList, false, true); adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() { @Override public void onItemClick(int position) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index 4f9214438e..4884fe616c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -62,6 +62,7 @@ import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.views.layers.MapControlsLayer; import org.apache.commons.logging.Log; @@ -69,7 +70,8 @@ import java.io.File; import java.util.List; -public class FollowTrackFragment extends ContextMenuScrollFragment implements CardListener, IRouteInformationListener { +public class FollowTrackFragment extends ContextMenuScrollFragment implements CardListener, + IRouteInformationListener, MapControlsLayer.MapControlsThemeInfoProvider { public static final String TAG = FollowTrackFragment.class.getName(); @@ -556,15 +558,15 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.drawable.travel_card_bg_light, R.drawable.travel_card_bg_dark); } else { topShadow.setVisibility(View.VISIBLE); - AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); - AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); + AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); + AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); } } } private void setupButtons(View view) { View buttonsContainer = view.findViewById(R.id.buttons_container); - buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg)); + buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color)); View cancelButton = view.findViewById(R.id.dismiss_button); cancelButton.setOnClickListener(new View.OnClickListener() { @@ -639,4 +641,9 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca public void routeWasFinished() { } + + @Override + protected String getThemeInfoProviderTag() { + return TAG; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index f3576af790..f0216f1c9d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1633,7 +1633,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener String via = generateViaDescription(); GPXRouteParamsBuilder routeParamsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); if (routeParamsBuilder != null) { - String fileName = new File(routeParamsBuilder.getFile().path).getName(); + GPXFile gpxFile = routeParamsBuilder.getFile(); + String fileName = null; + if (!Algorithms.isEmpty(gpxFile.path)) { + fileName = new File(gpxFile.path).getName(); + } else if (!Algorithms.isEmpty(gpxFile.tracks)) { + fileName = gpxFile.tracks.get(0).name; + } + if (Algorithms.isEmpty(fileName)) { + fileName = app.getString(R.string.shared_string_gpx_track); + } title.setText(GpxUiHelper.getGpxTitle(fileName)); description.setText(R.string.follow_track); buttonDescription.setText(R.string.shared_string_add); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java index 78633b080e..e8ac9e448e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/ImportTrackCard.java @@ -29,7 +29,8 @@ public class ImportTrackCard extends BaseCard { @Override protected void updateContent() { - int color = ContextCompat.getColor(app, R.color.preference_category_title); + int color = ContextCompat.getColor(app, nightMode ? + R.color.active_color_primary_dark : R.color.active_color_primary_light); Typeface typeface = FontCache.getRobotoMedium(app); String importTrack = app.getString(R.string.plan_route_import_track); SpannableString spannable = UiUtilities.createCustomFontSpannable(typeface, importTrack, importTrack, importTrack); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java index 3357e4f2fa..94770e0135 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksToFollowCard.java @@ -23,6 +23,8 @@ public class TracksToFollowCard extends BaseCard { private List gpxInfoList; private String selectedCategory; + private String defaultCategory; + private String visibleCategory; private GpxTrackAdapter tracksAdapter; @@ -30,6 +32,8 @@ public class TracksToFollowCard extends BaseCard { super(mapActivity); this.gpxInfoList = gpxInfoList; this.selectedCategory = selectedCategory; + defaultCategory = app.getString(R.string.shared_string_all); + visibleCategory = app.getString(R.string.shared_string_visible); gpxInfoCategories = getGpxInfoCategories(); } @@ -62,7 +66,7 @@ public class TracksToFollowCard extends BaseCard { filesRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); filesRecyclerView.setNestedScrollingEnabled(false); - tracksAdapter = new GpxTrackAdapter(view.getContext(), gpxInfoList, false); + tracksAdapter = new GpxTrackAdapter(view.getContext(), gpxInfoList, false, showFoldersName()); tracksAdapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() { @Override public void onItemClick(int position) { @@ -88,6 +92,7 @@ public class TracksToFollowCard extends BaseCard { public void onItemSelected(String item) { selectedCategory = item; List items = gpxInfoCategories.get(item); + tracksAdapter.setShowFolderName(showFoldersName()); tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList()); tracksAdapter.notifyDataSetChanged(); @@ -101,17 +106,19 @@ public class TracksToFollowCard extends BaseCard { selectionAdapter.notifyDataSetChanged(); } + private boolean showFoldersName() { + return defaultCategory.equals(selectedCategory) || visibleCategory.equals(selectedCategory); + } + private Map> getGpxInfoCategories() { - String all = app.getString(R.string.shared_string_all); - String visible = app.getString(R.string.shared_string_visible); Map> gpxInfoCategories = new LinkedHashMap<>(); - gpxInfoCategories.put(visible, new ArrayList()); - gpxInfoCategories.put(all, new ArrayList()); + gpxInfoCategories.put(visibleCategory, new ArrayList()); + gpxInfoCategories.put(defaultCategory, new ArrayList()); for (GPXInfo info : gpxInfoList) { if (info.isSelected()) { - addGpxInfoCategory(gpxInfoCategories, info, visible); + addGpxInfoCategory(gpxInfoCategories, info, visibleCategory); } if (!Algorithms.isEmpty(info.getFileName())) { File file = new File(info.getFileName()); @@ -120,7 +127,7 @@ public class TracksToFollowCard extends BaseCard { addGpxInfoCategory(gpxInfoCategories, info, dirName); } } - addGpxInfoCategory(gpxInfoCategories, info, all); + addGpxInfoCategory(gpxInfoCategories, info, defaultCategory); } return gpxInfoCategories; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 0dbbbb931b..df6a6eaafa 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -337,13 +337,13 @@ public class RouteCalculationResult { tunnelAlarm = null; } while (true) { + if (i == s.getEndPointIndex() && routeInd != list.size() - 1) { + break; + } Location n = new Location(""); //$NON-NLS-1$ LatLon point = s.getPoint(i); n.setLatitude(point.getLatitude()); n.setLongitude(point.getLongitude()); - if (i == s.getEndPointIndex() && routeInd != list.size() - 1) { - break; - } if (vls != null && i * 2 + 1 < vls.length) { float h = vls[2 * i + 1]; n.setAltitude(h); @@ -356,10 +356,21 @@ public class RouteCalculationResult { } lastHeight = h; } + // FIXME: investigate gpx file + if (s.getObject().getPoint31XTile(i) == 0 && s.getObject().getPoint31YTile(i) == 0) { + if (locations.size() > 0) { + Location prev = locations.get(locations.size() - 1); + n.setLatitude(prev.getLatitude()); + n.setLongitude(prev.getLongitude()); + if (prev.hasAltitude()) { + n.setAltitude(prev.getAltitude()); + } + } + } locations.add(n); attachAlarmInfo(alarms, s, i, locations.size()); segmentsToPopulate.add(s); - if (i == s.getEndPointIndex() ) { + if (i == s.getEndPointIndex()) { break; } if (plus) { diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java index ada5b13921..5ac7aea8e8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleParametersBottomSheet.java @@ -23,6 +23,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -196,13 +197,12 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet { return; } if (AndroidUiHelper.isOrientationPortrait(activity)) { - mainView.setBackgroundResource(showTopShadow ? getPortraitBgResId() : getBgColorId()); + AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity)); if (!showTopShadow) { mainView.setPadding(0, 0, 0, 0); } } else { - mainView.setBackgroundResource(showTopShadow - ? getLandscapeTopsidesBgResId() : getLandscapeSidesBgResId()); + AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity)); } } }; diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 53d49bd2a7..4381dd61f6 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -432,15 +432,15 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.drawable.travel_card_bg_light, R.drawable.travel_card_bg_dark); } else { topShadow.setVisibility(View.VISIBLE); - AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); - AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); + AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); + AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); } } } private void setupButtons(View view) { View buttonsContainer = view.findViewById(R.id.buttons_container); - buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg)); + buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color)); View saveButton = view.findViewById(R.id.right_bottom_button); saveButton.setOnClickListener(new View.OnClickListener() { @Override @@ -720,6 +720,11 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement } } + @Override + protected String getThemeInfoProviderTag() { + return TAG; + } + public interface OnNeedScrollListener { void onVerticalScrollNeeded(int y); } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java index 7663a4845b..21277e2426 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java @@ -28,6 +28,8 @@ import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import androidx.core.view.ViewPropertyAnimatorCompat; import androidx.core.view.ViewPropertyAnimatorListener; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import com.google.android.material.slider.Slider; @@ -69,8 +71,10 @@ import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.corenative.NativeCoreContext; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import gnu.trove.list.array.TIntArrayList; @@ -133,6 +137,7 @@ public class MapControlsLayer extends OsmandMapLayer { private boolean forceShowCompass; private LatLon requestedLatLon; private long compassPressed; + private Set themeInfoProviderTags = new HashSet<>(); public MapControlsLayer(MapActivity activity) { this.mapActivity = activity; @@ -836,7 +841,7 @@ public class MapControlsLayer extends OsmandMapLayer { } private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings drawSettings) { - boolean isNight = drawSettings != null && drawSettings.isNightMode(); + boolean isNight = isNightModeForMapControls(drawSettings); boolean portrait = isPotrait(); // int shadw = isNight ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night) : // mapActivity.getResources().getColor(R.color.widgettext_shadow_day); @@ -916,6 +921,25 @@ public class MapControlsLayer extends OsmandMapLayer { } } + private boolean isNightModeForMapControls(DrawSettings drawSettings) { + MapControlsThemeInfoProvider themeInfoProvider = getThemeInfoProvider(); + if (themeInfoProvider != null) { + return themeInfoProvider.isNightModeForMapControls(); + } + return drawSettings != null && drawSettings.isNightMode(); + } + + private MapControlsThemeInfoProvider getThemeInfoProvider() { + FragmentManager fm = mapActivity.getSupportFragmentManager(); + for (String tag : themeInfoProviderTags) { + Fragment f = fm.findFragmentByTag(tag); + if (f instanceof MapControlsThemeInfoProvider) { + return (MapControlsThemeInfoProvider) f; + } + } + return null; + } + public void updateCompass(boolean isNight) { float mapRotate = mapActivity.getMapView().getRotate(); boolean showCompass = shouldShowCompass(); @@ -1419,4 +1443,16 @@ public class MapControlsLayer extends OsmandMapLayer { } } } + + public void addThemeInfoProviderTag(String tag) { + themeInfoProviderTags.add(tag); + } + + public void removeThemeInfoProviderTag(String tag) { + themeInfoProviderTags.remove(tag); + } + + public interface MapControlsThemeInfoProvider { + boolean isNightModeForMapControls(); + } }