@Override
  public boolean onDragEvent(DragEvent event) {
    switch (event.getAction()) {
      case DragEvent.ACTION_DRAG_STARTED:
        Log.i(TAG, "FPN Drag Started.");
        return onDragStarted(event);
      case DragEvent.ACTION_DRAG_ENTERED:
        Log.i(TAG, "FPN Drag entered.");
        return onDragEntered(event);
      case DragEvent.ACTION_DRAG_LOCATION:
        Log.i(TAG, "FPN Drag location absolute, x: " + event.getX() + " y: " + event.getY());
        return onDragMoveOn(event);
      case DragEvent.ACTION_DRAG_EXITED:
        Log.i(TAG, "FPN Drag exited.");
        return onDragExited(event);
      case DragEvent.ACTION_DROP:
        Log.i(TAG, "FPN Drag droped.");
        return onDrop(event);
      case DragEvent.ACTION_DRAG_ENDED:
        Log.i(TAG, "FPN Drag ended.");
        return onDragEnded(event);
    }

    return super.onDragEvent(event);
  }
  private boolean findAppropriateDropHandle(DragEvent event) {
    Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:" + mLocationOnScreen[1]);
    mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX());
    mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY());
    Log.i(
        TAG,
        "FPN Drag location relative, x: "
            + mDragLocationOnScreen[0]
            + " y: "
            + mDragLocationOnScreen[1]);

    if (mCurrentDropHandleView != null) {
      ((DropAcceptable) mCurrentDropHandleView).onDrop(event);
      mCurrentDropHandleView = null;
      return true;
    } else {
      return false;
    }
  }
Example #3
0
    @Override
    public boolean onDrag(View viewTarget, DragEvent event) {
      switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          break;

        case DragEvent.ACTION_DRAG_ENTERED:
          viewTarget.setBackgroundResource(R.drawable.shape_droptarget);
          break;

        case DragEvent.ACTION_DRAG_EXITED:
          viewTarget.setBackgroundResource(R.drawable.shape);
          break;

        case DragEvent.ACTION_DRAG_LOCATION:
          Display display = getWindowManager().getDefaultDisplay();
          Point displaySize = new Point();
          display.getSize(displaySize);
          int displayMaxY = displaySize.y;

          Rect rect = new Rect();
          viewTarget.getGlobalVisibleRect(rect);
          Point touchPosition =
              new Point(rect.left + Math.round(event.getX()), rect.top + Math.round(event.getY()));

          int scrollTopThreshold =
              displayMaxY / 5 + mActionBar.getHeight() + statusBarBackground.getHeight();
          int scrollBottomThreshold = displayMaxY - (displayMaxY / 5);

          if (touchPosition.y < scrollTopThreshold) scrollView.smoothScrollBy(0, -15);
          if (touchPosition.y > scrollBottomThreshold) scrollView.smoothScrollBy(0, 15);
          break;

        case DragEvent.ACTION_DROP:
          View draggedView = (View) event.getLocalState();
          View currentView = ((LinearLayout) viewTarget).getChildAt(0);

          if (draggedView != null) {
            ViewGroup owner = (ViewGroup) draggedView.getParent();
            LinearLayout container = (LinearLayout) viewTarget;

            owner.removeView(draggedView);
            container.addView(draggedView);

            container.removeView(currentView);
            owner.addView(currentView);

            draggedView.setVisibility(View.VISIBLE);
          }
          break;

        case DragEvent.ACTION_DRAG_ENDED:
          isDragging = false;
          viewTarget.setBackgroundResource(R.drawable.shape);
          View draggedView2 = (View) event.getLocalState();
          if (draggedView2 != null) draggedView2.setVisibility(View.VISIBLE);
          break;

        default:
          break;
      }
      return true;
    }
  private boolean findAppropriateDragMoveHandle(DragEvent event) {
    Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:" + mLocationOnScreen[1]);
    mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX());
    mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY());
    Log.i(
        TAG,
        "FPN Drag location relative, x: "
            + mDragLocationOnScreen[0]
            + " y: "
            + mDragLocationOnScreen[1]);

    boolean moveOnHandleView;
    if (mCurrentDropHandleView != null) {
      Log.i(TAG, "There is drop handle view, test it!");
      // Test if still move on the drop handle view
      moveOnHandleView =
          ViewUtil.isViewContained(
              mCurrentDropHandleView, mDragLocationOnScreen[0], mDragLocationOnScreen[1]);

      if (!moveOnHandleView) {
        // Exit
        ((DropAcceptable) mCurrentDropHandleView).onDragExited(event);
        mCurrentDropHandleView = null;
        return false;
      } else {
        return true;
      }
    } else {
      // Test if there is a new view become drop handle
      boolean foundNewDropHandle = false;
      for (int i = 0; i < mNavigatorContainer.getChildCount(); i++) {
        View view = mNavigatorContainer.getChildAt(i);

        moveOnHandleView =
            ViewUtil.isViewContained(view, mDragLocationOnScreen[0], mDragLocationOnScreen[1]);
        if (moveOnHandleView) {
          Log.i(
              TAG,
              "Drag enter child view: "
                  + i
                  + " class: "
                  + view.getClass().getSimpleName()
                  + " l: "
                  + view.getLeft()
                  + " width: "
                  + view.getWidth()
                  + " t: "
                  + view.getTop()
                  + " height: "
                  + view.getHeight()
                  + " r: "
                  + view.getRight()
                  + " b: "
                  + view.getBottom());
          if (view instanceof DropAcceptable) {
            mCurrentDropHandleView = view;
            foundNewDropHandle = true;
            ((DropAcceptable) mCurrentDropHandleView).onDragEntered(event);
          }

          if (foundNewDropHandle) {
            Log.i(TAG, "Find new drop handle view!");
            return true;
          } else {
            Log.i(TAG, "Not find new drop handle view yet!");
          }
        }
      }

      return false;
    }
  }
Example #5
0
    /** OnDrag event actions */
    @Override
    public boolean onDrag(View v, DragEvent event) {
      switch (event.getAction()) {
        case DragEvent.ACTION_DRAG_STARTED:
          break;
        case DragEvent.ACTION_DRAG_ENTERED:
          break;
        case DragEvent.ACTION_DRAG_EXITED:
          break;
        case DragEvent.ACTION_DROP:
          View vTmp = (View) event.getLocalState();
          if (vTmp instanceof CardView) {
            CardView view = (CardView) vTmp;
            ViewGroup parent = (ViewGroup) (view.getParent());
            parent.removeViewInLayout(view);
            addView(view);
            if (parent instanceof HandView) {
              CardView card = (CardView) view;
              card.setOnDragListener(null);
              Gallery g2 =
                  (Gallery)
                      GameActivity.getActivity()
                          .findViewById(R.id.playerview_slider_board_cardgallery);
              if (g2 != null) {
                SliderbarCardGallery a2 = (SliderbarCardGallery) g2.getAdapter();
                a2.notifyDataSetChanged();
              }
            } else if (parent instanceof BoardView) {
              // Cards grouped moving
              if (cardsGroup.getTouching().size() > 1)
                cardsGroup.move(event.getX(), event.getY(), getWidth(), getHeight());
            }
            MarginLayoutParams marginParams = new MarginLayoutParams(view.getLayoutParams());
            int left = (int) (event.getX() - (view.getWidth() / 2));
            int top = (int) (event.getY() - (view.getHeight() / 2));
            int right = (int) (((View) view.getParent()).getWidth() - left + view.getWidth());
            int bottom = (int) (((View) view.getParent()).getHeight() - top + view.getHeight());
            marginParams.setMargins(left, top, right, bottom);
            view.setLayoutParams(new RelativeLayout.LayoutParams(marginParams));

            if (parent instanceof HandView) {
              Log.i(WifiDirectProperty.TAG, "1");
              MoveCardAction movecard =
                  new MoveCardAction("Player", GA.user.getId(), view.getCard(), "BoardView");
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));

            } else if (parent instanceof DrawPileView) {
              MoveCardAction movecard =
                  new MoveCardAction("DrawPileView", "BoardView", view.getCard());
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));
            } else if (parent instanceof DiscardPileView) {
              MoveCardAction movecard =
                  new MoveCardAction("DiscardPileView", "BoardView", view.getCard());
              movecard.setPourcentageX(left * 100 / ((View) view.getParent()).getWidth());
              movecard.setPourcentageY(top * 100 / ((View) view.getParent()).getHeight());
              Log.i(
                  WifiDirectProperty.TAG,
                  movecard.getPourcentageX() + " " + movecard.getPourcentageY());
              GameActivity.getActivity()
                  .getWifiDirectManager()
                  .sendEvent(new WifiDirectEventImpl(WifiDirectEvent.EVENT, movecard));
            }
            View tmp;
            for (int i = 0; i < getChildCount(); i++) {
              tmp = getChildAt(i);
              if (tmp instanceof CardView) tmp.setVisibility(View.VISIBLE);
            }
            vTmp.setVisibility(View.VISIBLE);
          } else {
            vTmp.setVisibility(View.VISIBLE);
          }
          cardsGroup.getTouching().clear();
          break;
        case DragEvent.ACTION_DRAG_ENDED:
          break;
        default:
          break;
      }
      return true;
    }