public void reLayout(int which) { layout( viewBox.getLeft(which), viewBox.getTop(which), viewBox.getLeft(which) + getWidth(), viewBox.getTop(which) + getHeight()); }
// 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; }