Firstly I'm quite an inexperienced user, so apologies if this is a basic query.
I'm writing a v simple app which lets a user take a picture with their android and save some meta information about the pixture.
The first layout uses spech-rec to capture the meta-text. You then click to a second layout to check the text . Then click to a third which takes the photo and holds it in the image control. Most of the code is customised from the examples in the Droidscript help.
The speech rec layout seems to work ok. I can then click through to the second layout ok , and then onto the third. I can take take a picture, but when I click the tick to save it on the camera app, it returns to the first layout rather than the thrid (i.e the one which has the image placeholder). So I don't get to see the picture which I've just taken. I can get the photo example from the Droidscript to help though, and my app uses pretty much the same code.
Any ideas what I'm doing wrong? Does the app run the OnStart function again when it closes down the camera app? If that it is the problem, then are there any pointers for getting around it.
Code is below
Thank you in advance!
Chris
//Speech recognition sample.
//Note: The speech recognition engine for some
//languages can be downloaded for off-line use.
// Global variables to store the record
// Hold the position in the list of fields
var index=0;
// The Photo Title
var photoTitle;
// The Description
var photoDesc
// Time Period
var timePhoto
// The Photo Location
// var photoLoc
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" )
//Create a label to tell us what variable we are choosing
lblHeader=app.CreateText("Tell me the Photo Title", 0.8,0.1)
lay.AddChild(lblHeader)
//Create a button to prompt user to say something
btnPrompt = app.CreateButton( "Say the Title", 0.3, 0.1 )
btnPrompt.SetMargins( 0, 0.05, 0, 0 )
btnPrompt.SetOnTouch( btnPrompt_OnTouch )
lay.AddChild( btnPrompt )
//Create a button to prompt user to save the text
// Don't show it for now
btnSave = app.CreateButton( "Save your text", 0.3, 0.1 )
btnSave.SetMargins( 0, 0.05, 0, 0 )
btnSave.SetOnTouch( btnSave_OnTouch )
lay.AddChild( btnSave )
// Text Box to Hold record when browsing
txtTitle = app.CreateTextEdit( "", 0.9, 0.4, "multiline" )
txtTitle.SetMargins( 0,0.1,0,0 )
txtTitle.SetBackColor( "#ff222222" )
txtTitle.SetTextSize( 18 )
txtTitle.SetPosition(0.1,0.1)
lay.AddChild( txtTitle )
txtTitle.Hide
//Add layout to app.
app.AddLayout( lay )
//Create recognition object and set callbacks.
speech = app.CreateSpeechRec()
speech.SetOnReady( speech_OnReady )
speech.SetOnResult( speech_OnResult )
speech.SetOnError( speech_OnError )
//Create a button to move to the photo screen
btnNext = app.CreateButton( "Check text and take photo", 0.3, 0.1 )
btnNext.SetMargins( 0, 0.05, 0, 0 )
btnNext.SetOnTouch( btnNext_OnTouch )
lay.AddChild( btnNext )
// Create the layout which lets you check the text
layCheck = app.CreateLayout( "linear", "VCenter,FillXY" )
app.AddLayout(layCheck);
lblCheckHeader=app.CreateText("Checking the Text", 0.8,0.1)
layCheck.AddChild(lblCheckHeader)
//Button which moves to the take a photo layout
btnToPhoto = app.AddButton( layCheck, "Move to Photo Screen", 0.4 )
btnToPhoto.SetMargins( 0, 0.05, 0, 0 )
btnToPhoto.SetOnTouch( btnToPhoto_OnTouch )
// Create the layout which takes the photo
// Include a button and an image and a label
layPhoto = app.CreateLayout( "linear", "VCenter,FillXY" )
//Add an image.
imgPhoto = app.AddImage( layPhoto, null, 0.8, 0.6 )
imgPhoto.SetBackColor( "#222222" )
//Add a button.
btnPhoto = app.AddButton( layPhoto, "Take Photo", 0.4 )
btnPhoto.SetMargins( 0, 0.05, 0, 0 )
btnPhoto.SetOnTouch( btnPhoto_OnTouch )
lblPhotoHeader=app.CreateText("Checking the Text", 0.8,0.1)
layPhoto.AddChild(lblPhotoHeader)
app.AddLayout(layPhoto);
// Hide the layouts which aren't used at the start
layCheck.Hide();
layPhoto.Hide();
}
//Called when user touches the talk prompt button.
function btnPrompt_OnTouch()
{
//Start recognizing.
speech.Recognize()
}
//Called when user touches the save buttom.
function btnSave_OnTouch()
{
// app.Alert("You are saving the Title")
//Change the Header Label so we know we are moving onto the next variable
if (index==0) {
photoTitle=txtTitle.GetText()
app.Alert("The Title you have given us is " + photoTitle)
lblHeader.SetText("Choose the Description")
btnPrompt.SetText("Say the Description")
txtTitle.SetText("");
}
if (index==1) {
photoDesc=txtTitle.GetText()
app.Alert("The Title you have given us is " + photoTitle)
lblHeader.SetText("Choose the Time Period")
btnPrompt.SetText("Say the Time Period")
txtTitle.SetText("");
}
if (index==2) {
lblHeader.SetText("Choose the Time Period")
btnPrompt.SetText("Say the Time Period")
txtTitle.SetText("");
}
index++;
app.Alert("Index is now " + index)
}
//Called when user touches the button to check the text.
function btnNext_OnTouch()
{
app.Alert ("Now going to check text and take the photo")
lay.Hide();
layCheck.Show();
}
//Called when user touches the button to move to taking the photo layout.
function btnToPhoto_OnTouch()
{
app.Alert ("Now take the photo")
layCheck.Hide();
layPhoto.Show();
}
// Called when photo is taken
function btnPhoto_OnTouch()
{
//Create a placeholder file.
file = "/Private/photo.jpg"
app.WriteFile( file, "" )
//Get a public URI for the file.
var uri = app.Path2Uri( file )
//Send intent to built-in photo app.
let extras = [ {name:"output", type:"uri", value:uri} ]
extras = JSON.stringify(extras)
app.SendIntent( null,null,"android.media.action.IMAGE_CAPTURE",
null,null,null, extras, "result", OnResult )
}
//Handle the photo result.
function OnResult( code, data )
{
if(code<0) img.SetImage( file )
}
//Called when speech engine is ready.
function speech_OnReady()
{
app.ShowPopup( "Listening...", "Short" )
}
//Called with the recognition result(s).
function speech_OnResult( results )
{
//An array of recognition results is returned
//here, with the most probable at the front
//of the array.
//Show the top result.
app.ShowPopup( results[0] )
txtTitle.SetText(results[0]);
}
//Called if recognition fails.
function speech_OnError()
{
app.ShowPopup( "Please speak more clearly!" )
}