示例#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);
   }
 }
  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);
  }
  @Override
  protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    final ViewGroup row = (ViewGroup) getChildAt(1);
    int top = row.getTop();
    int bottom = getBottom();
    // Left side border.
    final int left = row.getChildAt(0).getLeft() + getLeft();
    canvas.drawLine(left + FLOAT_FUDGE, top, left + FLOAT_FUDGE, bottom, dividerPaint);

    // Each cell's right-side border.
    for (int c = 0; c < 7; c++) {
      float x = left + row.getChildAt(c).getRight() - FLOAT_FUDGE;
      canvas.drawLine(x, top, x, bottom, dividerPaint);
    }
  }
  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;
  }
示例#5
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;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mDragListener != null || mDropListener != null) {
      switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          int itemnum = pointToPosition(x, y);
          if (itemnum == AdapterView.INVALID_POSITION) {
            break;
          }
          ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
          mDragPoint = y - item.getTop();
          mCoordOffset = ((int) ev.getRawY()) - y;
          View dragger = item.findViewById(R.id.grabber);
          Rect r = mTempRect;
          dragger.getDrawingRect(r);
          // The dragger icon itself is quite small, so pretend the
          // touch area is bigger
          if (x < r.right * 2) {
            // Fix x position while dragging
            int[] itemPos = new int[2];
            item.getLocationOnScreen(itemPos);

            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());
            startDragging(bitmap, itemPos[0], y);
            mDragPos = itemnum;
            mFirstDragPos = mDragPos;
            mHeight = getHeight();
            int touchSlop = mTouchSlop;
            mUpperBound = Math.min(y - touchSlop, mHeight / 3);
            mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3);
            return false;
          }
          stopDragging();
          break;
      }
    }
    return super.onInterceptTouchEvent(ev);
  }
示例#7
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;
 }
示例#8
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();
 }
示例#9
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;
    }
  }
示例#11
0
  @Override
  public boolean onInterceptTouchEvent(final MotionEvent ev) {
    if (this.mRemoveListener != null && this.mGestureDetector == null) {
      if (this.mRemoveMode == FLING) {
        this.mGestureDetector =
            new GestureDetector(
                this.getContext(),
                new SimpleOnGestureListener() {
                  @Override
                  public boolean onFling(
                      final MotionEvent e1,
                      final MotionEvent e2,
                      final float velocityX,
                      final float velocityY) {
                    if (TouchListView.this.mDragView != null) {
                      if (velocityX > 1000) {
                        Rect r = TouchListView.this.mTempRect;
                        TouchListView.this.mDragView.getDrawingRect(r);
                        if (e2.getX() > r.right * 2 / 3) {
                          // fast fling right with release
                          // near the right edge of the screen
                          TouchListView.this.stopDragging();
                          TouchListView.this.mRemoveListener.remove(
                              TouchListView.this.mFirstDragPos);
                          TouchListView.this.unExpandViews(true);
                        }
                      }
                      // flinging while dragging should have no
                      // effect
                      return true;
                    }
                    return false;
                  }
                });
      }
    }
    if (this.mDragListener != null || this.mDropListener != null) {
      switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          int itemnum = this.pointToPosition(x, y);
          if (itemnum == AdapterView.INVALID_POSITION) {
            break;
          }
          ViewGroup item = (ViewGroup) this.getChildAt(itemnum - this.getFirstVisiblePosition());
          this.mDragPoint = y - item.getTop();
          this.mCoordOffset = ((int) ev.getRawY()) - y;
          View dragger = item.findViewById(this.grabberId);
          Rect r = this.mTempRect;
          // dragger.getDrawingRect(r);

          r.left = dragger.getLeft();
          r.right = dragger.getRight();
          r.top = dragger.getTop();
          r.bottom = dragger.getBottom();

          if ((r.left < x) && (x < r.right)) {
            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());
            this.startDragging(bitmap, y);
            this.mDragPos = itemnum;
            this.mFirstDragPos = this.mDragPos;
            this.mHeight = this.getHeight();
            int touchSlop = this.mTouchSlop;
            this.mUpperBound = Math.min(y - touchSlop, this.mHeight / 3);
            this.mLowerBound = Math.max(y + touchSlop, this.mHeight * 2 / 3);
            return false;
          }
          this.mDragView = null;
          break;
      }
    }
    return super.onInterceptTouchEvent(ev);
  }
示例#12
0
  @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 (mDragView != null) {
                      if (velocityX > 1000) {
                        Rect r = mTempRect;
                        mDragView.getDrawingRect(r);
                        if (e2.getX() > r.right * 2 / 3) {
                          // fast fling right with release near the right edge of the screen
                          stopDragging();
                          mRemoveListener.remove(mFirstDragPos);
                          unExpandViews(true);
                        }
                      }
                      // flinging while dragging should have no effect
                      return true;
                    }
                    return false;
                  }
                });
      }
    }
    if (mDragListener != null || mDropListener != null) {
      switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
          int x = (int) ev.getX();
          int y = (int) ev.getY();
          int itemnum = pointToPosition(x, y);
          if (itemnum == AdapterView.INVALID_POSITION) {
            break;
          }
          ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
          mDragPoint = y - item.getTop();
          mCoordOffset = ((int) ev.getRawY()) - y;

          // Get the dragger by using the hardcoded ID defined in the
          // library.
          View dragger = item.findViewById(R.id.list_grabber);

          Rect r = mTempRect;
          //									dragger.getDrawingRect(r);

          r.left = dragger.getLeft();
          r.right = dragger.getRight();
          r.top = dragger.getTop();
          r.bottom = dragger.getBottom();

          if ((r.left < x) && (x < r.right)) {
            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());
            startDragging(bitmap, y);
            mDragPos = itemnum;
            mFirstDragPos = mDragPos;
            mHeight = getHeight();
            int touchSlop = mTouchSlop;
            mUpperBound = Math.min(y - touchSlop, mHeight / 3);
            mLowerBound = Math.max(y + touchSlop, mHeight * 2 / 3);
            return false;
          }
          mDragView = null;
          break;
      }
    }
    return super.onInterceptTouchEvent(ev);
  }
  @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);
  }