User Tools

Site Tools


script_multitool

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_multitool [2014/07/28 21:58]
lm13 v1.3
script_multitool [2016/02/09 08:08] (current)
st1d
Line 2: Line 2:
   * Purpose : This script is a multifunctional tool to do or show a lot of stuff   * Purpose : This script is a multifunctional tool to do or show a lot of stuff
   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]
-  * Current Version : 1.3 
   * Link : https://​plus.google.com/​115366157037831519359/​posts/​fQwfu5AUj5m   * Link : https://​plus.google.com/​115366157037831519359/​posts/​fQwfu5AUj5m
- +  ​Download available! ​(Check repository)
-====== Changelog ======  +
-  ​Version 1.0 (20/7/2014): initial release in wiki +
-  * Version 1.1 (21/​7/​2014):​ replaced move item script with trianguloY'​s solution.  +
-  * Version 1.2 (25/​7/​2014):​ replaced change home page with move pages to extend functionality,​ sorted choices on script-side +
-  * Version 1.2.1 (26/​7/​2014):​ added Intent to Item details  +
-  * Version 1.3 (28/​7/​2014):​ fix: no touch data in swipe event, add resize, add save, add containers ID+
  
 ====== How to use the script ====== ====== How to use the script ======
-  * enable the script in any menu or event you want to run it+  * see App
  
 ====== Current functionality ====== ====== Current functionality ======
Line 19: Line 12:
   * Show Container related parameters   * Show Container related parameters
   * Show Item related parameters   * Show Item related parameters
 +  * Show Icons and images for an item
   * Attach/​Detach all Items   * Attach/​Detach all Items
   * Resize all detached items   * Resize all detached items
   * Delete all Items   * Delete all Items
   * Move (a) specific page(s) to another position. This can be used to change the home page by selecting all items   * Move (a) specific page(s) to another position. This can be used to change the home page by selecting all items
-  * Reset Tag+  ​* Export Scripts 
 +  * Import Script 
 +  * Autoformat Script 
 +  * Search in Scripts 
 +  ​* Reset Tags
   * Reset Tool © by trianguloY   * Reset Tool © by trianguloY
   * save all Layout changes   * save all Layout changes
 +  * Reset the recent apps list
  
-====== Issues and hints ====== 
-  * Find the hidden treasure :D 
  
 //please report all bugs in the g+ community// //please report all bugs in the g+ community//
  
-====== ​Script ​====== +<​spoiler|Script ​(won't work without the apk)> 
-<sxh javascript;>​var choice=parseInt(prompt("​What do you want to do?\n1 - Show Event related parameters\n2 - Show Container related parameters\n3 - Show Item related parameters\n4 - Attach/Detach all Items\n5- Resize all detached Items\n6 - Delete all Items\n7 - Move Pages\n8 - Reset Tag\n9 - Reset Tool © by trianguloY\n10 - Save changes",""​));​+<sxh javascript;>/​/​Created ​by Lukas Morawietz in collaboration with TrianguloY
  
 +//import java classes
 +LL.bindClass("​android.app.AlertDialog"​);​
 +LL.bindClass("​android.app.ProgressDialog"​);​
 +LL.bindClass("​android.content.DialogInterface"​);​
 +LL.bindClass("​android.os.Environment"​);​
 +LL.bindClass("​android.R"​);​
 +LL.bindClass("​android.widget.ExpandableListView"​);​
 +LL.bindClass("​android.widget.ImageView"​);​
 +LL.bindClass("​android.widget.LinearLayout"​);​
 +LL.bindClass("​android.widget.ListView"​);​
 +LL.bindClass("​android.widget.NumberPicker"​);​
 +LL.bindClass("​android.widget.SimpleAdapter"​);​
 +LL.bindClass("​android.widget.SimpleExpandableListAdapter"​);​
 +LL.bindClass("​android.widget.ScrollView"​);​
 +LL.bindClass("​android.widget.TextView"​);​
 +LL.bindClass("​java.io.File"​);​
 +LL.bindClass("​java.io.BufferedReader"​);​
 +LL.bindClass("​java.io.FileReader"​);​
 +LL.bindClass("​java.io.FileWriter"​);​
 +LL.bindClass("​java.util.HashMap"​);​
 +LL.bindClass("​java.util.ArrayList"​);​
  
-switch(choice) + 
- +var hasItem=(LL.getEvent().getItem()!=null)
- case 1: + 
- var e=LL.getEvent()+//define Strings to display 
- try +var title="What do you want to do?"; 
-+var items=[] 
- e.getTouchScreenX()+var info=["Information",[]]; 
- var ok=true+info[1].push("Event")
- } +info[1].push("Container") 
- catch(Exception) +if(hasItem){ 
- +    ​info[1].push("Item"); 
- var ok=false; +    ​info[1].push("Intent"); 
-+    ​info[1].push("Icon"); 
- alert("Source: "​+e.getSource()+"​\nDate:​ "​+e.getDate()+"​\nContainer:​ "​+e.getContainer()+"​\nItem:​ "​+e.getItem()+(ok?("\nTouch: "​+e.getTouchX()+","​+e.getTouchY()+"​\nTouch (Screen): "​+e.getTouchScreenX()+","​+e.getTouchScreenY()):""​))+
- break; +var itemUtils=["Item Utilities",[]]; 
- case 2: +itemUtils[1].push("​Attach/​Detach all Items"); 
- var c=LL.getEvent().getContainer();​ +itemUtils[1].push("Resize all detached Items"); 
- var t=c.getType();​ +itemUtils[1].push("Delete all Items"); 
- alert("Type: "​+t+"​\nName/​Label:​ "​+(t=="​Desktop"?​c.getName():​c.getOpener().getLabel())+"​\nID:​ "​+c.getId()+"​\nTag:​ "​+c.getTag()+"​\nSize:​ "​+c.getWidth()+","+c.getHeight()+"\nBoundingbox: ​"+c.getBoundingBox()+"​\nCell Size: "+c.getCellWidth()+","+c.getCellHeight()+"​\nCurrent Position: "​+c.getPositionX()+","​+c.getPositionY()+"​\nCurrent Scale: "​+c.getPositionScale()+"​\nItems:​ "​+c.getItems());​ +itemUtils[1].push("Move Pages"); 
- break; +var scriptUtils=["​Script Tools",​[]]
- case 3: +scriptUtils[1].push("​Export Scripts ​(Backup)"); 
- var i=LL.getEvent().getItem(); +scriptUtils[1].push("Import Script"); 
- alert(i==null?"​no item found":"​Label:​ "+i.getLabel()+"\nType: ​"+i.getType()+"​\nTag:​ "​+i.getTag()+"​\nID:​ "​+i.getId()+"​\nSize:​ "​+i.getWidth()+","​+i.getHeight()+"​\nPosition:​ "​+i.getPositionX()+","​+i.getPositionY()+"​\nScale:​ "​+i.getScaleX()+","​+i.getScaleY()+"​\nAngle:​ "​+i.getRotation()+"​\nCenter:​ "​+center(i)+(i.getType()=="​Shortcut"?"​\nIntent:"​+i.getIntent():""​)); +scriptUtils[1].push("Autoformat Scripts"); 
- break; +scriptUtils[1].push("Search in Scripts"); 
- case 4: +var other = ["Other",​[]];​ 
- var items=LL.getEvent().getContainer().getItems();​ +other[1].push("Reset Tag")
- var togrid=confirm("Attach? if not, detach"); +other[1].push("Reset Tool"); 
- for(x=0;​x<​items.length;​x++) +other[1].push("Save changes"); 
-+other[1].push("Delete recent app history"); 
- var i=items.getAt(x);​ +items.push(info); 
- i.getProperties().edit().setBoolean("i.onGrid",​togrid).commit(); +items.push(itemUtils); 
- +items.push(scriptUtils); 
- break; +items.push(other); 
- case 5: + 
- try + 
-+//normal run 
- var s=JSON.parse("​["+prompt("which size? (input like width,height)",""​)+"​]")+if(typeof resultCode==='​undefined'​expandableList(items,​mainOnClick,​title); 
- var items=LL.getEvent().getContainer().getItems(); +//user has selected a file to import 
- for(var a=0;​a<​items.length;​a++) +else import_handleInput(); 
- items.getAt(a).setSize(s[0],​s[1]); + 
-+//handle user selection 
- catch(Exception) +function mainOnClick(groupPosition,​childPosition)
-+ switch(groupPosition)
- Android.makeNewToast("Invalid input",​true).show(); + case 0://​Information 
- + switch(childPosition){ 
- break; + case 0://Event related 
- case 6: +     eventData()
- if(confirm("Are you sure?")) + break
-+ case 1://​container related 
- var c=LL.getEvent().getContainer(); +     containerData() 
- var i=c.getItems(); + break
- for(a=0;​a<​i.length;​a++) + case 2://item related 
- c.removeItem(i.getAt(a));​ +     itemData(); 
-+ break
- case 7: + case 3://intent 
- var cont=LL.getEvent().getContainer()+     intentData(); 
- var items=cont.getItems(); + break; 
- var cwidth=cont.getWidth()+ case 4://icon 
- var cheight=cont.getHeight(); +     iconData(); 
- var cellsFloatX=cwidth/​cont.getCellWidth();​ + break;
- var cellsFloatY=cheight/​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+
- try +
-+
- var s=prompt("​Which page do you want to move? (* for all) input has to be x,y (e.g. *,* for all pages)",""​).split(","); +
- var move=JSON.parse("​[\""​+s[0]+"​\",\""​+s[1]+"​\"​]")+
- var done=true;​ +
-+
- catch(Exception) +
-+
- var done=false;​ +
-+
- if(!done||move==null||move[0]==null||(move[0]!="*"&&​isNaN(parseInt(move[0])))||move[1]==null||(move[1]!="​*"&&​isNaN(parseInt(move[1])))) +
-+
- Android.makeNewToast("Invalid input",​true).show(); +
- return; +
-+
- if(move[0]!="*")move[0]=parseInt(move[0]); +
- if(move[1]!="*")move[1]=parseInt(move[1]); +
- try +
-+
- var dist=JSON.parse("​["​+prompt("​How far do you want to move? input has to be x,y (e.g. 1,0 for one page right)",""​)+"​]"​); +
- var done=true;​ +
-+
- catch(Exception) +
-+
- var done=false+
- +
- if(!done||dist==null||dist[0]==null||isNaN(dist[0])||dist[1]==null||isNaN(dist[1])+
- +
- Android.makeNewToast("​Invalid input",​true).show(); +
- return; +
- } +
- if(dist[0]==0&&​dist[1]==0)return; +
- for(var i=items.getLength()-1;i>​=0;​--i) +
- { +
- var item=items.getAt(i); +
- var pos=[item.getPositionX(),​item.getPositionY()]; +
- if((move[0]=="​*"​||(pos[0]>​cwidth*move[0]&&​pos[0]<​cwidth*(move[0]+1)))&&​(move[1]=="​*"​||(pos[1]>​cheight*move[1]&&​pos[1]<​cheight*(move[1]+1)))) +
- +
- var prop=item.getProperties(); +
- var xx=1,yy=1; +
- var pinmode=prop.getString("​i.pinMode"​); +
- if(pinmode[0]=="​X"​)xx=0+
- if(pinmode.indexOf("​Y"​)!=-1)yy=0+
- if(prop.getBoolean("​i.onGrid"​)) +
- +
- var cell=item.getCell(); +
- item.setCell(cell.getLeft()+cellsX*dist[0]*xx,​cell.getTop()+cellsY*dist[1]*yy,​cell.getRight()+cellsX*dist[0]*xx,​cell.getBottom()+cellsY*dist[1]*yy)+
- } +
- else +
- {item.setPosition(pos[0]+cwidth*dist[0]*xx,​pos[1]+cheight*dist[1]*yy); +
- }+
  }  }
-+ break; 
- LL.save(); + case 1://item utilities 
- break; + switch(childPosition){ 
- case 8+ case 0://​Attach/​Detach all items 
- var d=LL.getEvent().getContainer(); +     attachDetachAll();​ 
- var i=LL.getEvent().getItem();(i!=null?i:d).setTag(null); + break;​ 
- Android.makeNewToast((i==null?"container":"​item"​)+"​s tag resetted.",false).show(); + case 1://resize detached items 
- break+     resizeAllDetached();​ 
- case 9: + break;​ 
- var cont=LL.getEvent().getContainer();​ + case 2://delete items 
- var items=cont.getItems(); +     deleteAll();​ 
- var bools=[];bools[0]=confirm("Reset cell? (only grid items[0,0]"); + break;​ 
- bools[1]=confirm("Reset position? ​(only free items[0,0] "); + case 3://move pages 
- bools[2]=confirm("Reset rotation? (only free items[0]"); +     movePages();​ 
- bools[3]=confirm("Reset scale? ​(only free items[1,1]"); + break;​ 
- bools[4]=confirm("Reset skew? (only free items[0,0]"); + } 
- bools[5]=confirm("Reset size? (only free items[cell size]"); + break; 
- bools[6]=confirm("Reset visibility? [true]"); + case 2://Script Tools 
- for(var i=0;i<items.getLength();++i+ switch(childPosition){ 
- + case 0://​export 
- var t=items.getAt(i); +     exportScripts(); 
- if(bools[0])t.setCell(0,0,1,1); + break; 
- if(bools[1])t.setPosition(0,0); + case 1://import 
- if(bools[2])t.setRotation(0); +     import_askForInput();​ 
- if(bools[3])t.setScale(1,1); + break;​ 
- if(bools[4])t.setSkew(0,0); + case 2://​autoformat 
- if(bools[5])t.setSize(cont.getCellWidth(),cont.getCellHeight()); +     autoFormat();​ 
- if(bools[6])t.setVisibility(true); + break;​ 
- } +     case 3://serach in scripts 
- break+         searchScripts();​ 
- case 10: +         break; 
- LL.save(); +
- break+ break; 
- case 42: + case 3://other 
- alert("You found the hidden treasure!\n ​             ​(_\n            ​(___\n            ​(___\n            ​(___\n      /​\\__/​---\\__/​\\ \n      \\_°_¤-¤_°_/​ \n         \\ __°__ / \n          |\\_--_/| \n           [|\\_/|\n           [|[¤]|] \n           ​[|:​¤:​|] \n           ​[::​¤::​] \n           ​[|:​¤:​|] \n           ​[|:​¤:​|] \n           ​[|[¤]|] \n           ​[|[¤]|] \n           ​||[¤]|| \n           ​\\|[•]|/​ \n            \\[•]/ \n             \\./ \n               '​ "); + switch(childPosition){ 
- default: + case 0://reset Tag 
- Android.makeNewToast("illegal input: ​"+choice,false).show(); +     resetTags();​ 
- break;+ break;​ 
 + case 1://reset tool by trianguloY, ask him how it works :D 
 +     resetTool();​ 
 + break;​ 
 + case 2: 
 +     saveLayout();​ 
 + break;​ 
 + case 3: 
 +     resetRecents();​ 
 +     break; 
 +
 + break; 
 +
 +
 + 
 + 
 +function eventData(){ 
 + var e=LL.getEvent()
 + try{ //test if event contains touch data 
 + e.getTouchScreenX(); 
 + var ok=true; 
 +
 + catch(Exception){ 
 + var ok=false; 
 +    } 
 + text("​Source:​ "​+e.getSource()+"​\nDate:​ "​+e.getDate()+"​\nContainer:​ "​+e.getContainer()+"​\nItem:​ "​+e.getItem()+(ok?​("​\nTouch:​ "​+e.getTouchX()+","​+e.getTouchY()+"​\nTouch (Screen): "​+e.getTouchScreenX()+","​+e.getTouchScreenY()):""​),"​Event Information"​);​ 
 +
 + 
 +function containerData(){ 
 + var c=LL.getEvent().getContainer(); 
 + var t=c.getType();//​Differentiate between Desktop and other containers 
 + 
 + //read Tags from launcher file 
 + var s=read(LL.getContext().getFilesDir().getPath()+"/​pages/"​+c.getId()+"/​conf"​); 
 + var data=JSON.parse(s);​ 
 + var tags="​Default:​ "​+c.getTag();​ 
 + for(property in data.tags) 
 + tags+="​\n"​+property+":​ "+data.tags[property];​ 
 +    text("Type: "​+t+"​\nName/​Label:​ "+(t=="​Desktop"​?c.getName():​c.getOpener().getLabel())+"\nID: "+c.getId()+"​\nSize: "+c.getWidth()+","​+c.getHeight()+"\nBoundingbox:​ "+c.getBoundingBox()+"​\nCell Size: "​+c.getCellWidth()+","​+c.getCellHeight()+"​\nCurrent Position: "+c.getPositionX()+","​+c.getPositionY()+"​\nCurrent Scale: "​+c.getPositionScale()+"​\nTags:​ "​+tags+"​\nItems:​ "​+c.getItems(),"​Container Information"​); 
 +
 + 
 +function itemData(){ 
 + var i=LL.getEvent().getItem();if(i==null)//​check if event contains item 
 + text("​no item found","​Error 5"); 
 + 
 + //read tags from launcher file 
 + var s=read(LL.getContext().getFilesDir().getPath()+"/​pages/"​+LL.getEvent().getContainer().getId()+"/​items"​); 
 + var all=JSON.parse(s).i
 + var x; 
 + var item; 
 + for(x=0;x<​all.length;​x++){ 
 + item=all[x]
 + if(item.b==i.getId())break; 
 +
 + if(x==all.length)
 + text("​Can'​t find Tags","Error 6"); 
 + return; 
 +
 + var tags="Default: "​+i.getTag()
 + for(property in item.an){ 
 + if(property=="​_")continue
 + tags+="​\n"​+property+":​ "​+item.an[property]
 +
 +    text("​Label:​ "​+i.getLabel()+"​\nType:​ "​+i.getType()+"​\nID:​ "​+i.getId()+"​\nSize:​ "​+i.getWidth()+","​+i.getHeight()+"​\nPosition:​ "​+i.getPositionX()+","​+i.getPositionY()+"​\nScale:​ "​+i.getScaleX()+","​+i.getScaleY()+"​\nAngle:​ "​+i.getRotation()+"​\nCenter:​ "​+center(i)+((i.getType()=="​Shortcut"​||i.getType()=="Folder"​)?"​\nIntent:"​+i.getIntent():""​)+"​\nTags:​ "​+tags,"​Item Information"); 
 +
 + 
 +function intentData(){ 
 +    it=LL.getEvent().getItem()
 + if(it==null)text("​No Intent found."​,"​Error ​1"); 
 + else text("Intent: "​+it.getIntent()+"​\nExtras:​ "​+it.getIntent().getExtras(),"​Intent Information"); 
 +
 + 
 +function iconData(){ 
 + it=LL.getEvent().getItem();​ 
 + //create view structure 
 + var root=new LinearLayout(LL.getContext());​ 
 + root.setOrientation(LinearLayout.VERTICAL);​ 
 + 
 + //check for all kinds of images in this item and add them to the view if there are any 
 + addImageIfNotNull(root,​it.getBoxBackground("n"​),"​Normal Box Background"​);​ 
 + addImageIfNotNull(root,​it.getBoxBackground("​s"​),"​Selected Box Background"); 
 + addImageIfNotNull(root,​it.getBoxBackground("​f"​),"​Focused Box Background"​);​ 
 + if(it.getType()=="​Shortcut"​){ 
 + addImageIfNotNull(root,​image=it.getDefaultIcon(),"Default Icon"); 
 + addImageIfNotNull(root,image=it.getCustomIcon(),"​Custom Icon"​);​ 
 +
 + if(root.getChildCount()>​0){ //at least one image found 
 +     var scroll=new ScrollView(LL.getContext()); 
 + scroll.addView(root);​ 
 + customDialog(scroll,"​Icon"​);​ 
 +
 + else Android.makeNewToast("​No Image Data available",​true).show();​ //no image found 
 +
 + 
 +function attachDetachAll(){ 
 + var items=LL.getEvent().getContainer().getItems(); 
 + var attachDetach = function(toGrid){ 
 +     for(x=0;​x<​items.length;​x++) 
 +     ​
 +     var i=items.getAt(x); 
 +        ​ i.getProperties().edit().setBoolean("​i.onGrid"​,toGrid).commit();​ 
 +     } 
 +     Android.makeNewToast("​Done!"​,true).show(); 
 +
 + var attach = function(){attachDetach(true);​} 
 + var detach = function(){attachDetach(false);​} 
 + chooser([function(){},​attach,​detach],​["​Cancel","​Attach","​Detach"​],"​Do you want to attach or detach all items?","​MultiTool"​)
 +
 + 
 +function resizeAllDetached(){ 
 +    var linearLayout = new LinearLayout(LL.getContext()); 
 +    var c = LL.getEvent().getContainer(); 
 +    ​linearLayout.setOrientation(LinearLayout.VERTICAL)
 +    var widthText = new TextView(LL.getContext()); 
 +    ​widthText.setText("​Width:​ ")
 +    linearLayout.addView(widthText); 
 +    var widthPicker = new NumberPicker(LL.getContext()); 
 +    widthPicker.setMinValue(1); 
 +    widthPicker.setMaxValue(9999);​ 
 +    widthPicker.setValue(c.getCellWidth()); 
 +    linearLayout.addView(widthPicker);​ 
 +    var heightText = new TextView(LL.getContext()); 
 +    ​heightText.setText("​Height:​ ")
 +    linearLayout.addView(heightText); 
 +    var heightPicker = new NumberPicker(LL.getContext());​ 
 +    ​heightPicker.setMinValue(1)
 +    ​heightPicker.setMaxValue(9999);​ 
 +    ​heightPicker.setValue(c.getCellHeight()); 
 +    ​linearLayout.addView(heightPicker)
 +    var onClick = function(){ 
 +        var s=[widthPicker.getValue(),​heightPicker.getValue()]; 
 + var items=c.getItems()
 + for(var a=0;​a<​items.length;​a++) 
 + items.getAt(a).setSize(s[0],s[1]); 
 +    } 
 +    ​customConfirmDialog(linearLayout,​"To which size?",onClick)
 +
 + 
 +function deleteAll(){ 
 +    var f = function(){ 
 + var c=LL.getEvent().getContainer(); 
 + var i=c.getItems();​ 
 + for(a=0;​a<​i.length;​a++) 
 +     c.removeItem(i.getAt(a));​ 
 +
 + chooser([function(){},​f],​["​No","​Yes"​],"​Are you sure?","​Delete all items"​);
 } }
  
-function ​center(item) +function ​movePages(){ 
-+ var cont=LL.getEvent().getContainer()
- var r=item.getRotation()*Math.PI/180+ var items=cont.getItems(); 
- var sin=Math.abs(Math.sin(r)); + var cWidth=cont.getWidth(); 
- var cos=Math.abs(Math.cos(r)); + var cHeight=cont.getHeight(); 
- var w=item.getWidth()*item.getScaleX(); + var cellsFloatX=cWidth/cont.getCellWidth()
- var h=item.getHeight()*item.getScaleY(); + var cellsFloatY=cHeight/​cont.getCellHeight(); 
- return[item.getPositionX()+(w*cos+h*sin)*0.5,item.getPositionY()+(h*cos+w*sin)*0.5]; + var cellsX=Math.round(cellsFloatX)
-} + var cellsY=Math.round(cellsFloatY); 
-</sxh>+ var f=function()
 +        try{ 
 +            //page(sselection 
 +            var s=prompt("​Which page do you want to move? (for all) input has to be x,y (e.g. *,* for all pages)",""​).split(","​)
 +            var move=JSON.parse("​[\""​+s[0]+"​\",​\""​+s[1]+"​\"​]"​)
 +            var done=true;​ 
 +        ​
 +        ​catch(Exception){ 
 +            var done=false;​ 
 +        } 
 +        ​//check for valid input 
 +        if(!done||move==null||move[0]==null||(move[0]!="​*"&&​isNaN(parseInt(move[0])))||move[1]==null||(move[1]!=
script_multitool.1406584687.txt.gz · Last modified: 2014/07/28 21:58 by lm13