Esempio n. 1
0
 private void onDrag(int x, int y) {
   if (dragImageView != null) {
     windowParams.alpha = 0.8f;
     windowParams.x = (x - mLastX - xtox) + dragItemView.getLeft() + 8;
     windowParams.y =
         (y - mLastY - ytoy) + dragItemView.getTop() + (int) (45 * Configure.screenDensity);
     windowManager.updateViewLayout(dragImageView, windowParams);
   }
 }
Esempio n. 2
0
  public boolean isInContentArea(int x, int y) {
    mContentArea.left = mContentFrame.getLeft() + mContentFrame.getPaddingLeft();
    mContentArea.top =
        mContentFrame.getTop()
            + mContentFrame.getPaddingTop()
            + (int) mContentParent.getTranslationY(); // account for any adjustment
    mContentArea.right = mContentFrame.getRight() - mContentFrame.getPaddingRight();
    mContentArea.bottom = mContentFrame.getBottom() - mContentFrame.getPaddingBottom();

    offsetDescendantRectToMyCoords(mContentParent, mContentArea);
    return mContentArea.contains(x, y);
  }
  private Rect getChildViewRect(View parentView, View childView) {
    final Rect childRect =
        new Rect(
            childView.getLeft(), childView.getTop(), childView.getRight(), childView.getBottom());
    if (parentView == childView) {
      return childRect;
    }

    ViewGroup parent;
    while ((parent = (ViewGroup) childView.getParent()) != parentView) {
      childRect.offset(parent.getLeft(), parent.getTop());
      childView = parent;
    }

    return childRect;
  }
Esempio n. 4
0
  private void startDrag(Bitmap bm, int x, int y) {
    stopDrag();
    windowParams = new WindowManager.LayoutParams();
    windowParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowParams.x = dragItemView.getLeft() + 8;
    windowParams.y = dragItemView.getTop() + (int) (45 * Configure.screenDensity);
    windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    windowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    windowParams.alpha = 0.8f;

    ImageView iv = new ImageView(getContext());
    iv.setImageBitmap(bm);
    windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    windowManager.addView(iv, windowParams);

    dragImageView = iv;
  }
Esempio n. 5
0
 @Override
 public boolean onDoubleTap(MotionEvent e) {
   if (mDoubleClickListener != null) {
     View target;
     ViewGroup bottom = getBottomView();
     ViewGroup surface = getSurfaceView();
     if (e.getX() > bottom.getLeft()
         && e.getX() < bottom.getRight()
         && e.getY() > bottom.getTop()
         && e.getY() < bottom.getBottom()) {
       target = bottom;
     } else {
       target = surface;
     }
     mDoubleClickListener.onDoubleClick(SwipeLayout.this, target == surface);
   }
   return true;
 }
Esempio n. 6
0
 /**
  * close surface
  *
  * @param smooth smoothly or not.
  * @param notify if notify all the listeners.
  */
 public void close(boolean smooth, boolean notify) {
   ViewGroup surface = getSurfaceView();
   int dx, dy;
   if (smooth) mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
   else {
     Rect rect = computeSurfaceLayoutArea(false);
     dx = rect.left - surface.getLeft();
     dy = rect.top - surface.getTop();
     surface.layout(rect.left, rect.top, rect.right, rect.bottom);
     if (notify) {
       dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
       dispatchSwipeEvent(rect.left, rect.top, dx, dy);
     } else {
       safeBottomView();
     }
   }
   invalidate();
 }
Esempio n. 7
0
 public void open(boolean smooth, boolean notify) {
   ViewGroup surface = getSurfaceView(), bottom = getBottomView();
   int dx, dy;
   Rect rect = computeSurfaceLayoutArea(true);
   if (smooth) {
     mDragHelper.smoothSlideViewTo(getSurfaceView(), rect.left, rect.top);
   } else {
     dx = rect.left - surface.getLeft();
     dy = rect.top - surface.getTop();
     surface.layout(rect.left, rect.top, rect.right, rect.bottom);
     if (getShowMode() == ShowMode.PullOut) {
       Rect bRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, rect);
       bottom.layout(bRect.left, bRect.top, bRect.right, bRect.bottom);
     }
     if (notify) {
       dispatchRevealEvent(rect.left, rect.top, rect.right, rect.bottom);
       dispatchSwipeEvent(rect.left, rect.top, dx, dy);
     } else {
       safeBottomView();
     }
   }
   invalidate();
 }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    Rect windowRect = new Rect();
    mDecorView.getWindowVisibleDisplayFrame(windowRect);

    if (mSlideTarget == SLIDE_TARGET_WINDOW) {
      mDrawerContent.layout(left, top + windowRect.top, right, bottom);
      mDecorContent.layout(
          mDecorContent.getLeft(), mDecorContent.getTop(), mDecorContent.getLeft() + right, bottom);
    } else {
      mDrawerContent.layout(left, 0, right, bottom);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mDecorContent.layout(mDecorContent.getLeft(), 0, mDecorContent.getLeft() + right, bottom);
      } else {
        mDecorContent.layout(mDecorContent.getLeft(), top, mDecorContent.getLeft() + right, bottom);
      }
    }

    mDrawerWidth = mDrawerContent.getMeasuredWidth();
    if (mDrawerWidth > right - mTouchTargetWidth) {
      mDrawerContent.setPadding(0, 0, mTouchTargetWidth, 0);
      mDrawerWidth -= mTouchTargetWidth;
    }
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    final ViewConfiguration vc = ViewConfiguration.get(getContext());
    final int widthPixels = getResources().getDisplayMetrics().widthPixels;

    final int deltaX = (int) (event.getX() + 0.5f) - mGestureCurrentX;
    final int deltaY = (int) (event.getY() + 0.5f) - mGestureCurrentY;

    /*
     * Obtain a new VelocityTracker if we don't already have one. Also add this MotionEvent
     * to the new/existing VelocityTracker so we can determine flings later on.
     */
    if (mVelocityTracker == null) {
      mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);

    /*
     * Update the current X and Y positions for the ongoing gesture.
     */
    mGestureCurrentX = (int) (event.getX() + 0.5f);
    mGestureCurrentY = (int) (event.getY() + 0.5f);

    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        mDrawerMoving = true;

        if (mDecorOffsetX + deltaX > mDrawerWidth) {
          if (mDecorOffsetX != mDrawerWidth) {
            mDrawerOpened = true;
            mDecorContent.offsetLeftAndRight(mDrawerWidth - mDecorOffsetX);
            mDecorOffsetX = mDrawerWidth;
            invalidate();
          }
        } else if (mDecorOffsetX + deltaX < 0) {
          if (mDecorOffsetX != 0) {
            mDrawerOpened = false;
            mDecorContent.offsetLeftAndRight(0 - mDecorContent.getLeft());
            mDecorOffsetX = 0;
            invalidate();
          }
        } else {
          mDecorContent.offsetLeftAndRight(deltaX);
          mDecorOffsetX += deltaX;
          invalidate();
        }

        return true;
      case MotionEvent.ACTION_UP:
        mGestureStarted = false;
        mDrawerMoving = false;

        /*
         * Determine if the user performed a fling based on the final velocity of the
         * gesture.
         */
        mVelocityTracker.computeCurrentVelocity(1000);
        if (Math.abs(mVelocityTracker.getXVelocity()) > vc.getScaledMinimumFlingVelocity()) {
          /*
           * Okay, the user did a fling, so determine the direction in which
           * the fling was flung so we know which way to toggle the drawer state.
           */
          if (mVelocityTracker.getXVelocity() > 0) {
            mDrawerOpened = false;
            openDrawer();
          } else {
            mDrawerOpened = true;
            closeDrawer();
          }
        } else {
          /*
           * No sizable fling has been flung, so fling the drawer towards whichever side
           * we're closest to being flung at.
           */
          if (mDecorOffsetX > (widthPixels / 2.0)) {
            mDrawerOpened = false;
            openDrawer();
          } else {
            mDrawerOpened = true;
            closeDrawer();
          }
        }
        return true;
    }
    return false;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mRemoveListener != null && mGestureDetector == null) {
      if (mRemoveMode == FLING) {
        mGestureDetector =
            new GestureDetector(
                getContext(),
                new SimpleOnGestureListener() {
                  @Override
                  public boolean onFling(
                      MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    if (mFloatView != null) {
                      if (velocityX > 1000) {
                        Rect r = mTempRect;
                        mFloatView.getDrawingRect(r);
                        if (e2.getX() > r.right * 2 / 3) {
                          // fast fling right with release near the
                          // right edge of the screen
                          dropFloatView(true);
                        }
                      }
                      // flinging while dragging should have no effect
                      // i.e. the gesture should not pass on to other
                      // onTouch handlers. Gobble...
                      return true;
                    }
                    return false;
                  }
                });
      }
    }
    if (mDragListener != null || mDropListener != null) {
      switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
          // Log.d("mobeta", "action down!");
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          mLastX = x;
          mLastY = y;
          mDownY = y;
          int itemnum = pointToPosition(x, y); // includes
          // headers/footers

          final int numHeaders = getHeaderViewsCount();
          final int numFooters = getFooterViewsCount();

          // Log.d("mobeta", "touch down on position " + itemnum);
          if (itemnum == AdapterView.INVALID_POSITION
              || itemnum < numHeaders
              || itemnum >= getCount() - numFooters) {
            break;
          }
          ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());

          mDragPointX = x - item.getLeft();
          mDragPointY = y - item.getTop();
          final int rawX = (int) ev.getRawX();
          final int rawY = (int) ev.getRawY();
          mXOffset = rawX - x;
          mYOffset = rawY - y;

          View dragBox = (View) item.getTag();
          boolean dragHit = false;
          if (dragBox != null) {
            dragBox.getLocationOnScreen(mTempLoc);

            dragHit =
                rawX > mTempLoc[0]
                    && rawY > mTempLoc[1]
                    && rawX < mTempLoc[0] + dragBox.getWidth()
                    && rawY < mTempLoc[1] + dragBox.getHeight();
          }

          if (dragHit) {
            // item.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
            item.setDrawingCacheEnabled(true);
            // Create a copy of the drawing cache so that it does
            // not get recycled
            // by the framework when the list tries to clean up
            // memory
            Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
            item.setDrawingCacheEnabled(false);

            mFloatViewHeight = item.getHeight();
            mFloatViewHeightHalf = mFloatViewHeight / 2;

            mExpDragPos = itemnum;
            mSrcDragPos = itemnum;

            // Log.d("mobeta", "getCount() = " + getCount());
            // Log.d("mobeta", "headers = " +
            // getHeaderViewsCount());

            startDragging(bitmap, x, y);

            // cancel ListView fling
            MotionEvent ev2 = MotionEvent.obtain(ev);
            ev2.setAction(MotionEvent.ACTION_CANCEL);
            super.onInterceptTouchEvent(ev2);

            // return false;
            return true;
          }
          removeFloatView();
          break;
      }
    }
    return super.onInterceptTouchEvent(ev);
  }