package tonio.noa; import android.content.ClipData; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.speech.tts.TextToSpeech; 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 TutorialScene4Activity 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("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) { super.onActivityResult(requestCode, resultCode, data); setContentView(R.layout.tutorial4_display); TextView txtV = findViewById(R.id.cons_tut4); smallCons = "Met les carrés dans les cases correspondantes."; txtV.setText(smallCons); setTts(); findViewById(R.id.blue_rectangle41).setOnTouchListener(this); findViewById(R.id.blue_rectangle42).setOnTouchListener(this); findViewById(R.id.blue_rectangle43).setOnTouchListener(this); findViewById(R.id.blue_rectangle44).setOnTouchListener(this); findViewById(R.id.red_rectangle41).setOnTouchListener(this); findViewById(R.id.red_rectangle42).setOnTouchListener(this); findViewById(R.id.red_rectangle43).setOnTouchListener(this); findViewById(R.id.red_rectangle44).setOnTouchListener(this); findViewById(R.id.green_rectangle41).setOnTouchListener(this); findViewById(R.id.green_rectangle42).setOnTouchListener(this); findViewById(R.id.green_rectangle43).setOnTouchListener(this); findViewById(R.id.green_rectangle44).setOnTouchListener(this); findViewById(R.id.anchor_blue_rectangle).setOnDragListener(this); findViewById(R.id.anchor_red_rectangle).setOnDragListener(this); findViewById(R.id.anchor_green_rectangle).setOnDragListener(this); findViewById(R.id.blue_rectangle41).setOnDragListener(this); findViewById(R.id.blue_rectangle42).setOnDragListener(this); findViewById(R.id.blue_rectangle43).setOnDragListener(this); findViewById(R.id.blue_rectangle44).setOnDragListener(this); findViewById(R.id.red_rectangle41).setOnDragListener(this); findViewById(R.id.red_rectangle42).setOnDragListener(this); findViewById(R.id.red_rectangle43).setOnDragListener(this); findViewById(R.id.red_rectangle44).setOnDragListener(this); findViewById(R.id.green_rectangle41).setOnDragListener(this); findViewById(R.id.green_rectangle42).setOnDragListener(this); findViewById(R.id.green_rectangle43).setOnDragListener(this); findViewById(R.id.green_rectangle44).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 == 12 && !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.anchor_red_rectangle)) { if (view == findViewById(R.id.red_rectangle41) || view == findViewById(R.id.red_rectangle42) || view == findViewById(R.id.red_rectangle43) || view == findViewById(R.id.red_rectangle44)) { //stop displaying the view where it was before it was dragged view.setVisibility(View.INVISIBLE); win_counter++; } } else if (v == findViewById(R.id.anchor_blue_rectangle)) { if (view == findViewById(R.id.blue_rectangle41) || view == findViewById(R.id.blue_rectangle42) || view == findViewById(R.id.blue_rectangle43) || view == findViewById(R.id.blue_rectangle44)) { //stop displaying the view where it was before it was dragged view.setVisibility(View.INVISIBLE); win_counter++; } } else if (v == findViewById(R.id.anchor_green_rectangle)) { if (view == findViewById(R.id.green_rectangle41) || view == findViewById(R.id.green_rectangle42) || view == findViewById(R.id.green_rectangle43) || view == findViewById(R.id.green_rectangle44)) { //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)); } }