Swipe and launch script

Swipe and launch script

I recently discovered how to trigger the material effect on lightning’s items, and made this little script.

The script is made to be set on the touch event of an item, and will allow to swipe across the items in the same container, selecting/deselecting them as you pass above them, launching when releasing.

Note: it only works if the selection effect is set to material, otherwise nothing will be shown (you can still launch them though). Also, non-clickable items are excluded.

In the video I show the script with a visible item at the bottom, for demonstration. Another option is to make it invisible, and big enough to cover all of the other ones, as if you can press wherever, but releasing will launch (you won’t be able to long tap or scroll this way, don’t make it full screen!).

]]>

One Commentto Swipe and launch script

  1. Anonymous says:

    < ![CDATA[

    bindClass(“android.R”)




    var x = event.getX();


    var y = event.getY();



    switch(event.getAction()) {


    case MotionEvent.ACTION_DOWN:


    pre = null


    //break


    case MotionEvent.ACTION_MOVE:


    var it=getSelected();



    if(it==null || pre==null || (pre!=null && it.getId()!=pre.getId())){


    if(it!=null){


    select(it);


    }


    if(pre!=null){


    unselect(pre)


    }


    pre=it;


    }



    break;


    case MotionEvent.ACTION_UP:


    case MotionEvent.ACTION_CANCEL:



    var it=getSelected();


    pre = null;


    if(it!=null){


    unselect(it);


    it.launch();


    }



    break;


    default:


    alert(event.getAction())


    }



    return true;





    function getSelected(){


    var cx = x+item.getPositionX();


    var cy = y+item.getPositionY();



    var items = item.getParent().getItems();


    for(var t=items.length-1;t>=0;–t){


    var it=items.getAt(t);


    if(it.getProperties().getBoolean(“i.enabled“) && it.getId()!=item.getId() && isInside(it,cx,cy)){


    return it;


    }


    }


    return null;


    }





    function isInside(it,cx,cy){


    var bb=[it.getPositionX(),it.getPositionY(),0,0]


    bb[2]=bb[0]+it.getWidth();


    bb[3]=bb[1]+it.getHeight();



    return bb[0]< =cx && cx<=bb[2] && bb[1]<=cy && cy<=bb[3];



    }






    function select(item){


    try{


    item.getRootView().getBackground().setState([ R.attr.state_pressed, R.attr.state_enabled ]);


    }catch(e){}


    }



    function unselect(item){


    try{


    item.getRootView().getBackground().setState([]);


    }catch(e){}


    }

    ]]>

Leave a Reply

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