Skip to content

Commit

Permalink
Added custom bubble layout, to have a clean "More info" arrow.
Browse files Browse the repository at this point in the history
I also moved the POI markers to their own FolderOverlay to deal with clustering later.
But it weirdly stops the starter Marker to show its title...

Signed-off-by: Thomas Gaudin <thomas.gaudin@centraliens-lille.org>
  • Loading branch information
nymous committed Jul 28, 2015
1 parent 4b977f9 commit 5f344ee
Showing 5 changed files with 86 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
@@ -19,14 +21,12 @@
import com.wikijourney.wikijourney.R;
import com.wikijourney.wikijourney.functions.CustomInfoWindow;
import com.wikijourney.wikijourney.functions.POI;
import com.wikijourney.wikijourney.functions.Routing;

import org.json.JSONArray;
import org.json.JSONObject;
import org.osmdroid.api.IMapController;
import org.osmdroid.bonuspack.clustering.RadiusMarkerClusterer;
import org.osmdroid.bonuspack.overlays.Marker;
import org.osmdroid.bonuspack.routing.OSRMRoadManager;
import org.osmdroid.bonuspack.routing.RoadManager;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
@@ -109,7 +109,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
/* TODO Called when a new location is found by the network location provider. */
drawMap(location, map, finalCoord, locationManager, this);
drawMap(location, map, locationManager, this);
}

public void onStatusChanged(String provider, int status, Bundle extras) {
@@ -144,8 +144,8 @@ public void onDetach() {



public void drawMap(Location location, MapView map, double coord[], LocationManager locationManager, LocationListener locationListener) {
Routing routing = new Routing(getActivity());
public void drawMap(Location location, MapView map, LocationManager locationManager, LocationListener locationListener) {
// Routing routing = new Routing(getActivity());
Gson gson = new Gson();

// TODO Temporary fix
@@ -168,16 +168,17 @@ public void drawMap(Location location, MapView map, double coord[], LocationMana
map.invalidate();

// We can change some properties of the marker (don't forget to refresh the map !!)
startMarker.setInfoWindow(new CustomInfoWindow(map));
startMarker.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.ic_place));
startMarker.setTitle(getString(R.string.you_are_here));
map.invalidate();

// Now we can also calculate and draw roads
// First we need to choose a road manager
RoadManager roadManager = new OSRMRoadManager();
// RoadManager roadManager = new OSRMRoadManager();

// Then we add some waypoints
ArrayList<GeoPoint> waypoints = new ArrayList<>();
// ArrayList<GeoPoint> waypoints = new ArrayList<>();
// Type arrayGeoType = new TypeToken<ArrayList<GeoPoint>>() {}.getType();

// We get the POI around the user with WikiJourney API
@@ -199,11 +200,19 @@ public void drawMap(Location location, MapView map, double coord[], LocationMana
Type arrayPoiType = new TypeToken<ArrayList<POI>>(){}.getType();
poiList = gson.fromJson(finalResponse.toString(), arrayPoiType);

// We create an Overlay Folder to store every POI, so that they are grouped in clusters
// if there are too many of them
RadiusMarkerClusterer poiMarkers = new RadiusMarkerClusterer(getActivity());
Drawable clusterIconD = ContextCompat.getDrawable(getActivity(), R.drawable.marker_cluster);
Bitmap clusterIcon = ((BitmapDrawable)clusterIconD).getBitmap();
poiMarkers.setIcon(clusterIcon);
map.getOverlays().add(poiMarkers);

for (POI poi:poiList) {
double mLat = poi.getLatitude();
double mLong = poi.getLongitude();
GeoPoint poiWaypoint = new GeoPoint(mLat, mLong);
waypoints.add(poiWaypoint);
// waypoints.add(poiWaypoint);
Marker marker = new Marker(map);
marker.setPosition(poiWaypoint);
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
@@ -219,12 +228,13 @@ public void drawMap(Location location, MapView map, double coord[], LocationMana
// icon.setColorFilter(R.color.accent, PorterDuff.Mode.SRC_ATOP);
// DrawableCompat.setTint(icon, R.color.accent); // Doesn't work
marker.setIcon(icon);
map.getOverlays().add(marker);

poiMarkers.add(marker);
}

waypoints.add(0, startPoint);
GeoPoint endPoint = new GeoPoint(coord[0], coord[1]);
map.invalidate();

// waypoints.add(0, startPoint);
// GeoPoint endPoint = new GeoPoint(coord[0], coord[1]);
// waypoints.add(endPoint);

// And we get the road between the points, we build the polyline between them
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import android.view.View;
import android.widget.Button;

import com.wikijourney.wikijourney.R;

import org.osmdroid.bonuspack.overlays.Marker;
import org.osmdroid.bonuspack.overlays.MarkerInfoWindow;
import org.osmdroid.views.MapView;
@@ -16,9 +18,9 @@ public class CustomInfoWindow extends MarkerInfoWindow {
private POI mSelectedPoi;

public CustomInfoWindow(MapView mapView) {
super(org.osmdroid.bonuspack.R.layout.bonuspack_bubble, mapView);
super(R.layout.bonuspack_bubble, mapView);

Button btn = (Button) (mView.findViewById(org.osmdroid.bonuspack.R.id.bubble_moreinfo));
Button btn = (Button) (mView.findViewById(R.id.bubble_moreinfo));

btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
@@ -30,11 +32,10 @@ public void onClick(View view) {
});
}

@Override public void onOpen(Object item){
@Override
public void onOpen(Object item){
super.onOpen(item);
mView.findViewById(org.osmdroid.bonuspack.R.id.bubble_moreinfo).setVisibility(View.VISIBLE);
mView.findViewById(org.osmdroid.bonuspack.R.id.bubble_moreinfo).setScaleX(0.25f);
mView.findViewById(org.osmdroid.bonuspack.R.id.bubble_moreinfo).setScaleY(0.5f);
mView.findViewById(R.id.bubble_moreinfo).setVisibility(View.VISIBLE);

Marker marker = (Marker)item;
mSelectedPoi = (POI)marker.getRelatedObject();
Binary file added app/src/main/res/drawable-mdpi/marker_cluster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions app/src/main/res/layout/bonuspack_bubble.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/bonuspack_bubble" >
<ImageView android:id="@+id/bubble_image"
android:layout_width="65dp"
android:layout_height="65dp"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView android:id="@+id/bubble_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:maxEms="17"
android:layout_gravity="start"
android:layout_weight="1"
android:text="Title" />
<Button android:id="@+id/bubble_moreinfo"
android:background="@drawable/btn_moreinfo"
android:visibility="gone"
android:layout_width="25sp"
android:layout_height="25sp"
android:layout_gravity="end"
android:layout_weight="0" />
</LinearLayout>
<TextView android:id="@+id/bubble_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="12sp"
android:maxEms="17"
android:text="Description" />
<TextView android:id="@+id/bubble_subdescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="10sp"
android:maxEms="17"
android:text="Address"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

2 comments on commit 5f344ee

@nymous
Copy link
Member Author

@nymous nymous commented on 5f344ee Jul 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #29

@nymous
Copy link
Member Author

@nymous nymous commented on 5f344ee Aug 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #16

Please sign in to comment.