Class: Toybox::WatchUi::SimpleDataField

Inherits:
DataField show all

Overview

Note:

The system will call the onUpdate() method inherited from View when a Data Field is displayed by the system. Because compute() and onUpdate() are asynchronous, there is no guarantee that compute() will be called before onUpdate(). For this reason, variables should never be initialized in compute().

Create a SimpleDataField.

A SimpleDataField is a special View that automatically provides Activity.Info once per second via the compute() method.

Just like in a DataField, a SimpleDataField automatically provides Activity.Info once per second via the compute() method. In exchange for the flexibility offered in a DataField, all field layout is handled automatically in a SimpleDataField.

A SimpleDatField requires two items:

  • A compute() method should return the value to be displayed by the SimpleDataField. Allowed types are Number, Float, Long, Double, Duration, and String.

  • A “label” variable, which should be assigned a String label for the field.

Examples:

A SimpleDataField that displays current heart rate

using Toybox.WatchUi;

class MySimpleHRField extends WatchUi.SimpleDataField {

    // Set the label of the field here
    function initialize() {
        SimpleDataField.initialize();
        label = "My Current HR";
    }

    // Specify the Activity info to display in the field here
    function compute(info) {
        return info.currentHeartRate;
    }
}

See Also:

Since:

  • 1.0.0

Supported Devices:

  • All devices

Constant Summary

Constants inherited from DataField

DataField::OBSCURE_BOTTOM, DataField::OBSCURE_LEFT, DataField::OBSCURE_RIGHT, DataField::OBSCURE_TOP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DataField

createField, getBackgroundColor, getObscurityFlags, onNextMultisportLeg, onTimerLap, onTimerPause, onTimerReset, onTimerResume, onTimerStart, onTimerStop, onWorkoutStepComplete

Methods inherited from View

findDrawableById, onHide, onLayout, onShow, onUpdate, setKeyToSelectableInteraction, setLayout

Methods inherited from Lang::Object

equals, hashCode, method, toString, weak

Constructor Details

initializeSimpleDataField

Returns a new instance of SimpleDataField

Since:

  • 1.0.0


12706
12707
# File 'Monkeybrains.rb', line 12706

def initialize()
end

Instance Attribute Details

labelObject

The field label String.

Since:

  • 1.0.0


12703
12704
12705
# File 'Monkeybrains.rb', line 12703

def label
  @label
end

Instance Method Details

compute(info) ⇒ Object

Retrieve Activity.Info in a SimpleDataField.

This method is called once per second and automatically provides Activity.Info to the SimpleDataField object for display or additional computation. It is necessary to override compute() when implementing a SimpleDataField. The value to be displayed in the field must be returned by this method.

Examples:

function compute(info) {
    return info.currentHeartRate;
}

Parameters:

See Also:

Since:

  • 1.0.0


12723
12724
# File 'Monkeybrains.rb', line 12723

def compute(info)
end