From 138b4862af373e9d69a3e0d4307683c6eb5ad589 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 21 Jul 2020 16:19:15 +0300 Subject: [PATCH 01/59] Fix #7065 --- .../osmand/plus/quickaction/CreateEditActionDialog.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java index d82ace3da6..81476161f9 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java @@ -31,6 +31,7 @@ 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.osmedit.AddPOIAction; import java.util.List; @@ -232,6 +233,10 @@ public class CreateEditActionDialog extends DialogFragment @Override public void onClick(View view) { + if (action instanceof AddPOIAction) { + saveFirstTagWithEmptyValue(); + } + if (action.fillParams(((ViewGroup) root.findViewById(R.id.container)).getChildAt(0), (MapActivity) getActivity())) { if (quickActionRegistry.isNameUnique(action, getContext())) { @@ -272,6 +277,10 @@ public class CreateEditActionDialog extends DialogFragment Toast.makeText(getContext(), R.string.quick_action_empty_param_error, Toast.LENGTH_SHORT).show(); } } + + private void saveFirstTagWithEmptyValue() { + ((ViewGroup) root.findViewById(R.id.container)).getChildAt(0).requestFocus(); + } }); } From 3112c1e0a851038167ef2a83cbd35bb0939c4916 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 22 Jul 2020 18:45:36 +0300 Subject: [PATCH 02/59] Fix new route file extension --- .../osmand/plus/measurementtool/MeasurementToolFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index cb4492c4f4..d38453902c 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -451,7 +451,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { } else { if (newGpxData == null) { final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); - String fileName = getSuggestedName(dir); + String fileName = getSuggestedName(dir) + GPX_FILE_EXT; saveNewGpx(dir, fileName, true, SaveType.ROUTE_POINT, true); } else { addToGpx(mapActivity); From 7c7cadb9e85bdb070d115fa25616085c494f0f81 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 24 Jul 2020 00:18:17 +0300 Subject: [PATCH 03/59] Show start finish track icons by default --- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 5403c814ca..c010b2964e 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -188,7 +188,7 @@ public class GPXDatabase { private boolean showAsMarkers; private boolean joinSegments; private boolean showArrows; - private boolean showStartFinish; + private boolean showStartFinish = true; public GpxDataItem(File file, GPXTrackAnalysis analysis) { this.file = file; From f229da7582e3e76f6c54deb83050f9e46936ab03 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 24 Jul 2020 14:08:39 +0300 Subject: [PATCH 04/59] Fix track appearance icons --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 20 +++--- .../plus/track/DirectionArrowsCard.java | 5 ++ .../plus/track/TrackAppearanceFragment.java | 65 ++++++++++++++++++- .../net/osmand/plus/track/TrackWidthCard.java | 7 +- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index c60117f58c..ec5c85166e 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -41,8 +41,8 @@ import androidx.core.view.ViewCompat; import androidx.core.widget.TintableCompoundButton; import com.google.android.material.slider.RangeSlider; -import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.slider.Slider; +import com.google.android.material.snackbar.BaseTransientBottomBar; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.SnackbarContentLayout; @@ -60,7 +60,6 @@ import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; - import gnu.trove.map.hash.TLongObjectHashMap; import static net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem; @@ -135,12 +134,13 @@ public class UiUtilities { public Drawable getLayeredIcon(@DrawableRes int bgIconId, @DrawableRes int foregroundIconId, @ColorRes int bgColorId, @ColorRes int foregroundColorId) { - Drawable b = getDrawable(bgIconId, bgColorId); - Drawable f = getDrawable(foregroundIconId, foregroundColorId); - Drawable[] layers = new Drawable[2]; - layers[0] = b; - layers[1] = f; - return new LayerDrawable(layers); + Drawable background = getDrawable(bgIconId, bgColorId); + Drawable foreground = getDrawable(foregroundIconId, foregroundColorId); + return getLayeredIcon(background, foreground); + } + + public static Drawable getLayeredIcon(Drawable... icons) { + return new LayerDrawable(icons); } public Drawable getThemedIcon(@DrawableRes int id) { @@ -215,13 +215,11 @@ public class UiUtilities { @ColorInt public static int getColorWithAlpha(@ColorInt int color, float ratio) { - int newColor = 0; int alpha = Math.round(Color.alpha(color) * ratio); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); - newColor = Color.argb(alpha, r, g, b); - return newColor; + return Color.argb(alpha, r, g, b); } @ColorInt diff --git a/OsmAnd/src/net/osmand/plus/track/DirectionArrowsCard.java b/OsmAnd/src/net/osmand/plus/track/DirectionArrowsCard.java index f7ce7bacc6..0fa14c14c4 100644 --- a/OsmAnd/src/net/osmand/plus/track/DirectionArrowsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/DirectionArrowsCard.java @@ -42,6 +42,11 @@ public class DirectionArrowsCard extends BaseCard { compoundButton.setChecked(checked); trackDrawInfo.setShowArrows(checked); mapActivity.refreshMap(); + + CardListener listener = getListener(); + if (listener != null) { + listener.onCardPressed(DirectionArrowsCard.this); + } } }); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index ef578f90f2..8c70993eb7 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.track; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Build; @@ -12,7 +13,9 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; @@ -42,6 +45,8 @@ import java.util.ArrayList; import java.util.List; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; +import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; +import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH; public class TrackAppearanceFragment extends ContextMenuFragment implements CardListener { @@ -240,6 +245,10 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card if (trackWidthCard != null) { trackWidthCard.updateItems(); } + } else if (card instanceof TrackWidthCard) { + updateAppearanceIcon(); + } else if (card instanceof DirectionArrowsCard) { + updateAppearanceIcon(); } } } @@ -250,10 +259,27 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card } private void updateAppearanceIcon() { - Drawable icon = getPaintedContentIcon(R.drawable.ic_action_gpx_width_bold, trackDrawInfo.getColor()); + Drawable icon = getTrackIcon(app, trackDrawInfo.getWidth(), trackDrawInfo.isShowArrows(), trackDrawInfo.getColor()); appearanceIcon.setImageDrawable(icon); } + public Drawable getTrackIcon(OsmandApplication app, String widthAttr, boolean showArrows, @ColorInt int color) { + int widthIconId = getWidthIconId(widthAttr); + Drawable widthIcon = app.getUIUtilities().getPaintedIcon(widthIconId, color); + + int strokeIconId = getStrokeIconId(widthAttr); + int strokeColor = UiUtilities.getColorWithAlpha(Color.BLACK, 0.7f); + Drawable strokeIcon = app.getUIUtilities().getPaintedIcon(strokeIconId, strokeColor); + + Drawable arrows = null; + if (showArrows) { + int arrowsIconId = getArrowsIconId(widthAttr); + int contrastColor = UiUtilities.getContrastColor(app, color, false); + arrows = app.getUIUtilities().getPaintedIcon(arrowsIconId, contrastColor); + } + return UiUtilities.getLayeredIcon(widthIcon, strokeIcon, arrows); + } + private void updateCardsLayout() { View mainView = getMainView(); if (mainView != null) { @@ -289,7 +315,10 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card @Override public void onClick(View v) { discardChanges(); - dismiss(); + FragmentActivity activity = getActivity(); + if (activity != null) { + activity.onBackPressed(); + } } }); @@ -384,6 +413,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card cardsContainer.addView(splitIntervalCard.build(mapActivity)); DirectionArrowsCard directionArrowsCard = new DirectionArrowsCard(mapActivity, trackDrawInfo); + directionArrowsCard.setListener(this); cardsContainer.addView(directionArrowsCard.build(mapActivity)); TrackColoringCard trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo); @@ -391,6 +421,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card cardsContainer.addView(trackColoringCard.build(mapActivity)); trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo); + trackWidthCard.setListener(this); cardsContainer.addView(trackWidthCard.build(mapActivity)); } } @@ -433,4 +464,34 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card return false; } } + + public static int getWidthIconId(String widthAttr) { + if (TRACK_WIDTH_BOLD.equals(widthAttr)) { + return R.drawable.ic_action_track_line_bold_color; + } else if (TRACK_WIDTH_MEDIUM.equals(widthAttr)) { + return R.drawable.ic_action_track_line_medium_color; + } else { + return R.drawable.ic_action_track_line_thin_color; + } + } + + public static int getStrokeIconId(String widthAttr) { + if (TRACK_WIDTH_BOLD.equals(widthAttr)) { + return R.drawable.ic_action_track_line_bold_stroke; + } else if (TRACK_WIDTH_MEDIUM.equals(widthAttr)) { + return R.drawable.ic_action_track_line_medium_stroke; + } else { + return R.drawable.ic_action_track_line_thin_stroke; + } + } + + public static int getArrowsIconId(String widthAttr) { + if (TRACK_WIDTH_BOLD.equals(widthAttr)) { + return R.drawable.ic_action_track_line_bold_direction; + } else if (TRACK_WIDTH_MEDIUM.equals(widthAttr)) { + return R.drawable.ic_action_track_line_medium_direction; + } else { + return R.drawable.ic_action_track_line_thin_direction; + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java index 65ccad6b73..7dc668e3d6 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java @@ -195,6 +195,11 @@ public class TrackWidthCard extends BaseCard { updateHeader(); updateCustomWidthSlider(); + + CardListener listener = getListener(); + if (listener != null) { + listener.onCardPressed(TrackWidthCard.this); + } } }); } @@ -207,7 +212,7 @@ public class TrackWidthCard extends BaseCard { iconId = R.drawable.ic_action_settings; color = AndroidUtils.getColorFromAttr(holder.itemView.getContext(), R.attr.active_color_basic); } else { - iconId = GpxAppearanceAdapter.getWidthIconId(item.getValue()); + iconId = TrackAppearanceFragment.getWidthIconId(item.getValue()); } holder.icon.setImageDrawable(app.getUIUtilities().getPaintedIcon(iconId, color)); } From c4321fe2a7db7f25d242f9cad30615255f1383e5 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 24 Jul 2020 15:13:09 +0300 Subject: [PATCH 05/59] Hide widgets and topbar --- .../osmand/plus/helpers/AndroidUiHelper.java | 11 ++++++ .../plus/mapmarkers/PlanRouteFragment.java | 22 +++-------- .../MeasurementToolFragment.java | 37 +++++++------------ .../plus/track/TrackAppearanceFragment.java | 29 +++++++++++++++ .../osmand/plus/views/ContextMenuLayer.java | 22 ++++------- .../plus/views/MapQuickActionLayer.java | 13 +------ .../mapwidgets/MapInfoWidgetsFactory.java | 1 + .../mapwidgets/MapMarkersWidgetsFactory.java | 1 + 8 files changed, 70 insertions(+), 66 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/AndroidUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/AndroidUiHelper.java index 2ed487f736..4bebdaf751 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AndroidUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AndroidUiHelper.java @@ -92,6 +92,17 @@ public class AndroidUiHelper { } return false; } + + public static void mark(Activity activity, int status, int... widgets) { + if (activity != null) { + for (int widget : widgets) { + View view = activity.findViewById(widget); + if (view != null) { + view.setVisibility(status); + } + } + } + } public static boolean isXLargeDevice(@NonNull Activity ctx) { int lt = (ctx.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 8050da14d9..64e458ff5a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -38,13 +38,11 @@ import net.osmand.TspAnt; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -57,6 +55,8 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.MapMarkersLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; @@ -623,11 +623,11 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat markersLayer.setInPlanRouteMode(true); mapActivity.disableDrawer(); - mark(portrait ? View.INVISIBLE : View.GONE, + AndroidUiHelper.mark(mapActivity, portrait ? View.INVISIBLE : View.GONE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); - mark(View.GONE, + AndroidUiHelper.mark(mapActivity, View.GONE, R.id.map_route_info_button, R.id.map_menu_button, R.id.map_compass_button, @@ -694,7 +694,7 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat mapActivity.hideTopToolbar(toolbarController); } - mark(View.VISIBLE, + AndroidUiHelper.mark(mapActivity, View.VISIBLE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info, @@ -778,18 +778,6 @@ public class PlanRouteFragment extends BaseOsmAndFragment implements OsmAndLocat } } - private void mark(int status, int... widgets) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - for (int widget : widgets) { - View v = mapActivity.findViewById(widget); - if (v != null) { - v.setVisibility(status); - } - } - } - } - private void showHideMarkersList() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null && portrait) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index cb4492c4f4..c9911bc100 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -1047,7 +1047,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { mapActivity.showTopToolbar(toolBarController); } markGeneralComponents(enable ? View.GONE : View.VISIBLE); - mark(enable ? View.VISIBLE : View.GONE, + AndroidUiHelper.mark(mapActivity, enable ? View.VISIBLE : View.GONE, R.id.move_point_text, R.id.move_point_controls); mainIcon.setImageDrawable(getActiveIcon(enable @@ -1067,7 +1067,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { mapActivity.showTopToolbar(toolBarController); } markGeneralComponents(enable ? View.GONE : View.VISIBLE); - mark(enable ? View.VISIBLE : View.GONE, + AndroidUiHelper.mark(mapActivity,enable ? View.VISIBLE : View.GONE, R.id.add_point_before_after_text, R.id.add_point_before_after_controls); if (!enable) { @@ -1076,12 +1076,15 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { } private void markGeneralComponents(int status) { - mark(status, - R.id.measurement_distance_text_view, - R.id.measurement_points_text_view, - R.id.distance_to_center_text_view, - R.id.up_down_button, - R.id.measure_mode_controls); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + AndroidUiHelper.mark(mapActivity, status, + R.id.measurement_distance_text_view, + R.id.measurement_points_text_view, + R.id.distance_to_center_text_view, + R.id.up_down_button, + R.id.measure_mode_controls); + } } private void addInitialPoint() { @@ -1551,11 +1554,11 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { mapActivity.refreshMap(); mapActivity.disableDrawer(); - mark(portrait ? View.INVISIBLE : View.GONE, + AndroidUiHelper.mark(mapActivity, portrait ? View.INVISIBLE : View.GONE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); - mark(View.GONE, + AndroidUiHelper.mark(mapActivity, View.GONE, R.id.map_route_info_button, R.id.map_menu_button, R.id.map_compass_button, @@ -1585,7 +1588,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { measurementLayer.setInMeasurementMode(false); mapActivity.enableDrawer(); - mark(View.VISIBLE, + AndroidUiHelper.mark(mapActivity, View.VISIBLE, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info, @@ -1605,18 +1608,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { } } - private void mark(int status, int... widgets) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - for (int widget : widgets) { - View v = mapActivity.findViewById(widget); - if (v != null) { - v.setVisibility(status); - } - } - } - } - public void quit(boolean hidePointsListFirst) { if (editingCtx.getOriginalPointToMove() != null) { cancelMovePointMode(); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 8c70993eb7..e419e42451 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -154,6 +154,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card params.gravity = Gravity.BOTTOM | Gravity.START; view.findViewById(R.id.control_buttons).setLayoutParams(params); } + enterMeasurementMode(); runLayoutListener(); } return view; @@ -197,6 +198,34 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card } } + @Override + public void onDestroyView() { + super.onDestroyView(); + exitMeasurementMode(); + } + + private void enterMeasurementMode() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); + AndroidUiHelper.mark(mapActivity, portrait ? View.INVISIBLE : View.GONE, + R.id.map_left_widgets_panel, + R.id.map_right_widgets_panel, + R.id.map_center_info); + } + } + + private void exitMeasurementMode() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + AndroidUiHelper.mark(mapActivity, View.VISIBLE, + R.id.map_left_widgets_panel, + R.id.map_right_widgets_panel, + R.id.map_center_info, + R.id.map_search_button); + } + } + @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index ea5cf50027..5e21db83d4 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -57,6 +57,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityActions; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; @@ -454,7 +455,7 @@ public class ContextMenuLayer extends OsmandMapLayer { mInGpxDetailsMode = true; activity.disableDrawer(); - mark(View.INVISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(activity, View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = activity.findViewById(R.id.map_collapse_button); @@ -469,7 +470,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public void exitGpxDetailsMode() { mInGpxDetailsMode = false; activity.enableDrawer(); - mark(View.VISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(activity, View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = activity.findViewById(R.id.map_collapse_button); @@ -480,7 +481,7 @@ public class ContextMenuLayer extends OsmandMapLayer { private void quitMovingMarker() { mInChangeMarkerPositionMode = false; - mark(View.VISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(activity, View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = activity.findViewById(R.id.map_collapse_button); @@ -491,7 +492,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public void quitAddGpxPoint() { mInAddGpxPointMode = false; - mark(View.VISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(activity, View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = activity.findViewById(R.id.map_collapse_button); @@ -508,7 +509,7 @@ public class ContextMenuLayer extends OsmandMapLayer { mInAddGpxPointMode = true; mAddGpxPointBottomSheetHelper.show(newGpxPoint); - mark(View.INVISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(activity, View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = activity.findViewById(R.id.map_collapse_button); @@ -541,7 +542,7 @@ public class ContextMenuLayer extends OsmandMapLayer { mInChangeMarkerPositionMode = true; mMoveMarkerBottomSheetHelper.show(menu.getRightIcon()); - mark(View.INVISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(activity, View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = activity.findViewById(R.id.map_collapse_button); @@ -555,15 +556,6 @@ public class ContextMenuLayer extends OsmandMapLayer { view.refreshMap(); } - private void mark(int status, int... widgets) { - for (int widget : widgets) { - View v = activity.findViewById(widget); - if (v != null) { - v.setVisibility(status); - } - } - } - public void cancelMovingMarker() { cancelApplyingNewMarkerPosition = true; quitMovingMarker(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 18aaa84bf2..63146a40d7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -311,7 +311,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe view.setLatLon(lat, lon); inMovingMarkerMode = true; - mark(View.INVISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(mapActivity, View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = mapActivity.findViewById(R.id.map_collapse_button); @@ -349,7 +349,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } inMovingMarkerMode = false; - mark(View.VISIBLE, R.id.map_ruler_layout, + AndroidUiHelper.mark(mapActivity, View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); View collapseButton = mapActivity.findViewById(R.id.map_collapse_button); @@ -359,15 +359,6 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe view.refreshMap(); } - private void mark(int status, int... widgets) { - for (int widget : widgets) { - View v = mapActivity.findViewById(widget); - if (v != null) { - v.setVisibility(status); - } - } - } - @Override public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { if (isInMovingMarkerMode() && !pressedQuickActionWidget(point.x, point.y)) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 5b209060f5..30b73e7299 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -1275,6 +1275,7 @@ public class MapInfoWidgetsFactory { public boolean updateInfo() { boolean visible = settings.SHOW_COORDINATES_WIDGET.get() && map.getContextMenu().shouldShowTopControls() && map.getMapRouteInfoMenu().shouldShowTopControls() && !map.isTopToolbarActive() + && !map.getMapLayers().getGpxLayer().isInTrackAppearanceMode() && !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible; updateVisibility(visible); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 4f1ebd953d..1ddd521fc9 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -191,6 +191,7 @@ public class MapMarkersWidgetsFactory { || addressTopBar.getVisibility() == View.VISIBLE || map.isTopToolbarActive() || !map.getContextMenu().shouldShowTopControls() + || map.getMapLayers().getGpxLayer().isInTrackAppearanceMode() || map.getMapLayers().getMapMarkersLayer().isInPlanRouteMode()) { updateVisibility(false); return; From a7fcf369189a5b155af4a12d5738c7db7c3c5dab Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 24 Jul 2020 16:05:36 +0300 Subject: [PATCH 06/59] Add zoom buttons --- .../res/layout/fragment_show_all_routes.xml | 47 +----- OsmAnd/res/layout/map_hud_controls.xml | 47 ++++++ OsmAnd/res/layout/track_appearance.xml | 4 + .../TrackActivityFragmentAdapter.java | 4 +- .../plus/track/TrackAppearanceFragment.java | 156 +++++++++++++++++- 5 files changed, 206 insertions(+), 52 deletions(-) create mode 100644 OsmAnd/res/layout/map_hud_controls.xml diff --git a/OsmAnd/res/layout/fragment_show_all_routes.xml b/OsmAnd/res/layout/fragment_show_all_routes.xml index 86ac60d4c5..423b85574d 100644 --- a/OsmAnd/res/layout/fragment_show_all_routes.xml +++ b/OsmAnd/res/layout/fragment_show_all_routes.xml @@ -249,51 +249,6 @@ - - - - - - - - - - - - - + \ No newline at end of file diff --git a/OsmAnd/res/layout/map_hud_controls.xml b/OsmAnd/res/layout/map_hud_controls.xml new file mode 100644 index 0000000000..212f06dd79 --- /dev/null +++ b/OsmAnd/res/layout/map_hud_controls.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_appearance.xml b/OsmAnd/res/layout/track_appearance.xml index a302486a39..ba8267efb2 100644 --- a/OsmAnd/res/layout/track_appearance.xml +++ b/OsmAnd/res/layout/track_appearance.xml @@ -112,4 +112,8 @@ + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 504686054e..6d22a7f305 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -308,9 +308,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } }); + splitColorView.setVisibility(View.GONE); if (showMapOnly) { splitIntervalView.setVisibility(View.GONE); - splitColorView.setVisibility(View.GONE); appearanceView.setVisibility(View.GONE); divider.setVisibility(View.GONE); bottomDivider.setVisibility(View.VISIBLE); @@ -354,11 +354,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } }); appearanceView.setVisibility(View.VISIBLE); - splitColorView.setVisibility(View.VISIBLE); divider.setVisibility(View.VISIBLE); } else { appearanceView.setVisibility(View.GONE); - splitColorView.setVisibility(View.GONE); divider.setVisibility(View.GONE); } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index e419e42451..de72d33f8e 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.track; +import android.Manifest; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.AsyncTask; @@ -10,31 +11,37 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; +import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; +import androidx.core.app.ActivityCompat; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.ContextMenuFragment; +import net.osmand.plus.base.ContextMenuFragment.ContextMenuFragmentListener; import net.osmand.plus.dialogs.GpxAppearanceAdapter; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.views.OsmandMapTileView; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; @@ -49,7 +56,7 @@ import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH; -public class TrackAppearanceFragment extends ContextMenuFragment implements CardListener { +public class TrackAppearanceFragment extends ContextMenuFragment implements CardListener, ContextMenuFragmentListener { public static final String TAG = TrackAppearanceFragment.class.getName(); @@ -62,13 +69,15 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card private SelectedGpxFile selectedGpxFile; private List displayGroups; - private ImageView appearanceIcon; - private int menuTitleHeight; private long modifiedTime = -1; private TrackWidthCard trackWidthCard; + private ImageView appearanceIcon; + private View zoomButtonsView; + private ImageButton myLocButtonView; + @Override public int getMainLayoutId() { return R.layout.track_appearance; @@ -141,6 +150,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { appearanceIcon = view.findViewById(R.id.appearance_icon); + setListener(this); if (isPortrait()) { updateCardsLayout(); @@ -154,6 +164,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card params.gravity = Gravity.BOTTOM | Gravity.START; view.findViewById(R.id.control_buttons).setLayoutParams(params); } + buildZoomButtons(view); enterMeasurementMode(); runLayoutListener(); } @@ -180,6 +191,21 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card updateStatusBarColor(); } + @Override + public void onContextMenuYPosChanged(@NonNull ContextMenuFragment fragment, int y, boolean needMapAdjust, boolean animated) { + updateZoomButtonsPos(fragment, y, animated); + } + + @Override + public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int menuState) { + updateZoomButtonsVisibility(menuState); + } + + @Override + public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) { + + } + @Override public void onResume() { super.onResume(); @@ -287,6 +313,130 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card } + private void buildZoomButtons(@NonNull View view) { + OsmandApplication app = requireMyApplication(); + this.zoomButtonsView = view.findViewById(R.id.map_hud_controls); + ImageButton zoomInButtonView = (ImageButton) view.findViewById(R.id.map_zoom_in_button); + ImageButton zoomOutButtonView = (ImageButton) view.findViewById(R.id.map_zoom_out_button); + AndroidUtils.updateImageButton(app, zoomInButtonView, R.drawable.ic_zoom_in, R.drawable.ic_zoom_in, + R.drawable.btn_circle_trans, R.drawable.btn_circle_night, isNightMode()); + AndroidUtils.updateImageButton(app, zoomOutButtonView, R.drawable.ic_zoom_out, R.drawable.ic_zoom_out, + R.drawable.btn_circle_trans, R.drawable.btn_circle_night, isNightMode()); + zoomInButtonView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + doZoomIn(); + } + }); + zoomOutButtonView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + doZoomOut(); + } + }); + + myLocButtonView = (ImageButton) view.findViewById(R.id.map_my_location_button); + myLocButtonView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { + mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); + } else { + ActivityCompat.requestPermissions(mapActivity, + new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, + OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION); + } + } + } + }); + updateMyLocation(); + + zoomButtonsView.setVisibility(View.VISIBLE); + } + + private void updateMyLocation() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity == null) { + return; + } + OsmandApplication app = mapActivity.getMyApplication(); + Location lastKnownLocation = app.getLocationProvider().getLastKnownLocation(); + boolean enabled = lastKnownLocation != null; + boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); + + ImageButton myLocButtonView = this.myLocButtonView; + if (myLocButtonView != null) { + if (!enabled) { + myLocButtonView.setImageDrawable(getIcon(R.drawable.ic_my_location, R.color.icon_color_default_light)); + AndroidUtils.setBackground(app, myLocButtonView, isNightMode(), R.drawable.btn_circle, R.drawable.btn_circle_night); + myLocButtonView.setContentDescription(mapActivity.getString(R.string.unknown_location)); + } else if (tracked) { + myLocButtonView.setImageDrawable(getIcon(R.drawable.ic_my_location, R.color.color_myloc_distance)); + AndroidUtils.setBackground(app, myLocButtonView, isNightMode(), R.drawable.btn_circle, R.drawable.btn_circle_night); + } else { + myLocButtonView.setImageResource(R.drawable.ic_my_location); + AndroidUtils.setBackground(app, myLocButtonView, isNightMode(), R.drawable.btn_circle_blue, R.drawable.btn_circle_blue); + myLocButtonView.setContentDescription(mapActivity.getString(R.string.map_widget_back_to_loc)); + } + if (app.accessibilityEnabled()) { + myLocButtonView.setClickable(enabled && !tracked && app.getRoutingHelper().isFollowingMode()); + } + } + } + + public void updateZoomButtonsPos(@NonNull ContextMenuFragment fragment, int y, boolean animated) { + View zoomButtonsView = this.zoomButtonsView; + if (zoomButtonsView != null) { + int zoomY = y - getZoomButtonsHeight(); + if (animated) { + fragment.animateView(zoomButtonsView, zoomY); + } else { + zoomButtonsView.setY(zoomY); + } + } + } + + private int getZoomButtonsHeight() { + View zoomButtonsView = this.zoomButtonsView; + return zoomButtonsView != null ? zoomButtonsView.getHeight() : 0; + } + + public void doZoomIn() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + OsmandMapTileView map = mapActivity.getMapView(); + if (map.isZooming() && map.hasCustomMapRatio()) { + mapActivity.changeZoom(2, System.currentTimeMillis()); + } else { + mapActivity.changeZoom(1, System.currentTimeMillis()); + } + } + } + + public void doZoomOut() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.changeZoom(-1, System.currentTimeMillis()); + } + } + + private void updateZoomButtonsVisibility(int menuState) { + View zoomButtonsView = this.zoomButtonsView; + if (zoomButtonsView != null) { + if (menuState == MenuState.HEADER_ONLY) { + if (zoomButtonsView.getVisibility() != View.VISIBLE) { + zoomButtonsView.setVisibility(View.VISIBLE); + } + } else { + if (zoomButtonsView.getVisibility() == View.VISIBLE) { + zoomButtonsView.setVisibility(View.INVISIBLE); + } + } + } + } + private void updateAppearanceIcon() { Drawable icon = getTrackIcon(app, trackDrawInfo.getWidth(), trackDrawInfo.isShowArrows(), trackDrawInfo.getColor()); appearanceIcon.setImageDrawable(icon); From 63b101e3a79c3eec7b8342602f71fcfb5d593397 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 24 Jul 2020 17:46:08 +0300 Subject: [PATCH 07/59] Display split interval in card --- .../TrackActivityFragmentAdapter.java | 11 ++-- .../plus/track/SplitIntervalBottomSheet.java | 35 +++--------- .../osmand/plus/track/SplitIntervalCard.java | 53 ++++++++++++++++++- .../plus/track/TrackAppearanceFragment.java | 51 +++++++++++------- 4 files changed, 93 insertions(+), 57 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 6d22a7f305..29f14447fd 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -54,6 +54,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.measurementtool.NewGpxData; +import net.osmand.plus.track.SplitIntervalCard; import net.osmand.plus.track.SplitTrackAsyncTask; import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; @@ -802,20 +803,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { if (model.size() > 0) { if (distance) { double dvalue = OsmAndFormatter.calculateRoundedDist(value, app); - options.add(OsmAndFormatter.getFormattedDistance((float) dvalue, app)); + options.add(SplitIntervalCard.getFormattedDistanceInterval(app, value)); distanceSplit.add(dvalue); timeSplit.add(-1); if (Math.abs(model.get(0).getSplitDistance() - dvalue) < 1) { selectedSplitInterval = distanceSplit.size() - 1; } } else { - if (value < 60) { - options.add(value + " " + app.getString(R.string.int_seconds)); - } else if (value % 60 == 0) { - options.add((value / 60) + " " + app.getString(R.string.int_min)); - } else { - options.add((value / 60f) + " " + app.getString(R.string.int_min)); - } + options.add(SplitIntervalCard.getFormattedTimeInterval(app, value)); distanceSplit.add(-1d); timeSplit.add(value); if (model.get(0).getSplitTime() == value) { diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index e062483739..e8728d6003 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -1,6 +1,5 @@ package net.osmand.plus.track; -import android.os.AsyncTask; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -27,7 +26,6 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import org.apache.commons.logging.Log; @@ -190,7 +188,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { private void addDistanceOptionSplit(int value, @NonNull List displayGroups) { if (displayGroups.size() > 0) { double dvalue = OsmAndFormatter.calculateRoundedDist(value, app); - String formattedDist = OsmAndFormatter.getFormattedDistance((float) dvalue, app); + String formattedDist = SplitIntervalCard.getFormattedDistanceInterval(app, value); distanceSplitOptions.put(formattedDist, dvalue); if (Math.abs(displayGroups.get(0).getSplitDistance() - dvalue) < 1) { selectedDistanceSplitInterval = distanceSplitOptions.size() - 1; @@ -200,14 +198,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { private void addTimeOptionSplit(int value, @NonNull List model) { if (model.size() > 0) { - String time; - if (value < 60) { - time = value + " " + getString(R.string.int_seconds); - } else if (value % 60 == 0) { - time = (value / 60) + " " + getString(R.string.int_min); - } else { - time = (value / 60f) + " " + getString(R.string.int_min); - } + String time = SplitIntervalCard.getFormattedTimeInterval(app, value); timeSplitOptions.put(time, value); if (model.get(0).getSplitTime() == value) { selectedTimeSplitInterval = timeSplitOptions.size() - 1; @@ -311,24 +302,10 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { int timeSplit = new ArrayList<>(timeSplitOptions.values()).get(selectedTimeSplitInterval); double distanceSplit = new ArrayList<>(distanceSplitOptions.values()).get(selectedDistanceSplitInterval); - SplitTrackListener splitTrackListener = new SplitTrackListener() { - - @Override - public void trackSplittingStarted() { - - } - - @Override - public void trackSplittingFinished() { - if (selectedGpxFile != null) { - List groups = getDisplayGroups(); - selectedGpxFile.setDisplayGroups(groups, app); - } - } - }; - List groups = getDisplayGroups(); - new SplitTrackAsyncTask(app, selectedSplitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(), - timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + Fragment target = getTargetFragment(); + if (target instanceof TrackAppearanceFragment) { + ((TrackAppearanceFragment) target).applySplit(selectedSplitType, timeSplit, distanceSplit); + } } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java index 44b4d75b0c..377185e714 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java @@ -1,19 +1,31 @@ package net.osmand.plus.track; +import android.graphics.Typeface; +import android.text.Spannable; +import android.text.SpannableStringBuilder; +import android.text.style.ForegroundColorSpan; import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; +import net.osmand.AndroidUtils; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.helpers.FontCache; import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.plus.widgets.style.CustomTypefaceSpan; public class SplitIntervalCard extends BaseCard { - public SplitIntervalCard(@NonNull MapActivity mapActivity) { + private TrackDrawInfo trackDrawInfo; + + public SplitIntervalCard(@NonNull MapActivity mapActivity, @NonNull TrackDrawInfo trackDrawInfo) { super(mapActivity); + this.trackDrawInfo = trackDrawInfo; } @Override @@ -28,6 +40,17 @@ public class SplitIntervalCard extends BaseCard { TextView titleView = view.findViewById(R.id.title); titleView.setText(R.string.gpx_split_interval); + Typeface typeface = FontCache.getFont(app, app.getString(R.string.font_roboto_medium)); + int secondaryTextColor = AndroidUtils.getColorFromAttr(view.getContext(), R.attr.active_color_basic); + + String splitInterval = getSplitInterval(); + SpannableStringBuilder spannableSplitInterval = new SpannableStringBuilder(splitInterval); + spannableSplitInterval.setSpan(new ForegroundColorSpan(secondaryTextColor), 0, spannableSplitInterval.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + spannableSplitInterval.setSpan(new CustomTypefaceSpan(typeface), 0, spannableSplitInterval.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + + TextView descriptionView = view.findViewById(R.id.description); + descriptionView.setText(spannableSplitInterval); + view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -38,4 +61,32 @@ public class SplitIntervalCard extends BaseCard { } }); } + + private String getSplitInterval() { + String intervalStr = ""; + int splitInterval = (int) trackDrawInfo.getSplitInterval(); + if (splitInterval == 0) { + intervalStr = GpxSplitType.NO_SPLIT.getHumanString(app); + } else if (trackDrawInfo.getSplitType() == GpxSplitType.DISTANCE.getType()) { + intervalStr = getFormattedDistanceInterval(app, trackDrawInfo.getSplitInterval()); + } else if (trackDrawInfo.getSplitType() == GpxSplitType.TIME.getType()) { + intervalStr = getFormattedTimeInterval(app, splitInterval); + } + return intervalStr; + } + + public static String getFormattedTimeInterval(OsmandApplication app, double interval) { + if (interval < 60) { + return interval + " " + app.getString(R.string.int_seconds); + } else if (interval % 60 == 0) { + return (interval / 60) + " " + app.getString(R.string.int_min); + } else { + return (interval / 60f) + " " + app.getString(R.string.int_min); + } + } + + public static String getFormattedDistanceInterval(OsmandApplication app, double interval) { + double roundedDist = OsmAndFormatter.calculateRoundedDist(interval, app); + return OsmAndFormatter.getFormattedDistance((float) roundedDist, app); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index de72d33f8e..02fe4b4748 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -41,6 +41,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; @@ -73,6 +74,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card private long modifiedTime = -1; private TrackWidthCard trackWidthCard; + private SplitIntervalCard splitIntervalCard; private ImageView appearanceIcon; private View zoomButtonsView; @@ -544,27 +546,38 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card if (splitType == null) { splitType = GpxSplitType.NO_SPLIT; } - SplitTrackAsyncTask.SplitTrackListener splitTrackListener = new SplitTrackAsyncTask.SplitTrackListener() { - - @Override - public void trackSplittingStarted() { - - } - - @Override - public void trackSplittingFinished() { - if (selectedGpxFile != null) { - List groups = getGpxDisplayGroups(); - selectedGpxFile.setDisplayGroups(groups, app); - } - } - }; - List groups = getGpxDisplayGroups(); - new SplitTrackAsyncTask(app, splitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(), - timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + applySplit(splitType, timeSplit, distanceSplit); } } + void applySplit(GpxSplitType splitType, int timeSplit, double distanceSplit) { + if (splitIntervalCard != null) { + splitIntervalCard.updateContent(); + } + SplitTrackListener splitTrackListener = new SplitTrackListener() { + + @Override + public void trackSplittingStarted() { + + } + + @Override + public void trackSplittingFinished() { + if (selectedGpxFile != null) { + List groups = getGpxDisplayGroups(); + selectedGpxFile.setDisplayGroups(groups, app); + } + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) { + mapActivity.refreshMap(); + } + } + }; + List groups = getGpxDisplayGroups(); + new SplitTrackAsyncTask(app, splitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(), + timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + private void saveGpx(final GPXFile gpxFile) { new SaveGpxAsyncTask(gpxFile, new SaveGpxAsyncTask.SaveGpxListener() { @Override @@ -587,7 +600,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - SplitIntervalCard splitIntervalCard = new SplitIntervalCard(mapActivity); + splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo); splitIntervalCard.setListener(this); cardsContainer.addView(splitIntervalCard.build(mapActivity)); From 811c96104320df75a8abda3a8e9544f2e48eeebc Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 24 Jul 2020 18:42:15 +0300 Subject: [PATCH 08/59] Plan a route start --- .../bottom_sheet_item_simple_pad_32dp.xml | 35 +++ .../bottom_sheet_plan_route_select_file.xml | 60 +++++ .../layout/bottom_sheet_plan_route_start.xml | 40 +++ .../res/layout/fragment_measurement_tool.xml | 23 +- OsmAnd/res/layout/gpx_track_select_item.xml | 9 +- OsmAnd/res/values/sizes.xml | 3 + OsmAnd/res/values/strings.xml | 6 + OsmAnd/src/net/osmand/plus/UiUtilities.java | 5 +- .../osmand/plus/helpers/GpxTrackAdapter.java | 12 +- .../net/osmand/plus/helpers/ImportHelper.java | 44 +++- .../MeasurementToolFragment.java | 191 +++++++++++---- .../SelectFileBottomSheet.java | 186 ++++++++++++++ .../StartPlanRouteBottomSheet.java | 231 ++++++++++++++++++ 13 files changed, 767 insertions(+), 78 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_simple_pad_32dp.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_plan_route_select_file.xml create mode 100644 OsmAnd/res/layout/bottom_sheet_plan_route_start.xml create mode 100644 OsmAnd/src/net/osmand/plus/measurementtool/SelectFileBottomSheet.java create mode 100644 OsmAnd/src/net/osmand/plus/measurementtool/StartPlanRouteBottomSheet.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_simple_pad_32dp.xml b/OsmAnd/res/layout/bottom_sheet_item_simple_pad_32dp.xml new file mode 100644 index 0000000000..f7600c2bff --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_simple_pad_32dp.xml @@ -0,0 +1,35 @@ + + + + + + + + diff --git a/OsmAnd/res/layout/bottom_sheet_plan_route_select_file.xml b/OsmAnd/res/layout/bottom_sheet_plan_route_select_file.xml new file mode 100644 index 0000000000..cd6f08e0fe --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_plan_route_select_file.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_plan_route_start.xml b/OsmAnd/res/layout/bottom_sheet_plan_route_start.xml new file mode 100644 index 0000000000..fcc2753f32 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_plan_route_start.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index e126e58a29..12ab48d201 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -71,7 +71,7 @@ android:layout_marginStart="@dimen/measurement_tool_text_button_padding" android:layout_toEndOf="@id/main_icon" android:layout_toRightOf="@id/main_icon" - android:textAppearance="@style/TextAppearance.ListItemTitle" + android:textAppearance="@style/TextAppearance.ListItemCategoryTitle" tools:text="724 m,"/> @@ -221,8 +220,8 @@ android:text="@string/shared_string_add" android:textColor="@color/color_white" android:textAllCaps="false" - android:paddingEnd="@dimen/measurement_tool_button_padding" - android:paddingStart="@dimen/measurement_tool_button_padding" /> + android:paddingEnd="@dimen/measurement_tool_button_padding" + android:paddingStart="@dimen/measurement_tool_button_padding" /> @@ -251,8 +250,8 @@ android:text="@string/shared_string_apply" android:textColor="@color/color_white" android:textAllCaps="false" - android:paddingEnd="@dimen/measurement_tool_button_padding" - android:paddingStart="@dimen/measurement_tool_button_padding" /> + android:paddingEnd="@dimen/measurement_tool_button_padding" + android:paddingStart="@dimen/measurement_tool_button_padding" /> + android:paddingEnd="@dimen/measurement_tool_button_padding" + android:paddingStart="@dimen/measurement_tool_button_padding" />