fillcolor of widget not in hex code format

Post your questions and help other users.

Moderator: Martin

Post Reply
vamzicool
Posts: 67
Joined: 29 Dec 2014 17:47

fillcolor of widget not in hex code format

Post by vamzicool » 19 Nov 2017 06:37

I am using a widget to do an action. I change the color of the widget from green to orange depending on the event sensitive action. so i decide on the action to be done based on the color of the widget. But when i try to get the fillcolor of the background property of the widget instead of giving an hex code value , a negative integer is returned. Why is this negative integer returned for fillcolor? Or if this is the correct value how do i convert it into hex code color value. The hex code i need is for green color "#ff00ff00" and but the value returned is -16711936. Kindly help, i'm stuck.

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

Re: fillcolor of widget not in hex code format

Post by Desmanto » 19 Nov 2017 12:33

I also use the same green for my multi trigger widget. It also return the exact value as yours. -16711936 is signed integer. If you convert it in calc or any hex program, you will get #ff00ff00
I forgot to ask about the hex to dec conversion. It seems there is no way we can convert binary to decimal to hexadecimal back-thru. Should request this function later.

The value is correct, it is just automagic show them in decimal form. To get each color part, you can break down the each color byte.

Code: Select all

x = getWidgetElementProperty("Multi Trigger", "Background", "fillcolor"); // x = -16711936 (green)
a = getAlpha(x); // a = 255 = ff (opacity), ff means full, 00 means transparent
r = getRed(x); // r = 0 = 00
g = getGreen(x); // g = 255 = ff (green)
b = getBlue(x); // b = 0 = 00 
the problem now is how to convert 255 to ff and vice versa. There is no direct function in the script (or maybe I miss it too).

If you just need to check for the color, just check if the fillcolor is -16711936, is the same as checking if the color is green.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190829, Pie 9.0, Rooted.

vamzicool
Posts: 67
Joined: 29 Dec 2014 17:47

Re: fillcolor of widget not in hex code format

Post by vamzicool » 19 Nov 2017 13:56

Thank you Desmanto. Yes I'm now just checking whether the value returned matches that value to know it's green. :-)

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

Re: fillcolor of widget not in hex code format

Post by Desmanto » 20 Nov 2017 06:54

Yesterday I am thinking about creating the set function to convert from hexadecimal to decimal and vice versa. The concept will be using list and map and lookup each value from the modulus result. Loop until it can't be divided anymore. Then we can use eval() method to pack it to single function. It was a nice logic exercise. And before I continue further, I scroll check all automagic function if there is some function that I miss. Scrolling until the end, just realize there is java function.

A little googling on how to convert dec to hex and vice versa, shows up the method needed. So here it is.

Code: Select all

x = -16711936;
tohex = callJavaStaticMethod("java.lang.Integer", "toHexString(int)", x); // convert dec to hex

hex = "ff00ff00";
todec = callJavaStaticMethod("java.lang.Long", "parseLong(java.lang.String, int)", hex, 16); // convert hex to dec
Concat the # (hash) if you need exactly as shown in widget color.

Next time, I should check with java for any additional extended function. Basically automagic can do what java can do.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), Resurrection Remix Official 7.0.2 20190829, Pie 9.0, Rooted.

vamzicool
Posts: 67
Joined: 29 Dec 2014 17:47

Re: fillcolor of widget not in hex code format

Post by vamzicool » 20 Nov 2017 13:55

This is quite nice. Now I know How to extend the functionality of Automagic with Java function calls. Thanks a lot.

Post Reply