Android Open Source - AGOGCyberStat Br R






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;
/*from w w  w . j a  v  a 2 s .  c om*/
import java.util.StringTokenizer;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.WakefulBroadcastReceiver;
import android.widget.Toast;
import me.allenz.androidapplog.Logger;
import me.allenz.androidapplog.LoggerFactory;

public class BrR extends WakefulBroadcastReceiver {
  private static final Logger logger = LoggerFactory.getLogger();
  public static final String ACTION_WIFI = "com.agog.trigger.wifi";
  public static final String ACTION_SMS = "com.agog.trigger.sms";

  private Context mContext;

  @Override
  public void onReceive(Context context, Intent intent) {
    this.mContext = context;
    MyPrefs.init(context);

    Bundle bundle = intent.getExtras();
    String action = intent.getAction();

    logger.debug("onReceive " + action);     

    // We never want to send a notification unless we have a connection that is ready to transmit data.
    // A wifi disconnect should not be sent until a new network connection is ready.
    if(action.equals(ACTION_WIFI)) {
            String str = MyPrefs.getString("jsonsettings",null);
            JSONSettings jsonsettings = new JSONSettings(str);
            
            logger.debug( "ACTION_WIFI: onReceive() is called with " + intent);
            String msg =  (String) bundle.get("msg");
            if(msg == null) {
              return;
            }
            logger.debug( "msg " + msg);
            StringTokenizer st = new StringTokenizer(msg," "); 
            String verb = "";
            String ssid = "";
            if(st.hasMoreTokens()) { 
              verb = st.nextToken(); 
            }
            st.nextToken(); // skip from or to
            if(st.hasMoreTokens()) { 
              ssid = st.nextToken();
            }
            
            Trigger tr = jsonsettings.getTrigger(ssid,verb.equals("Connected"));
            if(tr != null) {
              setTemp(jsonsettings,tr);
            }

    }
    else if(action.equals(ACTION_SMS)) {
      logger.debug( "ACTION_SMS: onReceive() is called with " + intent);
      String msg =  (String) bundle.get("msg");
      if(msg == null) {
        return;
      }
      logger.debug( "msg " + msg);
      Toast.makeText(context, "SMS " + msg, Toast.LENGTH_SHORT).show();
    }

  }
  
  protected void setTemp(JSONSettings jsonsettings,Trigger tr) {
    int temp = tr.temp.equals("warm") ? jsonsettings.getWarm() :
      jsonsettings.getCold();
    String s = Integer.valueOf(temp).toString();
    
    logger.debug("setTemp " + temp + " " + s);
    new MotisonNetTask(this.mContext).execute(jsonsettings.getEmail(),
        jsonsettings.getPassword(),tr,s,tr.ssid + "  " +
            (tr.connect ? "Up" : "Down"));

  }


  protected void sendwifi(String msg)
  {
    Intent i = new Intent("com.agog.trigger.wifi");
    i.putExtra("msg",msg);
    logger.debug("send " + msg);
    mContext.sendBroadcast(i);
  }
  

}




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