import android.database.ContentObserver;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
};
private final class Receiver extends BroadcastReceiver {
+
private boolean mRegistered;
@Override
public void onReceive(Context context, Intent intent) {
if (DEBUG) Log.d(TAG, "Received " + intent.getAction());
- mHandler.post(mUpdateSwitch);
+ String action = intent.getAction();
+ if (action.equals(ACTION_POWER_SAVE_MODE_CHANGING)) {
+ mHandler.post(mUpdateSwitch);
+ } else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
+ final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
+ // disable BSM switch if phone is plugged in or at 100% while plugged in
+ mSwitchBar.setEnabled(
+ !(status == BatteryManager.BATTERY_STATUS_CHARGING
+ || status == BatteryManager.BATTERY_STATUS_FULL));
+ }
}
-
public void setListening(boolean listening) {
if (listening && !mRegistered) {
- mContext.registerReceiver(this, new IntentFilter(ACTION_POWER_SAVE_MODE_CHANGING));
+ final IntentFilter ifilter = new IntentFilter();
+ ifilter.addAction(ACTION_POWER_SAVE_MODE_CHANGING);
+ ifilter.addAction(Intent.ACTION_BATTERY_CHANGED);
+ mContext.registerReceiver(this, ifilter);
mRegistered = true;
} else if (!listening && mRegistered) {
mContext.unregisterReceiver(this);
mRegistered = false;
}
}
+
}
private final class SettingsObserver extends ContentObserver {