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 w w w . ja va 2s .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.List; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import fr.gotorennes.domain.Equipement; import fr.gotorennes.domain.MetroStation; public class EquipementService extends RemoteService<Equipement> { public static final String COMMAND = "getequipments"; public static final String NODE = "equipment"; private static EquipementService instance; private EquipementService(Context context) { super(); } protected String getVersion() { return "2.0"; } public static synchronized EquipementService getInstance(Context context) { if (instance == null) { instance = new EquipementService(context); } return instance; } private List<Equipement> cache = null; public List<Equipement> getEquipements() { if (cache == null) { cache = loadList(COMMAND, NODE); } return cache != null ? new ArrayList<Equipement>(cache) : cache; } public List<Equipement> getEquipements(MetroStation metroStation) { List<Equipement> equipements = getEquipements(); if (equipements == null) { return null; } List<Equipement> result = new ArrayList<Equipement>(); for (Equipement equipement : equipements) { if (equipement.station.equals(metroStation.id)) { result.add(equipement); } } return result; } @Override protected Equipement populate(JSONObject jsonObject) throws JSONException { Equipement equipement = new Equipement(); equipement.id = jsonObject.getString("id"); equipement.station = jsonObject.getString("station"); equipement.type = jsonObject.getString("type"); equipement.fromFloor = Integer.valueOf(jsonObject.getString("fromfloor")); equipement.toFloor = Integer.valueOf(jsonObject.getString("tofloor")); equipement.plateforme = Integer.valueOf(jsonObject.getString("platform")); return equipement; } }