Gauges

Gauges based on custom type hands

Description

This example shows how to use True Analog Clock library to create any analog gauges.

Anatomy

Face with 4 different gauges styles. 4 different hands with custom type show the current battery level.

XML Settings File

<?xml version="1.0" encoding="utf-8"?>
<TrueAnalogClock
    face="gauges_face"
    useSystemTime="true">

    <hand
        name="Power"
        angleOffset="-90"
        angleRange="60"
        image="gauges_hand_1"
        axisFacePoint="477:934"
        axisPoint="0:835"
        type="Custom"
        underFace="true"/>

    <hand
        name="Power"
        angleOffset="-90"
        angleRange="180"
        image="gauges_hand_2"
        axisFacePoint="1537:452"
        axisPoint="45:253"
        type="Custom"/>

    <hand
        name="Power"
        angleOffset="-45"
        angleRange="90"
        image="gauges_hand_3"
        axisFacePoint="478:1254"
        axisPoint="27:470"
        shadowBlurRadius="40"
        shadowColor="0xFFFFC500"
        type="Custom"/>

    <hand
        name="Power"
        angleOffset="-135"
        angleRange="270"
        image="gauges_hand_4"
        axisFacePoint="1550:1118"
        axisPoint="30:367"
        shadow="true"
        shadowBlurRadius="15"
        shadowColor="0xFF8BB59E"
        type="Custom"/>

</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);
  }
}