TrianguloY
now browsing by tag
Label Case switcher
Just a fast script that will change the labels of all the items in the app drawer (or a custom container if necessary, ask about)
The change can be done permanently or just visual (a restart will change them back)
Available types: ( you can write your own one if you know scripting)
– UPPER CASE
– lower case
– Sentence case
– Title Case (from http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript)
(Note: sorry for the lack of posts, in fact I have a lot of scripts I’m working on, but my free time has decrease suddenly, maybe in summer)
———————————————–
var container = LL.getContainerById(99);//LL.getEvent().getContainer();
var permanent = confirm(“Permanent change?”);
var type = parseInt(prompt(“1- UPPER CASE\n2- lower case\n3- As a sentence\n4- Title Case”,0));
run(container);
Android.makeNewToast(“Done”,true).show();
function run(cont){
var items = cont.getItems();
for(var i=items.getLength()- 1;i>=0; –i){
var item=items.getAt(i);
item.setLabel(change(item.getLabel()),permanent);
if(item.getType()==”Folder”||item.getType()==”Panel”)run(item.getContainer());
}
}
function change(label){
var ret=label;
switch(type){
case 1: ret=ret.toUpperCase(); break;
case 2: ret=ret.toLowerCase(); break;
case 3: ret=
ret.charAt(0).toUpperCase() + ret.substring(1,ret.length).toLowerCase(); break;
case 4: ret=ret.split(” “).map(function(i){return i[0].toUpperCase() + i.substring(1)}).join(” “);
break;
//Write here your custom label changer
}
return ret;
}
]]>Change the home page of a desktop (not the home desktop)
From a previous post, and improving my script with Lukas Morawietz vertical idea.
This is a script that move all the items in a container so the home page change.
Instructions:
– Copy paste this script as a new one, and check ‘appear in lightning menu’
– long click the background of the container you want to change, scripts, run this script.
– input the position of the new home desktop, this can be a bit confusing, I hope the pop-up helps you. You can also scroll to the desired home desktop, it will be detected and shown as default in the inputs.
If the number of cells don’t fit the screen (for example if the cells have a fixed size) you will be warned to exit.
Horizontal pinned items are not moved horizontally. The same with verticals and both.
I didn’t have so much time to test, if you can and you discover a bug please comment here. Thanks.
——————————————
var cont = LL.getEvent().getContainer();
var items=cont.getItems();
var distX=cont.getWidth();
var distY=cont.getHeight();
var cellsFloatX=distX/cont.getCellWidth();
var cellsFloatY=distY/cont.getCellHeight();
var cellsX=Math.round(cellsFloatX);
var cellsY=Math.round(cellsFloatY);
if(Math.abs(cellsFloatX-cellsX)>0.00001)if(!confirm(“Warning, the cells don’t fill the screen as an exact horizontal number.\nDo you want to continue?”))return;
if(Math.abs(cellsFloatY-cellsY)>0.00001)if(!confirm(“Warning, the cells don’t fill the screen as an exact vertical number.\nDo you want to continue?”))return;
var moveX = parseInt(prompt(“Which page do you want to be the home one? (horizontal)(left ones are negative)”,Math.round(cont.getPositionX()/distX))) || 0;
var moveY = parseInt(prompt(“Which page do you want to be the home one? (vertical)(top ones are negative)”,Math.round(cont.getPositionY()/distY))) || 0;
if(moveX==0&&moveY==0)return;
for(var i=items.getLength() – 1;i>=0; — i){
var item=items.getAt(i);
var prop=item.getProperties()
var xx=1;
var yy=1;
var pinmode = prop.getString(“i.pinMode”);
if(pinmode==”X”)xx=0;
else if(pinmode==”Y”)yy=0;
else if(pinmode==”XY”)xx=yy=0;
if(prop.getBoolean(“i.onGrid”)){
var cell=item.getCell();
item.setCell(cell.getLeft() – cellsX * moveX * xx,cell.getTop() – cellsY * moveY * yy,cell.getRight() – cellsX * moveX * xx ,cell.getBottom() – cellsY * moveY * yy);
}else{
item.setPosition(item.getPositionX() – distX * moveX * xx,item.getPositionY() – distY * moveY * yy);
}
}
cont.setPosition(cont.getPositionX() – moveX * distX,cont.getPositionY() – moveY * distY,cont.getPositionScale(),false);
]]>Boing and Save and restore position
Boing and Save and restore position
These are two different scripts, but if you want to use the first you will probably use the second.
Boing
This is a script that will move the item from where this script was launched bouncing around the screen.
You need to run it from an action involving an item. I recommend the swipe of the item (in any direction. The starting direction is totally random)
Save and restore position
This is a script that will save only the position x/y of all the items in a container.
It is saved in the container tag, avoid modify it (the script don’t check if the saved tag is the good one)
Just run it from an item in the container, or from the container itself.
Remember that you need to save the position every time a new item is added to the container. Otherwise that item won’t be restored.
I made the script easy to modify to save different data in case you want to edit it yourself.
—————————— Boing
var bounciness = 0.95;//Reduction every tick, between 0 (only one tick) and 1 (always bouncing) [Recommended 0.95]
var frecuency = 60;//ticks per second [Recommended 60]
var event = LL.getEvent();
var cont = event.getContainer();
var item = event.getItem();
if(item==null){alert(“No item attached to this event”); return;}
var vel = [ (Math.random() – 0.5) * cont.getWidth() , (Math.random() – 0.5) * cont.getHeight() ];
var size = [ item.getWidth() * item.getScaleX() , item.getHeight() * item.getScaleY() ]
tick();
function tick(){
//exit statement
if((Math.abs(vel[0])<1 && Math.abs(vel[1])<1)||LL.isPaused()) return;
//Reduction
vel=[ vel[0] * bounciness , vel[1] * bounciness ];
var newpos = [ item.getPositionX()+vel[0] , item.getPositionY()+vel[1] ];
var t;
//right
t=(newpos[0]+size[0]) – ( cont.getPositionX()+cont.getWidth()/cont.getPositionScale() ) ;
if(t>0){newpos[0]-=2 * t;vel[0]= -vel[0];}
//bottom
t=(newpos[1]+size[1]) – ( cont.getPositionY()+cont.getHeight()/cont.getPositionScale() ) ;
if(t>0){newpos[1]-=2 * t;vel[1]=-vel[1];}
//left
t= newpos[0]- cont.getPositionX();
if(t<0){newpos[0]-=2 * t;vel[0]= -vel[0];}
//top
t= newpos[1] – cont.getPositionY();
if(t<0){newpos[1]-= 2*t;vel[1]= - vel[1];}
//set and repeat
item.setPosition(newpos[0] , newpos[1] );
setTimeout(tick,1000/frecuency);
}
————————-Save and restore position
var velocity = 0.2;//The bigger, the faster (between (0,1] )
var frecuency = 60;//ticks per second [Recommended 60]
var cont = LL.getEvent().getContainer(); //The container
var tag = cont.getTag();
if(tag!=undefined){
//With data, hope it is from this script
var data=JSON.parse(tag);
if(confirm(“Restore?”)){
for(var i=data.ids.length – 1;i>=0; –i){
var item= LL.getItemById(data.ids[i]);
//move the item to their position
if(item!=null) move( item , data.posX[i] , data.posY[i] );
}
cont.setPosition(0,0,1,true);//can be omitted
return;
}
}
if(!confirm(“Save?”))return;
//save process
var data=new Object();
data.ids=[];
data.posX=[];
data.posY=[];
var items = cont.getItems();
for(var i=items.getLength() – 1;i>=0; –i){
//save the data of each item
var t = items.getAt(i);
data.posX[i]=t.getPositionX();
data.posY[i]=t.getPositionY();
data.ids[i]=t.getId();
};
//final save
cont.setTag(JSON.stringify(data));
Android.makeNewToast(“Saved “+data.ids.length+” item’s position”,true).show();
//custom lerp. It moves the item a bit and repeat
function move(item,posx,posy){
var xx=posx-item.getPositionX();
var yy=posy-item.getPositionY();
if( (Math.abs(xx)<1 && Math.abs(yy)<1) || LL.isPaused() ){
item.setPosition(posx,posy);
return;
}
xx *= velocity;
yy *= velocity;
item.setPosition( item.getPositionX()+xx , item.getPositionY()+yy );
setTimeout(function(){move(item,posx,posy);},1000/frecuency);
}
]]>Minimalistic page indicator
Minimalistic page indicator
Talking about indicators, I couldn’t stop thinking how to make a script. There is already one in the wiki, but I wanted one a bit more ‘stock’.
I started thinking complex ways of doing it, but then I realize that simplicity is the best in this case.
So I made one in 34 lines of code, easy to understand (this is an objective adjective, I know) and easy to set up.
Important: due to the custom characters I use, the maximum number of pages is 10. However you can change the character as you wish.
Instructions:
– Copy/paste this script as a new one
– Set it to run in the ‘position change’ event of the desktop
– place an item (recommend: shortcut to ‘do nothing’ and pinned) and label it ‘indicator’.
– [Recommended] Check the snap to pages and uncheck ‘fit desktop to items’ in scrolling options.
It automatically adapts to the desktop, for this reason the home page may not be the number 1.
————————————-
//The special characters
var fill = “➊❷❸❹❺❻❼❽❾❿”;
var empty = “①②③④⑤⑥⑦⑧⑨⑩”;
//Vars
var cont = LL.getEvent().getContainer();
var width=cont.getWidth();
var left = Math.round(cont.getBoundingBox().getLeft()/width);
var right = Math.round(cont.getBoundingBox().getRight()/width)-1;
var page = Math.round(cont.getPositionX()/width);
//With zoom –> no page selected
if(cont.getPositionScale()!=1) page=NaN;
var ind = “”;
var flag=false;
//if more pages, just show “…”
if(right-left+1>empty.length){
right=left+empty.length-1;
flag=true;
}
//indicator
for(var i=0;i<=right-left;++i)ind+=(left+i==page?fill[i]:empty[i]);
if(flag)ind+=”…”;
//apply
try{ item=cont.getItemByLabel(“indicator”).setLabel(ind);
}catch(e){
alert(“Item not found. You need to label an item ‘indicator'”);
}
]]>Can someone reproduce this?
Can someone reproduce this?
You will need a tablet, a device which ‘normal’ position is in lansdcape.
Set the desktop rotation to system default. (And enable the rotation in the device)
Rotate the tablet into portrait.
Go to lightning settings, desktop settings, any setting (just enter the settings)
Then go back to the desktop.
Now, in my tablet the whole desktop gets rotated, as in landscape, but the device is in portrait so it gets cutted.
To fix just rotate the tablet to landscape again.
Strange, very strange…and I discover it now…….I always use my tablet in landscape :P
]]>I think this is a bug, but I can be wrong.
If you set the tap action of the items in a container (the general settings of the container) it is applied for all items.
The problem? Panels are also items, and they don’t have visible this actions so you can’t modify it. The tap action is always executed.
(I guess it happens too with the other actions, but tap is the one I tested)
]]>Strange things happens with LL.runScript():
Steps:
Make two scripts, set a custom script tag for both (“scriptA” and “scriptB” respectively, this won’t change)
The script A is:
LL.runScript(“script B”,””);
alert(LL.getScriptTag());
alert(LL.getScriptTag());
The script B is:
var flag = true//false
if(flag)alert(“dummy alert”);
If flag=false
There is shown two alerts with title ‘script A’ and content ‘scriptA’. All ok.
If flag=true
There is shown two alerts, the first with title ‘script A’ and content ‘scriptA’ … but the second with title ‘script B’ and content ‘script B’!!!
The rest of the script is executed as if it were the script B, even thought it is the script A. And what happened with the dummy alert?
Can you reproduce this?
]]>Holes
Holes
This is a script that will move a panel to the opposite of the desktop, to give the illusion that it is a hole.
Check the video to better understanding. It is difficult to understand I know, but the fact is that both are panels, both are placed relative to the screen, not the desktop. That’s why it makes the illusion of holes, but they are panels!
It works also with zoom, and it move all the panels labeled “Hole” in the container.
It works also with panels inside folders, panels inside panels, etc. But to avoid misunderstanding the instructions says ‘desktop’ for the parent and ‘panels’ for the child panels it has.
Have in mind that you will be able to see only the main page of the panel, it’s recommended to check ‘use desktop size’ under layout on the panels settings. This will help you setting it.
Instructions:
– Copy/paste this script as a new one.
– Set it to run on the position change event of the desktop. Only the desktop, NOT the panels!
– Label the panels you want to as “Hole”, the others won’t work;
– [Optional] Disable the scrolling of the panels (Scroll direction: No scrolling at all)
– [Optional] Check the no scroll limit of the desktop, disable snap to pages and enable pinch to zoom and diagonal scrolling to move freely the panel.
These last two instructions are just optional, maybe you find an awesome way of using this script without them.
Pierre Hébert: This is the script that shows why you need to round the position, in case you want to test.
There is also another bad behavior that is shown when using this script. If you zoom the desktop, the panel will unzoom, but in edit mode the grid lines and the helpers are really really big, because the panel think it is really big (and it is, but not for the user). Not exactly a bug, but maybe you can think in this to give them an absolute size relative to the screen, not the container and their zoom.
——————————
//Vars
var desk =LL.getEvent().getContainer();
var scale = desk.getPositionScale();
var items=desk.getItems();
//for each item
for(var i=items.getLength()-1;i>=0;–i){
var panop = items.getAt(i);
if(panop.getLabel()!=”Hole” || panop.getType()!=”Panel”)continue;//only panels labeled “Hole”
var pan=panop.getContainer();
//Relative position
var posX= Math.round(panop.getPositionX())-desk.getPositionX();
var posY= Math.round(panop.getPositionY())-desk.getPositionY();
//The offset of the position if the panel has margins/borders/padding respectively
//if your pannels don’t have, you can comment this section to avoid extra operations
var prop=panop.getProperties().getBox(“i.box”); posX+=prop.getSize(“ml”)+prop.getSize(“bl”)+prop.getSize(“pl”); posY+=prop.getSize(“mt”)+prop.getSize(“bt”)+prop.getSize(“pt”);
//the final position
pan.setPosition( posX*scale , posY*scale ,1/scale,false);
}
]]>Little bug report.
If, for some reason, you set the scale, the position and/or the skew to NaN (for non programmers: Not A Number) the item disappear.
The only way to get it back is to restart the launcher.
With rotation it makes an error.
With size it just apply the minimum possible size (the same as set to zero)
]]>
D5 Creation