Show prediction time when both value are ready
Bug: 215767460 Test: make -j64 RunSettingsRoboTests Change-Id: I07947b3eca1f656e0dc603f9b9839825dd3149fd
This commit is contained in:
@@ -99,6 +99,10 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean mIsRegisterCallback = false;
|
boolean mIsRegisterCallback = false;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
boolean mIsLeftDeviceEstimateReady;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mIsRightDeviceEstimateReady;
|
||||||
|
@VisibleForTesting
|
||||||
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
final BluetoothAdapter.OnMetadataChangedListener mMetadataListener =
|
||||||
new BluetoothAdapter.OnMetadataChangedListener() {
|
new BluetoothAdapter.OnMetadataChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -226,6 +230,8 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING,
|
BluetoothDevice.METADATA_UNTETHERED_RIGHT_CHARGING,
|
||||||
R.string.bluetooth_right_name,
|
R.string.bluetooth_right_name,
|
||||||
RIGHT_DEVICE_ID);
|
RIGHT_DEVICE_ID);
|
||||||
|
|
||||||
|
showBothDevicesBatteryPredictionIfNecessary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,8 +371,13 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
+ ", ESTIMATE_READY : " + estimateReady
|
+ ", ESTIMATE_READY : " + estimateReady
|
||||||
+ ", BATTERY_ESTIMATE : " + batteryEstimate);
|
+ ", 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 {
|
} finally {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
@@ -380,7 +391,6 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
|||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
|
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
|
||||||
if (estimateReady == 1) {
|
if (estimateReady == 1) {
|
||||||
textView.setVisibility(View.VISIBLE);
|
|
||||||
textView.setText(
|
textView.setText(
|
||||||
StringUtil.formatElapsedTime(
|
StringUtil.formatElapsedTime(
|
||||||
mContext,
|
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,
|
private void showBatteryIcon(LinearLayout linearLayout, int level, int lowBatteryLevel,
|
||||||
boolean charging) {
|
boolean charging) {
|
||||||
final boolean enableLowBattery = level <= lowBatteryLevel && !charging;
|
final boolean enableLowBattery = level <= lowBatteryLevel && !charging;
|
||||||
|
@@ -387,34 +387,52 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showBatteryPredictionIfNecessary_estimateReadyIsAvailable_showView() {
|
public void estimateReadyIsBothAvailable_showsView() {
|
||||||
mController.showBatteryPredictionIfNecessary(1, 14218009,
|
mController.mIsLeftDeviceEstimateReady = true;
|
||||||
mLayoutPreference.findViewById(R.id.layout_left));
|
mController.mIsRightDeviceEstimateReady = true;
|
||||||
mController.showBatteryPredictionIfNecessary(1, 14218009,
|
|
||||||
mLayoutPreference.findViewById(R.id.layout_middle));
|
mController.showBothDevicesBatteryPredictionIfNecessary();
|
||||||
mController.showBatteryPredictionIfNecessary(1, 14218009,
|
|
||||||
mLayoutPreference.findViewById(R.id.layout_right));
|
|
||||||
|
|
||||||
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
|
||||||
View.VISIBLE);
|
View.VISIBLE);
|
||||||
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_middle),
|
|
||||||
View.VISIBLE);
|
|
||||||
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
|
||||||
View.VISIBLE);
|
View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showBatteryPredictionIfNecessary_estimateReadyIsNotAvailable_notShowView() {
|
public void leftDeviceEstimateIsReadyRightDeviceIsNotReady_notShowView() {
|
||||||
mController.showBatteryPredictionIfNecessary(0, 14218009,
|
mController.mIsLeftDeviceEstimateReady = true;
|
||||||
mLayoutPreference.findViewById(R.id.layout_left));
|
mController.mIsRightDeviceEstimateReady = false;
|
||||||
mController.showBatteryPredictionIfNecessary(0, 14218009,
|
|
||||||
mLayoutPreference.findViewById(R.id.layout_middle));
|
mController.showBothDevicesBatteryPredictionIfNecessary();
|
||||||
mController.showBatteryPredictionIfNecessary(0, 14218009,
|
|
||||||
mLayoutPreference.findViewById(R.id.layout_right));
|
|
||||||
|
|
||||||
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
|
||||||
View.GONE);
|
View.GONE);
|
||||||
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_middle),
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
|
||||||
|
View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void leftDeviceEstimateIsNotReadyRightDeviceIsReady_notShowView() {
|
||||||
|
mController.mIsLeftDeviceEstimateReady = false;
|
||||||
|
mController.mIsRightDeviceEstimateReady = true;
|
||||||
|
|
||||||
|
mController.showBothDevicesBatteryPredictionIfNecessary();
|
||||||
|
|
||||||
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
|
||||||
|
View.GONE);
|
||||||
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
|
||||||
|
View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bothDevicesEstimateIsNotReady_notShowView() {
|
||||||
|
mController.mIsLeftDeviceEstimateReady = false;
|
||||||
|
mController.mIsRightDeviceEstimateReady = false;
|
||||||
|
|
||||||
|
mController.showBothDevicesBatteryPredictionIfNecessary();
|
||||||
|
|
||||||
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_left),
|
||||||
View.GONE);
|
View.GONE);
|
||||||
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
|
assertBatteryPredictionVisible(mLayoutPreference.findViewById(R.id.layout_right),
|
||||||
View.GONE);
|
View.GONE);
|
||||||
|
Reference in New Issue
Block a user