Commit 4d5786fb9ff9a7ee71a0448c5da0809cb2e36b22
1 parent
99fbb132
ajout scene 3 : drag n drop multiples
Showing
6 changed files
with
207 additions
and
3 deletions
Show diff stats
app/src/main/AndroidManifest.xml
@@ -64,10 +64,18 @@ | @@ -64,10 +64,18 @@ | ||
64 | </activity> | 64 | </activity> |
65 | 65 | ||
66 | <activity | 66 | <activity |
67 | - android:name=".BravoActivity" | 67 | + android:name=".TutorialScene3Activity" |
68 | + android:parentActivityName=".TutorialScene1Activity" | ||
68 | android:screenOrientation="userLandscape"> | 69 | android:screenOrientation="userLandscape"> |
70 | + <meta-data | ||
71 | + android:name="android.support.PARENT_ACTIVITY" | ||
72 | + android:value=".MainActivity" /> | ||
69 | </activity> | 73 | </activity> |
70 | 74 | ||
75 | + <activity | ||
76 | + android:name=".BravoActivity" | ||
77 | + android:screenOrientation="userLandscape"></activity> | ||
78 | + | ||
71 | </application> | 79 | </application> |
72 | 80 | ||
73 | </manifest> | 81 | </manifest> |
74 | \ No newline at end of file | 82 | \ No newline at end of file |
app/src/main/java/tonio/noa/TutorialScene2Activity.java
1 | package tonio.noa; | 1 | package tonio.noa; |
2 | 2 | ||
3 | import android.content.ClipData; | 3 | import android.content.ClipData; |
4 | +import android.content.Intent; | ||
4 | import android.os.Build; | 5 | import android.os.Build; |
5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
6 | import android.view.DragEvent; | 7 | import android.view.DragEvent; |
@@ -68,7 +69,7 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou | @@ -68,7 +69,7 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou | ||
68 | case DragEvent.ACTION_DROP: | 69 | case DragEvent.ACTION_DROP: |
69 | //handle the dragged view being dropped over a target view | 70 | //handle the dragged view being dropped over a target view |
70 | View view = (View) event.getLocalState(); | 71 | View view = (View) event.getLocalState(); |
71 | - if(v==findViewById(R.id.red_rectangle)) { | 72 | + if (v == findViewById(R.id.red_rectangle)) { |
72 | //stop displaying the view where it was before it was dragged | 73 | //stop displaying the view where it was before it was dragged |
73 | view.setVisibility(View.INVISIBLE); | 74 | view.setVisibility(View.INVISIBLE); |
74 | //view dragged item is being dropped on | 75 | //view dragged item is being dropped on |
@@ -86,6 +87,7 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou | @@ -86,6 +87,7 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou | ||
86 | 87 | ||
87 | @Override | 88 | @Override |
88 | protected void next() { | 89 | protected void next() { |
90 | + startActivity(new Intent(this, TutorialScene3Activity.class)); | ||
89 | finish(); | 91 | finish(); |
90 | } | 92 | } |
91 | 93 |
app/src/main/java/tonio/noa/TutorialScene3Activity.java
0 → 100644
@@ -0,0 +1,102 @@ | @@ -0,0 +1,102 @@ | ||
1 | +package tonio.noa; | ||
2 | + | ||
3 | +import android.content.ClipData; | ||
4 | +import android.os.Build; | ||
5 | +import android.os.Bundle; | ||
6 | +import android.view.DragEvent; | ||
7 | +import android.view.MotionEvent; | ||
8 | +import android.view.View; | ||
9 | +import android.widget.ImageView; | ||
10 | + | ||
11 | +/** | ||
12 | + * Created by psyk on 15/01/18. | ||
13 | + */ | ||
14 | + | ||
15 | +public class TutorialScene3Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener { | ||
16 | + | ||
17 | + @Override | ||
18 | + protected void onCreate(Bundle savedInstanceState) { | ||
19 | + | ||
20 | + super.onCreate(savedInstanceState); | ||
21 | + setContentView(R.layout.tutorial3_display); | ||
22 | + | ||
23 | + findViewById(R.id.blue_rectangle31).setOnTouchListener(this); | ||
24 | + findViewById(R.id.blue_rectangle32).setOnTouchListener(this); | ||
25 | + findViewById(R.id.red_rectangle31).setOnTouchListener(this); | ||
26 | + findViewById(R.id.red_rectangle32).setOnTouchListener(this); | ||
27 | + findViewById(R.id.green_rectangle31).setOnTouchListener(this); | ||
28 | + findViewById(R.id.green_rectangle32).setOnTouchListener(this); | ||
29 | + | ||
30 | + findViewById(R.id.blue_rectangle31).setOnDragListener(this); | ||
31 | + findViewById(R.id.blue_rectangle32).setOnDragListener(this); | ||
32 | + findViewById(R.id.red_rectangle31).setOnDragListener(this); | ||
33 | + findViewById(R.id.red_rectangle32).setOnDragListener(this); | ||
34 | + findViewById(R.id.green_rectangle31).setOnDragListener(this); | ||
35 | + findViewById(R.id.green_rectangle32).setOnDragListener(this); | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public boolean onTouch(View view, MotionEvent event) { | ||
40 | + if (event.getAction() == MotionEvent.ACTION_DOWN) { | ||
41 | + | ||
42 | + View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view); | ||
43 | + ClipData data = ClipData.newPlainText("id", view.getResources().getResourceEntryName(view.getId())); | ||
44 | + | ||
45 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
46 | + view.startDragAndDrop(data, shadowBuilder, view, 0); | ||
47 | + } else { | ||
48 | + view.startDrag(data, shadowBuilder, view, 0); | ||
49 | + } | ||
50 | + return true; | ||
51 | + } else | ||
52 | + return false; | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + public boolean onDrag(View v, DragEvent event) { | ||
57 | + switch (event.getAction()) { | ||
58 | + // signal for the start of a drag and drop operation | ||
59 | + case DragEvent.ACTION_DRAG_STARTED: | ||
60 | + // do nothing | ||
61 | + break; | ||
62 | + | ||
63 | + // the drag point has entered the bounding box of the View | ||
64 | + case DragEvent.ACTION_DRAG_ENTERED: | ||
65 | + // do nothing | ||
66 | + break; | ||
67 | + | ||
68 | + // the user has moved the drag shadow outside the bounding box of the View | ||
69 | + case DragEvent.ACTION_DRAG_EXITED: | ||
70 | + // do nothing | ||
71 | + break; | ||
72 | + | ||
73 | + // the drag and drop operation has concluded | ||
74 | + case DragEvent.ACTION_DRAG_ENDED: | ||
75 | + break; | ||
76 | + | ||
77 | + //drag shadow has been released,the drag point is within the bounding box of the View | ||
78 | + case DragEvent.ACTION_DROP: | ||
79 | + //handle the dragged view being dropped over a target view | ||
80 | + View view = (View) event.getLocalState(); | ||
81 | + if (v == findViewById(R.id.red_rectangle)) { | ||
82 | + //stop displaying the view where it was before it was dragged | ||
83 | + view.setVisibility(View.INVISIBLE); | ||
84 | + //view dragged item is being dropped on | ||
85 | + ImageView dropTarget = (ImageView) v; | ||
86 | + //view being dragged and dropped | ||
87 | + ImageView dropped = (ImageView) view; | ||
88 | + dropTarget.setBackgroundColor(dropped.getSolidColor()); | ||
89 | + bravoPage(v); | ||
90 | + } | ||
91 | + break; | ||
92 | + } | ||
93 | + | ||
94 | + return true; | ||
95 | + } | ||
96 | + | ||
97 | + @Override | ||
98 | + protected void next() { | ||
99 | + finish(); | ||
100 | + } | ||
101 | + | ||
102 | +} |
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + android:shape="rectangle"> | ||
4 | + <solid android:color="@android:color/holo_green_light"/> | ||
5 | + <corners android:radius="5dp"/> | ||
6 | +</shape> | ||
0 | \ No newline at end of file | 7 | \ No newline at end of file |
app/src/main/res/layout/tutorial2_display.xml
@@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
34 | android:layout_width="wrap_content" | 34 | android:layout_width="wrap_content" |
35 | android:layout_height="wrap_content" | 35 | android:layout_height="wrap_content" |
36 | android:layout_alignParentBottom="true" | 36 | android:layout_alignParentBottom="true" |
37 | - android:layout_alignParentLeft="true" | 37 | + android:layout_alignParentStart="true" |
38 | android:layout_margin="5dp" | 38 | android:layout_margin="5dp" |
39 | android:onClick="backHome" | 39 | android:onClick="backHome" |
40 | android:text="@string/home" /> | 40 | android:text="@string/home" /> |
@@ -0,0 +1,86 @@ | @@ -0,0 +1,86 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + android:id="@+id/tut3" | ||
4 | + android:layout_width="match_parent" | ||
5 | + android:layout_height="match_parent" | ||
6 | + android:orientation="vertical"> | ||
7 | + | ||
8 | + <TextView | ||
9 | + android:id="@+id/text3" | ||
10 | + android:layout_width="wrap_content" | ||
11 | + android:layout_height="wrap_content" | ||
12 | + android:layout_centerHorizontal="true" | ||
13 | + android:layout_margin="20dp" | ||
14 | + android:text="Associe les carrés de même couleur ensemble." | ||
15 | + android:textSize="15sp" /> | ||
16 | + | ||
17 | + <ImageView | ||
18 | + android:id="@+id/blue_rectangle31" | ||
19 | + android:layout_width="50dp" | ||
20 | + android:layout_height="50dp" | ||
21 | + android:layout_alignParentStart="true" | ||
22 | + android:layout_below="@id/text3" | ||
23 | + android:layout_margin="50dp" | ||
24 | + android:background="@drawable/blue_rectangle" /> | ||
25 | + | ||
26 | + | ||
27 | + <ImageView | ||
28 | + android:id="@+id/red_rectangle31" | ||
29 | + android:layout_width="50dp" | ||
30 | + android:layout_height="50dp" | ||
31 | + android:layout_alignParentEnd="true" | ||
32 | + android:layout_below="@id/text3" | ||
33 | + android:layout_margin="50dp" | ||
34 | + android:background="@drawable/red_rectangle" | ||
35 | + android:nextFocusRight="@id/blue_rectangle31" /> | ||
36 | + | ||
37 | + <ImageView | ||
38 | + android:id="@+id/green_rectangle31" | ||
39 | + android:layout_width="50dp" | ||
40 | + android:layout_height="50dp" | ||
41 | + android:layout_alignParentStart="true" | ||
42 | + android:layout_below="@id/blue_rectangle31" | ||
43 | + android:layout_margin="50dp" | ||
44 | + android:background="@drawable/green_rectangle" /> | ||
45 | + | ||
46 | + | ||
47 | + <ImageView | ||
48 | + android:id="@+id/red_rectangle32" | ||
49 | + android:layout_width="50dp" | ||
50 | + android:layout_height="50dp" | ||
51 | + android:layout_alignParentEnd="true" | ||
52 | + android:layout_below="@id/red_rectangle31" | ||
53 | + android:layout_margin="50dp" | ||
54 | + android:background="@drawable/red_rectangle" | ||
55 | + android:nextFocusRight="@id/green_rectangle31" /> | ||
56 | + | ||
57 | + <ImageView | ||
58 | + android:id="@+id/blue_rectangle32" | ||
59 | + android:layout_width="50dp" | ||
60 | + android:layout_height="50dp" | ||
61 | + android:layout_alignParentStart="true" | ||
62 | + android:layout_below="@id/green_rectangle31" | ||
63 | + android:layout_margin="50dp" | ||
64 | + android:background="@drawable/blue_rectangle" /> | ||
65 | + | ||
66 | + <ImageView | ||
67 | + android:id="@+id/green_rectangle32" | ||
68 | + android:layout_width="50dp" | ||
69 | + android:layout_height="50dp" | ||
70 | + android:layout_alignParentEnd="true" | ||
71 | + android:layout_below="@id/red_rectangle32" | ||
72 | + android:layout_margin="50dp" | ||
73 | + android:background="@drawable/green_rectangle" | ||
74 | + android:nextFocusRight="@id/blue_rectangle32" /> | ||
75 | + | ||
76 | + <Button | ||
77 | + android:id="@+id/button_id_home" | ||
78 | + android:layout_width="wrap_content" | ||
79 | + android:layout_height="wrap_content" | ||
80 | + android:layout_alignParentBottom="true" | ||
81 | + android:layout_alignParentStart="true" | ||
82 | + android:layout_margin="5dp" | ||
83 | + android:onClick="backHome" | ||
84 | + android:text="@string/home" /> | ||
85 | + | ||
86 | +</RelativeLayout> | ||
0 | \ No newline at end of file | 87 | \ No newline at end of file |