Commit f8dc1876 authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Add CaptureSpeech action

parent 9c41dc66
......@@ -12,12 +12,15 @@ import com.example.qrquest.actions.Action;
import com.example.qrquest.actions.AddAtom;
import com.example.qrquest.actions.AddNode;
import com.example.qrquest.actions.CaptureQR;
import com.example.qrquest.actions.CaptureSpeech;
import com.example.qrquest.actions.ClearNodes;
import com.example.qrquest.actions.QRChecker;
import com.example.qrquest.actions.Checker;
import com.example.qrquest.actions.RemoveAtom;
import com.example.qrquest.actions.TTSReading;
import com.example.qrquest.atom.Atom;
import com.example.qrquest.atom.ItemAtom;
import com.example.qrquest.atom.QRAtom;
import com.example.qrquest.atom.SpeechAtom;
import com.example.qrquest.node.Node;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
......@@ -30,7 +33,6 @@ import androidx.appcompat.widget.Toolbar;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.view.Menu;
......@@ -38,9 +40,6 @@ import android.view.MenuItem;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
public class MainActivity extends AppCompatActivity {
......@@ -50,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
public TTSReader ttsreader;
public MainThread mainThread;
private CaptureQR QRActionRequesting;
private CaptureSpeech SpeechRequest;
//game logic
public ArrayList<Atom> Atoms;
......@@ -85,7 +85,7 @@ public class MainActivity extends AppCompatActivity {
A1.add(new RemoveAtom(this,1, new ItemAtom(0)));
A1.add(new AddAtom(this,1, new ItemAtom(1)));
A1.add(new ClearNodes(this,1));
A1.add(new AddNode(this,1, 3));
A1.add(new AddNode(this,1, 6));
ArrayList<Atom> C1 = new ArrayList<Atom>();
C1.add(new ItemAtom(0));
......@@ -99,7 +99,7 @@ public class MainActivity extends AppCompatActivity {
A3.add(new ClearNodes(this,3));
A3.add(new TTSReading(this,3, "Cherchons un QR"));
A3.add(new CaptureQR(this,3));
A3.add(new QRChecker(this,3, "36271", 4,2));
A3.add(new Checker(this,3, "36271", QRAtom.class, 4,2));
ArrayList<Atom> C3 = new ArrayList<Atom>();
C3.add(new ItemAtom(1));
......@@ -109,14 +109,40 @@ public class MainActivity extends AppCompatActivity {
A4.add(new TTSReading(this,4, "Vous avez gagné"));
ArrayList<Atom> C4 = new ArrayList<Atom>();
ArrayList<Action> A5 = new ArrayList<Action>();
A5.add(new ClearNodes(this,5));
A5.add(new TTSReading(this,5, "Mauvaise réponse"));
A5.add(new AddNode(this,5, 6));
ArrayList<Atom> C5 = new ArrayList<Atom>();
ArrayList<Action> A6 = new ArrayList<Action>();
A6.add(new ClearNodes(this,6));
A6.add(new TTSReading(this,6, "Combien font 4 fois 2 ?"));
A6.add(new CaptureSpeech(this,6));
A6.add(new Checker(this,6, "8", SpeechAtom.class, 7,5));
ArrayList<Atom> C6 = new ArrayList<Atom>();
C6.add(new ItemAtom(1));
ArrayList<Action> A7 = new ArrayList<Action>();
A7.add(new ClearNodes(this,7));
A7.add(new TTSReading(this,7, "Bonne réponse"));
A7.add(new TTSReading(this,7, "Vous avez gagné"));
ArrayList<Atom> C7 = new ArrayList<Atom>();
Node n1 = new Node(this,1, A1, C1); // node that launch other nodes
Node n2 = new Node(this,2, A2, C2); // wrong QR code node
Node n3 = new Node(this,3, A3, C3); // Node that check QR codes (launch and check)
Node n4 = new Node(this,4, A4, C4); // Node that declare victory
Node n5 = new Node(this,5, A5, C5); // wrong answer math
Node n6 = new Node(this,6, A6, C6); // Math question
Node n7 = new Node(this,7, A7, C7); // good answer math question
EveryNode.add(n1);
EveryNode.add(n2);
EveryNode.add(n3);
EveryNode.add(n4);
EveryNode.add(n5);
EveryNode.add(n6);
EveryNode.add(n7);
OpenNodes.add(n1);
......@@ -276,6 +302,8 @@ public class MainActivity extends AppCompatActivity {
{
Log.d("Debug", "Best confidence result (from main activity): " + result);
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
if(SpeechRequest != null) SpeechRequest.GiveSpeechResult(result);
}
private void requestRecordAudioPermission() {
......@@ -301,4 +329,9 @@ public class MainActivity extends AppCompatActivity {
}
}
}
public void GetSpeech(CaptureSpeech calling_action) {
this.SpeechRequest = calling_action;
DemoListener();
}
}
package com.example.qrquest.actions;
import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.SpeechAtom;
public class CaptureSpeech extends Action {
public CaptureSpeech(MainActivity mainActivity, int nodeID) {
super(mainActivity, nodeID);
}
public void Do()
{
super.Do();
mainActivity.GetSpeech(this);
}
public void GiveSpeechResult(String result)
{
mainActivity.Atoms.add(new SpeechAtom(result));
End();
}
}
......@@ -6,12 +6,16 @@ import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.Atom;
import com.example.qrquest.atom.QRAtom;
public class QRChecker extends Action {
public class Checker extends Action {
private String WaitedValue;
private int SuccessNodeID, FailNodeID;
public QRChecker(MainActivity mainActivity, int nodeID, String WaitedValue, int SuccessNodeID, int FailNodeID) {
private Class AtomType;
public Checker(MainActivity mainActivity, int nodeID, String WaitedValue, Class AtomType, int SuccessNodeID, int FailNodeID) {
super(mainActivity, nodeID);
this.WaitedValue = WaitedValue;
this.AtomType = AtomType;
this.SuccessNodeID = SuccessNodeID;
this.FailNodeID = FailNodeID;
}
......@@ -22,7 +26,7 @@ public class QRChecker extends Action {
for (Atom a: mainActivity.Atoms
) {
Log.d("Debug2","QR checker action reads " + a.GetStringValue());
if(a.getClass() == QRAtom.class)
if(a.getClass() == AtomType)
{
Log.d("Debug2","QR checker detected a QRAtom");
if(a.GetStringValue().equals(WaitedValue)) mainActivity.OpenNodes.add(mainActivity.GetNode(SuccessNodeID));
......
......@@ -43,9 +43,12 @@ public class Node {
public void Trigger()
{
if(this.ID == 3) Log.d("Debug2", "Node 3 triggered");
if(Actions.size() == 0)
{
Log.w("Debug2", "Tried to trigger node but no action were found");
return;
}
this.TODOActions = new ArrayList<>(Actions);
if(this.ID == 3) Log.d("Debug2", Integer.toString(TODOActions.size()) + " actions to do for node 3");
TODOActions.get(0).Do();
/*
for (Action a: Actions
......
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 to comment