Refactoring
This commit is contained in:
parent
f90fdd0867
commit
e38f2652ed
@ -1,5 +1,4 @@
|
|||||||
package com.example.se.catornot2;
|
package com.example.se.catornot2;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -16,6 +15,7 @@ import java.util.Locale;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private static final int SPEECH_REQUEST_CODE = 0;
|
private static final int SPEECH_REQUEST_CODE = 0;
|
||||||
TextToSpeech tts;
|
TextToSpeech tts;
|
||||||
|
|
||||||
@ -25,8 +25,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
initializeTextToSpeech();
|
initializeTextToSpeech();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This callback is invoked when the Speech Recognizer returns.
|
// 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
|
// Randomly picks a string from the list and tells the result
|
||||||
private void randomizer(List<String> T) {
|
private void randomizer(List<String> T) {
|
||||||
|
|
||||||
// Randomly picks a string
|
// Randomly picks a string
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
String answer = T.get(rand.nextInt(T.size()));
|
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'
|
//vibrate if answer is 'It is a cat'
|
||||||
|
|
||||||
if (answer.equals("It is a cat")){
|
if (answer.equals("It is a cat")){
|
||||||
shakeItBaby();
|
shakeItBaby();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Says the result
|
// Says the result
|
||||||
try {
|
try {
|
||||||
Thread.sleep(4000);
|
Thread.sleep(4000);
|
||||||
tts.speak(answer, TextToSpeech.QUEUE_FLUSH, null);
|
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
|
// camera shutter sound (?); indication of app taking a photo
|
||||||
MediaPlayer mySound;
|
MediaPlayer mySound;
|
||||||
mySound= MediaPlayer.create(MainActivity.this,R.raw.photosound);
|
mySound= MediaPlayer.create(MainActivity.this, R.raw.photosound);
|
||||||
mySound.start();
|
mySound.start();
|
||||||
|
|
||||||
// Starting question
|
// Starting question
|
||||||
try {
|
try {
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
@ -120,6 +113,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
tts.speak(question, TextToSpeech.QUEUE_FLUSH, null);
|
tts.speak(question, TextToSpeech.QUEUE_FLUSH, null);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initiating randomizer method on 'answers'
|
// Initiating randomizer method on 'answers'
|
||||||
List<String> answers = Arrays.asList("It is a cat", "It is NOT a cat");
|
List<String> answers = Arrays.asList("It is a cat", "It is NOT a cat");
|
||||||
randomizer(answers);
|
randomizer(answers);
|
||||||
|
Loading…
Reference in New Issue
Block a user