Android Open Source - PTScreenOff Power Toggles Plugin






From Project

Back to project page PTScreenOff.

License

The source code is released under:

GNU General Public License

If you think the Android project PTScreenOff 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 org.liberty.android.ptplugin.screenoff;
/*from  www  .j a  va 2 s. co m*/
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

public abstract class PowerTogglesPlugin extends BroadcastReceiver {

  // Intent send by PowerToggles asking for a state change
  public static final String ACTION_SET_STATE = "com.painless.pc.ACTION_SET_STATE";

  // Intent extra denoting the state. Value must be a boolean.
  public static final String EXTRA_STATE = "state";

  // Must be set to the class name of the receiver, when informing PowerToggles
  // of a state change. 
  public static final String EXTRA_VARID = "varID";

  @Override
  public void onReceive(Context context, Intent intent) {
    if (ACTION_SET_STATE.equals(intent.getAction())) {
      changeState(context, intent.getBooleanExtra(EXTRA_STATE, false));
    }
  }

  /**
   * Called when the PowerToggles widget requests a state change because
   * the user clicked the corresponding toggle.
   */
  protected abstract void changeState(Context context, boolean newState);

  /**
   * Updates the plugin state in PowerToggles widget.
   */
  public final void sendStateUpdate(Context context, boolean newState) {
    sendStateUpdate(this.getClass(), newState, context);
  }

  /**
   * Updates the plugin state in PowerToggles widget.
   * @param pluginClass The receiver implementing the plugin. An application can
   * define multiple plugins, with one receiver per plugin.
   * @param newState
   * @param context
   */
  public static final void sendStateUpdate(Class<? extends PowerTogglesPlugin> pluginClass,
      boolean newState, Context context) {
    context.sendBroadcast(new Intent()
      .setComponent(new ComponentName("com.painless.pc", "com.painless.pc.PluginUpdateReceiver"))
      .putExtra(EXTRA_VARID, pluginClass.getName())
      .putExtra(EXTRA_STATE, newState));
  }
}




Java Source Code List

eu.chainfire.libsuperuser.Application.java
eu.chainfire.libsuperuser.Debug.java
eu.chainfire.libsuperuser.HideOverlaysReceiver.java
eu.chainfire.libsuperuser.ShellNotClosedException.java
eu.chainfire.libsuperuser.ShellOnMainThreadException.java
eu.chainfire.libsuperuser.Shell.java
eu.chainfire.libsuperuser.StreamGobbler.java
org.liberty.android.ptplugin.screenoff.MainActivityTest.java
org.liberty.android.ptplugin.screenoff.MainActivity.java
org.liberty.android.ptplugin.screenoff.MainReceiver.java
org.liberty.android.ptplugin.screenoff.PowerTogglesPlugin.java
org.liberty.android.ptplugin.screenoff.ScreenOffUtil.java