Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/MapFragment.java
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
import it.reyboz.bustorino.backend.Stop; | import it.reyboz.bustorino.backend.Stop; | ||||
import it.reyboz.bustorino.data.NextGenDB; | import it.reyboz.bustorino.data.NextGenDB; | ||||
import it.reyboz.bustorino.map.CustomInfoWindow; | import it.reyboz.bustorino.map.CustomInfoWindow; | ||||
import it.reyboz.bustorino.map.LocationOverlay; | import it.reyboz.bustorino.map.LocationOverlay; | ||||
import it.reyboz.bustorino.middleware.GeneralActivity; | import it.reyboz.bustorino.middleware.GeneralActivity; | ||||
import it.reyboz.bustorino.util.Permissions; | import it.reyboz.bustorino.util.Permissions; | ||||
public class MapFragment extends BaseFragment { | public class MapFragment extends ScreenBaseFragment { | ||||
private static final String TAG = "Busto-MapActivity"; | private static final String TAG = "Busto-MapActivity"; | ||||
private static final String MAP_CURRENT_ZOOM_KEY = "map-current-zoom"; | private static final String MAP_CURRENT_ZOOM_KEY = "map-current-zoom"; | ||||
private static final String MAP_CENTER_LAT_KEY = "map-center-lat"; | private static final String MAP_CENTER_LAT_KEY = "map-center-lat"; | ||||
private static final String MAP_CENTER_LON_KEY = "map-center-lon"; | private static final String MAP_CENTER_LON_KEY = "map-center-lon"; | ||||
private static final String FOLLOWING_LOCAT_KEY ="following"; | private static final String FOLLOWING_LOCAT_KEY ="following"; | ||||
public static final String BUNDLE_LATIT = "lat"; | public static final String BUNDLE_LATIT = "lat"; | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | protected final LocationOverlay.OverlayCallbacks locationCallbacks = new LocationOverlay.OverlayCallbacks() { | ||||
@Override | @Override | ||||
public void onEnableFollowMyLocation() { | public void onEnableFollowMyLocation() { | ||||
updateGUIForLocationFollowing(true); | updateGUIForLocationFollowing(true); | ||||
followingLocation=true; | followingLocation=true; | ||||
} | } | ||||
}; | }; | ||||
private final ActivityResultLauncher<String[]> positionRequestLauncher = | private final ActivityResultLauncher<String[]> positionRequestLauncher = | ||||
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { | registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), result -> { | ||||
@Override | |||||
@SuppressLint("MissingPermission") | |||||
public void onActivityResult(Map<String, Boolean> result) { | |||||
if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) && result.get(Manifest.permission.ACCESS_FINE_LOCATION)){ | if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) && result.get(Manifest.permission.ACCESS_FINE_LOCATION)){ | ||||
map.getOverlays().remove(mLocationOverlay); | map.getOverlays().remove(mLocationOverlay); | ||||
startLocationOverlay(true, map); | startLocationOverlay(true, map); | ||||
if(getContext()==null || getContext().getSystemService(Context.LOCATION_SERVICE)==null) | if(getContext()==null || getContext().getSystemService(Context.LOCATION_SERVICE)==null) | ||||
return; | return; | ||||
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE); | LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE); | ||||
@SuppressLint("MissingPermission") | |||||
Location userLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); | Location userLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); | ||||
if (userLocation != null) { | if (userLocation != null) { | ||||
map.getController().setZoom(POSITION_FOUND_ZOOM); | map.getController().setZoom(POSITION_FOUND_ZOOM); | ||||
GeoPoint startPoint = new GeoPoint(userLocation); | GeoPoint startPoint = new GeoPoint(userLocation); | ||||
setLocationFollowing(true); | setLocationFollowing(true); | ||||
map.getController().setCenter(startPoint); | map.getController().setCenter(startPoint); | ||||
} | } | ||||
} | } | ||||
else Log.w(DEBUG_TAG,"No location permission"); | else Log.w(DEBUG_TAG,"No location permission"); | ||||
} | |||||
}); | }); | ||||
public MapFragment() { | public MapFragment() { | ||||
} | } | ||||
public static MapFragment getInstance(){ | public static MapFragment getInstance(){ | ||||
return new MapFragment(); | return new MapFragment(); | ||||
} | } | ||||
public static MapFragment getInstance(double stopLatit, double stopLong, String stopName, String stopID){ | public static MapFragment getInstance(double stopLatit, double stopLong, String stopName, String stopID){ | ||||
▲ Show 20 Lines • Show All 415 Lines • ▼ Show 20 Lines | public Marker makeMarker(GeoPoint geoPoint, String stopName, String ID, boolean isStartMarker) { | ||||
if (isStartMarker) { | if (isStartMarker) { | ||||
marker.showInfoWindow(); | marker.showInfoWindow(); | ||||
//map.getController().animateTo(marker.getPosition()); | //map.getController().animateTo(marker.getPosition()); | ||||
} | } | ||||
return marker; | return marker; | ||||
} | } | ||||
@Nullable | |||||
@org.jetbrains.annotations.Nullable | |||||
@Override | |||||
public View getBaseViewForSnackBar() { | |||||
return null; | |||||
} | |||||
/** | /** | ||||
* Simple asyncTask class to load the stops in the background | * Simple asyncTask class to load the stops in the background | ||||
* Holds a weak reference to the fragment to do callbacks | * Holds a weak reference to the fragment to do callbacks | ||||
*/ | */ | ||||
static class AsyncStopFetcher extends AsyncTask<AsyncStopFetcher.BoundingBoxLimit,Void, List<Stop>>{ | static class AsyncStopFetcher extends AsyncTask<AsyncStopFetcher.BoundingBoxLimit,Void, List<Stop>>{ | ||||
final WeakReference<MapFragment> fragmentWeakReference; | final WeakReference<MapFragment> fragmentWeakReference; | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register