BatterySaver: Make the bars orange.
Bug:16203820 Change-Id: I85f700d30a90212202626fc10fb289aca7f2b688
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
<color name="system_bar_background_opaque">#ff000000</color>
|
||||
<color name="system_bar_background_semi_transparent">#66000000</color> <!-- 40% black -->
|
||||
<color name="system_bar_background_transparent">#00000000</color>
|
||||
<color name="system_bar_background_warning">#fff4511e</color><!-- deep orange 600 -->
|
||||
<color name="notification_panel_solid_background">#ff000000</color>
|
||||
<drawable name="status_bar_recents_app_thumbnail_background">#88000000</drawable>
|
||||
<color name="status_bar_recents_app_label_color">#ffffffff</color>
|
||||
|
||||
@@ -44,6 +44,7 @@ public class BarTransitions {
|
||||
public static final int MODE_TRANSLUCENT = 2;
|
||||
public static final int MODE_LIGHTS_OUT = 3;
|
||||
public static final int MODE_TRANSPARENT = 4;
|
||||
public static final int MODE_WARNING = 5;
|
||||
|
||||
public static final int LIGHTS_IN_DURATION = 250;
|
||||
public static final int LIGHTS_OUT_DURATION = 750;
|
||||
@@ -100,6 +101,7 @@ public class BarTransitions {
|
||||
if (mode == MODE_TRANSLUCENT) return "MODE_TRANSLUCENT";
|
||||
if (mode == MODE_LIGHTS_OUT) return "MODE_LIGHTS_OUT";
|
||||
if (mode == MODE_TRANSPARENT) return "MODE_TRANSPARENT";
|
||||
if (mode == MODE_WARNING) return "MODE_WARNING";
|
||||
throw new IllegalArgumentException("Unknown mode " + mode);
|
||||
}
|
||||
|
||||
@@ -115,6 +117,7 @@ public class BarTransitions {
|
||||
private final int mOpaque;
|
||||
private final int mSemiTransparent;
|
||||
private final int mTransparent;
|
||||
private final int mWarning;
|
||||
private final Drawable mGradient;
|
||||
private final TimeInterpolator mInterpolator;
|
||||
|
||||
@@ -135,10 +138,12 @@ public class BarTransitions {
|
||||
mOpaque = 0xff0000ff;
|
||||
mSemiTransparent = 0x7f0000ff;
|
||||
mTransparent = 0x2f0000ff;
|
||||
mWarning = 0xffff0000;
|
||||
} else {
|
||||
mOpaque = res.getColor(R.color.system_bar_background_opaque);
|
||||
mSemiTransparent = res.getColor(R.color.system_bar_background_semi_transparent);
|
||||
mTransparent = res.getColor(R.color.system_bar_background_transparent);
|
||||
mWarning = res.getColor(R.color.system_bar_background_warning);
|
||||
}
|
||||
mGradient = res.getDrawable(gradientResourceId);
|
||||
mInterpolator = new LinearInterpolator();
|
||||
@@ -189,7 +194,9 @@ public class BarTransitions {
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
int targetGradientAlpha = 0, targetColor = 0;
|
||||
if (mMode == MODE_TRANSLUCENT) {
|
||||
if (mMode == MODE_WARNING) {
|
||||
targetColor = mWarning;
|
||||
} else if (mMode == MODE_TRANSLUCENT) {
|
||||
targetColor = mSemiTransparent;
|
||||
} else if (mMode == MODE_SEMI_TRANSPARENT) {
|
||||
targetColor = mSemiTransparent;
|
||||
|
||||
@@ -28,6 +28,8 @@ import static com.android.systemui.statusbar.phone.BarTransitions.MODE_OPAQUE;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_SEMI_TRANSPARENT;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSLUCENT;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_TRANSPARENT;
|
||||
import static com.android.systemui.statusbar.phone.BarTransitions.MODE_WARNING;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.TimeInterpolator;
|
||||
@@ -125,6 +127,7 @@ import com.android.systemui.statusbar.SpeedBumpView;
|
||||
import com.android.systemui.statusbar.StatusBarIconView;
|
||||
import com.android.systemui.statusbar.StatusBarState;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
|
||||
import com.android.systemui.statusbar.policy.BluetoothControllerImpl;
|
||||
import com.android.systemui.statusbar.policy.CastControllerImpl;
|
||||
import com.android.systemui.statusbar.policy.FlashlightController;
|
||||
@@ -705,6 +708,16 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
// Other icons
|
||||
mLocationController = new LocationControllerImpl(mContext); // will post a notification
|
||||
mBatteryController = new BatteryController(mContext);
|
||||
mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() {
|
||||
@Override
|
||||
public void onPowerSaveChanged() {
|
||||
mHandler.post(mCheckBarModes);
|
||||
}
|
||||
@Override
|
||||
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
|
||||
// noop
|
||||
}
|
||||
});
|
||||
mNetworkController = new NetworkControllerImpl(mContext);
|
||||
mHotspotController = new HotspotControllerImpl(mContext);
|
||||
mBluetoothController = new BluetoothControllerImpl(mContext);
|
||||
@@ -2310,7 +2323,12 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
}
|
||||
|
||||
private void checkBarMode(int mode, int windowState, BarTransitions transitions) {
|
||||
final boolean anim = (mScreenOn == null || mScreenOn) && windowState != WINDOW_STATE_HIDDEN;
|
||||
final boolean powerSave = mBatteryController.isPowerSave();
|
||||
final boolean anim = (mScreenOn == null || mScreenOn) && windowState != WINDOW_STATE_HIDDEN
|
||||
&& !powerSave;
|
||||
if (powerSave && getBarState() != StatusBarState.KEYGUARD) {
|
||||
mode = MODE_WARNING;
|
||||
}
|
||||
transitions.transitionTo(mode, anim);
|
||||
}
|
||||
|
||||
@@ -2325,7 +2343,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
@Override
|
||||
public void run() {
|
||||
checkBarModes();
|
||||
}};
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void setInteracting(int barWindow, boolean interacting) {
|
||||
@@ -2644,6 +2663,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
if (mUserSwitcherController != null) {
|
||||
mUserSwitcherController.dump(fd, pw, args);
|
||||
}
|
||||
if (mBatteryController != null) {
|
||||
mBatteryController.dump(fd, pw, args);
|
||||
}
|
||||
}
|
||||
|
||||
private String hunStateToString(Entry entry) {
|
||||
@@ -3111,6 +3133,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
|
||||
int barMode = "opaque".equals(mode) ? MODE_OPAQUE :
|
||||
"translucent".equals(mode) ? MODE_TRANSLUCENT :
|
||||
"semi-transparent".equals(mode) ? MODE_SEMI_TRANSPARENT :
|
||||
"transparent".equals(mode) ? MODE_TRANSPARENT :
|
||||
"warning".equals(mode) ? MODE_WARNING :
|
||||
-1;
|
||||
if (barMode != -1) {
|
||||
boolean animate = true;
|
||||
|
||||
@@ -363,6 +363,11 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPowerSaveChanged() {
|
||||
// could not care less
|
||||
}
|
||||
|
||||
private void updateClickTargets() {
|
||||
setClickable(!mKeyguardShowing || mExpanded);
|
||||
mDateTime.setClickable(mExpanded);
|
||||
|
||||
@@ -16,41 +16,49 @@
|
||||
|
||||
package com.android.systemui.statusbar.policy;
|
||||
|
||||
import com.android.internal.app.IBatteryStats;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.statusbar.phone.StatusBarHeaderView;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.BatteryStats;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.text.format.Formatter;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class BatteryController extends BroadcastReceiver {
|
||||
private static final String TAG = "StatusBar.BatteryController";
|
||||
private static final String TAG = "BatteryController";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private ArrayList<BatteryStateChangeCallback> mChangeCallbacks = new ArrayList<>();
|
||||
private final ArrayList<BatteryStateChangeCallback> mChangeCallbacks = new ArrayList<>();
|
||||
private final PowerManager mPowerManager;
|
||||
|
||||
private int mLevel;
|
||||
private boolean mPluggedIn;
|
||||
private boolean mCharging;
|
||||
private boolean mCharged;
|
||||
|
||||
public interface BatteryStateChangeCallback {
|
||||
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging);
|
||||
}
|
||||
private boolean mPowerSave;
|
||||
|
||||
public BatteryController(Context context) {
|
||||
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
|
||||
context.registerReceiver(this, filter);
|
||||
|
||||
updatePowerSave();
|
||||
}
|
||||
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
pw.println("BatteryController state:");
|
||||
pw.print(" mLevel="); pw.println(mLevel);
|
||||
pw.print(" mPluggedIn="); pw.println(mPluggedIn);
|
||||
pw.print(" mCharging="); pw.println(mCharging);
|
||||
pw.print(" mCharged="); pw.println(mCharged);
|
||||
pw.print(" mPowerSave="); pw.println(mPowerSave);
|
||||
}
|
||||
|
||||
public void addStateChangedCallback(BatteryStateChangeCallback cb) {
|
||||
@@ -75,9 +83,40 @@ public class BatteryController extends BroadcastReceiver {
|
||||
mCharged = status == BatteryManager.BATTERY_STATUS_FULL;
|
||||
mCharging = mCharged || status == BatteryManager.BATTERY_STATUS_CHARGING;
|
||||
|
||||
for (BatteryStateChangeCallback cb : mChangeCallbacks) {
|
||||
cb.onBatteryLevelChanged(mLevel, mPluggedIn, mCharging);
|
||||
}
|
||||
fireBatteryLevelChanged();
|
||||
} else if (action.equals(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)) {
|
||||
updatePowerSave();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPowerSave() {
|
||||
return mPowerSave;
|
||||
}
|
||||
|
||||
private void updatePowerSave() {
|
||||
final boolean powerSave = mPowerManager.isPowerSaveMode();
|
||||
if (powerSave == mPowerSave) return;
|
||||
mPowerSave = powerSave;
|
||||
if (DEBUG) Log.d(TAG, "Power save is " + (mPowerSave ? "on" : "off"));
|
||||
firePowerSaveChanged();
|
||||
}
|
||||
|
||||
private void fireBatteryLevelChanged() {
|
||||
final int N = mChangeCallbacks.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
mChangeCallbacks.get(i).onBatteryLevelChanged(mLevel, mPluggedIn, mCharging);
|
||||
}
|
||||
}
|
||||
|
||||
private void firePowerSaveChanged() {
|
||||
final int N = mChangeCallbacks.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
mChangeCallbacks.get(i).onPowerSaveChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public interface BatteryStateChangeCallback {
|
||||
void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging);
|
||||
void onPowerSaveChanged();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user