Methods Summary |
---|
void | log(java.lang.String s)
mLog.setText(mLog.getText() + "\n" + mDateFormat.format(new Date()) + ": " + s);
|
public void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
// Set the layout for this activity. You can find it
// in res/layout/hello_activity.xml
setContentView(R.layout.battery_waster);
findViewById(R.id.checkbox).setOnClickListener(mClickListener);
findViewById(R.id.checkbox_wake).setOnClickListener(mWakeClickListener);
mLog = (TextView)findViewById(R.id.log);
mDateFormat = DateFormat.getInstance();
mFilter = new IntentFilter();
mFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
mFilter.addAction(Intent.ACTION_BATTERY_LOW);
mFilter.addAction(Intent.ACTION_BATTERY_OKAY);
mFilter.addAction(Intent.ACTION_POWER_CONNECTED);
PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
mPartialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BatteryWaster");
mPartialWakeLock.setReferenceCounted(false);
|
public void | onDestroy()
super.onDestroy();
stopRunning();
if (mPartialWakeLock.isHeld()) {
mPartialWakeLock.release();
}
|
public void | onResume()
super.onResume();
if (((CheckBox)findViewById(R.id.checkbox)).isChecked()) {
startRunning();
}
if (((CheckBox)findViewById(R.id.checkbox_wake)).isChecked()) {
mWaking = true;
updateWakeLock();
}
|
void | startRunning()
if (!mWasting) {
log("Start");
registerReceiver(mReceiver, mFilter);
mWasting = true;
updateWakeLock();
if (mThread == null) {
mThread = new SpinThread();
mThread.start();
}
}
|
void | stopRunning()
if (mWasting) {
log("Stop");
unregisterReceiver(mReceiver);
mWasting = false;
updateWakeLock();
if (mThread != null) {
mThread.quit();
mThread = null;
}
}
|
void | updateWakeLock()
if (mWasting) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
if (mWaking) {
if (!mPartialWakeLock.isHeld()) {
mPartialWakeLock.acquire();
}
} else {
if (mPartialWakeLock.isHeld()) {
mPartialWakeLock.release();
}
}
|