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; ...@@ -15,6 +15,7 @@ import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.text.InputType; import android.text.InputType;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
...@@ -135,6 +136,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -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, "IVONA Text-to-Speech HQ");
tts = new TextToSpeech(this, this); tts = new TextToSpeech(this, this);
tts.setOnUtteranceProgressListener(new OnTTSEndListener());
this.tapeGridView.setOnDragListener(new OnPictoDragListener()); this.tapeGridView.setOnDragListener(new OnPictoDragListener());
this.pictoCategoriesGridView.setOnDragListener(new OnPictoDragListener()); this.pictoCategoriesGridView.setOnDragListener(new OnPictoDragListener());
...@@ -631,26 +633,44 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -631,26 +633,44 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
private class OnTTSButtonClickListener implements View.OnClickListener { private class OnTTSButtonClickListener implements View.OnClickListener {
@Override @Override
public void onClick(View arg0) { public void onClick(View arg0) {
// Send websocket action
LinkedList<Picto> lp = tapeAdapter.getAll(); LinkedList<Picto> lp = tapeAdapter.getAll();
// Call to static log method
PCBcontext.getActionLog().log(new PictosAction(lp)); 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 @Override
// (Unsupported on previous versions) public void onDone(String utteranceId) {
tapeAdapter.ttsAllNew(tts); Log.d(LOG_TAG, "TTS tape read end");
tapeAdapter.deleteAll(); this.finishSpeech();
tapeAdapter.notifyDataSetChanged(); }
RelativeLayout rl = (RelativeLayout) findViewById(R.id.pictogramLayout); @Override
rl.setBackgroundColor(Color.parseColor("#BDBDBD")); public void onError(String utteranceId) {
Log.d(LOG_TAG, "TTS tape read error");
this.finishSpeech();
}
// Load the categories private void finishSpeech() {
runOnUiThread(new Runnable() {
@Override
public void run() {
tapeAdapter.deleteAll();
tapeAdapter.notifyDataSetChanged();
showPictoCategoriesGridView(); showPictoCategoriesGridView();
} }
});
}
} }
/** /**
......
...@@ -4,6 +4,7 @@ import android.annotation.TargetApi; ...@@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -104,18 +105,11 @@ public class TapeAdapter extends BaseAdapter { ...@@ -104,18 +105,11 @@ public class TapeAdapter extends BaseAdapter {
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void ttsAllNew(TextToSpeech tts){ public void ttsAllNew(TextToSpeech tts) {
// DE PRUEBA
//String input = pictoLinkedList.getFirst().get_translation();
String input = getAllAsString(); String input = getAllAsString();
//String input = "Geni, vaya fin de semana en el bater vas a pasar !!!";
Bundle params = new Bundle(); Bundle params = new Bundle();
params.putString(TextToSpeech.Engine.KEY_PARAM_VOLUME, "1"); params.putString(TextToSpeech.Engine.KEY_PARAM_VOLUME, "1");
params.putString(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "TAPE_READ");
//tts.setPitch((float) 0.6); tts.speak(input, TextToSpeech.QUEUE_FLUSH, params, "TAPE_READ");
//tts.setSpeechRate((float) 1);
tts.speak(input, TextToSpeech.QUEUE_FLUSH, params, null);
} }
} }
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