I’d like to use a script to update the box background of an item by referencing a file on my sdcard, but can’t get…

I’d like to use a script to update the box background of an item by referencing a file on my sdcard, but can’t get the setBoxBackground command to work. Could use some help from the script experts here …

]]>

15 Commentsto I’d like to use a script to update the box background of an item by referencing a file on my sdcard, but can’t get…

  1. Anonymous says:

    < ![CDATA[

    Post what you already have, otherwise we can’t tell you whats wrong.

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Here’s what I have … I get a “Can’t find method net.pierrox.lightning_launcher.b.a.k.setBoxBackground(string)” error on line 2. Thanks!



    var item=LL.getCurrentDesktop().getItemByName(‘map’);


    item.setBoxBackground(‘/storage/emulated/0/Tasker/map.png’);

    ]]>

  3. Anonymous says:

    < ![CDATA[

    setBoxBackground requires an image.


    Create an image from the file first, then pass it to setBocBackground. Additionally setBoxBackground requires you to pass a second argument: the state. Normally you want to set this to “nsf”.




    see http://www.pierrox.net/android/applications/lightning_launcher/script/reference/net/pierrox/lightning_launcher/script/api/Item.html#setBoxBackground%28net.pierrox.lightning_launcher.script.api.Image,%20java.lang.String%29

    ]]>

  4. Anonymous says:

    < ![CDATA[

    Lukas Morawietz thank you, that did the trick! I have two follow-up questions if you don’t mind:


    1. If I use the permissions manager you created to allow internet access, is it possible for the image to be directly linked to a URL (specifically, I want to do a http get of static google maps image)? I’m currently using Tasker to run the http get but because scripting needs LL in the foreground it’s cumbersome


    2. I’d like the same script (refresh map image) to run when I scroll the desktop right (so the map page comes into view). What’s the best way of doing this? Stop points? I tried the “resume” event but it doesn’t trigger when the page comes into view, only when the desktop status is changed

    ]]>

  5. Anonymous says:

    < ![CDATA[

    With the internet permission you can use HTTP APIs to fetch data from the internet although this is not exactly straightforward. A simple thing that may work (not tested) is to use a custom view with a single ImageView and use ImageView.setImageUri(“http://your_image“);

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Pierre Hébert would it look something like this? noob at scripts and haven’t used custom view before so here’s what I gathered from looking up online …



    var item=LL.getCurrentDesktop().getItemByName(‘map’);


    var image= new ImageView();


    image.setImageUri(“http://your_image“);


    item.setBoxBackground(image, “nsf”);

    ]]>

  7. Anonymous says:

    < ![CDATA[

    No, because setBoxBackground does not need an ImageView but an Image object.



    What you need to do instead is add a Custom View item and edit its create script with the following:


    LL.bindClass(“android.widget.ImageView”);


    var image_view= new ImageView();


    image_view.setImageUri(“http://your_image“);


    return image_view;



    The ImageView is an Android component that may take care of loading the image using the “content resolver”, but again I didn’t tested whether it works with http URIs. To test whether the image can be loaded from a file you can use this URI: “file:///path/to/the/image”.

    ]]>

  8. Anonymous says:

    < ![CDATA[

    Here’s what I tried, but I get a TypeError: Cannot find function setImageUri in object android.widget.ImageView … any advice?



    LL.bindClass(“android.widget.ImageView”);


    var imgView=new ImageView(LL.getContext());


    imgView.setImageUri(‘file:///storage/emulated/0/Tasker/map.png’);


    return imgView;

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Oh sorry, my bad, I forgot that the string need to be converted to a Uri object, this way:



    imgView.setImageUri(Uri.parse(‘file:///storage/emulated/0/Tasker/map.png’));

    ]]>

  10. Anonymous says:

    < ![CDATA[

    Thanks for the quick response! Tried that too but get the same error …

    ]]>

  11. Anonymous says:

    < ![CDATA[

    Arggg, this is setImageURI not setImageUri, lol

    ]]>

  12. Anonymous says:

    < ![CDATA[

    Thanks! Changing to URI worked, but unfortunately setImageURI does not allow for http retrieval. Looks like one needs to download the file to SD or an image cache first …

    ]]>

  13. Anonymous says:

    < ![CDATA[

    Ok, as expected this was less than obvious, but here is a sample script to fetch an image from a random Internet source:



    LL.bindClass(“android.os.Handler”);


    LL.bindClass(“android.widget.ImageView”);


    LL.bindClass(“java.net.URL”);


    LL.bindClass(“java.lang.Thread”);


    LL.bindClass(“java.lang.Runnable”);


    LL.bindClass(“android.graphics.BitmapFactory”);



    var i = new ImageView(LL.getContext());



    // cannot use AsyncTask, so use a Thread and a Handler


    var handler = new Handler();



    new Thread(new Runnable({


        run: function(params) {


            var con = null;


            var is = null;


            try {


                var url = new URL(“http://lorempixel.com/400/200/“);


                con = url.openConnection();


                is = con.getInputStream();


                var bitmap = BitmapFactory.decodeStream(is);



                handler.post(new Runnable({


                    run: function() {


                        if(bitmap != null) {


                            i.setImageBitmap(bitmap);


                        } else {


                            // error handling here


                        }


                    }


                }));


            } catch(e) {


                return null;


            } finally {


                if(is != null) try { is.close(); } catch(e) {}


                if(con != null) con.disconnect();


            }


        }


    })).start();



    return i;



    (I’ll put this on the wiki so that it can be imported easily)

    ]]>

  14. Anonymous says:

    < ![CDATA[

    Thank you … will try this out

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *