Add new track appearance prefs for current recording track

This commit is contained in:
Vitaliy 2020-07-30 21:34:57 +03:00
parent 7567a1b3ae
commit dd40c4dce6
5 changed files with 143 additions and 94 deletions

View file

@ -50,7 +50,7 @@
osmand:typeface="@string/font_roboto_medium" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/appearance_icon"
android:id="@+id/track_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
@ -94,7 +94,8 @@
android:id="@+id/map_controls_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
android:layout_gravity="bottom"
tools:visibility="invisible">
<include
layout="@layout/map_ruler"
@ -104,8 +105,7 @@
android:layout_marginStart="@dimen/fab_margin_right"
android:layout_marginLeft="@dimen/fab_margin_right"
android:layout_marginEnd="@dimen/fab_margin_right"
android:layout_marginRight="@dimen/fab_margin_right"
tools:visibility="invisible" />
android:layout_marginRight="@dimen/fab_margin_right" />
<include
layout="@layout/map_hud_controls"
@ -115,8 +115,7 @@
android:layout_marginStart="@dimen/fab_margin_right"
android:layout_marginLeft="@dimen/fab_margin_right"
android:layout_marginEnd="@dimen/fab_margin_right"
android:layout_marginRight="@dimen/fab_margin_right"
tools:visibility="invisible" />
android:layout_marginRight="@dimen/fab_margin_right" />
</FrameLayout>

View file

@ -2194,6 +2194,9 @@ public class OsmandSettings {
public final OsmandPreference<Long> LAST_UPDATES_CARD_REFRESH = new LongPreference("last_updates_card_refresh", 0).makeGlobal();
public final CommonPreference<Integer> CURRENT_TRACK_COLOR = new IntPreference("current_track_color", 0).makeGlobal().cache();
public final CommonPreference<String> CURRENT_TRACK_WIDTH = new StringPreference("current_track_width", "").makeGlobal().cache();
public final CommonPreference<Boolean> CURRENT_TRACK_SHOW_ARROWS = new BooleanPreference("current_track_show_arrows", false).makeGlobal().cache();
public final CommonPreference<Boolean> CURRENT_TRACK_SHOW_START_FINISH = new BooleanPreference("current_track_show_start_finish", true).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile();

View file

@ -9,9 +9,11 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@ -74,7 +76,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
private TrackWidthCard trackWidthCard;
private SplitIntervalCard splitIntervalCard;
private ImageView appearanceIcon;
private ImageView trackIcon;
@Override
public int getMainLayoutId() {
@ -131,6 +133,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
if (currentRecording) {
trackDrawInfo = new TrackDrawInfo(true);
trackDrawInfo.setColor(app.getSettings().CURRENT_TRACK_COLOR.get());
trackDrawInfo.setWidth(app.getSettings().CURRENT_TRACK_WIDTH.get());
trackDrawInfo.setShowArrows(app.getSettings().CURRENT_TRACK_SHOW_ARROWS.get());
trackDrawInfo.setShowStartFinish(app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.get());
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
gpxDataItem = app.getGpxDbHelper().getItem(new File(gpxFilePath));
@ -163,13 +169,14 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
appearanceIcon = view.findViewById(R.id.appearance_icon);
trackIcon = view.findViewById(R.id.track_icon);
if (isPortrait()) {
updateCardsLayout();
}
updateCards();
updateButtons(view);
setupCards();
setupButtons(view);
setupScrollShadow();
updateAppearanceIcon();
if (!isPortrait()) {
int widthNoShadow = getLandscapeNoShadowWidth();
@ -327,7 +334,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
private void updateAppearanceIcon() {
Drawable icon = getTrackIcon(app, trackDrawInfo.getWidth(), trackDrawInfo.isShowArrows(), trackDrawInfo.getColor());
appearanceIcon.setImageDrawable(icon);
trackIcon.setImageDrawable(icon);
}
private void adjustMapPosition(int y) {
@ -387,7 +394,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
}
private void updateButtons(View view) {
private void setupButtons(View view) {
View buttonsContainer = view.findViewById(R.id.buttons_container);
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg));
View saveButton = view.findViewById(R.id.right_bottom_button);
@ -418,6 +425,26 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
AndroidUiHelper.updateVisibility(view.findViewById(R.id.buttons_divider), true);
}
private void setupScrollShadow() {
int shadowIconId = isNightMode() ? R.drawable.bg_contextmenu_shadow : R.drawable.bg_contextmenu_shadow;
final Drawable shadowIcon = app.getUIUtilities().getIcon(shadowIconId);
final ScrollView scrollView = getBottomScrollView();
final FrameLayout bottomContainer = getBottomContainer();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int scrollY = scrollView.getScrollY();
if (scrollY <= 0 && bottomContainer.getForeground() != null) {
bottomContainer.setForeground(null);
} else if (scrollY > 0 && bottomContainer.getForeground() == null) {
bottomContainer.setForeground(shadowIcon);
}
}
});
}
private void saveTrackInfo() {
GPXFile gpxFile = selectedGpxFile.getGpxFile();
@ -440,6 +467,9 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor());
app.getSettings().CURRENT_TRACK_WIDTH.set(trackDrawInfo.getWidth());
app.getSettings().CURRENT_TRACK_SHOW_ARROWS.set(trackDrawInfo.isShowArrows());
app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.set(trackDrawInfo.isShowStartFinish());
} else {
if (gpxDataItem != null) {
gpxDataItem = new GpxDataItem(new File(gpxFile.path), gpxFile);
@ -508,7 +538,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private void updateCards() {
private void setupCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
ViewGroup cardsContainer = getCardsContainer();

View file

@ -109,6 +109,10 @@ public class TrackDrawInfo {
this.showArrows = showArrows;
}
public void setShowStartFinish(boolean showStartFinish) {
this.showStartFinish = showStartFinish;
}
public boolean isShowStartFinish() {
return showStartFinish;
}

View file

@ -89,9 +89,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private Paint paint;
private Paint shadowPaint;
private Paint paintIcon;
private int cachedHash;
@ColorInt
private int cachedColor;
private int currentTrackColor;
private float defaultTrackWidth;
private Map<String, Float> cachedTrackWidth = new HashMap<>();
@ -129,8 +130,13 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
@ColorInt
private int grayColor;
private CommonPreference<String> currentTrackColorPref;
private CommonPreference<String> defaultTrackColorPref;
private CommonPreference<String> defaultTrackWidthPref;
private CommonPreference<Integer> currentTrackColorPref;
private CommonPreference<String> currentTrackWidthPref;
private CommonPreference<Boolean> currentTrackShowArrowsPref;
private CommonPreference<Boolean> currentTrackShowStartFinishPref;
@Override
public void initLayer(OsmandMapTileView view) {
@ -138,8 +144,14 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
currentTrackColorPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
currentTrackWidthPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
currentTrackColorPref = view.getSettings().CURRENT_TRACK_COLOR;
currentTrackWidthPref = view.getSettings().CURRENT_TRACK_WIDTH;
currentTrackShowArrowsPref = view.getSettings().CURRENT_TRACK_SHOW_ARROWS;
currentTrackShowStartFinishPref = view.getSettings().CURRENT_TRACK_SHOW_START_FINISH;
defaultTrackColorPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR).cache();
defaultTrackWidthPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR).cache();
initUI();
}
@ -228,7 +240,6 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
List<SelectedGpxFile> selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles();
cache.clear();
currentTrackColor = view.getSettings().CURRENT_TRACK_COLOR.get();
if (!selectedGPXFiles.isEmpty()) {
drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
@ -249,7 +260,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
boolean nightMode = drawSettings != null && drawSettings.isNightMode();
int hash = calculateHash(rrs, cachedTrackWidth, routePoints, nightMode, tileBox.getMapDensity(), tileBox.getZoom(),
currentTrackColorPref.get(), currentTrackWidthPref.get());
defaultTrackColorPref.get(), defaultTrackWidthPref.get());
if (hash != cachedHash) {
cachedHash = hash;
cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track);
@ -257,16 +268,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
if (rrs != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
if (currentTrackColorPref != null && currentTrackColorPref.isSet()) {
if (defaultTrackColorPref != null && defaultTrackColorPref.isSet()) {
RenderingRuleProperty ctColor = rrs.PROPS.get(CURRENT_TRACK_COLOR_ATTR);
if (ctColor != null) {
req.setStringFilter(ctColor, currentTrackColorPref.get());
req.setStringFilter(ctColor, defaultTrackColorPref.get());
}
}
if (currentTrackWidthPref != null && currentTrackWidthPref.isSet()) {
if (defaultTrackWidthPref != null && defaultTrackWidthPref.isSet()) {
RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
if (ctWidth != null) {
req.setStringFilter(ctWidth, currentTrackWidthPref.get());
req.setStringFilter(ctWidth, defaultTrackWidthPref.get());
}
}
String additional = "";
@ -305,10 +316,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
paint.setColor(color == 0 ? cachedColor : color);
Float strikeWidth = cachedTrackWidth.get(width);
if (strikeWidth != null) {
paint.setStrokeWidth(strikeWidth);
}
paint.setStrokeWidth(getTrackWidth(width, defaultTrackWidth));
}
private void acquireTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) {
@ -342,17 +350,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
if (tileBox.getZoom() >= START_ZOOM) {
// request to load
OsmandApplication app = view.getApplication();
for (SelectedGpxFile g : selectedGPXFiles) {
List<GpxDisplayGroup> groups = g.getDisplayGroups(app);
if (groups != null && !groups.isEmpty()) {
int color = g.getGpxFile().getColor(0);
if (color == 0) {
color = g.getModifiableGpxFile().getColor(0);
}
if (color == 0) {
color = cachedColor;
}
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
List<GpxDisplayGroup> groups = selectedGpxFile.getDisplayGroups(app);
if (!Algorithms.isEmpty(groups)) {
int color = getTrackColor(selectedGpxFile.getGpxFile(), cachedColor);
paintInnerRect.setColor(color);
paintInnerRect.setAlpha(179);
@ -416,25 +417,12 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private void drawDirectionArrows(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (!tileBox.isZoomAnimated()) {
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
boolean showArrows = selectedGpxFile.getGpxFile().isShowArrows();
if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) {
showArrows = trackDrawInfo.isShowArrows();
}
boolean showArrows = isShowArrowsForTrack(selectedGpxFile.getGpxFile());
if (showArrows) {
QuadRect correctedQuadRect = getCorrectedQuadRect(tileBox.getLatLonBounds());
String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get());
int color = selectedGpxFile.getGpxFile().getColor(cachedColor);
if (selectedGpxFile.isShowCurrentTrack()) {
color = currentTrackColor;
}
if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) {
color = trackDrawInfo.getColor();
width = trackDrawInfo.getWidth();
}
Float trackWidth = cachedTrackWidth.get(width);
if (trackWidth == null) {
trackWidth = defaultTrackWidth;
}
String width = getTrackWidthName(selectedGpxFile.getGpxFile(), defaultTrackWidthPref.get());
float trackWidth = getTrackWidth(width, defaultTrackWidth);
int color = getTrackColor(selectedGpxFile.getGpxFile(), cachedColor);
int contrastColor = UiUtilities.getContrastColor(view.getApplication(), color, false);
GeometryWayStyle arrowsWayStyle = new GeometryArrowsWayStyle(wayContext, arrowBitmap, contrastColor, color, trackWidth);
for (TrkSegment segment : selectedGpxFile.getPointsToDisplay()) {
@ -587,10 +575,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private void drawSelectedFilesStartEndPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (tileBox.getZoom() >= START_ZOOM) {
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
boolean showStartFinish = selectedGpxFile.getGpxFile().isShowStartFinish();
if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) {
showStartFinish = trackDrawInfo.isShowStartFinish();
}
boolean showStartFinish = isShowStartFinishForTrack(selectedGpxFile.getGpxFile());
if (showStartFinish) {
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
for (TrkSegment segment : segments) {
@ -605,11 +590,6 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
private boolean hasTrackDrawInfoForSelectedGpx(SelectedGpxFile selectedGpxFile) {
return trackDrawInfo != null && (trackDrawInfo.isCurrentRecording() && selectedGpxFile.isShowCurrentTrack()
|| selectedGpxFile.getGpxFile().path.equals(trackDrawInfo.getFilePath()));
}
private void drawStartEndPoints(Canvas canvas, RotatedTileBox tileBox, WptPt start, WptPt end) {
int startX = (int) tileBox.getPixXFromLatLon(start.lat, start.lon);
int startY = (int) tileBox.getPixYFromLatLon(start.lat, start.lon);
@ -717,13 +697,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
int color = trackChartPoints.getSegmentColor();
if (color == 0) {
color = trackChartPoints.getGpx().getColor(0);
if (trackChartPoints.getGpx().showCurrentTrack) {
color = currentTrackColor;
}
if (color == 0) {
color = cachedColor;
}
color = getTrackColor(trackChartPoints.getGpx(), cachedColor);
trackChartPoints.setSegmentColor(color);
}
paintGridCircle.setColor(color);
@ -782,21 +756,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
SelectedGpxFile currentTrack = null;
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get());
if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) {
width = trackDrawInfo.getWidth();
}
String width = getTrackWidthName(selectedGpxFile.getGpxFile(), defaultTrackWidthPref.get());
if (!cachedTrackWidth.containsKey(width)) {
cachedTrackWidth.put(width, null);
}
}
SelectedGpxFile currentTrack = null;
for (SelectedGpxFile g : selectedGPXFiles) {
if (g.isShowCurrentTrack()) {
currentTrack = g;
if (selectedGpxFile.isShowCurrentTrack()) {
currentTrack = selectedGpxFile;
} else {
drawSelectedFileSegments(g, false, canvas, tileBox, settings);
drawSelectedFileSegments(selectedGpxFile, false, canvas, tileBox, settings);
}
}
if (currentTrack != null) {
@ -805,21 +774,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas,
RotatedTileBox tileBox, DrawSettings settings) {
RotatedTileBox tileBox, DrawSettings settings) {
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
for (TrkSegment ts : segments) {
String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get());
int color = selectedGpxFile.getGpxFile().getColor(0);
if (currentTrack) {
color = currentTrackColor;
}
if (color == 0) {
color = ts.getColor(cachedColor);
}
if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) {
color = trackDrawInfo.getColor();
width = trackDrawInfo.getWidth();
}
String width = getTrackWidthName(selectedGpxFile.getGpxFile(), defaultTrackWidthPref.get());
int color = getTrackColor(selectedGpxFile.getGpxFile(), ts.getColor(cachedColor));
if (ts.renderer == null && !ts.points.isEmpty()) {
if (currentTrack) {
ts.renderer = new Renderable.CurrentTrack(ts.points);
@ -834,6 +793,60 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
private float getTrackWidth(String width, float defaultTrackWidth) {
Float trackWidth = cachedTrackWidth.get(width);
return trackWidth != null ? trackWidth : defaultTrackWidth;
}
private int getTrackColor(GPXFile gpxFile, int defaultColor) {
int color;
if (hasTrackDrawInfoForTrack(gpxFile)) {
color = trackDrawInfo.getColor();
} else if (gpxFile.showCurrentTrack) {
color = currentTrackColorPref.get();
} else {
color = gpxFile.getColor(defaultColor);
}
return color != 0 ? color : defaultColor;
}
private String getTrackWidthName(GPXFile gpxFile, String defaultWidth) {
String width;
if (hasTrackDrawInfoForTrack(gpxFile)) {
width = trackDrawInfo.getWidth();
} else if (gpxFile.showCurrentTrack) {
width = currentTrackWidthPref.get();
} else {
width = gpxFile.getWidth(defaultWidth);
}
return width != null ? width : defaultWidth;
}
private boolean isShowArrowsForTrack(GPXFile gpxFile) {
if (hasTrackDrawInfoForTrack(gpxFile)) {
return trackDrawInfo.isShowArrows();
} else if (gpxFile.showCurrentTrack) {
return currentTrackShowArrowsPref.get();
} else {
return gpxFile.isShowArrows();
}
}
private boolean isShowStartFinishForTrack(GPXFile gpxFile) {
if (hasTrackDrawInfoForTrack(gpxFile)) {
return trackDrawInfo.isShowStartFinish();
} else if (gpxFile.showCurrentTrack) {
return currentTrackShowStartFinishPref.get();
} else {
return gpxFile.isShowStartFinish();
}
}
private boolean hasTrackDrawInfoForTrack(GPXFile gpxFile) {
return trackDrawInfo != null && (trackDrawInfo.isCurrentRecording() && gpxFile.showCurrentTrack
|| gpxFile.path.equals(trackDrawInfo.getFilePath()));
}
private boolean isPointVisited(WptPt o) {
boolean visit = false;
String visited = o.getExtensionsToRead().get("VISITED_KEY");