Quick Theme

The right place to talk JavaScript
Post Reply
User avatar
JayM
Posts: 83
Joined: Tue Jan 29, 2019 11:57 pm

Quick Theme

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

This script pulls colors from your wallpaper and let's you choose 1 to set as box background colors on any items that you tell it to.

Script in post #2
Attachments
Screenshot_20200404-191017_Lightning Launcher.jpg
Screenshot_20200404-191017_Lightning Launcher.jpg (644.67 KiB) Viewed 1349 times
Last edited by JayM on Sun Apr 05, 2020 4:45 am, edited 1 time in total.

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

Re: Quick Theme

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

bindClass("android.app.WallpaperManager");
bindClass("android.app.AlertDialog");
bindClass("android.content.DialogInterface");
bindClass("android.widget.LinearLayout");
bindClass("android.widget.LinearLayout.LayoutParams");
bindClass("android.widget.Button");
bindClass("android.view.View");

var VARIABLE = "mycolor"; // Put your Variable name between the quotes
var colors = [];
var pickedColor;
var mctx = LL.getContext();

wallpaperColor();

var adb = new AlertDialog.Builder(mctx);
//adb.setTitle("Quick Theme v2");
adb.setCancelable(true);
var bl = new View.OnClickListener(){

onClick: function(view)
{
switch(view)
{
case b1:
pickedColor = colors[0];
break;

case b2:
pickedColor = colors[1];
break;

case b3:
pickedColor = colors[2];
break;

case b4:
pickedColor = colors[3];
break;

case b5:
pickedColor = colors[4];
break;

case b6:
pickedColor = colors[5];
break;

}

LL.setVariableString(VARIABLE, "c:" + pickedColor);
// Handle Transparency

}

}


// custom view

var ll = new LinearLayout(mctx);
ll.setOrientation(LinearLayout.VERTICAL);
var lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
ll.setLayoutParams(lp);

var b1 = new Button(mctx);
b1.setText("Light Vibrant");
b1.setOnClickListener(bl);
var b2 = new Button(mctx);
b2.setText("Vibrant");
b2.setOnClickListener(bl);
var b3 = new Button(mctx);
b3.setText("Dark Vibrant");
b3.setOnClickListener(bl);
var b4 = new Button(mctx);
b4.setText("Light Muted");
b4.setOnClickListener(bl);
var b5 = new Button(mctx);
b5.setText("Muted");
b5.setOnClickListener(bl);
var b6 = new Button(mctx);
b6.setText("Dark Muted");
b6.setOnClickListener(bl);

ll.addView(b1);
ll.addView(b2);
ll.addView(b3);
ll.addView(b4);
ll.addView(b5);
ll.addView(b6);
adb.setView(ll);

return adb.create().show();

function wallpaperColor()
{
try {
    // extract the wallpaper bitmap
    var wp = WallpaperManager.getInstance(mctx).getDrawable();
    var bitmap = wp.getBitmap();
    Palette.generateAsync(bitmap, {
         onGenerated: function(palette) {
colors.push(palette.getLightVibrantColor([0]));
colors.push(palette.getVibrantColor([1]));
colors.push(palette.getDarkVibrantColor([2]));
colors.push(palette.getLightMutedColor([3]));
colors.push(palette.getMutedColor([4]));
colors.push(palette.getDarkMutedColor([5]));
b1.setBackgroundColor(colors[0]);
b2.setBackgroundColor(colors[1]);
b3.setBackgroundColor(colors[2]);
b4.setBackgroundColor(colors[3]);
b5.setBackgroundColor(colors[04]);
b6.setBackgroundColor(colors[05]);

         }
    }).execute(null);
} catch(e) {
e.printStackTrace();
    // no bitmap or OOM
}

}

Post Reply