I am writing script into the text of a widget and am noticing a couple of differences with accepting in that manner.
Normally when you do:
{global_dateExample,dateformat,HH:mm} by itself, it will work, but when i use it together with a sting it only returns the raw Unix timestamp like the "dateformat,HH:mm" part doesn't exist.
Script inside widget script
Moderator: Martin
- digitalstone
- Posts: 342
- Joined: 21 Oct 2017 12:36
- Location: The Netherlands
Script inside widget script
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: Script inside widget script
Usually it is because part of the string doesn't quoted properly or the format of the datetime is wrong. I just tried with {getDate(),dateformat,HH:mm}, it is working properly. Probably if you can post the full string, then we analyze the problem. Try to use the same script and test in other flow, use debug dialog to check the result.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
- digitalstone
- Posts: 342
- Joined: 21 Oct 2017 12:36
- Location: The Netherlands
Re: Script inside widget script
Alright, the example is pretty simple actually.
{getDate(),dateformat,HH:mm}
Will show the time in the correct format such as:
"15:42"
{"time: " + getDate(),dateformat,HH:mm}
Will show the timestamp format like:
"time: 1527676279092"
"Playing" with quotes combinations either ends in syntax errors or misinterpretations.
P.S. There is/are going to be more script involved (like if-statements) so i really need the strings to be inside the script.
{getDate(),dateformat,HH:mm}
Will show the time in the correct format such as:
"15:42"
{"time: " + getDate(),dateformat,HH:mm}
Will show the timestamp format like:
"time: 1527676279092"
"Playing" with quotes combinations either ends in syntax errors or misinterpretations.
P.S. There is/are going to be more script involved (like if-statements) so i really need the strings to be inside the script.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)
Re: Script inside widget script
Oh I see now. You can't concatenate using plus sign (+) anymore. Since the text field itself is already concatenation box.
The reason why your original script evaluated to the one you have is because the concat happen before the dateformat.
{"time: " + getDate(),dateformat,HH:mm}
will be evaluated to
{"time: " + 1527676279092,dateformat,HH:mm}
continued, it is string concatenation
{"time: 1527676279092",dateformat,HH:mm}
since the whole "time: 1527676279092" is a string, not a valid date, nothing will show up when parsed using dateformat, thus retain its original form.
"time: 1527676279092"
You should put your time as here.
time: {getDate(),dateformat,HH:mm}
or if you need the braces, you need double it, each part get its own pair
{"time: "}{getDate(),dateformat,HH:mm}
"time: " can be replaced with if() statement if you want
{if(1==2) true else false} {getDate(),dateformat,HH:mm}
So the braces only surround the one need to be evaluated before showing. "time: " is not needed to be evaluated, need to put outside. All of the pattern format (numberformat, dateformat, listformat etc), may not have concatenation at the beginning part inside the braces, as it will concatenate first before parsed using the pattern format. The concatenation must happen outside of the braces. And you can't concatenate braces inside concat() function when using it in text field,
because you will need nested braces, which is not supported. This happen in all text fields which support variable using curly braces, including : Widget Text, Message Dialog, Notification on Screen (toast message), and a lot of other elements which support variable through curly braces.
However, In scripting box : script, expression, control UI and extra field (Start activity, service, broadcast etc), you can use the pattern format inside concat() (and any other function which require argument), as you don't need braces to surround the concat() (or other function).
The reason why your original script evaluated to the one you have is because the concat happen before the dateformat.
{"time: " + getDate(),dateformat,HH:mm}
will be evaluated to
{"time: " + 1527676279092,dateformat,HH:mm}
continued, it is string concatenation
{"time: 1527676279092",dateformat,HH:mm}
since the whole "time: 1527676279092" is a string, not a valid date, nothing will show up when parsed using dateformat, thus retain its original form.
"time: 1527676279092"
You should put your time as here.
time: {getDate(),dateformat,HH:mm}
or if you need the braces, you need double it, each part get its own pair
{"time: "}{getDate(),dateformat,HH:mm}
"time: " can be replaced with if() statement if you want
{if(1==2) true else false} {getDate(),dateformat,HH:mm}
So the braces only surround the one need to be evaluated before showing. "time: " is not needed to be evaluated, need to put outside. All of the pattern format (numberformat, dateformat, listformat etc), may not have concatenation at the beginning part inside the braces, as it will concatenate first before parsed using the pattern format. The concatenation must happen outside of the braces. And you can't concatenate braces inside concat() function when using it in text field,
Code: Select all
{concat("time: ", "{getDate(),dateformat,HH:mm}"} // is wrong in text field, need nested braces
However, In scripting box : script, expression, control UI and extra field (Start activity, service, broadcast etc), you can use the pattern format inside concat() (and any other function which require argument), as you don't need braces to surround the concat() (or other function).
Code: Select all
text = concat("time: ", "{getDate(),dateformat,HH:mm}") // is correct if used in script action, only single pair of braces
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.
- digitalstone
- Posts: 342
- Joined: 21 Oct 2017 12:36
- Location: The Netherlands
Re: Script inside widget script
Alright, so nested braces inside text fields aren't supported.
In that case i will need to split up my widget element and make them visible/invisible by external means/commands.
Thanks for explaining concatenation problem by taking the logical steps that lead to the point of understanding.
In that case i will need to split up my widget element and make them visible/invisible by external means/commands.
Thanks for explaining concatenation problem by taking the logical steps that lead to the point of understanding.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)