Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/ActivityMap.java
Show All 26 Lines | |||||
import android.location.LocationManager; | import android.location.LocationManager; | ||||
import android.os.Build; | import android.os.Build; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.util.Log; | import android.util.Log; | ||||
import android.view.View; | import android.view.View; | ||||
import android.widget.ImageButton; | import android.widget.ImageButton; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.annotation.RequiresApi; | import androidx.annotation.RequiresApi; | ||||
import androidx.core.app.ActivityCompat; | import androidx.core.app.ActivityCompat; | ||||
import androidx.preference.PreferenceManager; | import androidx.preference.PreferenceManager; | ||||
import it.reyboz.bustorino.middleware.GeneralActivity; | import it.reyboz.bustorino.middleware.GeneralActivity; | ||||
import it.reyboz.bustorino.data.NextGenDB; | import it.reyboz.bustorino.data.NextGenDB; | ||||
import org.osmdroid.api.IMapController; | import org.osmdroid.api.IMapController; | ||||
Show All 39 Lines | public class ActivityMap extends GeneralActivity { | ||||
private MapView map = null; | private MapView map = null; | ||||
public Context ctx; | public Context ctx; | ||||
private MyLocationNewOverlay mLocationOverlay = null; | private MyLocationNewOverlay mLocationOverlay = null; | ||||
private FolderOverlay stopsFolderOverlay = null; | private FolderOverlay stopsFolderOverlay = null; | ||||
protected ImageButton btCenterMap; | protected ImageButton btCenterMap; | ||||
protected ImageButton btFollowMe; | protected ImageButton btFollowMe; | ||||
private final CustomInfoWindow.TouchResponder touchResponder = new CustomInfoWindow.TouchResponder() { | |||||
@Override | |||||
public void onActionUp(@NonNull String stopID, @Nullable String stopName) { | |||||
Intent intent = new Intent(ctx, ActivityMain.class); | |||||
Bundle b = new Bundle(); | |||||
b.putString("bus-stop-ID", stopID); | |||||
b.putString("bus-stop-display-name", stopName); | |||||
intent.putExtras(b); | |||||
intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); | |||||
// start ActivityMain with the previous intent | |||||
ctx.startActivity(intent); | |||||
} | |||||
}; | |||||
//@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) | //@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB) | ||||
@Override | @Override | ||||
public void onCreate(Bundle savedInstanceState) { | public void onCreate(Bundle savedInstanceState) { | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
//handle permissions first, before map is created. not depicted here | //handle permissions first, before map is created. not depicted here | ||||
//load/initialize the osmdroid configuration | //load/initialize the osmdroid configuration | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | public class ActivityMap extends GeneralActivity { | ||||
} | } | ||||
public Marker makeMarker(GeoPoint geoPoint, String stopName, String ID, boolean isStartMarker) { | public Marker makeMarker(GeoPoint geoPoint, String stopName, String ID, boolean isStartMarker) { | ||||
// add a marker | // add a marker | ||||
Marker marker = new Marker(map); | Marker marker = new Marker(map); | ||||
// set custom info window as info window | // set custom info window as info window | ||||
CustomInfoWindow popup = new CustomInfoWindow(map, ID, stopName); | CustomInfoWindow popup = new CustomInfoWindow(map, ID, stopName, touchResponder); | ||||
marker.setInfoWindow(popup); | marker.setInfoWindow(popup); | ||||
// make the marker clickable | // make the marker clickable | ||||
marker.setOnMarkerClickListener((thisMarker, mapView) -> { | marker.setOnMarkerClickListener((thisMarker, mapView) -> { | ||||
if (thisMarker.isInfoWindowOpen()) { | if (thisMarker.isInfoWindowOpen()) { | ||||
// on second click | // on second click | ||||
// create an intent with these extras | // create an intent with these extras | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | public void loadMarkers() { | ||||
GeoPoint marker = new GeoPoint(stop.getLatitude(), stop.getLongitude()); | GeoPoint marker = new GeoPoint(stop.getLatitude(), stop.getLongitude()); | ||||
Marker stopMarker = makeMarker(marker, stop.getStopDefaultName(), stop.ID, false); | Marker stopMarker = makeMarker(marker, stop.getStopDefaultName(), stop.ID, false); | ||||
stopsFolderOverlay.add(stopMarker); | stopsFolderOverlay.add(stopMarker); | ||||
} | } | ||||
} | } | ||||
@Override | |||||
protected void onPostResume() { | |||||
super.onPostResume(); | |||||
ctx = this; | |||||
} | |||||
protected boolean detachMapFromPosition(){ | protected boolean detachMapFromPosition(){ | ||||
if (mLocationOverlay.isFollowLocationEnabled()) { | if (mLocationOverlay.isFollowLocationEnabled()) { | ||||
mLocationOverlay.disableFollowLocation(); | mLocationOverlay.disableFollowLocation(); | ||||
btFollowMe.setImageResource(R.drawable.ic_follow_me); | btFollowMe.setImageResource(R.drawable.ic_follow_me); | ||||
return true; | return true; | ||||
} return false; | } return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||||
setOption(LOCATION_PERMISSION_GIVEN, false); | setOption(LOCATION_PERMISSION_GIVEN, false); | ||||
} | } | ||||
break; | break; | ||||
//add other cases for permissions | //add other cases for permissions | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
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