Merge pull request #6973 from osmandapp/rp-mylocation

Rp mylocation
This commit is contained in:
Alexey 2019-05-23 17:37:17 +03:00 committed by GitHub
commit b94b7bc116
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 29 deletions

View file

@ -1,11 +1,14 @@
package net.osmand.plus.routepreparationmenu;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
@ -27,6 +30,7 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
@ -213,14 +217,17 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private void createMyLocItem() {
BaseBottomSheetItem myLocationItem = new SimpleBottomSheetItem.Builder()
.setIcon(getIcon(R.drawable.ic_action_location_color, 0))
.setIcon(getIcon(OsmAndLocationProvider.isLocationPermissionAvailable(getActivity())
? R.drawable.ic_action_location_color : R.drawable.ic_action_location_color_lost, 0))
.setTitle(getString(R.string.shared_string_my_location))
.setLayoutId(R.layout.bottom_sheet_item_simple_56dp)
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
Activity activity = getActivity();
if (app != null) {
if (OsmAndLocationProvider.isLocationPermissionAvailable(app)) {
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
Location myLocation = app.getLocationProvider().getLastKnownLocation();
if (myLocation != null) {
@ -250,6 +257,11 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
break;
}
}
} else if (activity != null) {
ActivityCompat.requestPermissions(activity,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
OsmAndLocationProvider.REQUEST_LOCATION_PERMISSION);
}
}
dismiss();
}

View file

@ -1640,9 +1640,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
public void updateFromIcon(View parentView) {
MapActivity mapActivity = getMapActivity();
int locationIconResByStatus = OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)
? R.drawable.ic_action_location_color : R.drawable.ic_action_location_color_lost;
if (mapActivity != null) {
((ImageView) parentView.findViewById(R.id.fromIcon)).setImageDrawable(ContextCompat.getDrawable(mapActivity,
mapActivity.getMyApplication().getTargetPointsHelper().getPointToStart() == null ? R.drawable.ic_action_location_color : R.drawable.list_startpoint));
mapActivity.getMyApplication().getTargetPointsHelper().getPointToStart() == null
? locationIconResByStatus : R.drawable.list_startpoint));
}
}