Code example for DragEvent

Methods: getAction, getClipData, getX, getY

0
      private static final String DROPTAG = "DropTarget";
      private int dropCount = 0;
      private ObjectAnimator anim;
 
      public boolean onDrag(View v, DragEvent event) {
        int action = event.getAction();
        boolean result = true;
        switch (action) {
        case DragEvent.ACTION_DRAG_STARTED:
          System.out.println(">>>>>>>>>>>>>>>>@@@@@@@@@@@@@@@");
          break; 
        case DragEvent.ACTION_DRAG_ENTERED:
          anim = ObjectAnimator.ofFloat((Object) v, "alpha", 1f, 0.5f);
          anim.setInterpolator(new CycleInterpolator(40));
          anim.setDuration(30 * 1000);
          anim.start();
          break; 
        case DragEvent.ACTION_DRAG_EXITED:
          if (anim != null) {
            anim.end();
            anim = null;
          } 
          break; 
        case DragEvent.ACTION_DRAG_LOCATION:
          System.out.println("drag proceeding in dropTarget: " + event.getX() + ", " + event.getY());
          break; 
        case DragEvent.ACTION_DROP:
          System.out.println("drag drop in dropTarget");
 
          if (anim != null) {
            anim.end();
            anim = null;
          } 
          ClipData data = event.getClipData();
          System.out.println("Item data is " + data.getItemAt(0).getText());
          dropCount++;
          String message = dropCount + " drop";
          if (dropCount > 1)
            message += "s";