diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/DatabaseHandler.java b/app/src/main/java/de/apps4ics/mountainnavigation/DatabaseHandler.java index a514301..d8c33bc 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/DatabaseHandler.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/DatabaseHandler.java @@ -5,6 +5,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; import java.util.ArrayList; import java.util.List; @@ -14,7 +15,7 @@ */ public class DatabaseHandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; - private static final String DATABASE_NAME = "mountainNavigation"; + private static final String DATABASE_NAME = "mountainNavigation.db"; private static final String TABLE_GP = "geopoint"; private static final String TABLE_FOUNTAIN = "fountain"; private static final String TABLE_PATH = "path"; @@ -309,8 +310,11 @@ new String[]{String.valueOf(gp_id)}, null, null, null, null); if(gpCursor != null){ gpCursor.moveToFirst(); + return getGeoPointFromCursor(gpCursor); + } else { + Log.e(MainActivity.TAG, "No geopoint with id " + gp_id + " found"); + return null; } - return getGeoPointFromCursor(gpCursor); } private Fountain getFountainFromCursor(Cursor cursor){ diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java index 29e3120..eb83059 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java @@ -404,17 +404,46 @@ String snippetText = res.getString(R.string.osm_marker_snippet, gp.getLatitude(), gp.getLongitude(), gp.getAltitude(), df_full.format(new Date(dbgp.getTime()))); String subDescText; - if(type == Types.FOUNTAIN) title += " (" + fountainSizes[((Fountain) poi).getSize()] + ")"; + switch(type){ + case Types.FOUNTAIN: + title += " (" + fountainSizes[((Fountain) poi).getSize()] + ")"; + break; + case Types.PATH: { + Path p = (Path) poi; + DbGeoPoint pathEnd = p.getEndGp(); + title += " (" + p.getLength() + ")"; + Marker positionMarker = new Marker(mapView); + positionMarker.setPosition(new GeoPoint(pathEnd.getLat(), pathEnd.getLon(), pathEnd.getAlt())); + positionMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); + positionMarker.setTitle(title); + positionMarker.setSnippet(snippetText); + positionMarker.setImage(res.getDrawable(entryImgs[getPos(type)])); + Drawable[] iconLayer = new Drawable[2]; + iconLayer[0] = res.getDrawable(R.mipmap.ic_poi); + BitmapDrawable bd = (BitmapDrawable) res.getDrawable(entryImgs[getPos(type)]); + if(bd == null) continue; + Bitmap b = bd.getBitmap(); + Bitmap bResized = Bitmap.createScaledBitmap(b, b.getWidth()/2, b.getHeight()/2, false); + bd = new BitmapDrawable(res, bResized); + bd.setGravity(Gravity.CENTER_HORIZONTAL); + iconLayer[1] = bd; + LayerDrawable icon = new LayerDrawable(iconLayer); + positionMarker.setIcon(icon); + result.add(positionMarker); + poiMarkers[getPos(type)].add(positionMarker); + } + break; + } Marker positionMarker = new Marker(mapView); positionMarker.setPosition(gp); positionMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM); positionMarker.setTitle(title); positionMarker.setSnippet(snippetText); - positionMarker.setImage(res.getDrawable(entryImgs[type])); + positionMarker.setImage(res.getDrawable(entryImgs[getPos(type)])); Drawable[] iconLayer = new Drawable[2]; iconLayer[0] = res.getDrawable(R.mipmap.ic_poi); - BitmapDrawable bd = (BitmapDrawable) res.getDrawable(entryImgs[type]); + BitmapDrawable bd = (BitmapDrawable) res.getDrawable(entryImgs[getPos(type)]); if(bd == null) continue; Bitmap b = bd.getBitmap(); Bitmap bResized = Bitmap.createScaledBitmap(b, b.getWidth()/2, b.getHeight()/2, false); @@ -424,7 +453,7 @@ LayerDrawable icon = new LayerDrawable(iconLayer); positionMarker.setIcon(icon); result.add(positionMarker); - poiMarkers[type].add(positionMarker); + poiMarkers[getPos(type)].add(positionMarker); } return result; } @@ -961,7 +990,7 @@ public boolean longPressHelper(GeoPoint geoPoint) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(VIB_LENGTH); - OverlayItem oI = new OverlayItem(null, null, geoPoint); + OverlayItem oI = new OverlayItem("", null, null, geoPoint); oI.setMarker(getApplicationContext().getResources().getDrawable(R.mipmap.ic_poi_red)); overlay.addItem(oI); popupMapView.invalidate(); @@ -1016,18 +1045,38 @@ ArrayList waypoints = new ArrayList<>(); DbGeoPoint current = null; DbGeoPoint last = null; + boolean currentNew = false; + boolean lastNew = false; for(int i=0; i