Quantcast
Jump to content


Recommended Posts

Posted

Smart watch users are interested in having an interactive and eye-catching watch faces, which makes creating watch faces a great area for developers to explore. You can create varieties of watch faces, focusing on different perspectives and purposes. This blog can help you create a basic watch face using HTML and JavaScript in Tizen Studio. We will also discuss simple interactions, such as launching an app from watch face, providing sensor data, and so on.

Design Watch Face

Figure 1 shows a sample watch face that implements an analog clock, has two interactive icons, and shows the wearer’s step count using the pedometer sensor. One of the icons launches the SHealth app to measure heart rate, and another icon displays the current date and launches the Calendar app.

2019-12-10-01-01.png
Figure 1: Sample watch face design

Define Category

Add wearable_clock as the category of your app in the config.xml file. It defines your application as a watch face.

<tizen:category name="http://tizen.org/category/wearable_clock"/>

Create a Basic Watch Face

As this is an analog clock, first you’ll have to calculate the rotation angles of the watch hands and then update the UI accordingly. A sample implementation is shown in the following code snippets: the updateTime() function calculates rotation angle with respect to time, and the rotateElement() function updates the UI with rotating watch hands (see Figure 2).

function updateTime() {
    var curtime = new Date(),
        hour = curtime.getHours(),
        minute = curtime.getMinutes(),
        second = curtime.getSeconds();
rotateElement("hand-main-hour", (hour + (minute / 60) + (second / 3600)) * 30);
rotateElement("hand-main-minute", (minute + second / 60) * 6);
rotateElement("hand-main-second", second * 6);
     if (curDate < 10)
         str_curdate.innerHTML = "0" + curDate;
     else
         str_curdate.innerHTML = curDate;
    }

function rotateElement(elementID, angle) {
    var element = document.querySelector("#" + elementID);
    element.style.transform = "rotate(" + angle + "deg)";
}

2019-12-10-01-02.png
Figure 2: Basic watch face

Add Functionality

Launch App

The Application API provides a method to launch an app in Tizen. To launch the app, add following privilege to the config.xml file:

<tizen:privilege name="http://tizen.org/privilege/application.launch"/>

Then use launch(ApplicationID) method to launch the desired application. If you do not know the ID of that application, you can use getAppsInfo() to get the list of IDs.
The Heart icon launches SHealth app’s heart rate measuring page (com.samsung.shealth.heartrate.measure). The implementation is as follows:

var heart_click = document.getElementById("heart");
heart_click.addEventListener('click', function() {
    tizen.application.launch("com.samsung.shealth.heartrate.measure");
});

2019-12-10-01-03.png
Figure 3: Launch SHealth from the watch face

The Calendar icon shows the current date and launches the calendar application (com.samsung.w-calendar2) on the watch.

var calendar_click = document.getElementById('date-calendar');
calendar_click.addEventListener('click', function() {
    tizen.application.launch("com.samsung.w-calendar2");
});
var curtime = new Date(),
    curDate = curtime.getDate(),
    str_curdate = document.getElementById("date-calendar");
str_curdate.innerHTML = curDate;

2019-12-10-01-04.png
Figure 4: Launch Calendar from the watch face

Access Device Sensor Data

The pedometer sensor provides step count data. To access this sensor, you need to add a feature and a privilege to the config.xml file:



Next, you have to ask for user permission to start reading data from the pedometer sensor. The following code snippet shows the implementation:

function onchangedCB(pedometerInfo) {
   var str_step = document.getElementById('step-count');
   str_step.innerHTML = pedometerInfo.cumulativeTotalStepCount;

}
function onSuccess() {
   tizen.humanactivitymonitor.start("PEDOMETER", onchangedCB,onError,option);
}
function onError(e) {
   console.log("error " + JSON.stringify(e));
}
tizen.ppm.requestPermission("http://tizen.org/privilege/healthinfo", onSuccess, onError);

2019-12-10-01-05.png
Figure 5: Step count

It’s simple to add functionalities to a basic watch face, isn’t it? I hope this blog inspires and helps you create some amazing watch faces using your own ideas and designs.

View the full blog at its source



  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Similar Topics

    • By Samsung Newsroom
      The Samsung Galaxy Watch is an essential gadget for modern health-conscious people. It provides health-related data that helps to prevent health issues. These Galaxy Watch features are driving its rapid rise in popularity and encouraging application developers to create applications specifically for it.
      The Galaxy Watch offers a great user experience and performance. This is where the Flutter framework plays a crucial role. It is a top choice when it comes to a beautiful UI, good performance, and rapid development. Flutter offers cross-platform support, which means we can build applications for multiple platforms using a single code base. With Flutter’s strong community support, developers can make production-grade applications with little effort.
      This blog outlines the steps involved in creating an application for the Galaxy Watch using Flutter, allowing you to explore the possibilities it offers.
      Set up your environment
      Please follow the official Set up Flutter guide to install the Flutter framework correctly on your device. After the installation, please check the status by running the following command. It tells you if any component is missing or suggests what to do next.
      flutter doctor NoteIf the above command provides suggestions or fixes, follow those to solve any problems before continuing. Get started with Flutter projects
      To simplify this application example, we are retrieving the battery levels from a Galaxy Watch to make it easy to understand the development process.
      In this blog, we use Android Studio as the IDE. But, if you are comfortable with VS Code, you can follow this Official Codelab to build your first Flutter application with that instead.
      To start, install the Flutter and Dart plugins on Android Studio. These plugins make it easier to manage Flutter development using the UI instead of the CLI.
      Figure 1: Install Flutter and Dart plugins
      After completing the setup, it is time to create the Flutter Project for Galaxy Watch.
      Go to File > New > New Flutter Project. Note that this method only appears if you installed the plugins mentioned above. Select Flutter from the left side panel and set the Flutter SDK path where it was installed during the Flutter setup, and click the Next button. Enter a project name and location, and choose the language according to your preferences. Uncheck all platform options except Android and keep the other options as they are. Click the Create button, and a new window should open with the project. You are now done. Next, we need to modify the code for Galaxy Watch.
      Break down the elements of a Flutter project
      A simple Flutter project for the Android platform contains the following folders:
      android/: Contains Android platform code and configurations. lib/: The main folder for a Flutter application. It contains your Dart code. The main.dart file is the entry point of a Flutter application. pubspec.yaml: A configuration file for Flutter. It manages the application’s dependencies and assets. Configure the project to support Galaxy Watch
      Let’s modify the generated code to include the battery level, allowing it to be displayed. Open the pubspec.yaml file and add the following plugins under dependencies:
      dependencies: flutter: sdk: flutter wear: ^1.1.0 battery_plus: ^6.0.3 We use the wear and battery_plus plugins for this project. The wear plugin provides APIs for wear-related functionality, and battery_plus is for accessing battery information from the OS. Both plugins were developed by the Flutter Community. You can even get battery information or trigger Wear OS native APIs using the Method Channel, which we will cover in our future blogs.
      Change the value of minSdk to 23, which is required for the plugins that we are using. Go to android > app > build.gradle and change the minSdk property value under defaultConfig.
      defaultConfig { applicationId = "com.example.flutter_app" minSdk = 23 targetSdk = flutter.targetSdkVersion versionCode = flutterVersionCode.toInteger() versionName = flutterVersionName } Add the following code to your AndroidManifest.xml file, above the <application> tag. This tag defines that we are building the application for watches.
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-feature android:name="android.hardware.type.watch" /> <application android:label="galaxy_watch_battery_info" Build the watch application
      The main challenge is crafting your application to fit a tiny screen. We must be aware of good practices regarding UI, UX, and compactness at the same time. But as mentioned, this application is a simple one.
      Here we work with the build function of the MyHomePage class, where the UI implementation is applied. The main() function is the starting point for a Flutter application. It triggers the build function sequentially. Refer to the following build method for an example.
      @override Widget build(BuildContext context) { return MaterialApp( title: 'Galaxy Watch Demo', theme: ThemeData( visualDensity: VisualDensity.compact, useMaterial3: true, colorSchemeSeed: const Color(0x9f4376f8), ), home: Scaffold( body: SafeArea( child: _getWatchView(context), ), ), ); } The widgets we use are:
      MaterialApp: The root widget that contains all the contents of the application UI and provides application functionalities like home, theming, navigations, localizations, and so on. Scaffold: It provides a visual layout structure for an application, which has options like an app bar and body. SafeArea: A widget that encircles its child to ensure it avoids overlap with the OS interface. Tailor the UI
      We can now access the WatchShape widget since we converted our application to a watch application. WatchShape is the key widget for watch UI design. It provides the basic interface shapes for watches along with ambient modes of the watch. As mentioned earlier, the UI has a simple button that queries the battery level and shows it in a dialog.
      Widget _getWatchView(BuildContext context) { return WatchShape( builder: (BuildContext context, WearShape shape, Widget? child) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [const Text("Hello from Galaxy Watch"), ElevatedButton(onPressed: () { _battery.batteryLevel.then((batteryLevel) { showDialog<void>(context: context, builder: (_) => AlertDialog( content: Text('Battery: $batteryLevel%'), actions: <Widget>[ TextButton( onPressed: () { Navigator.pop(context); }, child: const Text('OK'), ) ])); }); }, child: const Text('Get battery level'))]) ); }, ); } The widgets we use are:
      WatchShape: This widget makes the UI compact to fit the watch’s small screen. battery.batteryLevel: To access the battery information, we need to create an instance of the Battery class. Please refer to the following code as an example. final Battery _battery = Battery(); Test the application
      Now it’s time to see how your application works. Save all the changes and run the application by clicking the Run button from the “Main Toolbar.” You should see a new UI titled “Hello from Galaxy Watch” with a single button. You have created a Flutter application for a Galaxy Watch. Congratulations!
      Figure 2: Sample application
      Conclusion
      This blog walked you through building an application for Galaxy Watch. Flutter offers an amazing toolkit for crafting beautiful UIs. Within a short time you can build applications on a device to accomplish what you want.
      Don’t forget to experiment with building applications and enjoy the journey of creating something new for Galaxy Watches. For more tips and tricks on Galaxy Watch application development, please keep your eyes on the Samsung Developer portal.
      View the full blog at its source
    • By Samsung Newsroom
      A sensor's maximum and minimum values are crucial for calibration, data interpretation, threshold setting, user interface, error handling, sensor selection, and performance optimization.
      Understanding the expected range of values helps identify and handle sensor errors or anomalies, and selecting the right sensor for the intended use case is essential. Efficient use of sensor data, especially in resource-constrained environments like mobile devices, can optimize data processing algorithms.
      The maximum and minimum values of sensors play a crucial role in the accurate and efficient functioning of sensor-based applications across various domains. In this tutorial, a wearable application is developed to collect the maximum and minimum ranges of sensors from a Galaxy Watch running Wear OS powered by Samsung. This tutorial shows how to retrieve all sensor ranges together, as well as from one specific sensor separately.
      Environment
      Android Studio IDE is used for developing the Wear OS application. In this tutorial, Java is used, but Kotlin can also be used.
      Let’s get started
      The SensorManager library is used here to collect sensor data from a Galaxy Watch running Wear OS powered by Samsung.
      Retrieve the maximum range of a sensor
      To get access and retrieve the maximum ranges from the sensor:
      In Android Studio, create a wearable application project by selecting New Project > Wear OS > Blank Activity > Finish. To access the sensor, add the body sensor in the application’s “manifests” file.
      <uses-permission android:name="android.permission.BODY_SENSORS" /> To run the application on devices with Android version 6 (API level 23) or later, you need runtime permission from the user to use the BODY_SENSORS APIs.
      Add the following code snippet to the onCreate() method before calling any sensor operations:
      if (checkSelfPermission(Manifest.permission.BODY_SENSORS) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[]{Manifest.permission.BODY_SENSORS}, 1); } else { Log.d("TAG___", "ALREADY GRANTED"); } After this code executes, a pop-up window appears and requests permission from the user. The sensor APIs return values only if the user grants permission. The application asks for permission only the first time it is run. Once the user grants permission, the application can access the sensors.
      Figure 1: Permission screen
      More details about runtime permissions can be found here.
      Create an instance of the SensorManager library before using it in the code.
      private SensorManager sensorManager; sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); To retrieve the maximum range of all sensors, create a sensor list using API Sensor.TYPE_ALL.
      List<Sensor> sensors = sensorManager.getSensorList(Sensor.TYPE_ALL); ArrayList<String> arrayList = new ArrayList<String>(); for (Sensor sensor : sensors) { if (sensor != null) { arrayList.add(sensor.getName()); arrayList.add(sensor.getMaximumRange() + ""); arrayList.add(sensor.getResolution() + ""); } } arrayList.forEach((n) -> System.*out*.println(n)); The above code shows the sensor name, maximum range, and resolution. You can get all the available data from the sensors, such as type, vendor, version, resolution, maximum range, and power consumption, by applying this same approach.
      Remember, sensor information may vary from device to device.
      Additionally, not every sensor that appears in the logcat view is accessible. Third-party applications are still not allowed to access Samsung's private sensors using the Android SensorManager. You get a “null” value if you try to access the private sensors.
      Moreover, there are no plans to make these sensors available to the public in the near future.
      You can check my blog Check Which Sensor You Can Use in Galaxy Watch Running Wear OS Powered by Samsung to find out which sensors are accessible on your Galaxy Watch and which are not.
      Retrieve the minimum range of a sensor
      The minimum range is the complement of maximum range.
      If the maximum range is x, then the minimum range can be calculated like this: x*(-1) = -x.
      If a specific sensor value should always be absolute, then the minimum range is zero (0).
      There is no direct API available to retrieve the minimum range of sensors from Galaxy Watch.
      Get a specific sensor value
      To get specific sensor values from a Galaxy Watch, you can filter the sensor list or use the getDefaultSensor() method. Here is an example that demonstrates how to do this. Add the necessary permission in the “manifests” file for the accelerometer sensor:
      <uses-feature android:name="android.hardware.sensor.accelerometer" /> Use the following code in your Activity or Fragment to retrieve the accelerometer data:
      sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (sensor != null) { textView_maxV.setText(textView_maxV.getText() + "" + sensor.getMaximumRange() + ""); textView_resolution.setText(textView_resolution.getText() + "" + sensor.getResolution() + ""); } Ensure you have added the TextView element to your XML file. Output of the above code:
      Figure 2: Maximum range and resolution of the accelerometer
      Remember, sensor ranges may vary from device to device. You may get different values for different Galaxy Watch models.
      Download the example from this blog:
      SensorMinxMax (313.2KB) Sep 10, 2024 Summary
      This article demonstrates how you can retrieve the maximum and minimum ranges of sensors from your Galaxy Watch running Wear OS powered by Samsung. You can also use the above approaches to get other necessary available information from the watch that can be used for the precise and effective operation of sensor-based applications in a variety of fields.
      If you have any questions about or need help with the information in this article, you can reach out to us on the Samsung Developers Forum or contact us through Developer Support.
      View the full blog at its source
    • By Samsung Newsroom
      View the full blog at its source





×
×
  • Create New...