From cdd6230272e1e06bfa0047a45c4a35f8fb35839a Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 12 Mar 2019 13:14:54 +0200 Subject: [PATCH 1/2] Remove check for location permission for opening route preparation dialog --- OsmAnd/res/values/strings.xml | 3 +++ .../MapRouteInfoMenu.java | 24 ++++++++++++------- .../osmand/plus/views/MapControlsLayer.java | 10 +------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8affa58f36..f38eba8d81 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,9 @@ Thx - Hardy --> + Add start and end points + Add start point + Select start point Unpaved Sand Grass diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index ce5eb6f8e4..dc90ca9256 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -42,6 +42,7 @@ import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; @@ -1412,21 +1413,22 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper(); TargetPoint startPoint = targetPointsHelper.getPointToStart(); TargetPoint endPoint = targetPointsHelper.getPointToNavigate(); - if (endPoint == null) { + Location loc = app.getLocationProvider().getLastKnownLocation(); + if (loc == null && startPoint == null && endPoint == null) { + app.showShortToastMessage(R.string.add_start_and_end_points); + } else if (endPoint == null) { app.showShortToastMessage(R.string.mark_final_location_first); } else { - if (startPoint == null) { - Location loc = app.getLocationProvider().getLastKnownLocation(); - if (loc != null) { - startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), - new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, - mapActivity.getString(R.string.shared_string_my_location))); - } + if (startPoint == null && loc != null) { + startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), + new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location))); } if (startPoint != null) { targetPointsHelper.navigateToPoint(startPoint.point, false, -1, startPoint.getPointDescription(mapActivity)); targetPointsHelper.setStartPoint(endPoint.point, false, endPoint.getPointDescription(mapActivity)); targetPointsHelper.updateRouteAndRefresh(true); + } else { + app.showShortToastMessage(R.string.route_add_start_point); } } } @@ -1751,7 +1753,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (start != null) { fromText.setText(name); } else { - fromText.setText(R.string.shared_string_my_location); + if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { + fromText.setText(R.string.shared_string_my_location); + } else { + fromText.setText(R.string.route_descr_select_start_point); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 174e72be42..04cc4b80e3 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -390,15 +390,7 @@ public class MapControlsLayer extends OsmandMapLayer { public void doRoute(boolean hasTargets) { this.hasTargets = hasTargets; - if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) { - onNavigationClick(); - } else if (!ActivityCompat.shouldShowRequestPermissionRationale(mapActivity, Manifest.permission.ACCESS_FINE_LOCATION)) { - app.showToastMessage(R.string.ask_for_location_permission); - } else { - ActivityCompat.requestPermissions(mapActivity, - new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, - REQUEST_LOCATION_FOR_NAVIGATION_PERMISSION); - } + onNavigationClick(); } public void doNavigate() { From 9ad5efc9c758828a6e416a739e1c0525f1588fc9 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 12 Mar 2019 18:52:51 +0200 Subject: [PATCH 2/2] Fix control buttons --- OsmAnd/res/layout/plan_route_info.xml | 2 +- .../route_info_menu_control_buttons.xml | 19 +++++++-------- .../ShowRouteInfoDialogFragment.java | 3 ++- .../MapRouteInfoMenu.java | 12 +++++++--- .../MapRouteInfoMenuFragment.java | 24 +++++++++---------- .../WaypointsFragment.java | 5 ---- .../plus/widgets/TextViewExProgress.java | 19 +++++++++++++++ 7 files changed, 52 insertions(+), 32 deletions(-) diff --git a/OsmAnd/res/layout/plan_route_info.xml b/OsmAnd/res/layout/plan_route_info.xml index c2b927037e..9757e28b1a 100644 --- a/OsmAnd/res/layout/plan_route_info.xml +++ b/OsmAnd/res/layout/plan_route_info.xml @@ -587,7 +587,7 @@ diff --git a/OsmAnd/res/layout/route_info_menu_control_buttons.xml b/OsmAnd/res/layout/route_info_menu_control_buttons.xml index 3261c200a6..fbdce267b2 100644 --- a/OsmAnd/res/layout/route_info_menu_control_buttons.xml +++ b/OsmAnd/res/layout/route_info_menu_control_buttons.xml @@ -30,6 +30,11 @@ + + - - diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index 9b3e26351f..fe9e6efee8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -664,7 +664,8 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment { spannable.append(OsmAndFormatter.getFormattedDistance((float) segment.getTravelDist(), app)); spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - SpannableString textType = new SpannableString(getString(R.string.by_transport_type, transportStopRoute.type.name().toLowerCase())); + String type = getString(transportStopRoute.getTypeStrRes()).toLowerCase(); + SpannableString textType = new SpannableString(getString(R.string.by_transport_type, type)); buildCollapsableRow(stopsContainer, spannable, textType, true, collapsableView, null); final TransportStop endStop = stops.get(stops.size() - 1); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index dc90ca9256..03f009c3c3 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -777,18 +777,24 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener View startButton = mainView.findViewById(R.id.start_button); TextView startButtonText = (TextView) mainView.findViewById(R.id.start_button_descr); + boolean publicTransportMode = routingHelper.getAppMode() == ApplicationMode.PUBLIC_TRANSPORT; + int iconId = publicTransportMode ? R.drawable.ic_map : R.drawable.ic_action_start_navigation; if (isRouteCalculated()) { AndroidUtils.setBackground(app, startButton, nightMode, R.color.active_buttons_and_links_light, R.color.active_buttons_and_links_dark); int color = nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light; startButtonText.setTextColor(ContextCompat.getColor(app, color)); - ((ImageView) mainView.findViewById(R.id.start_icon)).setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, color)); + Drawable icon = app.getUIUtilities().getIcon(iconId, color); + startButtonText.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); } else { AndroidUtils.setBackground(app, startButton, nightMode, R.color.activity_background_light, R.color.route_info_cancel_button_color_dark); int color = R.color.description_font_and_bottom_sheet_icons; startButtonText.setTextColor(ContextCompat.getColor(app, color)); - ((ImageView) mainView.findViewById(R.id.start_icon)).setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, color)); + Drawable icon = app.getUIUtilities().getIcon(iconId, color); + startButtonText.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); } - if (routingHelper.isFollowingMode() || routingHelper.isPauseNavigation()) { + if (publicTransportMode) { + startButtonText.setText(R.string.shared_string_show_on_map); + } else if (routingHelper.isFollowingMode() || routingHelper.isPauseNavigation()) { startButtonText.setText(R.string.shared_string_continue); } else { startButtonText.setText(R.string.shared_string_control_start); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java index c1a8383666..366d3613b5 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java @@ -23,7 +23,6 @@ import android.view.ViewParent; import android.view.ViewTreeObserver; import android.view.animation.DecelerateInterpolator; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.OverScroller; import android.widget.ProgressBar; @@ -33,6 +32,7 @@ import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.data.RotatedTileBox; import net.osmand.osm.edit.Node; +import net.osmand.plus.ApplicationMode; import net.osmand.plus.LockableScrollView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -335,6 +335,7 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { } MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { + updateInfo(); mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden(); wasDrawerDisabled = mapActivity.isDrawerDisabled(); if (!wasDrawerDisabled) { @@ -841,11 +842,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { textViewExProgress.color1 = ContextCompat.getColor(mapActivity, color); textViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); textViewExProgress.invalidate(); - ImageViewExProgress imageViewExProgress = (ImageViewExProgress) view.findViewById(R.id.start_icon); - imageViewExProgress.percent = progress / 100f; - imageViewExProgress.color1 = ContextCompat.getColor(mapActivity, color); - imageViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); - imageViewExProgress.invalidate(); } public void hideRouteCalculationProgressBar() { @@ -874,14 +870,16 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { textViewExProgress.color1 = ContextCompat.getColor(mapActivity, nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light); textViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); - ImageViewExProgress imageViewExProgress = (ImageViewExProgress) view.findViewById(R.id.start_icon); - imageViewExProgress.color1 = ContextCompat.getColor(mapActivity, nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light); - imageViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); - ((ImageView) view.findViewById(R.id.start_icon)).setImageResource(R.drawable.ic_action_start_navigation); + boolean publicTransportMode = app.getRoutingHelper().getAppMode() == ApplicationMode.PUBLIC_TRANSPORT; if (menu.isRouteCalculated()) { - AndroidUtils.setBackground(app, view.findViewById(R.id.start_button), nightMode, R.color.active_buttons_and_links_light, R.color.active_buttons_and_links_dark); + if (publicTransportMode) { + AndroidUtils.setBackground(app, view.findViewById(R.id.start_button), nightMode, R.color.card_and_list_background_light, R.color.card_and_list_background_dark); + textViewExProgress.color1 = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_buttons_and_links_dark : R.color.route_info_cancel_button_color_light); + } else { + AndroidUtils.setBackground(app, view.findViewById(R.id.start_button), nightMode, R.color.active_buttons_and_links_light, R.color.active_buttons_and_links_dark); + textViewExProgress.color1 = ContextCompat.getColor(mapActivity, nightMode ? R.color.main_font_dark : R.color.card_and_list_background_light); + } textViewExProgress.percent = 1; - imageViewExProgress.percent = 1; } } } @@ -936,6 +934,8 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { R.color.divider_light, R.color.divider_dark); AndroidUtils.setBackground(ctx, mainView.findViewById(R.id.dividerButtons), nightMode, R.color.divider_light, R.color.divider_dark); + AndroidUtils.setBackground(ctx, view.findViewById(R.id.controls_divider), nightMode, + R.color.divider_light, R.color.divider_dark); AndroidUtils.setBackground(ctx, view.findViewById(R.id.app_modes_options_container), nightMode, R.drawable.route_info_trans_gradient_light, R.drawable.route_info_trans_gradient_dark); AndroidUtils.setBackground(ctx, view.findViewById(R.id.app_modes_fold_container), nightMode, diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java index 75aafea57c..bd15106e18 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/WaypointsFragment.java @@ -543,11 +543,6 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS textViewExProgress.color1 = ContextCompat.getColor(mapActivity, color); textViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); textViewExProgress.invalidate(); - ImageViewExProgress imageViewExProgress = (ImageViewExProgress) view.findViewById(R.id.start_icon); - imageViewExProgress.percent = progress / 100f; - imageViewExProgress.color1 = ContextCompat.getColor(mapActivity, color); - imageViewExProgress.color2 = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); - imageViewExProgress.invalidate(); } public void setupRouteCalculationButtonProgressBar(@NonNull ProgressBar pb) { diff --git a/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java b/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java index 46ea3511fe..d3dcd1089e 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java +++ b/OsmAnd/src/net/osmand/plus/widgets/TextViewExProgress.java @@ -2,7 +2,9 @@ package net.osmand.plus.widgets; import android.content.Context; import android.graphics.Canvas; +import android.graphics.PorterDuff; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; public class TextViewExProgress extends TextViewEx { @@ -30,6 +32,15 @@ public class TextViewExProgress extends TextViewEx { public void draw(Canvas canvas) { canvas.save(); setTextColor(color1); + Drawable[] icons = getCompoundDrawables(); + for (int i = 0; i < icons.length; i++) { + Drawable drawable = icons[i]; + if (drawable != null) { + drawable.setColorFilter(color1, PorterDuff.Mode.SRC_ATOP); + icons[i] = drawable; + } + } + setCompoundDrawables(icons[0], icons[1], icons[2], icons[3]); int width = getWidth(); int widthP = (int) (width * percent); int height = getHeight(); @@ -39,6 +50,14 @@ public class TextViewExProgress extends TextViewEx { canvas.save(); setTextColor(color2); + for (int i = 0; i < icons.length; i++) { + Drawable drawable = icons[i]; + if (drawable != null) { + drawable.setColorFilter(color2, PorterDuff.Mode.SRC_ATOP); + icons[i] = drawable; + } + } + setCompoundDrawables(icons[0], icons[1], icons[2], icons[3]); int width2 = getWidth(); int widthP2 = (int) (width2 * percent); int height2 = getHeight();