User Tools

Site Tools


script_animated_icons

====== About the script ====== * Purpose : Uses a gif file to make an animated icon * Author : [[https://plus.google.com/u/1/105066926163073195690|TrianguloY]] * Link: https://plus.google.com/+TrianguloY/posts/1GpeJs5Ar22 ====== How to use the script ====== Currently the script can only use .gif files, but if you know any icon pack with animated icons that are not gifs, tell me and I'll try with that. Also if you know an icon pack of gif files tell us in comments, as I could only find this one: https://web.archive.org/web/20150320083052/http://www.redworks.com/en/free-flat-animated-icons (NOTE: the site seems to be now a different one. For this reason the link is from the web archive) The instructions are easy: run the script from the icon, choose a gif file, and accept if you want it to be automatically animated (otherwise you'll need to set the script to an event). If your want to change to another gif file, just run the script again. Important: the launcher keeps the reference of the gif file. If you remove it or change it's path it will prompt an error. Note: the more animated icons you have, the slower they all will become. You can change the fps in the script if necessary. {In the video there are 13 animated icons simultaneously, and they still play at a good rate.} Technical details: A Movie file is created with the path chosen as parameter. Successive timeouts are fired which draws that Movie in the live image of the icon. ====== Script code ====== <sxh javascript> var fps=60;//frames per second //classes LL.bindClass("android.graphics.Movie"); LL.bindClass("android.content.ContentResolver"); LL.bindClass("android.provider.MediaStore"); //tags var tagpath="anicon"; var tagid="aniconid"; //global vars var thisscript=LL.getCurrentScript(); var item=null; var source=""; //when used startActivityForResult if(typeof resultCode!='undefined'){ if(!filechosen()) return; }else{ //when launched from event item=LL.getEvent().getItem(); source=LL.getEvent().getSource(); } if(item==null) return; if(source=="I_PAUSED"){ stop(); return; } //file var path=item.getTag(tagpath); if(path==null||source=="MENU_ITEM"){ choosefile(); return; } //start token var gif=Movie.decodeFile(path);//gif movie if(gif == null){ if(confirm("The gif file couldn't be found. Did you removed it or renamed a parent folder?\n(saved path: '"+path+"')\n Do you want to choose another one?"))choosefile(); return; } var t=gif.duration()*Math.random();//the current time of the movie, random start fps=1000/fps; var im=item.getImage(); var size=[im.getWidth(),im.getHeight()];//size of the live image var oldid=item.getTag(tagid); var id; do{id=Math.random();}while(id==oldid); item.setTag(tagid,id);//unique token //start of the animation loop update(); function stop(){ item.setTag(tagid,"-1");//stop animation } function update(){ if(LL.isPaused()){ //launcher paused stop(); return; } if(id!=item.getTag(tagid)){ //another instance of this script is fired return; } var nim=LL.createImage(size[0],size[1]); //var nim=i.getImage(); var nc=nim.draw(); nc.scale(nim.getWidth()/gif.width(),nim.getHeight()/gif.height()); gif.setTime(t) gif.draw(nc,0,0);//draws the corresponding image nim.update(); item.setImage(nim); t=(t+fps)%gif.duration(); setTimeout(update,fps);//repeat } function choosefile(){ var intent =new Intent(); intent.setComponent(ComponentName.unflattenFromString("net.pierrox.lightning_launcher_extreme/net.pierrox.lightning_launcher.activities.FilePicker"));//file picker activity intent['putExtra(java.lang.String,java.lang.String[])']("e",["gif"]);//list of extensions to show if(thisscript.getTag()!=null)intent.putExtra("p",thisscript.getTag());//path where to start LL.startActivityForResult(intent,thisscript,item.getId()); } function filechosen(){ if(data==null){ Android.makeNewToast("Cancelled",true).show(); return false } var dp=data.getExtra("p");//last path opened var df=data.getExtra("f");//file chosen if(dp!=null)thisscript.setTag(data.getExtra("p"));//so next time it will open in the previous path if(df==null){ Android.makeNewToast("No file picked",true).show(); return false } //otherwise gif chosen item=LL.getItemById(token); item.setTag(tagpath,df);//saved path item.setCustomIcon(LL.createImage(df));//this makes the item to have a custom icon related to the animated one if(confirm("Do you want it to be automatically animated?\n(script in the resumed/paused event)")){ //it make this for you item.getProperties().edit() .setEventHandler("i.resumed",EventHandler.RUN_SCRIPT,thisscript.getId()) .setEventHandler("i.paused",EventHandler.RUN_SCRIPT, thisscript.getId()) .commit(); } return true; } </sxh>

script_animated_icons.txt · Last modified: 2018/08/14 16:52 by f43nd1r