Blame view

app/src/main/java/tonio/noa/TutorialScene3Activity.java 5.15 KB
4d5786fb   aarnaude   ajout scene 3 : d...
1
2
3
  package tonio.noa;
  
  import android.content.ClipData;
c13d9bc3   aarnaude   activity consigne...
4
  import android.content.Intent;
4d5786fb   aarnaude   ajout scene 3 : d...
5
6
  import android.os.Build;
  import android.os.Bundle;
4fbbe27a   aarnaude   ajout de la fonct...
7
  import android.speech.tts.TextToSpeech;
4d5786fb   aarnaude   ajout scene 3 : d...
8
9
10
11
  import android.view.DragEvent;
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.ImageView;
4fbbe27a   aarnaude   ajout de la fonct...
12
  import android.widget.TextView;
4d5786fb   aarnaude   ajout scene 3 : d...
13
14
15
16
17
18
19
  
  /**
   * Created by psyk on 15/01/18.
   */
  
  public class TutorialScene3Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener {
  
2ff2b441   aarnaude   scene 3 : done
20
      private int win_counter = 0;
95306d09   aarnaude   résolution bug su...
21
      private boolean done = false;
2ff2b441   aarnaude   scene 3 : done
22
  
4d5786fb   aarnaude   ajout scene 3 : d...
23
24
      @Override
      protected void onCreate(Bundle savedInstanceState) {
4d5786fb   aarnaude   ajout scene 3 : d...
25
          super.onCreate(savedInstanceState);
2db7566f   aarnaude   modification de M...
26
          lanceConsigne("J'ai encore une nouvelle mission pour toi!\nTu dois associer les carrés de même couleur.");
c13d9bc3   aarnaude   activity consigne...
27
28
29
30
31
      }
  
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
4d5786fb   aarnaude   ajout scene 3 : d...
32
33
          setContentView(R.layout.tutorial3_display);
  
4fbbe27a   aarnaude   ajout de la fonct...
34
35
36
37
38
          TextView txtV = findViewById(R.id.cons_tut3);
          smallCons = "Associe les carrés de même couleur.";
          txtV.setText(smallCons);
          setTts();
  
4d5786fb   aarnaude   ajout scene 3 : d...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
          findViewById(R.id.blue_rectangle31).setOnTouchListener(this);
          findViewById(R.id.blue_rectangle32).setOnTouchListener(this);
          findViewById(R.id.red_rectangle31).setOnTouchListener(this);
          findViewById(R.id.red_rectangle32).setOnTouchListener(this);
          findViewById(R.id.green_rectangle31).setOnTouchListener(this);
          findViewById(R.id.green_rectangle32).setOnTouchListener(this);
  
          findViewById(R.id.blue_rectangle31).setOnDragListener(this);
          findViewById(R.id.blue_rectangle32).setOnDragListener(this);
          findViewById(R.id.red_rectangle31).setOnDragListener(this);
          findViewById(R.id.red_rectangle32).setOnDragListener(this);
          findViewById(R.id.green_rectangle31).setOnDragListener(this);
          findViewById(R.id.green_rectangle32).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:
2db7566f   aarnaude   modification de M...
91
92
93
94
                  if (win_counter == 3 && !done) {
                      done = true;
                      bravoPage(v);
                  }
4d5786fb   aarnaude   ajout scene 3 : d...
95
96
97
98
99
100
                  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();
2ff2b441   aarnaude   scene 3 : done
101
102
103
104
105
106
107
108
                  if (
                          (v == findViewById(R.id.red_rectangle31) && view == findViewById(R.id.red_rectangle32)) ||
                                  (v == findViewById(R.id.red_rectangle32) && view == findViewById(R.id.red_rectangle31)) ||
                                  (v == findViewById(R.id.blue_rectangle31) && view == findViewById(R.id.blue_rectangle32)) ||
                                  (v == findViewById(R.id.blue_rectangle32) && view == findViewById(R.id.blue_rectangle31)) ||
                                  (v == findViewById(R.id.green_rectangle31) && view == findViewById(R.id.green_rectangle32)) ||
                                  (v == findViewById(R.id.green_rectangle32) && view == findViewById(R.id.green_rectangle31))
                          ) {
4d5786fb   aarnaude   ajout scene 3 : d...
109
110
111
112
113
114
115
                      //stop displaying the view where it was before it was dragged
                      view.setVisibility(View.INVISIBLE);
                      //view dragged item is being dropped on
                      ImageView dropTarget = (ImageView) v;
                      //view being dragged and dropped
                      ImageView dropped = (ImageView) view;
                      dropTarget.setBackgroundColor(dropped.getSolidColor());
2ff2b441   aarnaude   scene 3 : done
116
                      win_counter++;
4d5786fb   aarnaude   ajout scene 3 : d...
117
118
119
120
121
122
123
124
125
                  }
                  break;
          }
  
          return true;
      }
  
      @Override
      protected void next() {
48365340   aarnaude   ajout scène 4 tri...
126
          startActivity(new Intent(this, TutorialScene4Activity.class));
4d5786fb   aarnaude   ajout scene 3 : d...
127
      }
4d5786fb   aarnaude   ajout scene 3 : d...
128
  }