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; /*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); } }