====== Differences ====== This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
script_dim_bg [2014/07/18 12:07] lm13 [About the script] |
script_dim_bg [2015/07/25 12:19] (current) lm13 |
||
---|---|---|---|
Line 2: | Line 2: | ||
* Purpose : This script will dim all other stuff if you open a folder | * Purpose : This script will dim all other stuff if you open a folder | ||
* 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/24AHYbCWrXn | * Link : https://plus.google.com/115366157037831519359/posts/24AHYbCWrXn | ||
* Video : https://plus.google.com/115366157037831519359/posts/3ZY4BWnZbmp | * Video : https://plus.google.com/115366157037831519359/posts/3ZY4BWnZbmp | ||
- | + | * Download available! (Check repository) | |
- | ====== Changelog ====== | + | |
- | * Version 2.0 (28/5/2014): initial release in wiki | + | |
- | * Version 2.1 (18/7/2014): auto create item | + | |
====== How to use the script ====== | ====== How to use the script ====== | ||
- | * in the folder: set the script to paused and resumed event | + | * see Play Store |
- | * set up configuration if you don't like the standard values | + | |
====== Issues and hints ====== | ====== Issues and hints ====== | ||
* the orientation fix may interfere with your desktop boundings, so keep it off unless you need it | * the orientation fix may interfere with your desktop boundings, so keep it off unless you need it | ||
+ | * Note: The setup Script won't work outside of the APK | ||
//please report all bugs in the g+ community// | //please report all bugs in the g+ community// | ||
- | ====== Script code ====== | + | ====== Code ====== |
- | <code>/*config*/ | + | <spoiler|Setup Script> |
- | var speed=10;//lower is faster, 1 for instant | + | <sxh javascript;>LL.bindClass("android.app.AlertDialog"); |
- | var dim=150;//0 for nothing, 255 for solid black | + | LL.bindClass("android.content.DialogInterface"); |
- | var orientationfix=false;//true if you want to switch screen orientation while folder open | + | LL.bindClass("android.widget.EditText"); |
- | /*endconfig*/ | + | LL.bindClass("android.widget.TextView"); |
+ | LL.bindClass("android.widget.LinearLayout"); | ||
+ | LL.bindClass("android.widget.CheckBox"); | ||
+ | LL.bindClass("android.text.InputType"); | ||
+ | var MY_PKG="com.faendir.lightning_launcher.dimbackground"; | ||
+ | // 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; | ||
+ | } | ||
+ | |||
+ | //function to display an alert like Dialog, but scrollable and with custom Title | ||
+ | function text(txt,title) | ||
+ | { | ||
+ | var builder=new AlertDialog.Builder(LL.getContext()); | ||
+ | builder.setMessage(txt); | ||
+ | builder.setCancelable(true); | ||
+ | builder.setTitle(title); | ||
+ | builder.setNeutralButton("Close",new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.dismiss();}}); | ||
+ | builder.create().show(); | ||
+ | } | ||
+ | |||
+ | var c=LL.getEvent().getContainer(); | ||
+ | if(c.getType()!="Container"||c.getOpener()==null||c.getOpener().getType()!="Folder")text("This Script doesn't work outside of Folders.\nLoad it in a Folder!","Error"); | ||
+ | else | ||
+ | { | ||
+ | c.getOpener().close(); | ||
+ | var data=JSON.parse(LL.getEvent().getContainer().getTag("dim"))||new Object(); | ||
+ | var script=installScript("dimbackground","DimBackground"); | ||
+ | LL.runScript(script.getName(),null); | ||
+ | var root=new LinearLayout(LL.getContext()); | ||
+ | root.setOrientation(LinearLayout.VERTICAL); | ||
+ | var speedHint=new TextView(LL.getContext()); | ||
+ | speedHint.setText("Speed to fade in/out for this folder (lower is faster, 1 for instant):"); | ||
+ | root.addView(speedHint); | ||
+ | var speedInput=new EditText(LL.getContext()); | ||
+ | speedInput.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT)); | ||
+ | speedInput.setInputType(InputType.TYPE_CLASS_NUMBER); | ||
+ | speedInput.setText(data.speed||"10"); | ||
+ | root.addView(speedInput); | ||
+ | var dimHint=new TextView(LL.getContext()); | ||
+ | dimHint.setText("How dark should it be (0..255):"); | ||
+ | root.addView(dimHint); | ||
+ | var dimInput=new EditText(LL.getContext()); | ||
+ | dimInput.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT)); | ||
+ | dimInput.setInputType(InputType.TYPE_CLASS_NUMBER); | ||
+ | dimInput.setText(data.dim||"200"); | ||
+ | root.addView(dimInput); | ||
+ | var barBox = new CheckBox(LL.getContext()); | ||
+ | barBox.setText("Tint System Bars"); | ||
+ | barBox.setChecked(data.bars||true); | ||
+ | root.addView(barBox); | ||
+ | var fixBox=new CheckBox(LL.getContext()); | ||
+ | fixBox.setText("Orientationfix (Fixes bug when changing orientation while folder opened, but may break desktop boundings)"); | ||
+ | fixBox.setChecked(data.fix||false); | ||
+ | root.addView(fixBox); | ||
+ | var builder=new AlertDialog.Builder(LL.getContext()); | ||
+ | builder.setView(root); | ||
+ | builder.setCancelable(true); | ||
+ | builder.setTitle("Setup: Folder Dim"); | ||
+ | builder.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.cancel();}}); | ||
+ | builder.setPositiveButton("Confirm",new DialogInterface.OnClickListener() | ||
+ | { | ||
+ | onClick:function(dialog,id) | ||
+ | { | ||
+ | var speed=speedInput.getText().toString(); | ||
+ | var dim=dimInput.getText().toString(); | ||
+ | if(speed<=0||dim<0||dim>255) | ||
+ | { | ||
+ | Android.makeNewToast("Error:\nOne or more arguments are out of range. Please make sure that speed is 1 or bigger and dim is between 0 and 255",false).show(); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | dialog.dismiss(); | ||
+ | item=c.getItemByLabel("bg"); | ||
+ | while(item!=null) | ||
+ | { | ||
+ | c.removeItem(item); | ||
+ | item=c.getItemByLabel("bg"); | ||
+ | } | ||
+ | var data=new Object(); | ||
+ | data.speed=speed; | ||
+ | data.dim=dim; | ||
+ | data.fix=fixBox.isChecked(); | ||
+ | data.bars=barBox.isChecked(); | ||
+ | c.setTag("dim",JSON.stringify(data)); | ||
+ | c.getProperties().edit().setEventHandler("resumed",EventHandler.RUN_SCRIPT,script.getId()).setEventHandler("paused",EventHandler.RUN_SCRIPT,script.getId()).commit(); | ||
+ | Android.makeNewToast("Done!",true).show(); | ||
+ | c.getOpener().open(); | ||
+ | } | ||
+ | } | ||
+ | }); | ||
+ | builder.create().show(); | ||
+ | } | ||
+ | </sxh> | ||
+ | </spoiler> | ||
+ | <spoiler|Dim Script> | ||
+ | <sxh javascript;>var data=JSON.parse(LL.getEvent().getContainer().getTag("dim"))||new Object(); | ||
+ | var speed=data.speed||10;//lower is faster, 1 for instant | ||
+ | var dim=data.dim||150;//0 for nothing, 255 for solid black | ||
+ | var orientationfix=data.fix;//true if you want to switch screen orientation while folder open | ||
+ | var tintBars=data.bars; | ||
+ | |||
+ | |||
var d=LL.getCurrentDesktop(); | var d=LL.getCurrentDesktop(); | ||
- | var i=d.getItemByLabel("bg")||d.addShortcut("bg",new Intent(),0,0); | + | var dp=d.getProperties(); |
+ | var i=d.getItemByLabel("bg")||d.addShortcut("bg",new Intent(),0,0); | ||
var p=i.getProperties(); | var p=i.getProperties(); | ||
- | if(LL.getEvent().getSource()=="C_RESUMED") | + | if(LL.getEvent().getSource()=="C_RESUMED"&&LL.getOpenFolders().length==1) |
{ | { | ||
d.setItemZIndex(i.getId(),d.getItems().getLength()-1); | d.setItemZIndex(i.getId(),d.getItems().getLength()-1); | ||
Line 39: | Line 150: | ||
if(orientationfix){ | if(orientationfix){ | ||
var s=Math.max( d.getWidth(),d.getHeight())*1.1; | var s=Math.max( d.getWidth(),d.getHeight())*1.1; | ||
- | i.setSize(s,s);} | + | i.setSize(s,s); |
+ | } | ||
else i.setSize( d.getWidth(),d.getHeight()); | else i.setSize( d.getWidth(),d.getHeight()); | ||
i.setPosition(0,0); | i.setPosition(0,0); | ||
- | var i=0; | + | var x=0; |
a(); | a(); | ||
} | } | ||
- | else { | + | else if(LL.getOpenFolders().length==0){ |
- | var i=speed; | + | var x=speed; |
b(); | b(); | ||
} | } | ||
- | + | ||
+ | |||
function a() | function a() | ||
{ | { | ||
- | i++; | + | x++; |
- | p.edit().setInteger("i.alpha",i*dim/speed).commit(); | + | p.edit().setInteger("i.alpha",x*dim/speed).commit(); |
- | if(i<speed)setTimeout(a,0); | + | if(tintBars)dp.edit().setInteger("statusBarColor",Color.argb(x*dim/speed,0,0,0)).setInteger("navigationBarColor",Color.argb(x*dim/speed,0,0,0)).commit(); |
+ | if(x<speed)setTimeout(a,0); | ||
} | } | ||
- | + | ||
+ | |||
function b() | function b() | ||
{ | { | ||
- | i--; | + | x--; |
- | p.edit().setInteger("i.alpha",i*dim/speed).commit(); | + | p.edit().setInteger("i.alpha",x*dim/speed).commit(); |
- | if(i>0)setTimeout(b,0); | + | if(tintBars)dp.edit().setInteger("statusBarColor",Color.argb(x*dim/speed,0,0,0)).setInteger("navigationBarColor",Color.argb(x*dim/speed,0,0,0)).commit(); |
+ | if(x>0)setTimeout(b,0); | ||
+ | else d.removeItem(i); | ||
} | } | ||
- | </code> | + | </sxh></spoiler> |