Show prediction time when both value are ready

Bug: 215767460
Test: make -j64 RunSettingsRoboTests
Change-Id: I07947b3eca1f656e0dc603f9b9839825dd3149fd
This commit is contained in:
Hugh Chen
2022-02-17 09:10:49 +00:00
parent 01ad893e8c
commit 827910d3c3
2 changed files with 66 additions and 20 deletions

View File

@@ -99,6 +99,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
@VisibleForTesting
boolean mIsRegisterCallback = false;
@VisibleForTesting
boolean mIsLeftDeviceEstimateReady;
@VisibleForTesting
boolean mIsRightDeviceEstimateReady;
@VisibleForTesting
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
new BluetoothAdapter.OnMetadataChangedListener() {
@Override
@@ -226,6 +230,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING,
R.string.bluetooth_right_name,
RIGHT_DEVICE_ID);
showBothDevicesBatteryPredictionIfNecessary();
}
}
}
@@ -365,8 +371,13 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
+ ", ESTIMATE_READY : " + estimateReady
+ ", BATTERY_ESTIMATE : " + batteryEstimate);
}
showBatteryPredictionIfNecessary(estimateReady, batteryEstimate,
linearLayout);
showBatteryPredictionIfNecessary(estimateReady, batteryEstimate, linearLayout);
if (batteryId == LEFT_DEVICE_ID) {
mIsLeftDeviceEstimateReady = estimateReady == 1;
} else if (batteryId == RIGHT_DEVICE_ID) {
mIsRightDeviceEstimateReady = estimateReady == 1;
}
}
} finally {
cursor.close();
@@ -380,7 +391,6 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
ThreadUtils.postOnMainThread(() -> {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
if (estimateReady == 1) {
textView.setVisibility(View.VISIBLE);
textView.setText(
StringUtil.formatElapsedTime(
mContext,
@@ -393,6 +403,24 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
});
}
@VisibleForTesting
void showBothDevicesBatteryPredictionIfNecessary() {
TextView leftDeviceTextView =
mLayoutPreference.findViewById(R.id.layout_left)
.findViewById(R.id.bt_battery_prediction);
TextView rightDeviceTextView =
mLayoutPreference.findViewById(R.id.layout_right)
.findViewById(R.id.bt_battery_prediction);
boolean isBothDevicesEstimateReady =
mIsLeftDeviceEstimateReady && mIsRightDeviceEstimateReady;
int visibility = isBothDevicesEstimateReady ? View.VISIBLE : View.GONE;
ThreadUtils.postOnMainThread(() -> {
leftDeviceTextView.setVisibility(visibility);
rightDeviceTextView.setVisibility(visibility);
});
}
private void showBatteryIcon(LinearLayout linearLayout, int level, int lowBatteryLevel,
boolean charging) {
final boolean enableLowBattery = level <= lowBatteryLevel && !charging;