public void onDragOver(DragObject d) {
    final DragView dragView = d.dragView;
    final int scrollOffset = mScrollView.getScrollY();
    final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
    r[0] -= getPaddingLeft();
    r[1] -= getPaddingTop();

    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent translatedEv =
        MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);

    if (!mAutoScrollHelper.isEnabled()) {
      mAutoScrollHelper.setEnabled(true);
    }

    final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
    translatedEv.recycle();

    if (handled) {
      mReorderAlarm.cancelAlarm();
    } else {
      mTargetCell =
          mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
      if (isLayoutRtl()) {
        mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
      }
      if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
        mReorderAlarm.cancelAlarm();
        mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
        mReorderAlarm.setAlarm(REORDER_DELAY);
        mPreviousTargetCell[0] = mTargetCell[0];
        mPreviousTargetCell[1] = mTargetCell[1];
      }
    }
  }
Exemple #2
0
  /*
   * 拖动结束
   */
  public void onDragOver(DragObject d) {
    float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView, null);
    mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1], 1, 1, mTargetCell);

    if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
      mReorderAlarm.cancelAlarm();
      mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
      mReorderAlarm.setAlarm(150);
      mPreviousTargetCell[0] = mTargetCell[0];
      mPreviousTargetCell[1] = mTargetCell[1];
    }
  }
Exemple #3
0
  // On touch Event.
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    final int iAction = event.getAction();
    final int iCurrentx = (int) event.getX();
    final int iCurrenty = (int) event.getY();
    switch (iAction) {
      case MotionEvent.ACTION_DOWN:
        Log.e(TAG, "ACTION_DOWN");
        mState = STATE_MOVE;
        mPreviousx = iCurrentx;
        mPreviousy = iCurrenty;
        mPreviousBox = viewBox.whichBox(this);
        Main.boxList[mPreviousBox] = false;
        break;
      case MotionEvent.ACTION_MOVE:
        Log.e(TAG, "ACTION_MOVE");
        mState = STATE_MOVE;
        int iDeltx = iCurrentx - mPreviousx;
        int iDelty = iCurrenty - mPreviousy;
        final int iLeft = getLeft();
        final int iTop = getTop();
        layout(
            iLeft + iDeltx,
            iTop + iDelty,
            iLeft + iDeltx + getWidth(),
            iTop + iDelty + getHeight());

        //			dragController.startDrag(this);
        mPreviousx = iCurrentx - iDeltx;
        mPreviousy = iCurrenty - iDelty;
        break;
      case MotionEvent.ACTION_UP:
        Log.e(TAG, "ACTION_UP");

        int iDeltx1 = iCurrentx - mPreviousx;
        int iDelty1 = iCurrenty - mPreviousy;
        mCurBox = viewBox.whichBox(this);
        final int iLeft1 = viewBox.getLeft(mCurBox);
        final int iTop1 = viewBox.getTop(mCurBox);
        layout(
            iLeft1 + iDeltx1,
            iTop1 + iDelty1,
            iLeft1 + iDeltx1 + getWidth(),
            iTop1 + iDelty1 + getHeight());

        mCellLayout.findNearestArea(160, 160, 1, 1, null);
        mCellLayout.findNearestArea(200, 200, 1, 1, null);
        mCellLayout.findNearestArea(160, 160, 2, 1, null);

        mPreviousx = iCurrentx - iDeltx1;
        mPreviousy = iCurrenty - iDelty1;
        Main.boxList[mCurBox] = true;
        mState = STATE_STOP;
        break;
      case MotionEvent.ACTION_CANCEL:
        Log.e(TAG, "ACTION_CANCEL");
        mState = STATE_STOP;
        break;
    }
    return true;
  }