This is a small script I made myself to make better use of the new material effect, but this can be used in other…

This is a small script I made myself to make better use of the new material effect, but this can be used in other things too.

The script provided is made so it takes the average color of the icon of an item, and apply it to the selected color (configurable). You can use it on an item (running it from the item) or in all items in a container (running it from the container).

The script consist of a function (that you can use for other things if you want) that takes an image and a number, and returns the exact average color of the image (using all pixels, half of them,…depends on the number). It can take time, specially with high resolution ones and using all the pixels.

If you just want to get the color and don’t change it in a while, use all pixels (resolution=1), but if you plan to implement it dynamically, better use less pixels (resolution=66 means approximately 100/66=1.5% of the pixels)

Note: in the video that was my testing desktop, and there were other items out of view. The process is slow, but no so much.

Anyway you can change the resolution settings and it will be faster (but less precise)

]]>

7 Commentsto This is a small script I made myself to make better use of the new material effect, but this can be used in other…

  1. Anonymous says:

    < ![CDATA[

    var applyto=”s”;//combination of ‘n’ ‘s’ ‘f’ , normal selected focused respectively


    var resolution=1;//number of pixels that will be used. 1=all, 2=half, 3=third part, and so on




    var item=LL.getEvent().getItem();


    var cont=LL.getEvent().getContainer();



    if(!confirm(“This will set the color of “+(item!=null?”the item”:”all the items in the container”)+”\nThis can take a while, are you sure?”)) return




    if(item!=null)


    colorize(item);


    else{


    var items=cont.getItems();


    for(var t=0;t


    if(items.getAt(t).getType()!=”Shortcut”) continue;


    colorize(items.getAt(t));


    }


    }






    function colorize(item){


    if(item.getType()!=”Shortcut”) return;


    var pic=item.getCustomIcon()||item.getDefaultIcon();



    if(pic==null) return;



    pic = pic.getBitmap();



    var prop=item.getProperties().edit()


    prop.getBox(“i.box”).setColor(“c”,applyto,mainColor(pic,resolution))


    prop.commit();



    }





    function mainColor(pic,skip){



    var siz=[pic.getWidth(),pic.getHeight()];



    //color values


    var r=0;


    var g=0;


    var b=0;


    //number of data (decimal values depending on alpha)


    var n=0;



    for(var t=Math.round((siz[0]%skip)/2);t


    for(var tt=Math.round((siz[1]%skip)/2);tt



    var c=pic.getPixel(t,tt);


    var a=Color.alpha(c)/255;



    r+=Color.red(c)*a;


    g+=Color.green(c)*a;


    b+=Color.blue(c)*a;


    n+=a;



    }



    return Color.argb(0xff,Math.round(r/n),Math.round(g/n),Math.round(b/n));



    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Cool you should put in a progress dialog or a toast so the user knows its going to take a while after they hit accept.



    Edit I mean so they know something’s happening after they hit accept because in the video it seems like it froze/not responding.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    In general any action taking longer than 10 seconds should not be done on the UI thread, otherwise it may cause an ANR error.

    ]]>

  4. Anonymous says:

    < ![CDATA[

    However, as it is now it doesn’t make any error.


    But if I set it with timeouts, it does.



    Lukas, what do you recommend me to do here?

    ]]>

  5. Anonymous says:

    < ![CDATA[

    TrianguloY​ MultiTool line 767 ++

    ]]>

  6. Anonymous says:

    < ![CDATA[

    And yes, LL seems to handle long actions quite good. I think I never saw a ANR caused by a script. Still, a frozen screen may make the user think that it is stuck.

    ]]>

  7. Anonymous says:

    < ![CDATA[

    For very long and unbreakable operations you may possibly create a thread, although this is touchy: LL APIs are not thread safe, nor are Android UI components. You need to use an instance of Handle.

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *