User Tools

Site Tools


script_palette

====== About the script ====== * Purpose : set the background color of an item with colors extracted from the wallpaper * Author : Pierre Hébert ====== How to use the script ====== Make sure you run Lightning v12.4b2 or newer. Import the script and set its "Item menu" flag. Long tap on an item, select Action -> Scripts and tap on this script. This is a sample code demonstrating the use of the Android Palette API. It will compute colors asynchronously and use the result. ====== Script code ====== <sxh javascript> LL.bindClass("android.app.WallpaperManager"); try { // extract the wallpaper bitmap var wp = WallpaperManager.getInstance(LL.getContext()).getDrawable(); var bitmap = wp.getBitmap(); Palette.generateAsync(bitmap, { onGenerated: function(palette) { var item = LL.getEvent().getItem(); var ed = item.getProperties().edit(); var box = ed.getBox("i.box"); box.setColor("c", "n", palette.getMutedColor(0)); box.setColor("c", "s", palette.getLightMutedColor(0)); ed.setString("i.selectionEffect", "PLAIN"); ed.commit(); } }).execute(null); } catch(e) { e.printStackTrace(); // no bitmap or OOM } </sxh>

script_palette.txt · Last modified: 2015/04/03 08:37 by pierrox