Hi everyone

Hi everyone,

I tried building a preference screen to easily customize the colors and fonts of my homescreen that consists of Zooper and/or KWGT widgets. I followed the clock example on lightninglauncher.com and tried to run the script on the push of an icon, but nothing happens.

Can anyone please shed some more light on the process of accomplishing this?

I might end up creating a little add-on that can be used in conjunction with LLX to easily set up variables with colors and fonts and broadcast those values to LLX, Tasker, Zooper and KWGT.

]]>

23 Commentsto Hi everyone

  1. Anonymous says:

    < ![CDATA[

    Just a script about variable could be fine here.. Variable editor by TrianguloY​​


    Plus Tasker

    ]]>

  2. Anonymous says:

    < ![CDATA[

    The Variable Editor does work fine for text variables, but I would like to implement the colour picker for colour variables

    ]]>

  3. Anonymous says:

    < ![CDATA[

    Rudolph van Coppenhagen of course it works. It works for all types. I’m using it for my automatic sms text

    ]]>

  4. Anonymous says:

    < ![CDATA[

    Uhm…I think you missed the part about the colour picker

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Rudolph van Coppenhagen I’ll try it. Never tried. Could you give an example of the variable you are trying to set ?

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Well, basically I would like to edit variables containing color information using the LLPreferenceColor class. So everything is the same as the variable editor, except you use a color picker to edit the value.


    http://www.lightninglauncher.com/scripting/reference/api/reference/net/pierrox/lightning_launcher/prefs/LLPreferenceColor.html

    ]]>

  7. Anonymous says:

    < ![CDATA[

    Rudolph van Coppenhagen ah OK. TrianguloY​ is it possible to use color picker and to record the value in a variable ?

    ]]>

  8. Anonymous says:

    < ![CDATA[

    Perhaps, although with the simple dialogs the script is using it will be a bit tedious to choose between editing text or color. Using the LLPreference classes is an interesting option, but I didn’t play enough with them and currently I don’t think I can.

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Ok well just knowing it is (might be) possible and having TrianguloY​’s Variable Editor to reverse engineer, I will play with it and whatever I accomplish I will share. Thank you both for your time and effort in replying.

    ]]>

  10. Anonymous says:

    < ![CDATA[

    Rudolph van Coppenhagen the script is publicly available and you can edit/modify/share it as you want, and if you improve it I will like to see it 🙂


    I wrote some comments, and shouldn’t be very difficult to understand (maybe) but if you have any question ask!

    ]]>

  11. Anonymous says:

    < ![CDATA[

    Thanks a lot mate. I will tag you when I am done with it and share it ☺

    ]]>

  12. Anonymous says:

    < ![CDATA[

    Sorry for the delay. Could you share the script please?


    Using LLPreference is the way to go, maybe you are just missing a single step.

    ]]>

  13. Anonymous says:

    < ![CDATA[

    Hi Pierre Hébert​. I’m super glad you could join the conversation.☺ I have been reverse engineering the Variable Editor and I know now where I went wrong with the LLPreference.



    I have a new issue now. Lol!


    Like TrianguloY​ reads the variables file in the Variable Editor, I would like to differentiate between variables containing color information, variables containing font name, and then any other variables. So I would want to have 3 LLPreferenceCategory preferences (Colors, Fonts, Other).



    How can I evaluate these variables after or while extracting them from the variables file and create them in the LLPreferenceListView using the appropriate class (LLPreferenceColor or LLPreferenceText etc)



    I will share the script in my next comment below. I just want to tidy up the code quickly.

    ]]>

  14. Anonymous says:

    < ![CDATA[

    LL.bindClass(“android.app.AlertDialog“);


    LL.bindClass(“android.content.DialogInterface“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceListView“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceColor“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceCategory“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceCheckBox“);




    //global variables


    var context = LL.getContext();


    var newvariabletext = ” — create a new variable — “;


    var vars;


    var colorvars;


    var fontvars;


    var othervars;


    var names;



    showSettings();





    // Build and show a dialog with preferences


    function showSettings()


    {


    // Save to force the file to be updated


    LL.save();



    // Reads the content of the file


    vars = JSON.parse(read(“data/data/net.pierrox.lightning_launcher_extreme/files/variables”));



    // Extracts the variable names, if any


    names = vars.v == null ? [] : vars.v.map(function(a){return a.n+”: ‘”+a.v+”‘”});



    // if variable value is null then return nothing… else if the variable name contains “clr” return it in a color preference… else if the variable contains “fnt” return it in a text preference… else return the variable as TrianguloY originally returned it.



    if (vars.v == null)


    {


    names = [];


    }


    else if (vars.n.substring(“clr”, vars.n))


    {


    var colorvar = vars.n;


    return new LLPreferenceColor(0, colorvar, colorvar, vars.v, vars.v, true);


    }


    else if (vars.n.substring(“fnt”, vars.n))


    {


    var fontvar = vars.n;


    return new LLPreferenceText(0, fontvar, fontvar, vars.v, vars.v);


    }


    else


    {


    var othervar = vars.n;


    return new LLPreferenceText(0, othervar, othervar, vars.v, vars.v);


    }



    // Adds the ‘create variable’ entry


    names.push(newvariabletext);




    // Description of preferences


    var catColor = new LLPreferenceCategory(0, “COLORS”);


    var catFonts = new LLPreferenceCategory(0, “FONTS”);


    var clrPrimaryText = new LLPreferenceColor(0, “Primary Text”, “clrPrimaryText”, 0xff484848, 0xff484848, true);



    // Create a listview to display preferences


    var listView = new LLPreferenceListView(context, null);


    listView.setPreferences([ catColor, clrPrimaryText, catFonts ]);



    // Setup the dialog and assign it’s content view with the preference list view


    var builder = new AlertDialog.Builder(context);


    builder.setView(listView);


    builder.setCancelable(true);


    builder.setTitle(“LLX Themer”);



    /* OK button will use TrianguloY’s function to edit variable and save it back into the file



    // Create OK button and click function


    builder.setPositiveButton(“OK”,


    {onClick:function(dialog, id)


    {



    }


    });


    */



    // Create CANCEL button


    builder.setNegativeButton(“CANCEL”, new DialogInterface.OnClickListener() {onClick:function(dialog, id){dialog.cancel();}});


    builder.show();


    }




    // File reader


    function read(filePath)


    {


    var file = new File(filePath);


    var r = new BufferedReader(new FileReader(file));


    var s = “”;


    var l;



    while((l=r.readLine())!=null)s+=(l+”\n”);


    return s.substring(0, s.length – 1);


    }


    ]]>

  15. Anonymous says:

    < ![CDATA[

    If you use direct decoding of the file using the JAvaScript engine JSON implementation, then you may be able to use the JavaScript keyword “typeof” which will return the type of the data.


    Otherwise you can also ask Lightning about the variable type (if it is in sync with the file), using Variable.getType()



    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof


    http://www.lightninglauncher.com/scripting/reference/api/reference/net/pierrox/lightning_launcher/script/api/VariableSet.html#getType(java.lang.String)

    ]]>

  16. Anonymous says:

    < ![CDATA[

    Yes, try to use “typeof vars.v”, I think it should work.

    ]]>

  17. Anonymous says:

    < ![CDATA[

    I do get errors since I added the part from the beginning of the showSettings function to the “// Adds the ‘create variable’ entry”.



    If that part is removed the dialog works, but I would like to make it flexible by allowing a user to use his already existing variables (if possible). Otherwise, I will hard-code a wide range of variables and make them configurable and then user can replace variables in his/her setup with the script’s

    ]]>

  18. Anonymous says:

    < ![CDATA[

    So my else if statements should look as follows?



    Else if (typeof vars.v == “color”)


    {


    var colorvar = vars.n


    return new LLPreferenceColor(0, colorvar, colorvar, vars.v, vars.v, true);


    }

    ]]>

  19. Anonymous says:

    < ![CDATA[

    The result of typeof will be one of “number”, “string”, “boolean”, etc. (please see the mozilla link above for the exact values). Colors are not a type by themselves, they are integer. Same for fonts, they are strings (stored as the path to the font file). There’s a font picker in Lighting but it’s not available to scripts yet.



    The issue with the script is your use of vars.


    A sample variable file is:


    {


    “v”: [


    {


    “n”: “a”,


    “v”: 5,


    }


    ]


    }



    This means:


    – there’s a “v” object


    – “v” is an array


    – in that array there is one object with “n” (for name) and “v” (for value) properties, with values “a” and 5. It defines a variable whose name is “a” and value number 5


    Hence to access variables you need to iterate over vars.v, and use an index to access a given variable, for instance:


    vars.v[0].n –> “a”


    vars.v[0].v –> 5

    ]]>

  20. Anonymous says:

    < ![CDATA[

    Pierre Hébert​ I had time to continue with this today. I’m getting the attached error though. If I am understanding what I am doing, then I think it is because I am trying to create the preferences based on the data type of variable and then add them to the appropriate array of preferences in my for-loop and the LLPreferenceListView.setPreferences method does not allow me to add preferences in the form of arrays.



    If you have the time, pleeeease check my script in the next comment to see where I am going wrong? I really appreciate all the support, time and effort.



    P.S -> line 74 is the “listView.setPreferences” statement.



    https://lh3.googleusercontent.com/dY6esO4gHF_K01d_K62J0za6VDQoXMAZWbk96hqwwci1P3ub4flETQ2y2QlsTYpiovu1BQ8EWw

    ]]>

  21. Anonymous says:

    < ![CDATA[

    Here is my script…




    LL.bindClass(“java.io.BufferedReader“);


    LL.bindClass(“java.io.FileReader“);


    LL.bindClass(“java.io.File“);


    LL.bindClass(“android.app.AlertDialog“);


    LL.bindClass(“android.content.DialogInterface“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreference“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceListView“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceColor“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceCategory“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceCheckBox“);


    LL.bindClass(“net.pierrox.lightning_launcher.prefs.LLPreferenceText“);




    //global variables


    var context = LL.getContext();


    var newvariabletext = ” — create a new variable — “;


    var vars;


    var names;


    var colorvars = [];


    var intvars = [];


    var textvars = [];


    var othervars = [];


    showSettings();





    // Build and show a dialog with preferences


    function showSettings()


    {


    // Save to force the file to be updated


    LL.save();



    // Reads the content of the file


    vars = JSON.parse(read(“data/data/net.pierrox.lightning_launcher_extreme/files/variables”));



    // Extracts the variable names (if any) and assign them to the correct LLPreference type array


    names = vars.v == null ? [] : vars.v.map(function(a)


    {


    for (var i = 0; i < vars.v.length – 1; i++)


    {


    if (typeof a[i]==”integer” && a[i].v.length==9)


    {


    colorvars.push = new LLPreferenceColor(0, a.v[i].n, null, a.v[i].v, a.v[i].v, true);


    }


    else if (typeof a[i]==”integer” && a[i].v.length<9)


    {


    intvars.push = new LLPreference(0, a.v[i].n, null, a.v[i].v, a.v[i].v);


    }


    else if (typeof a[i]==”string”)


    {


    textvars.push = new LLPreferenceText(0, a.v[i].n, a.v[i].v, a.v[i].v);


    }


    else


    {


    othervars.push = new LLPreference(0, vars.v[i].n, null, vars.v[i].v, vars.v[i].v);


    }


    }


    });




    // Adds the ‘create variable’ entry


    names.push(newvariabletext);




    // Description of preferences


    var catColor = new LLPreferenceCategory(0, “COLORS”);


    var catInt = new LLPreferenceCategory(0, “INTEGERS”);


    var catString = new LLPreferenceCategory(0, “STRINGS”);


    var catOther = new LLPreferenceCategory(0, “OTHER”);




    // Create a listview to display preferences


    var listView = new LLPreferenceListView(context, null);


    listView.setPreferences([ catColor, colorvars, catInt, intvars, catString, textvars, catOther, othervars ]);



    // Setup the dialog and assign it’s content view with the preference list view


    var builder = new AlertDialog.Builder(context);


    builder.setView(listView);


    builder.setCancelable(true);


    builder.setTitle(“LLX Themer”);




    /* ADD button will use TrianguloY’s function to add variable and save it back into the file



    // Create ADD button and click function


    builder.setPositiveButton(“ADD”,


    {onClick:function(dialog, id)


    {



    }


    });


    */




    /* OK button will use TrianguloY’s function to edit variable and save it back into the file



    // Create OK button and click function


    builder.setPositiveButton(“OK”,


    {onClick:function(dialog, id)


    {



    }


    });


    */




    // Create CANCEL button


    builder.setNegativeButton(“CANCEL”, new DialogInterface.OnClickListener(){onClick:function(dialog, id){dialog.cancel();}});


    builder.show();



    }




    // File reader


    function read(filePath)


    {


    var file = new File(filePath);


    var r = new BufferedReader(new FileReader(file));


    var s = “”;


    var l;



    while((l=r.readLine())!=null)s+=(l+”\n”);


    return s.substring(0, s.length – 1);


    }


    ]]>

  22. Anonymous says:

    < ![CDATA[

    Still stuck with this. Can anyone please help?

    ]]>

  23. Anonymous says:

    < ![CDATA[

    Ok, support officially sucks

    ]]>

Leave a Reply

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