Power Reserve
Clock with power reserve indicator
Description
Clock with power reserve feature that shows the battery level. Power reserve indicator implemented as a custom type hand with pair lines of code.
Anatomy
Round face with 3 standard hands and custom retrograde hand for power reserve indicator at 12 o'clock.
XML Settings File
<?xml version="1.0" encoding="utf-8"?>
<TrueAnalogClock
face="power_reserve_face"
useSystemTime="true">
<hand
angleOffset="135"
angleRange="90"
image="power_reserve_hand_power"
axisFacePoint="1021:372"
axisPoint="47:262"
shadow="true"
shadowOffset="5:5"
type="Custom"
name="Power"/>
<hand
image="power_reserve_hand_hour"
axisFacePoint="1020:1020"
axisPoint="58:621"
shadow="true"
shadowOffset="7:7"
type="Hour"/>
<hand
image="power_reserve_hand_minute"
axisFacePoint="1020:1020"
axisPoint="42:872"
shadow="true"
shadowOffset="9:9"
type="Minute"/>
<hand
image="power_reserve_hand_second"
axisFacePoint="1020:1020"
axisPoint="31:871"
shadow="true"
shadowOffset="11:11"
type="Second"/>
</TrueAnalogClock>
Manual code
The code finds all hands with "Power" name and then sets current battery parameters as value and value range.
Object[] hands = clock.findHands("Power");
if (hands.length > 0) {
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = registerReceiver(null, iFilter);
for (Object item : hands) {
TrueAnalogClockHand hand = (TrueAnalogClockHand) item;
if (batteryStatus != null) {
hand.setValueRange(batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1));
} else hand.setValueRange(10);
if (batteryStatus != null) {
hand.setValue(batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1));
} else hand.setValue(0);
}
}