From d88bf79930c54355d1aa2824a4b559b302280f05 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 13 Jul 2020 19:17:34 +0300 Subject: [PATCH 01/20] Track appearance screen first part --- .../layout/point_editor_group_select_item.xml | 10 +- OsmAnd/res/layout/track_appearance.xml | 115 ++++++++ OsmAnd/res/layout/track_width_card.xml | 112 ++++++++ OsmAnd/res/values-ru/strings.xml | 2 + OsmAnd/res/values/sizes.xml | 3 +- OsmAnd/res/values/strings.xml | 6 + .../plus/dialogs/GpxAppearanceAdapter.java | 49 ++-- .../plus/myplaces/DirectionArrowsCard.java | 64 +++++ .../myplaces/TrackAppearanceFragment.java | 164 +++++++++++ .../osmand/plus/myplaces/TrackWidthCard.java | 259 ++++++++++++++++++ 10 files changed, 763 insertions(+), 21 deletions(-) create mode 100644 OsmAnd/res/layout/track_appearance.xml create mode 100644 OsmAnd/res/layout/track_width_card.xml create mode 100644 OsmAnd/src/net/osmand/plus/myplaces/DirectionArrowsCard.java create mode 100644 OsmAnd/src/net/osmand/plus/myplaces/TrackAppearanceFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/myplaces/TrackWidthCard.java diff --git a/OsmAnd/res/layout/point_editor_group_select_item.xml b/OsmAnd/res/layout/point_editor_group_select_item.xml index 09afe219ff..e747485150 100644 --- a/OsmAnd/res/layout/point_editor_group_select_item.xml +++ b/OsmAnd/res/layout/point_editor_group_select_item.xml @@ -37,15 +37,17 @@ tools:text="255" /> - \ No newline at end of file diff --git a/OsmAnd/res/layout/track_appearance.xml b/OsmAnd/res/layout/track_appearance.xml new file mode 100644 index 0000000000..967501118d --- /dev/null +++ b/OsmAnd/res/layout/track_appearance.xml @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_width_card.xml b/OsmAnd/res/layout/track_width_card.xml new file mode 100644 index 0000000000..03103560eb --- /dev/null +++ b/OsmAnd/res/layout/track_width_card.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 659e2b28c2..15f0a65b91 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -3817,4 +3817,6 @@ Мотороллер Закрытая заметка OSM Инвалидная коляска + Выберите нужный вариант разбиения: по времени или по расстоянию. + Выберите интервал с которым будут отображаться метки с расстоянием или временем на треке. \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index ebefb8942f..55119079e5 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -96,7 +96,8 @@ 3dp 14dp 6dp - + 60dp + 96dp 16dp 48dp diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 5d733cf83f..83cb0a8b90 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,12 @@ Thx - Hardy --> + Direction arrows + Custom + Select the desired splitting option: by time or by distance. + Select the interval at which marks with distance or time on the track will be displayed. + Select width + Show start finish icons Closed OSM Note Go-cart Wheelchair forward diff --git a/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java b/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java index 048461da55..a330e2c940 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/GpxAppearanceAdapter.java @@ -18,10 +18,14 @@ import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; +import java.util.ArrayList; import java.util.List; public class GpxAppearanceAdapter extends ArrayAdapter { + public static final String TRACK_WIDTH_BOLD = "bold"; + public static final String TRACK_WIDTH_MEDIUM = "medium"; + private OsmandApplication app; private GpxAppearanceAdapterType adapterType; private int currentColor; @@ -61,14 +65,7 @@ public class GpxAppearanceAdapter extends ArrayAdapter getAppearanceItems(OsmandApplication app, GpxAppearanceAdapterType adapterType) { + List items = new ArrayList<>(); RenderingRuleProperty trackWidthProp = null; RenderingRuleProperty trackColorProp = null; RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); @@ -102,30 +114,31 @@ public class GpxAppearanceAdapter extends ArrayAdapter appearanceItems; + + public TrackWidthCard(MapActivity mapActivity, SelectedGpxFile selectedGpxFile) { + super(mapActivity); + this.mapActivity = mapActivity; + this.selectedGpxFile = selectedGpxFile; + appearanceItems = getWidthAppearanceItems(); + } + + @Override + public int getCardLayoutId() { + return R.layout.track_width_card; + } + + @Override + protected void updateContent() { + updateHeader(); + updateCustomWidthSlider(); + + RecyclerView groupRecyclerView = view.findViewById(R.id.recycler_view); + groupRecyclerView.setAdapter(new GpxWidthAdapter(appearanceItems)); + groupRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); + } + + private AppearanceListItem getSelectedItem() { + if (selectedItem == null) { + String selectedWidth = selectedGpxFile.getGpxFile().getWidth(null); + for (AppearanceListItem item : appearanceItems) { + if (Algorithms.objectEquals(item.getValue(), selectedWidth) + || Algorithms.isInt(selectedWidth) && CUSTOM_WIDTH.equals(item.getAttrName())) { + selectedItem = item; + break; + } + } + } + return selectedItem; + } + + private List getWidthAppearanceItems() { + List items = GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_WIDTH); + + String selectedWidth = selectedGpxFile.getGpxFile().getWidth(null); + String customWidth = Algorithms.isInt(selectedWidth) ? selectedWidth : String.valueOf(CUSTOM_WIDTH_MIN); + + items.add(new AppearanceListItem(CUSTOM_WIDTH, customWidth, app.getString(R.string.shared_string_custom))); + return items; + } + + private void updateHeader() { + AndroidUiHelper.updateVisibility(view.findViewById(R.id.icon), false); + + TextView titleView = view.findViewById(R.id.title); + titleView.setText(R.string.select_track_width); + + TextView descriptionView = view.findViewById(R.id.description); + descriptionView.setText(getSelectedItem().getLocalizedValue()); + } + + private void updateCustomWidthSlider() { + if (CUSTOM_WIDTH.equals(getSelectedItem().getAttrName())) { + Slider widthSlider = view.findViewById(R.id.width_slider); + + widthSlider.setValueTo(CUSTOM_WIDTH_MAX); + widthSlider.setValueFrom(CUSTOM_WIDTH_MIN); + + ((TextView) view.findViewById(R.id.width_value_min)).setText(String.valueOf(CUSTOM_WIDTH_MIN)); + ((TextView) view.findViewById(R.id.width_value_max)).setText(String.valueOf(CUSTOM_WIDTH_MAX)); + + String width = getSelectedItem().getValue(); + if (!Algorithms.isEmpty(width) && Algorithms.isInt(width)) { + try { + widthSlider.setValue(Integer.parseInt(width)); + } catch (NumberFormatException e) { + widthSlider.setValue(1); + } + } else { + widthSlider.setValue(1); + } + + final TextView selectedCustomWidth = view.findViewById(R.id.width_value_tv); + widthSlider.addOnChangeListener(new Slider.OnChangeListener() { + @Override + public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { + if (fromUser) { + String valueStr = String.valueOf((int) value); + selectedCustomWidth.setText(valueStr); + getSelectedItem().setValue(valueStr); + setGpxWidth(valueStr); + } + } + }); + UiUtilities.setupSlider(widthSlider, nightMode, null); + AndroidUiHelper.updateVisibility(view.findViewById(R.id.slider_container), true); + } else { + AndroidUiHelper.updateVisibility(view.findViewById(R.id.slider_container), false); + } + } + + private void setGpxWidth(String width) { + if (selectedGpxFile.getGpxFile() != null) { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + gpxFile.setWidth(width); + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); + if (gpxDataItem != null) { + app.getGpxDbHelper().updateWidth(gpxDataItem, width); + } + mapActivity.refreshMap(); + } + } + + private class GpxWidthAdapter extends RecyclerView.Adapter { + + private List items; + + private GpxWidthAdapter(List items) { + this.items = items; + } + + @NonNull + @Override + public GpxWidthViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + LayoutInflater themedInflater = UiUtilities.getInflater(parent.getContext(), nightMode); + View view = themedInflater.inflate(R.layout.point_editor_group_select_item, parent, false); + view.getLayoutParams().width = app.getResources().getDimensionPixelSize(R.dimen.gpx_group_button_width); + view.getLayoutParams().height = app.getResources().getDimensionPixelSize(R.dimen.gpx_group_button_height); + + GpxWidthViewHolder holder = new GpxWidthViewHolder(view); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setBackground(app, holder.widthButton, nightMode, R.drawable.ripple_solid_light_6dp, + R.drawable.ripple_solid_dark_6dp); + } + return holder; + } + + @Override + public void onBindViewHolder(@NonNull final GpxWidthViewHolder holder, int position) { + AppearanceListItem item = items.get(position); + holder.widthAttrName.setText(item.getLocalizedValue()); + + updateButtonBg(holder, item); + updateWidthIcon(holder, item); + + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int prevSelectedPosition = getItemPosition(getSelectedItem()); + selectedItem = items.get(holder.getAdapterPosition()); + notifyItemChanged(holder.getAdapterPosition()); + notifyItemChanged(prevSelectedPosition); + + setGpxWidth(selectedItem.getValue()); + + updateHeader(); + updateCustomWidthSlider(); + } + }); + } + + private void updateWidthIcon(GpxWidthViewHolder holder, AppearanceListItem item) { + int color; + if (selectedGpxFile.isShowCurrentTrack()) { + color = app.getSettings().CURRENT_TRACK_COLOR.get(); + } else { + color = selectedGpxFile.getGpxFile().getColor(0); + } + + int iconId; + if (CUSTOM_WIDTH.equals(item.getAttrName())) { + iconId = R.drawable.ic_action_settings; + color = AndroidUtils.getColorFromAttr(holder.itemView.getContext(), R.attr.active_color_basic); + } else { + iconId = GpxAppearanceAdapter.getWidthIconId(item.getValue()); + } + holder.widthIcon.setImageDrawable(app.getUIUtilities().getPaintedIcon(iconId, color)); + } + + private void updateButtonBg(GpxWidthViewHolder holder, AppearanceListItem item) { + GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline); + if (rectContourDrawable != null) { + if (getSelectedItem() != null && getSelectedItem().equals(item)) { + int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); + rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 2), strokeColor); + } else { + int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.stroked_buttons_and_links_outline_dark + : R.color.stroked_buttons_and_links_outline_light); + rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 1), strokeColor); + } + holder.widthButton.setImageDrawable(rectContourDrawable); + } + } + + @Override + public int getItemCount() { + return items.size(); + } + + int getItemPosition(AppearanceListItem name) { + return items.indexOf(name); + } + } + + private static class GpxWidthViewHolder extends RecyclerView.ViewHolder { + + final TextView widthAttrName; + final ImageView widthIcon; + final ImageView widthButton; + + GpxWidthViewHolder(View itemView) { + super(itemView); + widthAttrName = itemView.findViewById(R.id.groupName); + widthIcon = itemView.findViewById(R.id.groupIcon); + widthButton = itemView.findViewById(R.id.outlineRect); + } + } +} \ No newline at end of file From 67d2166d0fb6cb8f6304b620a7c94d521f2bc0db Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 14 Jul 2020 11:49:44 +0300 Subject: [PATCH 02/20] Move GpxSplitType and GradientScaleType to android module --- .../main/java/net/osmand/GPXUtilities.java | 69 ++++--------------- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 34 ++++++--- OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 4 +- .../net/osmand/plus/GpxSelectionHelper.java | 18 ++--- .../TrackActivityFragmentAdapter.java | 2 +- .../net/osmand/plus/track/GpxSplitType.java | 32 +++++++++ .../osmand/plus/track/GradientScaleType.java | 40 +++++++++++ 7 files changed, 122 insertions(+), 77 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/track/GpxSplitType.java create mode 100644 OsmAnd/src/net/osmand/plus/track/GradientScaleType.java diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 3498450ab4..9b055cd01f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1514,52 +1514,38 @@ public class GPXUtilities { return new QuadRect(left, top, right, bottom); } - public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) { + public int getGradientScaleColor(String gradientScaleType, int defColor) { String clrValue = null; if (extensions != null) { - clrValue = extensions.get(gradientScaleType.getTypeName()); + clrValue = extensions.get(gradientScaleType); } return parseColor(clrValue, defColor); } - public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleColor) { - getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); + public void setGradientScaleColor(String gradientScaleType, int gradientScaleColor) { + getExtensionsToWrite().put(gradientScaleType, Algorithms.colorToString(gradientScaleColor)); } - public GradientScaleType getGradientScaleType() { + public String getGradientScaleType() { if (extensions != null) { - String gradientScaleTypeName = extensions.get("gradient_scale_type"); - if (!Algorithms.isEmpty(gradientScaleTypeName)) { - try { - return GradientScaleType.valueOf(gradientScaleTypeName); - } catch (IllegalArgumentException e) { - log.error("Error reading gradientScaleType", e); - } - } + return extensions.get("gradient_scale_type"); } return null; } - public void setGradientScaleType(GradientScaleType gradientScaleType) { - getExtensionsToWrite().put("gradient_scale_type", gradientScaleType.name()); + public void setGradientScaleType(String gradientScaleType) { + getExtensionsToWrite().put("gradient_scale_type", gradientScaleType); } - public GpxSplitType getSplitType() { + public String getSplitType() { if (extensions != null) { - String gradientScaleTypeName = extensions.get("split_type"); - if (!Algorithms.isEmpty(gradientScaleTypeName)) { - try { - return GpxSplitType.valueOf(gradientScaleTypeName); - } catch (IllegalArgumentException e) { - log.error("Error reading GpxSplitType", e); - } - } + return extensions.get("split_type"); } return null; } - public void setSplitType(GpxSplitType gpxSplitType) { - getExtensionsToWrite().put("split_type", gpxSplitType.name()); + public void setSplitType(String gpxSplitType) { + getExtensionsToWrite().put("split_type", gpxSplitType); } public double getSplitInterval() { @@ -1615,37 +1601,6 @@ public class GPXUtilities { getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish)); } - public enum GradientScaleType { - SPEED("gradient_speed_color"), - ALTITUDE("gradient_altitude_color"), - SLOPE("gradient_slope_color"); - - private String typeName; - - GradientScaleType(String typeName) { - this.typeName = typeName; - } - - public String getTypeName() { - return typeName; - } - } - - public enum GpxSplitType { - NO_SPLIT(-1), - DISTANCE(1), - TIME(2); - - private int type; - - GpxSplitType(int type) { - this.type = type; - } - - public int getType() { - return type; - } - } } public static String asString(GPXFile file) { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index d0a19e80b9..7a3ec03992 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -4,11 +4,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import net.osmand.plus.track.GpxSplitType; +import net.osmand.plus.track.GradientScaleType; import net.osmand.util.Algorithms; import java.io.File; @@ -201,17 +202,34 @@ public class GPXDatabase { public GpxDataItem(File file, @NonNull GPXFile gpxFile) { this.file = file; + readGpxParams(gpxFile); + } + + private void readGpxParams(GPXFile gpxFile) { color = gpxFile.getColor(0); width = gpxFile.getWidth(null); showArrows = gpxFile.isShowArrows(); showStartFinish = gpxFile.isShowStartFinish(); - gradientScaleType = gpxFile.getGradientScaleType(); - gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0); - gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0); - gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0); - if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) { - splitType = gpxFile.getSplitType().getType(); - splitInterval = gpxFile.getSplitInterval(); + gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getTypeName(), 0); + gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), 0); + gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), 0); + + if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() != 0) { + for (GpxSplitType gpxSplitType : GpxSplitType.values()) { + if (gpxSplitType.name().equalsIgnoreCase(gpxFile.getSplitType())) { + splitType = gpxSplitType.getType(); + splitInterval = gpxFile.getSplitInterval(); + break; + } + } + } + if (!Algorithms.isEmpty(gpxFile.getGradientScaleType())) { + for (GradientScaleType scaleType : GradientScaleType.values()) { + if (scaleType.name().equalsIgnoreCase(gpxFile.getGradientScaleType())) { + gradientScaleType = scaleType; + break; + } + } } } diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index fc0ffb636e..d5e05e8db3 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -8,11 +8,11 @@ import androidx.annotation.Nullable; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.GPXFile.GpxSplitType; -import net.osmand.GPXUtilities.GPXFile.GradientScaleType; +import net.osmand.plus.track.GpxSplitType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; +import net.osmand.plus.track.GradientScaleType; import java.io.File; import java.util.List; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 6f239e2286..f75a5bf829 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -11,8 +11,7 @@ import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.GPXFile.GpxSplitType; -import net.osmand.GPXUtilities.GPXFile.GradientScaleType; +import net.osmand.plus.track.GpxSplitType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Route; import net.osmand.GPXUtilities.Track; @@ -29,6 +28,7 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants; +import net.osmand.plus.track.GradientScaleType; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -524,7 +524,7 @@ public class GpxSelectionHelper { for (GradientScaleType scaleType : GradientScaleType.values()) { if (obj.has(scaleType.getTypeName())) { int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName())); - gpx.setGradientScaleColor(scaleType, clr); + gpx.setGradientScaleColor(scaleType.getTypeName(), clr); } } if (obj.has(SHOW_ARROWS)) { @@ -534,7 +534,7 @@ public class GpxSelectionHelper { if (obj.has(GRADIENT_SCALE_TYPE)) { String gradientScaleTypeName = obj.optString(GRADIENT_SCALE_TYPE); if (!Algorithms.isEmpty(gradientScaleTypeName)) { - gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName)); + gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName).getTypeName()); } } if (obj.has(SHOW_START_FINISH)) { @@ -592,7 +592,7 @@ public class GpxSelectionHelper { obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows()); obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish()); for (GradientScaleType scaleType : GradientScaleType.values()) { - int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType, 0); + int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getTypeName(), 0); if (gradientScaleColor != 0) { obj.put(scaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); } @@ -650,16 +650,16 @@ public class GpxSelectionHelper { gpx.setColor(dataItem.getColor()); } if (dataItem.getGradientSpeedColor() != 0) { - gpx.setGradientScaleColor(GradientScaleType.SPEED, dataItem.getGradientSpeedColor()); + gpx.setGradientScaleColor(GradientScaleType.SPEED.getTypeName(), dataItem.getGradientSpeedColor()); } if (dataItem.getGradientAltitudeColor() != 0) { - gpx.setGradientScaleColor(GradientScaleType.ALTITUDE, dataItem.getGradientAltitudeColor()); + gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), dataItem.getGradientAltitudeColor()); } if (dataItem.getGradientSlopeColor() != 0) { - gpx.setGradientScaleColor(GradientScaleType.SLOPE, dataItem.getGradientSlopeColor()); + gpx.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), dataItem.getGradientSlopeColor()); } if (dataItem.getGradientScaleType() != null) { - gpx.setGradientScaleType(dataItem.getGradientScaleType()); + gpx.setGradientScaleType(dataItem.getGradientScaleType().getTypeName()); } if (dataItem.getWidth() != null) { gpx.setWidth(dataItem.getWidth()); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 260d7fccda..99cfa60ddc 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -39,7 +39,7 @@ import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.GPXFile.GpxSplitType; +import net.osmand.plus.track.GpxSplitType; import net.osmand.GPXUtilities.WptPt; import net.osmand.PicassoUtils; import net.osmand.data.LatLon; diff --git a/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java b/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java new file mode 100644 index 0000000000..76659a36ce --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java @@ -0,0 +1,32 @@ +package net.osmand.plus.track; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; + +import net.osmand.plus.R; + +public enum GpxSplitType { + + NO_SPLIT(-1, R.string.shared_string_none), + DISTANCE(1, R.string.distance), + TIME(2, R.string.shared_string_time); + + private int type; + @StringRes + private int resId; + + GpxSplitType(int type, @StringRes int resId) { + this.type = type; + this.resId = resId; + } + + public int getType() { + return type; + } + + public String getHumanString(@NonNull Context ctx) { + return ctx.getString(resId); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java b/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java new file mode 100644 index 0000000000..9c2ae36a59 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java @@ -0,0 +1,40 @@ +package net.osmand.plus.track; + +import android.content.Context; + +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; + +import net.osmand.plus.R; + +public enum GradientScaleType { + + SPEED("gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed), + ALTITUDE("gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average), + SLOPE("gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent); + + private String typeName; + @StringRes + private int resId; + @DrawableRes + private int iconId; + + GradientScaleType(@NonNull String typeName, @StringRes int resId, @DrawableRes int iconId) { + this.typeName = typeName; + this.resId = resId; + this.iconId = iconId; + } + + public String getTypeName() { + return typeName; + } + + public int getIconId() { + return iconId; + } + + public String getHumanString(@NonNull Context ctx) { + return ctx.getString(resId); + } +} From bd54b829efdfce06082ce330652ccfe4ab4b14a7 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 14 Jul 2020 15:00:34 +0300 Subject: [PATCH 03/20] Add solid gradient scale type and track coloring card --- .../main/java/net/osmand/GPXUtilities.java | 1 - OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/GpxSelectionHelper.java | 2 +- .../osmand/plus/track/GradientScaleType.java | 1 + .../TrackAppearanceFragment.java | 6 +- .../osmand/plus/track/TrackColoringCard.java | 287 ++++++++++++++++++ .../{myplaces => track}/TrackWidthCard.java | 2 +- 7 files changed, 296 insertions(+), 4 deletions(-) rename OsmAnd/src/net/osmand/plus/{myplaces => track}/TrackAppearanceFragment.java (95%) create mode 100644 OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java rename OsmAnd/src/net/osmand/plus/{myplaces => track}/TrackWidthCard.java (99%) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 9b055cd01f..aec72cbbcb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1600,7 +1600,6 @@ public class GPXUtilities { public void setShowStartFinish(boolean showStartFinish) { getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish)); } - } public static String asString(GPXFile file) { diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 83cb0a8b90..b7feef3e1b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Solid Direction arrows Custom Select the desired splitting option: by time or by distance. diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index f75a5bf829..f8adfdbf5c 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -659,7 +659,7 @@ public class GpxSelectionHelper { gpx.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), dataItem.getGradientSlopeColor()); } if (dataItem.getGradientScaleType() != null) { - gpx.setGradientScaleType(dataItem.getGradientScaleType().getTypeName()); + gpx.setGradientScaleType(dataItem.getGradientScaleType().name()); } if (dataItem.getWidth() != null) { gpx.setWidth(dataItem.getWidth()); diff --git a/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java b/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java index 9c2ae36a59..b458078528 100644 --- a/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java +++ b/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java @@ -10,6 +10,7 @@ import net.osmand.plus.R; public enum GradientScaleType { + SOLID("gradient_solid_color", R.string.track_coloring_solid, R.drawable.ic_action_circle), SPEED("gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed), ALTITUDE("gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average), SLOPE("gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java similarity index 95% rename from OsmAnd/src/net/osmand/plus/myplaces/TrackAppearanceFragment.java rename to OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 839084db2a..0c60221f9a 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -1,4 +1,4 @@ -package net.osmand.plus.myplaces; +package net.osmand.plus.track; import android.os.Bundle; import android.view.Gravity; @@ -19,6 +19,7 @@ import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.myplaces.DirectionArrowsCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard; @@ -124,6 +125,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment { BaseCard arrowsCard = new DirectionArrowsCard(mapActivity, selectedGpxFile); cardsContainer.addView(arrowsCard.build(mapActivity)); + TrackColoringCard trackColoringCard = new TrackColoringCard(mapActivity, selectedGpxFile); + cardsContainer.addView(trackColoringCard.build(mapActivity)); + BaseCard width = new TrackWidthCard(mapActivity, selectedGpxFile); cardsContainer.addView(width.build(mapActivity)); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java new file mode 100644 index 0000000000..c9117b3bc0 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -0,0 +1,287 @@ +package net.osmand.plus.track; + +import android.graphics.drawable.GradientDrawable; +import android.os.Build; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.appcompat.content.res.AppCompatResources; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; +import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.plus.widgets.FlowLayout; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; + +public class TrackColoringCard extends BaseCard { + + private SelectedGpxFile selectedGpxFile; + + private GradientScaleType selectedScaleType; + + @ColorInt + private int selectedColor; + + public TrackColoringCard(MapActivity mapActivity, GpxSelectionHelper.SelectedGpxFile selectedGpxFile) { + super(mapActivity); + this.mapActivity = mapActivity; + this.selectedGpxFile = selectedGpxFile; + } + + @Override + public int getCardLayoutId() { + return R.layout.track_coloring_card; + } + + @Override + protected void updateContent() { + updateHeader(); + updateCustomWidthSlider(); + createColorSelector(); + + RecyclerView groupRecyclerView = view.findViewById(R.id.recycler_view); + groupRecyclerView.setAdapter(new GpxWidthAdapter(Arrays.asList(GradientScaleType.values()))); + groupRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); + } + + private void createColorSelector() { + FlowLayout selectColor = view.findViewById(R.id.select_color); + List colors = new ArrayList<>(); + for (AppearanceListItem appearanceListItem : getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { + if (!colors.contains(appearanceListItem.getColor())) { + colors.add(appearanceListItem.getColor()); + } + } + for (int color : colors) { + selectColor.addView(createColorItemView(color, selectColor), new FlowLayout.LayoutParams(0, 0)); + } + + if (selectedGpxFile.isShowCurrentTrack()) { + selectedColor = app.getSettings().CURRENT_TRACK_COLOR.get(); + } else { + selectedColor = selectedGpxFile.getGpxFile().getColor(0); + } + updateColorSelector(selectedColor, selectColor); + } + + private View createColorItemView(@ColorInt final int color, final FlowLayout rootView) { + FrameLayout colorItemView = (FrameLayout) UiUtilities.getInflater(rootView.getContext(), nightMode) + .inflate(R.layout.point_editor_button, rootView, false); + ImageView outline = colorItemView.findViewById(R.id.outline); + outline.setImageDrawable( + UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_point_circle_contour), + ContextCompat.getColor(app, + nightMode ? R.color.stroked_buttons_and_links_outline_dark + : R.color.stroked_buttons_and_links_outline_light))); + ImageView backgroundCircle = colorItemView.findViewById(R.id.background); + backgroundCircle.setImageDrawable(UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, R.drawable.bg_point_circle), color)); + backgroundCircle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + updateColorSelector(color, rootView); + } + }); + colorItemView.setTag(color); + return colorItemView; + } + + private void updateColorSelector(int color, View rootView) { + View oldColor = rootView.findViewWithTag(selectedColor); + if (oldColor != null) { + oldColor.findViewById(R.id.outline).setVisibility(View.INVISIBLE); + ImageView icon = oldColor.findViewById(R.id.icon); + icon.setImageDrawable(UiUtilities.tintDrawable(icon.getDrawable(), R.color.icon_color_default_light)); + } + View newColor = rootView.findViewWithTag(color); + if (newColor != null) { + newColor.findViewById(R.id.outline).setVisibility(View.VISIBLE); + } + selectedColor = color; + setGpxColor(color); + } + + private void setGpxColor(int color) { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + if (gpxFile != null) { + if (color != 0) { + selectedGpxFile.getGpxFile().setColor(color); + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); + if (gpxDataItem != null) { + app.getGpxDbHelper().updateColor(gpxDataItem, color); + } + } + if (gpxFile.showCurrentTrack) { + app.getSettings().CURRENT_TRACK_COLOR.set(color); + } + mapActivity.refreshMap(); + } + } + + private GradientScaleType getSelectedScaleType() { + if (selectedScaleType == null) { + String gradientScaleType = selectedGpxFile.getGpxFile().getGradientScaleType(); + for (GradientScaleType item : GradientScaleType.values()) { + if (item.name().equalsIgnoreCase(gradientScaleType)) { + selectedScaleType = item; + break; + } + } + if (selectedScaleType == null) { + selectedScaleType = GradientScaleType.SOLID; + } + } + return selectedScaleType; + } + + private void updateHeader() { + AndroidUiHelper.updateVisibility(view.findViewById(R.id.icon), false); + + TextView titleView = view.findViewById(R.id.title); + titleView.setText(R.string.select_color); + + TextView descriptionView = view.findViewById(R.id.description); + descriptionView.setText(getSelectedScaleType().getHumanString(view.getContext())); + } + + private void updateCustomWidthSlider() { + boolean visible = GradientScaleType.SOLID == getSelectedScaleType(); + AndroidUiHelper.updateVisibility(view.findViewById(R.id.select_color), visible); + } + + private void setGradientScaleType(GradientScaleType gradientScaleType) { + if (selectedGpxFile.getGpxFile() != null) { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + gpxFile.setGradientScaleType(gradientScaleType.getTypeName()); + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); + if (gpxDataItem != null) { + app.getGpxDbHelper().updateGradientScaleType(gpxDataItem, gradientScaleType); + } + mapActivity.refreshMap(); + } + } + + private class GpxWidthAdapter extends RecyclerView.Adapter { + + private List items; + + private GpxWidthAdapter(List items) { + this.items = items; + } + + @NonNull + @Override + public GpxWidthViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + LayoutInflater themedInflater = UiUtilities.getInflater(parent.getContext(), nightMode); + View view = themedInflater.inflate(R.layout.point_editor_group_select_item, parent, false); + view.getLayoutParams().width = app.getResources().getDimensionPixelSize(R.dimen.gpx_group_button_width); + view.getLayoutParams().height = app.getResources().getDimensionPixelSize(R.dimen.gpx_group_button_height); + + GpxWidthViewHolder holder = new GpxWidthViewHolder(view); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setBackground(app, holder.widthButton, nightMode, R.drawable.ripple_solid_light_6dp, + R.drawable.ripple_solid_dark_6dp); + } + return holder; + } + + @Override + public void onBindViewHolder(@NonNull final GpxWidthViewHolder holder, int position) { + GradientScaleType item = items.get(position); + holder.widthAttrName.setText(item.getHumanString(holder.itemView.getContext())); + + updateButtonBg(holder, item); + + int colorId; + if (item == GradientScaleType.SOLID) { + if (selectedGpxFile.isShowCurrentTrack()) { + colorId = app.getSettings().CURRENT_TRACK_COLOR.get(); + } else { + colorId = selectedGpxFile.getGpxFile().getColor(0); + } + } else if (item.equals(getSelectedScaleType())) { + colorId = ContextCompat.getColor(app, nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light); + } else { + colorId = AndroidUtils.getColorFromAttr(holder.itemView.getContext(), R.attr.default_icon_color); + } + + holder.widthIcon.setImageDrawable(app.getUIUtilities().getPaintedIcon(item.getIconId(), colorId)); + + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + int prevSelectedPosition = getItemPosition(getSelectedScaleType()); + selectedScaleType = items.get(holder.getAdapterPosition()); + notifyItemChanged(holder.getAdapterPosition()); + notifyItemChanged(prevSelectedPosition); + + setGradientScaleType(selectedScaleType); + + updateHeader(); + updateCustomWidthSlider(); + } + }); + } + + private void updateButtonBg(GpxWidthViewHolder holder, GradientScaleType item) { + GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline); + if (rectContourDrawable != null) { + if (getSelectedScaleType() != null && getSelectedScaleType().equals(item)) { + int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); + rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 2), strokeColor); + } else { + int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.stroked_buttons_and_links_outline_dark + : R.color.stroked_buttons_and_links_outline_light); + rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 1), strokeColor); + } + holder.widthButton.setImageDrawable(rectContourDrawable); + } + } + + @Override + public int getItemCount() { + return items.size(); + } + + int getItemPosition(GradientScaleType name) { + return items.indexOf(name); + } + } + + private static class GpxWidthViewHolder extends RecyclerView.ViewHolder { + + final TextView widthAttrName; + final ImageView widthIcon; + final ImageView widthButton; + + GpxWidthViewHolder(View itemView) { + super(itemView); + widthAttrName = itemView.findViewById(R.id.groupName); + widthIcon = itemView.findViewById(R.id.groupIcon); + widthButton = itemView.findViewById(R.id.outlineRect); + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackWidthCard.java b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java similarity index 99% rename from OsmAnd/src/net/osmand/plus/myplaces/TrackWidthCard.java rename to OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java index e49ff6beb9..bceded63f0 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackWidthCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java @@ -1,4 +1,4 @@ -package net.osmand.plus.myplaces; +package net.osmand.plus.track; import android.graphics.drawable.GradientDrawable; import android.os.Build; From e5c61ddc8b91ba447fff7eac34ee63dcdccc4989 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 14 Jul 2020 17:31:21 +0300 Subject: [PATCH 04/20] Remove track color setting from TrackActivityFragmentAdapter --- OsmAnd/res/layout/gpx_item_list_header.xml | 34 ------ .../TrackActivityFragmentAdapter.java | 112 +----------------- .../osmand/plus/track/TrackColoringCard.java | 1 - .../net/osmand/plus/track/TrackWidthCard.java | 1 - 4 files changed, 2 insertions(+), 146 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_list_header.xml b/OsmAnd/res/layout/gpx_item_list_header.xml index 43ceaf7e3f..4cef607fb6 100644 --- a/OsmAnd/res/layout/gpx_item_list_header.xml +++ b/OsmAnd/res/layout/gpx_item_list_header.xml @@ -158,40 +158,6 @@ - - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 99cfa60ddc..74991ffce2 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -39,7 +39,6 @@ import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.plus.track.GpxSplitType; import net.osmand.GPXUtilities.WptPt; import net.osmand.PicassoUtils; import net.osmand.data.LatLon; @@ -55,19 +54,15 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; -import net.osmand.plus.dialogs.GpxAppearanceAdapter; -import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; -import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType; import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; +import net.osmand.plus.track.GpxSplitType; import net.osmand.plus.widgets.tools.CropCircleTransformation; import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; -import net.osmand.render.RenderingRulesStorage; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -76,9 +71,6 @@ import java.util.Map; import gnu.trove.list.array.TIntArrayList; -import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; -import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; - public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { private OsmandApplication app; @@ -308,7 +300,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { final View splitColorView = headerView.findViewById(R.id.split_color_view); final View divider = headerView.findViewById(R.id.divider); final View splitIntervalView = headerView.findViewById(R.id.split_interval_view); - final View colorView = headerView.findViewById(R.id.color_view); vis = (SwitchCompat) headerView.findViewById(R.id.showOnMapToggle); final View bottomDivider = headerView.findViewById(R.id.bottom_divider); GPXFile gpxFile = getGpx(); @@ -340,7 +331,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { setTrackVisibilityOnMap(vis.isChecked()); if (!showMapOnly) { updateSplitIntervalView(splitIntervalView); - updateColorView(colorView); } TrackActivity trackActivity = getTrackActivity(); if (trackActivity != null) { @@ -358,37 +348,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } else { bottomDivider.setVisibility(View.GONE); - updateColorView(colorView); - colorView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - TrackActivity activity = getTrackActivity(); - final GPXFile gpxFile = getGpx(); - if (activity != null && gpxFile != null) { - final GpxAppearanceAdapter appearanceAdapter = new GpxAppearanceAdapter(activity, - gpxFile.getColor(0), GpxAppearanceAdapterType.TRACK_WIDTH_COLOR); - OnItemClickListener itemClickListener = new OnItemClickListener() { - - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - AppearanceListItem item = appearanceAdapter.getItem(position); - if (item != null) { - if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) { - setGpxColor(item, gpxFile); - } else if (CURRENT_TRACK_WIDTH_ATTR.equals(item.getAttrName())) { - setGpxWidth(item, gpxFile); - } - } - colorListPopupWindow.dismiss(); - updateColorView(colorView); - } - }; - colorListPopupWindow = createPopupWindow(activity, splitIntervalView, appearanceAdapter, itemClickListener); - colorListPopupWindow.show(); - } - } - }); - if (hasPath) { if (!gpxFile.showCurrentTrack && listItemsCount > 0) { prepareSplitIntervalAdapterData(); @@ -428,41 +387,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } } - private void setGpxColor(AppearanceListItem item, GPXFile gpxFile) { - int color = item.getColor(); - if (vis.isChecked()) { - SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false); - if (color != 0 && sf.getModifiableGpxFile() != null) { - sf.getModifiableGpxFile().setColor(color); - if (getGpxDataItem() != null) { - app.getGpxDbHelper().updateColor(getGpxDataItem(), color); - } - } - } else if (getGpxDataItem() != null) { - app.getGpxDbHelper().updateColor(getGpxDataItem(), color); - } - if (gpxFile.showCurrentTrack) { - app.getSettings().CURRENT_TRACK_COLOR.set(color); - } - refreshTrackBitmap(); - } - - private void setGpxWidth(AppearanceListItem item, GPXFile gpxFile) { - String width = item.getValue(); - if (vis.isChecked()) { - SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false); - if (width != null && sf.getModifiableGpxFile() != null) { - sf.getModifiableGpxFile().setWidth(width); - if (getGpxDataItem() != null) { - app.getGpxDbHelper().updateWidth(getGpxDataItem(), width); - } - } - } else if (getGpxDataItem() != null) { - app.getGpxDbHelper().updateWidth(getGpxDataItem(), width); - } - refreshTrackBitmap(); - } - private ListPopupWindow createPopupWindow(Activity activity, View anchorView, ListAdapter adapter, OnItemClickListener itemClickListener) { ListPopupWindow popupWindow = new ListPopupWindow(activity); popupWindow.setAnchorView(anchorView); @@ -773,33 +697,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { return Math.max(position, 0); } - private void updateColorView(View colorView) { - final ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage); - int color = getGpxDataItem() != null ? getGpxDataItem().getColor() : 0; - GPXFile gpxFile = getGpx(); - if (color == 0 && gpxFile != null) { - if (gpxFile.showCurrentTrack) { - color = app.getSettings().CURRENT_TRACK_COLOR.get(); - } else { - color = gpxFile.getColor(0); - } - } - if (color == 0) { - RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); - CommonPreference prefColor = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR); - color = GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get()); - } - if (color == 0) { - colorImageView.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle)); - } else { - colorImageView.setImageDrawable(app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, color)); - } - TrackBitmapDrawer trackDrawer = getTrackBitmapDrawer(); - if (trackDrawer != null) { - trackDrawer.setTrackColor(color); - } - } - public List flatten(List groups) { ArrayList list = new ArrayList<>(); for (GpxDisplayGroup g : groups) { @@ -1057,11 +954,6 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { List groups = fragment.getDisplayGroups(); selectedGpx.setDisplayGroups(groups, app); } - /* - if (fragment.isVisible()) { - fragment.updateContent(); - } - */ } } @@ -1079,4 +971,4 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { return null; } } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index c9117b3bc0..8bf1fb89e6 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -48,7 +48,6 @@ public class TrackColoringCard extends BaseCard { public TrackColoringCard(MapActivity mapActivity, GpxSelectionHelper.SelectedGpxFile selectedGpxFile) { super(mapActivity); - this.mapActivity = mapActivity; this.selectedGpxFile = selectedGpxFile; } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java index bceded63f0..3159e516b8 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java @@ -46,7 +46,6 @@ public class TrackWidthCard extends BaseCard { public TrackWidthCard(MapActivity mapActivity, SelectedGpxFile selectedGpxFile) { super(mapActivity); - this.mapActivity = mapActivity; this.selectedGpxFile = selectedGpxFile; appearanceItems = getWidthAppearanceItems(); } From 1eb20f7dfa3900d097b5e59227bfab50adedb341 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 14 Jul 2020 20:59:08 +0300 Subject: [PATCH 05/20] Add split interval card and bottom sheet --- OsmAnd/res/layout/track_coloring_card.xml | 45 +++ OsmAnd/res/layout/track_split_interval.xml | 169 +++++++++ .../osmand/plus/activities/TrackActivity.java | 2 +- .../myplaces/SplitSegmentDialogFragment.java | 4 +- .../plus/myplaces/SplitTrackAsyncTask.java | 76 ++++ .../TrackActivityFragmentAdapter.java | 117 +++--- .../plus/track/SplitIntervalBottomSheet.java | 358 ++++++++++++++++++ .../osmand/plus/track/SplitIntervalCard.java | 44 +++ .../plus/track/TrackAppearanceFragment.java | 6 +- 9 files changed, 745 insertions(+), 76 deletions(-) create mode 100644 OsmAnd/res/layout/track_coloring_card.xml create mode 100644 OsmAnd/res/layout/track_split_interval.xml create mode 100644 OsmAnd/src/net/osmand/plus/myplaces/SplitTrackAsyncTask.java create mode 100644 OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java create mode 100644 OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java diff --git a/OsmAnd/res/layout/track_coloring_card.xml b/OsmAnd/res/layout/track_coloring_card.xml new file mode 100644 index 0000000000..1b71491c5d --- /dev/null +++ b/OsmAnd/res/layout/track_coloring_card.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_split_interval.xml b/OsmAnd/res/layout/track_split_interval.xml new file mode 100644 index 0000000000..7b12e4c22d --- /dev/null +++ b/OsmAnd/res/layout/track_split_interval.xml @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index 64c137e347..15f37141db 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -178,7 +178,7 @@ public class TrackActivity extends TabActivity { } } - public List getGpxFile(boolean useDisplayGroups) { + public List getGpxDisplayGroups(boolean useDisplayGroups) { if (gpxFile == null) { return new ArrayList<>(); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java index c7b3d0ba18..4601f73e11 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SplitSegmentDialogFragment.java @@ -380,7 +380,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { private List filterGroups(boolean useDisplayGroups) { List groups = new ArrayList<>(); if (getTrackActivity() != null) { - List result = getTrackActivity().getGpxFile(useDisplayGroups); + List result = getTrackActivity().getGpxDisplayGroups(useDisplayGroups); for (GpxDisplayGroup group : result) { boolean add = hasFilterType(group.getType()); if (add) { @@ -397,7 +397,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { TrackActivity trackActivity = getTrackActivity(); List splitSegments = new ArrayList<>(); if (trackActivity != null) { - List result = trackActivity.getGpxFile(true); + List result = trackActivity.getGpxDisplayGroups(true); if (result != null && result.size() > 0 && trkSegment.points.size() > 0) { for (GpxDisplayGroup group : result) { splitSegments.addAll(collectDisplayItemsFromGroup(group)); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SplitTrackAsyncTask.java b/OsmAnd/src/net/osmand/plus/myplaces/SplitTrackAsyncTask.java new file mode 100644 index 0000000000..464530a16d --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/myplaces/SplitTrackAsyncTask.java @@ -0,0 +1,76 @@ +package net.osmand.plus.myplaces; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.track.GpxSplitType; + +import java.util.List; + +public class SplitTrackAsyncTask extends AsyncTask { + + private OsmandApplication app; + private GpxSplitType gpxSplitType; + private List groups; + private SplitTrackListener splitTrackListener; + + private boolean joinSegments; + private int timeSplitInterval; + private double distanceSplitInterval; + + public SplitTrackAsyncTask(@NonNull OsmandApplication app, + @NonNull GpxSplitType gpxSplitType, + @NonNull List groups, + @Nullable SplitTrackListener splitTrackListener, + boolean joinSegments, + int timeSplitInterval, + double distanceSplitInterval) { + this.app = app; + this.groups = groups; + this.gpxSplitType = gpxSplitType; + this.splitTrackListener = splitTrackListener; + this.joinSegments = joinSegments; + this.timeSplitInterval = timeSplitInterval; + this.distanceSplitInterval = distanceSplitInterval; + } + + @Override + protected void onPreExecute() { + if (splitTrackListener != null) { + splitTrackListener.trackSplittingStarted(); + } + } + + @Override + protected Void doInBackground(Void... params) { + for (GpxSelectionHelper.GpxDisplayGroup model : groups) { + if (gpxSplitType == GpxSplitType.NO_SPLIT) { + model.noSplit(app); + } else if (gpxSplitType == GpxSplitType.DISTANCE && distanceSplitInterval > 0) { + model.splitByDistance(app, distanceSplitInterval, joinSegments); + } else if (gpxSplitType == GpxSplitType.TIME && timeSplitInterval > 0) { + model.splitByTime(app, timeSplitInterval, joinSegments); + } + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + if (splitTrackListener != null) { + splitTrackListener.trackSplittingFinished(); + } + } + + public interface SplitTrackListener { + + void trackSplittingStarted(); + + void trackSplittingFinished(); + } +} \ 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 74991ffce2..c5899000f4 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -55,6 +55,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.myplaces.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.track.GpxSplitType; @@ -64,7 +65,6 @@ import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.data.TravelArticle; -import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -639,7 +639,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { List groups = new ArrayList<>(); TrackActivity activity = getTrackActivity(); if (activity != null) { - List result = activity.getGpxFile(useDisplayGroups); + List result = activity.getGpxDisplayGroups(useDisplayGroups); for (GpxDisplayGroup group : result) { boolean add = hasFilterType(group.getType()); if (add) { @@ -738,14 +738,55 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { addOptionSplit(3600, false, groups); } - private void updateSplit(@NonNull List groups, @Nullable SelectedGpxFile sf) { + private void updateSplit(@NonNull List groups, @Nullable final SelectedGpxFile selectedGpx) { TrackActivity activity = getTrackActivity(); if (activity != null) { - new SplitTrackAsyncTask(activity, this, sf, groups) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); + GpxSplitType gpxSplitType = getGpxSplitType(); + if (gpxSplitType != null) { + int timeSplit = this.timeSplit.get(selectedSplitInterval); + double distanceSplit = this.distanceSplit.get(selectedSplitInterval); + + SplitTrackListener splitTrackListener = new SplitTrackListener() { + + @Override + public void trackSplittingStarted() { + TrackActivity activity = getTrackActivity(); + if (activity != null) { + activity.setSupportProgressBarIndeterminateVisibility(true); + } + } + + @Override + public void trackSplittingFinished() { + TrackActivity activity = getTrackActivity(); + if (activity != null) { + if (AndroidUtils.isActivityNotDestroyed(activity)) { + activity.setSupportProgressBarIndeterminateVisibility(false); + } + if (selectedGpx != null) { + List groups = getDisplayGroups(); + selectedGpx.setDisplayGroups(groups, app); + } + } + } + }; + new SplitTrackAsyncTask(app, gpxSplitType, groups, splitTrackListener, activity.isJoinSegments(), + timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } } } + private GpxSplitType getGpxSplitType() { + if (selectedSplitInterval == 0) { + return GpxSplitType.NO_SPLIT; + } else if (distanceSplit.get(selectedSplitInterval) > 0) { + return GpxSplitType.DISTANCE; + } else if (timeSplit.get(selectedSplitInterval) > 0) { + return GpxSplitType.TIME; + } + return null; + } + private void addOptionSplit(int value, boolean distance, @NonNull List model) { if (model.size() > 0) { if (distance) { @@ -905,70 +946,4 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { public void drawTrackBitmap(Bitmap bitmap) { imageView.setImageDrawable(new BitmapDrawable(app.getResources(), bitmap)); } - - private static class SplitTrackAsyncTask extends AsyncTask { - private final SelectedGpxFile selectedGpx; - private OsmandApplication app; - private final WeakReference activityRef; - private final WeakReference fragmentAdapterRef; - private final List groups; - - private List distanceSplit; - private TIntArrayList timeSplit; - private int selectedSplitInterval; - private boolean joinSegments; - - SplitTrackAsyncTask(@NonNull TrackActivity activity, - @NonNull TrackActivityFragmentAdapter fragmentAdapter, - @Nullable SelectedGpxFile selectedGpx, - @NonNull List groups) { - activityRef = new WeakReference<>(activity); - fragmentAdapterRef = new WeakReference<>(fragmentAdapter); - app = activity.getMyApplication(); - this.selectedGpx = selectedGpx; - this.groups = groups; - - selectedSplitInterval = fragmentAdapter.selectedSplitInterval; - distanceSplit = fragmentAdapter.distanceSplit; - timeSplit = fragmentAdapter.timeSplit; - joinSegments = activity.isJoinSegments(); - } - - @Override - protected void onPreExecute() { - TrackActivity activity = activityRef.get(); - if (activity != null) { - activity.setSupportProgressBarIndeterminateVisibility(true); - } - } - - @Override - protected void onPostExecute(Void result) { - TrackActivity activity = activityRef.get(); - TrackActivityFragmentAdapter fragment = fragmentAdapterRef.get(); - if (activity != null && fragment != null) { - if (!activity.isFinishing()) { - activity.setSupportProgressBarIndeterminateVisibility(false); - } - if (selectedGpx != null) { - List groups = fragment.getDisplayGroups(); - selectedGpx.setDisplayGroups(groups, app); - } - } - } - - @Override - protected Void doInBackground(Void... params) { - for (GpxDisplayGroup model : groups) { - if (selectedSplitInterval == 0) { - model.noSplit(app); - } else if (distanceSplit.get(selectedSplitInterval) > 0) { - model.splitByDistance(app, distanceSplit.get(selectedSplitInterval), joinSegments); - } else if (timeSplit.get(selectedSplitInterval) > 0) { - model.splitByTime(app, timeSplit.get(selectedSplitInterval), joinSegments); - } - } - return null; - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java new file mode 100644 index 0000000000..64ee8f266e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -0,0 +1,358 @@ +package net.osmand.plus.track; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.slider.Slider; + +import net.osmand.PlatformUtil; +import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +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.myplaces.SplitTrackAsyncTask; +import net.osmand.plus.myplaces.SplitTrackAsyncTask.SplitTrackListener; + +import org.apache.commons.logging.Log; + +import java.io.File; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import static net.osmand.plus.track.TrackAppearanceFragment.SELECTED_TRACK_FILE_PATH; + +public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = SplitIntervalBottomSheet.class.getSimpleName(); + + private static final Log log = PlatformUtil.getLog(SplitIntervalBottomSheet.class); + + public static final String SELECTED_TRACK_SPLIT_TYPE = "selected_track_split_type"; + public static final String SELECTED_TIME_SPLIT_INTERVAL = "selected_time_split_interval"; + public static final String SELECTED_DISTANCE_SPLIT_INTERVAL = "selected_distance_split_interval"; + + + private OsmandApplication app; + private SelectedGpxFile selectedGpxFile; + + private Map timeSplitOptions = new LinkedHashMap<>(); + private Map distanceSplitOptions = new LinkedHashMap<>(); + + private int selectedTimeSplitInterval; + private int selectedDistanceSplitInterval; + private GpxSplitType selectedSplitType = GpxSplitType.NO_SPLIT; + + private Slider slider; + private View sliderContainer; + private TextView splitValueMin; + private TextView splitValueMax; + private TextView selectedSplitValue; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + app = requiredMyApplication(); + + Bundle arguments = getArguments(); + if (savedInstanceState != null) { + String gpxFilePath = savedInstanceState.getString(SELECTED_TRACK_FILE_PATH); + selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); + prepareSplitIntervalOptions(); + + selectedTimeSplitInterval = savedInstanceState.getInt(SELECTED_TIME_SPLIT_INTERVAL); + selectedDistanceSplitInterval = savedInstanceState.getInt(SELECTED_DISTANCE_SPLIT_INTERVAL); + selectedSplitType = GpxSplitType.valueOf(savedInstanceState.getString(SELECTED_TRACK_SPLIT_TYPE)); + } else if (arguments != null) { + String gpxFilePath = arguments.getString(SELECTED_TRACK_FILE_PATH); + selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); + prepareSplitIntervalOptions(); + updateSelectedSplitParams(); + } + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + items.add(new TitleItem(getString(R.string.gpx_split_interval))); + items.add(new LongDescriptionItem(getString(R.string.gpx_split_interval_descr))); + + LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode); + View view = themedInflater.inflate(R.layout.track_split_interval, null); + + sliderContainer = view.findViewById(R.id.slider_container); + slider = sliderContainer.findViewById(R.id.split_slider); + + splitValueMin = (TextView) view.findViewById(R.id.split_value_min); + splitValueMax = (TextView) view.findViewById(R.id.split_value_max); + selectedSplitValue = (TextView) view.findViewById(R.id.split_value_tv); + + UiUtilities.setupSlider(slider, nightMode, null); + + view.findViewById(R.id.left_btn_container).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectedSplitType = GpxSplitType.NO_SPLIT; + updateSlider(); + } + }); + view.findViewById(R.id.center_btn_container).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectedSplitType = GpxSplitType.TIME; + updateSlider(); + } + }); + view.findViewById(R.id.right_btn_container).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + selectedSplitType = GpxSplitType.DISTANCE; + updateSlider(); + } + }); + + SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(view) + .create(); + items.add(titleItem); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(SELECTED_TIME_SPLIT_INTERVAL, selectedTimeSplitInterval); + outState.putInt(SELECTED_DISTANCE_SPLIT_INTERVAL, selectedDistanceSplitInterval); + outState.putString(SELECTED_TRACK_SPLIT_TYPE, selectedSplitType.name()); + outState.putString(SELECTED_TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); + } + + private void updateSelectedSplitParams() { + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(selectedGpxFile.getGpxFile().path)); + if (gpxDataItem != null) { + if (gpxDataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { + selectedSplitType = GpxSplitType.DISTANCE; + List splitOptions = new ArrayList<>(distanceSplitOptions.values()); + int index = splitOptions.indexOf(gpxDataItem.getSplitInterval()); + selectedDistanceSplitInterval = Math.max(index, 0); + } else if (gpxDataItem.getSplitType() == GpxSplitType.TIME.getType()) { + selectedSplitType = GpxSplitType.TIME; + List splitOptions = new ArrayList<>(timeSplitOptions.values()); + int index = splitOptions.indexOf((int) gpxDataItem.getSplitInterval()); + selectedTimeSplitInterval = Math.max(index, 0); + } + } + } + + private void prepareSplitIntervalOptions() { + List groups = getDisplayGroups(); + addDistanceOptionSplit(30, groups); // 50 feet, 20 yards, 20 m + addDistanceOptionSplit(60, groups); // 100 feet, 50 yards, 50 m + addDistanceOptionSplit(150, groups); // 200 feet, 100 yards, 100 m + addDistanceOptionSplit(300, groups); // 500 feet, 200 yards, 200 m + addDistanceOptionSplit(600, groups); // 1000 feet, 500 yards, 500 m + addDistanceOptionSplit(1500, groups); // 2000 feet, 1000 yards, 1 km + addDistanceOptionSplit(3000, groups); // 1 mi, 2 km + addDistanceOptionSplit(6000, groups); // 2 mi, 5 km + addDistanceOptionSplit(15000, groups); // 5 mi, 10 km + + addTimeOptionSplit(15, groups); + addTimeOptionSplit(30, groups); + addTimeOptionSplit(60, groups); + addTimeOptionSplit(120, groups); + addTimeOptionSplit(150, groups); + addTimeOptionSplit(300, groups); + addTimeOptionSplit(600, groups); + addTimeOptionSplit(900, groups); + addTimeOptionSplit(1800, groups); + addTimeOptionSplit(3600, groups); + } + + 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); + distanceSplitOptions.put(formattedDist, dvalue); + if (Math.abs(displayGroups.get(0).getSplitDistance() - dvalue) < 1) { + selectedDistanceSplitInterval = distanceSplitOptions.size() - 1; + } + } + } + + 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); + } + timeSplitOptions.put(time, value); + if (model.get(0).getSplitTime() == value) { + selectedTimeSplitInterval = timeSplitOptions.size() - 1; + } + } + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + updateSlider(); + } + + private void updateSlider() { + if (selectedSplitType != GpxSplitType.NO_SPLIT) { + slider.clearOnChangeListeners(); + if (selectedSplitType == GpxSplitType.TIME) { + updateSliderTimeInterval(); + } else { + updateSliderDistanceInterval(); + } + AndroidUiHelper.updateVisibility(sliderContainer, true); + } else { + AndroidUiHelper.updateVisibility(sliderContainer, false); + } + setupHeightAndBackground(getView()); + } + + private void updateSliderTimeInterval() { + final List splitOptions = new ArrayList<>(timeSplitOptions.keySet()); + updateSliderMinMaxValues(splitOptions); + + slider.setValue(selectedTimeSplitInterval); + slider.addOnChangeListener(new Slider.OnChangeListener() { + @Override + public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { + if (fromUser) { + selectedTimeSplitInterval = (int) value; + selectedSplitValue.setText(splitOptions.get(selectedTimeSplitInterval)); + } + } + }); + selectedSplitValue.setText(splitOptions.get(selectedTimeSplitInterval)); + } + + private void updateSliderDistanceInterval() { + final List splitOptions = new ArrayList<>(distanceSplitOptions.keySet()); + updateSliderMinMaxValues(splitOptions); + + slider.setValue(selectedDistanceSplitInterval); + slider.addOnChangeListener(new Slider.OnChangeListener() { + @Override + public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { + if (fromUser) { + selectedDistanceSplitInterval = (int) value; + selectedSplitValue.setText(splitOptions.get(selectedDistanceSplitInterval)); + } + } + }); + selectedSplitValue.setText(splitOptions.get(selectedDistanceSplitInterval)); + } + + private void updateSliderMinMaxValues(List splitOptions) { + int valueFrom = 0; + int valueTo = splitOptions.size() - 1; + + slider.setValueTo(valueTo); + slider.setValueFrom(valueFrom); + splitValueMin.setText(splitOptions.get(valueFrom)); + splitValueMax.setText(splitOptions.get(valueTo)); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + @Override + protected void onRightBottomButtonClick() { + applySelectedSplit(); + updateSplitInDatabase(); + dismiss(); + } + + private void updateSplitInDatabase() { + double splitInterval = 0; + if (selectedSplitType == GpxSplitType.NO_SPLIT) { + splitInterval = 0; + } else if (selectedSplitType == GpxSplitType.DISTANCE) { + splitInterval = new ArrayList<>(distanceSplitOptions.values()).get(selectedDistanceSplitInterval); + } else if (selectedSplitType == GpxSplitType.TIME) { + splitInterval = new ArrayList<>(timeSplitOptions.values()).get(selectedTimeSplitInterval); + } + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(selectedGpxFile.getGpxFile().path)); + if (gpxDataItem != null) { + app.getGpxDbHelper().updateSplit(gpxDataItem, selectedSplitType, splitInterval); + } + } + + private void applySelectedSplit() { + 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 = selectedGpxFile.getDisplayGroups(app); + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(selectedGpxFile.getGpxFile().path)); + boolean isJoinSegments = gpxDataItem != null && gpxDataItem.isJoinSegments(); + + new SplitTrackAsyncTask(app, selectedSplitType, groups, splitTrackListener, isJoinSegments, + timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + @NonNull + private List getDisplayGroups() { + List groups = new ArrayList<>(); + for (GpxDisplayGroup group : selectedGpxFile.getDisplayGroups(app)) { + if (GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT == group.getType()) { + groups.add(group); + } + } + return groups; + } + + public static void showInstance(@NonNull FragmentManager fragmentManager, SelectedGpxFile selectedGpxFile) { + try { + if (fragmentManager.findFragmentByTag(SplitIntervalBottomSheet.TAG) == null) { + Bundle args = new Bundle(); + args.putString(SELECTED_TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); + + SplitIntervalBottomSheet splitIntervalBottomSheet = new SplitIntervalBottomSheet(); + splitIntervalBottomSheet.setArguments(args); + splitIntervalBottomSheet.show(fragmentManager, SplitIntervalBottomSheet.TAG); + } + } catch (RuntimeException e) { + log.error("showInstance", e); + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java new file mode 100644 index 0000000000..12ed4d6091 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java @@ -0,0 +1,44 @@ +package net.osmand.plus.track; + +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; + +public class SplitIntervalCard extends BaseCard { + + private SelectedGpxFile selectedGpxFile; + + public SplitIntervalCard(@NonNull MapActivity mapActivity, SelectedGpxFile selectedGpxFile) { + super(mapActivity); + this.selectedGpxFile = selectedGpxFile; + } + + @Override + public int getCardLayoutId() { + return R.layout.bottom_sheet_item_with_right_descr; + } + + @Override + protected void updateContent() { + AndroidUiHelper.updateVisibility(view.findViewById(R.id.icon), false); + + TextView titleView = view.findViewById(R.id.title); + titleView.setText(R.string.gpx_split_interval); + + TextView descriptionView = view.findViewById(R.id.description); + + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), selectedGpxFile); + } + }); + } +} \ 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 0c60221f9a..1989d02b13 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -27,13 +27,12 @@ public class TrackAppearanceFragment extends ContextMenuFragment { public static final String SELECTED_TRACK_FILE_PATH = "selected_track_file_path"; - private OsmandApplication app; private SelectedGpxFile selectedGpxFile; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - app = requireMyApplication(); + OsmandApplication app = requireMyApplication(); String gpxFilePath = null; Bundle arguments = getArguments(); @@ -122,6 +121,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); + BaseCard splitIntervalCard = new SplitIntervalCard(mapActivity, selectedGpxFile); + cardsContainer.addView(splitIntervalCard.build(mapActivity)); + BaseCard arrowsCard = new DirectionArrowsCard(mapActivity, selectedGpxFile); cardsContainer.addView(arrowsCard.build(mapActivity)); From 620b8215127c5ceacf360c17dfe448ade1147eea Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 15 Jul 2020 09:24:52 +0300 Subject: [PATCH 06/20] Add radio group instead of simple buttons --- OsmAnd/res/drawable/radio_button_center.xml | 5 ++ OsmAnd/res/drawable/radio_button_left.xml | 5 ++ .../drawable/radio_button_regular_center.xml | 7 ++ .../drawable/radio_button_regular_left.xml | 10 +++ .../drawable/radio_button_regular_right.xml | 10 +++ OsmAnd/res/drawable/radio_button_right.xml | 5 ++ .../drawable/radio_button_selected_center.xml | 8 ++ .../drawable/radio_button_selected_left.xml | 11 +++ .../drawable/radio_button_selected_right.xml | 11 +++ .../res/drawable/radio_flat_text_selector.xml | 5 ++ OsmAnd/res/layout/track_split_interval.xml | 81 ++++++++----------- .../plus/track/SplitIntervalBottomSheet.java | 39 +++++---- .../net/osmand/plus/track/TrackWidthCard.java | 5 +- 13 files changed, 134 insertions(+), 68 deletions(-) create mode 100644 OsmAnd/res/drawable/radio_button_center.xml create mode 100644 OsmAnd/res/drawable/radio_button_left.xml create mode 100644 OsmAnd/res/drawable/radio_button_regular_center.xml create mode 100644 OsmAnd/res/drawable/radio_button_regular_left.xml create mode 100644 OsmAnd/res/drawable/radio_button_regular_right.xml create mode 100644 OsmAnd/res/drawable/radio_button_right.xml create mode 100644 OsmAnd/res/drawable/radio_button_selected_center.xml create mode 100644 OsmAnd/res/drawable/radio_button_selected_left.xml create mode 100644 OsmAnd/res/drawable/radio_button_selected_right.xml create mode 100644 OsmAnd/res/drawable/radio_flat_text_selector.xml diff --git a/OsmAnd/res/drawable/radio_button_center.xml b/OsmAnd/res/drawable/radio_button_center.xml new file mode 100644 index 0000000000..1c1304d0fc --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_center.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_left.xml b/OsmAnd/res/drawable/radio_button_left.xml new file mode 100644 index 0000000000..838a3f4929 --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_left.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_regular_center.xml b/OsmAnd/res/drawable/radio_button_regular_center.xml new file mode 100644 index 0000000000..e0cca408c5 --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_regular_center.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_regular_left.xml b/OsmAnd/res/drawable/radio_button_regular_left.xml new file mode 100644 index 0000000000..4a983673da --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_regular_left.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_regular_right.xml b/OsmAnd/res/drawable/radio_button_regular_right.xml new file mode 100644 index 0000000000..e2186a923b --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_regular_right.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_right.xml b/OsmAnd/res/drawable/radio_button_right.xml new file mode 100644 index 0000000000..7c227b1319 --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_right.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_selected_center.xml b/OsmAnd/res/drawable/radio_button_selected_center.xml new file mode 100644 index 0000000000..e429400abe --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_selected_center.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_selected_left.xml b/OsmAnd/res/drawable/radio_button_selected_left.xml new file mode 100644 index 0000000000..a96a06f544 --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_selected_left.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_button_selected_right.xml b/OsmAnd/res/drawable/radio_button_selected_right.xml new file mode 100644 index 0000000000..ffb60d307b --- /dev/null +++ b/OsmAnd/res/drawable/radio_button_selected_right.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/radio_flat_text_selector.xml b/OsmAnd/res/drawable/radio_flat_text_selector.xml new file mode 100644 index 0000000000..359b2777c6 --- /dev/null +++ b/OsmAnd/res/drawable/radio_flat_text_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_split_interval.xml b/OsmAnd/res/layout/track_split_interval.xml index 7b12e4c22d..becc0378d7 100644 --- a/OsmAnd/res/layout/track_split_interval.xml +++ b/OsmAnd/res/layout/track_split_interval.xml @@ -1,13 +1,12 @@ - - + android:layout_weight="1" + android:background="@drawable/radio_button_left" + android:button="@android:color/transparent" + android:checked="true" + android:foreground="?attr/selectableItemBackground" + android:gravity="center" + android:text="@string/shared_string_none" + android:textColor="@drawable/radio_flat_text_selector" /> - - - - - + android:layout_weight="1" + android:background="@drawable/radio_button_center" + android:button="@android:color/transparent" + android:foreground="?attr/selectableItemBackground" + android:gravity="center" + android:text="@string/shared_string_time" + android:textColor="@drawable/radio_flat_text_selector" /> - - - - - + android:layout_weight="1" + android:background="@drawable/radio_button_right" + android:button="@android:color/transparent" + android:foreground="?attr/selectableItemBackground" + android:gravity="center" + android:text="@string/distance" + android:textColor="@drawable/radio_flat_text_selector" + android:textSize="@dimen/default_desc_text_size" /> - - - - - + items = GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_WIDTH); String selectedWidth = selectedGpxFile.getGpxFile().getWidth(null); - String customWidth = Algorithms.isInt(selectedWidth) ? selectedWidth : String.valueOf(CUSTOM_WIDTH_MIN); + String customWidth = !Algorithms.isEmpty(selectedWidth) && Algorithms.isInt(selectedWidth) ? selectedWidth : String.valueOf(CUSTOM_WIDTH_MIN); items.add(new AppearanceListItem(CUSTOM_WIDTH, customWidth, app.getString(R.string.shared_string_custom))); return items; From 6773ef50310fa21e7363cd3067c2b1172a713cfd Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 15 Jul 2020 13:45:41 +0300 Subject: [PATCH 07/20] Move SaveGpxAsyncTask to separate file and remove duplicates --- .../net/osmand/plus/GpxSelectionHelper.java | 6 +- .../osmand/plus/base/ContextMenuFragment.java | 6 +- .../editors/WptPtEditorFragment.java | 43 +++--- .../editors/WptPtEditorFragmentNew.java | 45 +++--- .../plus/myplaces/SaveGpxAsyncTask.java | 50 +++++++ .../plus/myplaces/TrackSegmentFragment.java | 139 +++++++----------- .../plus/track/TrackAppearanceFragment.java | 64 +++++++- 7 files changed, 203 insertions(+), 150 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/myplaces/SaveGpxAsyncTask.java diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index f8adfdbf5c..3d74fca4d4 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -11,7 +11,6 @@ import androidx.core.content.ContextCompat; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.plus.track.GpxSplitType; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Route; import net.osmand.GPXUtilities.Track; @@ -28,6 +27,7 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.settings.backend.OsmandSettings.MetricsConstants; +import net.osmand.plus.track.GpxSplitType; import net.osmand.plus.track.GradientScaleType; import net.osmand.util.Algorithms; @@ -533,9 +533,7 @@ public class GpxSelectionHelper { } if (obj.has(GRADIENT_SCALE_TYPE)) { String gradientScaleTypeName = obj.optString(GRADIENT_SCALE_TYPE); - if (!Algorithms.isEmpty(gradientScaleTypeName)) { - gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName).getTypeName()); - } + gpx.setGradientScaleType(gradientScaleTypeName); } if (obj.has(SHOW_START_FINISH)) { boolean showStartFinish = obj.optBoolean(SHOW_START_FINISH, false); diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index 343594a990..c385364c59 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -148,6 +148,10 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { return getLandscapeWidth() - getResources().getDimensionPixelSize(R.dimen.dashboard_land_shadow_width); } + public float getMiddleStateKoef() { + return MIDDLE_STATE_KOEF; + } + public abstract int getToolbarHeight(); public boolean isSingleFragment() { @@ -605,7 +609,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { } private int getMinHalfY(MapActivity mapActivity) { - return viewHeight - (int) Math.min(viewHeight * MIDDLE_STATE_KOEF, + return viewHeight - (int) Math.min(viewHeight * getMiddleStateKoef(), MIDDLE_STATE_MIN_HEIGHT_DP * mapActivity.getMapView().getDensity() ); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java index 21cbe28ff1..444163fdd7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java @@ -12,7 +12,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; -import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.LatLon; @@ -27,9 +26,10 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; +import net.osmand.plus.myplaces.SaveGpxAsyncTask; +import net.osmand.plus.myplaces.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; -import java.io.File; import java.util.Map; public class WptPtEditorFragment extends PointEditorFragment { @@ -251,7 +251,7 @@ public class WptPtEditorFragment extends PointEditorFragment { } } else { addWpt(gpx, description, name, category, color); - new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + saveGpx(getMyApplication(), gpx, editor.isGpxSelected()); } syncGpx(gpx); } @@ -284,7 +284,7 @@ public class WptPtEditorFragment extends PointEditorFragment { } else { gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color); - new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + saveGpx(getMyApplication(), gpx, editor.isGpxSelected()); } syncGpx(gpx); } @@ -309,7 +309,7 @@ public class WptPtEditorFragment extends PointEditorFragment { savingTrackHelper.deletePointData(wpt); } else { gpx.deleteWptPt(wpt); - new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + saveGpx(getMyApplication(), gpx, editor.isGpxSelected()); } syncGpx(gpx); } @@ -378,28 +378,19 @@ public class WptPtEditorFragment extends PointEditorFragment { return color == 0 ? defaultColor : color; } - private static class SaveGpxAsyncTask extends AsyncTask { - private final OsmandApplication app; - private final GPXFile gpx; - private final boolean gpxSelected; + private void saveGpx(final OsmandApplication app, final GPXFile gpxFile, final boolean gpxSelected) { + new SaveGpxAsyncTask(gpxFile, new SaveGpxListener() { + @Override + public void gpxSavingStarted() { - SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, boolean gpxSelected) { - this.app = app; - this.gpx = gpx; - this.gpxSelected = gpxSelected; - } - - @Override - protected Void doInBackground(Void... params) { - GPXUtilities.writeGpxFile(new File(gpx.path), gpx); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!gpxSelected) { - app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); } - } + + @Override + public void gpxSavingFinished() { + if (!gpxSelected) { + app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile); + } + } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index 94ecff5478..334275e760 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -14,7 +14,6 @@ import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentActivity; -import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.FavouritePoint.BackgroundType; @@ -31,9 +30,10 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; +import net.osmand.plus.myplaces.SaveGpxAsyncTask; +import net.osmand.plus.myplaces.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; -import java.io.File; import java.util.List; import java.util.Map; import java.util.Set; @@ -269,7 +269,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { } } else { addWpt(gpx, description, name, category, color, iconName, backgroundTypeName); - new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + saveGpx(getMyApplication(), gpx, editor.isGpxSelected()); } syncGpx(gpx); } @@ -303,7 +303,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { } else { gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(), System.currentTimeMillis(), description, name, category, color, iconName, backgroundTypeName); - new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + saveGpx(getMyApplication(), gpx, editor.isGpxSelected()); } syncGpx(gpx); } @@ -332,7 +332,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { savingTrackHelper.deletePointData(wpt); } else { gpx.deleteWptPt(wpt); - new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + saveGpx(getMyApplication(), gpx, editor.isGpxSelected()); } syncGpx(gpx); } @@ -478,28 +478,19 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { return 0; } - private static class SaveGpxAsyncTask extends AsyncTask { - private final OsmandApplication app; - private final GPXFile gpx; - private final boolean gpxSelected; + private void saveGpx(final OsmandApplication app, final GPXFile gpxFile, final boolean gpxSelected) { + new SaveGpxAsyncTask(gpxFile, new SaveGpxListener() { + @Override + public void gpxSavingStarted() { - SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, boolean gpxSelected) { - this.app = app; - this.gpx = gpx; - this.gpxSelected = gpxSelected; - } - - @Override - protected Void doInBackground(Void... params) { - GPXUtilities.writeGpxFile(new File(gpx.path), gpx); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - if (!gpxSelected) { - app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); } - } + + @Override + public void gpxSavingFinished() { + if (!gpxSelected) { + app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile); + } + } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SaveGpxAsyncTask.java b/OsmAnd/src/net/osmand/plus/myplaces/SaveGpxAsyncTask.java new file mode 100644 index 0000000000..ac1e9c765b --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/myplaces/SaveGpxAsyncTask.java @@ -0,0 +1,50 @@ +package net.osmand.plus.myplaces; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; + +import java.io.File; + +public class SaveGpxAsyncTask extends AsyncTask { + + private final GPXFile gpx; + private final SaveGpxListener saveGpxListener; + + public SaveGpxAsyncTask(@NonNull GPXFile gpx, + @Nullable SaveGpxListener saveGpxListener) { + this.gpx = gpx; + this.saveGpxListener = saveGpxListener; + } + + @Override + protected void onPreExecute() { + if (saveGpxListener != null) { + saveGpxListener.gpxSavingStarted(); + } + } + + @Override + protected Void doInBackground(Void... params) { + GPXUtilities.writeGpxFile(new File(gpx.path), gpx); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + if (saveGpxListener != null) { + saveGpxListener.gpxSavingFinished(); + } + } + + public interface SaveGpxListener { + + void gpxSavingStarted(); + + void gpxSavingFinished(); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 41343f0fa3..f6129a5980 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -68,6 +68,7 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; import net.osmand.plus.measurementtool.NewGpxData; +import net.osmand.plus.myplaces.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.views.controls.PagerSlidingTabStrip; @@ -79,7 +80,6 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.io.File; -import java.lang.ref.WeakReference; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -788,10 +788,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit public boolean onMenuItemClick(MenuItem item) { int i = item.getItemId(); if (i == R.id.action_edit) { - TrkSegment segment = getTrkSegment(); - if (segment != null && fragmentAdapter != null) { - fragmentAdapter.addNewGpxData(NewGpxData.ActionType.EDIT_SEGMENT, segment); - } + editSegment(); return true; } else if (i == R.id.action_delete) { TrackActivity activity = getTrackActivity(); @@ -801,16 +798,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - TrackActivity trackActivity = getTrackActivity(); - if (trackActivity != null && deleteSegment()) { - GPXFile gpx = getGpx(); - if (gpx != null && fragmentAdapter != null) { - boolean showOnMap = fragmentAdapter.isShowOnMap(); - SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, showOnMap, false); - new SaveGpxAsyncTask(trackActivity, TrackSegmentFragment.this, gpx, showOnMap ? sf : null) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } + deleteAndSaveSegment(); } }); builder.setNegativeButton(R.string.shared_string_cancel, null); @@ -914,22 +902,10 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit public boolean onMenuItemClick(MenuItem item) { int i = item.getItemId(); if (i == R.id.action_edit) { - TrkSegment segment = getTrkSegment(); - if (segment != null && fragmentAdapter != null) { - fragmentAdapter.addNewGpxData(NewGpxData.ActionType.EDIT_SEGMENT, segment); - } + editSegment(); return true; } else if (i == R.id.action_delete) { - TrackActivity trackActivity = getTrackActivity(); - if (trackActivity != null && deleteSegment()) { - GPXFile gpx = getGpx(); - if (gpx != null && fragmentAdapter != null) { - boolean showOnMap = fragmentAdapter.isShowOnMap(); - SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, showOnMap, false); - new SaveGpxAsyncTask(trackActivity, TrackSegmentFragment.this, gpx, showOnMap ? sf : null) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } + deleteAndSaveSegment(); return true; } return false; @@ -1023,22 +999,10 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit public boolean onMenuItemClick(MenuItem item) { int i = item.getItemId(); if (i == R.id.action_edit) { - TrkSegment segment = getTrkSegment(); - if (segment != null && fragmentAdapter != null) { - fragmentAdapter.addNewGpxData(NewGpxData.ActionType.EDIT_SEGMENT, segment); - } + editSegment(); return true; } else if (i == R.id.action_delete) { - TrackActivity trackActivity = getTrackActivity(); - if (trackActivity != null && deleteSegment()) { - GPXFile gpx = getGpx(); - if (gpx != null && fragmentAdapter != null) { - boolean showOnMap = fragmentAdapter.isShowOnMap(); - SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, showOnMap, false); - new SaveGpxAsyncTask(trackActivity, TrackSegmentFragment.this, gpx, showOnMap ? sf : null) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } + deleteAndSaveSegment(); return true; } return false; @@ -1060,6 +1024,25 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit return view; } + private void editSegment() { + TrkSegment segment = getTrkSegment(); + if (segment != null && fragmentAdapter != null) { + fragmentAdapter.addNewGpxData(NewGpxData.ActionType.EDIT_SEGMENT, segment); + } + } + + private void deleteAndSaveSegment() { + TrackActivity trackActivity = getTrackActivity(); + if (trackActivity != null && deleteSegment()) { + GPXFile gpx = getGpx(); + if (gpx != null && fragmentAdapter != null) { + boolean showOnMap = fragmentAdapter.isShowOnMap(); + SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(gpx, showOnMap, false); + saveGpx(showOnMap ? selectedGpxFile : null, gpx); + } + } + } + private boolean deleteSegment() { TrkSegment segment = getTrkSegment(); if (segment != null) { @@ -1269,55 +1252,33 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit } } - private static class SaveGpxAsyncTask extends AsyncTask { - private final GPXFile gpx; - private final SelectedGpxFile selectedGpx; - private OsmandApplication app; - private final WeakReference activityRef; - private final WeakReference fragmentRef; - - SaveGpxAsyncTask(@NonNull TrackActivity activity, - @NonNull TrackSegmentFragment fragment, - @NonNull GPXFile gpx, - @Nullable SelectedGpxFile selectedGpx) { - this.gpx = gpx; - activityRef = new WeakReference<>(activity); - fragmentRef = new WeakReference<>(fragment); - app = activity.getMyApplication(); - this.selectedGpx = selectedGpx; - } - - @Override - protected void onPreExecute() { - TrackActivity activity = activityRef.get(); - if (activity != null) { - activity.setSupportProgressBarIndeterminateVisibility(true); + private void saveGpx(final SelectedGpxFile selectedGpxFile, GPXFile gpxFile) { + new SaveGpxAsyncTask(gpxFile, new SaveGpxListener() { + @Override + public void gpxSavingStarted() { + TrackActivity activity = getTrackActivity(); + if (activity != null && AndroidUtils.isActivityNotDestroyed(activity)) { + activity.setSupportProgressBarIndeterminateVisibility(true); + } } - } - @Override - protected Void doInBackground(Void... params) { - GPXUtilities.writeGpxFile(new File(gpx.path), gpx); - return null; - } - - @Override - protected void onPostExecute(Void aVoid) { - TrackActivity activity = activityRef.get(); - TrackSegmentFragment fragment = fragmentRef.get(); - if (activity != null && fragment != null) { - if (selectedGpx != null) { - List groups = fragment.getDisplayGroups(); - if (groups != null) { - selectedGpx.setDisplayGroups(groups, app); - selectedGpx.processPoints(app); + @Override + public void gpxSavingFinished() { + TrackActivity activity = getTrackActivity(); + if (activity != null) { + if (selectedGpxFile != null) { + List groups = getDisplayGroups(); + if (groups != null) { + selectedGpxFile.setDisplayGroups(groups, app); + selectedGpxFile.processPoints(app); + } + } + updateContent(); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + activity.setSupportProgressBarIndeterminateVisibility(false); } } - fragment.updateContent(); - if (!activity.isFinishing()) { - activity.setSupportProgressBarIndeterminateVisibility(false); - } } - } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } -} +} \ 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 1989d02b13..b75c776b44 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.os.AsyncTask; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; @@ -11,6 +12,8 @@ import android.widget.LinearLayout; import androidx.annotation.NonNull; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -20,19 +23,27 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.DirectionArrowsCard; +import net.osmand.plus.myplaces.SaveGpxAsyncTask; import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import java.io.File; public class TrackAppearanceFragment extends ContextMenuFragment { public static final String SELECTED_TRACK_FILE_PATH = "selected_track_file_path"; + private OsmandApplication app; + + private GpxDataItem gpxDataItem; + private TrackDrawInfo trackDrawInfo; private SelectedGpxFile selectedGpxFile; + private int menuTitleHeight; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - OsmandApplication app = requireMyApplication(); + app = requireMyApplication(); String gpxFilePath = null; Bundle arguments = getArguments(); @@ -43,6 +54,10 @@ public class TrackAppearanceFragment extends ContextMenuFragment { gpxFilePath = arguments.getString(SELECTED_TRACK_FILE_PATH); } selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); + + File file = new File(selectedGpxFile.getGpxFile().path); + gpxDataItem = app.getGpxDbHelper().getItem(file); + trackDrawInfo = new TrackDrawInfo(gpxDataItem); } @Override @@ -96,7 +111,8 @@ public class TrackAppearanceFragment extends ContextMenuFragment { saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - + saveTrackInfo(); + dismiss(); } }); @@ -115,6 +131,36 @@ public class TrackAppearanceFragment extends ContextMenuFragment { AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true); } + private void saveTrackInfo() { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + + gpxFile.setWidth(trackDrawInfo.getWidth()); + gpxFile.setGradientScaleType(trackDrawInfo.getGradientScaleType().name()); + gpxFile.setColor(trackDrawInfo.getColor()); + gpxFile.setGradientScaleColor(GradientScaleType.SPEED.getTypeName(), trackDrawInfo.getGradientSpeedColor()); + gpxFile.setGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), trackDrawInfo.getGradientAltitudeColor()); + gpxFile.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), trackDrawInfo.getGradientSlopeColor()); + + for (GpxSplitType gpxSplitType : GpxSplitType.values()) { + if (gpxSplitType.getType() == trackDrawInfo.getSplitType()) { + gpxFile.setSplitType(gpxSplitType.name()); + break; + } + } + + gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval()); + gpxFile.setShowArrows(trackDrawInfo.isShowArrows()); + gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish()); + + app.getSelectedGpxHelper().updateSelectedGpxFile(selectedGpxFile); + + saveGpx(gpxFile); + } + + private void saveGpx(GPXFile gpxFile) { + new SaveGpxAsyncTask(gpxFile, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + private void updateCards() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { @@ -142,7 +188,15 @@ public class TrackAppearanceFragment extends ContextMenuFragment { @Override public int getHeaderViewHeight() { - return 0; + return menuTitleHeight; + } + + @Override + protected void calculateLayout(View view, boolean initLayout) { + menuTitleHeight = view.findViewById(R.id.route_menu_top_shadow_all).getHeight() + + view.findViewById(R.id.control_buttons).getHeight() + - view.findViewById(R.id.buttons_shadow).getHeight(); + super.calculateLayout(view, initLayout); } @Override @@ -155,6 +209,10 @@ public class TrackAppearanceFragment extends ContextMenuFragment { return 0; } + public float getMiddleStateKoef() { + return 0.5f; + } + public static boolean showInstance(@NonNull MapActivity mapActivity, TrackAppearanceFragment fragment) { try { mapActivity.getSupportFragmentManager() From fce394f3f7335ccb49e9e9976acdf4d625ed3554 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 15 Jul 2020 13:47:18 +0300 Subject: [PATCH 08/20] Add trackDrawInfo for drawing unsaved gpx parameters --- .../plus/myplaces/DirectionArrowsCard.java | 29 +--- .../plus/track/SplitIntervalBottomSheet.java | 4 +- .../osmand/plus/track/SplitIntervalCard.java | 9 +- .../plus/track/TrackAppearanceFragment.java | 26 ++- .../osmand/plus/track/TrackColoringCard.java | 51 +----- .../net/osmand/plus/track/TrackDrawInfo.java | 160 ++++++++++++++++++ .../net/osmand/plus/track/TrackWidthCard.java | 32 +--- .../src/net/osmand/plus/views/GPXLayer.java | 23 ++- 8 files changed, 233 insertions(+), 101 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java diff --git a/OsmAnd/src/net/osmand/plus/myplaces/DirectionArrowsCard.java b/OsmAnd/src/net/osmand/plus/myplaces/DirectionArrowsCard.java index cd3b5f701a..a9f2fb87ee 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/DirectionArrowsCard.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/DirectionArrowsCard.java @@ -6,23 +6,19 @@ import android.widget.TextView; import androidx.annotation.NonNull; -import net.osmand.GPXUtilities.GPXFile; -import net.osmand.plus.GPXDatabase.GpxDataItem; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; - -import java.io.File; +import net.osmand.plus.track.TrackDrawInfo; public class DirectionArrowsCard extends BaseCard { - private SelectedGpxFile selectedGpxFile; + private TrackDrawInfo trackDrawInfo; - public DirectionArrowsCard(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile) { + public DirectionArrowsCard(@NonNull MapActivity mapActivity, @NonNull TrackDrawInfo trackDrawInfo) { super(mapActivity); - this.selectedGpxFile = selectedGpxFile; + this.trackDrawInfo = trackDrawInfo; } @Override @@ -38,27 +34,16 @@ public class DirectionArrowsCard extends BaseCard { titleView.setText(R.string.gpx_direction_arrows); final CompoundButton compoundButton = view.findViewById(R.id.compound_button); - compoundButton.setChecked(selectedGpxFile.getGpxFile().isShowStartFinish()); + compoundButton.setChecked(trackDrawInfo.isShowStartFinish()); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = !compoundButton.isChecked(); compoundButton.setChecked(checked); - setShowArrows(checked); + trackDrawInfo.setShowArrows(checked); + mapActivity.refreshMap(); } }); } - - private void setShowArrows(boolean showArrows) { - if (selectedGpxFile.getGpxFile() != null) { - GPXFile gpxFile = selectedGpxFile.getGpxFile(); - gpxFile.setShowArrows(showArrows); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); - if (gpxDataItem != null) { - app.getGpxDbHelper().updateShowArrows(gpxDataItem, showArrows); - } - mapActivity.refreshMap(); - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index cc777b008f..ba858187f9 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -346,11 +346,11 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { return groups; } - public static void showInstance(@NonNull FragmentManager fragmentManager, SelectedGpxFile selectedGpxFile) { + public static void showInstance(@NonNull FragmentManager fragmentManager, TrackDrawInfo trackDrawInfo) { try { if (fragmentManager.findFragmentByTag(SplitIntervalBottomSheet.TAG) == null) { Bundle args = new Bundle(); - args.putString(SELECTED_TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); + args.putString(SELECTED_TRACK_FILE_PATH, trackDrawInfo.getFilePath()); SplitIntervalBottomSheet splitIntervalBottomSheet = new SplitIntervalBottomSheet(); splitIntervalBottomSheet.setArguments(args); diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java index 12ed4d6091..f4e023b3cb 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java @@ -5,7 +5,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; @@ -13,11 +12,11 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard; public class SplitIntervalCard extends BaseCard { - private SelectedGpxFile selectedGpxFile; + private TrackDrawInfo trackDrawInfo; - public SplitIntervalCard(@NonNull MapActivity mapActivity, SelectedGpxFile selectedGpxFile) { + public SplitIntervalCard(@NonNull MapActivity mapActivity, TrackDrawInfo trackDrawInfo) { super(mapActivity); - this.selectedGpxFile = selectedGpxFile; + this.trackDrawInfo = trackDrawInfo; } @Override @@ -37,7 +36,7 @@ public class SplitIntervalCard extends BaseCard { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), selectedGpxFile); + SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), trackDrawInfo); } }); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index b75c776b44..d55d9cc047 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -80,6 +80,24 @@ public class TrackAppearanceFragment extends ContextMenuFragment { return view; } + @Override + public void onResume() { + super.onResume(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapLayers().getGpxLayer().setTrackDrawInfo(trackDrawInfo); + } + } + + @Override + public void onPause() { + super.onPause(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapLayers().getGpxLayer().setTrackDrawInfo(null); + } + } + @Override public void onSaveInstanceState(Bundle outState) { outState.putString(SELECTED_TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); @@ -167,16 +185,16 @@ public class TrackAppearanceFragment extends ContextMenuFragment { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - BaseCard splitIntervalCard = new SplitIntervalCard(mapActivity, selectedGpxFile); + BaseCard splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo); cardsContainer.addView(splitIntervalCard.build(mapActivity)); - BaseCard arrowsCard = new DirectionArrowsCard(mapActivity, selectedGpxFile); + BaseCard arrowsCard = new DirectionArrowsCard(mapActivity, trackDrawInfo); cardsContainer.addView(arrowsCard.build(mapActivity)); - TrackColoringCard trackColoringCard = new TrackColoringCard(mapActivity, selectedGpxFile); + TrackColoringCard trackColoringCard = new TrackColoringCard(mapActivity, selectedGpxFile, trackDrawInfo); cardsContainer.addView(trackColoringCard.build(mapActivity)); - BaseCard width = new TrackWidthCard(mapActivity, selectedGpxFile); + BaseCard width = new TrackWidthCard(mapActivity, trackDrawInfo); cardsContainer.addView(width.build(mapActivity)); } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index 8bf1fb89e6..2e893dc4a1 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -17,9 +17,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; -import net.osmand.GPXUtilities.GPXFile; -import net.osmand.plus.GPXDatabase.GpxDataItem; -import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -30,7 +27,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.widgets.FlowLayout; -import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -39,6 +35,7 @@ import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; public class TrackColoringCard extends BaseCard { + private TrackDrawInfo trackDrawInfo; private SelectedGpxFile selectedGpxFile; private GradientScaleType selectedScaleType; @@ -46,8 +43,9 @@ public class TrackColoringCard extends BaseCard { @ColorInt private int selectedColor; - public TrackColoringCard(MapActivity mapActivity, GpxSelectionHelper.SelectedGpxFile selectedGpxFile) { + public TrackColoringCard(MapActivity mapActivity, SelectedGpxFile selectedGpxFile, TrackDrawInfo trackDrawInfo) { super(mapActivity); + this.trackDrawInfo = trackDrawInfo; this.selectedGpxFile = selectedGpxFile; } @@ -120,35 +118,13 @@ public class TrackColoringCard extends BaseCard { newColor.findViewById(R.id.outline).setVisibility(View.VISIBLE); } selectedColor = color; - setGpxColor(color); - } - - private void setGpxColor(int color) { - GPXFile gpxFile = selectedGpxFile.getGpxFile(); - if (gpxFile != null) { - if (color != 0) { - selectedGpxFile.getGpxFile().setColor(color); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); - if (gpxDataItem != null) { - app.getGpxDbHelper().updateColor(gpxDataItem, color); - } - } - if (gpxFile.showCurrentTrack) { - app.getSettings().CURRENT_TRACK_COLOR.set(color); - } - mapActivity.refreshMap(); - } + trackDrawInfo.setColor(color); + mapActivity.refreshMap(); } private GradientScaleType getSelectedScaleType() { if (selectedScaleType == null) { - String gradientScaleType = selectedGpxFile.getGpxFile().getGradientScaleType(); - for (GradientScaleType item : GradientScaleType.values()) { - if (item.name().equalsIgnoreCase(gradientScaleType)) { - selectedScaleType = item; - break; - } - } + selectedScaleType = trackDrawInfo.getGradientScaleType(); if (selectedScaleType == null) { selectedScaleType = GradientScaleType.SOLID; } @@ -171,18 +147,6 @@ public class TrackColoringCard extends BaseCard { AndroidUiHelper.updateVisibility(view.findViewById(R.id.select_color), visible); } - private void setGradientScaleType(GradientScaleType gradientScaleType) { - if (selectedGpxFile.getGpxFile() != null) { - GPXFile gpxFile = selectedGpxFile.getGpxFile(); - gpxFile.setGradientScaleType(gradientScaleType.getTypeName()); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); - if (gpxDataItem != null) { - app.getGpxDbHelper().updateGradientScaleType(gpxDataItem, gradientScaleType); - } - mapActivity.refreshMap(); - } - } - private class GpxWidthAdapter extends RecyclerView.Adapter { private List items; @@ -237,7 +201,8 @@ public class TrackColoringCard extends BaseCard { notifyItemChanged(holder.getAdapterPosition()); notifyItemChanged(prevSelectedPosition); - setGradientScaleType(selectedScaleType); + trackDrawInfo.setGradientScaleType(selectedScaleType); + mapActivity.refreshMap(); updateHeader(); updateCustomWidthSlider(); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java new file mode 100644 index 0000000000..b933ba32ef --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -0,0 +1,160 @@ +package net.osmand.plus.track; + +import net.osmand.plus.GPXDatabase.GpxDataItem; + +public class TrackDrawInfo { + + private String filePath; + private String width; + private GradientScaleType gradientScaleType; + private int color; + private int gradientSpeedColor; + private int gradientAltitudeColor; + private int gradientSlopeColor; + private int splitType; + private double splitInterval; + private long fileLastModifiedTime; + private boolean apiImported; + private boolean showAsMarkers; + private boolean joinSegments; + private boolean showArrows; + private boolean showStartFinish; + + public TrackDrawInfo(GpxDataItem gpxDataItem) { + filePath = gpxDataItem.getFile().getPath(); + width = gpxDataItem.getWidth(); + gradientScaleType = gpxDataItem.getGradientScaleType(); + color = gpxDataItem.getColor(); + gradientSpeedColor = gpxDataItem.getGradientSpeedColor(); + gradientAltitudeColor = gpxDataItem.getGradientAltitudeColor(); + gradientSlopeColor = gpxDataItem.getGradientSlopeColor(); + splitType = gpxDataItem.getSplitType(); + splitInterval = gpxDataItem.getSplitInterval(); + fileLastModifiedTime = gpxDataItem.getFileLastModifiedTime(); + apiImported = gpxDataItem.isApiImported(); + showAsMarkers = gpxDataItem.isShowAsMarkers(); + joinSegments = gpxDataItem.isJoinSegments(); + showArrows = gpxDataItem.isShowArrows(); + showStartFinish = gpxDataItem.isShowStartFinish(); + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public String getWidth() { + return width; + } + + public void setWidth(String width) { + this.width = width; + } + + public GradientScaleType getGradientScaleType() { + return gradientScaleType; + } + + public void setGradientScaleType(GradientScaleType gradientScaleType) { + this.gradientScaleType = gradientScaleType; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + public int getGradientSpeedColor() { + return gradientSpeedColor; + } + + public void setGradientSpeedColor(int gradientSpeedColor) { + this.gradientSpeedColor = gradientSpeedColor; + } + + public int getGradientAltitudeColor() { + return gradientAltitudeColor; + } + + public void setGradientAltitudeColor(int gradientAltitudeColor) { + this.gradientAltitudeColor = gradientAltitudeColor; + } + + public int getGradientSlopeColor() { + return gradientSlopeColor; + } + + public void setGradientSlopeColor(int gradientSlopeColor) { + this.gradientSlopeColor = gradientSlopeColor; + } + + public int getSplitType() { + return splitType; + } + + public void setSplitType(int splitType) { + this.splitType = splitType; + } + + public double getSplitInterval() { + return splitInterval; + } + + public void setSplitInterval(double splitInterval) { + this.splitInterval = splitInterval; + } + + public long getFileLastModifiedTime() { + return fileLastModifiedTime; + } + + public void setFileLastModifiedTime(long fileLastModifiedTime) { + this.fileLastModifiedTime = fileLastModifiedTime; + } + + public boolean isApiImported() { + return apiImported; + } + + public void setApiImported(boolean apiImported) { + this.apiImported = apiImported; + } + + public boolean isShowAsMarkers() { + return showAsMarkers; + } + + public void setShowAsMarkers(boolean showAsMarkers) { + this.showAsMarkers = showAsMarkers; + } + + public boolean isJoinSegments() { + return joinSegments; + } + + public void setJoinSegments(boolean joinSegments) { + this.joinSegments = joinSegments; + } + + public boolean isShowArrows() { + return showArrows; + } + + public void setShowArrows(boolean showArrows) { + this.showArrows = showArrows; + } + + public boolean isShowStartFinish() { + return showStartFinish; + } + + public void setShowStartFinish(boolean showStartFinish) { + this.showStartFinish = showStartFinish; + } +} \ 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 27fca5b210..0e1c3a0d03 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackWidthCard.java @@ -17,9 +17,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.slider.Slider; import net.osmand.AndroidUtils; -import net.osmand.GPXUtilities.GPXFile; -import net.osmand.plus.GPXDatabase.GpxDataItem; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -30,7 +27,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.util.Algorithms; -import java.io.File; import java.util.List; public class TrackWidthCard extends BaseCard { @@ -39,14 +35,14 @@ public class TrackWidthCard extends BaseCard { private final static int CUSTOM_WIDTH_MIN = 1; private final static int CUSTOM_WIDTH_MAX = 24; - private SelectedGpxFile selectedGpxFile; + private TrackDrawInfo trackDrawInfo; private AppearanceListItem selectedItem; private List appearanceItems; - public TrackWidthCard(MapActivity mapActivity, SelectedGpxFile selectedGpxFile) { + public TrackWidthCard(MapActivity mapActivity, TrackDrawInfo trackDrawInfo) { super(mapActivity); - this.selectedGpxFile = selectedGpxFile; + this.trackDrawInfo = trackDrawInfo; appearanceItems = getWidthAppearanceItems(); } @@ -67,7 +63,7 @@ public class TrackWidthCard extends BaseCard { private AppearanceListItem getSelectedItem() { if (selectedItem == null) { - String selectedWidth = selectedGpxFile.getGpxFile().getWidth(null); + String selectedWidth = trackDrawInfo.getWidth(); for (AppearanceListItem item : appearanceItems) { if (Algorithms.objectEquals(item.getValue(), selectedWidth) || ((Algorithms.isEmpty(selectedWidth) || Algorithms.isInt(selectedWidth)) @@ -83,7 +79,7 @@ public class TrackWidthCard extends BaseCard { private List getWidthAppearanceItems() { List items = GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_WIDTH); - String selectedWidth = selectedGpxFile.getGpxFile().getWidth(null); + String selectedWidth = trackDrawInfo.getWidth(); String customWidth = !Algorithms.isEmpty(selectedWidth) && Algorithms.isInt(selectedWidth) ? selectedWidth : String.valueOf(CUSTOM_WIDTH_MIN); items.add(new AppearanceListItem(CUSTOM_WIDTH, customWidth, app.getString(R.string.shared_string_custom))); @@ -141,15 +137,8 @@ public class TrackWidthCard extends BaseCard { } private void setGpxWidth(String width) { - if (selectedGpxFile.getGpxFile() != null) { - GPXFile gpxFile = selectedGpxFile.getGpxFile(); - gpxFile.setWidth(width); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFile.path)); - if (gpxDataItem != null) { - app.getGpxDbHelper().updateWidth(gpxDataItem, width); - } - mapActivity.refreshMap(); - } + trackDrawInfo.setWidth(width); + mapActivity.refreshMap(); } private class GpxWidthAdapter extends RecyclerView.Adapter { @@ -201,12 +190,7 @@ public class TrackWidthCard extends BaseCard { } private void updateWidthIcon(GpxWidthViewHolder holder, AppearanceListItem item) { - int color; - if (selectedGpxFile.isShowCurrentTrack()) { - color = app.getSettings().CURRENT_TRACK_COLOR.get(); - } else { - color = selectedGpxFile.getGpxFile().getColor(0); - } + int color = trackDrawInfo.getColor(); int iconId; if (CUSTOM_WIDTH.equals(item.getAttrName())) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 7cc2e97f63..43d7e18d04 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -49,6 +49,7 @@ import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; +import net.osmand.plus.track.TrackDrawInfo; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.ContextMenuLayer.IMoveObjectProvider; import net.osmand.plus.views.MapTextLayer.MapTextProvider; @@ -92,6 +93,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private Drawable startPointIcon; private Drawable finishPointIcon; private LayerDrawable selectedPoint; + private TrackDrawInfo trackDrawInfo; private TrackChartPoints trackChartPoints; private GpxSelectionHelper selectedGpxHelper; @@ -136,6 +138,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM this.trackChartPoints = trackChartPoints; } + public void setTrackDrawInfo(TrackDrawInfo trackDrawInfo) { + this.trackDrawInfo = trackDrawInfo; + } + private void initUI() { paint = new Paint(); paint.setStyle(Style.STROKE); @@ -396,7 +402,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private void drawSelectedFilesStartEndPoints(Canvas canvas, RotatedTileBox tileBox, List selectedGPXFiles) { if (tileBox.getZoom() >= START_ZOOM) { for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) { - if (selectedGpxFile.getGpxFile().isShowStartFinish()) { + boolean showStartFinish = selectedGpxFile.getGpxFile().isShowStartFinish(); + if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) { + showStartFinish = trackDrawInfo.isShowStartFinish(); + } + if (showStartFinish) { List segments = selectedGpxFile.getPointsToDisplay(); TrkSegment endSegment = segments.get(segments.size() - 1); @@ -410,6 +420,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } } + private boolean hasTrackDrawInfoForSelectedGpx(SelectedGpxFile selectedGpxFile) { + return trackDrawInfo != null && trackDrawInfo.getFilePath().equals(selectedGpxFile.getGpxFile().path); + } + private void drawPoint(Canvas canvas, RotatedTileBox tileBox, WptPt wptPt, Drawable icon) { int pointX = (int) tileBox.getPixXFromLatLon(wptPt.lat, wptPt.lon); int pointY = (int) tileBox.getPixYFromLatLon(wptPt.lat, wptPt.lon); @@ -573,6 +587,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM List selectedGPXFiles, DrawSettings settings) { for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) { String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get()); + if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) { + width = trackDrawInfo.getWidth(); + } if (!cachedTrackWidth.containsKey(width)) { cachedTrackWidth.put(width, null); } @@ -602,6 +619,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM if (color == 0) { color = ts.getColor(cachedColor); } + if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) { + color = trackDrawInfo.getColor(); + width = trackDrawInfo.getWidth(); + } if (ts.renderer == null && !ts.points.isEmpty()) { if (currentTrack) { ts.renderer = new Renderable.CurrentTrack(ts.points); From debe7d19527e59aabf2f2c7137a3cf720fa36fad Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 15 Jul 2020 15:27:30 +0300 Subject: [PATCH 09/20] Save gpx appearance changes to db --- .../net/osmand/plus/track/TrackAppearanceFragment.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index d55d9cc047..3d84ce4d79 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -34,7 +34,6 @@ public class TrackAppearanceFragment extends ContextMenuFragment { private OsmandApplication app; - private GpxDataItem gpxDataItem; private TrackDrawInfo trackDrawInfo; private SelectedGpxFile selectedGpxFile; @@ -56,7 +55,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment { selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); File file = new File(selectedGpxFile.getGpxFile().path); - gpxDataItem = app.getGpxDbHelper().getItem(file); + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(file); trackDrawInfo = new TrackDrawInfo(gpxDataItem); } @@ -155,9 +154,6 @@ public class TrackAppearanceFragment extends ContextMenuFragment { gpxFile.setWidth(trackDrawInfo.getWidth()); gpxFile.setGradientScaleType(trackDrawInfo.getGradientScaleType().name()); gpxFile.setColor(trackDrawInfo.getColor()); - gpxFile.setGradientScaleColor(GradientScaleType.SPEED.getTypeName(), trackDrawInfo.getGradientSpeedColor()); - gpxFile.setGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), trackDrawInfo.getGradientAltitudeColor()); - gpxFile.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), trackDrawInfo.getGradientSlopeColor()); for (GpxSplitType gpxSplitType : GpxSplitType.values()) { if (gpxSplitType.getType() == trackDrawInfo.getSplitType()) { @@ -172,6 +168,8 @@ public class TrackAppearanceFragment extends ContextMenuFragment { app.getSelectedGpxHelper().updateSelectedGpxFile(selectedGpxFile); + GpxDataItem item = new GpxDataItem(new File(gpxFile.path), gpxFile); + app.getGpxDbHelper().add(item); saveGpx(gpxFile); } From ed1db1978ae8e96fb279f5e76651f66cbcd8da8b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 15 Jul 2020 16:20:15 +0300 Subject: [PATCH 10/20] Save track appearance params on orientation change --- OsmAnd/src/net/osmand/plus/GPXDatabase.java | 8 +- OsmAnd/src/net/osmand/plus/GpxDbHelper.java | 2 +- .../plus/track/SplitIntervalBottomSheet.java | 10 +-- .../plus/track/TrackAppearanceFragment.java | 29 ++++--- .../net/osmand/plus/track/TrackDrawInfo.java | 81 ++++++++++++------- 5 files changed, 75 insertions(+), 55 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 7a3ec03992..02af03f89f 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -539,7 +539,7 @@ public class GPXDatabase { return false; } - public boolean updateGradientScaleType(@NonNull GpxDataItem item, GradientScaleType gradientScaleType) { + public boolean updateGradientScaleType(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType) { SQLiteConnection db = openConnection(false); if (db != null) { try { @@ -547,7 +547,7 @@ public class GPXDatabase { String fileDir = getFileDir(item.file); db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_GRADIENT_SCALE_TYPE + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", - new Object[] {(gradientScaleType == null ? "" : gradientScaleType.name()), fileName, fileDir}); + new Object[] {gradientScaleType.name(), fileName, fileDir}); item.gradientScaleType = gradientScaleType; } finally { db.close(); @@ -723,7 +723,7 @@ public class GPXDatabase { } else { color = Algorithms.colorToString(item.color); } - String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.name() : null; + String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.name() : GradientScaleType.SOLID.name(); if (a != null) { db.execSQL( "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", @@ -891,7 +891,7 @@ public class GPXDatabase { try { item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType); } catch (IllegalArgumentException e) { - item.gradientScaleType = null; + item.gradientScaleType = GradientScaleType.SOLID; } return item; diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index d5e05e8db3..59a5f02895 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -85,7 +85,7 @@ public class GpxDbHelper { return res; } - public boolean updateGradientScaleType(@NonNull GpxDataItem item, @Nullable GradientScaleType gradientScaleType) { + public boolean updateGradientScaleType(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType) { boolean res = db.updateGradientScaleType(item, gradientScaleType); putToCache(item); return res; diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index ba858187f9..ffb3fade30 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -38,7 +38,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import static net.osmand.plus.track.TrackAppearanceFragment.SELECTED_TRACK_FILE_PATH; +import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH; public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { @@ -75,7 +75,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { Bundle arguments = getArguments(); if (savedInstanceState != null) { - String gpxFilePath = savedInstanceState.getString(SELECTED_TRACK_FILE_PATH); + String gpxFilePath = savedInstanceState.getString(TRACK_FILE_PATH); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); prepareSplitIntervalOptions(); @@ -83,7 +83,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { selectedDistanceSplitInterval = savedInstanceState.getInt(SELECTED_DISTANCE_SPLIT_INTERVAL); selectedSplitType = GpxSplitType.valueOf(savedInstanceState.getString(SELECTED_TRACK_SPLIT_TYPE)); } else if (arguments != null) { - String gpxFilePath = arguments.getString(SELECTED_TRACK_FILE_PATH); + String gpxFilePath = arguments.getString(TRACK_FILE_PATH); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); prepareSplitIntervalOptions(); updateSelectedSplitParams(); @@ -142,7 +142,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { outState.putInt(SELECTED_TIME_SPLIT_INTERVAL, selectedTimeSplitInterval); outState.putInt(SELECTED_DISTANCE_SPLIT_INTERVAL, selectedDistanceSplitInterval); outState.putString(SELECTED_TRACK_SPLIT_TYPE, selectedSplitType.name()); - outState.putString(SELECTED_TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); + outState.putString(TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); } private void updateSelectedSplitParams() { @@ -350,7 +350,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { try { if (fragmentManager.findFragmentByTag(SplitIntervalBottomSheet.TAG) == null) { Bundle args = new Bundle(); - args.putString(SELECTED_TRACK_FILE_PATH, trackDrawInfo.getFilePath()); + args.putString(TRACK_FILE_PATH, trackDrawInfo.getFilePath()); SplitIntervalBottomSheet splitIntervalBottomSheet = new SplitIntervalBottomSheet(); splitIntervalBottomSheet.setArguments(args); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 3d84ce4d79..e267a15dc1 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -28,9 +28,9 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard; import java.io.File; -public class TrackAppearanceFragment extends ContextMenuFragment { +import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH; - public static final String SELECTED_TRACK_FILE_PATH = "selected_track_file_path"; +public class TrackAppearanceFragment extends ContextMenuFragment { private OsmandApplication app; @@ -44,19 +44,18 @@ public class TrackAppearanceFragment extends ContextMenuFragment { super.onCreate(savedInstanceState); app = requireMyApplication(); - String gpxFilePath = null; Bundle arguments = getArguments(); - if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_TRACK_FILE_PATH)) { - gpxFilePath = savedInstanceState.getString(SELECTED_TRACK_FILE_PATH); + if (savedInstanceState != null) { + trackDrawInfo = new TrackDrawInfo(); + trackDrawInfo.readBundle(savedInstanceState); + selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(trackDrawInfo.getFilePath()); + } else if (arguments != null) { + String gpxFilePath = arguments.getString(TRACK_FILE_PATH); + selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); + File file = new File(selectedGpxFile.getGpxFile().path); + GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(file); + trackDrawInfo = new TrackDrawInfo(gpxDataItem); } - if (arguments != null && arguments.containsKey(SELECTED_TRACK_FILE_PATH)) { - gpxFilePath = arguments.getString(SELECTED_TRACK_FILE_PATH); - } - selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); - - File file = new File(selectedGpxFile.getGpxFile().path); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(file); - trackDrawInfo = new TrackDrawInfo(gpxDataItem); } @Override @@ -98,9 +97,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment { } @Override - public void onSaveInstanceState(Bundle outState) { - outState.putString(SELECTED_TRACK_FILE_PATH, selectedGpxFile.getGpxFile().path); + public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + trackDrawInfo.saveToBundle(outState); } private void updateCardsLayout() { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java index b933ba32ef..40cf4c52a7 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -1,9 +1,26 @@ package net.osmand.plus.track; +import android.os.Bundle; + +import androidx.annotation.NonNull; + import net.osmand.plus.GPXDatabase.GpxDataItem; public class TrackDrawInfo { + public static final String TRACK_FILE_PATH = "track_file_path"; + private static final String TRACK_WIDTH = "track_width"; + private static final String TRACK_GRADIENT_SCALE_TYPE = "track_gradient_scale_type"; + private static final String TRACK_COLOR = "track_color"; + private static final String TRACK_GRADIENT_SPEED_COLOR = "track_gradient_speed_color"; + private static final String TRACK_GRADIENT_ALTITUDE_COLOR = "track_gradient_altitude_color"; + private static final String TRACK_GRADIENT_SLOPE_COLOR = "track_gradient_slope_color"; + private static final String TRACK_SPLIT_TYPE = "track_split_type"; + private static final String TRACK_SPLIT_INTERVAL = "track_split_interval"; + private static final String TRACK_JOIN_SEGMENTS = "track_join_segments"; + private static final String TRACK_SHOW_ARROWS = "track_show_arrows"; + private static final String TRACK_SHOW_START_FINISH = "track_show_start_finish"; + private String filePath; private String width; private GradientScaleType gradientScaleType; @@ -13,13 +30,14 @@ public class TrackDrawInfo { private int gradientSlopeColor; private int splitType; private double splitInterval; - private long fileLastModifiedTime; - private boolean apiImported; - private boolean showAsMarkers; private boolean joinSegments; private boolean showArrows; private boolean showStartFinish; + public TrackDrawInfo() { + + } + public TrackDrawInfo(GpxDataItem gpxDataItem) { filePath = gpxDataItem.getFile().getPath(); width = gpxDataItem.getWidth(); @@ -30,9 +48,6 @@ public class TrackDrawInfo { gradientSlopeColor = gpxDataItem.getGradientSlopeColor(); splitType = gpxDataItem.getSplitType(); splitInterval = gpxDataItem.getSplitInterval(); - fileLastModifiedTime = gpxDataItem.getFileLastModifiedTime(); - apiImported = gpxDataItem.isApiImported(); - showAsMarkers = gpxDataItem.isShowAsMarkers(); joinSegments = gpxDataItem.isJoinSegments(); showArrows = gpxDataItem.isShowArrows(); showStartFinish = gpxDataItem.isShowStartFinish(); @@ -110,30 +125,6 @@ public class TrackDrawInfo { this.splitInterval = splitInterval; } - public long getFileLastModifiedTime() { - return fileLastModifiedTime; - } - - public void setFileLastModifiedTime(long fileLastModifiedTime) { - this.fileLastModifiedTime = fileLastModifiedTime; - } - - public boolean isApiImported() { - return apiImported; - } - - public void setApiImported(boolean apiImported) { - this.apiImported = apiImported; - } - - public boolean isShowAsMarkers() { - return showAsMarkers; - } - - public void setShowAsMarkers(boolean showAsMarkers) { - this.showAsMarkers = showAsMarkers; - } - public boolean isJoinSegments() { return joinSegments; } @@ -157,4 +148,34 @@ public class TrackDrawInfo { public void setShowStartFinish(boolean showStartFinish) { this.showStartFinish = showStartFinish; } + + protected void readBundle(@NonNull Bundle bundle) { + filePath = bundle.getString(TRACK_FILE_PATH); + width = bundle.getString(TRACK_WIDTH); + gradientScaleType = GradientScaleType.valueOf(bundle.getString(TRACK_GRADIENT_SCALE_TYPE)); + color = bundle.getInt(TRACK_COLOR); + gradientSpeedColor = bundle.getInt(TRACK_GRADIENT_SPEED_COLOR); + gradientAltitudeColor = bundle.getInt(TRACK_GRADIENT_ALTITUDE_COLOR); + gradientSlopeColor = bundle.getInt(TRACK_GRADIENT_SLOPE_COLOR); + splitType = bundle.getInt(TRACK_SPLIT_TYPE); + splitInterval = bundle.getDouble(TRACK_SPLIT_INTERVAL); + joinSegments = bundle.getBoolean(TRACK_JOIN_SEGMENTS); + showArrows = bundle.getBoolean(TRACK_SHOW_ARROWS); + showStartFinish = bundle.getBoolean(TRACK_SHOW_START_FINISH); + } + + protected void saveToBundle(@NonNull Bundle bundle) { + bundle.putString(TRACK_FILE_PATH, filePath); + bundle.putString(TRACK_WIDTH, width); + bundle.putString(TRACK_GRADIENT_SCALE_TYPE, gradientScaleType.name()); + bundle.putInt(TRACK_COLOR, color); + bundle.putInt(TRACK_GRADIENT_SPEED_COLOR, gradientSpeedColor); + bundle.putInt(TRACK_GRADIENT_ALTITUDE_COLOR, gradientAltitudeColor); + bundle.putInt(TRACK_GRADIENT_SLOPE_COLOR, gradientSlopeColor); + bundle.putInt(TRACK_SPLIT_TYPE, splitType); + bundle.putDouble(TRACK_SPLIT_INTERVAL, splitInterval); + bundle.putBoolean(TRACK_JOIN_SEGMENTS, joinSegments); + bundle.putBoolean(TRACK_SHOW_ARROWS, showArrows); + bundle.putBoolean(TRACK_SHOW_START_FINISH, showStartFinish); + } } \ No newline at end of file From 0e69e7cadfb52326808ba55c59c1eb71580d8ae7 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 16 Jul 2020 11:52:49 +0300 Subject: [PATCH 11/20] Discard split track changes --- .../plus/track/SplitIntervalBottomSheet.java | 62 ++++---- .../osmand/plus/track/SplitIntervalCard.java | 7 +- .../plus/track/TrackAppearanceFragment.java | 144 +++++++++++++----- 3 files changed, 146 insertions(+), 67 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index ffb3fade30..0deee639d2 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -9,14 +9,14 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import com.google.android.material.slider.Slider; import net.osmand.PlatformUtil; -import net.osmand.plus.GPXDatabase.GpxDataItem; -import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -32,7 +32,6 @@ import net.osmand.plus.myplaces.SplitTrackAsyncTask.SplitTrackListener; import org.apache.commons.logging.Log; -import java.io.File; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -50,9 +49,9 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { public static final String SELECTED_TIME_SPLIT_INTERVAL = "selected_time_split_interval"; public static final String SELECTED_DISTANCE_SPLIT_INTERVAL = "selected_distance_split_interval"; - private OsmandApplication app; private SelectedGpxFile selectedGpxFile; + private TrackDrawInfo trackDrawInfo; private Map timeSplitOptions = new LinkedHashMap<>(); private Map distanceSplitOptions = new LinkedHashMap<>(); @@ -73,6 +72,10 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { super.onCreate(savedInstanceState); app = requiredMyApplication(); + Fragment target = getTargetFragment(); + if (target instanceof TrackAppearanceFragment) { + trackDrawInfo = ((TrackAppearanceFragment) target).getTrackDrawInfo(); + } Bundle arguments = getArguments(); if (savedInstanceState != null) { String gpxFilePath = savedInstanceState.getString(TRACK_FILE_PATH); @@ -101,10 +104,10 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { sliderContainer = view.findViewById(R.id.slider_container); slider = sliderContainer.findViewById(R.id.split_slider); - splitValueMin = (TextView) view.findViewById(R.id.split_value_min); - splitValueMax = (TextView) view.findViewById(R.id.split_value_max); - selectedSplitValue = (TextView) view.findViewById(R.id.split_value_tv); - splitIntervalNoneDescr = (TextView) view.findViewById(R.id.split_interval_none_descr); + splitValueMin = view.findViewById(R.id.split_value_min); + splitValueMax = view.findViewById(R.id.split_value_max); + selectedSplitValue = view.findViewById(R.id.split_value_tv); + splitIntervalNoneDescr = view.findViewById(R.id.split_interval_none_descr); UiUtilities.setupSlider(slider, nightMode, null); @@ -146,17 +149,16 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { } private void updateSelectedSplitParams() { - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(selectedGpxFile.getGpxFile().path)); - if (gpxDataItem != null) { - if (gpxDataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { + if (trackDrawInfo != null) { + if (trackDrawInfo.getSplitType() == GpxSplitType.DISTANCE.getType()) { selectedSplitType = GpxSplitType.DISTANCE; List splitOptions = new ArrayList<>(distanceSplitOptions.values()); - int index = splitOptions.indexOf(gpxDataItem.getSplitInterval()); + int index = splitOptions.indexOf(trackDrawInfo.getSplitInterval()); selectedDistanceSplitInterval = Math.max(index, 0); - } else if (gpxDataItem.getSplitType() == GpxSplitType.TIME.getType()) { + } else if (trackDrawInfo.getSplitType() == GpxSplitType.TIME.getType()) { selectedSplitType = GpxSplitType.TIME; List splitOptions = new ArrayList<>(timeSplitOptions.values()); - int index = splitOptions.indexOf((int) gpxDataItem.getSplitInterval()); + int index = splitOptions.indexOf((int) trackDrawInfo.getSplitInterval()); selectedTimeSplitInterval = Math.max(index, 0); } } @@ -288,12 +290,12 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { @Override protected void onRightBottomButtonClick() { + updateSplit(); applySelectedSplit(); - updateSplitInDatabase(); dismiss(); } - private void updateSplitInDatabase() { + private void updateSplit() { double splitInterval = 0; if (selectedSplitType == GpxSplitType.NO_SPLIT) { splitInterval = 0; @@ -302,10 +304,8 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { } else if (selectedSplitType == GpxSplitType.TIME) { splitInterval = new ArrayList<>(timeSplitOptions.values()).get(selectedTimeSplitInterval); } - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(selectedGpxFile.getGpxFile().path)); - if (gpxDataItem != null) { - app.getGpxDbHelper().updateSplit(gpxDataItem, selectedSplitType, splitInterval); - } + trackDrawInfo.setSplitType(selectedSplitType.getType()); + trackDrawInfo.setSplitInterval(splitInterval); } private void applySelectedSplit() { @@ -327,26 +327,27 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { } } }; - List groups = selectedGpxFile.getDisplayGroups(app); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(new File(selectedGpxFile.getGpxFile().path)); - boolean isJoinSegments = gpxDataItem != null && gpxDataItem.isJoinSegments(); - - new SplitTrackAsyncTask(app, selectedSplitType, groups, splitTrackListener, isJoinSegments, + List groups = getDisplayGroups(); + new SplitTrackAsyncTask(app, selectedSplitType, groups, splitTrackListener, trackDrawInfo.isJoinSegments(), timeSplit, distanceSplit).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @NonNull - private List getDisplayGroups() { + public List getDisplayGroups() { List groups = new ArrayList<>(); - for (GpxDisplayGroup group : selectedGpxFile.getDisplayGroups(app)) { - if (GpxSelectionHelper.GpxDisplayItemType.TRACK_SEGMENT == group.getType()) { - groups.add(group); + Fragment target = getTargetFragment(); + if (target instanceof TrackAppearanceFragment) { + List result = ((TrackAppearanceFragment) target).getGpxDisplayGroups(); + for (GpxDisplayGroup group : result) { + if (GpxDisplayItemType.TRACK_SEGMENT == group.getType()) { + groups.add(group); + } } } return groups; } - public static void showInstance(@NonNull FragmentManager fragmentManager, TrackDrawInfo trackDrawInfo) { + public static void showInstance(@NonNull FragmentManager fragmentManager, TrackDrawInfo trackDrawInfo, Fragment target) { try { if (fragmentManager.findFragmentByTag(SplitIntervalBottomSheet.TAG) == null) { Bundle args = new Bundle(); @@ -354,6 +355,7 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { SplitIntervalBottomSheet splitIntervalBottomSheet = new SplitIntervalBottomSheet(); splitIntervalBottomSheet.setArguments(args); + splitIntervalBottomSheet.setTargetFragment(target, 0); splitIntervalBottomSheet.show(fragmentManager, SplitIntervalBottomSheet.TAG); } } catch (RuntimeException e) { diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java index f4e023b3cb..c8cfaa7714 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalCard.java @@ -4,6 +4,7 @@ import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -13,10 +14,12 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard; public class SplitIntervalCard extends BaseCard { private TrackDrawInfo trackDrawInfo; + private Fragment targetFragment; - public SplitIntervalCard(@NonNull MapActivity mapActivity, TrackDrawInfo trackDrawInfo) { + public SplitIntervalCard(@NonNull MapActivity mapActivity, TrackDrawInfo trackDrawInfo, Fragment targetFragment) { super(mapActivity); this.trackDrawInfo = trackDrawInfo; + this.targetFragment = targetFragment; } @Override @@ -36,7 +39,7 @@ public class SplitIntervalCard extends BaseCard { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), trackDrawInfo); + SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), trackDrawInfo, targetFragment); } }); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index e267a15dc1..0d634da7b9 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -14,6 +14,7 @@ import androidx.annotation.NonNull; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -24,9 +25,13 @@ import net.osmand.plus.base.ContextMenuFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.DirectionArrowsCard; import net.osmand.plus.myplaces.SaveGpxAsyncTask; +import net.osmand.plus.myplaces.SplitTrackAsyncTask; import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.util.Algorithms; import java.io.File; +import java.util.ArrayList; +import java.util.List; import static net.osmand.plus.track.TrackDrawInfo.TRACK_FILE_PATH; @@ -34,11 +39,40 @@ public class TrackAppearanceFragment extends ContextMenuFragment { private OsmandApplication app; + private GpxDataItem gpxDataItem; private TrackDrawInfo trackDrawInfo; private SelectedGpxFile selectedGpxFile; private int menuTitleHeight; + @Override + public int getMainLayoutId() { + return R.layout.track_appearance; + } + + @Override + public int getHeaderViewHeight() { + return menuTitleHeight; + } + + @Override + public boolean isHeaderViewDetached() { + return false; + } + + @Override + public int getToolbarHeight() { + return 0; + } + + public float getMiddleStateKoef() { + return 0.5f; + } + + public TrackDrawInfo getTrackDrawInfo() { + return trackDrawInfo; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -48,12 +82,13 @@ public class TrackAppearanceFragment extends ContextMenuFragment { if (savedInstanceState != null) { trackDrawInfo = new TrackDrawInfo(); trackDrawInfo.readBundle(savedInstanceState); + gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath())); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(trackDrawInfo.getFilePath()); } else if (arguments != null) { String gpxFilePath = arguments.getString(TRACK_FILE_PATH); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); File file = new File(selectedGpxFile.getGpxFile().path); - GpxDataItem gpxDataItem = app.getGpxDbHelper().getItem(file); + gpxDataItem = app.getGpxDbHelper().getItem(file); trackDrawInfo = new TrackDrawInfo(gpxDataItem); } } @@ -78,6 +113,14 @@ public class TrackAppearanceFragment extends ContextMenuFragment { return view; } + @Override + protected void calculateLayout(View view, boolean initLayout) { + menuTitleHeight = view.findViewById(R.id.route_menu_top_shadow_all).getHeight() + + view.findViewById(R.id.control_buttons).getHeight() + - view.findViewById(R.id.buttons_shadow).getHeight(); + super.calculateLayout(view, initLayout); + } + @Override public void onResume() { super.onResume(); @@ -136,6 +179,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment { cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + discardChanges(); dismiss(); } }); @@ -167,13 +211,57 @@ public class TrackAppearanceFragment extends ContextMenuFragment { app.getSelectedGpxHelper().updateSelectedGpxFile(selectedGpxFile); - GpxDataItem item = new GpxDataItem(new File(gpxFile.path), gpxFile); - app.getGpxDbHelper().add(item); + gpxDataItem = new GpxDataItem(new File(gpxFile.path), gpxFile); + app.getGpxDbHelper().add(gpxDataItem); saveGpx(gpxFile); } - private void saveGpx(GPXFile gpxFile) { - new SaveGpxAsyncTask(gpxFile, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + private void discardChanges() { + if (gpxDataItem.getSplitType() != trackDrawInfo.getSplitType() || gpxDataItem.getSplitInterval() != trackDrawInfo.getSplitInterval()) { + int timeSplit = (int) gpxDataItem.getSplitInterval(); + double distanceSplit = gpxDataItem.getSplitInterval(); + + GpxSplitType splitType = null; + if (gpxDataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { + splitType = GpxSplitType.DISTANCE; + } else if (gpxDataItem.getSplitType() == GpxSplitType.TIME.getType()) { + splitType = GpxSplitType.TIME; + } + if (splitType != null) { + 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); + } + } + } + + private void saveGpx(final GPXFile gpxFile) { + new SaveGpxAsyncTask(gpxFile, new SaveGpxAsyncTask.SaveGpxListener() { + @Override + public void gpxSavingStarted() { + + } + + @Override + public void gpxSavingFinished() { + app.showShortToastMessage(R.string.shared_string_track_is_saved, Algorithms.getFileWithoutDirs(gpxFile.path)); + } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } private void updateCards() { @@ -182,7 +270,7 @@ public class TrackAppearanceFragment extends ContextMenuFragment { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - BaseCard splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo); + BaseCard splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo, this); cardsContainer.addView(splitIntervalCard.build(mapActivity)); BaseCard arrowsCard = new DirectionArrowsCard(mapActivity, trackDrawInfo); @@ -196,36 +284,22 @@ public class TrackAppearanceFragment extends ContextMenuFragment { } } - @Override - public int getMainLayoutId() { - return R.layout.track_appearance; - } + private long modifiedTime = -1; + private List displayGroups; - @Override - public int getHeaderViewHeight() { - return menuTitleHeight; - } - - @Override - protected void calculateLayout(View view, boolean initLayout) { - menuTitleHeight = view.findViewById(R.id.route_menu_top_shadow_all).getHeight() - + view.findViewById(R.id.control_buttons).getHeight() - - view.findViewById(R.id.buttons_shadow).getHeight(); - super.calculateLayout(view, initLayout); - } - - @Override - public boolean isHeaderViewDetached() { - return false; - } - - @Override - public int getToolbarHeight() { - return 0; - } - - public float getMiddleStateKoef() { - return 0.5f; + public List getGpxDisplayGroups() { + GPXFile gpxFile = selectedGpxFile.getGpxFile(); + if (gpxFile == null) { + return new ArrayList<>(); + } + if (gpxFile.modifiedTime != modifiedTime) { + modifiedTime = gpxFile.modifiedTime; + displayGroups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); + if (selectedGpxFile.getDisplayGroups(app) != null) { + displayGroups = selectedGpxFile.getDisplayGroups(app); + } + } + return displayGroups; } public static boolean showInstance(@NonNull MapActivity mapActivity, TrackAppearanceFragment fragment) { From d8f7adc0232693ee4ca43f45fd2a3b3851f21af3 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 16 Jul 2020 13:33:55 +0300 Subject: [PATCH 12/20] Show track appearance fragment from track activity --- OsmAnd/res/layout/gpx_item_list_header.xml | 30 +++++++++++++++++++ .../osmand/plus/activities/MapActivity.java | 25 ++++++++++++++++ .../TrackActivityFragmentAdapter.java | 23 ++++++++++++++ .../plus/track/TrackAppearanceFragment.java | 24 +++++++++++++-- .../src/net/osmand/plus/views/GPXLayer.java | 4 +++ .../osmand/plus/views/MapControlsLayer.java | 28 ++++++++++------- 6 files changed, 120 insertions(+), 14 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_list_header.xml b/OsmAnd/res/layout/gpx_item_list_header.xml index 4cef607fb6..251eda21b6 100644 --- a/OsmAnd/res/layout/gpx_item_list_header.xml +++ b/OsmAnd/res/layout/gpx_item_list_header.xml @@ -160,6 +160,36 @@ + + + + + + + + displayGroups; private int menuTitleHeight; + private long modifiedTime = -1; @Override public int getMainLayoutId() { @@ -284,9 +294,6 @@ public class TrackAppearanceFragment extends ContextMenuFragment { } } - private long modifiedTime = -1; - private List displayGroups; - public List getGpxDisplayGroups() { GPXFile gpxFile = selectedGpxFile.getGpxFile(); if (gpxFile == null) { @@ -302,6 +309,17 @@ public class TrackAppearanceFragment extends ContextMenuFragment { return displayGroups; } + public void dismissImmediate() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + try { + mapActivity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); + } catch (Exception e) { + log.error(e); + } + } + } + public static boolean showInstance(@NonNull MapActivity mapActivity, TrackAppearanceFragment fragment) { try { mapActivity.getSupportFragmentManager() diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 43d7e18d04..8b05c2099f 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -138,6 +138,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM this.trackChartPoints = trackChartPoints; } + public boolean isInTrackAppearanceMode() { + return trackDrawInfo != null; + } + public void setTrackDrawInfo(TrackDrawInfo trackDrawInfo) { this.trackDrawInfo = trackDrawInfo; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 976bf8fd4b..52dd5cc884 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -37,15 +37,10 @@ import net.osmand.core.android.MapRendererContext; 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.settings.backend.OsmAndAppCustomization; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; -import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -63,6 +58,11 @@ import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmAndAppCustomization; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; +import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode; import net.osmand.plus.views.corenative.NativeCoreContext; import java.util.ArrayList; @@ -791,7 +791,9 @@ public class MapControlsLayer extends OsmandMapLayer { boolean routeDialogOpened = mapRouteInfoMenu.isVisible() || (showRouteCalculationControls && mapRouteInfoMenu.needShowMenu()); updateMyLocation(rh, routeDialogOpened || contextMenuOpened); boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) - && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode(); + && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() + && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode() + && !isInWaypointsChoosingMode() && !isInTrackAppearanceMode(); //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_info_dark : R.drawable.ic_action_gdirections_dark); int routePlanningBtnImage = mapRouteInfoMenu.getRoutePlanningBtnImage(); if (routePlanningBtnImage != 0) { @@ -811,10 +813,10 @@ public class MapControlsLayer extends OsmandMapLayer { menuControl.updateVisibility(showButtons); - mapZoomIn.updateVisibility(!routeDialogOpened && !contextMenuOpened && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait)); - mapZoomOut.updateVisibility(!routeDialogOpened && !contextMenuOpened && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait)); + mapZoomIn.updateVisibility(!routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode() && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait)); + mapZoomOut.updateVisibility(!routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode() && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait)); boolean forceHideCompass = routeDialogOpened || trackDialogOpened - || isInMeasurementToolMode() || isInPlanRouteMode() || contextMenuOpened || isInChoosingRoutesMode() || isInWaypointsChoosingMode(); + || isInMeasurementToolMode() || isInPlanRouteMode() || contextMenuOpened || isInChoosingRoutesMode() || isInTrackAppearanceMode() || isInWaypointsChoosingMode(); compassHud.forceHideCompass = forceHideCompass; compassHud.updateVisibility(!forceHideCompass && shouldShowCompass()); @@ -824,9 +826,9 @@ public class MapControlsLayer extends OsmandMapLayer { layersHud.update(app, isNight); } layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode() - && !contextMenuOpened && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode()); + && !contextMenuOpened && !isInChoosingRoutesMode() && !isInTrackAppearanceMode() && !isInWaypointsChoosingMode()); quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode() - && !contextMenuOpened && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode()); + && !contextMenuOpened && !isInChoosingRoutesMode() && !isInTrackAppearanceMode() && !isInWaypointsChoosingMode()); if (mapView.isZooming()) { lastZoom = System.currentTimeMillis(); @@ -1212,6 +1214,10 @@ public class MapControlsLayer extends OsmandMapLayer { return mapActivity.getMapLayers().getMapMarkersLayer().isInPlanRouteMode(); } + private boolean isInTrackAppearanceMode() { + return mapActivity.getMapLayers().getGpxLayer().isInTrackAppearanceMode(); + } + private boolean isInChoosingRoutesMode() { return MapRouteInfoMenu.chooseRoutesVisible; } From 0df0d3894b9c126b8357a498897a227c5716a4e3 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 16 Jul 2020 14:58:06 +0300 Subject: [PATCH 13/20] UI fixes first part --- OsmAnd/res/drawable/bg_dash_line_dark.xml | 6 ++ OsmAnd/res/drawable/bg_dash_line_light.xml | 6 ++ OsmAnd/res/layout/track_appearance.xml | 2 +- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/styles.xml | 2 + .../plus/track/TrackAppearanceFragment.java | 89 +++++++++++++++++-- .../net/osmand/plus/track/TrackDrawInfo.java | 55 ++++-------- .../net/osmand/plus/track/TrackWidthCard.java | 11 ++- 8 files changed, 128 insertions(+), 44 deletions(-) create mode 100644 OsmAnd/res/drawable/bg_dash_line_dark.xml create mode 100644 OsmAnd/res/drawable/bg_dash_line_light.xml diff --git a/OsmAnd/res/drawable/bg_dash_line_dark.xml b/OsmAnd/res/drawable/bg_dash_line_dark.xml new file mode 100644 index 0000000000..ac1547e5af --- /dev/null +++ b/OsmAnd/res/drawable/bg_dash_line_dark.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/OsmAnd/res/drawable/bg_dash_line_light.xml b/OsmAnd/res/drawable/bg_dash_line_light.xml new file mode 100644 index 0000000000..508cf2e78f --- /dev/null +++ b/OsmAnd/res/drawable/bg_dash_line_light.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/OsmAnd/res/layout/track_appearance.xml b/OsmAnd/res/layout/track_appearance.xml index 967501118d..1577d29817 100644 --- a/OsmAnd/res/layout/track_appearance.xml +++ b/OsmAnd/res/layout/track_appearance.xml @@ -30,7 +30,7 @@ android:layout_gravity="center" android:layout_marginTop="@dimen/context_menu_padding_margin_tiny" android:layout_marginBottom="@dimen/list_item_button_padding" - android:background="?attr/secondary_icon_color" /> + android:background="?attr/bg_dash_line" /> + diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 5b4dfd70b0..6ae9c18952 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -296,6 +296,7 @@ @dimen/action_bar_height @style/ToolbarStyle @style/ToolbarStyle + @drawable/bg_dash_line_light