set background color of "box" using variable

This is the place to ask "How do I ...?"
Post Reply
jalanchilo
Posts: 10
Joined: Sun Jan 27, 2019 5:31 pm

set background color of "box" using variable

Post by jalanchilo » Wed Mar 18, 2020 12:01 am

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.

User avatar
JayM
Posts: 78
Joined: Tue Jan 29, 2019 11:57 pm

Re: set background color of "box" using variable

Post by JayM » Thu Mar 26, 2020 2:41 pm

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

jalanchilo
Posts: 10
Joined: Sun Jan 27, 2019 5:31 pm

Re: set background color of "box" using variable

Post by jalanchilo » Wed Apr 01, 2020 7:47 am

Thanks. The script works.

User avatar
JayM
Posts: 78
Joined: Tue Jan 29, 2019 11:57 pm

Re: set background color of "box" using variable

Post by JayM » Thu Apr 02, 2020 12:10 pm

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));
}

jalanchilo
Posts: 10
Joined: Sun Jan 27, 2019 5:31 pm

Re: set background color of "box" using variable

Post by jalanchilo » Thu Apr 02, 2020 5:27 pm

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?

User avatar
JayM
Posts: 78
Joined: Tue Jan 29, 2019 11:57 pm

Re: set background color of "box" using variable

Post by JayM » Fri Apr 03, 2020 1:31 pm

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.

jalanchilo
Posts: 10
Joined: Sun Jan 27, 2019 5:31 pm

Re: set background color of "box" using variable

Post by jalanchilo » Fri Apr 03, 2020 4:11 pm

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.

User avatar
JayM
Posts: 78
Joined: Tue Jan 29, 2019 11:57 pm

Re: set background color of "box" using variable

Post by JayM » Sat Apr 04, 2020 2:46 am

here's a look at the new version hopefully I can get the transparency working.
Attachments
Screenshot_20200404-033207_Lightning Launcher.jpg
Screenshot_20200404-033207_Lightning Launcher.jpg (471.97 KiB) Viewed 44 times

jalanchilo
Posts: 10
Joined: Sun Jan 27, 2019 5:31 pm

Re: set background color of "box" using variable

Post by jalanchilo » Sat Apr 04, 2020 2:50 am

I like it.

User avatar
JayM
Posts: 78
Joined: Tue Jan 29, 2019 11:57 pm

Re: set background color of "box" using variable

Post by JayM » Sat Apr 04, 2020 6:30 pm

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
Attachments
Screenshot_20200404-191017_Lightning Launcher.jpg
Screenshot_20200404-191017_Lightning Launcher.jpg (644.67 KiB) Viewed 33 times

Post Reply