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

Improve example scenario and action logic (example not working)

parent 76c75dd6
......@@ -11,7 +11,9 @@ import android.os.Bundle;
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.ClearNodes;
import com.example.qrquest.actions.QRChecker;
import com.example.qrquest.actions.RemoveAtom;
import com.example.qrquest.actions.TTSReading;
import com.example.qrquest.atom.Atom;
......@@ -47,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
GoogleApiAvailability m_gga;
public TTSReader ttsreader;
private MainThread mainThread;
private CaptureQR QRActionRequesting;
//game logic
public ArrayList<Atom> Atoms;
......@@ -78,25 +81,42 @@ public class MainActivity extends AppCompatActivity {
OpenNodes = new ArrayList<Node>();
ArrayList<Action> A1 = new ArrayList<Action>();
A1.add(new AddAtom(this, new ItemAtom(2)));
A1.add(new TTSReading(this, "Test 1 aaa test 1"));
A1.add(new RemoveAtom(this, new ItemAtom(0)));
A1.add(new AddAtom(this, new ItemAtom(1)));
A1.add(new ClearNodes(this));
A1.add(new AddNode(this, 2));
A1.add(new AddNode(this, 3));
ArrayList<Atom> C1 = new ArrayList<Atom>();
C1.add(new ItemAtom(0));
ArrayList<Action> A2 = new ArrayList<Action>();
A2.add(new ClearNodes(this));
A2.add(new TTSReading(this, "Test 2 aaa test 2"));
A2.add(new TTSReading(this, "Mauvais QR code"));
A2.add(new AddNode(this, 3));
ArrayList<Atom> C2 = new ArrayList<Atom>();
C2.add(new ItemAtom(1));
Node n1 = new Node(1, A1, C1);
Node n2 = new Node(2, A2, C2);
ArrayList<Action> A3 = new ArrayList<Action>();
A3.add(new ClearNodes(this));
A3.add(new TTSReading(this, "Cherchons un QR"));
A3.add(new CaptureQR(this));
A3.add(new QRChecker(this, "36271", 4,2));
ArrayList<Atom> C3 = new ArrayList<Atom>();
C3.add(new ItemAtom(1));
ArrayList<Action> A4 = new ArrayList<Action>();
A4.add(new ClearNodes(this));
A4.add(new TTSReading(this, "Bon QR code"));
A4.add(new TTSReading(this, "Vous avez gagné"));
ArrayList<Atom> C4 = new ArrayList<Atom>();
Node n1 = new Node(1, A1, C1); // node that launch other nodes
Node n2 = new Node(2, A2, C2); // wrong QR code node
Node n3 = new Node(3, A3, C3); // Node that check QR codes (launch and check)
Node n4 = new Node(4, A4, C4); // Node that declare victory
......@@ -223,19 +243,33 @@ public class MainActivity extends AppCompatActivity {
public boolean DemoQR()
// The demo QR can cause a leaked memory warning. This may be fixed by binding a service to the photo activity.
Intent PhotoIntent = new Intent( this, QRCaptureActivity.class);
startActivityForResult(PhotoIntent, 1);
return true;
public boolean RequestQR(CaptureQR CaptureAction) // called by an action to request a QR code
//DemoQR(); return true;
Log.d("Debug2", "QR request action");
this.QRActionRequesting = CaptureAction;
Intent PhotoIntent = new Intent( this, QRCaptureActivity.class);
startActivityForResult(PhotoIntent, 1);
Log.d("Debug2", "Started QR activity for result");
return true;
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("Debug2", "QR data retrieved in main activity: " + data.getStringExtra("QR_CONTENT"));
Snackbar.make(findViewById(, "QR code says:" + data.getStringExtra("QR_CONTENT") , Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
public void SetListeningResults(String result) // to display listening results
......@@ -40,13 +40,16 @@ public class QRCaptureActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
Log.d("Debug2", "Created QR activity");
// Toolbar toolbar = findViewById(;
Log.d("Debug2", "Detector set up");
Log.d("Debug2", "Detection started");
package com.example.qrquest.actions;
import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.QRAtom;
public class CaptureQR extends Action {
......@@ -13,7 +14,12 @@ public class CaptureQR extends Action {
public void Do()
// open QRCaptureActivity here and wait for its result
public void GiveQRResult(String result)
mainActivity.Atoms.add(new QRAtom(result));
isOver = true;
package com.example.qrquest.actions;
import com.example.qrquest.MainActivity;
import com.example.qrquest.atom.Atom;
import com.example.qrquest.atom.QRAtom;
public class QRChecker extends Action {
private String WaitedValue;
private int SuccessNodeID, FailNodeID;
public QRChecker(MainActivity mainActivity, String WaitedValue, int SuccessNodeID, int FailNodeID) {
this.WaitedValue = WaitedValue;
this.SuccessNodeID = SuccessNodeID;
this.FailNodeID = FailNodeID;
public void Do()
for (Atom a: mainActivity.Atoms
) {
if(a.getClass() == QRAtom.class)
if(a.GetStringValue() == WaitedValue) mainActivity.OpenNodes.add(mainActivity.GetNode(SuccessNodeID));
else mainActivity.OpenNodes.add(mainActivity.GetNode(FailNodeID));
isOver = true;
......@@ -29,7 +29,6 @@ public class Node implements Runnable {
if(a2.isSame(a1)) UnresolvedConditions.remove(a2);
return (UnresolvedConditions.size() == 0);
Supports Markdown
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