diff --git a/app/src/main/java/tonio/noa/TutorialScene2Activity.java b/app/src/main/java/tonio/noa/TutorialScene2Activity.java index 758ef19..0786e8b 100644 --- a/app/src/main/java/tonio/noa/TutorialScene2Activity.java +++ b/app/src/main/java/tonio/noa/TutorialScene2Activity.java @@ -6,17 +6,13 @@ 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; +import android.widget.ImageView; /** * Created by psyk on 09/01/18. */ -public class TutorialScene2Activity extends MyPlayActivity implements View.OnTouchListener,View.OnDragListener{ - +public class TutorialScene2Activity extends MyPlayActivity implements View.OnTouchListener, View.OnDragListener { @Override protected void onCreate(Bundle savedInstanceState) { @@ -25,16 +21,15 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou setContentView(R.layout.tutorial2_display); findViewById(R.id.blue_rectangle).setOnTouchListener(this); - - findViewById(R.id.ts2l1).setOnDragListener(this); - findViewById(R.id.ts2r1).setOnDragListener(this); + findViewById(R.id.blue_rectangle).setOnDragListener(this); + findViewById(R.id.red_rectangle).setOnDragListener(this); } @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { - View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view); + 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) { @@ -42,11 +37,9 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou } else { view.startDrag(data, shadowBuilder, view, 0); } - - view.setVisibility(View.INVISIBLE); return true; - } - return false; + } else + return false; } @Override @@ -69,28 +62,22 @@ public class TutorialScene2Activity extends MyPlayActivity implements View.OnTou // 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: + //handle the dragged view being dropped over a target view 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); + 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); } - // make view visible as we set visibility to invisible while starting drag - view.setVisibility(View.VISIBLE); break; } diff --git a/app/src/main/res/layout/tutorial2_display.xml b/app/src/main/res/layout/tutorial2_display.xml index 4baa0a5..c16f07d 100644 --- a/app/src/main/res/layout/tutorial2_display.xml +++ b/app/src/main/res/layout/tutorial2_display.xml @@ -1,56 +1,42 @@ - - + android:layout_centerHorizontal="true" + android:text="Fais glisser le rectangle bleu sur le rectangle rouge." + android:textSize="15sp" /> + android:layout_centerHorizontal="true" + android:background="@drawable/blue_rectangle" /> - - - - - -