Disabled BSM mode switch when plugged in
Battery Saver mode can no longer be toggled when the device is plugged in. Additionaly, A content description was added to the switch so that talkback says something when it is single tapped. Bug: 30083279 Change-Id: Id901598dbe13c443cae0b32769a2e3ef50428c08
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.res.Resources;
|
|||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.BatteryManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
@@ -186,23 +187,36 @@ public class BatterySaverSettings extends SettingsPreferenceFragment
|
|||||||
};
|
};
|
||||||
|
|
||||||
private final class Receiver extends BroadcastReceiver {
|
private final class Receiver extends BroadcastReceiver {
|
||||||
|
|
||||||
private boolean mRegistered;
|
private boolean mRegistered;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (DEBUG) Log.d(TAG, "Received " + intent.getAction());
|
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) {
|
public void setListening(boolean listening) {
|
||||||
if (listening && !mRegistered) {
|
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;
|
mRegistered = true;
|
||||||
} else if (!listening && mRegistered) {
|
} else if (!listening && mRegistered) {
|
||||||
mContext.unregisterReceiver(this);
|
mContext.unregisterReceiver(this);
|
||||||
mRegistered = false;
|
mRegistered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class SettingsObserver extends ContentObserver {
|
private final class SettingsObserver extends ContentObserver {
|
||||||
|
Reference in New Issue
Block a user