Skip to content

Commit

Permalink
corretta classe MappaPercorso
Browse files Browse the repository at this point in the history
Signed-off-by: Luigi Amitrano <[email protected]>
  • Loading branch information
beken89 committed Jul 2, 2014
1 parent 0faf775 commit ffe2936
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 71 deletions.
4 changes: 2 additions & 2 deletions gen/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/it
/.gitignore
/android
/com
/it
/.gitignore
137 changes: 68 additions & 69 deletions src/it/unisa/followteam/MappaPercorso.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.provider.Settings;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -204,74 +205,72 @@ public void onClick(DialogInterface dialog, int which) {
public void onPause() {
super.onPause();
}

private class ReadTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... url) {
String data = "";
try {
HttpConnection http = new HttpConnection();
data = http.readUrl(url[0]);
} catch (Exception e) {
}
return data;
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
new ParserTask().execute(result);
}

private class ParserTask extends
AsyncTask<String, Integer, List<List<HashMap<String, String>>>> {

@Override
protected List<List<HashMap<String, String>>> doInBackground(
String... jsonData) {

JSONObject jObject;
List<List<HashMap<String, String>>> routes = null;

try {
jObject = new JSONObject(jsonData[0]);
PathJSONParser parser = new PathJSONParser();
routes = parser.parse(jObject);
} catch (Exception e) {
e.printStackTrace();
}
return routes;
}

@Override
protected void onPostExecute(
List<List<HashMap<String, String>>> routes) {
ArrayList<LatLng> points = null;
PolylineOptions polyLineOptions = null;

// traversing through routes
for (int i = 0; i < routes.size(); i++) {
points = new ArrayList<LatLng>();
polyLineOptions = new PolylineOptions();
List<HashMap<String, String>> path = routes.get(i);

for (int j = 0; j < path.size(); j++) {
HashMap<String, String> point = path.get(j);

double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);

points.add(position);
}

polyLineOptions.addAll(points);
polyLineOptions.width(2);
polyLineOptions.color(Color.BLUE);
}

map.addPolyline(polyLineOptions);
}
}
}
@Override
protected String doInBackground(String... url) {
String data = "";
try {
HttpConnection http = new HttpConnection();
data = http.readUrl(url[0]);
} catch (Exception e) {
}
return data;
}

@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
new ParserTask().execute(result);
}
}

private class ParserTask extends
AsyncTask<String, Integer, List<List<HashMap<String, String>>>> {

@Override
protected List<List<HashMap<String, String>>> doInBackground(
String... jsonData) {

JSONObject jObject;
List<List<HashMap<String, String>>> routes = null;

try {
jObject = new JSONObject(jsonData[0]);
PathJSONParser parser = new PathJSONParser();
routes = parser.parse(jObject);
} catch (Exception e) {
e.printStackTrace();
}
return routes;
}

@Override
protected void onPostExecute(List<List<HashMap<String, String>>> routes) {
ArrayList<LatLng> points = null;
PolylineOptions polyLineOptions = null;

// traversing through routes
for (int i = 0; i < routes.size(); i++) {
points = new ArrayList<LatLng>();
polyLineOptions = new PolylineOptions();
List<HashMap<String, String>> path = routes.get(i);

for (int j = 0; j < path.size(); j++) {
HashMap<String, String> point = path.get(j);

double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);

points.add(position);
}

polyLineOptions.addAll(points);
polyLineOptions.width(10);
polyLineOptions.color(Color.RED);
}
map.addPolyline(polyLineOptions);
}
}
}

0 comments on commit ffe2936

Please sign in to comment.