User Tools

Site Tools


script_most_launched_apps

====== About the script ====== * Purpose : It creates a panel in a container with the most launched (clicked) apps from the app drawer. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/u/1/105066926163073195690/posts/AY4zpcyDziG ====== How to use the script ====== This script is something I made some weeks ago, and I've been testing it myself since then. It seems to work, but unfortunately I don't use it too much to fully test it...and it crash the launcher if you do a specify thing :P (don't worry, it's a specific and predictable thing) The script is specially designed for those who use the app drawer a lot. More details: when you click an app from the app drawer (or from a folder from the app drawer) a copy of the app will be placed in the panel (If there is not one). That list is sorted by the most used one, based on a very simple algorithm that seems to work. Even more details: each app has an internal value from 2 to 0,5. Each time you click an app its value is raised a bit, and all the other apps decrease a bit. Those 'multiplier' values are in the script, and I plan to tune then from your suggestions. How to use it: first run the script from the app drawer, and the panel and all the necessary events will be set. You can run again to reinstall or to uninstall. If you want to remove an app from the panel run the script from the item. IMPORTANT!!!!!! If you try to enter edit mode in the panel, the launcher will crash. It will also crash when using the search app feature of the app drawer. Also make a backup before, just in case. (I never had any issues, even when it crash, but just in case) ====== Script code ====== <sxh javascript> //start config var increase = 1.2 var decrease = 0.99; var name="most used"; var tag="most used"; var id=99;//id of the container where the panel will be placed //end config var event=LL.getEvent(); var item=event.getItem(); var source=event.getSource(); var scriptid=LL.getCurrentScript().getId(); var drawer=LL.getContainerById(99); var panel=LL.getContainerById(id).getItemByName(name); if(source=="MENU_APP" || panel==null || item==null){ var noexist= (panel==null); if(!confirm("This will set all the tap action of all the containers from the app drawer to run this script." + ( noexist?" And will add a 'most used apps' panel at the top.":"") + "\n Do you want to continue?")){ if(confirm("Do you want instead to uninstall the script?")){ uninstall(); } return; } install(); return; } panel=panel.getContainer(); if(source=="I_CLICK"){ if(item.getType()=="Folder")tappedFolder(item); if(item.getType()=="Shortcut")tappedItem(item); return; } if(source=="MENU_ITEM" && item.getParent()==panel){ deleteItem(item); return; } //else Android.makeNewToast("Run the script from the menu app", true).show(); function install(){ if(noexist){ panel=LL.getContainerById(id).addPanel(0,0,drawer.getWidth(),1); LL.save(); panel.setName(name); panel.getContainer().getProperties().edit().setInteger("gridPRowNum",1).commit(); prepareContainer(panel.getContainer(),true); } //LL.save(); prepareContainer(drawer,true); } function uninstall(noexist){ if(!noexist)LL.getContainerById(id).removeItem(panel); LL.save(); prepareContainer(drawer,false); } function prepareContainer(cont,install){ var handler= install? EventHandler.RUN_SCRIPT : EventHandler.UNSET; var items=cont.getItems(); for(var t=0;t<items.getLength();++t){ var item=items.getAt(t); if(item.getType()=="Folder" || item.getType()=="Panel")prepareContainer(item.getContainer(),install); } cont.setTag(tag, install? 1 : null); cont.getProperties().edit().setEventHandler("i.tap",handler,scriptid).commit(); } function tappedItem(tapped){ var component=tapped.getIntent().toURI(); var items=panel.getItems(); var list=[]; var exists=false; for(var t=0;t<items.getLength();++t){ var item=items.getAt(t); list[t]=item; if(component==item.getIntent().toURI()){ item.setTag(tag, Math.min(item.getTag(tag)*increase,2) ); exists=true; }else{ item.setTag(tag, Math.max(item.getTag(tag)*decrease,0.5) ); } //item.setLabel(item.getTag(tag)); }//end for if(!exists){ var added=panel.addShortcut(tapped.getLabel(),tapped.getIntent(),0,0); added.setTag(tag,1); added.setDefaultIcon(tapped.getDefaultIcon()); list.push(added); } update(list); tapped.launch() } function update(list){ if(list==null){ var items=panel.getItems(); list=[]; for(var t=0;t<items.getLength();++t) list[t]=items.getAt(t); } list.sort(function(a,b){return b.getTag(tag)-a.getTag(tag);}); for(var t=0;t<list.length;++t){ list[t].setCell(t,0,t+1,1,true); }//end for }//end function function tappedFolder(folder){ if(folder.getContainer().getTag(tag)==null) prepareContainer(folder.getContainer(),true); folder.launch(); } function deleteItem(item){ if(confirm("Do you want to delete this item?"))panel.removeItem(item); update(); } </sxh>

script_most_launched_apps.txt · Last modified: 2015/08/16 15:53 by trianguloy