Connect IQ > データフィールド (Dynamic Data Field)


Contents

ダイナミックデータフィールド (Dynamic Data Fields) を用いると、デベロッパがデータフィールドに書き込むことができる。目的は、ユーザにワークアウトデータから簡単に新たなデータフィールドを提供するだけでなく、表現のカスタマイズをも提供するシステムを作ることである。

Datafield and SimpleDataField

データフィールドの基本クラスとなるのは WatchUi.DataField である。
このクラスはビュークラスの拡張クラスであり、他の WatchUi ビューと多くの面で同じように振る舞う。onUpdate() が、画面のアップデートが必要なタイミングで呼び出される。

Garmin アクティビティにおいて、ユーザーはページレイアウトを制御できる。特に一つのページにいくつ表示させるか、という点である。Connect IQ data field は全てのレイアウトを扱えなければならない。開発者はシミュレータを用いて、各デバイス、レイアウトでどのように表示されるかテストできる。

多くの開発者は、単一の値を表示させればよく、複雑な描画を扱う必要は無いと考えている。このような場合、シンプルデータフィールド (SimpleDataField) を用いる。シンプルデータフィールドは複数のサイズのフィールドでの描画を扱い、開発者は compute() の継承のみを行えばよい。compute() には Activity.Info の情報が渡されている。

例:“Beers Earned" データフィールド(ワークアウトでどれくらいの「ビール」のカロリーを稼いだか)

using Toybox.Application;
using Toybox.WatchUi;

class BeerView extends WatchUi.SimpleField
{
    function initialize() {
        units = "beers";
    }

    function compute(info) {
        return info.calories / 150; // Calories in average bottle of beer
    }
}

class BeersEarned extends Application.AppBase
{
    function getInitialView() {
        return new BeerView();
    }
}

Activity Info


The compute() method will be called before update in a data field. This method allows the developer to run a computation based on the workout information. The workout information is passed in as a Toybox.Activity.Info object. This object contains all the info about the workout that is computed by the system:


The following is the API for the data fields:

// DataField クラスはデータフィールドを生成するために用いられる。
// 開発者は毎秒コールされる compute() を実装する。
// システムはフィールドが表示されているとき、 View クラスの onUpdate() を呼び出す。

class DataField extends View
{
    // To retrieve Activity.Info data for DataFields, it is necessary to override compute().
    // This is the method that is called to update the field information.
    // @param [Activity.Info] info The updated Activity.Info object
    function compute( info );
}

// The SimpleDataField class is used for creating simple data fields.
// In a SimpleDataField, the developer is only required to implement a compute
// method. The compute method is passed an Activity.Info object, which contains
// all current workout information. The compute method should return a value to
// be displayed.  Allowed types are Number, Float, Long, Double, and String.
// The SimpleDataField also contains a variable "label".  This variable should
// be assigned to a String label for the field.
class SimpleDataField extends DataField
{
    //! Constructor
    function initialize();

    //! To retrieve Activity.Info data for DataFields, it is necessary to override compute().
    //! This is the method that is called to update the field information.
    //! @param [Activity.Info] info The updated Activity.Info object
    function compute( info );
}

Simulating a Workout


To test your data field in the simulator, feed your data field simulated databy clicking the Simulation menu, choose FIT Data and then Simulate. This will generate random but valid data. You can also use Simulation > FIT Data > Playback File… to simulate a workout by using a pre-recorded FIT file.
最終更新:2016年03月13日 00:15