diff --git a/app/src/main/java/tonio/noa/BravoActivity.java b/app/src/main/java/tonio/noa/BravoActivity.java index 0ca581a..93b86ab 100644 --- a/app/src/main/java/tonio/noa/BravoActivity.java +++ b/app/src/main/java/tonio/noa/BravoActivity.java @@ -3,15 +3,20 @@ package tonio.noa; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.speech.tts.TextToSpeech; import android.view.MotionEvent; import android.view.View; import android.widget.TextView; +import java.util.Locale; + /** * Created by tonio on 23/11/17. */ -public class BravoActivity extends Activity{ +public class BravoActivity extends Activity { + + private TextToSpeech bravoSpk; @Override protected void onCreate(Bundle savedInstanceState) { @@ -22,12 +27,31 @@ public class BravoActivity extends Activity{ View view = findViewById(R.id.bravo_view); view.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view,MotionEvent event) { - setResult(RESULT_OK,intent); - finish(); - return true; - } - }); + @Override + public boolean onTouch(View view, MotionEvent event) { + setResult(RESULT_OK, intent); + finish(); + return true; + } + }); + + bravoSpk = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { + @Override + public void onInit(int status) { + if (status != TextToSpeech.ERROR) { + bravoSpk.setLanguage(Locale.FRENCH); + bravoSpk.speak(getString(R.string.bravotxt), TextToSpeech.QUEUE_FLUSH, null, null); + } + } + }); + } + + @Override + public void onDestroy() { + if (bravoSpk != null) { + bravoSpk.stop(); + bravoSpk.shutdown(); + } + super.onDestroy(); } } diff --git a/app/src/main/java/tonio/noa/Hygiene1Activity.java b/app/src/main/java/tonio/noa/Hygiene1Activity.java index f10ee62..9ab6f3b 100644 --- a/app/src/main/java/tonio/noa/Hygiene1Activity.java +++ b/app/src/main/java/tonio/noa/Hygiene1Activity.java @@ -16,15 +16,8 @@ public class Hygiene1Activity extends MyPlayActivity implements View.OnTouchList @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.hygiene1_display); - - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "Salut!\nTu peux mettre la brosse à dent bleu\nsur son ombre ?"); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("Salut!\nTu peux mettre la brosse à dent bleu\nsur son ombre ?"); } @Override diff --git a/app/src/main/java/tonio/noa/Hygiene2Activity.java b/app/src/main/java/tonio/noa/Hygiene2Activity.java index dd25468..d2716a5 100644 --- a/app/src/main/java/tonio/noa/Hygiene2Activity.java +++ b/app/src/main/java/tonio/noa/Hygiene2Activity.java @@ -16,15 +16,8 @@ public class Hygiene2Activity extends MyPlayActivity implements View.OnTouchList @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.hygiene2_display); - - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "Maintenant met le dessin de la brosse à dent\nsur la photo de la brosse à dent."); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("Maintenant met le dessin de la brosse à dent\nsur la photo de la brosse à dent."); } @Override diff --git a/app/src/main/java/tonio/noa/Hygiene3Activity.java b/app/src/main/java/tonio/noa/Hygiene3Activity.java index 3597dbd..c26a0bd 100644 --- a/app/src/main/java/tonio/noa/Hygiene3Activity.java +++ b/app/src/main/java/tonio/noa/Hygiene3Activity.java @@ -16,15 +16,8 @@ public class Hygiene3Activity extends MyPlayActivity implements View.OnTouchList @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.hygiene3_display); - - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "Tu peux mettre la brosse à dent bleu\nsur la rouge?"); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("Tu peux mettre la brosse à dent bleu\nsur la rouge?"); } @Override diff --git a/app/src/main/java/tonio/noa/Hygiene4Activity.java b/app/src/main/java/tonio/noa/Hygiene4Activity.java index 815f8f2..6af0222 100644 --- a/app/src/main/java/tonio/noa/Hygiene4Activity.java +++ b/app/src/main/java/tonio/noa/Hygiene4Activity.java @@ -21,13 +21,8 @@ public class Hygiene4Activity extends MyPlayActivity implements View.OnTouchList @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "Tu peux m'aider ?\nPrépare mes affaires de toilette."); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("Tu peux m'aider ?\nPrépare mes affaires de toilette."); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/app/src/main/java/tonio/noa/MyPlayActivity.java b/app/src/main/java/tonio/noa/MyPlayActivity.java index a7edabb..fb961ac 100644 --- a/app/src/main/java/tonio/noa/MyPlayActivity.java +++ b/app/src/main/java/tonio/noa/MyPlayActivity.java @@ -2,6 +2,8 @@ package tonio.noa; import android.app.Activity; import android.content.Intent; +import android.os.Bundle; +import android.speech.tts.TextToSpeech; import android.view.View; import android.widget.Toast; @@ -13,18 +15,27 @@ import android.widget.Toast; public abstract class MyPlayActivity extends Activity { public static final int REQUEST_CODE = 1; + protected TextToSpeech tts; protected abstract void next(); - protected void bravoPage(View view){ + protected void bravoPage(View view) { startActivityForResult(new Intent(this, BravoActivity.class), REQUEST_CODE); } + + protected void lanceConsigne(String cons) { + Intent i = new Intent(this, ConsigneActivity.class); + i.putExtra("keyConsigne", cons); + int requestCode = 0; + startActivityForResult(i, requestCode); + } + @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data){ + protected void onActivityResult(int requestCode, int resultCode, Intent data) { try { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { + if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { this.next(); finish(); } @@ -39,4 +50,5 @@ public abstract class MyPlayActivity extends Activity { startActivity(new Intent(this, MainActivity.class)); finish(); } + } diff --git a/app/src/main/java/tonio/noa/TutorialScene1Activity.java b/app/src/main/java/tonio/noa/TutorialScene1Activity.java index ca5b47a..163b430 100644 --- a/app/src/main/java/tonio/noa/TutorialScene1Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene1Activity.java @@ -7,22 +7,19 @@ import android.os.Bundle; * Created by tonio on 22/11/17. */ -public class TutorialScene1Activity extends MyPlayActivity{ +public class TutorialScene1Activity extends MyPlayActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne","Salut!\nJe suis Noa.\nTu peux retrouver mon ballon de football?\nTouche l'écran pour m'aider."); - int requestCode = 0; - startActivityForResult(i,requestCode); + lanceConsigne("Salut!\nJe suis Noa.\nTu peux retrouver mon ballon de football?\nTouche l'écran pour m'aider."); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); setContentView(R.layout.tutorial1_display); - // do your stuff here after SecondActivity finished. + // do your stuff here after SecondActivity finished. } @Override diff --git a/app/src/main/java/tonio/noa/TutorialScene2Activity.java b/app/src/main/java/tonio/noa/TutorialScene2Activity.java index d7d4ea5..a28878a 100644 --- a/app/src/main/java/tonio/noa/TutorialScene2Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene2Activity.java @@ -17,15 +17,8 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.tutorial2_display); - - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "J'ai encore besoin de toi !\nMet le rectangle bleu sur le rouge."); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("J'ai encore besoin de toi !\nMet le rectangle bleu sur le rouge."); } @Override diff --git a/app/src/main/java/tonio/noa/TutorialScene3Activity.java b/app/src/main/java/tonio/noa/TutorialScene3Activity.java index d660a18..a21c627 100644 --- a/app/src/main/java/tonio/noa/TutorialScene3Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene3Activity.java @@ -20,13 +20,8 @@ public class TutorialScene3Activity extends MyPlayActivity implements View.OnTou @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "J'ai encore une nouvelle mission pour toi!\nTu dois associer les carrés de même couleur."); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("J'ai encore une nouvelle mission pour toi!\nTu dois associer les carrés de même couleur."); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { @@ -86,7 +81,10 @@ public class TutorialScene3Activity extends MyPlayActivity implements View.OnTou // the drag and drop operation has concluded case DragEvent.ACTION_DRAG_ENDED: - if (win_counter == 3 && !done){done=true; bravoPage(v);} + if (win_counter == 3 && !done) { + done = true; + bravoPage(v); + } break; //drag shadow has been released,the drag point is within the bounding box of the View diff --git a/app/src/main/java/tonio/noa/TutorialScene4Activity.java b/app/src/main/java/tonio/noa/TutorialScene4Activity.java index 14b3840..694a268 100644 --- a/app/src/main/java/tonio/noa/TutorialScene4Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene4Activity.java @@ -19,13 +19,8 @@ public class TutorialScene4Activity extends MyPlayActivity implements View.OnTou @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "Tu peux mettre les petits carrés de couleurs sur les gros de la même couleur ?\nMerci !"); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("Tu peux mettre les petits carrés de couleurs sur les gros de la même couleur ?\nMerci !"); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/app/src/main/java/tonio/noa/TutorialScene5Activity.java b/app/src/main/java/tonio/noa/TutorialScene5Activity.java index 744cb71..8d46b4d 100644 --- a/app/src/main/java/tonio/noa/TutorialScene5Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene5Activity.java @@ -16,13 +16,8 @@ public class TutorialScene5Activity extends MyPlayActivity implements View.OnTou @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Intent i = new Intent(this, ConsigneActivity.class); - i.putExtra("keyConsigne", "Cette fois\ntu dois cliquer sur les carrés verts!\nC'est ta dernière mission ;)"); - int requestCode = 0; - startActivityForResult(i, requestCode); - + lanceConsigne("Cette fois\ntu dois cliquer sur les carrés verts!\nC'est ta dernière mission ;)"); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { diff --git a/app/src/main/res/layout/bravo_display.xml b/app/src/main/res/layout/bravo_display.xml index 1696b7d..4be714d 100644 --- a/app/src/main/res/layout/bravo_display.xml +++ b/app/src/main/res/layout/bravo_display.xml @@ -26,7 +26,7 @@ android:layout_centerHorizontal="true" android:gravity="center" android:maxLines="3" - android:text="Bravo !\nTu as réussi la mission.\nClique sur l'écran pour continuer à jouer." + android:text="@string/bravotxt" android:textAppearance="@style/TextFont"/> \ No newline at end of file diff --git a/app/src/main/res/layout/tutorial1_display.xml b/app/src/main/res/layout/tutorial1_display.xml index 087fd6c..854e676 100644 --- a/app/src/main/res/layout/tutorial1_display.xml +++ b/app/src/main/res/layout/tutorial1_display.xml @@ -10,7 +10,7 @@ android:layout_alignParentBottom="true" android:layout_margin="20dp" android:layout_centerHorizontal="true" - android:text="Clique sur le ballon de foot." + android:text="Touche le ballon de foot." android:textAppearance="@style/TextFont" /> tutoriel Menu Thème + Bravo ! Tu as réussi la mission. Clique sur l\'écran pour continuer à jouer. -- libgit2 0.21.2