Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
3297dc90e4
2 changed files with 92 additions and 1 deletions
|
@ -20,12 +20,16 @@ import android.widget.TextView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;
|
||||
import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter;
|
||||
|
@ -40,7 +44,7 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll
|
|||
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
|
||||
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
|
||||
|
||||
public class PlanRouteFragment extends Fragment {
|
||||
public class PlanRouteFragment extends Fragment implements OsmAndLocationListener {
|
||||
|
||||
public static final String TAG = "PlanRouteFragment";
|
||||
|
||||
|
@ -52,6 +56,9 @@ public class PlanRouteFragment extends Fragment {
|
|||
private int previousMapPosition;
|
||||
private int selectedCount = 0;
|
||||
|
||||
private Location location;
|
||||
private boolean locationUpdateStarted;
|
||||
|
||||
private boolean nightMode;
|
||||
private boolean portrait;
|
||||
private boolean markersListOpened;
|
||||
|
@ -204,6 +211,18 @@ public class PlanRouteFragment extends Fragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
startLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
stopLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
@ -213,6 +232,18 @@ public class PlanRouteFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
boolean newLocation = this.location == null && location != null;
|
||||
boolean locationChanged = this.location != null && location != null
|
||||
&& this.location.getLatitude() != location.getLatitude()
|
||||
&& this.location.getLongitude() != location.getLongitude();
|
||||
if (newLocation || locationChanged) {
|
||||
this.location = location;
|
||||
updateLocationUi();
|
||||
}
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
|
@ -350,6 +381,27 @@ public class PlanRouteFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateLocationUi() {
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (mapActivity != null && adapter != null) {
|
||||
mapActivity.getMyApplication().runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (location == null) {
|
||||
location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
}
|
||||
MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities();
|
||||
boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null);
|
||||
|
||||
adapter.setUseCenter(useCenter);
|
||||
adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()));
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void mark(int status, int... widgets) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
|
@ -434,6 +486,23 @@ public class PlanRouteFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void startLocationUpdate() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null && !locationUpdateStarted) {
|
||||
locationUpdateStarted = true;
|
||||
mapActivity.getMyApplication().getLocationProvider().addLocationListener(this);
|
||||
updateLocationUi();
|
||||
}
|
||||
}
|
||||
|
||||
private void stopLocationUpdate() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null && locationUpdateStarted) {
|
||||
locationUpdateStarted = false;
|
||||
mapActivity.getMyApplication().getLocationProvider().removeLocationListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean quit(boolean hideMarkersListFirst) {
|
||||
if (markersListOpened && hideMarkersListFirst) {
|
||||
hideMarkersList();
|
||||
|
|
|
@ -8,10 +8,13 @@ import android.view.MotionEvent;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collections;
|
||||
|
@ -26,10 +29,21 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
|
|||
private List<MapMarker> markers;
|
||||
private MapMarkersListAdapterListener listener;
|
||||
|
||||
private LatLon location;
|
||||
private boolean useCenter;
|
||||
|
||||
public void setAdapterListener(MapMarkersListAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void setLocation(LatLon location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setUseCenter(boolean useCenter) {
|
||||
this.useCenter = useCenter;
|
||||
}
|
||||
|
||||
public MapMarkersListAdapter(MapActivity mapActivity) {
|
||||
this.mapActivity = mapActivity;
|
||||
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
|
||||
|
@ -116,6 +130,14 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
|
|||
descr = month + " " + day;
|
||||
}
|
||||
holder.description.setText(descr);
|
||||
|
||||
if (location != null) {
|
||||
holder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter
|
||||
? R.color.color_distance : R.color.color_myloc_distance));
|
||||
float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(),
|
||||
marker.getLatitude(), marker.getLongitude());
|
||||
holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue