Skip to content

Commit 8aab57c

Browse files
Adds expressions snippets (#782)
* Adds expressions snippets * Update watchface/src/main/res/raw/watchface_expressions.xml Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update watchface/src/main/res/raw/watchface_expressions.xml Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent b534c18 commit 8aab57c

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<WatchFace width="450" height="450">
18+
<Scene>
19+
<Condition>
20+
<Expressions>
21+
<Expression name="is_weekend_raw">
22+
<!-- [START android_watch_face_expression_raw] -->
23+
[DAY_OF_WEEK] == 6 || [DAY_OF_WEEK] == 7
24+
<!-- [END android_watch_face_expression_raw] -->
25+
</Expression>
26+
<Expression name="is_weekend_cdata">
27+
<!-- [START android_watch_face_expression_cdata] -->
28+
<![CDATA[[DAY_OF_WEEK] == 6 || [DAY_OF_WEEK] == 7]]>
29+
<!-- [END android_watch_face_expression_cdata] -->
30+
</Expression>
31+
<Expression name="function_example">
32+
<!-- [START android_watch_face_function] -->
33+
(5.0/90.0)*clamp([ACCELEROMETER_ANGLE_X],0,90) +
34+
(-5.0/90.0)*clamp([ACCELEROMETER_ANGLE_X],-90,0)
35+
<!-- [END android_watch_face_function] -->
36+
</Expression>
37+
<Expression name="afternoon_inefficient">
38+
<!-- [START android_watch_face_expression_inefficient] -->
39+
<!-- BAD: Re-evaluates every second -->
40+
[SECONDS_IN_DAY] > 43200
41+
<!-- [END android_watch_face_expression_inefficient] -->
42+
</Expression>
43+
<Expression name="afternoon_efficient">
44+
<!-- [START android_watch_face_expression_efficient] -->
45+
<!-- Good: Minimizes re-evaluation (1 = PM, 0 = AM) -->
46+
[AMPM_STATE] == 1
47+
<!-- [END android_watch_face_expression_efficient] -->
48+
</Expression>
49+
<Expression name="boolean_configuration_cdata">
50+
<!-- [START android_watch_face_expression_boolean_configuration_cdata] -->
51+
<![CDATA[[CONFIGURATION.showBackgroundInAfternoon] == "TRUE" && [AMPM_STATE] == 1]]>
52+
<!-- [END android_watch_face_expression_boolean_configuration_cdata] -->
53+
</Expression>
54+
<Expression name="boolean_configuration_raw">
55+
<!-- [START android_watch_face_expression_boolean_configuration_raw] -->
56+
[CONFIGURATION.showBackgroundInAfternoon] == "TRUE" &amp;&amp; [AMPM_STATE] == 1
57+
<!-- [END android_watch_face_expression_boolean_configuration_raw] -->
58+
</Expression>
59+
</Expressions>
60+
<Compare expression="is_weekend_raw">
61+
<!-- Weekend content here -->
62+
<PartText x="0" y="50" width="450" height="250">
63+
<Text align="CENTER">
64+
<Font family="pacifico" size="96">Weekend!</Font>
65+
</Text>
66+
</PartText>
67+
</Compare>
68+
69+
<Default>
70+
<!-- content -->
71+
</Default>
72+
</Condition>
73+
</Scene>
74+
</WatchFace>

0 commit comments

Comments
 (0)