式を構築する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
WFF は式言語を使用して、次の機能を有効にします。
Transform
または Gyro
を使用した外観の変換
Condition
ステートメントによる条件付き動作
Template
要素での文字列の書式設定
式言語は、一般的な演算子と使用できるさまざまな関数を含むスクリプト言語です。
式では、角かっこで表されるデータソースを使用して、現在の日時、健康やフィットネスの指標、天気などの外部入力に反応できます。
式を使用する場合、Transform
または Template
と Condition
の使用方法の主な違いは、Transform
と Template
では式の結果が値(囲む要素の新しい位置など)である必要があるのに対し、Condition
では式の結果がブール値である必要がある点です。
たとえば、Condition
は次を使用できます。
[DAY_OF_WEEK] == 6 || [DAY_OF_WEEK] == 7
これはブール値として評価され、DAY_OF_WEEK
データソースを使用して、週末かどうかを判断します。
関数もサポートされています。たとえば、Wear OS デバイスの加速度計の x-value
に基づいて、いずれかの方向に値を最大 5 度回転する式などです。
(5/90)*clamp([ACCELEROMETER_ANGLE_X],0,90) +
(-5/90)*clamp([ACCELEROMETER_ANGLE_X],-90,0)
clamp()
関数は、2 つの境界内に値を制限します。
式の再評価
式が再評価される頻度は、式で使用されるデータソースによって異なります。たとえば、[DAY_OF_WEEK] == 6 || [DAY_OF_WEEK] ==
7
式] は、新しい日が始まったときにのみ再評価されます。ただし、[SECOND]
データソースを使用する式は、1 秒ごとに再評価されます。
再評価により、式の結果の変化に基づいてシーンの再計算と再レンダリングが行われる場合があります。そのため、できるだけ頻繁に再評価されないデータソースを常に使用することが重要です。たとえば、午後かどうかを判断するには:
// Bad - re-evaluates every second
[SECONDS_IN_DAY] > 43200
// Good - limits re-evaluation frequency (1 = PM, 0 = AM)
[AMPM_STATE] == 1
式の設定値
関数とデータソースに加えて、構成値を使用できます。たとえば、UserConfigurations で showBackgroundInAfternoon
という名前の BooleanConfiguration
が定義されている場合、これは式で使用できます。
[CONFIGURATION.showBackgroundInAfternoon] == "TRUE" && [AMPM_STATE] == 1
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-07-27 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# Build expressions\n\nWFF uses an expression language to enable:\n\n- Transforming the appearance using `Transform` or `Gyro`\n- Conditional behavior through `Condition` statements\n- String formatting in `Template` elements\n\nThe expression language is a scripting language which contains your\ntypical operators and a range of functions that can be used.\n\nExpressions can use [data sources](/training/wearables/wff/common/attributes/source-type)---represented using square brackets---to\nlet you react to external inputs such as the current date and time, health\nand fitness metrics, or even the weather.\n\nWhen using expressions, the primary difference between `Transform` or `Template` and\n`Condition` usage, is that `Transform` and `Template` require the expression to result\nin a *value* (for example, the new position of the enclosing element) whereas\n`Condition` requires the expression to result in a *boolean*.\n\nFor example, a `Condition` might use: \n\n [DAY_OF_WEEK] == 6 || [DAY_OF_WEEK] == 7\n\nThis evaluates to a boolean and determines whether it is a weekend or not,\nusing the `DAY_OF_WEEK` data source.\n\n[Functions](/training/wearables/wff/common/attributes/arithmetic-expression#functions) are also supported---for example, an expression for rotating a\nvalue up to 5 degrees in either direction---based on the `x-value` of the Wear OS\ndevice's accelerometer: \n\n (5/90)*clamp([ACCELEROMETER_ANGLE_X],0,90) +\n (-5/90)*clamp([ACCELEROMETER_ANGLE_X],-90,0)\n\nThe `clamp()` function constrains a value within two bounds.\n\n### Expression re-evaluation\n\nThe frequency with which expressions are re-evaluated depends on the data\nsources used in them. For example, the \\[`DAY_OF_WEEK] == 6 || [DAY_OF_WEEK] ==\n7` expression only re-evaluates when a new day starts. However, an expression\nthat uses the `[SECOND]` data source re-evaluates every second.\n\nRe-evaluation may result in scene recalculations and rerendering, based on the\nchange in the result of the expression. Therefore it is important to always use\ndata sources that re-evaluate as infrequently as possible. For example, to\ndetermine whether it is afternoon: \n\n // Bad - re-evaluates every second\n [SECONDS_IN_DAY] \u003e 43200\n\n // Good - limits re-evaluation frequency (1 = PM, 0 = AM)\n [AMPM_STATE] == 1\n\n### Configuration values in expressions\n\nIn addition to functions and data sources, configuration values can be used. For\nexample, if in the [UserConfigurations](/training/wearables/wff/user-configuration/user-configurations) a `BooleanConfiguration` named\n`showBackgroundInAfternoon` has been defined, this can be used in an expression: \n\n [CONFIGURATION.showBackgroundInAfternoon] == \"TRUE\" && [AMPM_STATE] == 1"]]