Back to project page AGOGCyberStat.
The source code is released under:
MIT License
If you think the Android project AGOGCyberStat listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.agog.cyberstat; /* w w w .ja v a2 s .co m*/ import me.allenz.androidapplog.Logger; import me.allenz.androidapplog.LoggerFactory; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /** * @author greg@agog.com * * Wrapper around JSON parsing for interface to application settings */ public class JSONSettings { private static final Logger logger = LoggerFactory.getLogger(); JSONObject mReader; JSONSettings(String jstr) { try { mReader = new JSONObject(jstr); } catch (JSONException e) { logger.debug("JSONSettings " + e); } } String getString(String key) { if(mReader != null) { try { return(mReader.getString(key)); } catch (JSONException e) { logger.debug("getString parse error " + e); } } return(null); } int getInt(String key) { if(mReader != null) { try { return(mReader.getInt(key)); } catch (JSONException e) { logger.debug("getInt parse error " + e); } } return(0); } String getEmail() { return(getString("email")); } String getPassword() { return(getString("password")); } int getWarm() { return(getInt("warm")); } int getCold() { return(getInt("cold")); } Trigger getTrigger(String ssid,Boolean connect) { logger.debug("getTrigger " + ssid + " " + connect); if(mReader != null) { try { JSONArray ja = mReader.getJSONArray("trigger"); for(int i = 0; i < ja.length(); i++) { JSONObject jo = ja.getJSONObject(i); String s = jo.getString("ssid"); Boolean c = jo.getBoolean("connect"); if(s != null && ssid.equals(s) && connect == c) { Trigger tr = new Trigger(); tr.ssid = ssid; tr.connect = connect; tr.temp = jo.getString("temp"); tr.notify = jo.getBoolean("notify"); tr.sound = jo.getBoolean("sound"); tr.ringtone = jo.getString("ringtone"); return(tr); } } } catch (JSONException e) { logger.debug("getTrigger parse error " + e); } } return null; } }