d55d5943
aarnaude
resolution Bravo
|
1
2
|
package tonio.noa;
|
713264a5
aarnaude
ajout drag n drop...
|
3
4
|
import android.content.ClipData;
import android.os.Build;
|
d55d5943
aarnaude
resolution Bravo
|
5
|
import android.os.Bundle;
|
713264a5
aarnaude
ajout drag n drop...
|
6
7
|
import android.view.DragEvent;
import android.view.MotionEvent;
|
d55d5943
aarnaude
resolution Bravo
|
8
|
import android.view.View;
|
99fbb132
aarnaude
resolution bug dr...
|
9
|
import android.widget.ImageView;
|
d55d5943
aarnaude
resolution Bravo
|
10
11
12
13
14
|
/**
* Created by psyk on 09/01/18.
*/
|
99fbb132
aarnaude
resolution bug dr...
|
15
|
public class TutorialScene2Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener {
|
d55d5943
aarnaude
resolution Bravo
|
16
17
18
19
20
21
|
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial2_display);
|
713264a5
aarnaude
ajout drag n drop...
|
22
23
|
findViewById(R.id.blue_rectangle).setOnTouchListener(this);
|
99fbb132
aarnaude
resolution bug dr...
|
24
25
|
findViewById(R.id.blue_rectangle).setOnDragListener(this);
findViewById(R.id.red_rectangle).setOnDragListener(this);
|
713264a5
aarnaude
ajout drag n drop...
|
26
27
28
29
30
|
}
@Override
public boolean onTouch(View view, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
713264a5
aarnaude
ajout drag n drop...
|
31
|
|
99fbb132
aarnaude
resolution bug dr...
|
32
|
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
|
713264a5
aarnaude
ajout drag n drop...
|
33
34
35
36
37
38
39
|
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...
|
40
|
return true;
|
99fbb132
aarnaude
resolution bug dr...
|
41
42
|
} else
return false;
|
713264a5
aarnaude
ajout drag n drop...
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
}
@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...
|
65
66
67
68
|
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...
|
69
|
//handle the dragged view being dropped over a target view
|
713264a5
aarnaude
ajout drag n drop...
|
70
|
View view = (View) event.getLocalState();
|
99fbb132
aarnaude
resolution bug dr...
|
71
72
73
74
75
76
77
78
79
|
if(v==findViewById(R.id.red_rectangle)) {
//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...
|
80
|
}
|
713264a5
aarnaude
ajout drag n drop...
|
81
82
83
84
|
break;
}
return true;
|
d55d5943
aarnaude
resolution Bravo
|
85
86
87
88
89
90
|
}
@Override
protected void next() {
finish();
}
|
713264a5
aarnaude
ajout drag n drop...
|
91
|
|
d55d5943
aarnaude
resolution Bravo
|
92
|
}
|