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
* //www.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.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import fr.gotorennes.domain.MetroStation;
publicclass MetroStationStatusService extends RemoteService<String> {
publicstaticfinal String COMMAND = "getmetrostationsstatus";
publicstaticfinal String NODE = "station";
privatestatic MetroStationStatusService instance;
private MetroStationStatusService(Context context) {
super();
}
protected String getVersion() {
return"2.0";
}
publicstaticsynchronized MetroStationStatusService getInstance(Context context) {
if (instance == null) {
instance = new MetroStationStatusService(context);
}
return instance;
}
private Map<String, Long> lastUpdate = new HashMap<String, Long>();
private Map<String, Boolean> cache = new HashMap<String, Boolean>();
publicboolean getMetroStationStatus(MetroStation station) {
Boolean statut = cache.get(station.id);
if (statut == null || System.currentTimeMillis() - lastUpdate.get(station.id) > 600000) {
statut = "1".equals(loadObject(COMMAND, NODE, getStationParameters(station.id)));
cache.put(station.id, statut);
lastUpdate.put(station.id, System.currentTimeMillis());
}
return statut;
}
protected Map<String, String> getStationParameters(String id) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("mode", "station");
parameters.put("station", id);
return parameters;
}
@Override
protected String populate(JSONObject jsonObject) throws JSONException {
return jsonObject.getString("status");
}
}