48365340
aarnaude
ajout scène 4 tri...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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;
/**
* Created by psyk on 24/01/18.
*/
public class TutorialScene4Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener {
private int win_counter = 0;
|
95306d09
aarnaude
résolution bug su...
|
18
|
private boolean done = false;
|
48365340
aarnaude
ajout scène 4 tri...
|
19
20
21
22
23
24
|
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, ConsigneActivity.class);
|
b66e4091
aarnaude
ajout activités d...
|
25
|
i.putExtra("keyConsigne", "Tu peux mettre les petits carrés de couleurs sur les gros de la même couleur ?\nMerci !");
|
48365340
aarnaude
ajout scène 4 tri...
|
26
27
28
29
30
31
32
33
|
int requestCode = 0;
startActivityForResult(i, requestCode);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
34
|
setContentView(R.layout.tutorial4_display);
|
48365340
aarnaude
ajout scène 4 tri...
|
35
36
37
38
|
findViewById(R.id.blue_rectangle41).setOnTouchListener(this);
findViewById(R.id.blue_rectangle42).setOnTouchListener(this);
findViewById(R.id.blue_rectangle43).setOnTouchListener(this);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
39
|
findViewById(R.id.blue_rectangle44).setOnTouchListener(this);
|
48365340
aarnaude
ajout scène 4 tri...
|
40
41
42
|
findViewById(R.id.red_rectangle41).setOnTouchListener(this);
findViewById(R.id.red_rectangle42).setOnTouchListener(this);
findViewById(R.id.red_rectangle43).setOnTouchListener(this);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
43
|
findViewById(R.id.red_rectangle44).setOnTouchListener(this);
|
48365340
aarnaude
ajout scène 4 tri...
|
44
45
46
|
findViewById(R.id.green_rectangle41).setOnTouchListener(this);
findViewById(R.id.green_rectangle42).setOnTouchListener(this);
findViewById(R.id.green_rectangle43).setOnTouchListener(this);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
47
|
findViewById(R.id.green_rectangle44).setOnTouchListener(this);
|
48365340
aarnaude
ajout scène 4 tri...
|
48
49
50
51
52
53
54
|
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);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
55
|
findViewById(R.id.blue_rectangle44).setOnDragListener(this);
|
48365340
aarnaude
ajout scène 4 tri...
|
56
57
58
|
findViewById(R.id.red_rectangle41).setOnDragListener(this);
findViewById(R.id.red_rectangle42).setOnDragListener(this);
findViewById(R.id.red_rectangle43).setOnDragListener(this);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
59
|
findViewById(R.id.red_rectangle44).setOnDragListener(this);
|
48365340
aarnaude
ajout scène 4 tri...
|
60
61
62
|
findViewById(R.id.green_rectangle41).setOnDragListener(this);
findViewById(R.id.green_rectangle42).setOnDragListener(this);
findViewById(R.id.green_rectangle43).setOnDragListener(this);
|
aaefb55f
aarnaude
scène 4 : débogguée
|
63
|
findViewById(R.id.green_rectangle44).setOnDragListener(this);
|
48365340
aarnaude
ajout scène 4 tri...
|
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
|
}
@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:
|
95306d09
aarnaude
résolution bug su...
|
104
105
106
107
|
if (win_counter == 12 && !done) {
done = true;
bravoPage(v);
}
|
48365340
aarnaude
ajout scène 4 tri...
|
108
109
110
111
112
113
114
115
116
|
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)
|
aaefb55f
aarnaude
scène 4 : débogguée
|
117
118
|
|| view == findViewById(R.id.red_rectangle43)
|| view == findViewById(R.id.red_rectangle44)) {
|
48365340
aarnaude
ajout scène 4 tri...
|
119
120
121
122
123
124
125
|
//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)
|
aaefb55f
aarnaude
scène 4 : débogguée
|
126
127
|
|| view == findViewById(R.id.blue_rectangle43)
|| view == findViewById(R.id.blue_rectangle44)) {
|
48365340
aarnaude
ajout scène 4 tri...
|
128
129
130
131
132
133
134
|
//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)
|
aaefb55f
aarnaude
scène 4 : débogguée
|
135
136
|
|| view == findViewById(R.id.green_rectangle43)
|| view == findViewById(R.id.green_rectangle44)) {
|
48365340
aarnaude
ajout scène 4 tri...
|
137
138
139
140
141
142
143
144
145
146
147
148
|
//stop displaying the view where it was before it was dragged
view.setVisibility(View.INVISIBLE);
win_counter++;
}
}
break;
}
return true;
}
@Override
protected void next() {
|
aaefb55f
aarnaude
scène 4 : débogguée
|
149
|
startActivity(new Intent(this, TutorialScene5Activity.class));
|
48365340
aarnaude
ajout scène 4 tri...
|
150
151
|
}
}
|