From c606260def14cfc3de4017727d31509e64f73618 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Sun, 1 Nov 2020 17:38:09 +0200 Subject: [PATCH 1/3] Add favorite custom colors --- OsmAnd/res/layout/colors_card.xml | 17 ++ .../res/layout/point_editor_fragment_new.xml | 6 + .../editors/PointEditorFragmentNew.java | 62 +++-- .../cards/RouteInfoCard.java | 4 +- .../src/net/osmand/plus/track/ColorsCard.java | 243 ++++++++++++++++++ 5 files changed, 303 insertions(+), 29 deletions(-) create mode 100644 OsmAnd/res/layout/colors_card.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/ColorsCard.java diff --git a/OsmAnd/res/layout/colors_card.xml b/OsmAnd/res/layout/colors_card.xml new file mode 100644 index 0000000000..bef11dc500 --- /dev/null +++ b/OsmAnd/res/layout/colors_card.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/point_editor_fragment_new.xml b/OsmAnd/res/layout/point_editor_fragment_new.xml index 21c6396c53..36e46a6cab 100644 --- a/OsmAnd/res/layout/point_editor_fragment_new.xml +++ b/OsmAnd/res/layout/point_editor_fragment_new.xml @@ -458,6 +458,12 @@ android:layout_height="1dp" android:background="?attr/dashboard_divider" /> + + customColors; + + private int selectedColor; + + @Override + public int getCardLayoutId() { + return R.layout.colors_card; + } + + public ColorsCard(MapActivity mapActivity, int selectedColor, Fragment targetFragment, int[] colors) { + super(mapActivity); + this.targetFragment = targetFragment; + this.selectedColor = selectedColor; + this.colors = colors; + customColors = getCustomColors(); + } + + public int getSelectedColor() { + return selectedColor; + } + + public void setSelectedColor(int selectedColor) { + this.selectedColor = selectedColor; + } + + @Override + public void onColorSelected(Integer prevColor, int newColor) { + if (prevColor != null) { + int index = customColors.indexOf(prevColor); + if (index != INVALID_VALUE) { + customColors.set(index, newColor); + } + if (selectedColor == prevColor) { + selectedColor = newColor; + } + } else if (customColors.size() < MAX_CUSTOM_COLORS) { + customColors.add(newColor); + selectedColor = newColor; + } + saveCustomColors(); + updateContent(); + } + + @Override + protected void updateContent() { + createColorSelector(); + updateColorSelector(selectedColor, view); + } + + private void createColorSelector() { + FlowLayout selectColor = view.findViewById(R.id.select_color); + selectColor.removeAllViews(); + + for (int color : customColors) { + selectColor.addView(createColorItemView(color, selectColor, true)); + } + if (customColors.size() < 6) { + selectColor.addView(createAddCustomColorItemView(selectColor)); + } + selectColor.addView(createDividerView(selectColor)); + + for (int color : colors) { + selectColor.addView(createColorItemView(color, selectColor, false)); + } + updateColorSelector(selectedColor, selectColor); + } + + 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); + } + } + + private View createColorItemView(@ColorInt final int color, final FlowLayout rootView, boolean customColor) { + View colorItemView = createCircleView(rootView); + + ImageView backgroundCircle = colorItemView.findViewById(R.id.background); + + Drawable transparencyIcon = getTransparencyIcon(app, color); + Drawable colorIcon = app.getUIUtilities().getPaintedIcon(R.drawable.bg_point_circle, color); + Drawable layeredIcon = UiUtilities.getLayeredIcon(transparencyIcon, colorIcon); + double contrastRatio = ColorUtils.calculateContrast(color, ContextCompat.getColor(app, nightMode ? R.color.card_and_list_background_dark : R.color.card_and_list_background_light)); + if (contrastRatio < MINIMUM_CONTRAST_RATIO) { + backgroundCircle.setBackgroundResource(nightMode ? R.drawable.circle_contour_bg_dark : R.drawable.circle_contour_bg_light); + } + backgroundCircle.setImageDrawable(layeredIcon); + backgroundCircle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + updateColorSelector(color, rootView); + selectedColor = color; + + CardListener listener = getListener(); + if (listener != null) { + listener.onCardPressed(ColorsCard.this); + } + } + }); + if (customColor) { + backgroundCircle.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + CustomColorBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), targetFragment, color); + } + return false; + } + }); + } + colorItemView.setTag(color); + return colorItemView; + } + + private View createAddCustomColorItemView(FlowLayout rootView) { + View colorItemView = createCircleView(rootView); + ImageView backgroundCircle = colorItemView.findViewById(R.id.background); + + int bgColorId = nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light; + Drawable backgroundIcon = app.getUIUtilities().getIcon(R.drawable.bg_point_circle, bgColorId); + + ImageView icon = colorItemView.findViewById(R.id.icon); + icon.setVisibility(View.VISIBLE); + int activeColorResId = nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light; + icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, activeColorResId)); + + backgroundCircle.setImageDrawable(backgroundIcon); + backgroundCircle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + CustomColorBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), targetFragment, null); + } + } + }); + return colorItemView; + } + + private View createDividerView(FlowLayout rootView) { + LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode); + View divider = themedInflater.inflate(R.layout.simple_divider_item, rootView, false); + + LinearLayout dividerContainer = new LinearLayout(view.getContext()); + dividerContainer.addView(divider); + dividerContainer.setPadding(0, AndroidUtils.dpToPx(app, 1), 0, AndroidUtils.dpToPx(app, 5)); + + return dividerContainer; + } + + private View createCircleView(ViewGroup rootView) { + LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode); + View circleView = themedInflater.inflate(R.layout.point_editor_button, rootView, false); + ImageView outline = circleView.findViewById(R.id.outline); + int colorId = nightMode ? R.color.stroked_buttons_and_links_outline_dark : R.color.stroked_buttons_and_links_outline_light; + Drawable contourIcon = app.getUIUtilities().getIcon(R.drawable.bg_point_circle_contour, colorId); + outline.setImageDrawable(contourIcon); + return circleView; + } + + private Drawable getTransparencyIcon(OsmandApplication app, @ColorInt int color) { + int colorWithoutAlpha = UiUtilities.removeAlpha(color); + int transparencyColor = UiUtilities.getColorWithAlpha(colorWithoutAlpha, 0.8f); + return app.getUIUtilities().getPaintedIcon(R.drawable.ic_bg_transparency, transparencyColor); + } + + private List getCustomColors() { + List colors = new ArrayList<>(); + List colorNames = app.getSettings().CUSTOM_TRACK_COLORS.getStringsList(); + if (colorNames != null) { + for (String colorHex : colorNames) { + try { + if (!Algorithms.isEmpty(colorHex)) { + int color = Algorithms.parseColor(colorHex); + colors.add(color); + } + } catch (IllegalArgumentException e) { + log.error(e); + } + } + } + return colors; + } + + private void saveCustomColors() { + List colorNames = new ArrayList<>(); + for (Integer color : customColors) { + String colorHex = Algorithms.colorToString(color); + colorNames.add(colorHex); + } + app.getSettings().CUSTOM_TRACK_COLORS.setStringsList(colorNames); + } +} \ No newline at end of file From 48f81f2ccc0d5e62e01874c12ffb347ac22346f7 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 2 Nov 2020 03:36:07 +0200 Subject: [PATCH 2/3] Minor fixes --- .../res/layout/point_editor_fragment_new.xml | 10 +---- .../editors/PointEditorFragmentNew.java | 43 +++++++++---------- .../src/net/osmand/plus/track/ColorsCard.java | 4 +- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/OsmAnd/res/layout/point_editor_fragment_new.xml b/OsmAnd/res/layout/point_editor_fragment_new.xml index 36e46a6cab..9be9841750 100644 --- a/OsmAnd/res/layout/point_editor_fragment_new.xml +++ b/OsmAnd/res/layout/point_editor_fragment_new.xml @@ -444,9 +444,9 @@ osmand:typeface="@string/font_roboto_medium" /> - - - colors = new ArrayList<>(); + for (int color : ColorDialogs.pallette) { + colors.add(color); + } + int customColor = getPointColor(); + if (!ColorDialogs.isPaletteColor(customColor)) { + colors.add(customColor); + } + colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors); + colorsCard.setListener(this); + LinearLayout selectColor = view.findViewById(R.id.select_color); + selectColor.addView(colorsCard.build(view.getContext())); + } } @Override public void onColorSelected(Integer prevColor, int newColor) { - trackColoringCard.onColorSelected(prevColor, newColor); - selectedColor = trackColoringCard.getSelectedColor(); - updateColorSelector(selectedColor, view); + colorsCard.onColorSelected(prevColor, newColor); + int color = colorsCard.getSelectedColor(); + updateColorSelector(color, view); } - ColorsCard trackColoringCard; - @Override public void onCardLayoutNeeded(@NonNull BaseCard card) { @@ -487,8 +496,8 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen @Override public void onCardPressed(@NonNull BaseCard card) { if (card instanceof ColorsCard) { - selectedColor = ((ColorsCard) card).getSelectedColor(); - updateColorSelector(selectedColor, view); + int color = ((ColorsCard) card).getSelectedColor(); + updateColorSelector(color, view); } } @@ -498,16 +507,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen } 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); - } ((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color)); selectedColor = color; setColor(color); diff --git a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java index 596755c1f8..cb3c12936e 100644 --- a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java @@ -40,7 +40,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener { private Fragment targetFragment; - private int[] colors; + private List colors; private List customColors; private int selectedColor; @@ -50,7 +50,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener { return R.layout.colors_card; } - public ColorsCard(MapActivity mapActivity, int selectedColor, Fragment targetFragment, int[] colors) { + public ColorsCard(MapActivity mapActivity, int selectedColor, Fragment targetFragment, List colors) { super(mapActivity); this.targetFragment = targetFragment; this.selectedColor = selectedColor; From 3a3ea4825b3598fea4984c7ab609927d1f6731c6 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 2 Nov 2020 04:12:11 +0200 Subject: [PATCH 3/3] Remove code duplicates in custom colors --- .../src/net/osmand/plus/track/ColorsCard.java | 5 +- .../plus/track/TrackAppearanceFragment.java | 60 ++++- .../osmand/plus/track/TrackColoringCard.java | 217 +----------------- 3 files changed, 62 insertions(+), 220 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java index cb3c12936e..9fee9408c4 100644 --- a/OsmAnd/src/net/osmand/plus/track/ColorsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/ColorsCard.java @@ -8,6 +8,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.core.graphics.ColorUtils; import androidx.fragment.app.Fragment; @@ -55,7 +56,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener { this.targetFragment = targetFragment; this.selectedColor = selectedColor; this.colors = colors; - customColors = getCustomColors(); + customColors = getCustomColors(app); } public int getSelectedColor() { @@ -214,7 +215,7 @@ public class ColorsCard extends BaseCard implements ColorPickerListener { return app.getUIUtilities().getPaintedIcon(R.drawable.ic_bg_transparency, transparencyColor); } - private List getCustomColors() { + public static List getCustomColors(@NonNull OsmandApplication app) { List colors = new ArrayList<>(); List colorNames = app.getSettings().CUSTOM_TRACK_COLORS.getStringsList(); if (colorNames != null) { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 0c7cfce551..f8a9ebbfc3 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -38,6 +38,8 @@ import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.ContextMenuScrollFragment; import net.osmand.plus.dialogs.GpxAppearanceAdapter; +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.routepreparationmenu.cards.BaseCard.CardListener; @@ -58,6 +60,7 @@ import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; +import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener { @@ -80,6 +83,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement private TrackWidthCard trackWidthCard; private SplitIntervalCard splitIntervalCard; private TrackColoringCard trackColoringCard; + private ColorsCard colorsCard; private boolean showStartFinishIconsInitialValue; private ImageView trackIcon; @@ -339,7 +343,9 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement if (mapActivity != null) { if (card instanceof SplitIntervalCard) { SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), trackDrawInfo, this); - } else if (card instanceof TrackColoringCard) { + } else if (card instanceof ColorsCard) { + int color = ((ColorsCard) card).getSelectedColor(); + trackDrawInfo.setColor(color); updateColorItems(); } else if (card instanceof TrackWidthCard) { updateAppearanceIcon(); @@ -356,7 +362,15 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement @Override public void onColorSelected(Integer prevColor, int newColor) { - trackColoringCard.onColorSelected(prevColor, newColor); + if (prevColor != null) { + List customColors = ColorsCard.getCustomColors(app); + int index = customColors.indexOf(prevColor); + if (index != ColorsCard.INVALID_VALUE) { + saveCustomColorsToTracks(prevColor, newColor); + } + } + trackDrawInfo.setColor(newColor); + colorsCard.onColorSelected(prevColor, newColor); updateColorItems(); } @@ -475,6 +489,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement AndroidUiHelper.updateVisibility(saveButton, true); AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true); } + private void showShadowButton() { buttonsShadow.setVisibility(View.VISIBLE); buttonsShadow.animate() @@ -511,11 +526,30 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement AndroidUiHelper.updateVisibility(buttonsShadow, scrollToBottomAvailable); } + private void saveCustomColorsToTracks(int prevColor, int newColor) { + List gpxDataItems = app.getGpxDbHelper().getItems(); + for (GpxDataItem dataItem : gpxDataItems) { + if (prevColor == dataItem.getColor()) { + app.getGpxDbHelper().updateColor(dataItem, newColor); + } + } + List files = app.getSelectedGpxHelper().getSelectedGPXFiles(); + for (SelectedGpxFile selectedGpxFile : files) { + if (prevColor == selectedGpxFile.getGpxFile().getColor(0)) { + selectedGpxFile.getGpxFile().setColor(newColor); + } + } + } + private void updateColorItems() { updateAppearanceIcon(); if (trackWidthCard != null) { trackWidthCard.updateItems(); } + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.refreshMap(); + } } private void saveTrackInfo() { @@ -627,6 +661,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement trackColoringCard.setListener(this); cardsContainer.addView(trackColoringCard.build(mapActivity)); + setupColorsCard(cardsContainer); + trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo, new OnNeedScrollListener() { @Override @@ -647,6 +683,26 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement } } + private void setupColorsCard(ViewGroup cardsContainer) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + List colors = getTrackColors(); + colorsCard = new ColorsCard(mapActivity, trackDrawInfo.getColor(), this, colors); + colorsCard.setListener(this); + cardsContainer.addView(colorsCard.build(mapActivity)); + } + } + + private List getTrackColors() { + List colors = new ArrayList<>(); + for (AppearanceListItem appearanceListItem : getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { + if (!colors.contains(appearanceListItem.getColor())) { + colors.add(appearanceListItem.getColor()); + } + } + return colors; + } + public List getGpxDisplayGroups() { GPXFile gpxFile = selectedGpxFile.getGpxFile(); if (gpxFile == null) { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index 99571dad6c..0a17f5e06b 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -1,53 +1,36 @@ package net.osmand.plus.track; -import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.ColorInt; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; import androidx.core.content.ContextCompat; -import androidx.core.graphics.ColorUtils; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.internal.FlowLayout; - import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; -import net.osmand.plus.GPXDatabase.GpxDataItem; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dialogs.GpxAppearanceAdapter; -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.track.CustomColorBottomSheet.ColorPickerListener; -import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.util.ArrayList; import java.util.List; -public class TrackColoringCard extends BaseCard implements ColorPickerListener { +public class TrackColoringCard extends BaseCard { private static final int MINIMUM_CONTRAST_RATIO = 3; - public static final int INVALID_VALUE = -1; - private final static String SOLID_COLOR = "solid_color"; private static final Log log = PlatformUtil.getLog(TrackColoringCard.class); @@ -57,7 +40,6 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { private TrackAppearanceItem selectedAppearanceItem; private List appearanceItems; - private List customColors; private Fragment target; public TrackColoringCard(MapActivity mapActivity, TrackDrawInfo trackDrawInfo, Fragment target) { @@ -65,7 +47,6 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { this.target = target; this.trackDrawInfo = trackDrawInfo; appearanceItems = getGradientAppearanceItems(); - customColors = getCustomColors(); } @Override @@ -76,8 +57,6 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { @Override protected void updateContent() { updateHeader(); - createColorSelector(); - updateColorSelector(); // coloringAdapter = new TrackColoringAdapter(appearanceItems); // RecyclerView groupRecyclerView = view.findViewById(R.id.recycler_view); @@ -87,25 +66,6 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { AndroidUiHelper.updateVisibility(view.findViewById(R.id.top_divider), isShowDivider()); } - private List getCustomColors() { - List colors = new ArrayList<>(); - List colorNames = app.getSettings().CUSTOM_TRACK_COLORS.getStringsList(); - if (colorNames != null) { - for (String colorHex : colorNames) { - try { - if (!Algorithms.isEmpty(colorHex)) { - int color = Algorithms.parseColor(colorHex); - colors.add(color); - } - } catch (IllegalArgumentException e) { - log.error(e); - } - } - } - - return colors; - } - private List getGradientAppearanceItems() { List items = new ArrayList<>(); items.add(new TrackAppearanceItem(SOLID_COLOR, app.getString(R.string.track_coloring_solid), R.drawable.ic_action_circle)); @@ -117,138 +77,6 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { return items; } - private void createColorSelector() { - FlowLayout selectColor = view.findViewById(R.id.select_color); - selectColor.removeAllViews(); - - for (int color : customColors) { - selectColor.addView(createColorItemView(color, selectColor, true)); - } - if (customColors.size() < 6) { - selectColor.addView(createAddCustomColorItemView(selectColor)); - } - selectColor.addView(createDividerView(selectColor)); - - List colors = new ArrayList<>(); - for (AppearanceListItem appearanceListItem : GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { - if (!colors.contains(appearanceListItem.getColor())) { - colors.add(appearanceListItem.getColor()); - } - } - for (int color : colors) { - selectColor.addView(createColorItemView(color, selectColor, false)); - } - updateColorSelector(trackDrawInfo.getColor(), selectColor); - } - - private View createColorItemView(@ColorInt final int color, final FlowLayout rootView, boolean customColor) { - View colorItemView = createCircleView(rootView); - - ImageView backgroundCircle = colorItemView.findViewById(R.id.background); - - Drawable transparencyIcon = getTransparencyIcon(app, color); - Drawable colorIcon = app.getUIUtilities().getPaintedIcon(R.drawable.bg_point_circle, color); - Drawable layeredIcon = UiUtilities.getLayeredIcon(transparencyIcon, colorIcon); - double contrastRatio = ColorUtils.calculateContrast(color, ContextCompat.getColor(app, nightMode ? R.color.card_and_list_background_dark : R.color.card_and_list_background_light)); - if (contrastRatio < MINIMUM_CONTRAST_RATIO) { - backgroundCircle.setBackgroundResource(nightMode ? R.drawable.circle_contour_bg_dark : R.drawable.circle_contour_bg_light); - } - backgroundCircle.setImageDrawable(layeredIcon); - backgroundCircle.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - updateColorSelector(color, rootView); -// coloringAdapter.notifyDataSetChanged(); - trackDrawInfo.setColor(color); - - CardListener listener = getListener(); - if (listener != null) { - listener.onCardPressed(TrackColoringCard.this); - } - } - }); - if (customColor) { - backgroundCircle.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - CustomColorBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), target, color); - } - return false; - } - }); - } - colorItemView.setTag(color); - return colorItemView; - } - - private Drawable getTransparencyIcon(OsmandApplication app, @ColorInt int color) { - int colorWithoutAlpha = UiUtilities.removeAlpha(color); - int transparencyColor = UiUtilities.getColorWithAlpha(colorWithoutAlpha, 0.8f); - return app.getUIUtilities().getPaintedIcon(R.drawable.ic_bg_transparency, transparencyColor); - } - - private View createAddCustomColorItemView(FlowLayout rootView) { - View colorItemView = createCircleView(rootView); - ImageView backgroundCircle = colorItemView.findViewById(R.id.background); - - int bgColorId = nightMode ? R.color.activity_background_color_dark : R.color.activity_background_color_light; - Drawable backgroundIcon = app.getUIUtilities().getIcon(R.drawable.bg_point_circle, bgColorId); - - ImageView icon = colorItemView.findViewById(R.id.icon); - icon.setVisibility(View.VISIBLE); - int activeColorResId = nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light; - icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_plus, activeColorResId)); - - backgroundCircle.setImageDrawable(backgroundIcon); - backgroundCircle.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - CustomColorBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), target, null); - } - } - }); - return colorItemView; - } - - private View createDividerView(FlowLayout rootView) { - LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode); - View divider = themedInflater.inflate(R.layout.simple_divider_item, rootView, false); - - LinearLayout dividerContainer = new LinearLayout(view.getContext()); - dividerContainer.addView(divider); - dividerContainer.setPadding(0, AndroidUtils.dpToPx(app, 1), 0, AndroidUtils.dpToPx(app, 5)); - - return dividerContainer; - } - - private View createCircleView(ViewGroup rootView) { - LayoutInflater themedInflater = UiUtilities.getInflater(view.getContext(), nightMode); - View circleView = themedInflater.inflate(R.layout.point_editor_button, rootView, false); - ImageView outline = circleView.findViewById(R.id.outline); - int colorId = nightMode ? R.color.stroked_buttons_and_links_outline_dark : R.color.stroked_buttons_and_links_outline_light; - Drawable contourIcon = app.getUIUtilities().getIcon(R.drawable.bg_point_circle_contour, colorId); - outline.setImageDrawable(contourIcon); - return circleView; - } - - private void updateColorSelector(int color, View rootView) { - View oldColor = rootView.findViewWithTag(trackDrawInfo.getColor()); - 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); - } - mapActivity.refreshMap(); - } - private TrackAppearanceItem getSelectedAppearanceItem() { if (selectedAppearanceItem == null) { GradientScaleType scaleType = trackDrawInfo.getGradientScaleType(); @@ -293,49 +121,6 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener { updateColorSelector(); } - @Override - public void onColorSelected(Integer prevColor, int newColor) { - if (prevColor != null) { - int index = customColors.indexOf(prevColor); - if (index != INVALID_VALUE) { - customColors.set(index, newColor); - saveCustomColorsToTracks(prevColor, newColor); - } - if (trackDrawInfo.getColor() == prevColor) { - trackDrawInfo.setColor(newColor); - } - } else if (customColors.size() < 6) { - customColors.add(newColor); - trackDrawInfo.setColor(newColor); - } - saveCustomColors(); - updateContent(); - } - - private void saveCustomColorsToTracks(int prevColor, int newColor) { - List gpxDataItems = app.getGpxDbHelper().getItems(); - for (GpxDataItem dataItem : gpxDataItems) { - if (prevColor == dataItem.getColor()) { - app.getGpxDbHelper().updateColor(dataItem, newColor); - } - } - List files = app.getSelectedGpxHelper().getSelectedGPXFiles(); - for (SelectedGpxFile selectedGpxFile : files) { - if (prevColor == selectedGpxFile.getGpxFile().getColor(0)) { - selectedGpxFile.getGpxFile().setColor(newColor); - } - } - } - - private void saveCustomColors() { - List colorNames = new ArrayList<>(); - for (Integer color : customColors) { - String colorHex = Algorithms.colorToString(color); - colorNames.add(colorHex); - } - app.getSettings().CUSTOM_TRACK_COLORS.setStringsList(colorNames); - } - private class TrackColoringAdapter extends RecyclerView.Adapter { private List items;