Quando appare la schermata principale, i tasti Conferma e Annulla sono disattivati.
Sistemo il pulsante Annulla.
Ecco: a inizio di schermata, NUOVO è attivo, mentre CONFERMA e ANNULLA sono inattivi.
Poi, una volta recepito il comando verbale, si attivano CONFERMA e ANNULLA per le due scelte.
E' necessario che non vi sia l'esibizione dell'agendina al termine di questa schermata, ma semplicemente un avvio e uno stop del timer.
Correggo.
r Fatto.
E ho trovato una successione per i tre pulsanti, NUOVO, CONFERMA e ANNULLA.
Quando appare la schermata, NUOVO è abilitato, mentre CONFERMA e ANNULLA sono disabilitati, in modo che si possa premere solo NUOVO.
bttAnnulla=(Button) findViewById(R.id.bttAnnulla); bttAnnulla.setEnabled(false); ..... bttConferma=(Button)findViewById(R.id.bttConferma); bttConferma.setEnabled(false);Quando schiaccio NUOVO, dopo la ricezione della voce, si va a onActivityResult e, SE IL RISULTATO E' RESULT_OK, ossia -1, si abilitano CONFERMA e ANNULLA, mentre si disabilita NUOVO:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
lista=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
tts.speak(lista.get(0),TextToSpeech.QUEUE_FLUSH,null);
bottone.setEnabled(false);
bttConferma.setEnabled(true);
bttAnnulla.setEnabled(true);
}else{r
avviaTimer();
}
}
Se si sceglie di schiacciare CONFERMA, viene salvato il dato, quindi si disabilitano CONFERMA e ANNULLA mentre si riabilita NUOVO, e riparte il TIMER
bttConferma.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { helper.save(lista.get(0)); bttConferma.setEnabled(false); bttAnnulla.setEnabled(false); bottone.setEnabled(true); avviaTimer(); } });Se invece si sceglie di schiacciare ANNULLA, non viene salvato nessun dato, e ugualmente si disabilitano CONFERMA e ANNULLA, mentre si riabilita NUOVO, e riparte il TIMER.
bttAnnulla.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { bttConferma.setEnabled(false); bttAnnulla.setEnabled(false); bottone.setEnabled(true); avviaTimer(); } });
Se invece si evita di dare un input vocale e si schiaccia INDIETRO o si schiaccia al di fuori del prompt vocale, si agisce più a monte, e si dà un risultato sbagliato ad onActivityResult, per cui RESULT_OK è pari a zero invece che a -1: di conseguenza entra in gioco questo codice, che semplicemente riavvia il TIMER: dal momento che RESULT_OK è pari a zero, non si attivano CONFERMA e ANNULLA.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
lista=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
tts.speak(lista.get(0),TextToSpeech.QUEUE_FLUSH,null);
bottone.setEnabled(false);
bttConferma.setEnabled(true);
bttAnnulla.setEnabled(true);
}else{
avviaTimer();
}
}
Nessun commento:
Posta un commento