Commit 01ad6ba3 by Pablo Molina

Solved #403, en android la tira no desaparece hasta leerse

parent f6c257ff
......@@ -15,6 +15,7 @@ import android.os.Bundle;
import android.provider.MediaStore;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.util.Log;
......@@ -135,6 +136,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// tts = new TextToSpeech(this, this, "IVONA Text-to-Speech HQ");
tts = new TextToSpeech(this, this);
tts.setOnUtteranceProgressListener(new OnTTSEndListener());
this.tapeGridView.setOnDragListener(new OnPictoDragListener());
this.pictoCategoriesGridView.setOnDragListener(new OnPictoDragListener());
......@@ -631,25 +633,43 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
private class OnTTSButtonClickListener implements View.OnClickListener {
@Override
public void onClick(View arg0) {
// Send websocket action
LinkedList<Picto> lp = tapeAdapter.getAll();
// Call to static log method
PCBcontext.getActionLog().log(new PictosAction(lp));
tapeAdapter.ttsAllNew(tts);
}
}
//send_phrase_action(tapeAdapter.getAll());
/**
* Class for listening the TTS start/end/error events.
* It clears the tape and shows the category grid when the speech has finished or errored.
*/
private class OnTTSEndListener extends UtteranceProgressListener {
@Override
public void onStart(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read start");
}
// Uncomment next line for locution when the version of Android be greater than 5.0
// (Unsupported on previous versions)
tapeAdapter.ttsAllNew(tts);
tapeAdapter.deleteAll();
tapeAdapter.notifyDataSetChanged();
@Override
public void onDone(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read end");
this.finishSpeech();
}
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout);
rl.setBackgroundColor(Color.parseColor("#BDBDBD"));
@Override
public void onError(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read error");
this.finishSpeech();
}
// Load the categories
showPictoCategoriesGridView();
private void finishSpeech() {
runOnUiThread(new Runnable() {
@Override
public void run() {
tapeAdapter.deleteAll();
tapeAdapter.notifyDataSetChanged();
showPictoCategoriesGridView();
}
});
}
}
......
......@@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
......@@ -104,18 +105,11 @@ public class TapeAdapter extends BaseAdapter {
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void ttsAllNew(TextToSpeech tts){
// DE PRUEBA
//String input = pictoLinkedList.getFirst().get_translation();
public void ttsAllNew(TextToSpeech tts) {
String input = getAllAsString();
//String input = "Geni, vaya fin de semana en el bater vas a pasar !!!";
Bundle params = new Bundle();
params.putString(TextToSpeech.Engine.KEY_PARAM_VOLUME, "1");
//tts.setPitch((float) 0.6);
//tts.setSpeechRate((float) 1);
tts.speak(input, TextToSpeech.QUEUE_FLUSH, params, null);
params.putString(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "TAPE_READ");
tts.speak(input, TextToSpeech.QUEUE_FLUSH, params, "TAPE_READ");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment