Sync lastest SettingsLib interface
Test: rebuild Change-Id: I3131f701deb47acae9f19436cbe66e077ea004ee
This commit is contained in:
@@ -102,7 +102,7 @@ public class BatteryBroadcastReceiver extends BroadcastReceiver {
|
|||||||
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
|
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
|
||||||
final String batteryLevel = Utils.getBatteryPercentage(intent);
|
final String batteryLevel = Utils.getBatteryPercentage(intent);
|
||||||
final String batteryStatus = Utils.getBatteryStatus(
|
final String batteryStatus = Utils.getBatteryStatus(
|
||||||
mContext.getResources(), intent);
|
mContext, intent);
|
||||||
if (forceUpdate) {
|
if (forceUpdate) {
|
||||||
mBatteryListener.onBatteryChanged(BatteryUpdateType.MANUAL);
|
mBatteryListener.onBatteryChanged(BatteryUpdateType.MANUAL);
|
||||||
} else if(!batteryLevel.equals(mBatteryLevel)) {
|
} else if(!batteryLevel.equals(mBatteryLevel)) {
|
||||||
|
@@ -133,7 +133,7 @@ public class BatteryInfo {
|
|||||||
remaining = context.getString(R.string.remaining_length_format,
|
remaining = context.getString(R.string.remaining_length_format,
|
||||||
Formatter.formatShortElapsedTime(context, remainingTimeUs / 1000));
|
Formatter.formatShortElapsedTime(context, remainingTimeUs / 1000));
|
||||||
}
|
}
|
||||||
view.setBottomLabels(new CharSequence[] {timeString, remaining});
|
view.setBottomLabels(new CharSequence[]{timeString, remaining});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getBatteryInfo(final Context context, final Callback callback) {
|
public static void getBatteryInfo(final Context context, final Callback callback) {
|
||||||
@@ -232,9 +232,8 @@ public class BatteryInfo {
|
|||||||
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
info.batteryPercentString = Utils.formatPercentage(info.batteryLevel);
|
||||||
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
info.mCharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
|
||||||
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
|
info.averageTimeToDischarge = estimate.getAverageDischargeTime();
|
||||||
final Resources resources = context.getResources();
|
|
||||||
|
|
||||||
info.statusLabel = Utils.getBatteryStatus(resources, batteryBroadcast);
|
info.statusLabel = Utils.getBatteryStatus(context, batteryBroadcast);
|
||||||
if (!info.mCharging) {
|
if (!info.mCharging) {
|
||||||
updateBatteryInfoDischarging(context, shortString, estimate, info);
|
updateBatteryInfoDischarging(context, shortString, estimate, info);
|
||||||
} else {
|
} else {
|
||||||
@@ -261,12 +260,11 @@ public class BatteryInfo {
|
|||||||
R.string.power_remaining_charging_duration_only, timeString);
|
R.string.power_remaining_charging_duration_only, timeString);
|
||||||
info.chargeLabel = context.getString(resId, info.batteryPercentString, timeString);
|
info.chargeLabel = context.getString(resId, info.batteryPercentString, timeString);
|
||||||
} else {
|
} else {
|
||||||
final String chargeStatusLabel = resources.getString(
|
final String chargeStatusLabel = Utils.getBatteryStatus(context, batteryBroadcast);
|
||||||
R.string.battery_info_status_charging_lower);
|
|
||||||
info.remainingLabel = null;
|
info.remainingLabel = null;
|
||||||
info.chargeLabel = info.batteryLevel == 100 ? info.batteryPercentString :
|
info.chargeLabel = info.batteryLevel == 100 ? info.batteryPercentString :
|
||||||
resources.getString(R.string.power_charging, info.batteryPercentString,
|
resources.getString(R.string.power_charging, info.batteryPercentString,
|
||||||
chargeStatusLabel);
|
chargeStatusLabel.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -42,7 +42,6 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@@ -87,7 +86,7 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
assertThat(mBatteryBroadcastReceiver.mBatteryLevel)
|
assertThat(mBatteryBroadcastReceiver.mBatteryLevel)
|
||||||
.isEqualTo(Utils.getBatteryPercentage(mChargingIntent));
|
.isEqualTo(Utils.getBatteryPercentage(mChargingIntent));
|
||||||
assertThat(mBatteryBroadcastReceiver.mBatteryStatus)
|
assertThat(mBatteryBroadcastReceiver.mBatteryStatus)
|
||||||
.isEqualTo(Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
|
.isEqualTo(Utils.getBatteryStatus(mContext, mChargingIntent));
|
||||||
verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_LEVEL);
|
verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_LEVEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
|
public void testOnReceive_batteryDataNotChanged_listenerNotInvoked() {
|
||||||
final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
|
final String batteryLevel = Utils.getBatteryPercentage(mChargingIntent);
|
||||||
final String batteryStatus =
|
final String batteryStatus =
|
||||||
Utils.getBatteryStatus(mContext.getResources(), mChargingIntent);
|
Utils.getBatteryStatus(mContext, mChargingIntent);
|
||||||
mBatteryBroadcastReceiver.mBatteryLevel = batteryLevel;
|
mBatteryBroadcastReceiver.mBatteryLevel = batteryLevel;
|
||||||
mBatteryBroadcastReceiver.mBatteryStatus = batteryStatus;
|
mBatteryBroadcastReceiver.mBatteryStatus = batteryStatus;
|
||||||
|
|
||||||
@@ -136,7 +135,7 @@ public class BatteryBroadcastReceiverTest {
|
|||||||
assertThat(mBatteryBroadcastReceiver.mBatteryLevel)
|
assertThat(mBatteryBroadcastReceiver.mBatteryLevel)
|
||||||
.isEqualTo(Utils.getBatteryPercentage(mChargingIntent));
|
.isEqualTo(Utils.getBatteryPercentage(mChargingIntent));
|
||||||
assertThat(mBatteryBroadcastReceiver.mBatteryStatus)
|
assertThat(mBatteryBroadcastReceiver.mBatteryStatus)
|
||||||
.isEqualTo(Utils.getBatteryStatus(mContext.getResources(), mChargingIntent));
|
.isEqualTo(Utils.getBatteryStatus(mContext, mChargingIntent));
|
||||||
// 2 times because register will force update the battery
|
// 2 times because register will force update the battery
|
||||||
verify(mBatteryListener, times(2)).onBatteryChanged(BatteryUpdateType.MANUAL);
|
verify(mBatteryListener, times(2)).onBatteryChanged(BatteryUpdateType.MANUAL);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user