Blame view

app/src/main/java/tonio/noa/Food1Activity.java 5.01 KB
a5c66bd7   aarnaude   modif boutons/typ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  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() {
a5c66bd7   aarnaude   modif boutons/typ...
132
133
      }
  }