From 28c00dd5d64cf29762bb558e01aba2cfe771f93f Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 25 May 2018 18:08:31 +0300 Subject: [PATCH 1/5] Fix #5192 --- .../activities/OsmandActionBarActivity.java | 3 +- .../plus/mapcontextmenu/MenuBuilder.java | 6 +- .../builders/AmenityMenuBuilder.java | 59 +++++++++++++------ .../quickaction/QuickActionListFragment.java | 3 +- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java index 108baf0176..8085e3969d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java @@ -19,8 +19,7 @@ public class OsmandActionBarActivity extends OsmandInAppPurchaseActivity { //should be called after set content view protected void setupHomeButton(){ - Drawable back = ((OsmandApplication)getApplication()).getUIUtilities().getIcon(R.drawable.ic_arrow_back); - back.setColorFilter(ContextCompat.getColor(this, R.color.color_white), PorterDuff.Mode.MULTIPLY); + Drawable back = ((OsmandApplication)getApplication()).getUIUtilities().getIcon(R.drawable.ic_arrow_back, R.color.color_white); final ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { supportActionBar.setHomeButtonEnabled(true); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 4a6145d76e..aaea7d8283 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -13,6 +13,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v7.view.ContextThemeWrapper; import android.text.ClipboardManager; import android.text.TextUtils; @@ -752,7 +753,10 @@ public class MenuBuilder { public Drawable getRowIcon(Context ctx, String fileName) { Drawable d = RenderingIcons.getBigIcon(ctx, fileName); if (d != null) { - d.setColorFilter(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_icon_light : R.color.ctx_menu_bottom_view_icon_dark), PorterDuff.Mode.SRC_IN); + d = DrawableCompat.wrap(d); + d.mutate(); + d.setColorFilter(app.getResources().getColor(light + ? R.color.ctx_menu_bottom_view_icon_light : R.color.ctx_menu_bottom_view_icon_dark), PorterDuff.Mode.SRC_IN); return d; } else { return null; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 16754282bf..e8702f441e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -25,6 +25,7 @@ import net.osmand.data.Amenity; import net.osmand.data.PointDescription; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -49,6 +50,7 @@ import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -344,6 +346,7 @@ public class AmenityMenuBuilder extends MenuBuilder { Map> poiAdditionalCategories = new HashMap<>(); AmenityInfoRow cuisineRow = null; + List collectedPoiTypes = new ArrayList<>(); for (Map.Entry e : amenity.getAdditionalInfo().entrySet()) { int iconId = 0; @@ -362,14 +365,15 @@ public class AmenityMenuBuilder extends MenuBuilder { boolean isWiki = false; boolean isText = false; boolean isDescription = false; - boolean needLinks = !("population".equals(key) - || "height".equals(key)); + boolean needLinks = !("population".equals(key) || "height".equals(key)); boolean isPhoneNumber = false; boolean isUrl = false; boolean isCuisine = false; int poiTypeOrder = 0; String poiTypeKeyName = ""; + PoiType poiType = amenity.getType().getPoiTypeByKeyName(key); + AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key); if (pt == null && !Algorithms.isEmpty(vl) && vl.length() < 50) { pt = poiTypes.getAnyPoiAdditionalTypeByKey(key + "_" + vl); @@ -501,6 +505,8 @@ public class AmenityMenuBuilder extends MenuBuilder { if (icon == null && isText && iconId == 0) { iconId = R.drawable.ic_action_note_dark; } + } else if (poiType != null) { + collectedPoiTypes.add(poiType); } else { textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey()); vl = amenity.unzipContent(e.getValue()); @@ -524,12 +530,10 @@ public class AmenityMenuBuilder extends MenuBuilder { } if (isDescription) { descriptions.add(row); - } else { - if (!isCuisine) { - infoRows.add(row); - } else { - cuisineRow = row; - } + } else if (isCuisine) { + cuisineRow = row; + } else if (poiType == null) { + infoRows.add(row); } } @@ -568,12 +572,27 @@ public class AmenityMenuBuilder extends MenuBuilder { sb.append(pt.getTranslation()); } boolean cuisineOrDish = categoryName.equals(Amenity.CUISINE) || categoryName.equals(Amenity.DISH); - CollapsableView collapsableView = getPoiAdditionalCollapsableView(view.getContext(), true, categoryTypes, cuisineOrDish ? cuisineRow : null); + CollapsableView collapsableView = getPoiTypeCollapsableView(view.getContext(), true, categoryTypes, true, cuisineOrDish ? cuisineRow : null); infoRows.add(new AmenityInfoRow(poiAdditionalCategoryName, icon, pType.getPoiAdditionalCategoryTranslation(), sb.toString(), true, collapsableView, 0, false, false, false, pType.getOrder(), pType.getKeyName(), false, false, false, 1)); } } + if (collectedPoiTypes.size() > 0) { + CollapsableView collapsableView = getPoiTypeCollapsableView(view.getContext(), true, collectedPoiTypes, false, null); + PoiCategory poiCategory = amenity.getType(); + Drawable icon = getRowIcon(view.getContext(), poiCategory.getIconKeyName()); + StringBuilder sb = new StringBuilder(); + for (PoiType pt : collectedPoiTypes) { + if (sb.length() > 0) { + sb.append(" • "); + } + sb.append(pt.getTranslation()); + } + infoRows.add(new AmenityInfoRow(poiCategory.getKeyName(), icon, poiCategory.getTranslation(), sb.toString(), true, collapsableView, + 0, false, false, false, 40, poiCategory.getKeyName(), false, false, false, 1)); + } + Collections.sort(infoRows, new Comparator() { @Override public int compare(AmenityInfoRow row1, AmenityInfoRow row2) { @@ -664,9 +683,9 @@ public class AmenityMenuBuilder extends MenuBuilder { return params; } - private CollapsableView getPoiAdditionalCollapsableView( - final Context context, boolean collapsed, - @NonNull final List categoryTypes, AmenityInfoRow textCuisineRow) { + private CollapsableView getPoiTypeCollapsableView(final Context context, boolean collapsed, + @NonNull final List categoryTypes, + final boolean poiAdditional, AmenityInfoRow textRow) { final List buttons = new ArrayList<>(); @@ -684,9 +703,15 @@ public class AmenityMenuBuilder extends MenuBuilder { PoiUIFilter filter = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + amenity.getType().getKeyName()); if (filter != null) { filter.clearFilter(); - filter.setTypeToAccept(amenity.getType(), true); - filter.updateTypesToAccept(pt); - filter.setFilterByName(pt.getKeyName().replace('_', ':').toLowerCase()); + if (poiAdditional) { + filter.setTypeToAccept(amenity.getType(), true); + filter.updateTypesToAccept(pt); + filter.setFilterByName(pt.getKeyName().replace('_', ':').toLowerCase()); + } else { + LinkedHashSet accept = new LinkedHashSet<>(); + accept.add(pt.getKeyName()); + filter.selectSubTypesToAccept(amenity.getType(), accept); + } getMapActivity().showQuickSearch(filter); } } @@ -699,9 +724,9 @@ public class AmenityMenuBuilder extends MenuBuilder { view.addView(button); } - if (textCuisineRow != null) { + if (textRow != null) { TextViewEx button = buildButtonInCollapsableView(context, true, false, false); - String name = textCuisineRow.textPrefix + ": " + textCuisineRow.text.toLowerCase(); + String name = textRow.textPrefix + ": " + textRow.text.toLowerCase(); button.setText(name); view.addView(button); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index 6bd53dd8ac..07b8ed7513 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -109,8 +109,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick private void setUpToolbar(View view) { Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar); - Drawable back = getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back); - back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY); + Drawable back = getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back, R.color.color_white); toolbar.setNavigationIcon(back); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { From b05547e9f973790b684c4d4d408535afba47ebef Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 25 May 2018 18:25:44 +0300 Subject: [PATCH 2/5] Fix OsmAndLocationProvider#scheduleCheckIfGpsLost --- .../osmand/plus/OsmAndLocationProvider.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 962b71393b..5e716bcfc0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -684,7 +684,8 @@ public class OsmAndLocationProvider implements SensorEventListener { private void scheduleCheckIfGpsLost(final net.osmand.Location location) { final RoutingHelper routingHelper = app.getRoutingHelper(); - if (location != null) { + if (location != null && routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0 + && simulatePosition == null) { final long fixTime = location.getTime(); app.runMessageInUIThreadAndCancelPrevious(LOST_LOCATION_MSG_ID, new Runnable() { @@ -702,25 +703,23 @@ public class OsmAndLocationProvider implements SensorEventListener { setLocation(null); } }, LOST_LOCATION_CHECK_DELAY); - if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0 && simulatePosition == null) { - app.runMessageInUIThreadAndCancelPrevious(START_SIMULATE_LOCATION_MSG_ID, new Runnable() { + app.runMessageInUIThreadAndCancelPrevious(START_SIMULATE_LOCATION_MSG_ID, new Runnable() { - @Override - public void run() { - net.osmand.Location lastKnown = getLastKnownLocation(); - if (lastKnown != null && lastKnown.getTime() > fixTime) { - // false positive case, still strange how we got here with removeMessages - return; - } - List tunnel = routingHelper.getUpcomingTunnel(1000); - if(tunnel != null) { - simulatePosition = new SimulationProvider(); - simulatePosition.startSimulation(tunnel, location); - simulatePositionImpl(); - } + @Override + public void run() { + net.osmand.Location lastKnown = getLastKnownLocation(); + if (lastKnown != null && lastKnown.getTime() > fixTime) { + // false positive case, still strange how we got here with removeMessages + return; } - }, START_LOCATION_SIMULATION_DELAY); - } + List tunnel = routingHelper.getUpcomingTunnel(1000); + if(tunnel != null) { + simulatePosition = new SimulationProvider(); + simulatePosition.startSimulation(tunnel, location); + simulatePositionImpl(); + } + } + }, START_LOCATION_SIMULATION_DELAY); } } From de25575fa578e4bb065b603d6de588b7ec435efb Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 25 May 2018 18:32:46 +0300 Subject: [PATCH 3/5] Add check for "setLocation(null)" --- OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 5e716bcfc0..9bfbeef462 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -699,8 +699,10 @@ public class OsmAndLocationProvider implements SensorEventListener { gpsSignalLost = true; if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0) { routingHelper.getVoiceRouter().gpsLocationLost(); + if (simulatePosition == null) { + setLocation(null); + } } - setLocation(null); } }, LOST_LOCATION_CHECK_DELAY); app.runMessageInUIThreadAndCancelPrevious(START_SIMULATE_LOCATION_MSG_ID, new Runnable() { From 8820d75cb932a0e49b5f6001fe68ad3b043bdcea Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 25 May 2018 18:40:28 +0300 Subject: [PATCH 4/5] Fix check for "setLocation(null)" --- OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 9bfbeef462..bbbd20378b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -697,11 +697,10 @@ public class OsmAndLocationProvider implements SensorEventListener { return; } gpsSignalLost = true; - if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0) { + if (routingHelper.isFollowingMode() && routingHelper.getLeftDistance() > 0 + && simulatePosition == null) { routingHelper.getVoiceRouter().gpsLocationLost(); - if (simulatePosition == null) { - setLocation(null); - } + setLocation(null); } } }, LOST_LOCATION_CHECK_DELAY); From 665653810b7c1fa683f40c82a8134491432253f1 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 25 May 2018 18:52:18 +0300 Subject: [PATCH 5/5] Fix #5309 --- .../net/osmand/plus/views/OsmandMapTileView.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 58fb851fd5..7b0c5479fa 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -373,7 +373,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { if (mainLayer != null) { animatedDraggingThread.stopAnimating(); currentViewport.setZoomAndAnimation(zoom, 0, 0); - currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); + if (zoom <= LOWEST_ZOOM_TO_ROTATE) { + rotate = 0; + } + currentViewport.setRotate(rotate); refreshMap(); } } @@ -383,7 +386,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { animatedDraggingThread.stopAnimating(); currentViewport.setZoomAndAnimation(zoom, 0); currentViewport.setMapDensity(mapDensity); - currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); + if (zoom <= LOWEST_ZOOM_TO_ROTATE) { + rotate = 0; + } + currentViewport.setRotate(rotate); refreshMap(); } } @@ -899,7 +905,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { protected void zoomToAnimate(int zoom, double zoomToAnimate, boolean notify) { if (mainLayer != null && getMaxZoom() >= zoom && getMinZoom() <= zoom) { currentViewport.setZoomAndAnimation(zoom, zoomToAnimate); - currentViewport.setRotate(zoom > LOWEST_ZOOM_TO_ROTATE ? rotate : 0); + if (zoom <= LOWEST_ZOOM_TO_ROTATE) { + rotate = 0; + } + currentViewport.setRotate(rotate); refreshMap(); if (notify && locationListener != null) { locationListener.locationChanged(getLatitude(), getLongitude(), this);