From 09fb1dc651592e2f99057ff8ac19bda08ecac1eb Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Thu, 30 Jul 2020 15:26:02 +0300 Subject: [PATCH 01/20] Fix #4917 --- ...escr_switch_and_additional_button_56dp.xml | 96 +++++++++++++++++++ .../RouteOptionsBottomSheet.java | 84 +++++++++++----- 2 files changed, 155 insertions(+), 25 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_with_descr_switch_and_additional_button_56dp.xml diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_switch_and_additional_button_56dp.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_switch_and_additional_button_56dp.xml new file mode 100644 index 0000000000..006824b159 --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_switch_and_additional_button_56dp.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index cf5edfd4f3..808418aa05 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -2,9 +2,12 @@ package net.osmand.plus.routepreparationmenu; import android.app.Activity; import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Bundle; import android.view.MenuItem; import android.view.View; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -19,6 +22,7 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities; import net.osmand.StateChangedListener; +import net.osmand.plus.UiUtilities; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; @@ -168,32 +172,62 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) { boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); - final BottomSheetItemWithCompoundButton[] muteSoundItem = new BottomSheetItemWithCompoundButton[1]; - muteSoundItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() - .setCompoundButtonColorId(selectedModeColorId) - .setChecked(active) - .setDescription(getString(R.string.voice_announcements)) - .setIcon(getContentIcon(active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())) - .setTitle(getString(R.string.shared_string_sound)) - .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); - boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); - routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); - String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode); - if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { - OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false); - } else { - muteSoundItem[0].setChecked(!active); - muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); - } - updateMenu(); - } - }) + int selectedModeColor = ContextCompat.getColor(app, selectedModeColorId); + final View itemView = UiUtilities.getInflater(app, nightMode).inflate( + R.layout.bottom_sheet_item_with_descr_switch_and_additional_button_56dp, null, false); + final ImageView icon = itemView.findViewById(R.id.icon); + TextView tvTitle = itemView.findViewById(R.id.title); + TextView tvDescription = itemView.findViewById(R.id.description); + View basicItem = itemView.findViewById(R.id.basic_item_body); + final CompoundButton cb = itemView.findViewById(R.id.compound_button); + View voicePromptsBtn = itemView.findViewById(R.id.additional_button); + ImageView voicePromptsBtnImage = itemView.findViewById(R.id.additional_button_icon); + + tvTitle.setText(getString(R.string.shared_string_sound)); + tvDescription.setText(getString(R.string.voice_announcements)); + icon.setImageDrawable(getContentIcon(active ? + optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); + cb.setChecked(active); + cb.setFocusable(false); + UiUtilities.setupCompoundButton(nightMode, selectedModeColor, cb); + + basicItem.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); + boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); + routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); + String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode); + if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { + OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false); + } else { + cb.setChecked(!active); + icon.setImageDrawable(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); + } + updateMenu(); + } + }); + + Drawable drawable = app.getUIUtilities().getIcon(R.drawable.ic_action_settings, + nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); + if (Build.VERSION.SDK_INT >= 21) { + Drawable activeDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_settings, selectedModeColorId); + drawable = AndroidUtils.createPressedStateListDrawable(drawable, activeDrawable); + } + voicePromptsBtnImage.setImageDrawable(drawable); + + voicePromptsBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + BaseSettingsFragment.showInstance( + mapActivity, BaseSettingsFragment.SettingsScreenType.VOICE_ANNOUNCES); + dismiss(); + } + }); + + return new BaseBottomSheetItem.Builder() + .setCustomView(itemView) .create(); - return muteSoundItem[0]; } private BaseBottomSheetItem createTimeConditionalRoutingItem(final LocalRoutingParameter optionsItem) { From 638a9c62310c3682dd629f34fad56ecd667808ce Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 30 Jul 2020 18:11:41 +0300 Subject: [PATCH 02/20] Fix crash #9462 --- .../osmand/plus/osmedit/AdvancedEditPoiFragment.java | 2 +- OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java | 9 +++++---- .../src/net/osmand/plus/resources/ResourceManager.java | 10 ++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index 9d343a04c2..64451a19d7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -206,7 +206,7 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment continue; addTagView(tag.getKey(), tag.getValue()); } - if (editPoiData.hasEmptyValue()) { + if (editPoiData.hasEmptyValue() && linearLayout.findViewById(R.id.valueEditText) != null) { linearLayout.findViewById(R.id.valueEditText).requestFocus(); } editPoiData.setIsInEdit(false); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java index 27a25bfc1c..b11c828436 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java @@ -214,13 +214,14 @@ public class EditPoiData { } retrieveType(); PoiType pt = getPoiTypeDefined(); - if (pt != null) { - removeTypeTagWithPrefix(!tagValues.containsKey(REMOVE_TAG_PREFIX + pt.getEditOsmTag())); + String editOsmTag = pt != null ? pt.getEditOsmTag() : null; + if (editOsmTag != null) { + removeTypeTagWithPrefix(!tagValues.containsKey(REMOVE_TAG_PREFIX + editOsmTag)); currentPoiType = pt; String tagVal = pt.getEditOsmValue() != null ? pt.getEditOsmValue() : ""; - tagValues.put(pt.getEditOsmTag(), tagVal); + tagValues.put(editOsmTag, tagVal); if (userChanges) { - changedTags.add(pt.getEditOsmTag()); + changedTags.add(editOsmTag); } category = pt.getCategory(); } else if (currentPoiType != null) { diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 220bfe767a..ae123b2c8b 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -765,8 +765,14 @@ public class ResourceManager { toAddPoiTypes.put(poiCategory, new TreeMap()); } Map poiTypes = toAddPoiTypes.get(poiCategory); - for (String s : entry.getValue()) { - poiTypes.put(s, new PoiType(MapPoiTypes.getDefault(), poiCategory, null, s)); + if (poiTypes != null) { + for (String s : entry.getValue()) { + PoiType pt = new PoiType(MapPoiTypes.getDefault(), poiCategory, null, s); + pt.setOsmTag(""); + pt.setOsmValue(""); + pt.setNotEditableOsm(true); + poiTypes.put(s, pt); + } } } } From dd40c4dce61bc8b1e270706343766d3df13cc6e3 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 30 Jul 2020 21:34:57 +0300 Subject: [PATCH 03/20] Add new track appearance prefs for current recording track --- OsmAnd/res/layout/track_appearance.xml | 11 +- .../plus/settings/backend/OsmandSettings.java | 3 + .../plus/track/TrackAppearanceFragment.java | 44 ++++- .../net/osmand/plus/track/TrackDrawInfo.java | 4 + .../src/net/osmand/plus/views/GPXLayer.java | 175 ++++++++++-------- 5 files changed, 143 insertions(+), 94 deletions(-) diff --git a/OsmAnd/res/layout/track_appearance.xml b/OsmAnd/res/layout/track_appearance.xml index 5060722e54..089e1f174d 100644 --- a/OsmAnd/res/layout/track_appearance.xml +++ b/OsmAnd/res/layout/track_appearance.xml @@ -50,7 +50,7 @@ osmand:typeface="@string/font_roboto_medium" /> + android:layout_gravity="bottom" + tools:visibility="invisible"> + android:layout_marginRight="@dimen/fab_margin_right" /> + android:layout_marginRight="@dimen/fab_margin_right" /> diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index ea5d75452f..28373853b7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2194,6 +2194,9 @@ public class OsmandSettings { public final OsmandPreference LAST_UPDATES_CARD_REFRESH = new LongPreference("last_updates_card_refresh", 0).makeGlobal(); public final CommonPreference CURRENT_TRACK_COLOR = new IntPreference("current_track_color", 0).makeGlobal().cache(); + public final CommonPreference CURRENT_TRACK_WIDTH = new StringPreference("current_track_width", "").makeGlobal().cache(); + public final CommonPreference CURRENT_TRACK_SHOW_ARROWS = new BooleanPreference("current_track_show_arrows", false).makeGlobal().cache(); + public final CommonPreference 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 SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index b8e375a692..c56311e932 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -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(); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java index 9773ddd329..3dbacb7b56 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -109,6 +109,10 @@ public class TrackDrawInfo { this.showArrows = showArrows; } + public void setShowStartFinish(boolean showStartFinish) { + this.showStartFinish = showStartFinish; + } + public boolean isShowStartFinish() { return showStartFinish; } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 9e16b28060..8ee950f079 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -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 cachedTrackWidth = new HashMap<>(); @@ -129,8 +130,13 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM @ColorInt private int grayColor; - private CommonPreference currentTrackColorPref; + private CommonPreference defaultTrackColorPref; + private CommonPreference defaultTrackWidthPref; + + private CommonPreference currentTrackColorPref; private CommonPreference currentTrackWidthPref; + private CommonPreference currentTrackShowArrowsPref; + private CommonPreference 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 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 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 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 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 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 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 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 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"); From 0f89e927e0231df69afa08ad5a8c0d7f502527a0 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 31 Jul 2020 12:00:46 +0300 Subject: [PATCH 04/20] Fix dancing split interval --- .../src/net/osmand/plus/views/GPXLayer.java | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 8ee950f079..b2a893d6f3 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -374,15 +374,14 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM int r = (int) (12 * tileBox.getDensity()); paintTextIcon.setTextSize(r); int dr = r * 3 / 2; - int px = -1; - int py = -1; + float px = -1; + float py = -1; for (int k = 0; k < items.size(); k++) { GpxDisplayItem i = items.get(k); - WptPt o = i.locationEnd; - if (o != null && o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top && o.lon >= latLonBounds.left - && o.lon <= latLonBounds.right) { - int x = (int) tileBox.getPixXFromLatLon(o.lat, o.lon); - int y = (int) tileBox.getPixYFromLatLon(o.lat, o.lon); + WptPt point = i.locationEnd; + if (point != null) { + float x = tileBox.getPixXFromLatLon(point.lat, point.lon); + float y = tileBox.getPixYFromLatLon(point.lat, point.lon); if (px != -1 || py != -1) { if (Math.abs(x - px) <= dr && Math.abs(y - py) <= dr) { continue; @@ -390,25 +389,29 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } px = x; py = y; - String nm = i.splitName; - if (nm != null) { - int ind = nm.indexOf(' '); - if (ind > 0) { - nm = nm.substring(0, ind); + if (point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top + && point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) { + String name = i.splitName; + if (name != null) { + int ind = name.indexOf(' '); + if (ind > 0) { + name = name.substring(0, ind); + } + Rect bounds = new Rect(); + paintTextIcon.getTextBounds(name, 0, name.length(), bounds); + + float nameHalfWidth = bounds.width() / 2f; + float nameHalfHeight = bounds.height() / 2f; + float density = (float) Math.ceil(tileBox.getDensity()); + RectF rect = new RectF(x - nameHalfWidth - 2 * density, + y + nameHalfHeight + 3 * density, + x + nameHalfWidth + 3 * density, + y - nameHalfHeight - 2 * density); + + canvas.drawRoundRect(rect, 0, 0, paintInnerRect); + canvas.drawRoundRect(rect, 0, 0, paintOuterRect); + canvas.drawText(name, x, y + nameHalfHeight, paintTextIcon); } - Rect bounds = new Rect(); - paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds); - int nmWidth = bounds.width(); - int nmHeight = bounds.height(); - RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), - y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), - x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), - y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity())); - canvas.drawRoundRect(rect, 0, 0, paintInnerRect); - canvas.drawRoundRect(rect, 0, 0, paintOuterRect); -// canvas.drawRect(rect, paintInnerRect); -// canvas.drawRect(rect, paintOuterRect); - canvas.drawText(nm, x, y + nmHeight / 2, paintTextIcon); } } } @@ -1110,8 +1113,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM @Override public void applyNewObjectPosition(@NonNull Object o, - @NonNull LatLon position, - @Nullable final ContextMenuLayer.ApplyMovedObjectCallback callback) { + @NonNull LatLon position, + @Nullable final ContextMenuLayer.ApplyMovedObjectCallback callback) { if (o instanceof WptPt) { final WptPt objectInMotion = (WptPt) o; SelectedGpxFile selectedGpxFile = pointFileMap.get(objectInMotion); From 30a7ebcb305cc52329ff69760d65263afb61a833 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 31 Jul 2020 12:02:16 +0300 Subject: [PATCH 05/20] Fix split card visibility --- .../plus/track/SplitIntervalBottomSheet.java | 12 +++--------- .../osmand/plus/track/TrackAppearanceFragment.java | 14 +++++++++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java index e102dfffa9..15d94db2cc 100644 --- a/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/SplitIntervalBottomSheet.java @@ -15,7 +15,6 @@ import com.google.android.material.slider.Slider; import net.osmand.PlatformUtil; 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; @@ -30,6 +29,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import org.apache.commons.logging.Log; import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -310,17 +310,11 @@ public class SplitIntervalBottomSheet extends MenuBottomSheetDialogFragment { @NonNull public List getDisplayGroups() { - List groups = new ArrayList<>(); 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 ((TrackAppearanceFragment) target).getDisplaySegmentGroups(); } - return groups; + return Collections.emptyList(); } public static void showInstance(@NonNull FragmentManager fragmentManager, TrackDrawInfo trackDrawInfo, Fragment target) { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index c56311e932..0c2176687c 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -28,6 +28,7 @@ import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -544,7 +545,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - if (!selectedGpxFile.isShowCurrentTrack()) { + if (!selectedGpxFile.isShowCurrentTrack() && !Algorithms.isEmpty(getDisplaySegmentGroups())) { splitIntervalCard = new SplitIntervalCard(mapActivity, trackDrawInfo); splitIntervalCard.setListener(this); cardsContainer.addView(splitIntervalCard.build(mapActivity)); @@ -579,6 +580,17 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement return displayGroups; } + @NonNull + public List getDisplaySegmentGroups() { + List groups = new ArrayList<>(); + for (GpxDisplayGroup group : getGpxDisplayGroups()) { + if (GpxDisplayItemType.TRACK_SEGMENT == group.getType()) { + groups.add(group); + } + } + return groups; + } + public void dismissImmediate() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { From 0a773125353262fb8e9fd0c47c31046bf7f2a45e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 31 Jul 2020 13:08:09 +0200 Subject: [PATCH 06/20] Introduce relation group back --- .../src/main/java/net/osmand/osm/MapRenderingTypes.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java index a27cba56ec..7d0a95589b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapRenderingTypes.java @@ -292,8 +292,9 @@ public abstract class MapRenderingTypes { rtype.category = parentCategory == null ? null : parentCategory.category; rtype.onlyPoint = Boolean.parseBoolean(parser.getAttributeValue("", "point")); //$NON-NLS-1$ rtype.relation = Boolean.parseBoolean(parser.getAttributeValue("", "relation")); //$NON-NLS-1$ + rtype.relationGroup = Boolean.parseBoolean(parser.getAttributeValue("", "relationGroup")); //$NON-NLS-1$ if (rtype.isMain()) { - if (rtype.relation) { + if (rtype.relationGroup) { MapRulType mrt = MapRulType.createMainEntity(tag + "_" + value, null); mrt.order = rtype.order; mrt.category = rtype.category; @@ -533,6 +534,7 @@ public abstract class MapRenderingTypes { protected String category = null; protected boolean relation; + protected boolean relationGroup; // creation of only section protected boolean map = true; protected boolean poi = true; From 7b10a094efad6f6a05d7d55f4503a99047416806 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 31 Jul 2020 14:09:46 +0200 Subject: [PATCH 07/20] Fix #9529 --- .../net/osmand/search/core/SearchPhrase.java | 3 ++- .../main/java/net/osmand/util/Algorithms.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java index 4cc5e63a84..f1b5b45b05 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchPhrase.java @@ -160,7 +160,7 @@ public class SearchPhrase { public SearchPhrase generateNewPhrase(String text, SearchSettings settings) { - String textToSearch = text; + String textToSearch = Algorithms.normalizeSearchText(text); List leftWords = this.words; String thisTxt = getText(true); List foundWords = new ArrayList<>(); @@ -183,6 +183,7 @@ public class SearchPhrase { } + public static SearchPhrase emptyPhrase() { return emptyPhrase(null); } diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index b5a466cb8b..575b975c63 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -44,6 +44,29 @@ public class Algorithms { public static boolean isEmpty(Collection c) { return c == null || c.size() == 0; } + + private static char[] CHARS_TO_NORMALIZE_KEY = new char['’']; + private static char[] CHARS_TO_NORMALIZE_VALUE = new char['\'']; + + public static String normalizeSearchText(String s) { + boolean norm = false; + for (int i = 0; i < s.length() && !norm; i++) { + char ch = s.charAt(i); + for (int j = 0; j < CHARS_TO_NORMALIZE_KEY.length; j++) { + if (ch == CHARS_TO_NORMALIZE_KEY[j]) { + norm = true; + break; + } + } + } + if (!norm) { + return s; + } + for (int k = 0; k < CHARS_TO_NORMALIZE_KEY.length; k++) { + s = s.replace(CHARS_TO_NORMALIZE_KEY[k], CHARS_TO_NORMALIZE_VALUE[k]); + } + return s; + } public static boolean isEmpty(Map map) { return map == null || map.size() == 0; From 725fa98d7a3415df4d0c396cc00d791bac7d9aa3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 31 Jul 2020 17:00:46 +0200 Subject: [PATCH 08/20] Fix rendering rule storage --- .../osmand/render/RenderingRulesStorage.java | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java index 96e1280d76..7d8dad381b 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java @@ -26,7 +26,7 @@ import org.xmlpull.v1.XmlPullParserException; public class RenderingRulesStorage { private final static Log log = PlatformUtil.getLog(RenderingRulesStorage.class); - static boolean STORE_ATTTRIBUTES = false; + static boolean STORE_ATTRIBUTES = false; // keep sync ! // keep sync ! not change values @@ -186,26 +186,26 @@ public class RenderingRulesStorage { private class RenderingRulesHandler { private final XmlPullParser parser; private int state; - Stack stack = new Stack(); - - Map attrsMap = new LinkedHashMap(); private final RenderingRulesStorageResolver resolver; private RenderingRulesStorage dependsStorage; - - public RenderingRulesHandler(XmlPullParser parser, RenderingRulesStorageResolver resolver){ this.parser = parser; this.resolver = resolver; } public void parse(InputStream is) throws XmlPullParserException, IOException { + XmlPullParser parser = this.parser; + Map attrsMap = new LinkedHashMap(); parser.setInput(is, "UTF-8"); int tok; while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { if (tok == XmlPullParser.START_TAG) { - startElement(parser.getName()); +// String seq = parser.getAttributeValue("", "seq"); + attrsMap.clear(); + parseAttributes(parser, attrsMap); + startElement(attrsMap, parser.getName()); } else if (tok == XmlPullParser.END_TAG) { endElement(parser.getName()); } @@ -226,16 +226,14 @@ public class RenderingRulesStorage { return true; } - public void startElement(String name) throws XmlPullParserException, IOException { + public void startElement(Map attrsMap, String name) throws XmlPullParserException, IOException { boolean stateChanged = false; final boolean isCase = isCase(name); final boolean isSwitch = isSwitch(name); if(isCase || isSwitch){ //$NON-NLS-1$ - attrsMap.clear(); boolean top = stack.size() == 0 || isTopCase(); - parseAttributes(attrsMap); RenderingRule renderingRule = new RenderingRule(attrsMap, isSwitch, RenderingRulesStorage.this); - if(top || STORE_ATTTRIBUTES){ + if(top || STORE_ATTRIBUTES){ renderingRule.storeAttributes(attrsMap); } if (stack.size() > 0 && stack.peek() instanceof RenderingRule) { @@ -244,10 +242,8 @@ public class RenderingRulesStorage { } stack.push(renderingRule); } else if(isApply(name)){ //$NON-NLS-1$ - attrsMap.clear(); - parseAttributes(attrsMap); RenderingRule renderingRule = new RenderingRule(attrsMap, false, RenderingRulesStorage.this); - if(STORE_ATTTRIBUTES) { + if(STORE_ATTRIBUTES) { renderingRule.storeAttributes(attrsMap); } if (stack.size() > 0 && stack.peek() instanceof RenderingRule) { @@ -272,14 +268,14 @@ public class RenderingRulesStorage { state = POLYGON_RULES; stateChanged = true; } else if("renderingAttribute".equals(name)){ //$NON-NLS-1$ - String attr = parser.getAttributeValue("", "name"); + String attr = attrsMap.get("name"); RenderingRule root = new RenderingRule(new HashMap(), false, RenderingRulesStorage.this); renderingAttributes.put(attr, root); stack.push(root); } else if("renderingProperty".equals(name)){ //$NON-NLS-1$ - String attr = parser.getAttributeValue("", "attr"); + String attr = attrsMap.get("attr"); RenderingRuleProperty prop; - String type = parser.getAttributeValue("", "type"); + String type = attrsMap.get("type"); if("boolean".equalsIgnoreCase(type)){ prop = RenderingRuleProperty.createInputBooleanProperty(attr); } else if("string".equalsIgnoreCase(type)){ @@ -287,20 +283,20 @@ public class RenderingRulesStorage { } else { prop = RenderingRuleProperty.createInputIntProperty(attr); } - prop.setDescription(parser.getAttributeValue("", "description")); - prop.setDefaultValueDescription(parser.getAttributeValue("", "defaultValueDescription")); - prop.setCategory(parser.getAttributeValue("", "category")); - prop.setName(parser.getAttributeValue("", "name")); - if(parser.getAttributeValue("", "possibleValues") != null){ - prop.setPossibleValues(parser.getAttributeValue("", "possibleValues").split(",")); + prop.setDescription(attrsMap.get("description")); + prop.setDefaultValueDescription(attrsMap.get("defaultValueDescription")); + prop.setCategory(attrsMap.get("category")); + prop.setName(attrsMap.get("name")); + if (attrsMap.get("possibleValues") != null) { + prop.setPossibleValues(attrsMap.get("possibleValues").split(",")); } PROPS.registerRule(prop); } else if("renderingConstant".equals(name)){ //$NON-NLS-1$ - if(!renderingConstants.containsKey(parser.getAttributeValue("", "name"))){ - renderingConstants.put(parser.getAttributeValue("", "name"), parser.getAttributeValue("", "value")); + if(!renderingConstants.containsKey(attrsMap.get("name"))){ + renderingConstants.put(attrsMap.get("name"), attrsMap.get("value")); } } else if("renderingStyle".equals(name)){ //$NON-NLS-1$ - String depends = parser.getAttributeValue("", "depends"); + String depends = attrsMap.get("depends"); if(depends != null && depends.length()> 0){ this.dependsStorage = resolver.resolve(depends, resolver); } @@ -311,7 +307,7 @@ public class RenderingRulesStorage { PROPS = new RenderingRuleStorageProperties(dependsStorage.PROPS); } - internalRenderingName = parser.getAttributeValue("", "name"); + internalRenderingName = attrsMap.get("name"); } else if("renderer".equals(name)){ //$NON-NLS-1$ throw new XmlPullParserException("Rendering style is deprecated and no longer supported."); @@ -337,7 +333,7 @@ public class RenderingRulesStorage { return "group".equals(name) || "switch".equals(name); } - private Map parseAttributes(Map m) { + private Map parseAttributes(XmlPullParser parser, Map m) { for (int i = 0; i < parser.getAttributeCount(); i++) { String name = parser.getAttributeName(i); String vl = parser.getAttributeValue(i); @@ -396,7 +392,7 @@ public class RenderingRulesStorage { vl = ns.remove("value"); // reset rendering rule attributes renderingRule.init(ns); - if(STORE_ATTTRIBUTES) { + if(STORE_ATTRIBUTES) { renderingRule.storeAttributes(ns); } @@ -469,7 +465,7 @@ public class RenderingRulesStorage { public static void main(String[] args) throws XmlPullParserException, IOException { - STORE_ATTTRIBUTES = true; + STORE_ATTRIBUTES = true; // InputStream is = RenderingRulesStorage.class.getResourceAsStream("default.render.xml"); final String loc = "/Users/victorshcherb/osmand/repos/resources/rendering_styles/"; String defaultFile = loc + "UniRS.render.xml"; From 0a0709441cc9b0d3d2fa565676f65d1a35d6f125 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 31 Jul 2020 17:12:09 +0200 Subject: [PATCH 09/20] Fix rendering rule storage --- .../osmand/render/RenderingRulesStorage.java | 51 +++++++++++++++++-- .../render/RenderingRulesStoragePrinter.java | 2 +- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java index 7d8dad381b..1c9214f660 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStorage.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -18,6 +17,7 @@ import java.util.Map.Entry; import java.util.Stack; import net.osmand.PlatformUtil; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; @@ -183,6 +183,23 @@ public class RenderingRulesStorage { } } + private class XmlTreeSequence { + XmlTreeSequence parent; + String seqOrder; + Map attrsMap = new LinkedHashMap(); + String name; + List children = new ArrayList(); + + private void process(RenderingRulesHandler handler, int el) throws XmlPullParserException, IOException { + // TODO create new attrsMap and replace #SEQ -> el + handler.startElement(attrsMap, name); + for(XmlTreeSequence s : children) { + s.process(handler, el); + } + handler.endElement(name); + } + } + private class RenderingRulesHandler { private final XmlPullParser parser; private int state; @@ -200,14 +217,40 @@ public class RenderingRulesStorage { Map attrsMap = new LinkedHashMap(); parser.setInput(is, "UTF-8"); int tok; + XmlTreeSequence currentSeqElement = null; while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { if (tok == XmlPullParser.START_TAG) { -// String seq = parser.getAttributeValue("", "seq"); attrsMap.clear(); parseAttributes(parser, attrsMap); - startElement(attrsMap, parser.getName()); + String name = parser.getName(); + if (!Algorithms.isEmpty(parser.getAttributeValue("", "seq")) || currentSeqElement != null) { + XmlTreeSequence seq = new XmlTreeSequence(); + seq.name = name; + seq.attrsMap = attrsMap; + seq.parent = currentSeqElement; + if (currentSeqElement == null) { + seq.seqOrder = parser.getAttributeValue("", "seq"); + } else { + currentSeqElement.children.add(seq); + seq.seqOrder = currentSeqElement.seqOrder; + } + currentSeqElement = seq; + } else { + startElement(attrsMap, name); + } } else if (tok == XmlPullParser.END_TAG) { - endElement(parser.getName()); + if(currentSeqElement == null) { + endElement(parser.getName()); + } else { + XmlTreeSequence process = currentSeqElement; + currentSeqElement = currentSeqElement.parent; + if (currentSeqElement == null) { + // Here we process sequence element + for(int i = 1; i < 5; i++) { + process.process(this, i); + } + } + } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java index 5948bcb5e1..86d0c2cb73 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRulesStoragePrinter.java @@ -21,7 +21,7 @@ import org.xmlpull.v1.XmlPullParserException; public class RenderingRulesStoragePrinter { public static void main(String[] args) throws XmlPullParserException, IOException { - RenderingRulesStorage.STORE_ATTTRIBUTES = true; + RenderingRulesStorage.STORE_ATTRIBUTES = true; // InputStream is = RenderingRulesStorage.class.getResourceAsStream("default.render.xml"); String defaultFile = "/Users/victorshcherb/osmand/repos/resources/rendering_styles/default.render.xml"; if(args.length > 0) { From b2027d563fa83a15743a34acfbeae2787bce6eed Mon Sep 17 00:00:00 2001 From: ssantos Date: Thu, 30 Jul 2020 14:51:49 +0000 Subject: [PATCH 10/20] Translated using Weblate (Portuguese) Currently translated at 100.0% (3438 of 3438 strings) --- OsmAnd/res/values-pt/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/values-pt/strings.xml b/OsmAnd/res/values-pt/strings.xml index 2994d515d2..e3a77032a9 100644 --- a/OsmAnd/res/values-pt/strings.xml +++ b/OsmAnd/res/values-pt/strings.xml @@ -1250,7 +1250,7 @@ Posto alfandegário Portagem Sinal de stop - Acalmia de tráfego + Choque de velocidade Radar de velocidade Aviso de tráfego Favoritos pertos From d7bd71dd989c059f3549ccad3588b5b15b24d224 Mon Sep 17 00:00:00 2001 From: Matas Alius Date: Thu, 30 Jul 2020 17:57:38 +0000 Subject: [PATCH 11/20] Translated using Weblate (Lithuanian) Currently translated at 63.1% (2171 of 3438 strings) --- OsmAnd/res/values-lt/strings.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/res/values-lt/strings.xml b/OsmAnd/res/values-lt/strings.xml index ef952e3795..0c0692c543 100644 --- a/OsmAnd/res/values-lt/strings.xml +++ b/OsmAnd/res/values-lt/strings.xml @@ -2792,4 +2792,7 @@ Tai yra puikus būdas paremti OsmAnd ir OSM, jei jie jums patinka. Sukurti naują maršrutą Pasirinkite trasos failą kurį norite atidaryti Padaryta + Pridėtas taškas nebus matomas žemėlapyje, nes pasirinkta grupė yra paslėpta, ją galite rasti \"%s\". + Pasirinkite intervalą nuo kurio taškas su atstumu ar laiku bus pavaizduojamas ekrane ant trasos. + Pasirinkite norima dalinimo variantą: pagal laiką arba pagal atstumą. \ No newline at end of file From ea4ee619588d76f8d03e7a032f7652d475b70ef1 Mon Sep 17 00:00:00 2001 From: WaldiS Date: Fri, 31 Jul 2020 11:57:16 +0000 Subject: [PATCH 12/20] Translated using Weblate (Polish) Currently translated at 99.6% (3427 of 3438 strings) --- OsmAnd/res/values-pl/strings.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index eef7882af8..7e577df92d 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -1329,7 +1329,7 @@ Kontrola graniczna Punkt poboru opłat Znak Stop - Uspokojenie ruchu + Próg zwalniający Fotoradar Ostrzeżenia drogowe Kliknij istniejący element, aby zobaczyć szczegóły, naciśnij i przytrzymaj, aby wyłączyć lub usunąć. Aktualne dane na urządzeniu (%1$s wolne): @@ -3833,7 +3833,7 @@ Wybierz żądaną opcję podziału: według czasu lub odległości. Stałe OsmAnd GPX nie jest dobrze uformowany, prosimy o kontakt z zespołem wsparcia technicznego w celu dalszego zbadania sprawy. - Wybierz limit czasu ekranu po przebudzeniu. (\"%1$s\" nie powoduje przekroczenia limitu czasu). + Wybierz limit czasu ekranu po przebudzeniu. (\"%1$s\" nie powoduje przekroczenia limitu czasu) Pokaż ikony rozpoczęcia i zakończenia Wybierz przedział czasowy, w którym będą wyświetlane znaki z dystansem lub czasem na torze. Niestandardowy @@ -3844,4 +3844,5 @@ Utwórz nową trasę Wybierz plik ścieżki do otwarcia. Wykonane + Wyłączone. Wymaga \"Trzymaj ekran włączony\" w obszarze \"Limit czasu po przebudzeniu\". \ No newline at end of file From 729f7cd502ab11af23bfb0913497818aba35d710 Mon Sep 17 00:00:00 2001 From: Osoitz Date: Thu, 30 Jul 2020 14:41:51 +0000 Subject: [PATCH 13/20] Translated using Weblate (Basque) Currently translated at 97.5% (3355 of 3438 strings) --- OsmAnd/res/values-eu/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/res/values-eu/strings.xml b/OsmAnd/res/values-eu/strings.xml index 7bb968baf9..69685b97e5 100644 --- a/OsmAnd/res/values-eu/strings.xml +++ b/OsmAnd/res/values-eu/strings.xml @@ -3786,4 +3786,5 @@ Area honi dagokio: %1$s x %2$s Erakutsi/ezkutatu Mapillary Ezkutatu Mapillary Erakutsi Mapillary + Egina \ No newline at end of file From d09e3854a0a4caac19ba5e78450632631af5dec0 Mon Sep 17 00:00:00 2001 From: Yannick A Date: Fri, 31 Jul 2020 20:57:02 +0000 Subject: [PATCH 14/20] Translated using Weblate (French) Currently translated at 99.8% (3807 of 3812 strings) --- OsmAnd/res/values-fr/phrases.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values-fr/phrases.xml b/OsmAnd/res/values-fr/phrases.xml index bc34ba433b..40afcf7e35 100644 --- a/OsmAnd/res/values-fr/phrases.xml +++ b/OsmAnd/res/values-fr/phrases.xml @@ -198,7 +198,7 @@ Service de reproduction de clefs Jardin d\'enfants Kiosque - Korfbal + Korfball Décharge Point de repère Laverie @@ -2069,7 +2069,7 @@ Wiki mongole Accessibilité aux fauteuils roulants Informel - Caractéristique de l\'eau : boueux + Boue Broussailles Coupe de bois Zone de croisement From 7e1400a316d58b4f2379dcf28d847e4bccdc6af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Priit=20J=C3=B5er=C3=BC=C3=BCt?= Date: Fri, 31 Jul 2020 21:46:22 +0000 Subject: [PATCH 15/20] Translated using Weblate (Estonian) Currently translated at 94.2% (3241 of 3438 strings) --- OsmAnd/res/values-et/strings.xml | 193 ++++++++++++++++++++++--------- 1 file changed, 141 insertions(+), 52 deletions(-) diff --git a/OsmAnd/res/values-et/strings.xml b/OsmAnd/res/values-et/strings.xml index b13ac9510c..c20de763d4 100644 --- a/OsmAnd/res/values-et/strings.xml +++ b/OsmAnd/res/values-et/strings.xml @@ -168,7 +168,8 @@ Peida OSM Notes Täname sind tagasiside eest Punkti või teed ei leitud. - Otsingutulemused puuduvad\? Anna tagasisidet + Otsingutulemused puuduvad\? +\nJaga tagasisidet Laienda otsingu raadiust kuni %1$s Saada otsingu päring? Maailm @@ -420,7 +421,7 @@ Kaks Üks Vali, kuidas kuvada kaugus aktiivsete markeriteni. - Määra suunaviitade arv: + Määra suunaviitade arv. Lemmikute kategooria Lisa grupp Loo kaardimarkereid! @@ -461,7 +462,7 @@ Avaneb homme kell Kuva suletud teated Kuva/peida OSM teated kaardil. - OSC - sobib OpenStreetMap-i viimiseks. + OSC - sobib andmete laadimiseks OpenStreetMap\'i andmebaasi OSC fail Vali faililiik Kõik andmed @@ -604,7 +605,7 @@ Välju Sisene peatuses Kuva/peida GPX rajad - Lüliti valitud GPX radade kaardil kuvamisekks või peitmiseks. + Nupp valitud GPX radade kaardil kuvamiseks või peitmiseks. Peida GPX rajad Kuva GPX rajad Palun määra esmalt sihtkoht @@ -658,7 +659,7 @@ Jalgrattatee Määratlemata OsmAnd teekonna arvutamise kohta loe lähemalt meie blogist. - Ühistranspordiga navigeerimine on praegu beeta testimisel, arvesta vigade ja ebatäpsusega. + Ühistranspordiga liikumine on praegu beetatestimisel, arvesta vigade ja ebatäpsusega. Lisa vahepunkt Kõndimine Lühenda \"%s\" sildi pikkust vähemale kui 255 tähemärgile. @@ -771,7 +772,7 @@ Vaikimisi kiirus Muuda vaikimisi kiiruse seadeid Määra vähim/suurim kiirus - Kasutusel kohale jõudmise aja hindamiseks tundmatute teede korral ja kiiruse piiramiseks kõikidel teedel (võib muuta teekonda) + Hindab saamumisaega tundmatute teede korral ja kiirusepiiranguid kõikidel teedel (võib muuta teekonda) Uus profiil Kokkujooksmine OsmAnd jooksis viimati kasutades kokku. Palun aita meil veateadet jagades OsmAnd rakendust parandada. @@ -925,7 +926,7 @@ Kleebi OsmAnd andmekausta asukoht Muuta OsmAnd andmekausta\? Liiguta uude asukohta - Sisemine salvestusruum, kasutaja ja teiste rakenduste eest peidetud, ainult OsmAnd juurdepääsetav + Sisemine salvestusruum, kasutaja ja teiste rakenduste eest peidetud, juurdepääsetav ainult OsmAnd\'ile. Muuda andmete salvestamise kausta Maastikupark Saan @@ -971,9 +972,9 @@ Eelista katteta teid. Uuenda kõiki kaarte Oled kindel, et soovid kõiki (%1$d) kaarte uuendada\? - • Uuendatud rakenduse ja profiili seaded: seaded on nüüd järjestatud tüübi järgi. Igat profiili saab kohandada eraldi. + • Uuendatud rakenduse ja profiili seadeid, mis on nüüd järjestatud tüübi järgi. Igat profiili saab kohandada eraldi. \n -\n • Uus kaartide alla laadimise dialoog, mis soovitab sirvimise ajal kaarte alla laadimiseks +\n • Uus kaartide allalaadimise dialoog, mis soovitab sirvimise ajal kaarte allalaadimiseks \n \n • Öise teema parandused \n @@ -1001,15 +1002,15 @@ Kuva künkavarjutus Peida künkavarjutus Kuva/peida künkavarjutus - Kõnesünteesi mootorit ei saa käivitada + Kõnesünteesi mootorit ei saa käivitada. Ekspordi profiil OsmAnd profiil: %1$s - Profiil \'%1$s\' on juba olemas. Kirjutada üle\? + „%1$s“ on juba olemas. Kas kirjutame üle\? Profiili ei saanud eksportida. - Profiili import - Profiili importimiseks vali selle fail seadmes ja ava see OsmAndiga. + Impordi profiil + Profiili importimiseks ava profiilifail OsmAndiga. %1$s importimise viga: %2$s - %1$s edukalt imporditud. + %1$s on imporditud. Valge Vaheta %1$s ja %2$s Lähtepunkt @@ -1023,9 +1024,9 @@ Halda OsmAnd kasutamise ajal kuvatavaid hüpikaknaid, dialooge ja teateid. Sõlmede võrgud Soovitatud kaardid - Need kaardid on laienduse kasutamisel nõutud + Need kaardid on laienduse kasutamisel nõutud. Lisatud profiilid - Laiendus lisab uue OsmAnd profiili + Laienduse poolt lisatud OsmAnd profiilid Lülita välja Uus laiendus lisatud Liida lõigud @@ -1038,9 +1039,9 @@ Allalaadimine %s Jäme Kõrbete ja muude hõredalt asustatud piirkondade jaoks. Kuvab üksikasjad vaateskaalal. - Vali navigeerimise ikoon - Vali kaardi ikoon - Peale nupu Rakenda vajutamist on kustutatud profiilid jäädavalt kadunud. + Liikumisel kuvatav asukohaikoon + Peatumisel kuvatav asukohaikoon + Rakenda-nupu vajutamisel on eemaldatakse kustutatud profiilid jäädavalt. Ülemprofiil Vali värv OsmAnd vaikimisi profiile ei saa kustutada, aga saate need eelmisel ekraanil keelata või lõppu nihutada. @@ -1216,13 +1217,13 @@ Suusakaardi vaade Parkimiskoht Kauguse kalkulaator & planeerimistöövahend - OpenStreetMap muutmine + OpenStreetMap\'i muutmine Ümber nimetamine ebaõnnestus. päeva maas Vaata Nõlva hooldus - Suusakaartide kuvamiseks on vajalik laadida alla spetsiaalne võrguühenduseta kaart - Merekaartide kuvamiseks on vajalik laadida alla spetsiaalne võrguühenduseta kaart + Suusakaartide kuvamiseks on vajalik laadida alla spetsiaalne võrguühenduseta kaart. + Merekaartide kuvamiseks on vajalik laadida alla spetsiaalne võrguühenduseta kaart. EEMALDA SILT Lae alla öösiti avaldatud versioone. Avaldatud versioonid @@ -1957,7 +1958,8 @@ Sinu OSM salasõna Taustarežiim OsmAnd töötab taustal, ekraan välja lülitatud. - Lae alla {0} fail(i)\? {1} MB (kokku {2} MB-st) võetakse kasutusse. + Kas laeme alla {0} fail(i)\? +\n{1} MB (kokku {2} MB-st) võetakse kasutusse. Läbipaistev teema Kaardivaade automaatselt keskele Aeg kuni kaardivaade sünkroniseerub praeguse asukohaga. @@ -2182,7 +2184,7 @@ Kasuta veebipõhist navigeerimist Uuenda kaart Vali hoone - Vali veebipõhiste või puhverdatud kaardipaanide allikas + Vali veebipõhiste või puhverdatud kaardipaanide allikas. Otsi hoonet kasvavalt Hoone Hoone @@ -2350,8 +2352,11 @@ Teine kaardimarker Tööriistariba Vidinad - Pole piisavalt ruumi! {3} MB on vajalik ajutiselt, {1} MB püsivalt. (Ainult {2} MB saadaval.) - Laadida alla {0} fail(i)\? {3} MB kasutatakse ajutiselt, {1} MB püsivalt. (Kokku {2} MB-st.) + Pole piisavalt ruumi! +\n{3} MB on vajalik ajutiselt ning {1} MB püsivalt. +\n(Ainult {2} MB saadaval.) + Kas laeme alla {0} fail(i)\? +\n{3} MB kasutatakse ajutiselt, {1} MB püsivalt. (Kokku {2} MB-st.) Lae üles OSM märge Lae üles anonüümselt Vali kaardimarker @@ -2378,7 +2383,9 @@ Osa sinu annetusest saadetakse OSM kasutajatele, kes teevad kaardimuudatusi selles piirkonnas. Tellimuse seaded Palun osta esmalt OsmAnd Live tellimus - See liitumine võimaldab kogu maailma kaartide värskendusi iga tund. Osa sissetulekust läheb tagasi OSM kogukonnale ja makstakse välja iga OSM kaastöö eest. Kui sulle meeldib OsmAnd ja OSM ning soovite neid toetada ja olla nende poolt toetatud, ongi see suurepärane viis nii teha. + See liitumine võimaldab kogu maailma kaartide värskendusi kord tunnis. +\nOsa sissetulekust läheb tagasi OSM kogukonnale ja makstakse välja iga OSM kaastöö eest. +\nKui sulle meeldib OsmAnd ja OSM ning soovite neid toetada ja olla nende poolt toetatud, ongi see suurepärane viis nii teha. Ülemine riba Lülitatud ümber sisemälule, sest valitud andmekandjal puudub kirjutusõigus. Palun vali kirjutusõigusega salvestuskaust. Jagatud mälu @@ -2584,7 +2591,7 @@ Lülita sisse animeeritud oma asukohas kaardi panoraamimine navigeerimise ajal. Lae alla \'Kõrgusjoonte\' kaart selles piirkonnas kasutamiseks. Osta ja paigalda \'Kõrgusjoonte\' lisa astmestatud vertikaalsete alade kuvamiseks. - Lülita OSM märkmete kaardil kuvamine sisse või välja. + Nupp, mis lülitab OSM märkmete kaardil kuvamise sisse või välja. Sinu sihtkoht asub eramaal. Luba kasutada erateid sellel teekonnal\? Võimaldab kiireid Mapillary kaastöid. Veebis tänavataseme fotod kõigile. Avasta kohti, tee kaastööd, jäädvusta maailma. @@ -2622,13 +2629,13 @@ Pikk või lühike \'Kohad\' vajutus, seejärel vajuta markeri lipu nuppu. Impordi lemmikute grupid või teekonnapunktid markeritena. Läbituks märgitud markerid ilmuvad siia ekraanile. - Loo või muuda huvipunkte, ava või kommenteeri OSM märkmeid ja panusta GPX failide osas. + Loo või muuda huvipunkte, ava või kommenteeri OSM märkmeid ja lisa salvestatud GPX faile. Puuduta markerit kaardil selle liigutamiseks aktiivsete markerite algusesse ilma kontekstimenüüd avamata. Lisa heli, video või fotomärge igale punktile kaardil, kasutades vidinat või kontekstimenüüd. Muudatusi %1$s, kokku %2$s mBTC Lao GPX - sobib ekspordiks JOSM või teistesse OSM redaktoritesse. - Vali ekspordi liik: OSM märkmed, huvipunktid või mõlemad. + Ekspordi kas OSM märkmetena, huvipunktidena või mõlemana. Võrguühenduseta reisijuhi funktsioonide saamiseks osta üks järgmistest: Reisijuhid põhinevad praegu Wikivoyage\'il. Testige beetaversiooni ajal kõiki funktsioone tasuta. Pärast seda on reisijuhid kättesaadavad piiranguteta OsmAnd tellijatele ja OsmAnd+ omanikele. Saate ja peaksite redigeerima kõiki artikleid Wikivoyage\'is. Jagage teadmisi, kogemusi, annet ja oma tähelepanu. @@ -2693,7 +2700,7 @@ \nGlobaalsed andmed (vahemikus 70 ° põhja ja 70 ° lõuna) põhinevad mõõtmistel, mille on teinud SRTM (süstiku radari topograafiamissioon) ja ASTER (täiustatud kosmose termilise kiirguse ja peegelduse radiomeeter), NASA maavaatlussatelliitide süsteemi lipulaeva Terra pardal olev pildistamisinstrument. ASTER on NASA, Jaapani majandus-, kaubandus- ja tööstusministeeriumi (METI) ja Jaapani kosmosesüsteemide (J-kosmosesüsteemid) koostöö. Selle vaate aktiveerimine muudab OsmAndi kaardistiili \'Reisivaateks\'. See on reisijatele ja kutselistele autojuhtidele mõeldud eriline kõrglahutusega vaade. \n -\nSee vaade pakub igal kaardi suurendamisel maksimaalse hulga kaardiandmetes saada olevaid reisiandmeid (eriti teed, rajad, rajad ja orientatsioonimärgid). +\nSee vaade pakub igal kaardi suurendamisel maksimaalse hulga kaardiandmetes saada olevaid reisiandmeid (eriti teed, rajad ja orientatsioonimärgid). \n \nSamuti kujutab see värvikoodide abil üheselt mõistetavalt igat tüüpi teid, mis on kasulik nt. suurte sõidukite juhtimisel. \n @@ -2743,8 +2750,8 @@ WiFi ühendus puudub. Kas kasutada allalaadimiseks praegust internetiühendust\? Kuvab taustajälgimise ja navigeerimise sisselülitamise sätteid GPS-seadet perioodiliselt äratades (välja lülitatud ekraaniga). Oled kindel, et soovid sihtkoha (ja vahepealsed sihtkohad) tühjendada\? - Dropboxi lisa võimaldab sul sünkroonida lugusid ja heli- või videomärkmeid oma Dropboxi kontoga. - Edasise arengu toetamiseks palun kaalu \'Kõrgusjooned\' lisa ostmist. + Sünkrooni salvestatud radasid ja heli- või videomärkmeid oma Dropboxi kontole. + Edasise arendustöö toetamiseks palun kaalu Kõrgusjoonte lisa ostmist. Esitatakse määratud salvestuse heli. \n%1$s Puuduta \'Kasuta asukohta…\' asukohta märkuse lisamiseks. @@ -2757,7 +2764,8 @@ Kiirusele vastav suurendustase (kuni kaart on hetkeasukohaga sünkroonitud). Globaalne mobiilikaartide vaatamine ja navigeerimine OSM võrguühenduseta ja veebikaartide jaoks Globaalne mobiilikaardi vaatamine ja navigeerimine võrguühenduseta ja veebipõhistes OSM-kaartides - Kogu rakendusele eraldatud mälumaht %1$s MB (Dalvik %2$s MB, muu %3$s MB). Proportsionaalne mälumaht %4$s MB (Androidi limiit %5$s MB, Dalvik %6$s MB). + Kogu rakendusele eraldatud mälumaht on %1$s MB (Dalvik %2$s MB, muu %3$s MB). +\nProportsionaalne mälumaht on %4$s MB (Androidi mahupiir %5$s MB, Dalvik %6$s MB). Sinu kalendrisse on lisatud teavitus auto kättesaamise kohta ja seda saab seal muuta või eemaldada. Muuda kõik kaardil olevad maapealsed objektid läbipaistvaks. Optimeeri kaarti @@ -3346,8 +3354,8 @@ Teekond: vahemaa %s, marsruuteri aeg %s \nArvutamine: %.1f sek, %d teed, %d paani) Vajutades nupul %1$s kaovad kõik muudatused. - Kõik profiiliseaded lähtestatakse paigaldusjärgsesse olekusse. - Taasta kõikide profiiliseadete vaikeväärtused\? + Lähtesta kõik profiiliseaded paigaldusjärgsesse olekusse. + Kas asendame kõik profiiliseaded vaikeväärtustega\? %1$s: %2$s %1$s %2$s Hinda @@ -3370,11 +3378,11 @@ Teekonna ümberarvutamine Teata Kasutajanimi ja salasõna - Selle lisa seaded kehtivad kogu rakenduses ja rakenduvad kõikidele profiilidele. - OpenStreetMap muutmine - Kõiki üleslaadimata muudatusi või osm vigu saad vaadata menüüs %1$s. Üleslaaditud punkte OsmAnd ei kuva. + Need seaded rakenduvad kõikidele profiilidele. + OSM\'i andmete muutmine + Kõiki üleslaadimata muudatusi või OSM vigu saad vaadata menüüs %1$s. Üleslaaditud punkte OsmAnd ei kuva. OSM - Ikooni näed ainult navigeerimise või liikumise ajal. + Ikooni kuvatakse vaid navigeerimise või liikumise ajal. Kaardiikoon kuvatakse ainult kaardil ja muutub navigeerimise ajal navigeerimise ikooniks. Kontrolli ja jaga rakenduse detailseid logisid Geokavatsuse väärtusest \'%s\' ei saanud aru. @@ -3384,7 +3392,7 @@ Soovitus: proovige kõigepealt kasutada liikumisandurit minimaalse nihkefiltri (B) kaudu, kuna see võib anda paremaid tulemusi ja te kaotate vähem andmeid. Kui teie rajad jäävad madalatel kiirustel lärmakaks, proovige siin nullist erinevat väärtust. Pange tähele, et mõned mõõtmised ei pruugi kiiruse väärtust üldse anda (mõned võrgupõhised meetodid), sellisel juhul ei salvestaks te midagi. Märkus: kiirus > 0 kontroll: enamik GPS-kiibikomplekte teatab kiiruse väärtuse ainult siis, kui algoritm määrab teie liikumise, ja mitte ükski, kui te pole. Seega kasutab filtri sätte > 0 kasutamine teatud mõttes GPS-kiibistiku liikumistuvastust. Kuid isegi kui seda siin salvestuse ajal ei filtreerita, kasutame seda funktsiooni oma GPX analüüsis korrigeeritud vahemaa määramiseks, st sellel väljal kuvatav väärtus on liikumisel salvestatud vahemaa. See registreerib ainult minimaalse täpsusnäiduga mõõdetud punktid (meetrites / jalgades, nagu Androidi teatas teie kiibistiku kohta). Täpsus tähendab korduvate mõõtmiste hajumist ega ole otseselt seotud täpsusega, mis määratleb, kui lähedal on teie mõõtmised teie tegelikule asukohale. - Kõrvaltoime: täpsusega filtreerimise tulemusel võivad punktid olla nt nt. sildade all, puude all, kõrgete hoonete vahel või teatud ilmastikutingimuste korral. + Kõrvaltoime: täpsusega filtreerimise tulemusel võivad punktid olla näiteks sildade all, puude all, kõrgete hoonete vahel või teatud ilmastikutingimuste korral. Soovitus: raske on ennustada, mida salvestatakse ja mida mitte, võib-olla oleks parem see filter välja lülitada. Märkus: kui GPS oleks välja lülitatud vahetult enne salvestust, võib esimese mõõdetud punkti täpsus olla vähenenud, nii et meie koodis võiksime enne punkti salvestamist oodata umbes sekund (või salvestada 3 järjestikuse punkti parimad andmed jne.), kuid seda pole veel rakendatud. See filter väldib dubleerivate punktide registreerimist seal, kus tegelikku liikumist võis olla liiga vähe, muudab radade hilisema ruumilise väljanägemise, mida hiljem ei töödelda. @@ -3404,7 +3412,7 @@ Kaamera katiku heli Autoriseerimine õnnestus Ava seaded - Keela ümberarvutus + Ära kasuta ümberarvutust Määra profiili nimi Vali imporditavad andmed. Mõned kirjed on juba olemas @@ -3430,7 +3438,7 @@ Kohandatud profiil Maastik Kõrgusreljeefi kaart tumedate varjunditega nõlvade, tippude ja tasandike kirjeldamiseks. - Nõlv märgib maastikku värvidega. + Raja nõlva kallet visualiseeritakse värvidega. Määra vähima ja suurima suurenduse kaardikihi kuvamisel. Kõrgusreljeefi kuvamiseks on vaja täiendavaid kaarte. Nõlvade kuvamiseks on vaja täiendavaid kaarte. @@ -3438,12 +3446,12 @@ Läbipaistvus Suurendus Tingmärgid - Luba kõrgusreljeefi või nõlvakaardi kuvamiseks. Nendest kaarditüüpidest saab rohkem lugeda meie kodulehel + Luba kõrgusreljeefi või nõlvakaardi kuvamiseks. Neist kaarditüüpidest saad rohkem lugeda meie veebisaidis. Kõrgusreljeef - Kõik andmed %1$s-st imporditud, rakenduse vajaliku osaga töötamiseks võib kasutada nuppe allpool. + Kõik andmed %1$s-st on imporditud, rakenduse vajaliku osaga töötamiseks võid kasutada nuppe allpool. Imporditud Kirjed lisatud - OsmAnd kontrollib %1$s rakenduses korduvate kirjete osas. + OsmAnd kontrollib %1$s rakenduses korduvaid kirjeid. \n \nSelleks võib kuluda aega. Importimine @@ -3458,7 +3466,7 @@ Teekonna ümberarvutus, kui kaugus teekonnast praegusesse asukohta on suurem valitud väärtusest. %1$s %2$s-st Nõlvad - Kuva/peida maastik + Kuva või peida maastik Peida maastik Kuva maastik Nupp maastikukihi kuvamiseks või peitmiseks kaardil. @@ -3470,14 +3478,14 @@ Kaheksanurk Ruut Min - Asenda sellega mõni teine punkt + Asenda sellega mõni teine punkt. Suusasõit Mootorsaan Kohandatud OsmAnd pistik - Profiil %1$s muudetud. - Ei saanud lugeda %1$s. - Ei saanud kirjutada %1$s. - Ei saanud importida %1$s. + Profiil %1$s on muudetud. + Ei saanud lugeda %1$s\'st. + Ei saanud kirjutada %1$s\'sse. + Ei saanud importida %1$s\'st. Kõik Vikipeedia artiklid ei pruugi olla saadaval sinu valitud keeles. Kantoni Lõunamini @@ -3525,4 +3533,85 @@ Keel Kõik keeled Antarktis + Pseudo-Mercatori projektsioon + Üks pildifail paani kohta + SQLiteDB fail + Sisesta veebikaardi allika nimi. + Sisesta või kopeeri võrguallika aadress. + Muuda võrguallikat + Aegumise ajavahemik + Mercatori projektsioon + Salvestusvorming + Määra võrgukaardi kuvamiseks või laadimiseks vähim ja suurim suumitase. + Minimaalne kaugus marsruudi ümberarvutamiseks + %1$s — %2$s — %3$s + Menüü + Lähedusandur + Hoia ekraan sisselülitatuna + Hoia ekraan väljalülitatuna + Vikipedia huvipunktide kuvamiseks on vaja täiendavaid kaarte. + Valige kaardil olevad Vikipeedia artiklite keeled. Artikli lugemise ajal kasuta ükskõik millist saadaolevat keelt. + %1$s / %2$s + Otsi huvipunktide tüüpe + Peida ühistranspordi teave + Näita ühistranspordi teavet + Kuva või peida ühistransport + Nupp, mis kuvab või peidab ühistranspordiandmed kaardil. + Lisa või muuda huvipunkti + Öine kaart + Võrguallika lisamine + Nende muudatuste rakendamine tühjendab selle paaniallika vahemällu talletatud andmed + Suletud OSM märkus + Määra laeva kõrgus + Madalate sildade vältimiseks saad kirjeldada laeva kõrguse. Palun arvesta, et liikuva silla puhul me kasutame seda kõrgust ka siis, kui sild on avatud. + Madalate sildade vältimiseks kirjelda laeva kõrgus. Palun arvesta, et liikuva silla puhul me kasutame seda kõrgust ka siis, kui sild on avatud. + Lühikeste sildade vältimiseks kirjelda laeva laius + Näita või peida Mapillary andmed + Peida Mapillary andmed + Näita Mapillary andmeid + Nupp, mis näitab või peidab kaardil Mapillary kihti. + Eemalda ja taaskäivita + Rulluisud + Kustuta järgmine sihtpunkt + Sisselülitades saad seadme helitugevuse nuppudega kontrollida kaardi suumi taset. + Helitugevuse nupud toimivad suumina + Palun sisestage punkti nimi + Lae alla Vikipeedia kaardid + Hangi huviväärsuste kohta teavet Vikipeediast. See on sinu võrguühenduseta reisiraamat - luba lihtsalt Vikipeedia lisaprogramm ja loe artikleid enda ümber asuvate objektide kohta. + Kuna valitud grupp on peidetud, siis lisatud punkt ei ole kaardil nähtav. Vajadusel leiad ta „%s“ alt. + Kartauto + Parkimiskohad + Lisa lemmik või muuda seda + Ratastool + Enduro mootorratas + Motoroller + Vali välp, mille alusel kuvatakse rajal aja- või vahemaamärgid. + Vali soovitud jagamise viis - kas aja või vahemaa alusel. + Ühtlane + Iga navigeerimisjuhis lülitab ekraani tööle. + Navigeerimisjuhised + Seadme toitenupu vajutamisel lülitatakse ekraan tööle ning OsmAnd\'i näidatakse lukustuskuval. + Toitenupp + Eemalda + Täiendavad kaardid + Vali kuidas sa soovid allalaetud paane salvestada. + OsmAnd ja Mapillary + Kiirtegevus + Raadiuse joonlaud + Täpsusta marsruutidel lubatud sõiduki pikkus. + Pikkuse piirang + Kurss + %1$s on kustutatud + Selleks, et eemaldada kõik kiiruskaamerate andmed on vajalik seadme taaskäivitamine. + Siin seadmes puudub teave liikluskaamerate kohta. + Lisa profiil + Muuda rakenduse profiili + Ühtegi sellist profiili ei leidunud. + Maailma detailne üldkaart + Faili tüüp ei ole toetatud + Kuna mõnedel marsruutidel võidakse kohaldada sõidukite laiuspiiranguid, siis palun märkige oma sõiduki laius. + Kuna mõnedel marsruutidel võidakse kohaldada sõidukite kõrguspiiranguid, siis palun märkige oma sõiduki kõrgus. + Kuna mõnedel marsruutidel võidakse kohaldada piiranguid pikkade sõidukite suhtes, siis palun märkige oma sõiduki pikkus. + Kuna mõnedel marsruutidel võidakse kohaldada sõidukite kaalupiiranguid, siis palun märkige oma sõiduki kaal. + OsmAnd GPX faili vorming pole korrektne. Täpsemaks uurimiseks palun suhtle meie tugimeeskonnaga. \ No newline at end of file From 607ec9116d04d384372ed5bae8f59d1e3e85e6b7 Mon Sep 17 00:00:00 2001 From: Yannick A Date: Fri, 31 Jul 2020 20:58:02 +0000 Subject: [PATCH 16/20] Translated using Weblate (French) Currently translated at 99.2% (265 of 267 strings) Translation: OsmAnd/Telegram Translate-URL: https://hosted.weblate.org/projects/osmand/telegram/fr/ --- OsmAnd-telegram/res/values-fr/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd-telegram/res/values-fr/strings.xml b/OsmAnd-telegram/res/values-fr/strings.xml index 9ebff1a4d8..1b47b732fd 100644 --- a/OsmAnd-telegram/res/values-fr/strings.xml +++ b/OsmAnd-telegram/res/values-fr/strings.xml @@ -264,4 +264,5 @@ Définir l\'intervalle minimum pour partager sa position. La dernière fois qu\'un contact s\'est déplacé. Cacher les contacts qui ne se sont pas déplacés depuis un temps donné. + Définissez l\'heure à laquelle les contacts et groupes sélectionnés verront votre position en temps réel. \ No newline at end of file From 094bd14c62d4b8e3375972a00348e670b18db24d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 1 Aug 2020 13:35:42 +0300 Subject: [PATCH 17/20] Add custom track colors --- OsmAnd/build.gradle | 1 + OsmAnd/res/layout/custom_color_picker.xml | 63 +++++ OsmAnd/res/layout/track_coloring_card.xml | 2 +- .../plus/settings/backend/OsmandSettings.java | 1 + .../plus/track/CustomColorBottomSheet.java | 228 ++++++++++++++++++ .../plus/track/TrackAppearanceFragment.java | 13 +- .../osmand/plus/track/TrackColoringCard.java | 147 +++++++++-- 7 files changed, 437 insertions(+), 18 deletions(-) create mode 100644 OsmAnd/res/layout/custom_color_picker.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index 714b85eae8..e33b1ca75f 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -563,6 +563,7 @@ dependencies { implementation ("com.github.HITGIF:TextFieldBoxes:1.4.5"){ exclude group: 'com.android.support' } + implementation 'com.jaredrummler:colorpicker:1.1.0' huaweiImplementation files('libs/huawei-android-drm_v2.5.2.300.jar') freehuaweiImplementation files('libs/huawei-android-drm_v2.5.2.300.jar') diff --git a/OsmAnd/res/layout/custom_color_picker.xml b/OsmAnd/res/layout/custom_color_picker.xml new file mode 100644 index 0000000000..db6c3a254c --- /dev/null +++ b/OsmAnd/res/layout/custom_color_picker.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_coloring_card.xml b/OsmAnd/res/layout/track_coloring_card.xml index 47326a9ad7..5775a98c7d 100644 --- a/OsmAnd/res/layout/track_coloring_card.xml +++ b/OsmAnd/res/layout/track_coloring_card.xml @@ -40,7 +40,7 @@ - CURRENT_TRACK_WIDTH = new StringPreference("current_track_width", "").makeGlobal().cache(); public final CommonPreference CURRENT_TRACK_SHOW_ARROWS = new BooleanPreference("current_track_show_arrows", false).makeGlobal().cache(); public final CommonPreference CURRENT_TRACK_SHOW_START_FINISH = new BooleanPreference("current_track_show_start_finish", true).makeGlobal().cache(); + public final ListStringPreference CUSTOM_TRACK_COLORS = (ListStringPreference) new ListStringPreference("custom_track_colors", null, ",").makeGlobal(); // this value string is synchronized with settings_pref.xml preference name public final CommonPreference SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java new file mode 100644 index 0000000000..66029119d5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java @@ -0,0 +1,228 @@ +package net.osmand.plus.track; + +import android.app.Activity; +import android.graphics.Color; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.EditText; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import com.jaredrummler.android.colorpicker.ColorPanelView; +import com.jaredrummler.android.colorpicker.ColorPickerView; +import com.jaredrummler.android.colorpicker.ColorPickerView.OnColorChangedListener; + +import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; + +import org.apache.commons.logging.Log; + +public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implements OnColorChangedListener { + + private static final String TAG = CustomColorBottomSheet.class.getSimpleName(); + + private static final Log log = PlatformUtil.getLog(CustomColorBottomSheet.class); + + private static final String NEW_SELECTED_COLOR = "new_selected_color"; + private static final String PREV_SELECTED_COLOR = "prev_selected_color"; + + private ColorPickerView colorPicker; + private ColorPanelView newColorPanel; + + private EditText hexEditText; + private boolean fromEditText; + + @ColorInt + private int prevColor; + @ColorInt + private int newColor; + + @Override + public void createMenuItems(Bundle savedInstanceState) { + if (savedInstanceState != null) { + newColor = savedInstanceState.getInt(NEW_SELECTED_COLOR); + prevColor = savedInstanceState.getInt(PREV_SELECTED_COLOR); + } else { + Bundle args = getArguments(); + if (args != null) { + prevColor = args.getInt(PREV_SELECTED_COLOR); + newColor = prevColor != -1 ? prevColor : Color.RED; + } + } + + items.add(new TitleItem(getString(R.string.select_color))); + + BaseBottomSheetItem item = new SimpleBottomSheetItem.Builder() + .setCustomView(createPickerView()) + .create(); + items.add(item); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putInt(NEW_SELECTED_COLOR, newColor); + outState.putInt(PREV_SELECTED_COLOR, prevColor); + super.onSaveInstanceState(outState); + } + + private View createPickerView() { + LayoutInflater themedInflater = UiUtilities.getMaterialInflater(getActivity(), nightMode); + View colorView = themedInflater.inflate(R.layout.custom_color_picker, null); + colorPicker = colorView.findViewById(R.id.color_picker_view); + newColorPanel = colorView.findViewById(R.id.color_panel_new); + hexEditText = colorView.findViewById(R.id.color_hex_edit_text); + + setHex(newColor); + newColorPanel.setColor(newColor); + colorPicker.setColor(newColor, true); + colorPicker.setOnColorChangedListener(this); + hexEditText.addTextChangedListener(new TextWatcher() { + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + if (hexEditText.isFocused()) { + int color = parseColorString(s.toString()); + if (color != colorPicker.getColor()) { + fromEditText = true; + colorPicker.setColor(color, true); + } + } + } + }); + + return colorView; + } + + @Override + public void onColorChanged(int newColor) { + this.newColor = newColor; + if (newColorPanel != null) { + newColorPanel.setColor(newColor); + } + if (!fromEditText && hexEditText != null) { + setHex(newColor); + Activity activity = getActivity(); + if (activity != null && hexEditText.hasFocus()) { + AndroidUtils.hideSoftKeyboard(activity, hexEditText); + hexEditText.clearFocus(); + } + } + fromEditText = false; + } + + private void setHex(int color) { + hexEditText.setText(String.format("%08X", color)); + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + @Override + protected void onRightBottomButtonClick() { + Fragment target = getTargetFragment(); + if (target instanceof ColorPickerListener) { + ((ColorPickerListener) target).onColorSelected(prevColor, newColor); + } + dismiss(); + } + + public static void showInstance(@NonNull FragmentManager fragmentManager, Fragment target, int prevColor) { + try { + if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(CustomColorBottomSheet.TAG) == null) { + Bundle args = new Bundle(); + args.putInt(PREV_SELECTED_COLOR, prevColor); + + CustomColorBottomSheet customColorBottomSheet = new CustomColorBottomSheet(); + customColorBottomSheet.setArguments(args); + customColorBottomSheet.setTargetFragment(target, 0); + customColorBottomSheet.show(fragmentManager, CustomColorBottomSheet.TAG); + } + } catch (RuntimeException e) { + log.error(e); + } + } + + private static int parseColorString(String colorString) throws NumberFormatException { + int a, r, g, b = 0; + if (colorString.startsWith("#")) { + colorString = colorString.substring(1); + } + if (colorString.length() == 0) { + r = 0; + a = 255; + g = 0; + } else if (colorString.length() <= 2) { + a = 255; + r = 0; + b = Integer.parseInt(colorString, 16); + g = 0; + } else if (colorString.length() == 3) { + a = 255; + r = Integer.parseInt(colorString.substring(0, 1), 16); + g = Integer.parseInt(colorString.substring(1, 2), 16); + b = Integer.parseInt(colorString.substring(2, 3), 16); + } else if (colorString.length() == 4) { + a = 255; + r = Integer.parseInt(colorString.substring(0, 2), 16); + g = r; + r = 0; + b = Integer.parseInt(colorString.substring(2, 4), 16); + } else if (colorString.length() == 5) { + a = 255; + r = Integer.parseInt(colorString.substring(0, 1), 16); + g = Integer.parseInt(colorString.substring(1, 3), 16); + b = Integer.parseInt(colorString.substring(3, 5), 16); + } else if (colorString.length() == 6) { + a = 255; + r = Integer.parseInt(colorString.substring(0, 2), 16); + g = Integer.parseInt(colorString.substring(2, 4), 16); + b = Integer.parseInt(colorString.substring(4, 6), 16); + } else if (colorString.length() == 7) { + a = Integer.parseInt(colorString.substring(0, 1), 16); + r = Integer.parseInt(colorString.substring(1, 3), 16); + g = Integer.parseInt(colorString.substring(3, 5), 16); + b = Integer.parseInt(colorString.substring(5, 7), 16); + } else if (colorString.length() == 8) { + a = Integer.parseInt(colorString.substring(0, 2), 16); + r = Integer.parseInt(colorString.substring(2, 4), 16); + g = Integer.parseInt(colorString.substring(4, 6), 16); + b = Integer.parseInt(colorString.substring(6, 8), 16); + } else { + b = -1; + g = -1; + r = -1; + a = -1; + } + return Color.argb(a, r, g, b); + } + + public interface ColorPickerListener { + + void onColorSelected(@ColorInt int prevColor, @ColorInt int newColor); + + } +} \ 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 0c2176687c..4834a43b0e 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -41,6 +41,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener; import net.osmand.plus.track.SplitTrackAsyncTask.SplitTrackListener; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; @@ -57,9 +58,9 @@ 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; -public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener { +public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener { - public static final String TAG = TrackAppearanceFragment.class.getSimpleName(); + public static final String TAG = TrackAppearanceFragment.class.getName(); private static final Log log = PlatformUtil.getLog(TrackAppearanceFragment.class); @@ -76,6 +77,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement private TrackWidthCard trackWidthCard; private SplitIntervalCard splitIntervalCard; + private TrackColoringCard trackColoringCard; private ImageView trackIcon; @@ -324,6 +326,11 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement } + @Override + public void onColorSelected(int prevColor, int newColor) { + trackColoringCard.onColorSelected(prevColor, newColor); + } + @Override protected int applyPosY(int currentY, boolean needCloseMenu, boolean needMapAdjust, int previousMenuState, int newMenuState, int dZoom, boolean animated) { int y = super.applyPosY(currentY, needCloseMenu, needMapAdjust, previousMenuState, newMenuState, dZoom, animated); @@ -555,7 +562,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement directionArrowsCard.setListener(this); cardsContainer.addView(directionArrowsCard.build(mapActivity)); - TrackColoringCard trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo); + trackColoringCard = new TrackColoringCard(mapActivity, trackDrawInfo, this); trackColoringCard.setListener(this); cardsContainer.addView(trackColoringCard.build(mapActivity)); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index fbc9eebcdc..7d102c44fa 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -1,12 +1,13 @@ 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.FrameLayout; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.ColorInt; @@ -14,10 +15,14 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.internal.FlowLayout; + import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -25,16 +30,22 @@ 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 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; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; -public class TrackColoringCard extends BaseCard { +public class TrackColoringCard extends BaseCard implements ColorPickerListener { + + public static final int INVALID_VALUE = -1; private final static String SOLID_COLOR = "solid_color"; + private static final Log log = PlatformUtil.getLog(TrackColoringCard.class); private TrackDrawInfo trackDrawInfo; @@ -42,10 +53,15 @@ public class TrackColoringCard extends BaseCard { private TrackAppearanceItem selectedAppearanceItem; private List appearanceItems; - public TrackColoringCard(MapActivity mapActivity, TrackDrawInfo trackDrawInfo) { + private List customColors; + private Fragment target; + + public TrackColoringCard(MapActivity mapActivity, TrackDrawInfo trackDrawInfo, Fragment target) { super(mapActivity); + this.target = target; this.trackDrawInfo = trackDrawInfo; appearanceItems = getGradientAppearanceItems(); + customColors = getCustomColors(); } @Override @@ -67,6 +83,25 @@ public class TrackColoringCard extends BaseCard { 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)); @@ -80,6 +115,16 @@ public class TrackColoringCard extends BaseCard { 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 : getAppearanceItems(app, GpxAppearanceAdapterType.TRACK_COLOR)) { if (!colors.contains(appearanceListItem.getColor())) { @@ -87,20 +132,13 @@ public class TrackColoringCard extends BaseCard { } } for (int color : colors) { - selectColor.addView(createColorItemView(color, selectColor), new FlowLayout.LayoutParams(0, 0)); + selectColor.addView(createColorItemView(color, selectColor, false)); } updateColorSelector(trackDrawInfo.getColor(), 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))); + private View createColorItemView(@ColorInt final int color, final FlowLayout rootView, boolean customColor) { + View colorItemView = createCircleView(rootView); 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() { @@ -116,10 +154,68 @@ public class TrackColoringCard extends BaseCard { } } }); + 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 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_add, 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, TrackColoringCard.INVALID_VALUE); + } + } + }); + 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) { @@ -175,6 +271,29 @@ public class TrackColoringCard extends BaseCard { updateColorSelector(); } + @Override + public void onColorSelected(int prevColor, int newColor) { + if (prevColor == INVALID_VALUE && customColors.size() < 6) { + customColors.add(newColor); + } else if (!Algorithms.isEmpty(customColors)) { + int index = customColors.indexOf(prevColor); + if (index != INVALID_VALUE) { + customColors.set(index, newColor); + } + } + saveCustomColors(); + updateContent(); + } + + 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; From df0dc024f8faa2a76f445f5fd57d3fa98455db0b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 1 Aug 2020 15:01:34 +0300 Subject: [PATCH 18/20] Fix default track width --- OsmAnd/src/net/osmand/plus/views/GPXLayer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index b2a893d6f3..4eb6e3d30d 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -423,7 +423,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM boolean showArrows = isShowArrowsForTrack(selectedGpxFile.getGpxFile()); if (showArrows) { QuadRect correctedQuadRect = getCorrectedQuadRect(tileBox.getLatLonBounds()); - String width = getTrackWidthName(selectedGpxFile.getGpxFile(), defaultTrackWidthPref.get()); + String width = getTrackWidthName(selectedGpxFile.getGpxFile(), ""); float trackWidth = getTrackWidth(width, defaultTrackWidth); int color = getTrackColor(selectedGpxFile.getGpxFile(), cachedColor); int contrastColor = UiUtilities.getContrastColor(view.getApplication(), color, false); @@ -761,7 +761,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM List selectedGPXFiles, DrawSettings settings) { SelectedGpxFile currentTrack = null; for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) { - String width = getTrackWidthName(selectedGpxFile.getGpxFile(), defaultTrackWidthPref.get()); + String width = getTrackWidthName(selectedGpxFile.getGpxFile(), ""); if (!cachedTrackWidth.containsKey(width)) { cachedTrackWidth.put(width, null); } @@ -780,7 +780,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM RotatedTileBox tileBox, DrawSettings settings) { List segments = selectedGpxFile.getPointsToDisplay(); for (TrkSegment ts : segments) { - String width = getTrackWidthName(selectedGpxFile.getGpxFile(), defaultTrackWidthPref.get()); + String width = getTrackWidthName(selectedGpxFile.getGpxFile(), ""); int color = getTrackColor(selectedGpxFile.getGpxFile(), ts.getColor(cachedColor)); if (ts.renderer == null && !ts.points.isEmpty()) { if (currentTrack) { From c334cfa62e5252eb1114c9a4c21677c7ce9203fd Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 1 Aug 2020 15:53:41 +0300 Subject: [PATCH 19/20] Remove unnecessary method --- .../main/java/net/osmand/util/Algorithms.java | 4 +- .../net/osmand/plus/GpxSelectionHelper.java | 12 +++- .../plus/track/CustomColorBottomSheet.java | 63 +++---------------- .../src/net/osmand/plus/views/GPXLayer.java | 44 +++++++------ 4 files changed, 40 insertions(+), 83 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index b5a466cb8b..6a3425c05e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -320,10 +320,8 @@ public class Algorithms { * exception. Supported formats are: * #RRGGBB * #AARRGGBB - * 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', - * 'yellow', 'lightgray', 'darkgray' */ - public static int parseColor(String colorString) { + public static int parseColor(String colorString) throws IllegalArgumentException { if (colorString.charAt(0) == '#') { // Use a long to avoid rollovers on #ffXXXXXX if (colorString.length() == 4) { diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 76425c8e0c..8281a127e4 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -520,12 +520,12 @@ public class GpxSelectionHelper { } GPXFile gpx = GPXUtilities.loadGPXFile(fl); if (obj.has(COLOR)) { - int clr = Algorithms.parseColor(obj.getString(COLOR)); + int clr = parseColor(obj.getString(COLOR)); gpx.setColor(clr); } for (GradientScaleType scaleType : GradientScaleType.values()) { if (obj.has(scaleType.getColorTypeName())) { - int clr = Algorithms.parseColor(obj.getString(scaleType.getColorTypeName())); + int clr = parseColor(obj.getString(scaleType.getColorTypeName())); gpx.setGradientScaleColor(scaleType.getColorTypeName(), clr); } } @@ -567,6 +567,14 @@ public class GpxSelectionHelper { } } + private int parseColor(String color) { + try { + return Algorithms.isEmpty(color) ? 0 : Algorithms.parseColor(color); + } catch (IllegalArgumentException e) { + return 0; + } + } + private void saveCurrentSelections() { JSONArray ar = new JSONArray(); for (SelectedGpxFile s : selectedGPXFiles) { diff --git a/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java b/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java index 66029119d5..5096978208 100644 --- a/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/track/CustomColorBottomSheet.java @@ -26,6 +26,7 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -103,7 +104,13 @@ public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implem @Override public void afterTextChanged(Editable s) { if (hexEditText.isFocused()) { - int color = parseColorString(s.toString()); + int color = colorPicker.getColor(); + try { + color = Algorithms.parseColor("#" + s.toString()); + } catch (IllegalArgumentException e) { + hexEditText.setError(getString(R.string.wrong_input)); + log.error(e); + } if (color != colorPicker.getColor()) { fromEditText = true; colorPicker.setColor(color, true); @@ -166,60 +173,6 @@ public class CustomColorBottomSheet extends MenuBottomSheetDialogFragment implem } } - private static int parseColorString(String colorString) throws NumberFormatException { - int a, r, g, b = 0; - if (colorString.startsWith("#")) { - colorString = colorString.substring(1); - } - if (colorString.length() == 0) { - r = 0; - a = 255; - g = 0; - } else if (colorString.length() <= 2) { - a = 255; - r = 0; - b = Integer.parseInt(colorString, 16); - g = 0; - } else if (colorString.length() == 3) { - a = 255; - r = Integer.parseInt(colorString.substring(0, 1), 16); - g = Integer.parseInt(colorString.substring(1, 2), 16); - b = Integer.parseInt(colorString.substring(2, 3), 16); - } else if (colorString.length() == 4) { - a = 255; - r = Integer.parseInt(colorString.substring(0, 2), 16); - g = r; - r = 0; - b = Integer.parseInt(colorString.substring(2, 4), 16); - } else if (colorString.length() == 5) { - a = 255; - r = Integer.parseInt(colorString.substring(0, 1), 16); - g = Integer.parseInt(colorString.substring(1, 3), 16); - b = Integer.parseInt(colorString.substring(3, 5), 16); - } else if (colorString.length() == 6) { - a = 255; - r = Integer.parseInt(colorString.substring(0, 2), 16); - g = Integer.parseInt(colorString.substring(2, 4), 16); - b = Integer.parseInt(colorString.substring(4, 6), 16); - } else if (colorString.length() == 7) { - a = Integer.parseInt(colorString.substring(0, 1), 16); - r = Integer.parseInt(colorString.substring(1, 3), 16); - g = Integer.parseInt(colorString.substring(3, 5), 16); - b = Integer.parseInt(colorString.substring(5, 7), 16); - } else if (colorString.length() == 8) { - a = Integer.parseInt(colorString.substring(0, 2), 16); - r = Integer.parseInt(colorString.substring(2, 4), 16); - g = Integer.parseInt(colorString.substring(4, 6), 16); - b = Integer.parseInt(colorString.substring(6, 8), 16); - } else { - b = -1; - g = -1; - r = -1; - a = -1; - } - return Color.argb(a, r, g, b); - } - public interface ColorPickerListener { void onColorSelected(@ColorInt int prevColor, @ColorInt int newColor); diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 4eb6e3d30d..108c646776 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -379,7 +379,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM for (int k = 0; k < items.size(); k++) { GpxDisplayItem i = items.get(k); WptPt point = i.locationEnd; - if (point != null) { + if (point != null && point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top + && point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) { float x = tileBox.getPixXFromLatLon(point.lat, point.lon); float y = tileBox.getPixYFromLatLon(point.lat, point.lon); if (px != -1 || py != -1) { @@ -389,29 +390,26 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } px = x; py = y; - if (point.lat >= latLonBounds.bottom && point.lat <= latLonBounds.top - && point.lon >= latLonBounds.left && point.lon <= latLonBounds.right) { - String name = i.splitName; - if (name != null) { - int ind = name.indexOf(' '); - if (ind > 0) { - name = name.substring(0, ind); - } - Rect bounds = new Rect(); - paintTextIcon.getTextBounds(name, 0, name.length(), bounds); - - float nameHalfWidth = bounds.width() / 2f; - float nameHalfHeight = bounds.height() / 2f; - float density = (float) Math.ceil(tileBox.getDensity()); - RectF rect = new RectF(x - nameHalfWidth - 2 * density, - y + nameHalfHeight + 3 * density, - x + nameHalfWidth + 3 * density, - y - nameHalfHeight - 2 * density); - - canvas.drawRoundRect(rect, 0, 0, paintInnerRect); - canvas.drawRoundRect(rect, 0, 0, paintOuterRect); - canvas.drawText(name, x, y + nameHalfHeight, paintTextIcon); + String name = i.splitName; + if (name != null) { + int ind = name.indexOf(' '); + if (ind > 0) { + name = name.substring(0, ind); } + Rect bounds = new Rect(); + paintTextIcon.getTextBounds(name, 0, name.length(), bounds); + + float nameHalfWidth = bounds.width() / 2f; + float nameHalfHeight = bounds.height() / 2f; + float density = (float) Math.ceil(tileBox.getDensity()); + RectF rect = new RectF(x - nameHalfWidth - 2 * density, + y + nameHalfHeight + 3 * density, + x + nameHalfWidth + 3 * density, + y - nameHalfHeight - 2 * density); + + canvas.drawRoundRect(rect, 0, 0, paintInnerRect); + canvas.drawRoundRect(rect, 0, 0, paintOuterRect); + canvas.drawText(name, x, y + nameHalfHeight, paintTextIcon); } } } From d7aabd206cc441382933513670d85ef4513546ce Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 3 Aug 2020 16:02:13 +0300 Subject: [PATCH 20/20] Fix plan a route open track --- .../MeasurementToolFragment.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index ffd26ec83d..bc28b3995e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -236,14 +236,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { mainIcon = (ImageView) mainView.findViewById(R.id.main_icon); final NewGpxData newGpxData = editingCtx.getNewGpxData(); if (newGpxData != null) { - List points = newGpxData.getGpxFile().getRoutePoints(); - if (!points.isEmpty()) { - ApplicationMode snapToRoadAppMode = ApplicationMode - .valueOfStringKey(points.get(points.size() - 1).getProfileType(), null); - if (snapToRoadAppMode != null) { - enableSnapToRoadMode(snapToRoadAppMode); - } - } ActionType actionType = newGpxData.getActionType(); if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) { mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark)); @@ -502,6 +494,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { showSnapToRoadControls(); if (newGpxData != null && !gpxPointsAdded) { + List points = newGpxData.getGpxFile().getRoutePoints(); + if (!points.isEmpty()) { + ApplicationMode snapToRoadAppMode = ApplicationMode + .valueOfStringKey(points.get(points.size() - 1).getProfileType(), null); + if (snapToRoadAppMode != null) { + enableSnapToRoadMode(snapToRoadAppMode); + } + } ActionType actionType = newGpxData.getActionType(); if (actionType == ActionType.ADD_ROUTE_POINTS) { displayRoutePoints(); @@ -820,7 +820,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment { public void addNewGpxData(GPXFile gpxFile) { QuadRect rect = gpxFile.getRect(); TrkSegment segment = getTrkSegment(gpxFile); - NewGpxData newGpxData = new NewGpxData(gpxFile, rect, ActionType.EDIT_SEGMENT, segment); + NewGpxData newGpxData = new NewGpxData(gpxFile, rect, segment == null + ? ActionType.ADD_ROUTE_POINTS + : ActionType.EDIT_SEGMENT, + segment); editingCtx.setNewGpxData(newGpxData); initMeasurementMode(newGpxData); QuadRect qr = newGpxData.getRect();