The function parameters are passed by placing them in a list called "params" which is set each function call.
I use the "formatlist" and "fitonwatch" functions to take the contents of maps/lists stored in variables and display them with html formatting and bullets on my watch.
Example: Use voice commands to create lists and reminders using an AutoWear voice screen,
and immediately see items added to lists on an AutoWear text screen.
Call "formatlist" in any flow:
Code: Select all
outputlist=newList();headingcolor="red";keycolor="yellow";valuecolor="white";
// Function call
params=newList(remindermap["Times"], "--Daily ", ".*daily.*", "null", "ALARMS", formattedkeys);
eval(global_functions["formatlist"]);
// FUNCTION "formatlist" defined elsewhere
// Using the "formatlist" function in a flow:
// Create a list called "params" that will be passed to the function
// Your list or map will be params[0]
// Prefix each bullet with params[1]
// Only show elements containing params[2]
// Omit elements containing params[3]
// Use params[4] as a heading
// Provide the map keys in params[5] if params[0] is a map
// The map key will be put after the prefix and
// before " - " and the value. Sort your map keys
// before formatting them.
// Set variables headingcolor, keycolor, and valuecolor as "red", "yellow", etc.
split_function = newList("",
"list=params[0];prefix=params[1];contain=params[2];",
"omit=params[3];heading=params[4];formatkeys=params[5];",
"len=length(list);count=0;num=0;",
"if(len>0)if(heading!='') addElement(outputlist, '<font color='+headingcolor+'>'+heading+'</font>');",
"while(count<len){",
" count=count+1;",
" if(length(formatkeys)>0){", //then list is a map
" keys=sort(getMapKeys(list));key=keys[count-1];",
" formatkey=formatkeys[count-1]; thislistitem=replaceAll(list[key],' ',' ');}",
" else{",
" thislistitem=list[count-1]; formatkey='';}",
" if(matches(thislistitem,contain) AND not matches(thislistitem, omit) AND not isMap(thislistitem)){",
" num=num+1; addElement(outputlist, '<font color='+keycolor+'>'+prefix+formatkey+'</font> - <font color='+valuecolor+'>'+thislistitem+'</font>');}}",
"if(num==0 AND formatkeys!='') addElement(outputlist, prefix+'none');");
function="";
for(line in split_function) function=function+line;
addMapEntry(global_functions,"formatlist", function);
Call "fitonwatch" in any flow:
Code: Select all
// Function call
params=newList(outputlist);
eval(global_functions["fitonwatch"]);
// FUNCTION "fitonwatch" defined elsewhere
// After formatting your maps and lists using "formatlist", pass outputlist
// as params[0] to this function
split_function = newList("",
"list=params[0]; outputstring='<blockquote><blockquote>';",
"len=length(list); count=0;",
"while(count<len){",
" thislistitem=list[count];",
" outputstring=outputstring+thislistitem+'<br />';",
" count=count+1;}",
"outputstring=outputstring+'</blockquote></blockquote>'");
function="";
for(line in split_function) function=function+line;
addMapEntry(global_functions,"fitonwatch", function);
Let me know if you have questions, or have a better way of doing this.
I switched my global variable lists to local variables for sharing, so it wouldn't clog up your global variable list.
http://automagic4android.com/flow.php?i ... bd163f61e1