User Tools

Site Tools


script_app_drawer

====== 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_app_drawer [2015/03/20 23:49]
lm13
script_app_drawer [2015/04/23 14:49] (current)
lm13
Line 2: Line 2:
   * Purpose : This script will fill any container with all of your apps, like an App Drawer   * Purpose : This script will fill any container with all of your apps, like an App Drawer
   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]   * Author : [[https://​plus.google.com/​+LukasMorawietz|LM13]]
-  * Current Version : 3.0+  * Current Version : 3.2
   * Link: https://​plus.google.com/​115366157037831519359/​posts/​4F9TpMfz2fv   * Link: https://​plus.google.com/​115366157037831519359/​posts/​4F9TpMfz2fv
 +  * Video: https://​plus.google.com/​+LukasMorawietz/​posts/​L8r6qKajirq
   * Download available! (Check repository)   * Download available! (Check repository)
  
Line 12: Line 13:
   * Version 2.1 (28/​8/​2014):​ Sorting ignores Case   * Version 2.1 (28/​8/​2014):​ Sorting ignores Case
   * Version 3.0 (21/​3/​2015):​ Doesn'​t rely on LLs drawer anymore, hiding items improved   * Version 3.0 (21/​3/​2015):​ Doesn'​t rely on LLs drawer anymore, hiding items improved
 +  * Version 3.1 (21/​3/​2015):​ Fix crash on pre-lollipop devices, added reload
 +  * Version 3.2 (23/​4/​2015):​ Fix compatibility with latest Lightning Versions
  
  
Line 25: Line 28:
 //please report all bugs in the g+ community!//​ //please report all bugs in the g+ community!//​
  
 +====== Scripts ======
 <​spoiler|Setup>​ <​spoiler|Setup>​
 <sxh javascript;>​var MY_PKG="​net.pierrox.lightning_launcher.llscript.appdrawer";​ <sxh javascript;>​var MY_PKG="​net.pierrox.lightning_launcher.llscript.appdrawer";​
Line 62: Line 66:
 </​sxh>​ </​sxh>​
 </​spoiler>​ </​spoiler>​
- 
 <​spoiler|Menu>​ <​spoiler|Menu>​
 <sxh javascript;>​LL.bindClass("​android.R"​);​ <sxh javascript;>​LL.bindClass("​android.R"​);​
Line 69: Line 72:
 LL.bindClass("​android.widget.Button"​);​ LL.bindClass("​android.widget.Button"​);​
 LL.bindClass("​android.view.View"​);​ LL.bindClass("​android.view.View"​);​
 +LL.bindClass("​android.os.Build"​);​
  
 var sourceItem = LL.getEvent().getItem();​ var sourceItem = LL.getEvent().getItem();​
-var menuRoot=LL.getContext().getWindow().getDecorView().findViewById(R.id.content).getChildAt(0).getChildAt(2).getChildAt(2); +var context ​= LL.getContext()
-var menu = menuRoot.getChildAt(0);+var pkg = context.getPackageName()
 +var rsrc = context.getResources()
 +var id = rsrc.getIdentifier("​bubble_content",​ "id", ​ pkg)
 +var menu =context.getWindow().getDecorView().findViewById(id); 
 +var menuRoot ​= menu.getParent()
 +var version = Build.VERSION.SDK_INT;
  
 var obs=menuRoot.getViewTreeObserver();​ var obs=menuRoot.getViewTreeObserver();​
 var l=new ViewTreeObserver.OnGlobalLayoutListener(){ var l=new ViewTreeObserver.OnGlobalLayoutListener(){
-onGlobalLayout:​function() +    ​onGlobalLayout:​function(){ 
-+        var list=menu;​ 
-var list=menu.getChildAt(0)+        var first=list.getChildAt(0);​ 
-var first=list.getChildAt(0);​ +        list.removeAllViews();​ 
-list.removeAllViews();​ +        var v = !(typeof invisible === '​undefined'​ || invisible);​ 
-var v = !(typeof invisible === '​undefined'​ || invisible);​ +        add(v?"​Hide Hidden":"​Show Hidden",​function(){ 
-add(v?"​Hide Hidden":"​Show Hidden",​function(){ +            LL.runAction(EventHandler.LAUNCHER_MENU);​ 
-LL.runAction(EventHandler.LAUNCHER_MENU);​ +            invisible = v; 
-invisible = v; +            LL.runScript("​AppDrawer_main",​v?"":"​showHidden"​);​ 
-LL.runScript("​AppDrawer_main",​v?"":"​showHidden"​);​ +        },​first,​list);​ 
-},​first,​list);​ +        if(sourceItem!=null){ 
-if(sourceItem!=null){ +            v = !JSON.parse(sourceItem.getTag("​hide"​));​ 
-v = !JSON.parse(sourceItem.getTag("​hide"​));​ +            add(v?"​Hide":"​Unhide",​function(){ 
-add(v?"​Hide":"​Unhide",​function(){ +                LL.runAction(EventHandler.LAUNCHER_MENU);​ 
-LL.runAction(EventHandler.LAUNCHER_MENU);​ +                if(v)LL.getEvent().getContainer().setItemZIndex(sourceItem.getId(),​0);​ 
-if(v)LL.getEvent().getContainer().setItemZIndex(sourceItem.getId(),​0);​ +                sourceItem.setVisibility(!v);​ 
-sourceItem.setVisibility(!v);​ +                sourceItem.setTag("​hide",​v);​ 
-sourceItem.setTag("​hide",​v);​ +                LL.runScript("​AppDrawer_main",""​);​ 
-LL.runScript("​AppDrawer_main",""​);​ +            },​first,​list);​ 
-},​first,​list);​ +        
-+        ​add("​Reload",​function(){ 
-add("​Lightning Menu",​function(){ +            LL.runAction(EventHandler.LAUNCHER_MENU);​ 
-LL.runAction(EventHandler.LAUNCHER_MENU);​ +            LL.runScript("​AppDrawer_main","​reload"​);​ 
-if(sourceItem==null) LL.runAction(EventHandler.LAUNCHER_MENU) +        },​first,​list);​ 
-else LL.runAction(EventHandler.ITEM_MENU,​sourceItem,​null);​ +        ​add("​Lightning Menu",​function(){ 
-},​first,​list);​ +            LL.runAction(EventHandler.LAUNCHER_MENU);​ 
-obs.removeOnGlobalLayoutListener(l);​ +            if(sourceItem==null) LL.runAction(EventHandler.LAUNCHER_MENU) 
-return true; +            else LL.runAction(EventHandler.ITEM_MENU,​sourceItem,​null);​ 
-}+        },​first,​list);​ 
 +        obs.removeOnGlobalLayoutListener(l);​ 
 +        return true; 
 +    }
 }; };
  
Line 111: Line 123:
  
 function add(text,​onClickFunction,​first,​list){ function add(text,​onClickFunction,​first,​list){
-var t=new Button(LL.getContext());​ +    ​var t=new Button(LL.getContext());​ 
-t.setBackground(first.getBackground().mutate().getConstantState().newDrawable());​ +    ​if(version >= 16) t.setBackground(first.getBackground().mutate().getConstantState().newDrawable());​ 
-t.setTypeface(first.getTypeface());​ +    else t.setBackgroundDrawable(first.getBackground().mutate().newDrawable());​ 
-t.setAllCaps(false);​ +    ​t.setTypeface(first.getTypeface());​ 
-t.setTextSize(0,​first.getTextSize());​ +    ​if(version >= 14) t.setAllCaps(false);​ 
-t.setFontFeatureSettings(first.getFontFeatureSettings());​ +    t.setTextSize(0,​first.getTextSize());​ 
-t.setGravity(first.getGravity());​ +    ​if(version >= 21) t.setFontFeatureSettings(first.getFontFeatureSettings());​ 
-t.setText(text);​ +    t.setGravity(first.getGravity());​ 
-t.setOnClickListener(new View.OnClickListener(){ +    t.setText(text);​ 
-onClick:​onClickFunction +    t.setOnClickListener(new View.OnClickListener(){ 
-}); +    onClick:​onClickFunction 
-list.addView(t);​+    }); 
 +    list.addView(t);​
 } }
 </​sxh>​ </​sxh>​
 </​spoiler>​ </​spoiler>​
- +<​spoiler|Main>
- +
- +
-<​spoiler|Appdrawer>+
 <sxh javascript;>​var TAG = "​appdrawer_lukas";​ <sxh javascript;>​var TAG = "​appdrawer_lukas";​
  
Line 136: Line 146:
 var data=JSON.parse(c.getTag(TAG));​ var data=JSON.parse(c.getTag(TAG));​
 if(data == null)return;​ if(data == null)return;​
-var db=data.db||[];​+var db=data.db || [];
 var columns=data.columns;​ var columns=data.columns;​
 var rows=data.rows;​ var rows=data.rows;​
Line 143: Line 153:
 sort(); sort();
  
-if(db.length == 0){ +var initialize = (db.length == 0 || e.getData() == "​reload"​);​ 
-LL.bindClass("​android.app.ProgressDialog"​);​ +if(initialize){ 
-var progress = new ProgressDialog(LL.getContext());​ +    db = []; 
-progress.setTitle("​Initializing App Drawer"​) +    ​LL.bindClass("​android.app.ProgressDialog"​);​ 
-progress.setMessage("​Please wait..."​);​ +    var progress = new ProgressDialog(LL.getContext());​ 
-progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);​ +    progress.setTitle("​Initializing App Drawer"​) 
-progress.show();​+    progress.setMessage("​Please wait..."​);​ 
 +    progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);​ 
 +    progress.show();​
 } }
 setTimeout(function(){ setTimeout(function(){
-for(var a = 0; a < db.length; a++){ +    if(initialize){ 
-db[a][2] = false; +        var i=c.getItems();​ 
-}+     ​for(var a = 0; a < i.length; a++) c.removeItem(i.getAt(a));​ 
 +    } 
 +    for(var a = 0; a < db.length; a++) db[a][2] = false;
  
-var intent = new Intent(Intent.ACTION_MAIN);​ +    ​var intent = new Intent(Intent.ACTION_MAIN);​ 
-intent.addCategory(Intent.CATEGORY_LAUNCHER);​ +    intent.addCategory(Intent.CATEGORY_LAUNCHER);​ 
-var pm = LL.getContext().getPackageManager();​ +    var pm = LL.getContext().getPackageManager();​ 
-var apps = pm.queryIntentActivities(intent,​0);​ +    var apps = pm.queryIntentActivities(intent,​0);​ 
-for(var = 0; a < apps.size(); a++){ +    var = 0; 
-var app = apps.get(a); +    var f = function(){ 
-for(var b = 0; b < db.length && db[b][1] != app.activityInfo.name; b++); +        var app = apps.get(x); 
-if(b == db.length) { +        var name = app.activityInfo.name;​ 
-var i = new Intent(intent);​ +        var pkg = app.activityInfo.packageName;​ 
-i.setClassName(app.activityInfo.packageName,app.activityInfo.name); +        ​for(var b = 0; b < db.length && db[b][1] != name; b++); 
-var item = c.addShortcut(app.loadLabel(pm),​i,​0,​0);​ +        if(b == db.length) { 
-item.setName(item.getLabel());​ +            var i = new Intent(intent);​ 
-item.setTag("​hide",​false);​ +            i.setClassName(pkg, name); 
-var bmp = pm.getActivityIcon(i).getBitmap();​ +            var item = c.addShortcut(app.loadLabel(pm),​i,​0,​0);​ 
-var img = LL.createImage(bmp.getWidth(),​bmp.getHeight());​ +            item.setName(item.getLabel());​ 
-img.draw().drawBitmap(bmp,​0,​0,​null);​ +            item.setTag("​hide",​false);​ 
-item.setDefaultIcon(img);​ +            var bmp = pm.getActivityIcon(i).getBitmap();​ 
-item.getProperties().edit().setEventHandler("​i.longTap",​EventHandler.RUN_SCRIPT,​LL.getScriptByName("​AppDrawer_menu"​).getId()).commit();​ +            var img = LL.createImage(bmp.getWidth(),​bmp.getHeight());​ 
-db[b] = []; +            img.draw().drawBitmap(bmp,​0,​0,​null);​ 
-db[b][0] = item.getId();​ +            item.setDefaultIcon(img);​ 
-db[b][1] = app.activityInfo.name; +            item.getProperties().edit().setEventHandler("​i.longTap",​EventHandler.RUN_SCRIPT,​LL.getScriptByName("​AppDrawer_menu"​).getId()).commit();​ 
-+            db[b] = []; 
-db[b][2] = true; +            db[b][0] = item.getId();​ 
-} +            db[b][1] = name; 
-sort(); +        
-if(typeof progress !== '​undefined'​)progress.dismiss();​+        db[b][2] = true; 
 +        x++; 
 +        ​if(x<​apps.size()) setTimeout(f,​0);​ 
 +        else{ 
 +            ​sort(); 
 +            if(typeof progress !== '​undefined'​)progress.dismiss(); 
 +        } 
 +    }; 
 +    setTimeout(f,​0);
 },100); },100);
  
 function sort(){ function sort(){
-var labels=[];​ +    ​var labels=[];​ 
-for(var a = 0; a < db.length; a++){ +    for(var a = 0; a < db.length; a++){ 
-var item=LL.getItemById(db[a][0]);​ +        var item=LL.getItemById(db[a][0]);​ 
-if(db[a][2]){ +        if(db[a][2]){ 
-if(showHidden||!JSON.parse(item.getTag("​hide"​)))labels.push(item.getName());​ +            if(showHidden||!JSON.parse(item.getTag("​hide"​)))labels.push(item.getName());​ 
-else item.setVisibility(false);​ +            else item.setVisibility(false);​ 
-+        
-else{ +        else{ 
-c.removeItem(item);​ +            c.removeItem(item);​ 
-db.splice(a,​1);​ +            db.splice(a,​1);​ 
-a--; +            a--; 
-+        
-+    
-data.db = db; +    data.db = db; 
-c.setTag(TAG,​JSON.stringify(data));​ +    c.setTag(TAG,​JSON.stringify(data));​ 
-labels.sort(noCaseSort);​ +    labels.sort(noCaseSort);​ 
-for(var a = 0; a < labels.length;​ a++){ +    for(var a = 0; a < labels.length;​ a++){ 
-var item = c.getItemByName(labels[a]);​ +        var item = c.getItemByName(labels[a]);​ 
-item.setVisibility(true);​ +        item.setVisibility(true);​ 
-if(rows==0)item.setCell(a%columns,​Math.floor(a/​columns),​a%columns+1,​Math.floor(a/​columns)+1);​ +        if(rows==0)item.setCell(a%columns,​Math.floor(a/​columns),​a%columns+1,​Math.floor(a/​columns)+1);​ 
-else item.setCell(a%columns+columns*Math.floor(a/​(rows*columns)),​Math.floor(a/​columns)-rows*Math.floor(a/​(rows*columns)),​a%columns+columns*Math.floor(a/​(rows*columns))+1,​Math.floor(a/​columns)-rows*Math.floor(a/​(rows*columns))+1);​ +        else item.setCell(a%columns+columns*Math.floor(a/​(rows*columns)),​Math.floor(a/​columns)-rows*Math.floor(a/​(rows*columns)),​a%columns+columns*Math.floor(a/​(rows*columns))+1,​Math.floor(a/​columns)-rows*Math.floor(a/​(rows*columns))+1);​ 
-+    
-c.getItemByName(labels[a]) +    c.getItemByName(labels[a]) 
-LL.save();+    LL.save();
 } }
  
script_app_drawer.1426895380.txt.gz · Last modified: 2015/03/20 23:49 by lm13