diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dc90dd3..53b6de6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -137,6 +137,14 @@ + + + + diff --git a/app/src/main/java/tonio/noa/Food1Activity.java b/app/src/main/java/tonio/noa/Food1Activity.java new file mode 100644 index 0000000..faf8ced --- /dev/null +++ b/app/src/main/java/tonio/noa/Food1Activity.java @@ -0,0 +1,134 @@ +package tonio.noa; + +import android.content.ClipData; +import android.content.Intent; +import android.os.Build; +import android.os.Bundle; +import android.view.DragEvent; +import android.view.MotionEvent; +import android.view.View; +import android.widget.TextView; + +/** + * Created by psyk on 24/01/18. + */ + +public class Food1Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener { + + private int win_counter = 0; + private boolean done = false; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + lanceConsigne("Salut !\nTu peux m'aider à trier\nles aliments salés et sucrés ?\nTouche l'écran pour commencer."); + } + + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + setContentView(R.layout.food1_display); + + TextView txtV = findViewById(R.id.cons_food1); + smallCons = "Tri les aliments sucrés et ceux salés."; + txtV.setText(smallCons); + setTts(); + + findViewById(R.id.bacon).setOnTouchListener(this); + findViewById(R.id.muskmelon).setOnTouchListener(this); + findViewById(R.id.cake).setOnTouchListener(this); + findViewById(R.id.fries).setOnTouchListener(this); + findViewById(R.id.apple).setOnTouchListener(this); + findViewById(R.id.hot_dog).setOnTouchListener(this); + findViewById(R.id.cheese).setOnTouchListener(this); + findViewById(R.id.muffin).setOnTouchListener(this); + + findViewById(R.id.bacon).setOnDragListener(this); + findViewById(R.id.muffin).setOnDragListener(this); + findViewById(R.id.muskmelon).setOnDragListener(this); + findViewById(R.id.cake).setOnDragListener(this); + findViewById(R.id.fries).setOnDragListener(this); + findViewById(R.id.apple).setOnDragListener(this); + findViewById(R.id.hot_dog).setOnDragListener(this); + findViewById(R.id.cheese).setOnDragListener(this); + findViewById(R.id.salt).setOnDragListener(this); + findViewById(R.id.sugar).setOnDragListener(this); + + } + + @Override + public boolean onTouch(View view, MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + + View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view); + ClipData data = ClipData.newPlainText("id", view.getResources().getResourceEntryName(view.getId())); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + view.startDragAndDrop(data, shadowBuilder, view, 0); + } else { + view.startDrag(data, shadowBuilder, view, 0); + } + return true; + } else + return false; + } + + @Override + public boolean onDrag(View v, DragEvent event) { + switch (event.getAction()) { + // signal for the start of a drag and drop operation + case DragEvent.ACTION_DRAG_STARTED: + // do nothing + break; + + // the drag point has entered the bounding box of the View + case DragEvent.ACTION_DRAG_ENTERED: + // do nothing + break; + + // the user has moved the drag shadow outside the bounding box of the View + case DragEvent.ACTION_DRAG_EXITED: + // do nothing + break; + + // the drag and drop operation has concluded + case DragEvent.ACTION_DRAG_ENDED: + if (win_counter == 8 && !done) { + done = true; + bravoPage(v); + } + break; + + //drag shadow has been released,the drag point is within the bounding box of the View + case DragEvent.ACTION_DROP: + //handle the dragged view being dropped over a target view + View view = (View) event.getLocalState(); + if (v == findViewById(R.id.salt)) { + if (view == findViewById(R.id.bacon) + || view == findViewById(R.id.hot_dog) + || view == findViewById(R.id.cheese) + || view == findViewById(R.id.fries)) { + //stop displaying the view where it was before it was dragged + view.setVisibility(View.INVISIBLE); + win_counter++; + } + } else if (v == findViewById(R.id.sugar)) { + if (view == findViewById(R.id.muffin) + || view == findViewById(R.id.apple) + || view == findViewById(R.id.muskmelon) + || view == findViewById(R.id.cake)) { + //stop displaying the view where it was before it was dragged + view.setVisibility(View.INVISIBLE); + win_counter++; + } + } + break; + } + return true; + } + + @Override + protected void next() { + //startActivity(new Intent(this, TutorialScene5Activity.class)); + } +} diff --git a/app/src/main/java/tonio/noa/MainActivity.java b/app/src/main/java/tonio/noa/MainActivity.java index 0b30f6f..e411869 100644 --- a/app/src/main/java/tonio/noa/MainActivity.java +++ b/app/src/main/java/tonio/noa/MainActivity.java @@ -2,33 +2,65 @@ package tonio.noa; import android.app.Activity; import android.content.Intent; +import android.speech.tts.TextToSpeech; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; +import android.widget.TextView; -public class MainActivity extends Activity { +import java.util.Locale; + +public class MainActivity extends Activity implements View.OnLongClickListener { + + private TextToSpeech tts; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + findViewById(R.id.button_id_play).setOnLongClickListener(this); + findViewById(R.id.button_id_tutorial).setOnLongClickListener(this); + + tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { + @Override + public void onInit(int status) { + if (status != TextToSpeech.ERROR) { + tts.setLanguage(Locale.FRENCH); + } + } + }); } - public void themePage(View view){ + public void themePage(View view) { startActivity(new Intent(this, ThemeActivity.class)); finish(); } - public void configurePage(View view){ + public void configurePage(View view) { startActivity(new Intent(this, ConfigureActivity.class)); finish(); } - public void tutorialPage(View view){ + public void tutorialPage(View view) { startActivity(new Intent(this, TutorialScene1Activity.class)); finish(); } + + public boolean onLongClick(View view) { + tts.speak(((TextView) view).getText(), TextToSpeech.QUEUE_FLUSH, null, null); + return true; + } + + @Override + public void onDestroy() { + if (tts != null) { + tts.stop(); + tts.shutdown(); + } + super.onDestroy(); + } } diff --git a/app/src/main/java/tonio/noa/ThemeActivity.java b/app/src/main/java/tonio/noa/ThemeActivity.java index 93955b1..66dd002 100644 --- a/app/src/main/java/tonio/noa/ThemeActivity.java +++ b/app/src/main/java/tonio/noa/ThemeActivity.java @@ -4,32 +4,75 @@ package tonio.noa; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.speech.tts.TextToSpeech; import android.support.v7.app.AppCompatActivity; import android.view.View; +import android.widget.TextView; +import java.util.Locale; /** * Created by tonio on 16/11/17. */ -public class ThemeActivity extends Activity { +public class ThemeActivity extends Activity implements View.OnLongClickListener { - protected void onCreate(Bundle savedInstanceState){ + private TextToSpeech tts; + + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.theme_display); + + findViewById(R.id.button_id_health).setOnLongClickListener(this); + findViewById(R.id.button_id_sociability).setOnLongClickListener(this); + findViewById(R.id.button_id_security).setOnLongClickListener(this); + findViewById(R.id.button_id_hygiene).setOnLongClickListener(this); + findViewById(R.id.button_id_independence).setOnLongClickListener(this); + findViewById(R.id.button_id_food).setOnLongClickListener(this); + + tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { + @Override + public void onInit(int status) { + if (status != TextToSpeech.ERROR) { + tts.setLanguage(Locale.FRENCH); + } + } + }); } - public void healthPage(View view){ + @Override + public boolean onLongClick(View view) { + tts.speak(((TextView) view).getText(), TextToSpeech.QUEUE_FLUSH, null, null); + return true; + } + + public void healthPage(View view) { startActivity(new Intent(this, HealthActivity.class)); } - public void hygienePage(View view){ + + public void hygienePage(View view) { startActivity(new Intent(this, Hygiene1Activity.class)); } - public void backHome(View view){ - startActivity(new Intent( this, MainActivity.class)); + public void foodPage(View view) { + + startActivity(new Intent(this, Food1Activity.class)); + } + + public void backHome(View view) { + + startActivity(new Intent(this, MainActivity.class)); + } + + @Override + public void onDestroy() { + if (tts != null) { + tts.stop(); + tts.shutdown(); + } + super.onDestroy(); } } diff --git a/app/src/main/res/drawable/apple.png b/app/src/main/res/drawable/apple.png new file mode 100644 index 0000000..08b03a8 Binary files /dev/null and b/app/src/main/res/drawable/apple.png differ diff --git a/app/src/main/res/drawable/bacon.png b/app/src/main/res/drawable/bacon.png new file mode 100644 index 0000000..0689080 Binary files /dev/null and b/app/src/main/res/drawable/bacon.png differ diff --git a/app/src/main/res/drawable/cake.png b/app/src/main/res/drawable/cake.png new file mode 100644 index 0000000..8a8042e Binary files /dev/null and b/app/src/main/res/drawable/cake.png differ diff --git a/app/src/main/res/drawable/cheese.png b/app/src/main/res/drawable/cheese.png new file mode 100644 index 0000000..24e4166 Binary files /dev/null and b/app/src/main/res/drawable/cheese.png differ diff --git a/app/src/main/res/drawable/fries.png b/app/src/main/res/drawable/fries.png new file mode 100644 index 0000000..08a7a64 Binary files /dev/null and b/app/src/main/res/drawable/fries.png differ diff --git a/app/src/main/res/drawable/hot_dog.png b/app/src/main/res/drawable/hot_dog.png new file mode 100644 index 0000000..ada1184 Binary files /dev/null and b/app/src/main/res/drawable/hot_dog.png differ diff --git a/app/src/main/res/drawable/muffin.png b/app/src/main/res/drawable/muffin.png new file mode 100644 index 0000000..d3d9547 Binary files /dev/null and b/app/src/main/res/drawable/muffin.png differ diff --git a/app/src/main/res/drawable/muskmelon.png b/app/src/main/res/drawable/muskmelon.png new file mode 100644 index 0000000..b8c14df Binary files /dev/null and b/app/src/main/res/drawable/muskmelon.png differ diff --git a/app/src/main/res/drawable/salt.jpg b/app/src/main/res/drawable/salt.jpg new file mode 100644 index 0000000..4614a09 Binary files /dev/null and b/app/src/main/res/drawable/salt.jpg differ diff --git a/app/src/main/res/drawable/sugar.jpg b/app/src/main/res/drawable/sugar.jpg new file mode 100644 index 0000000..575eaba Binary files /dev/null and b/app/src/main/res/drawable/sugar.jpg differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 24888b6..d889cf0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -2,17 +2,27 @@ + android:background="@color/colorPrimary"> + +