Page MenuHomeGitPull.it

D24.1773286479.diff
No OneTemporary

Size
14 KB
Referenced Files
None
Subscribers
None

D24.1773286479.diff

diff --git a/AndroidManifest.xml b/AndroidManifest.xml
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -85,6 +85,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".ActivityMain"/>
</activity>
+ <activity
+ android:name=".ActivityMap"
+ android:label="@string/title_activity_map"
+ android:parentActivityName=".ActivityMain"
+ android:theme="@style/MapTheme">
+
+ <!-- API < 16: -->
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value=".ActivityMain"/>
+ </activity>
<provider
android:name=".middleware.AppDataProvider"
diff --git a/build.gradle b/build.gradle
--- a/build.gradle
+++ b/build.gradle
@@ -81,5 +81,7 @@
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'com.android.volley:volley:1.1.1'
+
+ implementation 'org.osmdroid:osmdroid-android:6.1.3'
}
}
diff --git a/res/drawable/bus_marker.xml b/res/drawable/bus_marker.xml
new file mode 100644
--- /dev/null
+++ b/res/drawable/bus_marker.xml
@@ -0,0 +1,12 @@
+<!-- drawable/bus_marker.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="24dp"
+ android:width="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:strokeWidth="1"
+ android:strokeColor="#FFF"
+ android:fillColor="@color/metro_red"
+ android:pathData="M12 2C7.58 2 4 2.5 4 6V16A3 3 0 0 0 5 18.22V20A1 1 0 0 0 6 21H7A1 1 0 0 0 8 20V19H14A8 8 0 0 1 13 15.5A5.55 5.55 0 0 1 15.38 11H6V6H18V10A4.07 4.07 0 0 1 18.5 10A5.34 5.34 0 0 1 20 10.22V6C20 2.5 16.42 2 12 2M7.5 14A1.5 1.5 0 1 1 6 15.5A1.5 1.5 0 0 1 7.5 14M18.5 12A3.54 3.54 0 0 0 15 15.5C15 18.1 18.5 22 18.5 22S22 18.1 22 15.5A3.54 3.54 0 0 0 18.5 12M18.5 16.8A1.2 1.2 0 1 1 18.5 14.4A1.29 1.29 0 0 1 19.7 15.6A1.15 1.15 0 0 1 18.5 16.8Z" />
+</vector>
\ No newline at end of file
diff --git a/res/drawable/map.xml b/res/drawable/map.xml
new file mode 100644
--- /dev/null
+++ b/res/drawable/map.xml
@@ -0,0 +1,8 @@
+<!-- drawable/map.xml -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:height="24dp"
+ android:width="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path android:fillColor="#FFF" android:pathData="M15,19L9,16.89V5L15,7.11M20.5,3C20.44,3 20.39,3 20.34,3L15,5.1L9,3L3.36,4.9C3.15,4.97 3,5.15 3,5.38V20.5A0.5,0.5 0 0,0 3.5,21C3.55,21 3.61,21 3.66,20.97L9,18.9L15,21L20.64,19.1C20.85,19 21,18.85 21,18.62V3.5A0.5,0.5 0 0,0 20.5,3Z" />
+</vector>
diff --git a/res/layout/activity_map.xml b/res/layout/activity_map.xml
new file mode 100644
--- /dev/null
+++ b/res/layout/activity_map.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <org.osmdroid.views.MapView android:id="@+id/map"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+</LinearLayout>
\ No newline at end of file
diff --git a/res/menu/main.xml b/res/menu/main.xml
--- a/res/menu/main.xml
+++ b/res/menu/main.xml
@@ -2,7 +2,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="it.reyboz.bustorino.ActivityMain">
-
+ <item
+ android:id="@+id/action_map"
+ android:icon="@drawable/map"
+ android:orderInCategory="1"
+ android:title="map"
+ app:showAsAction="ifRoom" />
<!--suppress AndroidDomInspection --> <!-- Android Studio can't find ic_star even though it's there. -->
<item
android:id="@+id/action_favorites"
diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml
--- a/res/values-it/strings.xml
+++ b/res/values-it/strings.xml
@@ -29,6 +29,7 @@
<string name="added_in_favorites">Fermata aggiunta ai preferiti</string>
<string name="cant_add_to_favorites">Impossibile aggiungere ai preferiti (memoria piena o database corrotto?)!</string>
<string name="title_activity_favorites">Preferiti</string>
+ <string name="title_activity_map">Mappa</string>
<string name="tip_add_favorite">Tocca il nome di una fermata per aggiungerla in questa lista</string>
<string name="action_remove_from_favourites">Rimuovi</string>
<string name="action_rename_bus_stop_username">Rinomina</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -35,6 +35,7 @@
<string name="removed_from_favorites">Bus stop removed from your favorites</string>
<string name="action_favorites">Favorites</string>
<string name="title_activity_favorites">Favorites</string>
+ <string name="title_activity_map">Map</string>
<string name="tip_add_favorite">Press on a bus stop name to populate this list</string>
<string name="action_remove_from_favourites">Delete</string>
<string name="action_rename_bus_stop_username">Rename</string>
diff --git a/res/values/theme.xml b/res/values/theme.xml
--- a/res/values/theme.xml
+++ b/res/values/theme.xml
@@ -13,6 +13,12 @@
<item name="colorAccent">@color/blue_700</item>
</style>
+ <style name="MapTheme" parent="Theme.AppCompat.Light.DarkActionBar">
+ <item name="colorPrimary">@color/orange_500</item>
+ <item name="colorPrimaryDark">@color/orange_700</item>
+ <item name="colorAccent">@color/teal_500</item>
+ </style>
+
<style name="preferenceTheme" parent="PreferenceThemeOverlay"></style>
</resources>
\ No newline at end of file
diff --git a/src/it/reyboz/bustorino/ActivityFavorites.java b/src/it/reyboz/bustorino/ActivityFavorites.java
--- a/src/it/reyboz/bustorino/ActivityFavorites.java
+++ b/src/it/reyboz/bustorino/ActivityFavorites.java
@@ -46,6 +46,8 @@
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
+import org.osmdroid.util.GeoPoint;
+
import java.util.List;
public class ActivityFavorites extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
@@ -130,13 +132,15 @@
Toast.makeText(getApplicationContext(),R.string.cannot_show_on_map_no_position,Toast.LENGTH_SHORT).show();
return true;
}
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(theGeoUrl));
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- if(intent.resolveActivity(getPackageManager())!=null)
- startActivity(intent);
- else {
- Toast.makeText(getApplicationContext(),R.string.cannot_show_on_map_no_activity,Toast.LENGTH_SHORT).show();
- }
+ Intent intent = new Intent(ActivityFavorites.this, ActivityMap.class);
+ Bundle b1 = new Bundle();
+ b1.putDouble("lat", busStop.getLatitude());
+ intent.putExtras(b1);
+ Bundle b2 = new Bundle();
+ b2.putDouble("lon", busStop.getLongitude());
+ intent.putExtras(b2);
+
+ startActivity(intent);
return true;
default:
return super.onContextItemSelected(item);
diff --git a/src/it/reyboz/bustorino/ActivityMain.java b/src/it/reyboz/bustorino/ActivityMain.java
--- a/src/it/reyboz/bustorino/ActivityMain.java
+++ b/src/it/reyboz/bustorino/ActivityMain.java
@@ -385,6 +385,9 @@
case R.id.action_favorites:
startActivity(new Intent(ActivityMain.this, ActivityFavorites.class));
return true;
+ case R.id.action_map:
+ startActivity(new Intent(ActivityMain.this, ActivityMap.class));
+ return true;
case R.id.action_about:
startActivity(new Intent(ActivityMain.this, ActivityAbout.class));
return true;
diff --git a/src/it/reyboz/bustorino/ActivityMap.java b/src/it/reyboz/bustorino/ActivityMap.java
new file mode 100644
--- /dev/null
+++ b/src/it/reyboz/bustorino/ActivityMap.java
@@ -0,0 +1,174 @@
+package it.reyboz.bustorino;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.annotation.RequiresApi;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.preference.PreferenceManager;
+
+import org.osmdroid.api.IMapController;
+import org.osmdroid.config.Configuration;
+import org.osmdroid.events.DelayedMapListener;
+import org.osmdroid.events.MapListener;
+import org.osmdroid.events.ScrollEvent;
+import org.osmdroid.events.ZoomEvent;
+import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
+import org.osmdroid.util.BoundingBox;
+import org.osmdroid.util.GeoPoint;
+import org.osmdroid.views.MapView;
+import org.osmdroid.views.overlay.Marker;
+
+import it.reyboz.bustorino.backend.Stop;
+import it.reyboz.bustorino.middleware.StopsDB;
+
+public class ActivityMap extends AppCompatActivity {
+
+ private static MapView map = null;
+ public Context ctx;
+
+ @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
+ @Override public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ //handle permissions first, before map is created. not depicted here
+
+ //load/initialize the osmdroid configuration, this can be done
+ ctx = getApplicationContext();
+ Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));
+ //setting this before the layout is inflated is a good idea
+ //it 'should' ensure that the map has a writable location for the map cache, even without permissions
+ //if no tiles are displayed, you can try overriding the cache path using Configuration.getInstance().setCachePath
+ //see also StorageUtils
+ //note, the load method also sets the HTTP User Agent to your application's package name, abusing osm's tile servers will get you banned based on this string
+
+ //inflate and create the map
+ setContentView(R.layout.activity_map);
+
+ map = (MapView) findViewById(R.id.map);
+ map.setTileSource(TileSourceFactory.MAPNIK);
+
+ // add ability to zoom with 2 fingers
+ map.setMultiTouchControls(true);
+
+ // take the parameters if it's called from other Activities
+ Bundle b = getIntent().getExtras();GeoPoint marker = null;
+ if(b != null) {
+ double lat = b.getDouble("lat");
+ double lon = b.getDouble("lon");
+ marker = new GeoPoint(lat, lon);
+ }
+ startMap(marker);
+
+ // on drag reload the markers
+ map.addMapListener(new DelayedMapListener(new MapListener() {
+
+ @Override
+ public boolean onScroll(ScrollEvent paramScrollEvent) {
+ loadMarkers();
+ return true;
+ }
+
+ @Override
+ public boolean onZoom(ZoomEvent event) {
+ loadMarkers();
+ return true;
+ }
+
+ }));
+ }
+
+ public void startMap(GeoPoint marker) {
+ // move the map on the marker position or on a default view point: Turin, Piazza Castello
+
+ IMapController mapController = map.getController();
+ GeoPoint startPoint;
+ if (marker != null) {
+ startPoint = marker;
+ mapController.setZoom(20.0);
+ } else {
+ startPoint = new GeoPoint(45.0708, 7.6858);
+ mapController.setZoom(18.0);
+ }
+ mapController.setCenter(startPoint);
+
+ loadMarkers();
+
+ }
+
+ public void makeMarker(GeoPoint geoPoint, String stopName, String ID) {
+ // add a marker
+
+ Marker marker = new Marker(map);
+
+ // make it clickable
+ Intent intent = new Intent(ActivityMap.this, ActivityMain.class);
+ Bundle b = new Bundle();
+ b.putString("bus-stop-ID", ID);
+ b.putString("bus-stop-display-name", stopName);
+ intent.putExtras(b);
+ intent.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
+ marker.setOnMarkerClickListener((marker1, mapView) -> {
+ if (marker.isInfoWindowOpen()) {
+ startActivity(intent);
+ } else {
+ marker.showInfoWindow();
+ }
+ return true;
+ });
+
+ // set its position
+ marker.setPosition(geoPoint);
+ marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
+ // display the marker
+ map.getOverlays().add(marker);
+ // add to it an icon
+ marker.setIcon(getResources().getDrawable(R.drawable.bus_marker));
+ // add to it a name
+ marker.setTitle(stopName);
+
+ }
+
+ public void loadMarkers() {
+
+ // get rid of the previous markers
+ map.getOverlays().clear();
+
+ // add new markers of the stops in the screen
+ BoundingBox bb = map.getBoundingBox();
+ double latFrom = bb.getLatSouth();
+ double latTo = bb.getLatNorth();
+ double lngFrom = bb.getLonWest();
+ double lngTo = bb.getLonEast();
+
+ StopsDB stopsDB = new StopsDB(ctx);
+ stopsDB.openIfNeeded();
+ Stop[] stops = stopsDB.queryAllInsideMapView(latFrom, latTo, lngFrom, lngTo);
+ stopsDB.closeIfNeeded();
+
+ for (Stop stop : stops) {
+ GeoPoint marker = new GeoPoint(stop.getLatitude(), stop.getLongitude());
+ makeMarker(marker, stop.getStopDefaultName(), stop.ID);
+ }
+
+ }
+
+ public void onResume(){
+ super.onResume();
+ //this will refresh the osmdroid configuration on resuming.
+ //if you make changes to the configuration, use
+ //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ //Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
+ map.onResume(); //needed for compass, my location overlays, v6.0.0 and up
+ }
+
+ public void onPause(){
+ super.onPause();
+ //this will refresh the osmdroid configuration on resuming.
+ //if you make changes to the configuration, use
+ //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ //Configuration.getInstance().save(this, prefs);
+ map.onPause(); //needed for compass, my location overlays, v6.0.0 and up
+ }
+}
\ No newline at end of file

File Metadata

Mime Type
text/plain
Expires
Thu, Mar 12, 04:34 (5 h, 29 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1739397
Default Alt Text
D24.1773286479.diff (14 KB)

Event Timeline