Android Open Source - AGOGCyberStat J S O N Settings






From Project

Back to project page AGOGCyberStat.

License

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.

Java Source Code

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;
   
  }
  
}




Java Source Code List

com.agog.cyberstat.BrR.java
com.agog.cyberstat.JSONSettings.java
com.agog.cyberstat.MainActivity.java
com.agog.cyberstat.MotisonNetTask.java
com.agog.cyberstat.MotisonXML.java
com.agog.cyberstat.MyPrefs.java
com.agog.cyberstat.NetR.java
com.agog.cyberstat.Trigger.java
me.allenz.androidapplog.AbstractAppender.java
me.allenz.androidapplog.AbstractLogger.java
me.allenz.androidapplog.AppenderSupportLogger.java
me.allenz.androidapplog.Appender.java
me.allenz.androidapplog.AsyncAppender.java
me.allenz.androidapplog.Configure.java
me.allenz.androidapplog.InternalLogger.java
me.allenz.androidapplog.LogCatAppender.java
me.allenz.androidapplog.LogEvent.java
me.allenz.androidapplog.LogLevel.java
me.allenz.androidapplog.LogTextView.java
me.allenz.androidapplog.LoggerConfig.java
me.allenz.androidapplog.LoggerFactory.java
me.allenz.androidapplog.Logger.java
me.allenz.androidapplog.PropertiesParser.java
me.allenz.androidapplog.ReflectUtils.java
me.allenz.androidapplog.Repository.java
me.allenz.androidapplog.RollingFileAppender.java
me.allenz.androidapplog.TextViewAppender.java