Skip to content

Commit

Permalink
measure text height in tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
fdansv committed Nov 23, 2013
1 parent a6d3cf3 commit 8f005f0
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 247 deletions.
32 changes: 16 additions & 16 deletions .idea/workspace.xml

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

1 change: 1 addition & 0 deletions src/.idea/modules.xml

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

208 changes: 171 additions & 37 deletions src/.idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/src/com/mapbox/mapboxsdk/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MapView extends org.osmdroid.views.MapView{
private MapController controller;
private ItemizedIconOverlay<OverlayItem> defaultMarkerOverlay;
private ArrayList<OverlayItem> defaultMarkerList = new ArrayList<OverlayItem>();

private Context context;
private boolean firstMarker = true;

Expand All @@ -40,8 +41,7 @@ public MapView(Context context, String URL){
*/

public Marker addMarker(double lat, double lon, String title, String text){
Marker marker = new Marker(title, text, new GeoPoint(lat, lon));
marker.fromMaki("restaurant");
Marker marker = new Marker(this, title, text, new GeoPoint(lat, lon));
if(firstMarker){
defaultMarkerList.add(marker);
setDefaultItemizedOverlay();
Expand Down
29 changes: 18 additions & 11 deletions src/src/com/mapbox/mapboxsdk/Marker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.mapboxsdk;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
Expand All @@ -13,23 +14,29 @@
import java.net.URL;

public class Marker extends OverlayItem{
public Marker(String aTitle, String aSnippet, GeoPoint aGeoPoint) {
super(aTitle, aSnippet, aGeoPoint);
//Drawable markerDrawable = ;
//this.setMarker(markerDrawable);
}
private Context context;


public Marker(String aUid, String aTitle, String aDescription, GeoPoint aGeoPoint) {
super(aUid, aTitle, aDescription, aGeoPoint);
public Marker(String aTitle, String aDescription, GeoPoint aGeoPoint) {
super(aTitle, aDescription, aGeoPoint);
fromMaki("markerstroked");
}
public Marker(MapView mv, String aTitle, String aDescription, GeoPoint aGeoPoint) {
super(aTitle, aDescription, aGeoPoint);
context = mv.getContext();
fromMaki("markerstroked");
}

public void fromMaki(String makiString){
String urlString = "https://raw.github.com/mapbox/maki/gh-pages/renders/"+makiString+"[email protected]";
this.setMarker(new BitmapDrawable());
new BitmapLoader().execute(urlString);

String urlString = makiString+"182x";
System.out.println(urlString);
int id = context.getResources().getIdentifier(urlString, "drawable", context.getPackageName());
System.out.println(""+id);
this.setMarker(context.getResources().getDrawable(id));
//this.setMarker(context.getResources().getDrawable(R.drawable.library182x));
}


class BitmapLoader extends AsyncTask<String, Void,Bitmap> {

@Override
Expand Down
12 changes: 6 additions & 6 deletions src/src/com/mapbox/mapboxsdk/Tooltip.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.mapbox.mapboxsdk;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.*;
import org.osmdroid.ResourceProxy;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.overlay.Overlay;
Expand All @@ -28,7 +25,10 @@ private Tooltip(ResourceProxy pResourceProxy) {

@Override
protected void draw(Canvas canvas, org.osmdroid.views.MapView mapView, boolean shadow) {
System.out.println("this is being called");
Rect bounds = new Rect();
String text = "Helloooo this is a tooltip!";
paint.getTextBounds(text, 0, text.length()-1, bounds);
int innerBoxHeight = bounds.height();
GeoPoint markerCoords = item.getPoint();
MapView.Projection projection = mapView.getProjection();
Point point = new Point();
Expand All @@ -42,6 +42,6 @@ protected void draw(Canvas canvas, org.osmdroid.views.MapView mapView, boolean s
paint.setColor(Color.rgb(50, 50, 50));
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(40f);
canvas.drawText("Helloooo this is a tooltip!", point.x, point.y-140, paint);
canvas.drawText(text, point.x, point.y-140, paint);
}
}
2 changes: 1 addition & 1 deletion test/.idea/.name

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

169 changes: 165 additions & 4 deletions test/.idea/misc.xml

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

4 changes: 1 addition & 3 deletions test/.idea/modules.xml

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

Loading

0 comments on commit 8f005f0

Please sign in to comment.