Page 1 of 1

set background color of "box" using variable

Posted: Wed Mar 18, 2020 12:01 am
by jalanchilo
I want to set the "box" background color to a variable that can be changed using a shortcut. how would I do that? Could I do it through a binding? I'm trying to use it to create themes for my layout.

Re: set background color of "box" using variable

Posted: Thu Mar 26, 2020 2:41 pm
by JayM
load up script editor and paste this code

LL.setVariableString("mycolor", "c:" + LL.pickColor("Set Background Color", 0xffffffff, true));

Now go into the bindings tab for each item you want to use this color and add a new binding set the property to box and value to $mycolor. The box property syntax is explained here.

https://www.lightninglauncher.com/wiki/ ... ndings_box

Re: set background color of "box" using variable

Posted: Wed Apr 01, 2020 7:47 am
by jalanchilo
Thanks. The script works.

Re: set background color of "box" using variable

Posted: Thu Apr 02, 2020 12:10 pm
by JayM
Cool, i made a quick update to the script so it can also pull color from the wallpaper for now it only gets the dark muted color because I found this to work the best for my setup and tbh the community's kinda dead so didn't think many people would be using it anyways, but it's easy to modify to get other colors even if you don't know Javascript, cheers to the dev for the sample code 👍

If you wanna edit the code for other colors and don't know JS
the following colors are supported.

Light Vibrant
Vibrant
Dark Vibrant
Light Muted
Muted
Dark Muted

link here for more info and examples httpss://developer.android.com/training/material/palette-colors

all you need to do is change the line that says palette.getDarkMutedColor() to something like palette.getGetLightMutedColor() or palette.getVibrantColor()

LL.bindClass("android.app.WallpaperManager");

var choice = parseInt(prompt("1. Extract color from wallpaper\n2. Use a custom hex color", ""));

switch(choice)
{
case 1:
wallpaperColor();
break;

case 2:
customColor();
break;
}

function wallpaperColor()
{
 
try {
    // extract the wallpaper bitmap
    var wp = WallpaperManager.getInstance(LL.getContext()).getDrawable();
    var bitmap = wp.getBitmap();
    Palette.generateAsync(bitmap, {
         onGenerated: function(palette) {
LL.setVariableString("mycolor", "c:" + palette.getDarkMutedColor([0]));
         }
    }).execute(null);
} catch(e) {
e.printStackTrace();
    // no bitmap or OOM
}

}


function customColor()
{
LL.setVariableString("mycolor", "c:" + LL.pickColor("Set Box Background Color", 0xffff5722, true));
}

Re: set background color of "box" using variable

Posted: Thu Apr 02, 2020 5:27 pm
by jalanchilo
Once again it works. I'd love to understand javascript, but for some reason I just never could get the hang of it. I learned how to do basic stuff like window.alert("hello world"); but that's about it. One more question. Does the script support transparency?

Re: set background color of "box" using variable

Posted: Fri Apr 03, 2020 1:31 pm
by JayM
I got into it when the dev added scripting to the launcher so my skills are pretty basic, it doesn't support transparency because I couldn't figure out how I'd go about doing it from what I read here https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4 I'd just need to swap the first 2 characters of the hex color code with 2 from the alpha but when i tested that it was giving me wrong results. I think il rewrite this script anyways and try a different way, I'd like to build a nice UI that shows previews of the wallpaper colors.

Re: set background color of "box" using variable

Posted: Fri Apr 03, 2020 4:11 pm
by jalanchilo
You've still been very helpful. You know more than I do. I wouldn't have a script at all on my own, so thank you.

Re: set background color of "box" using variable

Posted: Sat Apr 04, 2020 2:46 am
by JayM
here's a look at the new version hopefully I can get the transparency working.

Re: set background color of "box" using variable

Posted: Sat Apr 04, 2020 2:50 am
by jalanchilo
I like it.

Re: set background color of "box" using variable

Posted: Sat Apr 04, 2020 6:30 pm
by JayM
Still can't get transparency to work but I'm not giving up yet and I'm gonna upload the script before I lose it. I made a couple changes to its appearance so more of the desktops visible and easier to use, simply edit line 11 with your variables name.

Uploaded here if you wanna try it out viewtopic.php?f=14&t=1004