Article Introduction
In this article, I have explained how to develop a calendar application for Huawei Lite Wearable device using Huawei DevEco Studio and using JS language in Harmony OS. Calendar provides options to swipe to desired day, month and year.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Huawei Lite Wearable
Requirements
1) DevEco IDE
2) Lite wearable watch (Can use simulator also)
New Project (Lite Wearable)
After installation of DevEco Studio, make new project.
Select Lite Wearable in Device and select Empty Feature Ability in Template.
After the project is created, its directory as shown in image.
Integration process
Design the UI
Step 1: Add background image.
As the first step, we can create a UI that contains calendar text boxes which will filled by the dates. Create and add the background image for calculator screen using stack component.
index.hml
Code:
<stack class="stack">
<image src='/common/calendarbackground.png' class="background"></image>
</stack>
index.css
Code:
.background {
width:454px;
height:454px;
}
.stack {
width: 454px;
height: 454px;
justify-content: center;
}
Step 2: Add row of days in a week in highlighted text boxes.
Create and add a row for days from Sunday to Saturday with letters “S, M, T, W, T, F, and S”.
index.hml
Code:
<div class="days" for="{{value in days}}" tid="id">
<text class="days">{{value}}</text>
</div><strong> </strong>
index.js
Code:
days: ["S", "M", "T", "W", "T", "F", "S"],
Step 3: Add UI for calendar dates
Create and add row for 7 days and 6 weeks in a month. We need 7x6 matrix of text boxes. Use loop rendering for the boxes since all are similar boxes
Code:
<div class="containerRow" for="{{valueWeek in weeks}}" onswipe="touchMove">
<div class="datestext" for="{{value in valueWeek}}" tid="id">
<text class="datestext">{{value}}
</text>
</div>
</div>
Code:
.datestext {
display: flex;
font-size: 8px;
text-align: center;
width: 55px;
height: 40px;
border-width: 1px;
border-color: #414343;
color: #414343;
background-color: #e6e6e6;
}
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0201459080286730034
Gotta say DevCo and Harmony are getting better every day......I mean look at all this amazing applications we are able to develop and intergrate
Related
Map Kit has various SDKs and APIs. One of them is JavaScript API which is a solution for web applications and cross platforms.
What does Map Kit JavaScript API provide?
It provides the basic map display, map interaction, route planning, place search, geocoding, and other functions to meet requirements of most developers.
Which browsers are supported?
Currently, JavaScript APIs support the following browsers:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
What are the prerequisites to use Map Kit JavaScript API?
Before using the service, you need to apply for an API key on the HUAWEI Developer website.
How to integrate basic capabilities?
First thing is to copy API Key from the developer console:
Code:
AppGallery Connect > Your App > Develop > Overview > App Information > API key
We need to provide the HUAWEI Map Kit API file. The API key must be encoded. You can encode it programatically or you can try out online tools to do it manually.
Code:
<script src="https://mapapi.cloud.huawei.com/mapjs/v1/api/js?callback=initMap&key=API KEY"></script>
Create map element in the body:
Code:
<div id="map"></div>
Initialize the map. The following sample code is to create a map with Paris as the center and a zoom level of 8:
Code:
function initMap() {
const mapOptions = {};
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 8;
mapOptions.language='ENG';
const map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
}
Add a marker:
Code:
const mMarker = new HWMapJsSDK.HWMarker({
map,
position: {lat: 48.85, lng: 2.35},
label: 'A',
icon: {
opacity: 0.5
}
});
Show information window when clicking on marker:
Code:
const infoWindow = new HWMapJsSDK.HWInfoWindow({
map,
position: 10,
content: 'This is a InfoWindow.',
offset: [0, -40],
});
mMarker.addListener('click', () => {
infoWindow.open(mMarker);
});
Sample code is available on my GitHub page: /onurkenis/ionic-hms-map-demo
Hi,
Map kit Api will support navigation.how to show shortest path.
More information like this, you can visit HUAWEI Developer Forum
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201314254633580183&fid=0101188387844930001
In a previous post I’ve showed you how to make the account binding process to obtain the user’s Open Id. In this article I’m going to explain you how to use the Open Id to send push events to the users of your card ability.
Previous requirements
A card Ability
A developer Enterprise account
Huawei QuickApp IDE V2.5+
Huawei Ability Test Tool V1.0+
Your own server
Preparing the card
Open your card project in the Huawei QuickApp IDE and create a new widget by going to File > New widget.
Select a template for your card and click on "Ok"
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
New Widget Dialog
Use the selector to choose Config and then select your card
Card Selector
Use the + button to add parameters, you can define default values for testing.
Card Setup Dialog
Receiving the parameters
When you send push events, the params will be delivered to the card. To be able to render the card dynamically with the params, define an array of properties in your exports in the “script” part of your UX file.
Code:
<script>
const locales = {
zh: require('./i18n/zh.js'),
en: require('./i18n/en.js')
}
const device = require("@system.device");
import configuration from '@system.configuration'
const localeObject = configuration.getLocale();
let local = localeObject.language;
const $i18n = new I18n({ locale: local, messages: locales, fallbackLocale: 'en' });
module.exports = {
props: [
'title',
'big_text',
'small_text'
],
Modify the onInit function to receive the parameters using the next notation: this.property=params.paramName. Where property is one of the properties from the props array and paramName is the name you’ve defined in the config dialog.
Code:
onInit: function (params) {
this.title=params.title;
this.big_text=params.big_text;
this.small_text=params.small_text;
this.margin = Math.ceil(this.dpConvert(16));
try {
var windowLogicWidth = device.getInfoSync().windowLogicWidth;
this.width = (windowLogicWidth - (this.margin * 2));
this.height = Math.ceil((this.width / 16) * 9);
} catch (error) {
this.width = (750 - (this.margin * 2));
this.height = Math.ceil((this.width / 16) * 9);
}
}
Card Rendering
You can access to your properties from the template part to display your card according to the received params using the next notation: {{property}}
Code:
<template>
<div class="maptype_box" widgetid="12e7d1f4-68ec-4dd3-ab17-dde58e6c94c6">
<card_title id='title' title="{{title}}"></card_title>
<div class="maptype_content_box">
<image src="{{$t('message.url')}}" class="maptype_img" style="width: {{width}}px ;height:{{height}}px;"></image>
<div class="maptype_one">
<text class="maptype_text_one">{{big_text}}</text>
</div>
<div class="maptype_two">
<text class="maptype_textFour">{{small_text}}</text>
</div>
</div>
<card_bottom_2 dataSource="Source"></card_bottom_2>
</div>
</template>
Card update
Go to Build > Run release to create a signed RPK package of your card. Don’t forget to update the version name and version number.
Card Build Dialog
Once the process is complete, open the AGC console go to “My apps” and select your card. If you don’t have a card in AGC, you can click on “new app” and select RPK as package type.
App Gallery Connect
From version information, scroll down to software version and then click on “Software packages”.
Package Admin Dialog
Click on upload and select your generated package
Upload Progress Dialog
That’s all for AGC, let’s make the ability configuration.
This is not the end. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201314254633580183&fid=0101188387844930001
What does RPK stands for ?
After the quick app web component is used to pack an HTML5 app into a quick app, the original web page does not provide the function of returning to the home page. In an HTML5 quick app, users want to have an entry for returning to the home page when browsing any HTML5 page.
To implement this requirement, perform the following steps:
1. Define the loadUrl variable under data in the page script. This variable is used to store the URL of the HTML5 web page. In this demo, the Huawei official website is used as the home page entry.
HTML:
export default {
props: ['websrc'],
data: {
title: "",
// TODO Replace the link to the H5 app
loadUrl: "http://www.huawei.com/en",
allowThirdPartyCookies: true,
//Attribute supportzoom, indicates whether the H5 page can be zoomed with gestures.
supportZoom: true,
wideViewport: true,
overViewModeLoad: true,
},
}
2. Modify template code.
Bind the src attribute of web in template to the variable loadUrl defined in step 1.
Listen to the pagestart event of the web component, that is, onpagestart in the code.
Add the entry layout of returning to the home page, which needs product design. This demo uses an image as an example.
The sample code is as follows. Pay attention to the text in red to see the modification points.
HTML:
<template>
<div class="doc-page">
<image src="/Common/main.png" onclick="goMain"></image>
<web class="web-page" src="{{loadUrl}}" trustedurl="{{list}}" onpagestart="onPageStart" onpagefinish="onPageFinish"
onmessage="onMessage" ontitlereceive="onTitleReceive" onerror="onError" id="web" supportzoom="{{supportZoom}}"
wideviewport="{{wideViewport}}}" overviewmodeinload="{{overViewModeLoad}}" useragent="{{userAgent}}"
Precautions:
The event callback methods goMain and onPageStart in the preceding code must be defined in the script.
The value of src in the image component must be replaced with the actual image path in the project.
3. Modify the code in the script. The following code needs to be modified:
In the callback method onPageStart of the web component, assign the value of url (indicating the URL of the current page) to loadUrl.
HTML:
onPageStart(e) {
console.info('pagestart: ' + e.url)
this.loadUrl=e.url;
},
l In the goMain method, assign the home page URL to loadUrl.
HTML:
goMain: function () {
console.log("goMain :");
this.loadUrl = "https://www.huawei.com/en";
},
Then, you can click HUAWEI on the screen to go to the Huawei official website.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Introduction
In this article, will explain how to develop heart reading health application integration on Harmony lite wearable. Following are the APIs we are going to integrate with this application.
1) On Body status API: To detect the watch is tied with the user’s wrist.
2) Heart rate API: To read the heart rate.
3) Memory storage API: To cache the previous reading.
4) Keep screen on API: To keep the screen on for 5 minutes.
Moving to this article if you are new to the Harmony platform, you can check this article: Huawei Lite Wearable Application Development using HUAWEI DevEco Studio (HamonyOS)
Requirements
1) DevEco IDE
2) Lite wearable watch (Can use simulator also)
Steps to create the project
1) Open the DevEco studio, choose File > New > New Project to create the new project.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2) Select the Lite Wearable project and select Template.
3) Enter Project Name and Package name, and then click Finish.
Flow chart
Here is the flow chart of the application that we are going to integrate.
Integration process
Step 1: Design the UI
As the first step, we can create a UI that contains two texts, one for the heading and another for showing the result.
index.html
Code:
<div class="container" onswipe="touchMove">
<text class="title"> Your Heart Rate is </text>
<text class="title2"> {{title}} bpm </text>
</div>
index.css
Code:
.container {
display: flex;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 454px;
height: 454px;
flex-direction:column;
}
.title {
font-size: 30px;
text-align: center;
width: 200px;
height: 100px;
}
.title2 {
font-size: 30px;
text-align: center;
width: 400px;
height: 40px;
flex-wrap:wrap;
background-color: cornflowerblue;
}
Run the application, and you can see an output as given below.
Step 2: Integrate On Body State API
Now we will move to the API part. Firstly we have to add code to check if the user is tied with the watch or not. For that, we have on body state API.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0202454821219350012
Can we use any other IDE ?
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
IntroductionIn this article, I have explained how to develop a stopwatch application for Huawei Lite Wearable Device.
Huawei Lite Wearable watch application development supports JS language with the support of HTML tags and CSS for styling layouts.
Requirements
Dev Eco Studio IDE
Lite wearable watch or simulator
New Project For Lite WearableYou can create a new project for Lite Wearable in 3 steps as follows.
Step -1
Step-2
Step-3
Implementation
UI Design :
I used 2 basic components for the application. I used a text for the duration and 3 images to start, pause and finish the time.
index.hml:
Code:
<stack class="stack">
<image src='/common/Mirage.png' class="background"></image>
<div class="container" onswipe="touchMove">
<text class="title">
{{time}}
</text>
<div class="row">
<image src="{{src}}" class="stopWatchButtons" onclick="startOrPause"></image>
<image src="/common/stop-button.png" class="stopWatchButtons" onclick="reset"></image>
</div>
</div>
</stack>
index.css:
Code:
@import '../../common/style.css';
.stopWatchButtons{
width: 64px;
height: 64px;
margin: 5px;
}
Code Part :
setInterval function sets a repeating timer for the system to repeatedly execute a function at a fixed interval. In the remaining part, I calculated using the starting time and the elapsed time. I converted this time into hours, minutes, seconds and milliseconds and transferred it to the text.
index.js:
Code:
function timeToString(time) {
// milliseconds to hours
let diffInHrs = time / 3600000;
let hh = Math.floor(diffInHrs);
// hours to minutes
let diffInMin = (diffInHrs - hh) * 60;
let mm = Math.floor(diffInMin);
// minutes to seconds
let diffInSec = (diffInMin - mm) * 60;
let ss = Math.floor(diffInSec);
// seconds to milliseconds
let diffInMs = (diffInSec - ss) * 100;
let ms = Math.floor(diffInMs);
let formattedHH = padL(hh,2,0)
let formattedMM = padL(mm,2,0)
let formattedSS = padL(ss,2,0)
let formattedMS = padL(ms,2,0)
return `${formattedHH}:${formattedMM}:${formattedSS}:${formattedMS}`;
}
function padL(a,b,c) { //string/number,length=2,char=0
return (new Array(b || 2).join(c || 0) + a).slice(-b)
}
Output
ConclusionIf you are going to make an application related to the stopwatch, you can simply use it this way. In this article, we learned how to develop applications for Harmony OS using Dev Eco Studio.
Well explained, can we send notification?
sujith.e said:
Well explained, can we send notification?
Click to expand...
Click to collapse
First of all I'm sorry for the late reply. Yes, you can using App-to-app Message Communication. Related documents are below.
Android: https://developer.huawei.com/consum...ty-Guides/phone-send-message-0000001051059209
Lite Wearable: https://developer.huawei.com/consum...es/fitnesswatch-send-message-0000001052460491
Thank you!