Google Summer of Code – Week # 7

As the Abstracts section’s implementation was completed last week, it was time to move forward. The plan was to implement the ‘Schedule’ Section but unfrotunately my mentor, Sir Christian Garbers, told that they still had not finalized the Schedule JSON Format and he would be AFK for next few days. So I decided to skip ‘Schedule’ section for the moment and go on…



The basic task was to port the map activity for new version and layout from previous version, which I managed to do easily. The next step was to activate Google Maps API V2 by getting API key from Google. Google has outlined the process for getting API Key for your android app here:

I decided to extend the maps functionality for adding Navigation option so user can route himself or get directions for any of the marked locations on map from his/her current position, by clicking on the Marker infoWindow on the Map. For this purpose, I drafted custom layout for the marker infoWindow to add a ‘route’ icon alongwith the location label. Here’s how I did that:

 //adapter for custom info-window - added icon for navigation
 supportMap.setInfoWindowAdapter(new InfoWindowAdapter() {

 public View getInfoWindow(Marker arg0) {
 // TODO Auto-generated method stub
 return null;

 public View getInfoContents(Marker arg0) {
 // TODO Auto-generated method stub
 // Getting view from the layout file info_window_layout
 View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

 // Getting reference to the TextView to set title
 TextView note = (TextView) v.findViewById(;

 note.setText(arg0.getTitle() ); //sets marker title

 // Returning the view containing InfoWindow contents
 return v;

Note the R.layout.info_window_layout in getInfoContents method. That’s the layout file for the marker custom infoWindow – loaded with a TextView and an icon.

The layout is now ready – Next step was to implement navigation feature via Googel Maps App i.e. when user would click on the marker, it should open Google Maps application with marker pointed at that location. The functionality of  ‘Route’ / Navigation already exists in Google Maps app. Android provides option for GeoIntents – Intents that open Google maps app automatically. You just pass that intent with Longitude, Latitude and Label as parameters – Rest it handles itself. So in  setOnInfoWindowClickListener, I first got Title, Longitude and Latitude values for that marker and then passed that with GeoIntent. The GeoIntent URI format is: geo:0,0?q=lat,lng(label)  – This is how i did that:

Map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
 public void onInfoWindowClick(Marker marker) {
 LatLng position = marker.getPosition();
 Intent navigateIntent = new Intent(Intent.ACTION_VIEW);

 String currentLat = String.valueOf(position.latitude);  //Get Lat value
 String currentLong = String.valueOf(position.longitude);  //Get Long value
 String currLabel = marker.getTitle();  //Get Title of Location

 //Format URI as per required format which is > geo:0,0?q=lat,lng(label)
 String geoLocation = "geo:0,0?q=" + currentLat + "," + currentLong + "(" + currLabel + ")";


The complete code for Map feature can be found here:

Following are the screenshots of map activity:



Tabbed layout for AbstractContent Activity

The app is also supposed to have ‘Notes’ Section for Abstracts so user can take note against some particular Abstract. But before implementation of Notes section, I had to do something with Layout of AbstractContent Activity for making space for Notes. I did a lot of research on it and the only good solution was to implement tabbed layout with ViewPager and Fragments. 

Uptill now, I had never worked with Fragments so I was little confused and this was a challenging task. Thanks to the Documentation and Androidhive guy, he has a great tutorial on Viewpager and Fragments, I finally managed to convert the AbstractContent Activity into Viewpager with 2 Fragments layout.

The new structure goes something like this: AbstractContent Activity is now parent activity that hosts the ViewPager. ViewPager hosts Tabbed layout with 2 Tabs and 2 Fragments respectively via custom FragmentPagerAdapter (Needed to override some methods ). AbstractContentTabFragment is the fragment for the default tab and shows all the Abstract Content just like it used to in previous activity. The other Fragment is AbstractNotesFragment which is for the 2nd tab i.e ‘Notes’.

I won’t go into detail of code for each of these but here is the link for the commit where I converted the Activity into Viewpager and Fragments. abf8cdfbefa806348058afcd857c9376bfa63fa4

If you have any question about the code or related, feel free to ask in comments and do share your thoughts and feedback on it in comments below. I’ll be looking forward to any suggestions or feedback.

GSoC Week # 7 – (30 June 2014 – 06 July 2014)

Leave a Reply