Commit 2db7566f063d4b6d77e64c6edcfac2dab97cb314

Authored by aarnaude
1 parent 427a4dcd

modification de MyPlayActivity pour ajout methode lanceConsigne

app/src/main/java/tonio/noa/BravoActivity.java
@@ -3,15 +3,20 @@ package tonio.noa; @@ -3,15 +3,20 @@ package tonio.noa;
3 import android.app.Activity; 3 import android.app.Activity;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.Bundle; 5 import android.os.Bundle;
  6 +import android.speech.tts.TextToSpeech;
6 import android.view.MotionEvent; 7 import android.view.MotionEvent;
7 import android.view.View; 8 import android.view.View;
8 import android.widget.TextView; 9 import android.widget.TextView;
9 10
  11 +import java.util.Locale;
  12 +
10 /** 13 /**
11 * Created by tonio on 23/11/17. 14 * Created by tonio on 23/11/17.
12 */ 15 */
13 16
14 -public class BravoActivity extends Activity{ 17 +public class BravoActivity extends Activity {
  18 +
  19 + private TextToSpeech bravoSpk;
15 20
16 @Override 21 @Override
17 protected void onCreate(Bundle savedInstanceState) { 22 protected void onCreate(Bundle savedInstanceState) {
@@ -22,12 +27,31 @@ public class BravoActivity extends Activity{ @@ -22,12 +27,31 @@ public class BravoActivity extends Activity{
22 View view = findViewById(R.id.bravo_view); 27 View view = findViewById(R.id.bravo_view);
23 view.setOnTouchListener(new View.OnTouchListener() { 28 view.setOnTouchListener(new View.OnTouchListener() {
24 29
25 - @Override  
26 - public boolean onTouch(View view,MotionEvent event) {  
27 - setResult(RESULT_OK,intent);  
28 - finish();  
29 - return true;  
30 - }  
31 - }); 30 + @Override
  31 + public boolean onTouch(View view, MotionEvent event) {
  32 + setResult(RESULT_OK, intent);
  33 + finish();
  34 + return true;
  35 + }
  36 + });
  37 +
  38 + bravoSpk = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
  39 + @Override
  40 + public void onInit(int status) {
  41 + if (status != TextToSpeech.ERROR) {
  42 + bravoSpk.setLanguage(Locale.FRENCH);
  43 + bravoSpk.speak(getString(R.string.bravotxt), TextToSpeech.QUEUE_FLUSH, null, null);
  44 + }
  45 + }
  46 + });
  47 + }
  48 +
  49 + @Override
  50 + public void onDestroy() {
  51 + if (bravoSpk != null) {
  52 + bravoSpk.stop();
  53 + bravoSpk.shutdown();
  54 + }
  55 + super.onDestroy();
32 } 56 }
33 } 57 }
app/src/main/java/tonio/noa/Hygiene1Activity.java
@@ -16,15 +16,8 @@ public class Hygiene1Activity extends MyPlayActivity implements View.OnTouchList @@ -16,15 +16,8 @@ public class Hygiene1Activity extends MyPlayActivity implements View.OnTouchList
16 16
17 @Override 17 @Override
18 protected void onCreate(Bundle savedInstanceState) { 18 protected void onCreate(Bundle savedInstanceState) {
19 -  
20 super.onCreate(savedInstanceState); 19 super.onCreate(savedInstanceState);
21 - setContentView(R.layout.hygiene1_display);  
22 -  
23 - Intent i = new Intent(this, ConsigneActivity.class);  
24 - i.putExtra("keyConsigne", "Salut!\nTu peux mettre la brosse à dent bleu\nsur son ombre ?");  
25 - int requestCode = 0;  
26 - startActivityForResult(i, requestCode);  
27 - 20 + lanceConsigne("Salut!\nTu peux mettre la brosse à dent bleu\nsur son ombre ?");
28 } 21 }
29 22
30 @Override 23 @Override
app/src/main/java/tonio/noa/Hygiene2Activity.java
@@ -16,15 +16,8 @@ public class Hygiene2Activity extends MyPlayActivity implements View.OnTouchList @@ -16,15 +16,8 @@ public class Hygiene2Activity extends MyPlayActivity implements View.OnTouchList
16 16
17 @Override 17 @Override
18 protected void onCreate(Bundle savedInstanceState) { 18 protected void onCreate(Bundle savedInstanceState) {
19 -  
20 super.onCreate(savedInstanceState); 19 super.onCreate(savedInstanceState);
21 - setContentView(R.layout.hygiene2_display);  
22 -  
23 - Intent i = new Intent(this, ConsigneActivity.class);  
24 - i.putExtra("keyConsigne", "Maintenant met le dessin de la brosse à dent\nsur la photo de la brosse à dent.");  
25 - int requestCode = 0;  
26 - startActivityForResult(i, requestCode);  
27 - 20 + lanceConsigne("Maintenant met le dessin de la brosse à dent\nsur la photo de la brosse à dent.");
28 } 21 }
29 22
30 @Override 23 @Override
app/src/main/java/tonio/noa/Hygiene3Activity.java
@@ -16,15 +16,8 @@ public class Hygiene3Activity extends MyPlayActivity implements View.OnTouchList @@ -16,15 +16,8 @@ public class Hygiene3Activity extends MyPlayActivity implements View.OnTouchList
16 16
17 @Override 17 @Override
18 protected void onCreate(Bundle savedInstanceState) { 18 protected void onCreate(Bundle savedInstanceState) {
19 -  
20 super.onCreate(savedInstanceState); 19 super.onCreate(savedInstanceState);
21 - setContentView(R.layout.hygiene3_display);  
22 -  
23 - Intent i = new Intent(this, ConsigneActivity.class);  
24 - i.putExtra("keyConsigne", "Tu peux mettre la brosse à dent bleu\nsur la rouge?");  
25 - int requestCode = 0;  
26 - startActivityForResult(i, requestCode);  
27 - 20 + lanceConsigne("Tu peux mettre la brosse à dent bleu\nsur la rouge?");
28 } 21 }
29 22
30 @Override 23 @Override
app/src/main/java/tonio/noa/Hygiene4Activity.java
@@ -21,13 +21,8 @@ public class Hygiene4Activity extends MyPlayActivity implements View.OnTouchList @@ -21,13 +21,8 @@ public class Hygiene4Activity extends MyPlayActivity implements View.OnTouchList
21 21
22 @Override 22 @Override
23 protected void onCreate(Bundle savedInstanceState) { 23 protected void onCreate(Bundle savedInstanceState) {
24 -  
25 super.onCreate(savedInstanceState); 24 super.onCreate(savedInstanceState);
26 - Intent i = new Intent(this, ConsigneActivity.class);  
27 - i.putExtra("keyConsigne", "Tu peux m'aider ?\nPrépare mes affaires de toilette.");  
28 - int requestCode = 0;  
29 - startActivityForResult(i, requestCode);  
30 - 25 + lanceConsigne("Tu peux m'aider ?\nPrépare mes affaires de toilette.");
31 } 26 }
32 27
33 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 28 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
app/src/main/java/tonio/noa/MyPlayActivity.java
@@ -2,6 +2,8 @@ package tonio.noa; @@ -2,6 +2,8 @@ package tonio.noa;
2 2
3 import android.app.Activity; 3 import android.app.Activity;
4 import android.content.Intent; 4 import android.content.Intent;
  5 +import android.os.Bundle;
  6 +import android.speech.tts.TextToSpeech;
5 import android.view.View; 7 import android.view.View;
6 import android.widget.Toast; 8 import android.widget.Toast;
7 9
@@ -13,18 +15,27 @@ import android.widget.Toast; @@ -13,18 +15,27 @@ import android.widget.Toast;
13 public abstract class MyPlayActivity extends Activity { 15 public abstract class MyPlayActivity extends Activity {
14 16
15 public static final int REQUEST_CODE = 1; 17 public static final int REQUEST_CODE = 1;
  18 + protected TextToSpeech tts;
16 19
17 protected abstract void next(); 20 protected abstract void next();
18 21
19 - protected void bravoPage(View view){ 22 + protected void bravoPage(View view) {
20 startActivityForResult(new Intent(this, BravoActivity.class), REQUEST_CODE); 23 startActivityForResult(new Intent(this, BravoActivity.class), REQUEST_CODE);
21 } 24 }
  25 +
  26 + protected void lanceConsigne(String cons) {
  27 + Intent i = new Intent(this, ConsigneActivity.class);
  28 + i.putExtra("keyConsigne", cons);
  29 + int requestCode = 0;
  30 + startActivityForResult(i, requestCode);
  31 + }
  32 +
22 @Override 33 @Override
23 - protected void onActivityResult(int requestCode, int resultCode, Intent data){ 34 + protected void onActivityResult(int requestCode, int resultCode, Intent data) {
24 try { 35 try {
25 super.onActivityResult(requestCode, resultCode, data); 36 super.onActivityResult(requestCode, resultCode, data);
26 37
27 - if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { 38 + if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
28 this.next(); 39 this.next();
29 finish(); 40 finish();
30 } 41 }
@@ -39,4 +50,5 @@ public abstract class MyPlayActivity extends Activity { @@ -39,4 +50,5 @@ public abstract class MyPlayActivity extends Activity {
39 startActivity(new Intent(this, MainActivity.class)); 50 startActivity(new Intent(this, MainActivity.class));
40 finish(); 51 finish();
41 } 52 }
  53 +
42 } 54 }
app/src/main/java/tonio/noa/TutorialScene1Activity.java
@@ -7,22 +7,19 @@ import android.os.Bundle; @@ -7,22 +7,19 @@ import android.os.Bundle;
7 * Created by tonio on 22/11/17. 7 * Created by tonio on 22/11/17.
8 */ 8 */
9 9
10 -public class TutorialScene1Activity extends MyPlayActivity{ 10 +public class TutorialScene1Activity extends MyPlayActivity {
11 11
12 @Override 12 @Override
13 protected void onCreate(Bundle savedInstanceState) { 13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState); 14 super.onCreate(savedInstanceState);
15 - Intent i = new Intent(this, ConsigneActivity.class);  
16 - i.putExtra("keyConsigne","Salut!\nJe suis Noa.\nTu peux retrouver mon ballon de football?\nTouche l'écran pour m'aider.");  
17 - int requestCode = 0;  
18 - startActivityForResult(i,requestCode); 15 + lanceConsigne("Salut!\nJe suis Noa.\nTu peux retrouver mon ballon de football?\nTouche l'écran pour m'aider.");
19 } 16 }
20 17
21 @Override 18 @Override
22 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 19 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
23 super.onActivityResult(requestCode, resultCode, data); 20 super.onActivityResult(requestCode, resultCode, data);
24 setContentView(R.layout.tutorial1_display); 21 setContentView(R.layout.tutorial1_display);
25 - // do your stuff here after SecondActivity finished. 22 + // do your stuff here after SecondActivity finished.
26 } 23 }
27 24
28 @Override 25 @Override
app/src/main/java/tonio/noa/TutorialScene2Activity.java
@@ -17,15 +17,8 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou @@ -17,15 +17,8 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou
17 17
18 @Override 18 @Override
19 protected void onCreate(Bundle savedInstanceState) { 19 protected void onCreate(Bundle savedInstanceState) {
20 -  
21 super.onCreate(savedInstanceState); 20 super.onCreate(savedInstanceState);
22 - setContentView(R.layout.tutorial2_display);  
23 -  
24 - Intent i = new Intent(this, ConsigneActivity.class);  
25 - i.putExtra("keyConsigne", "J'ai encore besoin de toi !\nMet le rectangle bleu sur le rouge.");  
26 - int requestCode = 0;  
27 - startActivityForResult(i, requestCode);  
28 - 21 + lanceConsigne("J'ai encore besoin de toi !\nMet le rectangle bleu sur le rouge.");
29 } 22 }
30 23
31 @Override 24 @Override
app/src/main/java/tonio/noa/TutorialScene3Activity.java
@@ -20,13 +20,8 @@ public class TutorialScene3Activity extends MyPlayActivity implements View.OnTou @@ -20,13 +20,8 @@ public class TutorialScene3Activity extends MyPlayActivity implements View.OnTou
20 20
21 @Override 21 @Override
22 protected void onCreate(Bundle savedInstanceState) { 22 protected void onCreate(Bundle savedInstanceState) {
23 -  
24 super.onCreate(savedInstanceState); 23 super.onCreate(savedInstanceState);
25 - Intent i = new Intent(this, ConsigneActivity.class);  
26 - i.putExtra("keyConsigne", "J'ai encore une nouvelle mission pour toi!\nTu dois associer les carrés de même couleur.");  
27 - int requestCode = 0;  
28 - startActivityForResult(i, requestCode);  
29 - 24 + lanceConsigne("J'ai encore une nouvelle mission pour toi!\nTu dois associer les carrés de même couleur.");
30 } 25 }
31 26
32 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 27 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
@@ -86,7 +81,10 @@ public class TutorialScene3Activity extends MyPlayActivity implements View.OnTou @@ -86,7 +81,10 @@ public class TutorialScene3Activity extends MyPlayActivity implements View.OnTou
86 81
87 // the drag and drop operation has concluded 82 // the drag and drop operation has concluded
88 case DragEvent.ACTION_DRAG_ENDED: 83 case DragEvent.ACTION_DRAG_ENDED:
89 - if (win_counter == 3 && !done){done=true; bravoPage(v);} 84 + if (win_counter == 3 && !done) {
  85 + done = true;
  86 + bravoPage(v);
  87 + }
90 break; 88 break;
91 89
92 //drag shadow has been released,the drag point is within the bounding box of the View 90 //drag shadow has been released,the drag point is within the bounding box of the View
app/src/main/java/tonio/noa/TutorialScene4Activity.java
@@ -19,13 +19,8 @@ public class TutorialScene4Activity extends MyPlayActivity implements View.OnTou @@ -19,13 +19,8 @@ public class TutorialScene4Activity extends MyPlayActivity implements View.OnTou
19 19
20 @Override 20 @Override
21 protected void onCreate(Bundle savedInstanceState) { 21 protected void onCreate(Bundle savedInstanceState) {
22 -  
23 super.onCreate(savedInstanceState); 22 super.onCreate(savedInstanceState);
24 - Intent i = new Intent(this, ConsigneActivity.class);  
25 - i.putExtra("keyConsigne", "Tu peux mettre les petits carrés de couleurs sur les gros de la même couleur ?\nMerci !");  
26 - int requestCode = 0;  
27 - startActivityForResult(i, requestCode);  
28 - 23 + lanceConsigne("Tu peux mettre les petits carrés de couleurs sur les gros de la même couleur ?\nMerci !");
29 } 24 }
30 25
31 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 26 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
app/src/main/java/tonio/noa/TutorialScene5Activity.java
@@ -16,13 +16,8 @@ public class TutorialScene5Activity extends MyPlayActivity implements View.OnTou @@ -16,13 +16,8 @@ public class TutorialScene5Activity extends MyPlayActivity implements View.OnTou
16 16
17 @Override 17 @Override
18 protected void onCreate(Bundle savedInstanceState) { 18 protected void onCreate(Bundle savedInstanceState) {
19 -  
20 super.onCreate(savedInstanceState); 19 super.onCreate(savedInstanceState);
21 - Intent i = new Intent(this, ConsigneActivity.class);  
22 - i.putExtra("keyConsigne", "Cette fois\ntu dois cliquer sur les carrés verts!\nC'est ta dernière mission ;)");  
23 - int requestCode = 0;  
24 - startActivityForResult(i, requestCode);  
25 - 20 + lanceConsigne("Cette fois\ntu dois cliquer sur les carrés verts!\nC'est ta dernière mission ;)");
26 } 21 }
27 22
28 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 23 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
app/src/main/res/layout/bravo_display.xml
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 android:layout_centerHorizontal="true" 26 android:layout_centerHorizontal="true"
27 android:gravity="center" 27 android:gravity="center"
28 android:maxLines="3" 28 android:maxLines="3"
29 - android:text="Bravo !\nTu as réussi la mission.\nClique sur l'écran pour continuer à jouer." 29 + android:text="@string/bravotxt"
30 android:textAppearance="@style/TextFont"/> 30 android:textAppearance="@style/TextFont"/>
31 31
32 </RelativeLayout> 32 </RelativeLayout>
33 \ No newline at end of file 33 \ No newline at end of file
app/src/main/res/layout/tutorial1_display.xml
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 android:layout_alignParentBottom="true" 10 android:layout_alignParentBottom="true"
11 android:layout_margin="20dp" 11 android:layout_margin="20dp"
12 android:layout_centerHorizontal="true" 12 android:layout_centerHorizontal="true"
13 - android:text="Clique sur le ballon de foot." 13 + android:text="Touche le ballon de foot."
14 android:textAppearance="@style/TextFont" /> 14 android:textAppearance="@style/TextFont" />
15 15
16 <ImageButton 16 <ImageButton
app/src/main/res/values/strings.xml
@@ -12,4 +12,5 @@ @@ -12,4 +12,5 @@
12 <string name="tutorial">tutoriel</string> 12 <string name="tutorial">tutoriel</string>
13 <string name="home">Menu</string> 13 <string name="home">Menu</string>
14 <string name="theme">Thème</string> 14 <string name="theme">Thème</string>
  15 + <string name="bravotxt">Bravo ! Tu as réussi la mission. Clique sur l\'écran pour continuer à jouer.</string>
15 </resources> 16 </resources>