time since boot widget - how to do that?

Post your questions and help other users.

Moderator: Martin

Post Reply
orenmi
Posts: 3
Joined: 24 Feb 2015 11:14

time since boot widget - how to do that?

Post by orenmi » 24 Feb 2015 11:15

i would like a small text widget to show the phone "on time"
please help

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: time since boot widget - how to do that?

Post by Martin » 24 Feb 2015 19:39

Hi,

You can either use the function getUptimeMillis() in a script to get the milliseconds since boot, not counting time spent in deep sleep or you can use getElapsedRealtimeMillis() to get the overall millis since boot, including time spent in sleep.

You could use a script like this in a text element of a widget to show the duration in a more human readable format:
{getDurationString(getUptimeMillis())}

..or like this to strip off the seconds and milliseconds of the duration:
{getDurationString(getUptimeMillis()/60000*60000)}

You can also use function setWidgetElementProperty to update a text element of a widget from within a script. This could be useful when you want to show the duration in a custom format.

Regards,
Martin

orenmi
Posts: 3
Joined: 24 Feb 2015 11:14

Re: time since boot widget - how to do that?

Post by orenmi » 28 Feb 2015 11:23

beautiful :)
2015-02-25 15.41.13.jpg
2015-02-25 15.41.13.jpg (523.66 KiB) Viewed 11702 times
is there a list of commands we can use in widgets somewhere?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: time since boot widget - how to do that?

Post by Martin » 01 Mar 2015 13:55

You can use all functions documented in action Script (scroll down a bit to section Functions, also check out section String Inline Expressions).
However I would recommend to only use very simple inline scripts directly in a text element since it can become unreadable quite fast when nested function calls are involved. When you want to make more complex calculations I would recommend to move the function to a flow and to call setWidgetElementProperty to update the text on the widget. This method is also way more powerful since you can change every property of an element like color, size and position and not just the text.
The widget tutorial lists some ideas in the Tips section at the end of the tutorial.

User avatar
kintrupf
Posts: 257
Joined: 10 Sep 2013 08:59

Re: time since boot widget - how to do that?

Post by kintrupf » 02 Mar 2015 07:50

orenmi wrote:beautiful :)
2015-02-25 15.41.13.jpg
Looks great! Would you like to share the flows and the widget?

orenmi
Posts: 3
Joined: 24 Feb 2015 11:14

Re: time since boot widget - how to do that?

Post by orenmi » 02 Mar 2015 08:02

widget attached.
widget_Widget1_20150302_095445.xml
(6.64 KiB) Downloaded 748 times

Post Reply