var quotes = [ ];
var quotesFile = app.GetAppPath()+"/quotes.json";
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a text label and add it to layout.
txt = app.CreateText( "Hello" );
txt.SetTextSize( 32 );
lay.AddChild( txt );
//create a button
qotd = app.CreateButton("Qotd");
qotd.SetOnTouch(qotd_OnTouch);
lay.AddChild(qotd, "Quote of the Day");
//Add layout to app.
app.AddLayout( lay );
var temp = app.ReadFile(quotesFile);
quotes = JSON.parse(temp)
}
function qotd_OnTouch()
{
var len = quotes.length;
var pos = Math.floor(Math.random()*len);
app.Alert(quotes[pos])
}
var quotes = ["This app has no quotes","Please add a quotes file","When you add a quotes file it should be in JSON format" ];
quotesFile = "quotes.json";
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
lay.SetBackColor("#ddffdd")
//Create a text label and add it to layout.
txt = app.CreateText( "Please press button for quote" );
txt.SetTextSize( 18 );
txt.SetTextColor( "#224422" )
lay.AddChild( txt );
//create a button
qotd = app.CreateButton("Qotd");
qotd.SetOnTouch(qotd_OnTouch);
qotd.SetBackColor("#224422")
qotd.SetTextSize(24)
lay.AddChild(qotd, "Quote of the Day");
//Add layout to app.
app.AddLayout( lay );
if(app.FileExists(quotesFile))
quotes = JSON.parse(app.ReadFile(quotesFile))
// create a popup with size 24 text, background and text colors
tempDisplay = createPopup(24,"#446644", "#ddffdd" );
}
function qotd_OnTouch()
{
var len = quotes.length;
var pos = Math.floor(Math.random()*len);
// display for at least 5 seconds
tempDisplay.Popup(quotes[pos], 5)
}
function createPopup(textSize, backColor, textColor)
{
var dlg = app.CreateDialog( "","noTitle,noDim,noCancel" );
var lay = app.CreateLayout( "linear", "vertical,fillxy,left" );
lay.SetPadding( 0.02, 0, 0.02, 0.02 );
if (backColor) lay.SetBackColor( backColor )
dlg.AddLayout( lay );
var txt = app.CreateText( "",-1,-1,"multiLine");;
if(textSize) txt.SetTextSize( textSize );
if(textColor) txt.SetTextColor(textColor)
lay.AddChild( txt );
dlg.Popup = function(text, seconds)
{
txt.SetText( text );
seconds = seconds || 1;
dlg.Show();
setTimeout(dlg.Dismiss, seconds*1000);
}
return dlg;
}
This doesn't really answer your question because I don't really undetstand your question.
However, this version uses a JSON database I found in github and shows one way to deal with storing authors along with quotes.
Once you have worked out what that does, you may find there is a great chunk of code you can you can dispense with.
Believe it or not, I don't keep every line of code I write as answers for for other people.
Have you tried it?
The idea of using other people's code to help with writing your app is that you study it to learn how it works.
It can't be that difficult to find the code that displays the quote.
Once you have done that, you can add app.TextToSpeech() so that you have both the display and the speech working.
Then, if required, you can gradually remove the code that displays the quote, a bit at a time so that you know what the problem is if something gies wrong..
@Isaac, take a look at how I processed the json file, it may provide some minor hints of how to manipulate json.
put it after: "lay.AddChild(txt)"
code :
var btnCopy = app.CreateButton( "[fa-copy]" , -1,-1,"fontawesome");
btnCopy.SetOnTouch( function (){
app.SetClipboardText( txt.GetText() );
app.ShowPopup( "Copied to Clipboard . . . " );
});
lay.AddChild( btnCopy );