This is something I had since long time ago (almost 3 months now)

This is something I had since long time ago (almost 3 months now)

I never published it because I didn’t like how it is done (the code is a bit messy) but with some little changes I made recently I think it’s time to do so.

This script moves the items of the desktop based on Lagrange interpolation.

You specify data of an item in some pages and it will move smoothly from one to another.

It is made as efficient as possible. No saved data is not counted, and even with so much pages saved it should be unnoticeable. (Of course this depends on the device)

To use it only set it in the position change event of the desired container. Then save the data of each item (one by one, sorry) as seen in the video.

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

21 Commentsto This is something I had since long time ago (almost 3 months now)

  1. Anonymous says:

    < ![CDATA[

    var extrapolate=false;//set this to true to extrapolate





    //clases


    LL.bindClass(“android.app.AlertDialog”);


    LL.bindClass(“android.content.DialogInterface”);



    //vars


    var event=LL.getEvent();


    var item=event.getItem();


    var cont=event.getContainer();


    var source=event.getSource();



    //the list of parameters


    var parameters = [“Position X”,”Position Y”,”Rotation”,”Scale X”,”Scale Y”,”Alpha”,”Width”,”Height”];



    //vars related to the interpolation data


    var data=JSON.parse(cont.getTag(“intpol”))||{};


    var d;


    var page;


    var flags=[];



    if(source==”C_POSITION_CHANGED”){



    //interpolate


    apply();



    }else if(item!=null){



    //apply settings for the item



    //create the object that will contain the data


    d=(data[item.getId()])||{flags:[],lagrange:[],pages:[]};


    while(d.flags.length


    while(d.pages.length



    //the list of properties


    for(var t in d.flags)flags[t]=d.flags[t];



    choose();



    }else{



    //no item


    alert(“run the script from an item”);


    //prompt(“”,cont.getTag(“intpol”));//for debug



    }





    function choose(){


    //shows the dialogs



    //asks for the page (selected: current)


    var w=cont.getWidth();


    var x=cont.getPositionX();


    var b=cont.getBoundingBox();


    page=w*LL.pickNumericValue(“save for which page? (horizontally, 0 is the main page)”, Math.round(x/w), “FLOAT”, Math.floor(b.getLeft()/w)-1, Math.ceil(b.getRight()/w), 1, “page”);


    if(page==null)return;



    //parameters


    var builder=new AlertDialog.Builder(LL.getContext());


    builder.setTitle(“Choose parameters to save/remove”);


    builder.setMultiChoiceItems(parameters,flags,new DialogInterface.OnMultiChoiceClickListener(){onClick:function(dialog,which,checked){flags[which]=checked;}});


    builder.setNegativeButton(“Cancel”,null);


    builder.setPositiveButton(“Save”,new DialogInterface.OnClickListener(){onClick:save});


    builder.setNeutralButton(“Remove”,new DialogInterface.OnClickListener(){onClick:remove});


    builder.create().show();



    }





    function save(){


    //save the data of the selected parameters


    if(flags[0])d.pages[0][page]=item.getPositionX();


    if(flags[1])d.pages[1][page]=item.getPositionY();


    if(flags[2])d.pages[2][page]=item.getRotation();


    if(flags[3])d.pages[3][page]=item.getScaleX();


    if(flags[4])d.pages[4][page]=item.getScaleY();


    if(flags[5])d.pages[5][page]=item.getProperties().getInteger(“i.alpha”);


    if(flags[6])d.pages[6][page]=item.getWidth();


    if(flags[7])d.pages[7][page]=item.getHeight();



    update();


    }





    function update(){



    //create the polynomial for each animated parameter


    for(var t=0;t


    difdiv(d.pages[t],Object.keys(d.pages[t]).sort(function(a,b){return parseInt(a)-parseInt(b);}),t);


    }



    //save the data


    data[item.getId()]=d;


    cont.setTag(“intpol”,JSON.stringify(data));


    }




    function remove(){


    //removed the data of the selected parameters


    for(var t=0;t


    if(flags[t]) delete d.pages[t][page];


    }



    update();



    }




    function apply(){


    //sets the data when moving the desktop


    var ids=Object.keys(data);


    for(var t=0;t


    var item=LL.getItemById(ids[t]);


    if(item==null){


    //if a saved item is not found, removes the data of that item


    delete data[ids[t]];


    cont.setTag(“intpol”,JSON.stringify(data));


    continue;


    }



    //apply the interpolation


    d=data[ids[t]];



    if(d.flags[6]||d.flags[7])item.setSize(d.flags[6]?intpol(6):item.getWidth(),d.flags[7]?intpol(7):item.getHeight());



    if(d.flags[2])item.setRotation(intpol(2));



    if(d.flags[3]||d.flags[4])item.setScale(d.flags[3]?intpol(3):item.getScaleX(),d.flags[4]?intpol(4):item.getScaleY());




    if(d.flags[0]||d.flags[1])item.setPosition(d.flags[0]?intpol(0):item.getPositionX(),d.flags[1]?intpol(1):item.getPositionY());



    if(d.flags[5])item.getProperties().edit().setInteger(“i.alpha”,intpol(5,0,255)).commit();





    }


    }





    function intpol(prop,min,max){


    //fixed function: based of the saved polynomial returns the value


    var c=cont.getPositionX();


    var index=d.lagrange[prop];


    var n=index[0].length-1;


    if(!extrapolate){


    if(c>index[1][n]) return d.pages[prop][index[1][n]];


    if(c


    }


    var out=index[0][n];


    for(var t=n-1;t>=0;–t){


    out=index[0][t]+(c-index[1][t])*out;


    }


    if(min!=null&&out


    if(max!=null&&out>max)return max;


    return out;


    }





    function difdiv(values,nodes,prop){


    //fixed function: calculates the data of the interpolation polynomial based on the saved data


    var y=[[]];


    var n=nodes.length;



    if(n< =0){


    delete d.lagrange[prop];


    d.flags[prop]=false;


    }else{


    d.flags[prop]=true;


    }



    for(var t=0;t


    y[t]=[];


    y[t][0]=values[nodes[t]];


    }


    for(var k=1;k


    y[i][k]=(y[i+1][k-1]-y[i][k-1])/(nodes[i+k]-nodes[i]);


    }


    if(d.lagrange[prop]==null)d.lagrange[prop]=[];


    d.lagrange[prop][0]=y[0];


    d.lagrange[prop][1]=nodes;



    }





    /*


    data:{


    :{


    flags:[,] //will animate or not


    lagrange:[property]:{


    [0]: d of the polynomial


    [1]: nodes


    }


    pages:[property]{


    [page] value of that property at the current page


    }


    }


    }



    */

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Absolutely stunning.

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Amazing. So cool.

    ]]>

  4. Anonymous says:

    < ![CDATA[

    You never stop to amaze me. Your work is really showing of LLX’s potential, if somebody has some scripting skills

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Wow… is stupend… Congratulation for your Big idea…

    ]]>

  6. Anonymous says:

    < ![CDATA[

    I want to say unbelievable but if TrianguloY​​ name is associated to it, there is no cause to doubt.

    ]]>

  7. Anonymous says:

    < ![CDATA[

    Can’t wait to use this on something! Great work

    ]]>

  8. Anonymous says:

    < ![CDATA[

    Fun use of mathematics!

    ]]>

  9. Anonymous says:

    < ![CDATA[

    very cool

    ]]>

  10. Anonymous says:

    < ![CDATA[

    TrianguloY​ I have a suggestion if it’s no bother. Can you include a way remove an item when you set the alpha property to 0 similar to your dim background script?

    ]]>

  11. Anonymous says:

    < ![CDATA[

    Sergio Azar not sure which script are you talking, but if the item is removed…it will be deleted and won’t go back. I mean it will be a ‘one-slide’ item. Why (and what) do you want exactly?

    ]]>

  12. Anonymous says:

    < ![CDATA[

    Apologies for bumping an older post, but I can’t seem to get this working with the latest version of LLx. I’ve followed all of the steps in the video. Is this method outdated and incompatible with the current version of LLx?

    ]]>

  13. Anonymous says:

    < ![CDATA[

    Technically it should work but I’ll check it.

    ]]>

  14. Anonymous says:

    < ![CDATA[

    Thanks. I’d love to have a home screen built around interpolation.

    ]]>

  15. Anonymous says:

    < ![CDATA[

    I tested it and works.


    Are you sure you:


    Set the script on the position change event?


    Detached the items?


    Can scroll the desktop?

    ]]>

  16. Anonymous says:

    < ![CDATA[

    I’ve detached the items and can scroll the desktop, but how exactly do I set the script on position change event?

    ]]>

  17. Anonymous says:

    < ![CDATA[

    Desktop setting – events & action – position change event – run a script – choose the interpolation script, done.

    ]]>

  18. Anonymous says:

    < ![CDATA[

    That’s it! I think I finally understand how this works now. Thank you very much.

    ]]>

  19. Anonymous says:

    < ![CDATA[

    I can’t seem to get this script to work while scrolling vertical. Is there something I need to change?

    ]]>

  20. Anonymous says:

    < ![CDATA[

    It’s strange I didn’t allow that with a parameter. Probably due to the fact this script was made more than two years ago. Does it still works for you? (I mean, no errors when running?)



    To change the input from a horizontal scroll to a vertical one you need to change one line. Search for the line that says:


    >var c=cont.getPositionX();


    that is just under the intpol function definition (third chunk from the bottom) and change it to


    >var c=cont.getPositionY();

    ]]>

  21. Anonymous says:

    < ![CDATA[

    TrianguloY yep works great. Thanks again

    ]]>

Leave a Reply

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