This commit is contained in:
max-klaus 2020-09-28 18:10:15 +03:00
parent 735cfb3dce
commit e1086074c5
9 changed files with 145 additions and 37 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="start_finish_icons">Start/finish icons</string>
<string name="sort_name_ascending">Name: A Z</string> <string name="sort_name_ascending">Name: A Z</string>
<string name="sort_name_descending">Name: Z A</string> <string name="sort_name_descending">Name: Z A</string>
<string name="sort_last_modified">Last modified</string> <string name="sort_last_modified">Last modified</string>

View file

@ -25,10 +25,13 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
public static final String TRACK_WIDTH_BOLD = "bold"; public static final String TRACK_WIDTH_BOLD = "bold";
public static final String TRACK_WIDTH_MEDIUM = "medium"; public static final String TRACK_WIDTH_MEDIUM = "medium";
public static final String SHOW_START_FINISH_ATTR = "show_start_finish_attr";
private OsmandApplication app; private OsmandApplication app;
private GpxAppearanceAdapterType adapterType; private GpxAppearanceAdapterType adapterType;
private int currentColor; private int currentColor;
private boolean showStartFinishIcons;
private boolean nightMode;
public enum GpxAppearanceAdapterType { public enum GpxAppearanceAdapterType {
TRACK_WIDTH, TRACK_WIDTH,
@ -36,20 +39,15 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
TRACK_WIDTH_COLOR TRACK_WIDTH_COLOR
} }
public GpxAppearanceAdapter(Context context, String currentColorValue, GpxAppearanceAdapterType adapterType) { public GpxAppearanceAdapter(Context context, String currentColorValue, GpxAppearanceAdapterType adapterType,
boolean showStartFinishIcons, boolean nightMode) {
super(context, R.layout.rendering_prop_menu_item); super(context, R.layout.rendering_prop_menu_item);
this.app = (OsmandApplication) context.getApplicationContext(); this.app = (OsmandApplication) context.getApplicationContext();
this.adapterType = adapterType; this.adapterType = adapterType;
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer(); RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
this.currentColor = parseTrackColor(renderer, currentColorValue); this.currentColor = parseTrackColor(renderer, currentColorValue);
init(); this.showStartFinishIcons = showStartFinishIcons;
} this.nightMode = nightMode;
public GpxAppearanceAdapter(Context context, int currentColor, GpxAppearanceAdapterType adapterType) {
super(context, R.layout.rendering_prop_menu_item);
this.app = (OsmandApplication) context.getApplicationContext();
this.adapterType = adapterType;
this.currentColor = currentColor;
init(); init();
} }
@ -58,8 +56,9 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
public View getView(int position, View convertView, @NonNull ViewGroup parent) { public View getView(int position, View convertView, @NonNull ViewGroup parent) {
AppearanceListItem item = getItem(position); AppearanceListItem item = getItem(position);
View v = convertView; View v = convertView;
Context context = getContext();
if (v == null) { if (v == null) {
v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null); v = LayoutInflater.from(context).inflate(R.layout.rendering_prop_menu_item, null);
} }
if (item != null) { if (item != null) {
TextView textView = (TextView) v.findViewById(R.id.text1); TextView textView = (TextView) v.findViewById(R.id.text1);
@ -68,7 +67,7 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
int iconId = getWidthIconId(item.value); int iconId = getWidthIconId(item.value);
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getPaintedIcon(iconId, currentColor), null); app.getUIUtilities().getPaintedIcon(iconId, currentColor), null);
} else { } else if (ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR.equals(item.attrName)) {
if (item.color == -1) { if (item.color == -1) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null); app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null);
@ -76,8 +75,12 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null); app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null);
} }
} else if (SHOW_START_FINISH_ATTR.equals(item.attrName)) {
int iconId = showStartFinishIcons ? R.drawable.ic_check_box_dark : R.drawable.ic_check_box_outline_dark;
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, app.getUIUtilities().getIcon(iconId,
nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light), null);
} }
textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f)); textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(context, 10f));
v.findViewById(R.id.divider).setVisibility(item.lastItem v.findViewById(R.id.divider).setVisibility(item.lastItem
&& position < getCount() - 1 ? View.VISIBLE : View.GONE); && position < getCount() - 1 ? View.VISIBLE : View.GONE);
} }
@ -95,10 +98,15 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
} }
private void init() { private void init() {
addAll(getAppearanceItems(app, adapterType)); addAll(getAppearanceItems(app, adapterType, showStartFinishIcons));
} }
public static List<AppearanceListItem> getAppearanceItems(OsmandApplication app, GpxAppearanceAdapterType adapterType) { public static List<AppearanceListItem> getAppearanceItems(OsmandApplication app, GpxAppearanceAdapterType adapterType) {
return getAppearanceItems(app, adapterType, false);
}
public static List<AppearanceListItem> getAppearanceItems(OsmandApplication app, GpxAppearanceAdapterType adapterType,
boolean showStartFinishIcons) {
List<AppearanceListItem> items = new ArrayList<>(); List<AppearanceListItem> items = new ArrayList<>();
RenderingRuleProperty trackWidthProp = null; RenderingRuleProperty trackWidthProp = null;
RenderingRuleProperty trackColorProp = null; RenderingRuleProperty trackColorProp = null;
@ -118,11 +126,19 @@ public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.Appe
trackWidthProp.getPossibleValues()[j], trackWidthProp.getPossibleValues()[j],
SettingsActivity.getStringPropertyValue(app, trackWidthProp.getPossibleValues()[j])); SettingsActivity.getStringPropertyValue(app, trackWidthProp.getPossibleValues()[j]));
items.add(item); items.add(item);
if (adapterType != GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) {
if (j == trackWidthProp.getPossibleValues().length - 1) { if (j == trackWidthProp.getPossibleValues().length - 1) {
item.setLastItem(true); item.setLastItem(true);
} }
} }
} }
}
if (adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) {
AppearanceListItem startFinishIconsitem = new AppearanceListItem(SHOW_START_FINISH_ATTR,
showStartFinishIcons ? "false" : "true", app.getString(R.string.start_finish_icons));
items.add(startFinishIconsitem);
startFinishIconsitem.setLastItem(true);
}
if (trackColorProp != null) { if (trackColorProp != null) {
for (int j = 0; j < trackColorProp.getPossibleValues().length; j++) { for (int j = 0; j < trackColorProp.getPossibleValues().length; j++) {
AppearanceListItem item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR, AppearanceListItem item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR,

View file

@ -125,6 +125,7 @@ import static net.osmand.plus.OsmAndFormatter.YARDS_IN_ONE_METER;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT; import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR; import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.SHOW_START_FINISH_ATTR;
public class GpxUiHelper { public class GpxUiHelper {
@ -532,7 +533,8 @@ public class GpxUiHelper {
popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f)); popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f));
final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(new ContextThemeWrapper(activity, themeRes), final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(new ContextThemeWrapper(activity, themeRes),
gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get(), gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get(),
GpxAppearanceAdapter.GpxAppearanceAdapterType.TRACK_WIDTH_COLOR); GpxAppearanceAdapter.GpxAppearanceAdapterType.TRACK_WIDTH_COLOR,
gpxAppearanceParams.containsKey(SHOW_START_FINISH_ATTR) ? "true".equals(gpxAppearanceParams.get(SHOW_START_FINISH_ATTR)) : app.getSettings().SHOW_START_FINISH_ICONS.get(), nightMode);
popup.setAdapter(gpxApprAdapter); popup.setAdapter(gpxApprAdapter);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -544,6 +546,8 @@ public class GpxUiHelper {
gpxAppearanceParams.put(CURRENT_TRACK_WIDTH_ATTR, item.getValue()); gpxAppearanceParams.put(CURRENT_TRACK_WIDTH_ATTR, item.getValue());
} else if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) { } else if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) {
gpxAppearanceParams.put(CURRENT_TRACK_COLOR_ATTR, item.getValue()); gpxAppearanceParams.put(CURRENT_TRACK_COLOR_ATTR, item.getValue());
} else if (SHOW_START_FINISH_ATTR.equals(item.getAttrName())) {
gpxAppearanceParams.put(SHOW_START_FINISH_ATTR, item.getValue());
} }
} }
popup.dismiss(); popup.dismiss();
@ -567,10 +571,14 @@ public class GpxUiHelper {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (gpxAppearanceParams.size() > 0) { if (gpxAppearanceParams.size() > 0) {
for (Map.Entry<String, String> entry : gpxAppearanceParams.entrySet()) { for (Map.Entry<String, String> entry : gpxAppearanceParams.entrySet()) {
if (SHOW_START_FINISH_ATTR.equals(entry.getKey())) {
app.getSettings().SHOW_START_FINISH_ICONS.set("true".equals(entry.getValue()));
} else {
final OsmandSettings.CommonPreference<String> pref final OsmandSettings.CommonPreference<String> pref
= app.getSettings().getCustomRenderProperty(entry.getKey()); = app.getSettings().getCustomRenderProperty(entry.getKey());
pref.set(entry.getValue()); pref.set(entry.getValue());
} }
}
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
ConfigureMapMenu.refreshMapComplete((MapActivity) activity); ConfigureMapMenu.refreshMapComplete((MapActivity) activity);
} }

View file

@ -2214,6 +2214,8 @@ public class OsmandSettings {
} }
}.makeProfile().cache(); }.makeProfile().cache();
public final OsmandPreference<Boolean> SHOW_START_FINISH_ICONS = new BooleanPreference("show_start_finish_icons", true).makeGlobal().cache();
public final OsmandPreference<Boolean> GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
// public final OsmandPreference<Boolean> GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", true).makeGlobal().cache(); // public final OsmandPreference<Boolean> GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", true).makeGlobal().cache();
public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();

View file

@ -0,0 +1,59 @@
package net.osmand.plus.track;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
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 net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
class ShowStartFinishCard extends BaseCard {
private TrackDrawInfo trackDrawInfo;
private OsmandPreference<Boolean> showStartFinishPreference;
public ShowStartFinishCard(@NonNull MapActivity mapActivity, @NonNull TrackDrawInfo trackDrawInfo) {
super(mapActivity);
this.showStartFinishPreference = app.getSettings().SHOW_START_FINISH_ICONS;
this.trackDrawInfo = trackDrawInfo;
}
@Override
public int getCardLayoutId() {
return R.layout.bottom_sheet_item_with_switch;
}
@Override
protected void updateContent() {
AndroidUiHelper.updateVisibility(view.findViewById(R.id.icon), false);
TextView titleView = view.findViewById(R.id.title);
titleView.setText(R.string.track_show_start_finish_icons);
final CompoundButton compoundButton = view.findViewById(R.id.compound_button);
//compoundButton.setChecked(trackDrawInfo.isShowStartFinish());
compoundButton.setChecked(showStartFinishPreference.get());
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = !compoundButton.isChecked();
compoundButton.setChecked(checked);
//trackDrawInfo.setShowStartFinish(checked);
showStartFinishPreference.set(checked);
mapActivity.refreshMap();
CardListener listener = getListener();
if (listener != null) {
listener.onCardPressed(ShowStartFinishCard.this);
}
}
});
}
}

View file

@ -62,9 +62,10 @@ import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM;
public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener { public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener {
public static final String TAG = TrackAppearanceFragment.class.getName(); public static final String TAG = TrackAppearanceFragment.class.getName();
private static final Log log = PlatformUtil.getLog(TrackAppearanceFragment.class); private static final Log log = PlatformUtil.getLog(TrackAppearanceFragment.class);
private static final String SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY = "showStartFinishIconsInitialValueKey";
private OsmandApplication app; private OsmandApplication app;
@Nullable @Nullable
@ -79,6 +80,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
private TrackWidthCard trackWidthCard; private TrackWidthCard trackWidthCard;
private SplitIntervalCard splitIntervalCard; private SplitIntervalCard splitIntervalCard;
private TrackColoringCard trackColoringCard; private TrackColoringCard trackColoringCard;
private boolean showStartFinishIconsInitialValue;
private ImageView trackIcon; private ImageView trackIcon;
private View buttonsShadow; private View buttonsShadow;
@ -134,9 +136,12 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (!selectedGpxFile.isShowCurrentTrack()) { if (!selectedGpxFile.isShowCurrentTrack()) {
gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath())); gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath()));
} }
showStartFinishIconsInitialValue = savedInstanceState.getBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY,
app.getSettings().SHOW_START_FINISH_ICONS.get());
} else if (arguments != null) { } else if (arguments != null) {
String gpxFilePath = arguments.getString(TRACK_FILE_NAME); String gpxFilePath = arguments.getString(TRACK_FILE_NAME);
boolean currentRecording = arguments.getBoolean(CURRENT_RECORDING, false); boolean currentRecording = arguments.getBoolean(CURRENT_RECORDING, false);
showStartFinishIconsInitialValue = app.getSettings().SHOW_START_FINISH_ICONS.get();
if (gpxFilePath == null && !currentRecording) { if (gpxFilePath == null && !currentRecording) {
log.error("Required extra '" + TRACK_FILE_NAME + "' is missing"); log.error("Required extra '" + TRACK_FILE_NAME + "' is missing");
@ -152,7 +157,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else { } else {
gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath)); gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath));
trackDrawInfo = new TrackDrawInfo(gpxDataItem, false); trackDrawInfo = new TrackDrawInfo(app, gpxDataItem, false);
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath);
} }
updateTrackColor(); updateTrackColor();
@ -294,6 +299,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
public void onSaveInstanceState(@NonNull Bundle outState) { public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
trackDrawInfo.saveToBundle(outState); trackDrawInfo.saveToBundle(outState);
outState.putBoolean(SHOW_START_FINISH_ICONS_INITIAL_VALUE_KEY, showStartFinishIconsInitialValue);
} }
@Override @Override
@ -455,6 +461,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
@Override @Override
public void onClick(View v) { public void onClick(View v) {
discardSplitChanges(); discardSplitChanges();
discardShowStartFinishChanges();
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
activity.onBackPressed(); activity.onBackPressed();
@ -520,7 +527,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval()); gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval());
gpxFile.setShowArrows(trackDrawInfo.isShowArrows()); gpxFile.setShowArrows(trackDrawInfo.isShowArrows());
gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish()); //gpxFile.setShowStartFinish(trackDrawInfo.isShowStartFinish());
if (gpxFile.showCurrentTrack) { if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor()); app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor());
@ -551,6 +558,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
} }
} }
private void discardShowStartFinishChanges() {
app.getSettings().SHOW_START_FINISH_ICONS.set(showStartFinishIconsInitialValue);
}
void applySplit(GpxSplitType splitType, int timeSplit, double distanceSplit) { void applySplit(GpxSplitType splitType, int timeSplit, double distanceSplit) {
if (splitIntervalCard != null) { if (splitIntervalCard != null) {
splitIntervalCard.updateContent(); splitIntervalCard.updateContent();
@ -599,6 +610,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
directionArrowsCard.setListener(this); directionArrowsCard.setListener(this);
cardsContainer.addView(directionArrowsCard.build(mapActivity)); cardsContainer.addView(directionArrowsCard.build(mapActivity));
ShowStartFinishCard showStartFinishCard = new ShowStartFinishCard(mapActivity, trackDrawInfo);
showStartFinishCard.setListener(this);
cardsContainer.addView(showStartFinishCard.build(mapActivity));
trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo, this); trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo, this);
trackColoringCard.setListener(this); trackColoringCard.setListener(this);
cardsContainer.addView(trackColoringCard.build(mapActivity)); cardsContainer.addView(trackColoringCard.build(mapActivity));

View file

@ -29,6 +29,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; 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.AppearanceListItem;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType; import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
@ -41,8 +42,6 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems;
public class TrackColoringCard extends BaseCard implements ColorPickerListener { public class TrackColoringCard extends BaseCard implements ColorPickerListener {
private static final int MINIMUM_CONTRAST_RATIO = 3; private static final int MINIMUM_CONTRAST_RATIO = 3;
@ -131,7 +130,7 @@ public class TrackColoringCard extends BaseCard implements ColorPickerListener {
selectColor.addView(createDividerView(selectColor)); selectColor.addView(createDividerView(selectColor));
List<Integer> colors = new ArrayList<>(); List<Integer> colors = new ArrayList<>();
for (AppearanceListItem appearanceListItem : getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { for (AppearanceListItem appearanceListItem : GpxAppearanceAdapter.getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) {
if (!colors.contains(appearanceListItem.getColor())) { if (!colors.contains(appearanceListItem.getColor())) {
colors.add(appearanceListItem.getColor()); colors.add(appearanceListItem.getColor());
} }

View file

@ -5,6 +5,7 @@ import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING; import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
@ -40,7 +41,7 @@ public class TrackDrawInfo {
readBundle(bundle); readBundle(bundle);
} }
public TrackDrawInfo(GpxDataItem gpxDataItem, boolean currentRecording) { public TrackDrawInfo(@NonNull OsmandApplication app, @NonNull GpxDataItem gpxDataItem, boolean currentRecording) {
filePath = gpxDataItem.getFile().getPath(); filePath = gpxDataItem.getFile().getPath();
width = gpxDataItem.getWidth(); width = gpxDataItem.getWidth();
gradientScaleType = gpxDataItem.getGradientScaleType(); gradientScaleType = gpxDataItem.getGradientScaleType();

View file

@ -453,7 +453,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
if (segment.points.size() >= 2) { if (segment.points.size() >= 2) {
WptPt start = segment.points.get(0); WptPt start = segment.points.get(0);
WptPt end = segment.points.get(segment.points.size() - 1); WptPt end = segment.points.get(segment.points.size() - 1);
drawStartEndPoints(canvas, tileBox, start, end); drawStartEndPoints(canvas, tileBox, start, selectedGpxFile.isShowCurrentTrack() ? null : end);
} }
} }
} }
@ -461,26 +461,30 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
} }
private void drawStartEndPoints(Canvas canvas, RotatedTileBox tileBox, WptPt start, WptPt end) { private void drawStartEndPoints(@NonNull Canvas canvas, @NonNull RotatedTileBox tileBox, @Nullable WptPt start, @Nullable WptPt end) {
int startX = (int) tileBox.getPixXFromLatLon(start.lat, start.lon); int startX = start != null ? (int) tileBox.getPixXFromLatLon(start.lat, start.lon) : 0;
int startY = (int) tileBox.getPixYFromLatLon(start.lat, start.lon); int startY = start != null ? (int) tileBox.getPixYFromLatLon(start.lat, start.lon) : 0;
int endX = (int) tileBox.getPixXFromLatLon(end.lat, end.lon); int endX = end != null ? (int) tileBox.getPixXFromLatLon(end.lat, end.lon) : 0;
int endY = (int) tileBox.getPixYFromLatLon(end.lat, end.lon); int endY = end != null ? (int) tileBox.getPixYFromLatLon(end.lat, end.lon) : 0;
int iconSize = AndroidUtils.dpToPx(view.getContext(), 14); int iconSize = AndroidUtils.dpToPx(view.getContext(), 14);
QuadRect startRectWithoutShadow = calculateRect(startX, startY, iconSize, iconSize); QuadRect startRectWithoutShadow = calculateRect(startX, startY, iconSize, iconSize);
QuadRect endRectWithoutShadow = calculateRect(endX, endY, iconSize, iconSize); QuadRect endRectWithoutShadow = calculateRect(endX, endY, iconSize, iconSize);
if (QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) { if (start != null && end != null && QuadRect.intersects(startRectWithoutShadow, endRectWithoutShadow)) {
QuadRect startAndFinishRect = calculateRect(startX, startY, startAndFinishIcon.getIntrinsicWidth(), startAndFinishIcon.getIntrinsicHeight()); QuadRect startAndFinishRect = calculateRect(startX, startY, startAndFinishIcon.getIntrinsicWidth(), startAndFinishIcon.getIntrinsicHeight());
drawPoint(canvas, startAndFinishRect, startAndFinishIcon); drawPoint(canvas, startAndFinishRect, startAndFinishIcon);
} else { } else {
if (start != null) {
QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight()); QuadRect startRect = calculateRect(startX, startY, startPointIcon.getIntrinsicWidth(), startPointIcon.getIntrinsicHeight());
QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight());
drawPoint(canvas, startRect, startPointIcon); drawPoint(canvas, startRect, startPointIcon);
}
if (end != null) {
QuadRect endRect = calculateRect(endX, endY, finishPointIcon.getIntrinsicWidth(), finishPointIcon.getIntrinsicHeight());
drawPoint(canvas, endRect, finishPointIcon); drawPoint(canvas, endRect, finishPointIcon);
} }
} }
}
private void drawPoint(Canvas canvas, QuadRect rect, Drawable icon) { private void drawPoint(Canvas canvas, QuadRect rect, Drawable icon) {
icon.setBounds((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom); icon.setBounds((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom);
@ -711,6 +715,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
private boolean isShowStartFinishForTrack(GPXFile gpxFile) { private boolean isShowStartFinishForTrack(GPXFile gpxFile) {
return view.getApplication().getSettings().SHOW_START_FINISH_ICONS.get();
/*
if (hasTrackDrawInfoForTrack(gpxFile)) { if (hasTrackDrawInfoForTrack(gpxFile)) {
return trackDrawInfo.isShowStartFinish(); return trackDrawInfo.isShowStartFinish();
} else if (gpxFile.showCurrentTrack) { } else if (gpxFile.showCurrentTrack) {
@ -718,6 +724,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} else { } else {
return gpxFile.isShowStartFinish(); return gpxFile.isShowStartFinish();
} }
*/
} }
private boolean hasTrackDrawInfoForTrack(GPXFile gpxFile) { private boolean hasTrackDrawInfoForTrack(GPXFile gpxFile) {