Blame view

app/src/main/java/tonio/noa/TutorialScene2Activity.java 3.63 KB
d55d5943   aarnaude   resolution Bravo
1
2
  package tonio.noa;
  
713264a5   aarnaude   ajout drag n drop...
3
  import android.content.ClipData;
4d5786fb   aarnaude   ajout scene 3 : d...
4
  import android.content.Intent;
713264a5   aarnaude   ajout drag n drop...
5
  import android.os.Build;
d55d5943   aarnaude   resolution Bravo
6
  import android.os.Bundle;
4fbbe27a   aarnaude   ajout de la fonct...
7
  import android.speech.tts.TextToSpeech;
713264a5   aarnaude   ajout drag n drop...
8
9
  import android.view.DragEvent;
  import android.view.MotionEvent;
d55d5943   aarnaude   resolution Bravo
10
  import android.view.View;
99fbb132   aarnaude   resolution bug dr...
11
  import android.widget.ImageView;
4fbbe27a   aarnaude   ajout de la fonct...
12
  import android.widget.TextView;
d55d5943   aarnaude   resolution Bravo
13
14
15
16
17
  
  /**
   * Created by psyk on 09/01/18.
   */
  
99fbb132   aarnaude   resolution bug dr...
18
  public class TutorialScene2Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener {
d55d5943   aarnaude   resolution Bravo
19
20
21
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
d55d5943   aarnaude   resolution Bravo
22
          super.onCreate(savedInstanceState);
2db7566f   aarnaude   modification de M...
23
          lanceConsigne("J'ai encore besoin de toi !\nMet le rectangle bleu sur le rouge.");
c13d9bc3   aarnaude   activity consigne...
24
25
26
27
28
29
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          setContentView(R.layout.tutorial2_display);
713264a5   aarnaude   ajout drag n drop...
30
          findViewById(R.id.blue_rectangle).setOnTouchListener(this);
99fbb132   aarnaude   resolution bug dr...
31
32
          findViewById(R.id.blue_rectangle).setOnDragListener(this);
          findViewById(R.id.red_rectangle).setOnDragListener(this);
4fbbe27a   aarnaude   ajout de la fonct...
33
34
35
36
          TextView txtV = findViewById(R.id.cons_tut2);
          smallCons = "Fais glisser le rectangle bleu sur le rectangle rouge.";
          txtV.setText(smallCons);
          setTts();
713264a5   aarnaude   ajout drag n drop...
37
38
      }
  
c13d9bc3   aarnaude   activity consigne...
39
  
713264a5   aarnaude   ajout drag n drop...
40
41
42
      @Override
      public boolean onTouch(View view, MotionEvent event) {
          if (event.getAction() == MotionEvent.ACTION_DOWN) {
713264a5   aarnaude   ajout drag n drop...
43
  
99fbb132   aarnaude   resolution bug dr...
44
              View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
713264a5   aarnaude   ajout drag n drop...
45
46
47
48
49
50
51
              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);
              }
713264a5   aarnaude   ajout drag n drop...
52
              return true;
99fbb132   aarnaude   resolution bug dr...
53
54
          } else
              return false;
713264a5   aarnaude   ajout drag n drop...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
      }
  
      @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:
713264a5   aarnaude   ajout drag n drop...
77
78
79
80
                  break;
  
              //drag shadow has been released,the drag point is within the bounding box of the View
              case DragEvent.ACTION_DROP:
99fbb132   aarnaude   resolution bug dr...
81
                  //handle the dragged view being dropped over a target view
713264a5   aarnaude   ajout drag n drop...
82
                  View view = (View) event.getLocalState();
4d5786fb   aarnaude   ajout scene 3 : d...
83
                  if (v == findViewById(R.id.red_rectangle)) {
99fbb132   aarnaude   resolution bug dr...
84
85
86
87
88
89
90
91
                      //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());
                      bravoPage(v);
713264a5   aarnaude   ajout drag n drop...
92
                  }
713264a5   aarnaude   ajout drag n drop...
93
94
95
96
                  break;
          }
  
          return true;
d55d5943   aarnaude   resolution Bravo
97
98
99
100
      }
  
      @Override
      protected void next() {
4d5786fb   aarnaude   ajout scene 3 : d...
101
          startActivity(new Intent(this, TutorialScene3Activity.class));
d55d5943   aarnaude   resolution Bravo
102
      }
713264a5   aarnaude   ajout drag n drop...
103
  
4fbbe27a   aarnaude   ajout de la fonct...
104
  
d55d5943   aarnaude   resolution Bravo
105
  }