====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
script_multitool [2014/09/24 18:02] lm13 [Script] |
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 : 2.1 | ||
* Link : https://plus.google.com/115366157037831519359/posts/fQwfu5AUj5m | * Link : https://plus.google.com/115366157037831519359/posts/fQwfu5AUj5m | ||
- | * Download avialable! (Check repository) | + | * 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 | + | |
- | * Version 1.3.1 (31/8/2014): fix: Intent also for folders | + | |
- | * Version 2.0 (14/9/2014): new UI, added comments, removed the easteregg, because it's not reachable through the new UI | + | |
- | * Version 2.1 (24/9/2014): UI updated again, now selection is sorted into categorys, added import, export and autoformat scripts | + | |
====== 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 23: | 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 | ||
Line 30: | Line 20: | ||
* Import Script | * Import Script | ||
* Autoformat Script | * Autoformat Script | ||
- | * Reset Tag | + | * 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 | ||
//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;>//Flags app item | + | <sxh javascript;>//Created by Lukas Morawietz in collaboration with TrianguloY |
- | //Flags app item | + | |
//import java classes | //import java classes | ||
LL.bindClass("android.app.AlertDialog"); | LL.bindClass("android.app.AlertDialog"); | ||
+ | LL.bindClass("android.app.ProgressDialog"); | ||
LL.bindClass("android.content.DialogInterface"); | LL.bindClass("android.content.DialogInterface"); | ||
+ | LL.bindClass("android.os.Environment"); | ||
+ | LL.bindClass("android.R"); | ||
LL.bindClass("android.widget.ExpandableListView"); | 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.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.HashMap"); | ||
LL.bindClass("java.util.ArrayList"); | LL.bindClass("java.util.ArrayList"); | ||
- | LL.bindClass("android.R"); | ||
- | LL.bindClass("java.io.FileWriter"); | ||
- | LL.bindClass("java.io.File"); | ||
- | LL.bindClass("android.os.Environment"); | ||
- | LL.bindClass("java.io.FileReader"); | ||
- | LL.bindClass("java.io.BufferedReader"); | ||
- | //function to display a grouped list where the user can select one item | ||
- | //items should be an array containing arrays which first item is the group and the second item is an array of the items in this group | ||
- | //onClickFunction has to have two arguments. first is group position, second is child position | ||
- | function expandableList(items,onClickFunction,title) | ||
- | { | ||
- | var builder=new AlertDialog.Builder(LL.getContext()); | ||
- | var view=new ExpandableListView(LL.getContext()); | ||
- | |||
- | //transform array of items into the correct format | ||
- | var groupData=new ArrayList(); | ||
- | var childData=new ArrayList(); | ||
- | for(var x=0;x<items.length;x++) | ||
- | { | ||
- | var gd=new HashMap(); | ||
- | gd.put("root",items[x][0]); | ||
- | var cd=new ArrayList(); | ||
- | groupData.add(gd); | ||
- | for(var y=0;y<items[x][1].length;y++) | ||
- | { | ||
- | var cdMap=new HashMap(); | ||
- | cdMap.put("child",items[x][1][y]); | ||
- | cd.add(cdMap); | ||
- | } | ||
- | childData.add(cd); | ||
- | } | ||
- | |||
- | //assign the items to an adapter | ||
- | var adapter=new SimpleExpandableListAdapter(LL.getContext(),groupData,R.layout.simple_expandable_list_item_1,["root"],[R.id.text1],childData,R.layout.simple_expandable_list_item_1,["child"],[R.id.text1]); | ||
- | |||
- | //set function to run on Click to listener | ||
- | var listener=new ExpandableListView.OnChildClickListener() | ||
- | { | ||
- | onChildClick:function(parent,view,groupPosition,childPosition,id) | ||
- | { | ||
- | dialog.dismiss(); | ||
- | setTimeout(function(){onClickFunction(groupPosition,childPosition);},0); | ||
- | return true; | ||
- | } | ||
- | } | ||
- | |||
- | //assign adapter and listener to listview | ||
- | view.setAdapter(adapter); | ||
- | view.setOnChildClickListener(listener); | ||
- | //finish building | ||
- | builder.setView(view); | ||
- | builder.setCancelable(true); | ||
- | builder.setTitle(title); | ||
- | builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.cancel();}}); | ||
- | dialog=builder.create(); | ||
- | |||
- | dialog.show(); | ||
- | } | ||
- | |||
- | //function to display a List in a Popup, where the user can select one item | ||
- | function list(items,listener,title) | ||
- | { | ||
- | var builder=new AlertDialog.Builder(LL.getContext()); | ||
- | builder.setItems(items,listener); | ||
- | builder.setCancelable(true); | ||
- | builder.setTitle(title); | ||
- | builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.cancel();}});//it has a Cancel Button | ||
- | builder.create().show(); | ||
- | } | ||
- | |||
- | //helper function for item related, compute the center of an item | ||
- | function center(item) | ||
- | { | ||
- | var r=item.getRotation()*Math.PI/180; | ||
- | var sin=Math.abs(Math.sin(r)); | ||
- | var cos=Math.abs(Math.cos(r)); | ||
- | var w=item.getWidth()*item.getScaleX(); | ||
- | var h=item.getHeight()*item.getScaleY(); | ||
- | return[item.getPositionX()+(w*cos+h*sin)*0.5,item.getPositionY()+(h*cos+w*sin)*0.5]; | ||
- | } | ||
- | |||
- | //helper function for sorting labels | ||
- | function noCaseSort(a,b) | ||
- | { | ||
- | if(a.toLowerCase()>b.toLowerCase())return 1; | ||
- | if(a.toLowerCase()<b.toLowerCase())return -1; | ||
- | return 0; | ||
- | } | ||
var hasItem=(LL.getEvent().getItem()!=null); | var hasItem=(LL.getEvent().getItem()!=null); | ||
Line 141: | Line 59: | ||
//define Strings to display | //define Strings to display | ||
var title="What do you want to do?"; | var title="What do you want to do?"; | ||
- | var items=[["Information",hasItem?["Event","Container","Item","Intent","Open in Market"]:["Event","Container"]],["Item Utilities",["Attach/Detach all Items","Resize all detached Items","Delete all Items","Move Pages"]],["Script Tools",["Export Scripts","Import Script","Autoformat Scripts"]],["Other",["Reset Tag","Reset Tool © by TrianguloY","Save changes"]]]; | + | var items=[] |
+ | var info=["Information",[]]; | ||
+ | info[1].push("Event"); | ||
+ | info[1].push("Container") | ||
+ | if(hasItem){ | ||
+ | info[1].push("Item"); | ||
+ | info[1].push("Intent"); | ||
+ | info[1].push("Icon"); | ||
+ | } | ||
+ | var itemUtils=["Item Utilities",[]]; | ||
+ | itemUtils[1].push("Attach/Detach all Items"); | ||
+ | itemUtils[1].push("Resize all detached Items"); | ||
+ | itemUtils[1].push("Delete all Items"); | ||
+ | itemUtils[1].push("Move Pages"); | ||
+ | var scriptUtils=["Script Tools",[]]; | ||
+ | scriptUtils[1].push("Export Scripts (Backup)"); | ||
+ | scriptUtils[1].push("Import Script"); | ||
+ | scriptUtils[1].push("Autoformat Scripts"); | ||
+ | scriptUtils[1].push("Search in Scripts"); | ||
+ | var other = ["Other",[]]; | ||
+ | other[1].push("Reset Tag"); | ||
+ | other[1].push("Reset Tool"); | ||
+ | other[1].push("Save changes"); | ||
+ | other[1].push("Delete recent app history"); | ||
+ | items.push(info); | ||
+ | items.push(itemUtils); | ||
+ | items.push(scriptUtils); | ||
+ | items.push(other); | ||
+ | //normal run | ||
+ | if(typeof resultCode==='undefined') expandableList(items,mainOnClick,title); | ||
+ | //user has selected a file to import | ||
+ | else import_handleInput(); | ||
//handle user selection | //handle user selection | ||
- | function onClick(groupPosition,childPosition) | + | function mainOnClick(groupPosition,childPosition){ |
- | { | + | switch(groupPosition){ |
- | switch(groupPosition) | + | |
- | { | + | |
case 0://Information | case 0://Information | ||
- | switch(childPosition) | + | switch(childPosition){ |
- | { | + | |
case 0://Event related | case 0://Event related | ||
- | var e=LL.getEvent(); | + | eventData(); |
- | try//test if event contains touch data | + | |
- | { | + | |
- | e.getTouchScreenX(); | + | |
- | var ok=true; | + | |
- | } | + | |
- | catch(Exception) | + | |
- | { | + | |
- | var ok=false; | + | |
- | } | + | |
- | 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; | break; | ||
case 1://container related | case 1://container related | ||
- | var c=LL.getEvent().getContainer(); | + | containerData() |
- | var t=c.getType();//Differentiate between Desktop and other containers | + | |
- | 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()); | + | |
break; | break; | ||
case 2://item related | case 2://item related | ||
- | var i=LL.getEvent().getItem(); | + | itemData(); |
- | alert(i==null/*check if event contains item*/?"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"||i.getType()=="Folder")?"\nIntent:"+i.getIntent():"")); | + | |
break; | break; | ||
case 3://intent | case 3://intent | ||
- | it=LL.getEvent().getItem(); | + | intentData(); |
- | if(it==null) | + | |
- | alert("No Intent found."); | + | |
- | else alert("Intent: "+it.getIntent()+"\nExtras: "+it.getIntent().getExtras()); | + | |
break; | break; | ||
- | case 4://open the market page of this app | + | case 4://icon |
- | try | + | iconData(); |
- | { | + | |
- | LL.startActivity(Intent(Intent.ACTION_VIEW,Uri.parse("market://details?id="+LL.getEvent().getItem().getIntent().getComponent().getPackageName()))); | + | |
- | } | + | |
- | catch(Exception) | + | |
- | { | + | |
- | alert("No App found"); | + | |
- | } | + | |
break; | break; | ||
} | } | ||
break; | break; | ||
case 1://item utilities | case 1://item utilities | ||
- | switch(childPosition) | + | switch(childPosition){ |
- | { | + | |
case 0://Attach/Detach all items | case 0://Attach/Detach all items | ||
- | var items=LL.getEvent().getContainer().getItems(); | + | attachDetachAll(); |
- | var togrid=confirm("Attach? if not, detach"); | + | |
- | for(x=0;x<items.length;x++) | + | |
- | { | + | |
- | var i=items.getAt(x); | + | |
- | i.getProperties().edit().setBoolean("i.onGrid",togrid).commit(); | + | |
- | } | + | |
break; | break; | ||
case 1://resize detached items | case 1://resize detached items | ||
- | try | + | resizeAllDetached(); |
- | { | + | |
- | var s=JSON.parse("["+prompt("which size? (input like width,height)","")+"]"); | + | |
- | var items=LL.getEvent().getContainer().getItems(); | + | |
- | for(var a=0;a<items.length;a++) | + | |
- | items.getAt(a).setSize(s[0],s[1]); | + | |
- | } | + | |
- | catch(Exception) | + | |
- | { | + | |
- | Android.makeNewToast("Invalid input",true).show(); | + | |
- | } | + | |
break; | break; | ||
case 2://delete items | case 2://delete items | ||
- | if(confirm("Are you sure?")) | + | deleteAll(); |
- | { | + | |
- | var c=LL.getEvent().getContainer(); | + | |
- | var i=c.getItems(); | + | |
- | for(a=0;a<i.length;a++) | + | |
- | c.removeItem(i.getAt(a)); | + | |
- | } | + | |
break; | break; | ||
case 3://move pages | case 3://move pages | ||
- | var cont=LL.getEvent().getContainer(); | + | movePages(); |
- | var items=cont.getItems(); | + | |
- | var cwidth=cont.getWidth(); | + | |
- | var cheight=cont.getHeight(); | + | |
- | var cellsFloatX=cwidth/cont.getCellWidth(); | + | |
- | var cellsFloatY=cheight/cont.getCellHeight(); | + | |
- | var cellsX=Math.round(cellsFloatX); | + | |
- | var cellsY=Math.round(cellsFloatY); | + | |
- | //check for safe cell sizes | + | |
- | 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 | + | |
- | { | + | |
- | //page(s) selection | + | |
- | 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]!="*"&&isNaN(parseInt(move[1])))) | + | |
- | { | + | |
- | Android.makeNewToast("Invalid input",true).show(); | + | |
- | return; | + | |
- | } | + | |
- | //format to int if needed | + | |
- | if(move[0]!="*")move[0]=parseInt(move[0]); | + | |
- | if(move[1]!="*")move[1]=parseInt(move[1]); | + | |
- | try | + | |
- | { | + | |
- | //user selection: destination | + | |
- | 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; | + | |
- | } | + | |
- | //check for valid input | + | |
- | 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;//if nothing to do, do nothing :P | + | |
- | + | ||
- | //do the movement | + | |
- | for(var i=items.getLength()-1;i>=0;--i) | + | |
- | { | + | |
- | var item=items.getAt(i); | + | |
- | var pos=[item.getPositionX(),item.getPositionY()]; | + | |
- | //check if item should be moved | + | |
- | 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(); | + | |
- | + | ||
- | //handle pinned item | + | |
- | var xx=1,yy=1; | + | |
- | var pinmode=prop.getString("i.pinMode"); | + | |
- | if(pinmode[0]=="X")xx=0; | + | |
- | if(pinmode.indexOf("Y")!=-1)yy=0; | + | |
- | + | ||
- | //move it | + | |
- | 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); | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | LL.save(); | + | |
break; | break; | ||
} | } | ||
break; | break; | ||
case 2://Script Tools | case 2://Script Tools | ||
- | switch(childPosition) | + | switch(childPosition){ |
- | { | + | case 0://export |
- | case 0://export | + | exportScripts(); |
- | //Directory to save scripts in | + | |
- | var dir=new File(Environment.getExternalStorageDirectory()+File.separator+"LightningLauncher"+File.separator+"Scripts"+File.separator); | + | |
- | dir.mkdirs();//create Directory if missing | + | |
- | + | ||
- | //Iterate through all scripts | + | |
- | var scripts=LL.getAllScriptMatching(Script.FLAG_ALL); | + | |
- | for(var a=0;a<scripts.length;a++) | + | |
- | { | + | |
- | var s=scripts.getAt(a); | + | |
- | var file=new File(Environment.getExternalStorageDirectory()+File.separator+"LightningLauncher"+File.separator+"Scripts"+File.separator+s.getName()+".txt");//Define the file to save in | + | |
- | file.createNewFile();//create the file | + | |
- | + | ||
- | //Check for Flags | + | |
- | var app=s.hasFlag(Script.FLAG_APP_MENU); | + | |
- | var item=s.hasFlag(Script.FLAG_ITEM_MENU); | + | |
- | var custom=s.hasFlag(Script.FLAG_CUSTOM_MENU); | + | |
- | var flags=""; | + | |
- | if(app||item||custom) | + | |
- | { | + | |
- | flags="//Flags" | + | |
- | if(app)flags+=" app"; | + | |
- | if(item)flags+=" item"; | + | |
- | if(custom)flags+=" custom"; | + | |
- | flags+="\n"; | + | |
- | } | + | |
- | //write the code to the file | + | |
- | var f=new FileWriter(file); | + | |
- | f.write(flags+s.getText()); | + | |
- | f.flush(); | + | |
- | f.close(); | + | |
- | } | + | |
- | Android.makeNewToast("Scripts saved to "+dir.getAbsolutePath(),true).show(); | + | |
break; | break; | ||
case 1://import | case 1://import | ||
- | //ask android to let the user select a textfile | + | import_askForInput(); |
- | var i=new Intent(Intent.ACTION_GET_CONTENT); | + | |
- | i.setType("text/*"); | + | |
- | i.addCategory(Intent.CATEGORY_OPENABLE); | + | |
- | LL.startActivityForResult(Intent.createChooser(i,"Select Script to import"),LL.getCurrentScript(),null); | + | |
break; | break; | ||
case 2://autoformat | case 2://autoformat | ||
- | //config | + | autoFormat(); |
- | var directWrite=true;//wether to show a prompt or write directly to the script | + | |
- | //endconfig | + | |
- | + | ||
- | //create Strings to display | + | |
- | var title="Which script?"; | + | |
- | var items=[]; | + | |
- | var scripts=LL.getAllScriptMatching(Script.FLAG_ALL); | + | |
- | for(var z=0;z<scripts.length;z++)items.push(scripts.getAt(z).getName()); | + | |
- | items.sort(noCaseSort); | + | |
- | items.unshift("All Scripts (may need some time)"); | + | |
- | + | ||
- | //initialize vars | + | |
- | var switchLevel; | + | |
- | var i; | + | |
- | var s; | + | |
- | var t; | + | |
- | var out; | + | |
- | var noCode; | + | |
- | var starter; | + | |
- | var newLine; | + | |
- | + | ||
- | //handle user selection | + | |
- | var listener=new DialogInterface.OnClickListener(){ | + | |
- | onClick:function(dialog,id) | + | |
- | { | + | |
- | var selected; | + | |
- | if(id==0)selected=items.slice(1,items.length);//all scripts selected | + | |
- | else selected=[items[id]];//single script selected | + | |
- | for(var y=0;y<selected.length;y++) | + | |
- | { | + | |
- | s=LL.getScriptByName(selected[y]); | + | |
- | t=s.getText();//original text | + | |
- | out="";//output | + | |
- | i=0;//indentionlevel | + | |
- | noCode=false;//detectionhelper,true if in comment,string etc. | + | |
- | starter;//detectionhelper,contains the last noCode block starter | + | |
- | newLine=true;//true if in a new line | + | |
- | switchLevel=[];//detectionhelper,needed for switch commands | + | |
- | + | ||
- | //go through the text | + | |
- | for(a=0;a<t.length;a++) | + | |
- | { | + | |
- | //don't copy spaces and tabs, if not in a noCode block | + | |
- | if(!noCode&&((t[a]==" "&&(out[out.length-1].toLowerCase()==out[out.length-1].toUpperCase()||t[a+1].toLowerCase()==t[a+1].toUpperCase())&&out.slice(out.length-4,out.length)!="case"&&out.slice(out.length-6,out.length)!="return")||(t[a]=="\t")))continue; | + | |
- | + | ||
- | //detect wether the char is negated by a backslash or not | + | |
- | var backslashed=false; | + | |
- | for(b=out.length-1;out[b]=="\\";b--)backslashed=!backslashed; | + | |
- | + | ||
- | //detect start of a noCode block | + | |
- | if((t[a]=="\""||t[a]=="\'")&&!noCode) | + | |
- | { | + | |
- | noCode=true; | + | |
- | starter=t[a]; | + | |
- | if(out[out.length-1]=="\n")indentLine(); | + | |
- | } | + | |
- | else if(!noCode&&t[a]=="/"&&(t[a+1]=="/"||t[a+1]=="*")) | + | |
- | { | + | |
- | noCode=true; | + | |
- | starter=t.slice(a,a+2); | + | |
- | if(out[out.length-1]=="\n")indentLine(); | + | |
- | } | + | |
- | //detect end of a noCode block | + | |
- | else if(noCode&&(t[a]==starter||(starter=="/*"&&t.slice(a,a+2)=="*/")||(starter=="//"&&t[a]=="\n"))&&!backslashed) | + | |
- | { | + | |
- | noCode=false; | + | |
- | } | + | |
- | + | ||
- | //handle keychars | + | |
- | if(!noCode) | + | |
- | { | + | |
- | if(t[a]=="\n")//line end | + | |
- | { | + | |
- | newLine=true; | + | |
- | out=out.concat(t[a]); | + | |
- | continue; | + | |
- | } | + | |
- | if(t[a]=="}")//function block end | + | |
- | { | + | |
- | i--; | + | |
- | if(switchLevel.length!=0&&i<=switchLevel[0]&&switchLevel[0]>0)//special handling when in switch command | + | |
- | { | + | |
- | switchLevel.shift(); | + | |
- | i--; | + | |
- | } | + | |
- | } | + | |
- | if(newLine&&t[a]!="\n")//indent the next line | + | |
- | { | + | |
- | indentLine(); | + | |
- | } | + | |
- | if(t[a]=="{")i++;//function block start | + | |
- | if(t.slice(a,a+7)=="switch(")switchLevel.unshift(++i);//start of switch command | + | |
- | } | + | |
- | out=out.concat(t[a]);//concat the char | + | |
- | } | + | |
- | while(out[out.length-1]=="\n")out=out.slice(0,out.length-1);//remove unnessecary line brakes at the end of the script | + | |
- | if(directWrite)//set output to the script | + | |
- | { | + | |
- | s.setText(out); | + | |
- | if(y==selected.length-1)Android.makeNewToast("Done!",true).show();//notify if finished | + | |
- | } | + | |
- | else prompt("",out);//show output | + | |
- | } | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | //show selection list | + | |
- | list(items,listener,title); | + | |
- | + | ||
- | //creates tabs at the beginning of a line | + | |
- | function indentLine() | + | |
- | { | + | |
- | for(b=(switchLevel!=0&&(t.slice(a,a+4)=="case"||t.slice(a,a+7)=="default")?1:0);b<i;b++) | + | |
- | out=out.concat("\t"); | + | |
- | newLine=false; | + | |
- | } | + | |
break; | break; | ||
+ | case 3://serach in scripts | ||
+ | searchScripts(); | ||
+ | break; | ||
} | } | ||
break; | break; | ||
case 3://other | case 3://other | ||
- | switch(childPosition) | + | switch(childPosition){ |
- | { | + | |
case 0://reset Tag | case 0://reset Tag | ||
- | var d=LL.getEvent().getContainer(); | + | resetTags(); |
- | var i=LL.getEvent().getItem();(i!=null?i:d).setTag(null); | + | |
- | Android.makeNewToast((i==null?"container":"item")+"s tag resetted.",false).show(); | + | |
break; | break; | ||
case 1://reset tool by trianguloY, ask him how it works :D | case 1://reset tool by trianguloY, ask him how it works :D | ||
- | var cont=LL.getEvent().getContainer(); | + | resetTool(); |
- | var items=cont.getItems(); | + | |
- | var bools=[];bools[0]=confirm("Reset cell? (only grid items) [0,0]"); | + | |
- | bools[1]=confirm("Reset position? (only free items) [0,0] "); | + | |
- | bools[2]=confirm("Reset rotation? (only free items) [0]"); | + | |
- | bools[3]=confirm("Reset scale? (only free items) [1,1]"); | + | |
- | bools[4]=confirm("Reset skew? (only free items) [0,0]"); | + | |
- | bools[5]=confirm("Reset size? (only free items) [cell size]"); | + | |
- | bools[6]=confirm("Reset visibility? [true]"); | + | |
- | for(var i=0;i<items.getLength();++i) | + | |
- | { | + | |
- | var t=items.getAt(i); | + | |
- | if(bools[0])t.setCell(0,0,1,1); | + | |
- | if(bools[1])t.setPosition(0,0); | + | |
- | if(bools[2])t.setRotation(0); | + | |
- | if(bools[3])t.setScale(1,1); | + | |
- | if(bools[4])t.setSkew(0,0); | + | |
- | if(bools[5])t.setSize(cont.getCellWidth(),cont.getCellHeight()); | + | |
- | if(bools[6])t.setVisibility(true); | + | |
- | } | + | |
break; | break; | ||
case 2: | case 2: | ||
- | LL.save(); | + | saveLayout(); |
- | Android.makeNewToast("Done!",true).show(); | + | |
break; | break; | ||
+ | case 3: | ||
+ | resetRecents(); | ||
+ | break; | ||
} | } | ||
- | break; | ||
- | default://should never occur: illegal group selection | ||
- | Android.makeNewToast(txt==null?"Aborted":"illegal case: "+txt,false).show(); | ||
break; | break; | ||
} | } | ||
Line 517: | Line 168: | ||
- | if(typeof resultCode==='undefined')//normal run | + | function eventData(){ |
- | { | + | var e=LL.getEvent(); |
- | //display the list | + | try{ //test if event contains touch data |
- | expandableList(items,onClick,title); | + | 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"); | ||
} | } | ||
- | else//user has selected a file to import | + | |
- | { | + | function containerData(){ |
- | //the file to import | + | var c=LL.getEvent().getContainer(); |
- | var file=new File(data.getData().getPath()); | + | var t=c.getType();//Differentiate between Desktop and other containers |
- | //check for valid file | + | |
- | if(!file.canRead()) | + | //read Tags from launcher file |
- | { | + | var s=read(LL.getContext().getFilesDir().getPath()+"/pages/"+c.getId()+"/conf"); |
- | alert("Can't read file"); | + | var data=JSON.parse(s); |
- | return; | + | 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(file.length()>25000) | + | if(x==all.length){ |
- | { | + | text("Can't find Tags","Error 6"); |
- | alert("File is too big"); | + | |
return; | 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"); | ||
+ | } | ||
- | var r=new BufferedReader(new FileReader(file)); | + | function intentData(){ |
- | var s=""; | + | it=LL.getEvent().getItem(); |
- | //read the file | + | if(it==null)text("No Intent found.","Error 1"); |
- | var l=r.readLine(); | + | else text("Intent: "+it.getIntent()+"\nExtras: "+it.getIntent().getExtras(),"Intent Information"); |
- | if(l.indexOf("//Flags")!=-1)//check if file contains flag settings | + | } |
- | { | + | |
- | var app=(l.indexOf("app")!=-1); | + | function iconData(){ |
- | var item=(l.indexOf("item")!=-1); | + | it=LL.getEvent().getItem(); |
- | var custom=(l.indexOf("custom")!=-1); | + | //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"); | ||
} | } | ||
- | else s=l+"\n"; | + | if(root.getChildCount()>0){ //at least one image found |
- | while((l=r.readLine())!=null)s+=(l+"\n"); | + | var scroll=new ScrollView(LL.getContext()); |
- | //remove file extension | + | scroll.addView(root); |
- | var filename=file.getName(); | + | customDialog(scroll,"Icon"); |
- | var index=filename.lastIndexOf("."); | + | |
- | if(index!=-1)filename=filename.slice(0,index); | + | |
- | //ask for imported scripts name | + | |
- | var name=prompt("File read successfully. Enter name for the Script",filename); | + | |
- | //Write read data to script and create it if nessecary | + | |
- | var script=LL.getScriptByName(name); | + | |
- | if(script!=null) | + | |
- | { | + | |
- | if(!confirm("Script does already exist. Overwrite?"))return; | + | |
- | else script.setText(s); | + | |
} | } | ||
- | else script=LL.createScript(name,s,0); | + | else Android.makeNewToast("No Image Data available",true).show(); //no image found |
- | //aplly flags if found before | + | |
- | if(app)script.setFlag(Script.FLAG_APP_MENU,true); | + | |
- | if(item)script.setFlag(Script.FLAG_ITEM_MENU,true); | + | |
- | if(custom)script.setFlag(Script.FLAG_CUSTOM_MENU,true); | + | |
- | Android.makeNewToast("Done!",true); | + | |
} | } | ||
- | </sxh> | + | |
+ | 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 movePages(){ | ||
+ | var cont=LL.getEvent().getContainer(); | ||
+ | var items=cont.getItems(); | ||
+ | var cWidth=cont.getWidth(); | ||
+ | var cHeight=cont.getHeight(); | ||
+ | var cellsFloatX=cWidth/cont.getCellWidth(); | ||
+ | var cellsFloatY=cHeight/cont.getCellHeight(); | ||
+ | var cellsX=Math.round(cellsFloatX); | ||
+ | var cellsY=Math.round(cellsFloatY); | ||
+ | var f=function(){ | ||
+ | try{ | ||
+ | //page(s) selection | ||
+ | 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]!= |