Refactoring

This commit is contained in:
c00lerxo 2019-01-28 12:44:56 +01:00
parent f90fdd0867
commit e38f2652ed

View File

@ -1,5 +1,4 @@
package com.example.se.catornot2;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Build;
@ -16,6 +15,7 @@ import java.util.Locale;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
private static final int SPEECH_REQUEST_CODE = 0;
TextToSpeech tts;
@ -25,8 +25,6 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeTextToSpeech();
}
// This callback is invoked when the Speech Recognizer returns.
@ -70,28 +68,22 @@ public class MainActivity extends AppCompatActivity {
// Randomly picks a string from the list and tells the result
private void randomizer(List<String> T) {
// Randomly picks a string
Random rand = new Random();
String answer = T.get(rand.nextInt(T.size()));
/*
if statement with clue about result (vibration?),
depending on whether answer = "It is a cat" or = "It is NOT a cat";
thread must sleep for some time (3000ms-4000ms)
*/
//vibrate if answer is 'It is a cat'
if (answer.equals("It is a cat")){
shakeItBaby();
}
// Says the result
try {
Thread.sleep(4000);
tts.speak(answer, TextToSpeech.QUEUE_FLUSH, null);
}catch(Exception e) {
} catch(Exception e) {
// ...
}
}
@ -111,8 +103,9 @@ public class MainActivity extends AppCompatActivity {
// camera shutter sound (?); indication of app taking a photo
MediaPlayer mySound;
mySound= MediaPlayer.create(MainActivity.this,R.raw.photosound);
mySound= MediaPlayer.create(MainActivity.this, R.raw.photosound);
mySound.start();
// Starting question
try {
Thread.sleep(3000);
@ -120,6 +113,7 @@ public class MainActivity extends AppCompatActivity {
tts.speak(question, TextToSpeech.QUEUE_FLUSH, null);
}catch(Exception e) {
}
// Initiating randomizer method on 'answers'
List<String> answers = Arrays.asList("It is a cat", "It is NOT a cat");
randomizer(answers);