Languages

Menu
Sites
Language
Problem with Ambient mode and document.addEventListener "visibilitychange" if !document.hidden

My watch face is updated every 500 ms when document is not hidden. I want do the same when Ambient mode is turned on. And it works well but in a while it works like Ambient mode is 'document.hidden', so watch face isn't updated any more. I need to reboot device and it works fine again.

What is a reason? What do I need to do?

 

document.addEventListener("visibilitychange", function() {
            if (!document.hidden) {
                interval = setInterval(update_watch, 500);
            }

            else {   //or if (document.hidden) no matter, the same effect
                clearInterval(interval);
            }
            
        });

 

I don't even use window.addEventListener "ambientmodechanged"

I added just two cases.

- If hidden then stop updating.

- If not hidden then start updating

Edited by: Anonymous on 03 May, 2019
View Selected Answer

Responses

6 Replies

In the end I decided to do like this... Maybe it's a strange way to solve it but it works...

 

        window.addEventListener("ambientmodechanged", function(e) {
            if (e.detail.ambientMode === true) {
                clearInterval(interval);
                interval = setInterval(update_watch, 500);
            } 
        });
        
        
        document.addEventListener("visibilitychange", function() {
            if (!document.hidden) {
                clearInterval(interval);
                interval = setInterval(update_watch, 500);
            } 
            
            if (document.hidden) {
                clearInterval(interval);
            }
            
        });

haha! it doesn't work!!! WHY??? I still need help!!!

the most horrible thing that it works from time to time...

Mark as answer
Iqbal Hossain

hi Serzh Ivasyshyn

I have not understood the reason for which you wanted to update the watch face every 500ms. As per my knowledge, you can update the UI by using "timetick" event. 

Table: Ambient events
Type Description Attribute
ambientmodechanged Event is triggered when a device enables or disables the ambient mode. detail.ambientMode: the status of the mode.

The available values are true when the ambient mode is enabled and false when the ambient mode is disabled.

timetick Event is triggered once a minute while the device is in the ambient mode to notify the application that it can update its UI.
Note
The http://tizen.org/privilege/alarm privilege must be set to get timetick events.
 

Ref: https://developer.tizen.org/dev-guide/2.3.1/org.tizen.gettingstarted/html/web/details/event_handling_w.htm#ambient

So, add this event listener, 

window.addEventListener('timetick', function() {
    // TODO : Update the ambient view    
    updateAmbientWatch(); 
}); 

 

You can also see the IDE Sample App called "Ambient Watch"

And here is a time interval example, 

https://developer.tizen.org/community/code-snippet/web-code-snippet/how-use-ambient-events-low-powered-wearable-device

 

Thanks for your reply. Finally using 'timetick' is what I did.

500 ms updating in regular mode gives me blinked dotes, so I wanted it blinked in ambient mode too.

Now I'm looking how to add blinked dots. For example Samsung Watch Face ''Large" has animated blinked dots every 500 ms. So I think it's possible.

Iqbal Hossain

great ! and welcome.