**This is an old revision of the document!** ----
====== About the script ====== * Purpose : This script will fill any container with all of your apps, like an App Drawer * Author : [[https://plus.google.com/+LukasMorawietz|LM13]] * Current Version : 3.0 * Link: https://plus.google.com/115366157037831519359/posts/4F9TpMfz2fv * Download available! (Check repository) ====== Changelog ====== * Version 1.0 (18/7/2014): initial release in wiki * Version 1.1 (20/7/2014): added optional horizontal sorting * Version 2.0 (23/7/2014): Removed autovalues, due to an unfixable bug, added item remove and add again * Version 2.1 (28/8/2014): Sorting ignores Case * Version 3.0 (21/3/2015): Doesn't rely on LLs drawer anymore, hiding items improved ====== How to use the script ====== * load the apk ====== Issues and Hints ====== * first load may take some time * if you delete items in the normal way, it will cause an error * Note: The setup script won't work outside of the APK //please report all bugs in the g+ community!// <spoiler|Setup> <sxh javascript;>var MY_PKG="net.pierrox.lightning_launcher.llscript.appdrawer"; var TAG = "appdrawer_lukas"; // install (or update) a script given its id in the package, and its clear name in the launcher data function installScript(id,name){ // load the script (if any) among the existing ones var script=LL.getScriptByName(name); var script_text=LL.loadRawResource(MY_PKG,id); if(script==null){ // script not found: install it script=LL.createScript(name,script_text,0); }else{ // the script already exists: update its text script.setText(script_text); } return script; } var script=installScript("appdrawer","AppDrawer_main"); var menu= installScript("menu","AppDrawer_menu"); if(!confirm("Do you want to use this container as App Drawer?"))return; var data={}; data.columns=prompt("How many columns do you want?","5"); if(data.columns == null) return; data.rows=prompt("How many rows do you want? (0 for infinite)","0"); if(data.rows == null) return; var c=LL.getEvent().getContainer(); c.setTag(TAG,JSON.stringify(data)); c.getProperties().edit().setEventHandler("resumed",EventHandler.RUN_SCRIPT,script.getId()).setEventHandler("bgLongTap",EventHandler.RUN_SCRIPT,menu.getId()).commit(); Android.makeNewToast("Enjoy your new Appdrawer!",true).show(); </sxh> </spoiler> <spoiler|Menu> <sxh javascript;>LL.bindClass("android.R"); LL.bindClass("java.util.ArrayList"); LL.bindClass("android.view.ViewTreeObserver"); LL.bindClass("android.widget.Button"); LL.bindClass("android.view.View"); var sourceItem = LL.getEvent().getItem(); var menuRoot=LL.getContext().getWindow().getDecorView().findViewById(R.id.content).getChildAt(0).getChildAt(2).getChildAt(2); var menu = menuRoot.getChildAt(0); var obs=menuRoot.getViewTreeObserver(); var l=new ViewTreeObserver.OnGlobalLayoutListener(){ onGlobalLayout:function() { var list=menu.getChildAt(0); var first=list.getChildAt(0); list.removeAllViews(); var v = !(typeof invisible === 'undefined' || invisible); add(v?"Hide Hidden":"Show Hidden",function(){ LL.runAction(EventHandler.LAUNCHER_MENU); invisible = v; LL.runScript("AppDrawer_main",v?"":"showHidden"); },first,list); if(sourceItem!=null){ v = !JSON.parse(sourceItem.getTag("hide")); add(v?"Hide":"Unhide",function(){ LL.runAction(EventHandler.LAUNCHER_MENU); if(v)LL.getEvent().getContainer().setItemZIndex(sourceItem.getId(),0); sourceItem.setVisibility(!v); sourceItem.setTag("hide",v); LL.runScript("AppDrawer_main",""); },first,list); } add("Lightning Menu",function(){ LL.runAction(EventHandler.LAUNCHER_MENU); if(sourceItem==null) LL.runAction(EventHandler.LAUNCHER_MENU) else LL.runAction(EventHandler.ITEM_MENU,sourceItem,null); },first,list); obs.removeOnGlobalLayoutListener(l); return true; } }; obs.addOnGlobalLayoutListener(l); LL.runAction(EventHandler.LAUNCHER_MENU); function add(text,onClickFunction,first,list){ var t=new Button(LL.getContext()); t.setBackground(first.getBackground().mutate().getConstantState().newDrawable()); t.setTypeface(first.getTypeface()); t.setAllCaps(false); t.setTextSize(0,first.getTextSize()); t.setFontFeatureSettings(first.getFontFeatureSettings()); t.setGravity(first.getGravity()); t.setText(text); t.setOnClickListener(new View.OnClickListener(){ onClick:onClickFunction }); list.addView(t); } </sxh> </spoiler> <spoiler|Appdrawer> <sxh javascript;>var TAG = "appdrawer_lukas"; var e=LL.getEvent(); var c=e.getContainer(); var data=JSON.parse(c.getTag(TAG)); if(data == null)return; var db=data.db||[]; var columns=data.columns; var rows=data.rows; var showHidden = (e.getData() == "showHidden"); sort(); if(db.length == 0){ LL.bindClass("android.app.ProgressDialog"); var progress = new ProgressDialog(LL.getContext()); progress.setTitle("Initializing App Drawer") progress.setMessage("Please wait..."); progress.setProgressStyle(ProgressDialog.STYLE_SPINNER); progress.show(); } setTimeout(function(){ for(var a = 0; a < db.length; a++){ db[a][2] = false; } var intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); var pm = LL.getContext().getPackageManager(); var apps = pm.queryIntentActivities(intent,0); for(var a = 0; a < apps.size(); a++){ var app = apps.get(a); for(var b = 0; b < db.length && db[b][1] != app.activityInfo.name; b++); if(b == db.length) { var i = new Intent(intent); i.setClassName(app.activityInfo.packageName,app.activityInfo.name); var item = c.addShortcut(app.loadLabel(pm),i,0,0); item.setName(item.getLabel()); item.setTag("hide",false); var bmp = pm.getActivityIcon(i).getBitmap(); var img = LL.createImage(bmp.getWidth(),bmp.getHeight()); img.draw().drawBitmap(bmp,0,0,null); item.setDefaultIcon(img); item.getProperties().edit().setEventHandler("i.longTap",EventHandler.RUN_SCRIPT,LL.getScriptByName("AppDrawer_menu").getId()).commit(); db[b] = []; db[b][0] = item.getId(); db[b][1] = app.activityInfo.name; } db[b][2] = true; } sort(); if(typeof progress !== 'undefined')progress.dismiss(); },100); function sort(){ var labels=[]; for(var a = 0; a < db.length; a++){ var item=LL.getItemById(db[a][0]); if(db[a][2]){ if(showHidden||!JSON.parse(item.getTag("hide")))labels.push(item.getName()); else item.setVisibility(false); } else{ c.removeItem(item); db.splice(a,1); a--; } } data.db = db; c.setTag(TAG,JSON.stringify(data)); labels.sort(noCaseSort); for(var a = 0; a < labels.length; a++){ var item = c.getItemByName(labels[a]); item.setVisibility(true); if(rows==0)item.setCell(a%columns,Math.floor(a/columns),a%columns+1,Math.floor(a/columns)+1); else item.setCell(a%columns+columns*Math.floor(a/(rows*columns)),Math.floor(a/columns)-rows*Math.floor(a/(rows*columns)),a%columns+columns*Math.floor(a/(rows*columns))+1,Math.floor(a/columns)-rows*Math.floor(a/(rows*columns))+1); } c.getItemByName(labels[a]) LL.save(); } function noCaseSort(a,b) { if(a.toLowerCase()>b.toLowerCase())return 1; if(a.toLowerCase()<b.toLowerCase())return -1; return 0; } </sxh> </spoiler>