User Tools

Site Tools


script_reopen_previous_app

====== About the script ====== * Purpose : The script ideally takes the last used app (that is not the launcher) and change the item to be as the app shortcut of that app. * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/u/1/105066926163073195690/posts/AYw6vBACbw4 (with video) ====== How to use the script ====== Instructions: set it in the resumed event of an item (use a new shortcut, intent/icon/label will be overwritten) It will take the default icon, no icon packs. It can be buggy sometimes (I didn't tested it a lot too), and maybe it throws an error, but I hope not to. The code is a bit messy, and I'm sure it can be improved. It can be modified to show more than one of the recent apps, but it is not implemented. Feel free to do so. ====== Script code ====== <sxh javascript> var MAX=10; var FORCEALL=false; LL.bindClass("android.app.Activity"); var am = LL.getContext().getSystemService(Activity.ACTIVITY_SERVICE); var list = am.getRecentTasks(MAX,FORCEALL?1:0); var names=""; var last=""; var cmp=""; for(var i=0;i<list.size();++i){ cmp=list.get(i).baseIntent.getComponent().getPackageName(); names+=cmp+"\n"; if(last==""&&cmp!="net.pierrox.lightning_launcher_extreme")last=cmp; } //alert(names);//debug if(last=="")return; //set label and image var item=LL.getEvent().getItem(); if(item==null){alert("No item found");return;} var pm=LL.getContext().getPackageManager(); item.setLabel(pm.getApplicationLabel(pm.getApplicationInfo(last,0)),true); //convert the drawable to a LL image var bit=pm.getApplicationIcon(last).getBitmap(); var image=LL.createImage(bit.getWidth(),bit.getHeight()); var canv=image.draw(); canv.drawBitmap(bit,0,0,null); image.update(); item.setCustomIcon(image); item.setIntent(pm.getLaunchIntentForPackage(last)); </sxh>

script_reopen_previous_app.txt · Last modified: 2014/11/08 22:50 by trianguloy