User Tools

Site Tools


script_dim_bg

====== Differences ====== This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
script_dim_bg [2014/12/04 15:49]
lm13
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.3 
   * 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 ​avialable! (Check repository) +  * Download ​available! (Check repository)
- +
-====== Changelog ======  +
-  * Version 2.0 (28/​5/​2014):​ initial release in wiki +
-  * Version 2.1 (18/​7/​2014):​ auto create item +
-  * Version 2.2 (16/​11/​2014):​ bugfix, apk version contains UI +
-  * Version 2.3 (4/​12/​2014):​ bugfix+
  
 ====== 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  +
-Or: Simply load the apk in that folder+
  
 ====== 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 ====== 
 +<​spoiler|Setup ​Script
 +<sxh javascript;>​LL.bindClass("​android.app.AlertDialog"​);​ 
 +LL.bindClass("​android.content.DialogInterface"​);​ 
 +LL.bindClass("​android.widget.EditText"​);​ 
 +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(); <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 speed=data.speed||10;//​lower is faster, 1 for instant
 var dim=data.dim||150;//​0 for nothing, 255 for solid black 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 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 dp=d.getProperties();​
 var i=d.getItemByLabel("​bg"​)||d.addShortcut("​bg",​new Intent(),​0,​0);​ 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"&&​LL.getOpenFolders().length==0)+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 42: 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);​
Line 58: Line 167:
 x++; x++;
 p.edit().setInteger("​i.alpha",​x*dim/​speed).commit();​ p.edit().setInteger("​i.alpha",​x*dim/​speed).commit();​
 +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);​ if(x<​speed)setTimeout(a,​0);​
 } }
Line 66: Line 176:
 x--; x--;
 p.edit().setInteger("​i.alpha",​x*dim/​speed).commit();​ p.edit().setInteger("​i.alpha",​x*dim/​speed).commit();​
 +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);​ if(x>​0)setTimeout(b,​0);​
 else d.removeItem(i);​ else d.removeItem(i);​
 } }
-</​sxh>​+</sxh></​spoiler>
script_dim_bg.1417708176.txt.gz · Last modified: 2014/12/04 15:49 by lm13