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;
|
713264a5
aarnaude
ajout drag n drop...
|
9
10
11
12
|
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
|
d55d5943
aarnaude
resolution Bravo
|
13
14
15
16
17
|
/**
* Created by psyk on 09/01/18.
*/
|
713264a5
aarnaude
ajout drag n drop...
|
18
19
|
public class TutorialScene2Activity extends MyPlayActivity implements View.OnTouchListener,View.OnDragListener{
|
d55d5943
aarnaude
resolution Bravo
|
20
21
22
23
24
25
|
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial2_display);
|
713264a5
aarnaude
ajout drag n drop...
|
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
|
findViewById(R.id.blue_rectangle).setOnTouchListener(this);
findViewById(R.id.ts2l1).setOnDragListener(this);
findViewById(R.id.ts2r1).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);
}
view.setVisibility(View.INVISIBLE);
return true;
}
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:
this.next();
break;
//drag shadow has been released,the drag point is within the bounding box of the View
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
// we want to make sure it is dropped only to left and right parent view
if (v.getId() == R.id.ts2l1 || v.getId() == R.id.ts2r1) {
ViewGroup source = (ViewGroup) view.getParent();
source.removeView(view);
RelativeLayout target = (RelativeLayout) v;
target.addView(view);
String id = event.getClipData().getItemAt(0).getText().toString();
Toast.makeText(this, id + " dropped!", Toast.LENGTH_SHORT).show();
bravoPage(view);
}
// make view visible as we set visibility to invisible while starting drag
view.setVisibility(View.VISIBLE);
break;
}
return true;
|
d55d5943
aarnaude
resolution Bravo
|
98
99
100
101
102
103
|
}
@Override
protected void next() {
finish();
}
|
713264a5
aarnaude
ajout drag n drop...
|
104
|
|
d55d5943
aarnaude
resolution Bravo
|
105
|
}
|