Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class yesOunoActivity extends Activity implements OnInitListener{
- ImageView yes;
- ImageView no;
- public TextToSpeech tts;
- private int MY_DATA_CHECK_CODE = 0;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Intent checkIntent = new Intent();
- checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
- startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
- tts = new TextToSpeech(this, this);
- setContentView(R.layout.yesorno);
- yes = (ImageView) findViewById(R.id.yes);
- no = (ImageView) findViewById(R.id.no);
- yes.setClickable(true);
- yes.setOnTouchListener(new OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent arg1) {
- if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN) {
- tts.speak("yes!", TextToSpeech.QUEUE_ADD, null);
- }
- return true;
- }
- });
- no.setClickable(true);
- no.setOnTouchListener(new OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent arg1) {
- if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN) {
- //Intent myIntent = new Intent(v.getContext(), ParametrosActivity.class);
- tts.speak("no!", TextToSpeech.QUEUE_ADD, null);
- }
- return true;
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == MY_DATA_CHECK_CODE) {
- if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
- // success, create the TTS instance
- tts = new TextToSpeech(this, this);
- } else {
- // missing data, install it
- //ATTENTION: BELOW THIS GIVES ME PROBLEMS SINCE IT OPENS MARKET
- //AND I HAVE TO HIT THE BACK BUTTON, THEN, IT SPEAKS!
- //BTW TTS ENGINE "IS" INSTALLED!!
- Intent installIntent = new Intent();
- installIntent
- .setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
- startActivity(installIntent);
- }
- }
- }
- @Override
- public void onInit(int status) {
- if (status == TextToSpeech.SUCCESS) {
- } else if (status == TextToSpeech.ERROR) {
- }
- }
- @Override
- public void onDestroy() {
- if (tts != null) {
- tts.stop();
- tts.shutdown();
- }
- super.onDestroy();
- System.gc();
- }
- }
- @Override
- protected void onActivityResult(
- int requestCode, int resultCode, Intent data) {
- if (requestCode == MY_DATA_CHECK_CODE) {
- /*
- if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
- // success, create the TTS instance
- mTts = new TextToSpeech(this, this);
- } else {
- // missing data, install it
- Intent installIntent = new Intent();
- installIntent.setAction(
- TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
- startActivity(installIntent);
- }
- */
- if (mTts==null) {
- Intent installIntent = new Intent();
- installIntent.setAction(
- TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
- startActivity(installIntent);
- }
- mTts = new TextToSpeech(this, this);
- }
- }
- // in Activity
- private static TextToSpeech mTts;
- .
- .
- .
- // in onCreate()
- mTts = new TextToSpeech(this, this);
- .
- .
- .
- // in onDestroy()
- if (mTts != null) {
- mTts.stop();
- mTts.shutdown();
- mTts = null;
- }
Add Comment
Please, Sign In to add comment