Widget Variables?

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Widget Variables?

Post by digitalstone » 15 Dec 2017 11:38

Say, i'm busy with setting up some widgets.
But why don't they support variables? I suspect there is a good reason for that, but still i'm curious :)
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Widget Variables?

Post by Desmanto » 15 Dec 2017 14:44

Which part that doesn't support variable? You can use curly braces to put the variable to some fields. Example for text, you can put {global_text}, and it will dynamically replaced by the content of variable global_text.
Check my index, flow sharing - windows recognizer for example.

To modify other fields which maybe don't support variable, you can modify them in script, using setWidgetElementProperty(). There are a lot of things you can modify, and you can pass variable to it too. After finish modifying, you can force refresh the widget to get the result immediately.
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.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Widget Variables?

Post by digitalstone » 15 Dec 2017 23:33

in this screenshot it shows that i can't, for example, set the textsize through a variable since it only accepts numeric values.
Width and height of the widget itself as well.

That was what i meant with my original post.

But to answer your post... you're absolutely right.
I just didn't know.
Automagic is just awesome.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Re: Widget Variables?

Post by mbirth » 16 Dec 2017 00:21

digitalstone wrote:Width and height of the widget itself as well.
That's what I'm missing at the moment. I have an overlay widget that should fill the whole screen width. Yet, I can only set it to a fixed size, e.g. 1080px. When I now show it on another of my devices where the screen width is 1280, it only displays with 1080px width. And I can't make it stretch because all calculations are based on the actual pixel width.
BlackBerry KEY2, Android 8.1.0

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Widget Variables?

Post by digitalstone » 16 Dec 2017 05:07

mbirth wrote:
digitalstone wrote:Width and height of the widget itself as well.
That's what I'm missing at the moment. I have an overlay widget that should fill the whole screen width. Yet, I can only set it to a fixed size, e.g. 1080px. When I now show it on another of my devices where the screen width is 1280, it only displays with 1080px width. And I can't make it stretch because all calculations are based on the actual pixel width.
The only solution i can think of (with only hardcoding height and width) is to make the widget something like 5000px squared.... BUT...

Interesting problem:
I can't get the widget to accept a number larger than 1920, on the height OR width setting.
Meaning Automagic knows my screen dimensions and limiting the widget size potential based off of that.
Either Automagic has a build-in mechanism to prevent system override from the Android-side of things.

Either way, i don't know, but this widget width/height solution doesn't feel 'clean-coded'.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Widget Variables?

Post by Desmanto » 16 Dec 2017 09:22

I just realize the maximum widget size is limited to the longest resolution of our phone. I can't set beyond 1920x1920 for Full HD phone. This should be considedered as bug/limitation. As it is possible to design our widget on 800x480 phone, but want to use it in 2560x1440 phone. The action show widget even can be set to higher resolution than our phone, try 20000x20000. So the widget itself should be able to be created higher than that too. If there is size limitation because of hardware limitation, just increase the limit to 4K. (to cover all possible common resolution nowadays).

Using script also cannot change the widget real size, as it deals only with the elements inside.

The other things is the display resolution probably should be automagically retrieved by automagic itself. Maybe we can have new function as getDisplayResolutionWidth() and getDisplayResolutionHeight(). Later, we can put it at the show widget resolution after scaling it to certain number.
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.

User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Re: Widget Variables?

Post by mbirth » 16 Dec 2017 10:51

Another problem is: if you're creating a huuuuuge widget and then scaling it down to the display size: the contents get scaled as well. I'd need a way to programmatically change the "canvas" size to the real screen width and show the widget 1:1. And update width and element width after the orientation changes.
BlackBerry KEY2, Android 8.1.0

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Widget Variables?

Post by digitalstone » 16 Dec 2017 14:11

mbirth wrote: I'd need a way to programmatically change the "canvas" size to the real screen width and show the widget 1:1. And update width and element width after the orientation changes.
I think Desmanto described a solution to this:
Desmanto wrote: The other things is the display resolution probably should be automagically retrieved by automagic itself. Maybe we can have new function as getDisplayResolutionWidth() and getDisplayResolutionHeight(). Later, we can put it at the show widget resolution after scaling it to certain number.
As i'm looking in setting up the widget itself, i understand the initial resolution of the widget itself is needed to determine the original resolution to pass to Android.
Perhaps, i'm not sure, to be handled as a bitmap underneath it all.

Because i'm seeing this also happening in another application (Battery Widget).
It uses "widget size and location", equivalent to post-setting the widget resolution in Automagic with the "Show Custom Widget Overlay" element.
But it also uses an "Widget resolution" option, which can be set to 'Auto'... which is the equivalent of the 'hardcoded' resolution in Automagic, of which the 'Auto' feature implies that the native display resolution can be read no problem since i'm using that app for about 5 years i believe.

I think that Desmanto's idea of "getDisplayResolutionWidth() and getDisplayResolutionHeight()" is very possible.
And also very useful.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Re: Widget Variables?

Post by mbirth » 16 Dec 2017 15:11

digitalstone wrote:I think that Desmanto's idea of "getDisplayResolutionWidth() and getDisplayResolutionHeight()" is very possible.
And also very useful.
It's already possible - I use the Java code from this comment: viewtopic.php?p=19193#p19193

I just can't set the widget's canvas size programmatically. I have to manually edit the widget and change the number (as it's a numeric field, no variables allowed).

And when setting the widget to a fixed size, e.g. 800x4, showing it full-width on a screen with more pixels (e.g. 1600px), scales it - including the height of the bar. My initially 4px thick bar is suddenly 8px thick. I don't want that.
BlackBerry KEY2, Android 8.1.0

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Widget Variables?

Post by digitalstone » 16 Dec 2017 16:26

mbirth wrote:
digitalstone wrote:I think that Desmanto's idea of "getDisplayResolutionWidth() and getDisplayResolutionHeight()" is very possible.
And also very useful.
It's already possible - I use the Java code from this comment: viewtopic.php?p=19193#p19193

I just can't set the widget's canvas size programmatically. I have to manually edit the widget and change the number (as it's a numeric field, no variables allowed).

And when setting the widget to a fixed size, e.g. 800x4, showing it full-width on a screen with more pixels (e.g. 1600px), scales it - including the height of the bar. My initially 4px thick bar is suddenly 8px thick. I don't want that.
Well, you're right.
Enlarging the widget in a post-manner will only scale it with x-amount of procent instead of initializing a new base resolution (or canvas), which will make the internal widget settings, like outline thickness etc, kind of clumsy :oops:
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

Locked