package com.thalmic.android.sample.helloworld;

import org.json.*;
import com.google.android.gms.maps.model.LatLng;

public class Step {
	private JSONObject json;
	public int distance;
	public int duration;
	public LatLng start_location;
	public LatLng end_location;
	public Maneuver maneuver;
	
	public Step(JSONObject json) {
		this.json = json;
		this.distance = parse_value("distance");
		this.duration = parse_value("duration");
		this.start_location = parse_coordinates("start_location");
		this.end_location = parse_coordinates("end_location");
		this.maneuver = parse_maneuver();
	}
	
	private int parse_value(String name) {
    	try {
	        JSONObject json_obj = json.getJSONObject(name);
	        return json_obj.getInt("value");
    	} catch (JSONException e) {
    		return -1;
    	}
	}
	
	private LatLng parse_coordinates(String name) {
    	try {
	        JSONObject json_obj = json.getJSONObject(name);
	        double lat = json_obj.getDouble("lat");
	        double lng = json_obj.getDouble("lng");
	        return new LatLng(lat, lng);
    	} catch (JSONException e) {
        	return null;
    	}
	}
	
	private Maneuver parse_maneuver() {
		try {
			String maneuver_text = json.getString("maneuver");
			return new Maneuver(maneuver_text);
		} catch (JSONException e) {
			return new Maneuver("");
		}
	}
}

@@ -60,16 +60,49 @@
 json.*;%0A
+%0Aimport android.graphics.Color;%0A%0A
 import c
@@ -141,16 +141,74 @@
 .LatLng;
+%0Aimport com.google.android.gms.maps.model.PolylineOptions;
 %0A%0Apublic
@@ -378,16 +378,50 @@
 neuver;%0A
+%09public PolylineOptions polyline;%0A
 %09%0A%09publi
@@ -706,16 +706,52 @@
 uver();%0A
+%09%09this.polyline = parse_polyline();%0A
 %09%7D%0A%09%0A%09pr
@@ -1479,13 +1479,203 @@
 %22);%0A
-
 %09%09%7D%0A%09%7D%0A
+%09%0A%09private PolylineOptions parse_polyline() %7B%0A%09%09PolylineOptions poly = new PolylineOptions();%0A%09%09poly.add(this.start_location, this.end_location).width(5).color(Color.RED);%0A%09%09return poly;%0A%09%7D%0A
 %7D%0A

Add PolylineOptions