diff --git a/.idea/misc.xml b/.idea/misc.xml index 75dac50..3963879 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -24,7 +24,7 @@ - + diff --git a/app/src/main/java/tonio/noa/TutorialScene1Activity.java b/app/src/main/java/tonio/noa/TutorialScene1Activity.java index 882bfe0..68668a3 100644 --- a/app/src/main/java/tonio/noa/TutorialScene1Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene1Activity.java @@ -2,7 +2,6 @@ package tonio.noa; import android.content.Intent; import android.os.Bundle; -import android.view.View; /** * Created by tonio on 22/11/17. diff --git a/app/src/main/java/tonio/noa/TutorialScene2Activity.java b/app/src/main/java/tonio/noa/TutorialScene2Activity.java index cf672d7..758ef19 100644 --- a/app/src/main/java/tonio/noa/TutorialScene2Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene2Activity.java @@ -1,23 +1,105 @@ package tonio.noa; +import android.content.ClipData; +import android.os.Build; import android.os.Bundle; +import android.view.DragEvent; +import android.view.MotionEvent; import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.Toast; /** * Created by psyk on 09/01/18. */ -public class TutorialScene2Activity extends MyPlayActivity { +public class TutorialScene2Activity extends MyPlayActivity implements View.OnTouchListener,View.OnDragListener{ + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tutorial2_display); + + 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; } @Override protected void next() { finish(); } + } diff --git a/app/src/main/res/drawable/blue_rectangle.xml b/app/src/main/res/drawable/blue_rectangle.xml new file mode 100644 index 0000000..8f3bb3f --- /dev/null +++ b/app/src/main/res/drawable/blue_rectangle.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/red_rectangle.xml b/app/src/main/res/drawable/red_rectangle.xml new file mode 100644 index 0000000..6f8e3bc --- /dev/null +++ b/app/src/main/res/drawable/red_rectangle.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/tutorial2_display.xml b/app/src/main/res/layout/tutorial2_display.xml index 7046d3b..4baa0a5 100644 --- a/app/src/main/res/layout/tutorial2_display.xml +++ b/app/src/main/res/layout/tutorial2_display.xml @@ -4,20 +4,53 @@ android:layout_height="match_parent" android:orientation="vertical"> + + + android:layout_margin="5dp" + android:textSize="15sp" + android:text="Fais glisser le rectangle bleu sur le rectangle rouge." /> -