Carousel folder

Carousel folder

I had the idea of this one since looong time ago, but I forgot it. At that moment I tried to change the z-position of the items to allow ‘rotate’ the items in the folder preview, but it didn’t worked well.

Now with the ability to draw images it was just so easy 😛 so I made it more configurable.

Instructions: Run this script from a folder item (remember to check ‘item menu’ in the script editor) to:

Change the item folder

Set the script to the swipe directions and tap.

Open the folder.

You can optionally pass data to the script to perform this actions:

Launch the first item displayed: “launch” (by default when tap)

Rotate in one direction: “+” (by default swipe left/down)

Rotate in the other direction: “-” (by default swipe right/up)

There are also some settings in the script to change the maximum number of items to show, the size of them and the margin.

The order of the items is the z-position (the same when going into the hierarchy menu)

Note: folders by default have a custom background, you may want to remove it from the item/icon menu.

Enjoy 😀

]]>
« (Previous Post)
(Next Post) »

2 Commentsto Carousel folder

  1. Anonymous says:

    < ![CDATA[

    var displayed=4;//Maximum items displayed at once (minimum 1)


    var b=0.01//border around the item in %


    var wh=0.6//width/height of the items in %



    /*


    Custom data:


    “launch” will launch the first displayed item, at tap action by default


    “+” and “-” will rotate the items list


    (you can use the ‘launch item’ action to open the folder)


    */








    var event=LL.getEvent();


    var it=event.getItem();


    if(it==null||it.getType()!=”Folder”){


    alert(“This need to be launched from a folder’s item”);


    return;


    }



    //vars


    var cont=it.getContainer();


    var items=cont.getItems();


    var n=items.getLength();



    //get data


    var k=parseInt(it.getTag(“carousel”))||0;



    var size=Math.min(displayed,n);



    //icon


    var img=copyImage(it.getDefaultIcon());


    var canv=img.draw();



    //source


    var dir=event.getSource();


    var dat=event.getData();



    if(dir==”I_CLICK”||dat==”launch”){items.getAt(k).launch();return;}


    if(dir==”MENU_ITEM”){


    if(!menu())return;


    }



    if(dat==”+”||(dat==null&&(dir==”I_SWIPE_LEFT”||dir==”I_SWIPE_DOWN”)))++k;


    if(dat==”-“||(dat==null&&(dir==”I_SWIPE_RIGHT”||dir==”I_SWIPE_UP”)))–k;



    k=(k+n)%n;



    //vars


    var r=(1-wh-2*b)/Math.max(1,size-1);


    var paint=Paint(Paint.FILTER_BITMAP_FLAG);//ANTI_ALIAS_FLAG);



    LL.bindClass(“android.graphics.Rect”);



    //draw


    for(var i=size-1;i>=0;–i){



    var item=items.getAt((k+i)%n);


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


    if(bit==null){continue;}


    bit=bit.getBitmap();



    var rr=r* i;


    var rect=Rect(canv.getWidth()* (b+rr),canv.getHeight()* (1-b-wh-rr),canv.getWidth()* (b+wh+rr),canv.getHeight()* (1-b-rr));


    canv.drawBitmap(bit,null,rect,paint);



    }



    //final


    it.setCustomIcon(img);


    it.setTag(“carousel”,k);



    //end of script






    function menu(){



    if(!confirm(“Accept to configure the item\nCancel to open the folder”)){


    it.open();


    return false;


    }



    if(confirm(“Do you want to choose another image as the folder’s icon background? Will override the default previous icon.\n(a null image will set a transparent one)”)){



    var newimg=LL.pickImage(img.getWidth()*img.getHeight());



    if(newimg==null){


    newimg=LL.createImage(img.getWidth(),img.getHeight());


    }



    it.setDefaultIcon(newimg);


    img=copyImage(it.getDefaultIcon());


    canv=img.draw();




    }



    if(confirm(“Do you want to set this script to the four swipe directions of this item and the tap action?”)){



    var id=LL.getCurrentScript().getId();


    var prop=it.getProperties().edit();


    for(var t=0;t<5;++t){


    prop.setEventHandler([“i.swipeLeft”,”i.swipeRight”,”i.swipeUp”,”i.swipeDown”,”i.tap”][t],EventHandler.RUN_SCRIPT,id);


    }


    prop.commit();



    }



    return true;


    }








    //helpers


    function copyImage(src){


    var bmp_orig = src.getBitmap();



    var img_copy = LL.createImage(bmp_orig.getWidth(), bmp_orig.getHeight());


    img_copy.draw().drawBitmap(bmp_orig, 0, 0, null);


    img_copy.update();


    return img_copy;


    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Wow. Very impressive

    ]]>

Leave a Reply

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