예제 #1
0
    private static void destroyResources(View view) {
      view.destroyHardwareResources();

      if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;

        int count = group.getChildCount();
        for (int i = 0; i < count; i++) {
          destroyResources(group.getChildAt(i));
        }
      }
    }
예제 #2
0
  /**
   * Tests scrollability within child views of v given a delta of dx.
   *
   * @param v View to test for horizontal scrollability
   * @param checkV Whether the view v passed should itself be checked for scrollability (true), or
   *     just its children (false).
   * @param dx Delta scrolled in pixels
   * @param x X coordinate of the active touch point
   * @param y Y coordinate of the active touch point
   * @return true if child views of v can be scrolled by delta of dx.
   */
  protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
      final ViewGroup group = (ViewGroup) v;
      final int scrollX = v.getScrollX();
      final int scrollY = v.getScrollY();
      final int count = group.getChildCount();
      // Count backwards - let topmost views consume scroll distance first.
      for (int i = count - 1; i >= 0; i--) {
        final View child = group.getChildAt(i);
        if (x + scrollX >= child.getLeft()
            && x + scrollX < child.getRight()
            && y + scrollY >= child.getTop()
            && y + scrollY < child.getBottom()
            && canScroll(
                child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) {
          return true;
        }
      }
    }

    return checkV && ViewCompat.canScrollHorizontally(v, -dx);
  }
예제 #3
0
  @SuppressLint("ResourceAsColor")
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
  @Override
  public boolean onTouch(final View view, MotionEvent event) {
    if (mViewWidth < 2) {
      mViewWidth = mListView.getWidth();
      smallWidth = mViewWidth / 7;
      textwidth2 = mViewWidth / 3;
      textwidth = textwidth2;
      //            原版
      //            largewidth	=	textwidth+textwidth2;
      //           自己修改
      largewidth = textwidth;
    }

    int tempwidth = 0;
    if (SwipeType == 1) tempwidth = smallWidth;
    else tempwidth = textwidth2 / 2;

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (mPaused) {
            return false;
          }
          Rect rect = new Rect();
          int childCount = mListView.getChildCount();
          int[] listViewCoords = new int[2];
          mListView.getLocationOnScreen(listViewCoords);
          int x = (int) event.getRawX() - listViewCoords[0];
          int y = (int) event.getRawY() - listViewCoords[1];
          ViewGroup child;
          for (int i = 0; i < childCount; i++) {
            child = (ViewGroup) mListView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
              mDownView_parent = child;
              mDownView = (ViewGroup) child.findViewById(R.id.list_display_view_container);
              if (mDownView_parent.getChildCount() == 1) {
                textheight = mDownView_parent.getHeight();
                if (SwipeType == Dismiss) {
                  HalfColor = singleColor;
                  //                                HalfDrawable	=
                  //	activity.getResources().getDrawable(R.drawable.content_discard);
                }
                SetBackGroundforList();
              }

              if (old_mDownView != null && mDownView != old_mDownView) {
                ResetListItem(old_mDownView);
                old_mDownView = null;
                return false;
              }
              break;
            }
          }

          if (mDownView != null) {
            mDownX = event.getRawX();
            mDownY = event.getRawY();
            mDownPosition = mListView.getPositionForView(mDownView);
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(event);
          } else {
            mDownView = null;
          }

          // mSwipeDetected              =   false;
          temp_position = mListView.pointToPosition((int) event.getX(), (int) event.getY());
          view.onTouchEvent(event);
          return true;
        }

      case MotionEvent.ACTION_UP:
        {
          if (mVelocityTracker == null) {
            break;
          }
          float deltaX = event.getRawX() - mDownX;
          // 在OnItemClick事件中判断如果Deltax!=0则表示不是点击事件
          DeltaX = deltaX;
          mVelocityTracker.addMovement(event);
          mVelocityTracker.computeCurrentVelocity(1000); // 1000 by defaut but
          float velocityX = mVelocityTracker.getXVelocity(); // it was too much
          float absVelocityX = Math.abs(velocityX);
          float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
          boolean swipe = false;
          boolean swipeRight = false;

          if (Math.abs(deltaX) > tempwidth) {
            swipe = true;
            swipeRight = deltaX > 0;

          } else if (mMinFlingVelocity <= absVelocityX
              && absVelocityX <= mMaxFlingVelocity
              && absVelocityY < absVelocityX) {
            // dismiss only if flinging in the same direction as dragging
            swipe = (velocityX < 0) == (deltaX < 0);
            swipeRight = mVelocityTracker.getXVelocity() > 0;
          }
          if (deltaX < 0 && swipe) {
            mListView.setDrawSelectorOnTop(false);
            // && Math.abs(DeltaY)<30
            if (swipe && !swipeRight && deltaX <= -tempwidth && Math.abs(DeltaY) < 100) {
              FullSwipeTrigger();
            } else if (deltaX >= -textwidth && SwipeType == Double) {
              ResetListItem(mDownView);
            } else {
              ResetListItem(mDownView);
            }
          } else if (deltaX != 0) {
            ResetListItem(mDownView);
          }

          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          break;
        }

        // 根据手势滑动方向滑出滑入

      case MotionEvent.ACTION_MOVE:
        {
          float deltaX = event.getRawX() - mDownX;
          float deltaY = event.getRawY() - mDownY;
          DeltaY = deltaY;
          if (mVelocityTracker == null || mPaused || deltaX > 0) {
            break;
          }

          mVelocityTracker.addMovement(event);

          // && Math.abs(deltaY)<30
          if (Math.abs(deltaX) > (mSlop * 5) && Math.abs(deltaY) < 50) {
            mSwiping = true;
            mListView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(event);
            cancelEvent.setAction(
                MotionEvent.ACTION_CANCEL
                    | (event.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mListView.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
          } else if (Math.abs(deltaY) > 50) {
            mSwiping = false;
            //                     ResetListItem(mDownView);
          }
          System.out.println(
              "<<<<<<<<<" + deltaY + "<<<<<<" + deltaX + "<<<<" + mSwiping + "<<<<<" + mSlop * 10);
          if (mSwiping && deltaX < 0) {
            int width;
            //                     if(SwipeType==1){
            width = textwidth2;
            //                     }
            //                     else{
            //                         width	=	largewidth;
            //                     }

            if (-deltaX < width) {

              mDownView.setTranslationX(deltaX);
              return false;
            }
            return false;
          } else if (mSwiping) {
            ResetListItem(mDownView);
          }
          break;
        }
    }
    return false;
  }