Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <GridLayout
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:id="@+id/Grid"
  5. android:layout_marginLeft="8dp"
  6. android:layout_marginRight="6dp"
  7. android:layout_marginBottom="30dp"
  8. android:layout_gravity="center">
  9.  
  10. <LinearLayout android:layout_width="50dp"
  11. android:layout_height="50dp"
  12. android:id="@+id/AnswerOne"
  13. android:orientation="horizontal"
  14. android:layout_row="0"
  15. android:layout_column="0"
  16. >
  17. <ImageView
  18. android:layout_width="fill_parent"
  19. android:layout_height="fill_parent"
  20. android:id="@+id/ImageOne"
  21. />
  22. </LinearLayout>
  23. <LinearLayout android:layout_width="50dp"
  24. android:layout_height="50dp"
  25. android:id="@+id/AnswerTwo"
  26. android:orientation="horizontal"
  27. android:layout_row="0"
  28. android:layout_column="1"
  29. >
  30. <ImageView
  31. android:layout_width="fill_parent"
  32. android:layout_height="fill_parent"
  33. android:id="@+id/ImageTwo"/>
  34. </LinearLayout>
  35.  
  36. Images[0].setOnDragListener(new View.OnDragListener() {
  37. @Override
  38. public boolean onDrag(View v, DragEvent event) {
  39. clipDataImage = GameBoardOnDragListenerSwitchMethod(event, v, 0);
  40. return clipDataImage ;
  41. }
  42. });
  43.  
  44. Images[1].setOnDragListener(new View.OnDragListener() {
  45. @Override
  46. public boolean onDrag(View v, DragEvent event) {
  47. clipDataImage = GameBoardOnDragListenerSwitchMethod(event, v, 1);
  48. return clipDataImage ;
  49. }
  50. });
  51.  
  52. public boolean GameBoardOnDragListenerSwitchMethod(DragEvent myDrag, View myV, int dragListenerValue){
  53.  
  54. switch (myDrag.getAction()) {
  55. case DragEvent.ACTION_DRAG_STARTED:
  56. if (myDrag.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
  57. myV.invalidate();
  58. return true;
  59. }
  60. return true;
  61.  
  62. case DragEvent.ACTION_DRAG_ENTERED:
  63. gameImages[dragListenerValue].setBackgroundColor(Color.BLUE);
  64. gameImages[dragListenerValue].setPadding(5, 5, 5, 5);
  65.  
  66. return true;
  67.  
  68. case DragEvent.ACTION_DRAG_LOCATION:
  69.  
  70. return true;
  71.  
  72. case DragEvent.ACTION_DRAG_EXITED:
  73. gameImages[dragListenerValue].setBackgroundColor(0);
  74. gameImages[dragListenerValue].setPadding(0, 0, 0, 0);
  75.  
  76. return true;
  77.  
  78. case DragEvent.ACTION_DROP:
  79. DragEvent myEvent = myDrag;
  80. getGameImages(myEvent, dragListenerValue);
  81.  
  82. return true;
  83.  
  84. case DragEvent.ACTION_DRAG_ENDED:
  85.  
  86. return true;
  87.  
  88. // An unknown action type was received.
  89. default:
  90. Log.e("DragDrop Example", "Unknown action type received by OnDragListener.");
  91. break;
  92. }
  93. return true;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement