====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
script_slideshow [2014/04/01 17:22] lm13 [Main Script code] |
script_slideshow [2016/06/28 12:16] (current) f43nd1r |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== About the script ====== | ====== About the script ====== | ||
- | * Purpose : This script will make your container scroll automatically, like a slideshow | + | * Purpose : This script will make your Panel scroll automatically, like a slideshow |
- | * Author : Lukas Morawietz alias LM13 | + | * Author : F43nd1r |
- | * Concept : Pierre Hébert | + | * Idea : Pierre Hébert |
- | * Current Version : 1.0 | + | * Current Version : 3.0 |
+ | * Link : https://plus.google.com/115366157037831519359/posts/84DvszxGQXA | ||
+ | * Video : https://plus.google.com/115366157037831519359/posts/9eUTw8cCCpi | ||
====== Changelog ====== | ====== Changelog ====== | ||
* Version 1.0 (1/4/2014): initial release in wiki | * Version 1.0 (1/4/2014): initial release in wiki | ||
+ | * Version 2.0 (27/7/2014): complete new coded, only one Script | ||
+ | * Version 3.0 (7/9/2014): added vertical support, added desktop support, switched from panelID to itemID | ||
====== How to use the script ====== | ====== How to use the script ====== | ||
- | * set up the configuration at the beginning of both scripts. | + | * set up the configuration at the beginning of the script. |
- | * if you want the slideshow to start automatically, set the main script in the load event of the panel | + | * if you want the slideshow to start automatically, set the script in the resumed and the paused event of the container |
- | * set the toggle script somewhere easy accessible, like swipe down on the panel | + | * if you want to start and stop it manually create a shortcut to the spcript or set it to other events |
- | * every time you perform that action, the slideshow will be turned on/off | + | * every time you perform that action, the slideshow will be toggled |
* watch it sliding! | * watch it sliding! | ||
====== Issues and hints ====== | ====== Issues and hints ====== | ||
- | * be aware, that only pages right from the start page will be reached! Pages on the other sides may break the script. | + | * if something goes wrong, first to try is restart launcher |
- | ====== Main Script code ====== | + | //please report all bugs in the g+ community// |
- | <code>//config | + | |
- | var panel_label="Slideshow"; | + | ====== Script code ====== |
- | var this_scripts_name="AutoScroll"; | + | <sxh javascript;>//config |
+ | var waitingTime=3000;//time between page switches, in ms, not exact | ||
+ | var itemID=0x000001;//if you take the ID from hierachy, put a '0x' in front of it, the ID of any item in the container | ||
+ | var notify=false;//mainly for debug, creates toasts with status | ||
+ | var vertical=false;//false for horizontal, true for vertical | ||
//endconfig | //endconfig | ||
- | var d=LL.getHomeDesktop(); | + | //start |
- | var p=d.getItemByLabel(panel_label); | + | if((typeof running==='undefined'||!running)) |
- | var c=p.getContainer(); | + | |
- | var w=p.getWidth(); | + | |
- | c.setTag(0); | + | |
- | var b=c.getBoundingBox(); | + | |
- | if(b.getRight()==0) | + | |
{ | { | ||
- | setTimeout(LL.runScript(this_scripts_name,null),100); | + | var c=LL.getItemById(itemID).getParent(); |
- | return; | + | if(c==null) |
+ | { | ||
+ | if(notify)Android.makeNewToast("Failed to load panel",true).show(); | ||
+ | return; | ||
+ | } | ||
+ | running=true; | ||
+ | start(); | ||
} | } | ||
- | var num_pages=(b.getRight()-b.getLeft())/c.getWidth(); | + | //stop |
- | + | else | |
- | var rotate = function() { | + | { |
- | var i=parseInt(c.getTag()); | + | running=false; |
- | if(i==-1)return; | + | |
- | c.setPosition(i*w, 0); | + | |
- | if(i==num_pages-1) i=0; | + | |
- | else i=i+1; | + | |
- | c.setTag(i); | + | |
- | setTimeout(rotate, 5000); | + | |
} | } | ||
- | rotate(); | + | function start() |
- | + | { | |
- | </code> | + | if(!vertical) |
- | + | { | |
- | ====== Toggle Script code ====== | + | w=c.getWidth(); |
- | <code>//config | + | if(w==0) |
- | var panel_label="Slideshow"; | + | { |
- | var main_scripts_name="AutoScroll"; | + | setTimeout(start,50); |
- | //endconfig | + | return; |
- | + | } | |
- | var c=LL.getHomeDesktop().getItemByLabel(panel_label).getContainer(); | + | box=c.getBoundingBox(); |
- | var i=parseInt(c.getTag()); | + | l=box.getLeft(); |
- | if(i==-1){ | + | d=box.getRight()-l; |
- | Android.makeNewToast("Autoscroll enabled",true).show(); | + | y=c.getPositionY(); |
- | LL.runScript(main_scripts_name,null); | + | } |
+ | else | ||
+ | { | ||
+ | h=c.getHeight(); | ||
+ | if(h==0) | ||
+ | { | ||
+ | setTimeout(start,50); | ||
+ | return; | ||
+ | } | ||
+ | box=c.getBoundingBox(); | ||
+ | t=box.getTop(); | ||
+ | b=box.getBottom()-t; | ||
+ | x=c.getPositionX(); | ||
+ | } | ||
+ | if(notify)Android.makeNewToast("Slideshow started",true).show(); | ||
+ | step(); | ||
} | } | ||
- | else { | + | |
- | Android.makeNewToast("Autoscroll disabled",true).show(); | + | function step() |
- | c.setTag(-1); | + | { |
+ | if(!running) | ||
+ | { | ||
+ | if(notify)Android.makeNewToast("Slideshow stopped",true).show(); | ||
+ | return; | ||
+ | } | ||
+ | if(typeof a==='undefined')a=0; | ||
+ | a+=2; | ||
+ | if(a>=waitingTime) | ||
+ | { | ||
+ | var goTo=(!vertical?((Math.floor(c.getPositionX()/w)*w-l+w)%d+l):((Math.floor(c.getPositionY()/h)*h-t+h)%b+t)); | ||
+ | c.setPosition(vertical?x:goTo,!vertical?y:goTo); | ||
+ | a=0; | ||
+ | } | ||
+ | setTimeout(step,1); | ||
} | } | ||
- | </code> | + | </sxh> |