2

Am trying to customize the view of Snippet & Title in MapView using CommonsWare's Example
However am not able to Customize the Typeface of the snippet.
Custom Snippet MapsV2
Any luck?

Community
  • 1
  • 1
VenomVendor
  • 15,064
  • 13
  • 65
  • 96

1 Answers1

4

If you extended the example from CommonsWare, you should have a PopupAdapter which is responsible for displaying your InfoWindow.

I've extended that PopupAdapter to load a Typeface from my assets folder, and set it as the title and snippet views typeface

class PopupAdapter implements InfoWindowAdapter {
    LayoutInflater inflater = null;

    // Context is most likely the map hosting activity. 
    // We need this so we get access to the Asset Manager
    Context context = null;

    PopupAdapter(LayoutInflater inflater, Context context) {
        this.inflater = inflater;
        this.context = context;
    }

    @Override
    public View getInfoWindow(Marker marker) {
        return (null);
    }

    @Override
    public View getInfoContents(Marker marker) {
        View popup = inflater.inflate(R.layout.popup, null);

        TextView tv = (TextView) popup.findViewById(R.id.title);

        tv.setText(marker.getTitle());

        // We load a typeface by using the static createFromAssets method
        // and provide the asset manager 
        // and a path to the file within the assets folder
        Typeface tf = Typeface.createFromAsset(context.getAssets(),
                "GoodDog.otf");
        // then set the TextViews typeface
        tv.setTypeface(tf);
        tv = (TextView) popup.findViewById(R.id.snippet);
        tv.setText(marker.getSnippet());
        tv.setTypeface(tf);

        return (popup);
    }
}
Daniel H.
  • 243
  • 1
  • 3
  • 10
  • I have down voted for following reasons, [Android doesn't support otf](http://stackoverflow.com/a/1430320/1008278). `getAssets()` is not recognized in `InfoWindowAdapter`. I strongly suggest you to make sure you implement the code before answering, cox, it can mislead the users. – VenomVendor Mar 31 '13 at 14:33
  • 1
    getAssets() is a method of the Context class, which is a parameter of the PopupAdapters constructor. Android supports otf but not since version 1.0, it's even in the update provided in your link. I'm not 100% sure since when OTF support is in Android, but my example is functional on a Galaxy Nexus running 4.2.2. – Daniel H. Mar 31 '13 at 14:44
  • I have replaced my code with your code, am getting runtime error. – VenomVendor Mar 31 '13 at 14:56
  • Can you link a pastebin with the runtime error? Just a sidenote, you can't just replace your code with mine, because you're most likely missing the font files that I have in my projects asset folder. Have you replaced the font I used with your own? – Daniel H. Mar 31 '13 at 15:02
  • I can only make an assuption here. Have you checked in the debugger that context is not null? The call that creates the PopupAdapter should lookesome like this: `map.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater(), this));`. Does the file exist as *projectroot*/assets/FrizQua.ttf? – Daniel H. Mar 31 '13 at 15:30
  • 1
    I'm a little out of ideas. I've created a fork from the CommonsWare example, and put my changes into it. It's available here https://github.com/tchackie/cw-omnibus. I tested it on Jelly Bean and a Gingerbread Device, and it's working on both. Hope you find a way to get your project working. – Daniel H. Mar 31 '13 at 16:21