Create a Watch Face Using Tag Expressions
create a watch face using tag expressions objective learn how to create a watch face that responds based on the date, time, step count, heart rate, and battery level using tag expressions in watch face studio in this code lab, you will create a basic watch face with complications such as step count, heart rate, and battery level later, you will improve its functionalities and make it visually dynamic using tag expressions overview watch face studio is a graphic authoring tool that enables you to create watch faces for wear os it offers a simple and intuitive way to add images and components, and to configure the watch movement without any coding watch face studio supports watch faces for the galaxy watch4 or newer version, and other watch devices that run on the same platform tag expressions are conditions in watch face studio that allows you to customize watch face through dynamic configuration of its movement and data set up your environment you will need the following watch face studio galaxy watch4 or newer any supported wear os watch start your project create a new project and input project name a blank studio will show upon clicking ok add analog hands and index watch face studio allows you to add components like text, image, shape, analog hands, and index in a watch face for your watch to have the look and feel of an analog watch, add the following components time > index time > analog hands > minute time > analog hands > hour notethe index and watch hand images used in this code lab are no longer included in the latest version of the watch face studio however, you can choose a design for the index and watch hands from available images in the resources folder you can also create and add your own design you will see that the hands move automatically and in sync with the device time select all the newly added components and click group rename the group as group_analogtime use a progress bar for seconds a component like a progress bar can be used to show how much of the process is completed and how much is left in this step, you will use it to show how far or close the next minute is to use a progress bar as seconds click add component and select progress bar rename the component to seconds move seconds behind group_analogtime in properties of seconds, do the following a adjust the dimension width and height to 395 b align the component to the center c drag the background slider to 0% d make sure that the type is a circular progress bar; otherwise change it e in range setting, change value to 0 and click tags beside it to open the tags window f type in [sec] it means that the value from 0 will increment as the value of the second increases g set max value to 59 since it is the maximum value of [sec] notein this scenario, the progress bar disappears in the canvas as the preview only uses the base value, which is 0 however, the component is still present in run format and position a digital clock in this step, you will learn how grouping works and affects its components you will also learn how to format the date and time using tags to format and position a digital clock, you need to add a digital clock > time twice rename them as hour and minute, respectively add a digital clock > date and rename the component as date put them in one group and rename it as group_digitaltime go to the properties of hour and change the text appearance to 80 do the same for minute adjust the text size of date to 15 adjust the y placements of the individual components to look like the image below when you change a certain component, it won’t affect other components in the group format hour to only show the time in hour a go to its properties and click the tags button in text field b replace text field value with [hour_0_23_z] to show the current hour with leading zero do the same for minute but replace the text field value with [min_z] to show the current minute in an hour with leading zero go to group_digitaltime placement properties and align it horizontally after that, place it to the left you will see the components adjusted as a group utilize health features and battery level watch face studio also allows you to utilize data like step count, heart rate, and battery level follow the steps below to show these real-time data using tags on texts or progress bar battery level add a circular progress bar and rename the component as battery level drag the background slider to 0% go to value properties replace the value with 0 and, in tags, input or choose [batt_per] to use the current battery percentage as the value add a circle complication slot and rename it as battery icon complications are a set of components that can be handled as one group set the type to fixed and change the default provider to watch battery select short text as complication type and choose icon + text for layout select and move battery level and battery icon together to the bottom right heart rate add a circular progress bar and rename the component as heart rate drag the background slider to 0% go to value properties replace the value with 0 and, in tags, input or choose [hr] to use heart rate as value set the max value to 240 since it's the maximum heart rate a person can have add a text component and rename it as heart rate label in the text field, input heart rate and change the text size to 12 change the y placement to 195 add another text component and rename it as heart rate text in the text field, input [hr] and change the text size to 30 group heart rate, heart rate label, and heart rate text together rename the group as group_heartrate move the group_heartrate placement to the center right step count add a circular progress bar and rename the component as step count drag the background slider to 0% go to value properties replace the value with 0 and, in tags, input or choose [sc_per] to use the current percentage to the goal of step count add a circle complication slot and rename it as step count text set the type to fixed and change the default provider to step count select short text as complication type and choose text + title for layout it will now show "steps" as title and step count as text place the step count text in the center horizontally select and move step count and step count text together to the top right select group_digitaltime, group_batterylevel, group_heartrate, group_stepcount, battery icon, and step count text drag them behind group_analoghands and seconds by doing this, the analog hands would overlap the components make use of tag expressions you already have three progress bars that show data of battery level, heart rate, and step count this time, you will make these features more functional by changing the progress bars' color to red using tag expressions tag expressions are conditions that allow you to change the rotation, placement, behavior, and opacity of a component based on tag values it can alter your watch face's appearance dynamically as the tag value changes tag expressions support different types of operators – arithmetic, relational, logical, and ternary for this step, you will apply tag expressions on the color opacity but first, you will have to duplicate all the circular progress bars seconds, battery level, heart rate, and step count move all the duplicates to a new group called group_colorchange make sure that group_colorchange is behind all other groups change individual component’s color to #ffffff or white duplicate this group and rename it as group_background move it behind group_colorchange drag the background slider to 16% and remove tags in the value properties of each component of group_background change group_colorchange color to #ff001e or red group_colorchange will be used as components underneath when you set the opacity of the main components to 0 using tag expressions group_background will serve as gap fillers of each progress bar below are conditions that will trigger the opacity of the main components to become 0 and reveal the duplicated red components change the color of the battery level to red if the battery level is equal to or less than 20% go to group_batterylevel and select battery level navigate to color properties check if the color opacity value is 100 this will serve as the base value in tags, input [batt_per]<=20?-100 0 to subtract 100 from the base value of opacity if the battery level is equal to or less than 20 otherwise, the base opacity value remains the same in the run pane, adjust the device > watch battery to 20% or less, and you will see how the color will change to red change the color of step count to red if the goal hasn't been reached yet and the time is already 18 00 6 00 pm or beyond go to group_stepcount and select step count navigate to color properties check if the color opacity value is 100 this will serve as the base value in tags, input [sc]<[sc_goal] * [hour_0_23]>=18 ?-100 0 to subtract 100 from the base value of opacity if the step count is less than the goal, and if the value of hour in a day is 18 or beyond otherwise, the base opacity value remains the same play with the time control bar in the run pane and health > steps data to see how the color will change from blue to red change the color of the heart rate and seconds to red if the heart rate is below or above the normal go to group_heartrate and select heart rate navigate to color properties check if the color opacity value is 100 this will serve as the base value in tags, input [hr]<60 + [hr]>100 ?-100 0 to subtract 100 from the base value of opacity if the heart rate is below or above the normal 60-100 otherwise, it remains the same do the same for seconds test it in the run pane by adjusting the health > heart rate to below 60 or above 100, and you will see how the color will change to red prolong the battery life now that you already know what group and tag expressions are, it's about time for you to use both to your advantage it is observed that the darker a watch face design is, the longer the battery life can be to help the watch stay powered even when there’s a little battery left, you will need to decrease the opacity of the watch face when the battery level is equal to or less than 10% to do this, you have to select and combine all created groups and components, except for group analogtime, battery icon, and step count text, to a new group called group_watchface go to group_watchface color properties and change the base opacity value to 20 in tags, input [batt_per]<=10?0 80 to add 0 to the base value of opacity if the battery level is equal to or less than 10 otherwise, it adds 80 to the base value, making the watch face 100% visible adjust the device > watch battery to 10% or less, and you will see how most components' opacity decreased choose components for always-on always-on display is a feature that allows your galaxy watch to show the time without checking on it by pressing a button or lifting your hand in watch face studio, you can choose which group or component to display on the always-on by following these steps go to the always-on tab, to see the same set of components you added and grouped click the eye icon next to the group name to hide or make it visible hide group_watchface, battery icon, and step count text at this point, your always-on display will display a basic analog watch face whenever your watch is in idle mode test the watch face to test your watch face, you need to connect a watch device to the same network as your computer in watch face studio, select project > run on device select the connected watch device you want to test with if your device is not detected automatically, click scan devices to detect your device or enter its ip address manually by clicking the + button you're done! congratulations! you have successfully achieved the goal of this code lab now, you can create and design a watch face using tag expressions by yourself! if you're having trouble, you may download this file tag expression complete project 272 71 kb to learn more about watch face studio, visit developer samsung com/watch-face-studio