diff options
Diffstat (limited to 'packages/SystemUI')
16 files changed, 661 insertions, 48 deletions
diff --git a/packages/SystemUI/res/layout/keyguard_status_bar.xml b/packages/SystemUI/res/layout/keyguard_status_bar.xml index 6cca05f..fcd7e62 100644 --- a/packages/SystemUI/res/layout/keyguard_status_bar.xml +++ b/packages/SystemUI/res/layout/keyguard_status_bar.xml @@ -62,6 +62,16 @@ android:visibility="gone" android:textSize="@dimen/battery_level_text_size" android:importantForAccessibility="noHideDescendants"/> + <com.android.systemui.DockBatteryLevelTextView android:id="@+id/dock_battery_level_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_marginStart="@dimen/header_battery_margin_keyguard" + android:paddingEnd="@dimen/battery_level_padding_end" + android:textColor="@color/status_bar_battery_level_text_color" + android:visibility="gone" + android:textSize="@dimen/battery_level_text_size" + android:importantForAccessibility="noHideDescendants"/> </LinearLayout> <com.android.keyguard.CarrierText diff --git a/packages/SystemUI/res/layout/status_bar.xml b/packages/SystemUI/res/layout/status_bar.xml index 3bedf3f..51f7df7 100644 --- a/packages/SystemUI/res/layout/status_bar.xml +++ b/packages/SystemUI/res/layout/status_bar.xml @@ -103,6 +103,15 @@ android:textColor="@color/status_bar_battery_level_text_color" android:textSize="@dimen/battery_level_text_size" /> + <com.android.systemui.BatteryLevelTextView android:id="@+id/dock_battery_level_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_marginStart="@dimen/header_battery_margin_keyguard" + android:textColor="@color/status_bar_battery_level_text_color" + android:textSize="@dimen/battery_level_text_size" + android:visibility="gone"/> + <com.android.systemui.statusbar.policy.Clock android:id="@+id/clock" android:textAppearance="@style/TextAppearance.StatusBar.Clock" diff --git a/packages/SystemUI/res/layout/status_bar_expanded_header.xml b/packages/SystemUI/res/layout/status_bar_expanded_header.xml index 5effca4..a017a2e 100644 --- a/packages/SystemUI/res/layout/status_bar_expanded_header.xml +++ b/packages/SystemUI/res/layout/status_bar_expanded_header.xml @@ -94,6 +94,16 @@ android:textColor="@color/status_bar_battery_level_text_color" android:textSize="@dimen/battery_level_text_size" android:importantForAccessibility="noHideDescendants"/> + <com.android.systemui.DockBatteryLevelTextView android:id="@+id/dock_battery_level_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:layout_marginStart="@dimen/header_battery_margin_expanded" + android:paddingEnd="@dimen/battery_level_padding_end" + android:textColor="@color/status_bar_battery_level_text_color" + android:textSize="@dimen/battery_level_text_size" + android:importantForAccessibility="noHideDescendants" + android:visibility="gone"/> </LinearLayout> <TextView diff --git a/packages/SystemUI/res/layout/system_icons.xml b/packages/SystemUI/res/layout/system_icons.xml index 8d15898..82e0667 100644 --- a/packages/SystemUI/res/layout/system_icons.xml +++ b/packages/SystemUI/res/layout/system_icons.xml @@ -38,4 +38,12 @@ android:layout_width="9.5dp" android:layout_marginBottom="@dimen/battery_margin_bottom" android:layout_marginStart="@dimen/signal_cluster_battery_padding"/> -</LinearLayout>
\ No newline at end of file + + <com.android.systemui.DockBatteryMeterView android:id="@+id/dock_battery" + android:layout_height="14.5dp" + android:layout_width="9.5dp" + android:layout_marginBottom="@dimen/battery_margin_bottom" + android:layout_marginStart="@dimen/signal_cluster_battery_padding" + android:visibility="gone"/> + +</LinearLayout> diff --git a/packages/SystemUI/res/values/cm_arrays.xml b/packages/SystemUI/res/values/cm_arrays.xml index 0664d05..7508a65 100644 --- a/packages/SystemUI/res/values/cm_arrays.xml +++ b/packages/SystemUI/res/values/cm_arrays.xml @@ -101,4 +101,46 @@ <item>@string/accessibility_quick_settings_live_display_changed_night</item> <item>@string/accessibility_quick_settings_live_display_changed_outdoor</item> </string-array> + + <array name="dockbatterymeter_bolt_points" translatable="false"> + <item>129</item><item>0</item> + <item>199</item><item>0</item> + <item>199</item><item>168</item> + <item>240</item><item>168</item> + <item>240</item><item>0</item> + <item>312</item><item>0</item> + <item>312</item><item>168</item> + <item>441</item><item>168</item> + <item>441</item><item>252</item> + <item>312</item><item>400</item> + <item>286</item><item>400</item> + <item>286</item><item>702</item> + <item>157</item><item>702</item> + <item>154</item><item>400</item> + <item>129</item><item>400</item> + <item>0</item><item>251</item> + <item>0</item><item>168</item> + <item>129</item><item>168</item> + </array> + + <array name="dockbatterymeter_inverted_bolt_points" translatable="false"> + <item>0</item><item>154</item> + <item>302</item><item>154</item> + <item>302</item><item>129</item> + <item>451</item><item>0</item> + <item>534</item><item>0</item> + <item>534</item><item>129</item> + <item>702</item><item>129</item> + <item>702</item><item>199</item> + <item>534</item><item>199</item> + <item>534</item><item>265</item> + <item>702</item><item>265</item> + <item>702</item><item>312</item> + <item>534</item><item>312</item> + <item>534</item><item>441</item> + <item>451</item><item>441</item> + <item>302</item><item>312</item> + <item>302</item><item>286</item> + <item>0</item><item>286</item> + </array> </resources> diff --git a/packages/SystemUI/res/values/cm_strings.xml b/packages/SystemUI/res/values/cm_strings.xml index 5cbca44..200a236 100644 --- a/packages/SystemUI/res/values/cm_strings.xml +++ b/packages/SystemUI/res/values/cm_strings.xml @@ -261,4 +261,7 @@ <!-- CellularTile data sim not configured state string --> <string name="data_sim_not_configured">No data SIM</string> + + <!-- Content description of the dock battery level icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] --> + <string name="accessibility_dock_battery_level">Dock battery <xliff:g id="number">%d</xliff:g> percent.</string> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java b/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java index 4717a0b..247e965 100644 --- a/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java @@ -17,6 +17,7 @@ package com.android.systemui; import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.statusbar.policy.BatteryStateRegistar; import android.content.Context; import android.content.res.Configuration; @@ -28,7 +29,10 @@ import java.text.NumberFormat; public class BatteryLevelTextView extends TextView implements BatteryController.BatteryStateChangeCallback{ - private BatteryController mBatteryController; + + private BatteryStateRegistar mBatteryStateRegistar; + private boolean mBatteryPresent; + private boolean mBatteryCharging; private boolean mForceShow; private boolean mAttached; @@ -38,7 +42,9 @@ public class BatteryLevelTextView extends TextView implements public BatteryLevelTextView(Context context, AttributeSet attrs) { super(context, attrs); - mRequestedVisibility = getVisibility(); + // setBatteryStateRegistar (if called) will made the view visible and ready to be hidden + // if the view shouldn't be displayed. Otherwise this view should be hidden from start. + mRequestedVisibility = GONE; } public void setForceShown(boolean forceShow) { @@ -46,10 +52,11 @@ public class BatteryLevelTextView extends TextView implements updateVisibility(); } - public void setBatteryController(BatteryController batteryController) { - mBatteryController = batteryController; + public void setBatteryStateRegistar(BatteryStateRegistar batteryStateRegistar) { + mRequestedVisibility = VISIBLE; + mBatteryStateRegistar = batteryStateRegistar; if (mAttached) { - mBatteryController.addStateChangedCallback(this); + mBatteryStateRegistar.addStateChangedCallback(this); } } @@ -69,10 +76,12 @@ public class BatteryLevelTextView extends TextView implements } @Override - public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { + public void onBatteryLevelChanged(boolean present, int level, boolean pluggedIn, + boolean charging) { String percentage = NumberFormat.getPercentInstance().format((double) level / 100.0); setText(percentage); - if (mBatteryCharging != charging) { + if (mBatteryPresent != present || mBatteryCharging != charging) { + mBatteryPresent = present; mBatteryCharging = charging; updateVisibility(); } @@ -94,8 +103,8 @@ public class BatteryLevelTextView extends TextView implements public void onAttachedToWindow() { super.onAttachedToWindow(); - if (mBatteryController != null) { - mBatteryController.addStateChangedCallback(this); + if (mBatteryStateRegistar != null) { + mBatteryStateRegistar.addStateChangedCallback(this); } mAttached = true; @@ -106,21 +115,22 @@ public class BatteryLevelTextView extends TextView implements super.onDetachedFromWindow(); mAttached = false; - if (mBatteryController != null) { - mBatteryController.removeStateChangedCallback(this); + if (mBatteryStateRegistar != null) { + mBatteryStateRegistar.removeStateChangedCallback(this); } } private void updateVisibility() { - boolean showNextPercent = mPercentMode == BatteryController.PERCENTAGE_MODE_OUTSIDE - || (mBatteryCharging && mPercentMode == BatteryController.PERCENTAGE_MODE_INSIDE); + boolean showNextPercent = mBatteryPresent && ( + mPercentMode == BatteryController.PERCENTAGE_MODE_OUTSIDE + || (mBatteryCharging && mPercentMode == BatteryController.PERCENTAGE_MODE_INSIDE)); if (mStyle == BatteryController.STYLE_GONE) { showNextPercent = false; } else if (mStyle == BatteryController.STYLE_TEXT) { showNextPercent = true; } - if (showNextPercent || mForceShow) { + if (mBatteryStateRegistar != null && (showNextPercent || mForceShow)) { super.setVisibility(mRequestedVisibility); } else { super.setVisibility(GONE); diff --git a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java index 244b7f7..e606156 100755 --- a/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryMeterView.java @@ -17,6 +17,7 @@ package com.android.systemui; import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.statusbar.policy.BatteryStateRegistar; import android.animation.ArgbEvaluator; import android.content.BroadcastReceiver; @@ -73,6 +74,7 @@ public class BatteryMeterView extends View implements DemoMode, private final Path mClipPath = new Path(); private final Path mTextPath = new Path(); + private BatteryStateRegistar mBatteryStateRegistar; private BatteryController mBatteryController; private boolean mPowerSaveEnabled; @@ -92,7 +94,7 @@ public class BatteryMeterView extends View implements DemoMode, private BatteryMeterDrawable mBatteryMeterDrawable; private int mIconTint = Color.WHITE; - private class BatteryTracker extends BroadcastReceiver { + protected class BatteryTracker extends BroadcastReceiver { public static final int UNKNOWN_LEVEL = -1; // current battery status @@ -128,7 +130,6 @@ public class BatteryMeterView extends View implements DemoMode, technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY); voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0); temperature = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, 0); - setContentDescription( context.getString(R.string.accessibility_battery_level, level)); if (mBatteryMeterDrawable != null) { @@ -193,7 +194,9 @@ public class BatteryMeterView extends View implements DemoMode, // preload the battery level mTracker.onReceive(getContext(), sticky); } - mBatteryController.addStateChangedCallback(this); + if (mBatteryStateRegistar != null) { + mBatteryStateRegistar.addStateChangedCallback(this); + } mAttached = true; } @@ -203,7 +206,9 @@ public class BatteryMeterView extends View implements DemoMode, mAttached = false; getContext().unregisterReceiver(mTracker); - mBatteryController.removeStateChangedCallback(this); + if (mBatteryStateRegistar != null) { + mBatteryStateRegistar.removeStateChangedCallback(this); + } } public BatteryMeterView(Context context) { @@ -279,20 +284,28 @@ public class BatteryMeterView extends View implements DemoMode, width = height; } else if (mMeterMode == BatteryMeterMode.BATTERY_METER_TEXT) { onSizeChanged(width, height, 0, 0); // Force a size changed event - } else if (mMeterMode.compareTo(BatteryMeterMode.BATTERY_METER_ICON_LANDSCAPE) == 0) { + } else if (mMeterMode == BatteryMeterMode.BATTERY_METER_ICON_LANDSCAPE) { width = (int)(height * 1.2f); } setMeasuredDimension(width, height); } + public void setBatteryStateRegistar(BatteryStateRegistar batteryStateRegistar) { + mBatteryStateRegistar = batteryStateRegistar; + if (!mAttached) { + mBatteryStateRegistar.addStateChangedCallback(this); + } + } + public void setBatteryController(BatteryController batteryController) { mBatteryController = batteryController; mPowerSaveEnabled = mBatteryController.isPowerSave(); } @Override - public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { + public void onBatteryLevelChanged(boolean present, int level, boolean pluggedIn, + boolean charging) { // TODO: Use this callback instead of own broadcast receiver. } @@ -742,9 +755,7 @@ public class BatteryMeterView extends View implements DemoMode, } private float[] loadBoltPoints(Resources res) { - final int[] pts = res.getIntArray((mHorizontal - ? R.array.batterymeter_inverted_bolt_points - : R.array.batterymeter_bolt_points)); + final int[] pts = res.getIntArray(getBoltPointsArrayResource()); int maxX = 0, maxY = 0; for (int i = 0; i < pts.length; i += 2) { maxX = Math.max(maxX, pts[i]); @@ -757,6 +768,12 @@ public class BatteryMeterView extends View implements DemoMode, } return ptsF; } + + protected int getBoltPointsArrayResource() { + return mHorizontal + ? R.array.batterymeter_inverted_bolt_points + : R.array.batterymeter_bolt_points; + } } protected class CircleBatteryMeterDrawable implements BatteryMeterDrawable { @@ -858,7 +875,7 @@ public class BatteryMeterView extends View implements DemoMode, } private float[] loadBoltPoints(Resources res) { - final int[] pts = res.getIntArray(R.array.batterymeter_bolt_points); + final int[] pts = res.getIntArray(getBoltPointsArrayResource()); int maxX = 0, maxY = 0; for (int i = 0; i < pts.length; i += 2) { maxX = Math.max(maxX, pts[i]); @@ -872,6 +889,10 @@ public class BatteryMeterView extends View implements DemoMode, return ptsF; } + protected int getBoltPointsArrayResource() { + return R.array.batterymeter_bolt_points; + } + private void drawCircle(Canvas canvas, BatteryTracker tracker, float textX, RectF drawRect) { boolean unknownStatus = tracker.status == BatteryManager.BATTERY_STATUS_UNKNOWN; diff --git a/packages/SystemUI/src/com/android/systemui/DockBatteryLevelTextView.java b/packages/SystemUI/src/com/android/systemui/DockBatteryLevelTextView.java new file mode 100644 index 0000000..1678e94 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/DockBatteryLevelTextView.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui; + +import android.content.Context; +import android.graphics.Paint; +import android.util.AttributeSet; + +public class DockBatteryLevelTextView extends BatteryLevelTextView { + + public DockBatteryLevelTextView(Context context, AttributeSet attrs) { + super(context, attrs); + setPaintFlags(getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + } + +} diff --git a/packages/SystemUI/src/com/android/systemui/DockBatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/DockBatteryMeterView.java new file mode 100755 index 0000000..b80e6d0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/DockBatteryMeterView.java @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui; + +import android.content.Context; +import android.content.Intent; +import android.content.res.Resources; +import android.os.BatteryManager; +import android.util.AttributeSet; +import android.view.View; + +public class DockBatteryMeterView extends BatteryMeterView { + + private BatteryManager mBatteryService; + private final boolean mSupported; + + private class DockBatteryTracker extends BatteryTracker { + + public DockBatteryTracker() { + super(); + present = false; + } + + @Override + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { + if (testmode && ! intent.getBooleanExtra("testmode", false)) return; + + if (mSupported) { + level = (int)(100f + * intent.getIntExtra(BatteryManager.EXTRA_DOCK_LEVEL, 0) + / intent.getIntExtra(BatteryManager.EXTRA_DOCK_SCALE, 100)); + + present = intent.getBooleanExtra(BatteryManager.EXTRA_DOCK_PRESENT, false); + plugType = intent.getIntExtra(BatteryManager.EXTRA_DOCK_PLUGGED, 0); + // We need to add a extra check over the status because of dock batteries + // PlugType doesn't means that the dock battery is charging (some devices + // doesn't charge under dock usb) + plugged = plugType != 0 && (status == BatteryManager.BATTERY_STATUS_CHARGING || + status == BatteryManager.BATTERY_STATUS_FULL); + health = intent.getIntExtra(BatteryManager.EXTRA_DOCK_HEALTH, + BatteryManager.BATTERY_HEALTH_UNKNOWN); + status = intent.getIntExtra(BatteryManager.EXTRA_DOCK_STATUS, + BatteryManager.BATTERY_STATUS_UNKNOWN); + technology = intent.getStringExtra(BatteryManager.EXTRA_DOCK_TECHNOLOGY); + voltage = intent.getIntExtra(BatteryManager.EXTRA_DOCK_VOLTAGE, 0); + temperature = intent.getIntExtra(BatteryManager.EXTRA_DOCK_TEMPERATURE, 0); + + + if (present && (mMeterMode != BatteryMeterMode.BATTERY_METER_GONE && + mMeterMode != BatteryMeterMode.BATTERY_METER_TEXT)) { + setContentDescription(context.getString( + R.string.accessibility_dock_battery_level, level)); + setVisibility(View.VISIBLE); + invalidate(); + } else { + setContentDescription(null); + setVisibility(View.GONE); + } + } else { + setContentDescription(null); + setVisibility(View.GONE); + + // If dock is not supported then we don't need this receiver anymore + getContext().unregisterReceiver(this); + } + } else if (action.equals(ACTION_LEVEL_TEST)) { + testmode = true; + post(new Runnable() { + int curLevel = 0; + int incr = 1; + int saveLevel = level; + int savePlugged = plugType; + Intent dummy = new Intent(Intent.ACTION_BATTERY_CHANGED); + @Override + public void run() { + if (curLevel < 0) { + testmode = false; + dummy.putExtra("level", saveLevel); + dummy.putExtra("plugged", savePlugged); + dummy.putExtra("testmode", false); + } else { + dummy.putExtra("level", curLevel); + dummy.putExtra("plugged", incr > 0 + ? BatteryManager.BATTERY_DOCK_PLUGGED_AC : 0); + dummy.putExtra("testmode", true); + } + getContext().sendBroadcast(dummy); + + if (!testmode) return; + + curLevel += incr; + if (curLevel == 100) { + incr *= -1; + } + postDelayed(this, 200); + } + }); + } + } + } + + public DockBatteryMeterView(Context context) { + this(context, null, 0); + } + + public DockBatteryMeterView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public DockBatteryMeterView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + mBatteryService = ((BatteryManager) context.getSystemService(Context.BATTERY_SERVICE)); + mSupported = mBatteryService.isDockBatterySupported(); + mDemoTracker = new DockBatteryTracker(); + mTracker = new DockBatteryTracker(); + } + + @Override + public void onDetachedFromWindow() { + // We already unregistered the listener once when we decided + // support was absent. Don't do it again. + if (mSupported) { + super.onDetachedFromWindow(); + } + } + + @Override + public void setMode(BatteryMeterMode mode) { + super.setMode(mode); + int visibility = getVisibility(); + if (visibility == View.VISIBLE && !mSupported) { + setVisibility(View.GONE); + } + } + + @Override + protected BatteryMeterDrawable createBatteryMeterDrawable(BatteryMeterMode mode) { + Resources res = mContext.getResources(); + switch (mode) { + case BATTERY_METER_CIRCLE: + return new DockCircleBatteryMeterDrawable(res); + case BATTERY_METER_ICON_LANDSCAPE: + return new DockNormalBatteryMeterDrawable(res, true); + case BATTERY_METER_TEXT: + case BATTERY_METER_GONE: + return null; + default: + return new DockNormalBatteryMeterDrawable(res, false); + } + } + + protected class DockNormalBatteryMeterDrawable extends NormalBatteryMeterDrawable { + + public DockNormalBatteryMeterDrawable(Resources res, boolean horizontal) { + super(res, horizontal); + } + + @Override + protected int getBoltPointsArrayResource() { + return mHorizontal + ? R.array.dockbatterymeter_inverted_bolt_points + : R.array.dockbatterymeter_bolt_points; + } + } + + protected class DockCircleBatteryMeterDrawable extends CircleBatteryMeterDrawable { + public DockCircleBatteryMeterDrawable(Resources res) { + super(res); + } + + @Override + protected int getBoltPointsArrayResource() { + return R.array.dockbatterymeter_bolt_points; + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java index 7524732..ec307de 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2014 The Android Open Source Project - * + * Copyright (C) 2016 The CyanogenMod Project * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -31,8 +31,10 @@ import android.widget.TextView; import com.android.systemui.BatteryLevelTextView; import com.android.systemui.BatteryMeterView; +import com.android.systemui.DockBatteryMeterView; import com.android.systemui.R; import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.statusbar.policy.DockBatteryController; import com.android.systemui.statusbar.policy.KeyguardUserSwitcher; import com.android.systemui.statusbar.policy.UserInfoController; import com.android.systemui.statusbar.policy.UserSwitcherController; @@ -49,8 +51,8 @@ public class KeyguardStatusBarView extends RelativeLayout { private MultiUserSwitch mMultiUserSwitch; private ImageView mMultiUserAvatar; private BatteryLevelTextView mBatteryLevel; + private BatteryLevelTextView mDockBatteryLevel; - private BatteryController mBatteryController; private KeyguardUserSwitcher mKeyguardUserSwitcher; private int mSystemIconsSwitcherHiddenExpandedMargin; @@ -69,6 +71,7 @@ public class KeyguardStatusBarView extends RelativeLayout { mMultiUserSwitch = (MultiUserSwitch) findViewById(R.id.multi_user_switch); mMultiUserAvatar = (ImageView) findViewById(R.id.multi_user_avatar); mBatteryLevel = (BatteryLevelTextView) findViewById(R.id.battery_level_text); + mDockBatteryLevel = (BatteryLevelTextView) findViewById(R.id.dock_battery_level_text); mCarrierLabel = (TextView) findViewById(R.id.keyguard_carrier_text); loadDimens(); mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(getContext(), @@ -110,6 +113,9 @@ public class KeyguardStatusBarView extends RelativeLayout { removeView(mMultiUserSwitch); } mBatteryLevel.setVisibility(View.VISIBLE); + if (mDockBatteryLevel != null) { + mDockBatteryLevel.setVisibility(View.VISIBLE); + } } private void updateSystemIconsLayoutParams() { @@ -130,9 +136,26 @@ public class KeyguardStatusBarView extends RelativeLayout { } public void setBatteryController(BatteryController batteryController) { - mBatteryController = batteryController; - ((BatteryMeterView) findViewById(R.id.battery)).setBatteryController(batteryController); - mBatteryLevel.setBatteryController(batteryController); + BatteryMeterView v = ((BatteryMeterView) findViewById(R.id.battery)); + v.setBatteryStateRegistar(batteryController); + v.setBatteryController(batteryController); + mBatteryLevel.setBatteryStateRegistar(batteryController); + } + + public void setDockBatteryController(DockBatteryController dockBatteryController) { + DockBatteryMeterView v = ((DockBatteryMeterView) findViewById(R.id.dock_battery)); + if (dockBatteryController != null) { + v.setBatteryStateRegistar(dockBatteryController); + mDockBatteryLevel.setBatteryStateRegistar(dockBatteryController); + } else { + if (v != null ) { + removeView(v); + } + if (mDockBatteryLevel != null) { + removeView(mDockBatteryLevel); + mDockBatteryLevel = null; + } + } } public void setUserSwitcherController(UserSwitcherController controller) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index a64f6d8..c5e74a5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -64,6 +64,7 @@ import android.media.session.MediaSession; import android.media.session.MediaSessionManager; import android.media.session.PlaybackState; import android.os.AsyncTask; +import android.os.BatteryManager; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; @@ -124,6 +125,7 @@ import com.android.keyguard.ViewMediatorCallback; import com.android.systemui.BatteryMeterView; import com.android.systemui.BatteryLevelTextView; import com.android.systemui.DemoMode; +import com.android.systemui.DockBatteryMeterView; import com.android.systemui.EventLogConstants; import com.android.systemui.EventLogTags; import com.android.systemui.Prefs; @@ -160,10 +162,11 @@ import com.android.systemui.statusbar.VisualizerView; import com.android.systemui.statusbar.phone.UnlockMethodCache.OnUnlockMethodChangedListener; import com.android.systemui.statusbar.policy.AccessibilityController; import com.android.systemui.statusbar.policy.BatteryController; -import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; +import com.android.systemui.statusbar.policy.BatteryStateRegistar.BatteryStateChangeCallback; import com.android.systemui.statusbar.policy.BluetoothControllerImpl; import com.android.systemui.statusbar.policy.BrightnessMirrorController; import com.android.systemui.statusbar.policy.CastControllerImpl; +import com.android.systemui.statusbar.policy.DockBatteryController; import com.android.systemui.statusbar.policy.FlashlightController; import com.android.systemui.statusbar.policy.HeadsUpManager; import com.android.systemui.statusbar.policy.HotspotControllerImpl; @@ -297,7 +300,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, // These are no longer handled by the policy, because we need custom strategies for them BluetoothControllerImpl mBluetoothController; SecurityControllerImpl mSecurityController; + BatteryManager mBatteryManager; BatteryController mBatteryController; + DockBatteryController mDockBatteryController; LocationControllerImpl mLocationController; NetworkControllerImpl mNetworkController; HotspotControllerImpl mHotspotController; @@ -1052,6 +1057,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mLocationController = new LocationControllerImpl(mContext, mHandlerThread.getLooper()); // will post a notification } + if (mBatteryManager == null) { + mBatteryManager = (BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE); + } if (mBatteryController == null) { mBatteryController = new BatteryController(mContext, mHandler); mBatteryController.addStateChangedCallback(new BatteryStateChangeCallback() { @@ -1064,7 +1072,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } @Override - public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { + public void onBatteryLevelChanged(boolean present, int level, + boolean pluggedIn, boolean charging) { // noop } @@ -1074,6 +1083,11 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } }); } + if (mBatteryManager.isDockBatterySupported()) { + if (mDockBatteryController == null) { + mDockBatteryController = new DockBatteryController(mContext, mHandler); + } + } if (mNetworkController == null) { mNetworkController = new NetworkControllerImpl(mContext, mHandlerThread.getLooper()); } @@ -1271,13 +1285,36 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mUserInfoController.reloadUserInfo(); mHeader.setBatteryController(mBatteryController); + BatteryMeterView batteryMeterView = ((BatteryMeterView) mStatusBarView.findViewById(R.id.battery)); + batteryMeterView.setBatteryStateRegistar(mBatteryController); batteryMeterView.setBatteryController(mBatteryController); batteryMeterView.setAnimationsEnabled(false); ((BatteryLevelTextView) mStatusBarView.findViewById(R.id.battery_level_text)) - .setBatteryController(mBatteryController); + .setBatteryStateRegistar(mBatteryController); mKeyguardStatusBar.setBatteryController(mBatteryController); + mHeader.setDockBatteryController(mDockBatteryController); + mKeyguardStatusBar.setDockBatteryController(mDockBatteryController); + if (mDockBatteryController != null) { + DockBatteryMeterView dockBatteryMeterView = + ((DockBatteryMeterView) mStatusBarView.findViewById(R.id.dock_battery)); + dockBatteryMeterView.setBatteryStateRegistar(mDockBatteryController); + ((BatteryLevelTextView) mStatusBarView.findViewById(R.id.dock_battery_level_text)) + .setBatteryStateRegistar(mDockBatteryController); + } else { + DockBatteryMeterView dockBatteryMeterView = + (DockBatteryMeterView) mStatusBarView.findViewById(R.id.dock_battery); + if (dockBatteryMeterView != null) { + mStatusBarView.removeView(dockBatteryMeterView); + } + BatteryLevelTextView dockBatteryLevel = + (BatteryLevelTextView) mStatusBarView.findViewById(R.id.dock_battery_level_text); + if (dockBatteryLevel != null) { + mStatusBarView.removeView(dockBatteryLevel); + } + } + mVisualizerView.setKeyguardMonitor(mKeyguardMonitor); mHeader.setNextAlarmController(mNextAlarmController); mHeader.setWeatherController(mWeatherController); @@ -3348,6 +3385,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (mBatteryController != null) { mBatteryController.dump(fd, pw, args); } + if (mDockBatteryController != null) { + mDockBatteryController.dump(fd, pw, args); + } if (mNextAlarmController != null) { mNextAlarmController.dump(fd, pw, args); } @@ -3657,6 +3697,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (mBatteryController != null) { mBatteryController.setUserId(mCurrentUserId); } + if (mDockBatteryController != null) { + mDockBatteryController.setUserId(mCurrentUserId); + } } private void resetUserSetupObserver() { @@ -4184,6 +4227,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } if (modeChange || command.equals(COMMAND_BATTERY)) { dispatchDemoCommandToView(command, args, R.id.battery); + dispatchDemoCommandToView(command, args, R.id.dock_battery); } if (modeChange || command.equals(COMMAND_STATUS)) { mIconController.dispatchDemoCommand(command, args); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java index 27c8a4d..339d469 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java @@ -17,9 +17,7 @@ package com.android.systemui.statusbar.phone; import android.app.ActivityManager; -import android.app.ActivityManagerNative; import android.app.AlarmManager; -import android.app.IUserSwitchObserver; import android.app.PendingIntent; import android.content.ContentUris; import android.content.ContentResolver; @@ -58,6 +56,7 @@ import android.widget.Toast; import com.android.keyguard.KeyguardStatusView; import com.android.systemui.BatteryLevelTextView; import com.android.systemui.BatteryMeterView; +import com.android.systemui.DockBatteryMeterView; import com.android.systemui.FontSizeUtils; import com.android.systemui.R; import com.android.systemui.cm.UserContentObserver; @@ -65,6 +64,7 @@ import com.android.systemui.qs.QSDragPanel; import com.android.systemui.qs.QSPanel; import com.android.systemui.qs.QSTile; import com.android.systemui.statusbar.policy.BatteryController; +import com.android.systemui.statusbar.policy.DockBatteryController; import com.android.systemui.statusbar.policy.NetworkControllerImpl.EmergencyListener; import com.android.systemui.statusbar.policy.NextAlarmController; import com.android.systemui.statusbar.policy.UserInfoController; @@ -108,6 +108,7 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL private ImageView mQsDetailHeaderProgress; private TextView mEmergencyCallsOnly; private BatteryLevelTextView mBatteryLevel; + private BatteryLevelTextView mDockBatteryLevel; private TextView mAlarmStatus; private TextView mWeatherLine1, mWeatherLine2; private TextView mEditTileDoneText; @@ -138,7 +139,6 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL private float mAvatarCollapsedScaleFactor; private ActivityStarter mActivityStarter; - private BatteryController mBatteryController; private NextAlarmController mNextAlarmController; private WeatherController mWeatherController; private QSDragPanel mQSPanel; @@ -193,6 +193,7 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL mQsDetailHeaderProgress = (ImageView) findViewById(R.id.qs_detail_header_progress); mEmergencyCallsOnly = (TextView) findViewById(R.id.header_emergency_calls_only); mBatteryLevel = (BatteryLevelTextView) findViewById(R.id.battery_level_text); + mDockBatteryLevel = (BatteryLevelTextView) findViewById(R.id.dock_battery_level_text); mAlarmStatus = (TextView) findViewById(R.id.alarm_status); mAlarmStatus.setOnClickListener(this); mSignalCluster = findViewById(R.id.signal_cluster); @@ -340,9 +341,26 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL } public void setBatteryController(BatteryController batteryController) { - mBatteryController = batteryController; - ((BatteryMeterView) findViewById(R.id.battery)).setBatteryController(batteryController); - mBatteryLevel.setBatteryController(batteryController); + BatteryMeterView v = ((BatteryMeterView) findViewById(R.id.battery)); + v.setBatteryStateRegistar(batteryController); + v.setBatteryController(batteryController); + mBatteryLevel.setBatteryStateRegistar(batteryController); + } + + public void setDockBatteryController(DockBatteryController dockBatteryController) { + DockBatteryMeterView v = ((DockBatteryMeterView) findViewById(R.id.dock_battery)); + if (dockBatteryController != null) { + v.setBatteryStateRegistar(dockBatteryController); + mDockBatteryLevel.setBatteryStateRegistar(dockBatteryController); + } else { + if (v != null) { + removeView(v); + } + if (mDockBatteryLevel != null) { + removeView(mDockBatteryLevel); + mDockBatteryLevel = null; + } + } } public void setNextAlarmController(NextAlarmController nextAlarmController) { @@ -414,6 +432,10 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL mEmergencyCallsOnly.setVisibility(mExpanded && mShowEmergencyCallsOnly ? VISIBLE : GONE); mBatteryLevel.setForceShown(mExpanded && mShowBatteryTextExpanded); mBatteryLevel.setVisibility(View.VISIBLE); + if (mDockBatteryLevel != null) { + mDockBatteryLevel.setForceShown(mExpanded && mShowBatteryTextExpanded); + mDockBatteryLevel.setVisibility(View.VISIBLE); + } } private void updateSignalClusterDetachment() { @@ -763,6 +785,9 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL applyAlpha(mDateCollapsed, values.dateCollapsedAlpha); applyAlpha(mDateExpanded, values.dateExpandedAlpha); applyAlpha(mBatteryLevel, values.batteryLevelAlpha); + if (mDockBatteryLevel != null) { + applyAlpha(mDockBatteryLevel, values.batteryLevelAlpha); + } applyAlpha(mSettingsContainer, values.settingsAlpha); applyAlpha(mWeatherLine1, values.settingsAlpha); applyAlpha(mWeatherLine2, values.settingsAlpha); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java index a154544..c59a0d8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java @@ -34,7 +34,7 @@ import java.util.ArrayList; import cyanogenmod.providers.CMSettings; -public class BatteryController extends BroadcastReceiver { +public class BatteryController extends BroadcastReceiver implements BatteryStateRegistar { private static final String TAG = "BatteryController"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); @@ -52,6 +52,7 @@ public class BatteryController extends BroadcastReceiver { private final PowerManager mPowerManager; private int mLevel; + private boolean mPresent; private boolean mPluggedIn; private boolean mCharging; private boolean mCharged; @@ -85,18 +86,21 @@ public class BatteryController extends BroadcastReceiver { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("BatteryController state:"); pw.print(" mLevel="); pw.println(mLevel); + pw.print(" mPresent="); pw.println(mPresent); pw.print(" mPluggedIn="); pw.println(mPluggedIn); pw.print(" mCharging="); pw.println(mCharging); pw.print(" mCharged="); pw.println(mCharged); pw.print(" mPowerSave="); pw.println(mPowerSave); } + @Override public void addStateChangedCallback(BatteryStateChangeCallback cb) { mChangeCallbacks.add(cb); - cb.onBatteryLevelChanged(mLevel, mPluggedIn, mCharging); + cb.onBatteryLevelChanged(mPresent, mLevel, mPluggedIn, mCharging); cb.onBatteryStyleChanged(mStyle, mPercentMode); } + @Override public void removeStateChangedCallback(BatteryStateChangeCallback cb) { mChangeCallbacks.remove(cb); } @@ -107,6 +111,7 @@ public class BatteryController extends BroadcastReceiver { mLevel = (int)(100f * intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100)); + mPresent = intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false); mPluggedIn = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0; final int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, @@ -140,7 +145,7 @@ public class BatteryController extends BroadcastReceiver { private void fireBatteryLevelChanged() { final int N = mChangeCallbacks.size(); for (int i = 0; i < N; i++) { - mChangeCallbacks.get(i).onBatteryLevelChanged(mLevel, mPluggedIn, mCharging); + mChangeCallbacks.get(i).onBatteryLevelChanged(mPresent, mLevel, mPluggedIn, mCharging); } } @@ -158,12 +163,6 @@ public class BatteryController extends BroadcastReceiver { } } - public interface BatteryStateChangeCallback { - void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging); - void onPowerSaveChanged(); - void onBatteryStyleChanged(int style, int percentMode); - } - private final class SettingsObserver extends ContentObserver { private ContentResolver mResolver; private boolean mRegistered; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryStateRegistar.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryStateRegistar.java new file mode 100644 index 0000000..9fe9bb4 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryStateRegistar.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +public interface BatteryStateRegistar { + interface BatteryStateChangeCallback { + void onBatteryLevelChanged(boolean present, int level, boolean pluggedIn, boolean charging); + void onPowerSaveChanged(); + void onBatteryStyleChanged(int style, int percentMode); + } + + public void addStateChangedCallback(BatteryStateChangeCallback cb); + public void removeStateChangedCallback(BatteryStateChangeCallback cb); +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DockBatteryController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DockBatteryController.java new file mode 100644 index 0000000..3faf7d0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DockBatteryController.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.statusbar.policy; + +import android.content.BroadcastReceiver; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.database.ContentObserver; +import android.net.Uri; +import android.os.BatteryManager; +import android.os.Handler; +import android.provider.Settings; + +import java.io.FileDescriptor; +import java.io.PrintWriter; +import java.util.ArrayList; + +import cyanogenmod.providers.CMSettings; + +public class DockBatteryController extends BroadcastReceiver implements BatteryStateRegistar { + + private final ArrayList<BatteryStateChangeCallback> mChangeCallbacks = new ArrayList<>(); + + private int mLevel; + private boolean mPresent; + private boolean mPluggedIn; + private boolean mCharging; + private boolean mCharged; + private boolean mPowerSave; + + private int mStyle; + private int mPercentMode; + private int mUserId; + private SettingsObserver mObserver; + + public DockBatteryController(Context context, Handler handler) { + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_BATTERY_CHANGED); + context.registerReceiver(this, filter); + + mObserver = new SettingsObserver(context, handler); + mObserver.observe(); + } + + public void setUserId(int userId) { + mUserId = userId; + mObserver.observe(); + } + + public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { + pw.println("BatteryController state:"); + pw.print(" mLevel="); pw.println(mLevel); + pw.print(" mPresent="); pw.println(mPresent); + pw.print(" mPluggedIn="); pw.println(mPluggedIn); + pw.print(" mCharging="); pw.println(mCharging); + pw.print(" mCharged="); pw.println(mCharged); + pw.print(" mPowerSave="); pw.println(mPowerSave); + } + + @Override + public void addStateChangedCallback(BatteryStateChangeCallback cb) { + mChangeCallbacks.add(cb); + cb.onBatteryLevelChanged(mPresent, mLevel, mPluggedIn, mCharging); + cb.onBatteryStyleChanged(mStyle, mPercentMode); + } + + @Override + public void removeStateChangedCallback(BatteryStateChangeCallback cb) { + mChangeCallbacks.remove(cb); + } + + public void onReceive(Context context, Intent intent) { + final String action = intent.getAction(); + if (action.equals(Intent.ACTION_BATTERY_CHANGED)) { + mLevel = (int)(100f + * intent.getIntExtra(BatteryManager.EXTRA_DOCK_LEVEL, 0) + / intent.getIntExtra(BatteryManager.EXTRA_DOCK_SCALE, 100)); + mPresent = intent.getBooleanExtra(BatteryManager.EXTRA_DOCK_PRESENT, false); + mPluggedIn = intent.getIntExtra(BatteryManager.EXTRA_DOCK_PLUGGED, 0) != 0; + + final int status = intent.getIntExtra(BatteryManager.EXTRA_DOCK_STATUS, + BatteryManager.BATTERY_STATUS_UNKNOWN); + mCharged = status == BatteryManager.BATTERY_STATUS_FULL; + mCharging = mPluggedIn && (mCharged || status == BatteryManager.BATTERY_STATUS_CHARGING); + + fireBatteryLevelChanged(); + } + } + + private void fireBatteryLevelChanged() { + final int N = mChangeCallbacks.size(); + for (int i = 0; i < N; i++) { + mChangeCallbacks.get(i).onBatteryLevelChanged(mPresent, mLevel, mPresent, mCharging); + } + } + + private void fireSettingsChanged() { + final int N = mChangeCallbacks.size(); + for (int i = 0; i < N; i++) { + mChangeCallbacks.get(i).onBatteryStyleChanged(mStyle, mPercentMode); + } + } + + private final class SettingsObserver extends ContentObserver { + private ContentResolver mResolver; + private boolean mRegistered; + + private final Uri STYLE_URI = + CMSettings.System.getUriFor(CMSettings.System.STATUS_BAR_BATTERY_STYLE); + private final Uri PERCENT_URI = + CMSettings.System.getUriFor(CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT); + + public SettingsObserver(Context context, Handler handler) { + super(handler); + mResolver = context.getContentResolver(); + } + + public void observe() { + if (mRegistered) { + mResolver.unregisterContentObserver(this); + } + mResolver.registerContentObserver(STYLE_URI, false, this, mUserId); + mResolver.registerContentObserver(PERCENT_URI, false, this, mUserId); + mRegistered = true; + + update(); + } + + @Override + public void onChange(boolean selfChange, Uri uri) { + update(); + } + + private void update() { + mStyle = CMSettings.System.getIntForUser(mResolver, + CMSettings.System.STATUS_BAR_BATTERY_STYLE, 0, mUserId); + mPercentMode = CMSettings.System.getIntForUser(mResolver, + CMSettings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, mUserId); + + fireSettingsChanged(); + } + }; +} |