Back to project page PalmaBici.
The source code is released under:
GNU General Public License
If you think the Android project PalmaBici listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright 2012 Sergio Garcia Villalonga (yayalose@gmail.com) */* w w w . j a v a 2 s . c o m*/ * This file is part of PalmaBici. * * PalmaBici is free software: you can redistribute it and/or modify * it under the terms of the Affero GNU General Public License version 3 * as published by the Free Software Foundation. * * PalmaBici is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * Affero GNU General Public License for more details * (https://www.gnu.org/licenses/agpl-3.0.html). * */ package com.poguico.palmabici.util; import java.util.ArrayList; import com.poguico.palmabici.R; import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.PathOverlay; import org.xmlpull.v1.XmlPullParser; import android.app.Activity; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.util.DisplayMetrics; public class BikeLane { //private static ArrayList<ArrayList<GeoPoint>> paths = null; private static ArrayList<PathOverlay> osmPaths = null; private static void init (Activity activity, MapView mapView) { PathOverlay pathOverlay; osmPaths = new ArrayList<PathOverlay>(); Resources res = activity.getResources(); XmlResourceParser xpp = res.getXml(R.xml.carril_bici_palma); DisplayMetrics dpi = activity.getResources().getDisplayMetrics(); float pathWidth = dpi.density*4; try { xpp.next(); int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("coordinates")) { eventType = xpp.next(); if(eventType == XmlPullParser.TEXT) { String text = xpp.getText(); pathOverlay = new PathOverlay(0xffa0a0ff, pathWidth, mapView.getResourceProxy()); for (String coordinate : text.split("\n")) { String[] coordElements = coordinate.split(","); pathOverlay.addPoint( new GeoPoint(Double.valueOf(coordElements[1]), Double.valueOf(coordElements[0]))); } osmPaths.add(pathOverlay); } } else { eventType = xpp.next(); } } } catch (Exception e) { e.printStackTrace(); } } public static ArrayList<PathOverlay> getOSMPaths(Activity activity, MapView mapView) { if (osmPaths == null) { init(activity, mapView); } return osmPaths; } }