Blame view

app/src/main/java/tonio/noa/Hygiene2Activity.java 3.37 KB
b66e4091   aarnaude   ajout activités d...
1
2
3
4
5
6
  package tonio.noa;
  
  import android.content.ClipData;
  import android.content.Intent;
  import android.os.Build;
  import android.os.Bundle;
4fbbe27a   aarnaude   ajout de la fonct...
7
  import android.speech.tts.TextToSpeech;
b66e4091   aarnaude   ajout activités d...
8
9
10
  import android.view.DragEvent;
  import android.view.MotionEvent;
  import android.view.View;
4fbbe27a   aarnaude   ajout de la fonct...
11
  import android.widget.TextView;
b66e4091   aarnaude   ajout activités d...
12
13
14
15
16
17
18
19
20
  
  /**
   * Created by psyk on 31/01/18.
   */
  
  public class Hygiene2Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
b66e4091   aarnaude   ajout activités d...
21
          super.onCreate(savedInstanceState);
2db7566f   aarnaude   modification de M...
22
          lanceConsigne("Maintenant met le dessin de la brosse à dent\nsur la photo de la brosse à dent.");
b66e4091   aarnaude   ajout activités d...
23
24
25
26
27
28
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          setContentView(R.layout.hygiene2_display);
4fbbe27a   aarnaude   ajout de la fonct...
29
30
31
32
33
34
  
          TextView txtV = findViewById(R.id.cons_hyg2);
          smallCons = "Met le dessin de la brosse à dent sur sa photo.";
          txtV.setText(smallCons);
          setTts();
  
b66e4091   aarnaude   ajout activités d...
35
36
37
38
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
91
92
93
94
95
          findViewById(R.id.blue_toothbrush).setOnTouchListener(this);
          findViewById(R.id.blue_toothbrush).setOnDragListener(this);
          findViewById(R.id.blue_toothbrush_pic).setOnDragListener(this);
          // do your stuff here after SecondActivity finished.
      }
  
  
      @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:
                  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.blue_toothbrush_pic)) {
                      //stop displaying the view where it was before it was dragged
                      view.setVisibility(View.INVISIBLE);
                      bravoPage(v);
                  }
                  break;
          }
  
          return true;
      }
  
b66e4091   aarnaude   ajout activités d...
96
97
98
99
100
      @Override
      protected void next() {
          startActivity(new Intent(this, Hygiene3Activity.class));
      }
  }