From d88bf79930c54355d1aa2824a4b559b302280f05 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 13 Jul 2020 19:17:34 +0300 Subject: [PATCH] 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