Center to user position
This commit is contained in:
parent
0e8f9e2dfa
commit
7b26938efb
@ -31,6 +31,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import it.danieleverducci.nextcloudmaps.R;
|
import it.danieleverducci.nextcloudmaps.R;
|
||||||
|
import it.danieleverducci.nextcloudmaps.activity.detail.GeofavoriteDetailActivity;
|
||||||
import it.danieleverducci.nextcloudmaps.activity.main.MainActivity;
|
import it.danieleverducci.nextcloudmaps.activity.main.MainActivity;
|
||||||
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
import it.danieleverducci.nextcloudmaps.model.Geofavorite;
|
||||||
import it.danieleverducci.nextcloudmaps.utils.MapUtils;
|
import it.danieleverducci.nextcloudmaps.utils.MapUtils;
|
||||||
@ -40,6 +41,7 @@ import it.danieleverducci.nextcloudmaps.views.GeofavMarkerInfoWindow;
|
|||||||
public class GeofavoriteMapFragment extends GeofavoritesFragment implements MainActivity.OnGpsPermissionGrantedListener {
|
public class GeofavoriteMapFragment extends GeofavoritesFragment implements MainActivity.OnGpsPermissionGrantedListener {
|
||||||
|
|
||||||
private MapView map;
|
private MapView map;
|
||||||
|
private MyLocationNewOverlay mLocationOverlay;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -53,6 +55,9 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
|
|||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
View v = inflater.inflate(R.layout.fragment_geofavorite_map, container, false);
|
View v = inflater.inflate(R.layout.fragment_geofavorite_map, container, false);
|
||||||
|
|
||||||
|
// Register listeners
|
||||||
|
v.findViewById(R.id.center_position).setOnClickListener((cpv) -> moveToUserPosition());
|
||||||
|
|
||||||
// Setup map
|
// Setup map
|
||||||
map = v.findViewById(R.id.map);
|
map = v.findViewById(R.id.map);
|
||||||
map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
|
map.getZoomController().setVisibility(CustomZoomButtonsController.Visibility.NEVER);
|
||||||
@ -147,19 +152,30 @@ public class GeofavoriteMapFragment extends GeofavoritesFragment implements Main
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyLocationNewOverlay mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(requireContext()), map);
|
// Display user position on screen
|
||||||
|
mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(requireContext()), map);
|
||||||
|
// On first gps fix, show "center to my position" icon
|
||||||
|
mLocationOverlay.runOnFirstFix(() -> {
|
||||||
|
if(getActivity() != null) {
|
||||||
|
getActivity().runOnUiThread(() -> {
|
||||||
|
getView().findViewById(R.id.center_position).setVisibility(View.VISIBLE);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
mLocationOverlay.enableMyLocation();
|
mLocationOverlay.enableMyLocation();
|
||||||
mLocationOverlay.runOnFirstFix(() -> requireActivity().runOnUiThread(() -> map.getController().animateTo(mLocationOverlay.getMyLocation())));
|
|
||||||
|
|
||||||
map.getOverlays().add(mLocationOverlay);
|
map.getOverlays().add(mLocationOverlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveToUserPosition() {
|
||||||
|
if (mLocationOverlay != null)
|
||||||
|
map.getController().animateTo(mLocationOverlay.getMyLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMarker(Geofavorite geofavorite){
|
private void addMarker(Geofavorite geofavorite){
|
||||||
GeoPoint pos = new GeoPoint(geofavorite.getLat(), geofavorite.getLng());
|
GeoPoint pos = new GeoPoint(geofavorite.getLat(), geofavorite.getLng());
|
||||||
|
|
||||||
// Set icon and color
|
// Set icon and color
|
||||||
Drawable icon = DrawableCompat.wrap(AppCompatResources.getDrawable(requireContext(), R.drawable.ic_list_pin));
|
Drawable icon = DrawableCompat.wrap(AppCompatResources.getDrawable(requireContext(), R.drawable.ic_map_pin));
|
||||||
DrawableCompat.setTint(icon, geofavorite.categoryColor() == 0 ? requireContext().getColor(R.color.defaultBrand) : geofavorite.categoryColor());
|
DrawableCompat.setTint(icon, geofavorite.categoryColor() == 0 ? requireContext().getColor(R.color.defaultBrand) : geofavorite.categoryColor());
|
||||||
|
|
||||||
// Set infowindow (popup opened on marker click) and its listeners
|
// Set infowindow (popup opened on marker click) and its listeners
|
||||||
|
@ -53,4 +53,18 @@
|
|||||||
|
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/center_position"
|
||||||
|
android:layout_width="@dimen/floating_bar_height"
|
||||||
|
android:layout_height="@dimen/floating_bar_height"
|
||||||
|
android:layout_marginRight="100dp"
|
||||||
|
android:layout_marginBottom="25dp"
|
||||||
|
android:layout_gravity="bottom|right"
|
||||||
|
android:background="@drawable/unselected_floating_semitransparent_button_background"
|
||||||
|
android:contentDescription="@string/list_mode"
|
||||||
|
android:padding="5dp"
|
||||||
|
android:tint="@color/text_color"
|
||||||
|
android:src="@drawable/ic_add_gps"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
Reference in New Issue
Block a user