Android Open Source - commotion-android Toggle Receiver






From Project

Back to project page commotion-android.

License

The source code is released under:

GNU General Public License

If you think the Android project commotion-android 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 net.commotionwireless.meshtether;
//from   www .  j  a  v a2  s.c o  m
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class ToggleReceiver extends BroadcastReceiver {
  final static String TAG = "ToggleReceiver";
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive " + intent.getAction());
    if (MeshTetherApp.ACTION_TOGGLE.equals(intent.getAction())) {
      // potential race conditions, but they are benign
      MeshService service = MeshService.singleton;
      //Log.d(TAG, "service " + ((service == null) ? "null" : "present"));
      if (service != null) {
        if (!intent.getBooleanExtra("start", false)) {
          Log.d(TAG, "stop");
          service.stopRequest();
        }
      } else {
        if (intent.getBooleanExtra("start", true)) {
          Log.d(TAG, "start");
          context.startService(new Intent(context, MeshService.class));
        }
      }
    } else if (MeshTetherApp.ACTION_CHECK.equals(intent.getAction())) {
      // FIXME: this is the most inefficient way of finding out the state
      MeshService service = MeshService.singleton;
      int state = (service != null) ? service.getState() : MeshService.STATE_STOPPED;
      MeshTetherApp.broadcastState(context, state);
    }
  }
}




Java Source Code List

net.commotionwireless.meshtether.IPPreference.java
net.commotionwireless.meshtether.InfoActivity.java
net.commotionwireless.meshtether.LinksActivity.java
net.commotionwireless.meshtether.MACPreference.java
net.commotionwireless.meshtether.MeshIPPreference.java
net.commotionwireless.meshtether.MeshService.java
net.commotionwireless.meshtether.MeshTetherApp.java
net.commotionwireless.meshtether.NativeHelper.java
net.commotionwireless.meshtether.SettingsActivity.java
net.commotionwireless.meshtether.StatusActivity.java
net.commotionwireless.meshtether.ToggleReceiver.java
net.commotionwireless.meshtether.Util.java