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.
Java Source Code
/*******************************************************************************
* Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com
* //fromwww.java2s.com
* 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.PointDeVenteCommune;
import fr.gotorennes.domain.PointDeVenteQuartier;
publicclass QuartierService extends RemoteService<PointDeVenteQuartier> {
publicstaticfinal String COMMAND = "getcitydistricts";
publicstaticfinal String NODE = "district";
privatestatic QuartierService instance;
private QuartierService(Context context) {
super();
}
protected String getVersion() {
return"2.0";
}
publicstaticsynchronized QuartierService getInstance(Context context) {
if (instance == null) {
instance = new QuartierService(context);
}
return instance;
}
private Map<String, List<PointDeVenteQuartier>> cache = new HashMap<String, List<PointDeVenteQuartier>>();
public List<PointDeVenteQuartier> getQuartiers(PointDeVenteCommune commune) {
List<PointDeVenteQuartier> quartiers = cache.get(commune.id);
if (quartiers == null) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("mode", "city");
parameters.put("city", commune.nom);
quartiers = loadList(COMMAND, NODE, parameters);
if (quartiers != null) {
cache.put(commune.id, quartiers);
}
}
return quartiers != null ? new ArrayList<PointDeVenteQuartier>(quartiers) : quartiers;
}
@Override
protected PointDeVenteQuartier populate(JSONObject jsonObject) throws JSONException {
PointDeVenteQuartier quartier = new PointDeVenteQuartier();
quartier.id = jsonObject.getString("id");
quartier.nom = jsonObject.getString("name");
return quartier;
}
}