From e38f2652ed0f31557d38c480887e12a6977bc9db Mon Sep 17 00:00:00 2001 From: c00lerxo Date: Mon, 28 Jan 2019 12:44:56 +0100 Subject: [PATCH] Refactoring --- .../example/se/catornot2/MainActivity.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/example/se/catornot2/MainActivity.java b/app/src/main/java/com/example/se/catornot2/MainActivity.java index 5907e7e..4a25653 100644 --- a/app/src/main/java/com/example/se/catornot2/MainActivity.java +++ b/app/src/main/java/com/example/se/catornot2/MainActivity.java @@ -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 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 answers = Arrays.asList("It is a cat", "It is NOT a cat"); randomizer(answers);