var newvariabletext=” — create a new variable — “;
var vars;
var names;
//starts
show();
function show(){
LL.save();//save to force the file to be updated
vars=JSON.parse(read(“data/data/net.pierrox.lightning_launcher_extreme/files/variables”));//reads the content of the file
names=vars.v==null?[]:vars.v.map(function(a){return a.n+”: ‘”+a.v+”‘”});//extracts the variable names, if any
names.push(newvariabletext);//adds the ‘create variable’ entry
list(names,clicked,”Choose a variable, or create a new one”);//shows the list
}
//when clicked an element
function clicked(dialog,which){
var variable=vars.v[which];
if(which==names.length-1){
//the ‘add a variable’ entry chosen
addvariable();
}else{
//a variable chosen
editvariable(variable);
}
setTimeout(show,0);//shows the list again. On a timeout so the startActivity() is correctly launched before
}
//editing a variable
function editvariable(variable){
var name=variable.n;
//gets it’s type
var llvar=LL.getVariables();
var type=llvar.getType(variable.n);
//gets its value
var oldv=variable.v//vars.v.filter(function(obj){return obj.n==name})[0].v;
//asks for a new value
var newv=prompt(name+” (“+type+”)”,oldv);
if(newv==null){
//cancelled. delete?
if(confirm(“Do you want to delete this variable?”))llvar.edit().setString(name,null).commit();
return;
}
//update the value
lightningcall(name,newv);
}
//adding a variable
function addvariable(){
var name=””;
do{
//ask for a not-used name
name=prompt(“Name of the variable”,name);
}while(names.indexOf(name)!=-1&& !confirm(“This variable name is already used, do you want to continue? (will be overwritten)”));
if(name==null)return;//cancelled
//asks for the value
var value=prompt(“Value of the variable ‘”+name+”‘”,””);
if(value==null)return;//cancelled
//create the variable
lightningcall(name,value);
}
//calls lightning action ‘set a variable’
function lightningcall(name,value){
var intent=new Intent.getIntent(“#Intent;component=net.pierrox.lightning_launcher_extreme/net.pierrox.lightning_launcher.activities.Dashboard;i.a=41;end”);//the base intent
intent.putExtra(“d”,name+”/”+value);//the extra data
LL.startActivity(intent);
}
//function to display a List in a Popup, where the user can select one item. Taken from Lukas Morawietz’s Multi tool script
function list(items,onClickFunction,title){
var builder=new AlertDialog.Builder(LL.getContext());
var listener=new DialogInterface.OnClickListener()
< ![CDATA[
You should never have a need to delete a variable. If you no longer want it to have a value, you can set it to null.
]]>
< ![CDATA[
Use the variable editor by TrianguloY
]]>
< ![CDATA[
//classes
LL.bindClass(“android.app.AlertDialog”);
LL.bindClass(“android.content.DialogInterface”);
LL.bindClass(“java.io.BufferedReader”);
LL.bindClass(“java.io.FileReader”);
LL.bindClass(“java.io.File”);
//global variables
var newvariabletext=” — create a new variable — “;
var vars;
var names;
//starts
show();
function show(){
LL.save();//save to force the file to be updated
vars=JSON.parse(read(“data/data/net.pierrox.lightning_launcher_extreme/files/variables”));//reads the content of the file
names=vars.v==null?[]:vars.v.map(function(a){return a.n+”: ‘”+a.v+”‘”});//extracts the variable names, if any
names.push(newvariabletext);//adds the ‘create variable’ entry
list(names,clicked,”Choose a variable, or create a new one”);//shows the list
}
//when clicked an element
function clicked(dialog,which){
var variable=vars.v[which];
if(which==names.length-1){
//the ‘add a variable’ entry chosen
addvariable();
}else{
//a variable chosen
editvariable(variable);
}
setTimeout(show,0);//shows the list again. On a timeout so the startActivity() is correctly launched before
}
//editing a variable
function editvariable(variable){
var name=variable.n;
//gets it’s type
var llvar=LL.getVariables();
var type=llvar.getType(variable.n);
//gets its value
var oldv=variable.v//vars.v.filter(function(obj){return obj.n==name})[0].v;
//asks for a new value
var newv=prompt(name+” (“+type+”)”,oldv);
if(newv==null){
//cancelled. delete?
if(confirm(“Do you want to delete this variable?”))llvar.edit().setString(name,null).commit();
return;
}
//update the value
lightningcall(name,newv);
}
//adding a variable
function addvariable(){
var name=””;
do{
//ask for a not-used name
name=prompt(“Name of the variable”,name);
}while(names.indexOf(name)!=-1&& !confirm(“This variable name is already used, do you want to continue? (will be overwritten)”));
if(name==null)return;//cancelled
//asks for the value
var value=prompt(“Value of the variable ‘”+name+”‘”,””);
if(value==null)return;//cancelled
//create the variable
lightningcall(name,value);
}
//calls lightning action ‘set a variable’
function lightningcall(name,value){
var intent=new Intent.getIntent(“#Intent;component=net.pierrox.lightning_launcher_extreme/net.pierrox.lightning_launcher.activities.Dashboard;i.a=41;end”);//the base intent
intent.putExtra(“d”,name+”/”+value);//the extra data
LL.startActivity(intent);
}
//function to display a List in a Popup, where the user can select one item. Taken from Lukas Morawietz’s Multi tool script
function list(items,onClickFunction,title){
var builder=new AlertDialog.Builder(LL.getContext());
var listener=new DialogInterface.OnClickListener()
{
onClick:function(dialog,which)
{
dialog.dismiss();
setTimeout(function(){onClickFunction(dialog,which);},0);
return true;
}
}
builder.setItems(items,listener);
builder.setCancelable(true);
builder.setTitle(title);
builder.setNegativeButton(“Cancel”,new DialogInterface.OnClickListener(){onClick:function(dialog,id){dialog.cancel();}});//it has a Cancel Button
builder.show();
}
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);
}
]]>