Back to project page Go2-Rennes.
The source code is released under:
GNU General Public License
If you think the Android project Go2-Rennes 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 (c) 2011 Michel DAVID mimah35-at-gmail.com * /*from ww w. ja v a 2 s. co m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ package fr.gotorennes.remote; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import fr.gotorennes.domain.MetroStation; public class MetroStationService extends RemoteService<MetroStation> { public static final String COMMAND = "getmetrostations"; public static final String NODE = "station"; private static MetroStationService instance; private MetroStationService(Context context) { super(); } protected String getVersion() { return "2.0"; } public static synchronized MetroStationService getInstance(Context context) { if (instance == null) { instance = new MetroStationService(context); } return instance; } private List<MetroStation> cache = null; public List<MetroStation> getMetroStations() { if (cache == null) { cache = loadList(COMMAND, NODE); } return cache != null ? new ArrayList<MetroStation>(cache) : cache; } public List<MetroStation> getMetroStations(double latitudeMin, double latitudeMax, double longitudeMax, double longitudeMin) { List<MetroStation> metroStations = getMetroStations(); if (metroStations == null) { return null; } List<MetroStation> result = new ArrayList<MetroStation>(); for (MetroStation metro : metroStations) { if (metro.latitude >= latitudeMin && metro.latitude <= latitudeMax && metro.longitude >= longitudeMin && metro.longitude <= longitudeMax) { result.add(metro); } } return result; } public List<MetroStation> getProximityMetroStations(double latitude, double longitude) { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("mode", "proximity"); parameters.put("type", "coords"); parameters.put("lat", String.valueOf(latitude)); parameters.put("lng", String.valueOf(longitude)); return loadList(COMMAND, NODE, parameters); } public MetroStation getMetroStation(String id) { List<MetroStation> metroStations = getMetroStations(); if (metroStations == null) { return null; } for (MetroStation metroStation : metroStations) { if (metroStation.id.equals(id)) { return metroStation; } } return null; } @Override protected MetroStation populate(JSONObject jsonObject) throws JSONException { MetroStation metroStation = new MetroStation(); metroStation.id = jsonObject.getString("id"); metroStation.name = jsonObject.getString("name"); metroStation.sequence = jsonObject.getInt("rankingPlatformDirection1"); metroStation.latitude = Double.valueOf(jsonObject.getString("latitude")); metroStation.longitude = Double.valueOf(jsonObject.getString("longitude")); return metroStation; } }