コード例 #1
0
  @Override
  public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) {
    childView = view.findChildViewUnder(event.getX(), event.getY());
    childViewPosition = view.getChildPosition(childView);

    return childView != null && gestureDetector.onTouchEvent(event);
  }
コード例 #2
0
 @Override
 public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
     View childView = view.findChildViewUnder(e.getX(), e.getY());
     if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
         mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
     }
     return false;
 }
コード例 #3
0
 @Override
 public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
   View child = rv.findChildViewUnder(e.getX(), e.getY());
   if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
     clickListener.onClick(child, rv.getChildLayoutPosition(child));
   }
   return false;
 }
コード例 #4
0
 @Override
 public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent event) {
   View child = rv.findChildViewUnder(event.getX(), event.getY());
   if (null != child && null != clickListener && gestureDetector.onTouchEvent(event)) {
     child.onTouchEvent(event);
     clickListener.onClick(child, rv.getChildPosition(child));
   }
   return false;
 }
コード例 #5
0
    @Override
    public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

      View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
      if (child != null && clickListener != null && gestureDetector.onTouchEvent(motionEvent)) {
        clickListener.onClick(child, recyclerView.getChildPosition(child));
      }
      return false;
    }
コード例 #6
0
 @Override
 public boolean onInterceptTouchEvent(android.support.v7.widget.RecyclerView rv, MotionEvent e) {
   View child = rv.findChildViewUnder(e.getX(), e.getY());
   RecyclerView.ViewHolder finalChild =
       rv.findViewHolderForAdapterPosition(rv.getChildAdapterPosition(child));
   if (child != null && clickListener != null && gestureDetector.onTouchEvent(e) == true) {
     clickListener.onClick(finalChild, rv.getChildPosition(child));
   }
   return false;
 }
コード例 #7
0
 @Override
 public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
   View childView = view.findChildViewUnder(e.getX(), e.getY());
   if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
     mListener.onItemClick(
         childView,
         Long.parseLong(childView.getTag().toString()),
         view.getChildPosition(childView));
     return true;
   }
   return false;
 }
コード例 #8
0
 /**
  * onInterceptTouchEvent Method that intercepts the touch event so we can detect the click on a
  * property item in the Recycler view
  *
  * @param view
  * @param e
  * @return
  */
 @Override
 public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
   View childView =
       view.findChildViewUnder(e.getX(), e.getY()); // Reference the childView of the touch event
   if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
     mListener.onItemClick(
         childView,
         view.getChildAdapterPosition(childView)); // Send the data via the listener interface
     return true;
   }
   return false;
 }
コード例 #9
0
  @Override
  public boolean onTouch(View v, MotionEvent event) {

    // Still need to pass motion event to list view to keep scroll behavior.
    v.onTouchEvent(event);

    float x = event.getRawX();
    float y = event.getRawY();

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mDownView = mRecyclerView.findChildViewUnder(event.getX(), event.getY());
        Log.d(TAG, "Down position = " + mRecyclerView.getChildAdapterPosition(mDownView));
        if (mDownView == null || mRecyclerView.getChildAdapterPosition(mDownView) == 0) break;

        mIsTouched = true;
        mTouchDownX = x;
        mTouchDownY = y;

        break;

      case MotionEvent.ACTION_MOVE:
        float deltaX = Math.abs(x - mTouchDownX);
        float deltaY = Math.abs(y - mTouchDownY);

        if (mDownView == null || deltaX == 0F || deltaY == 0F) break;

        double deltaZ = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
        int theta = Math.round((float) (Math.asin(deltaY / deltaZ) / Math.PI * 180));

        if (!mIsTouched || mIsDragging || x < mTouchDownX || theta > THRESHOLD_DRAG_THETA) {
          break;
        }

        startDragTaskItem();

        break;

      case MotionEvent.ACTION_UP:
        if (mDownView == null) break;
        resetTaskItemTouch();

        break;

      case MotionEvent.ACTION_CANCEL:
        if (mDownView == null) break;
        resetTaskItemTouch();

        break;
    }

    return true;
  }
コード例 #10
0
ファイル: RecyclerListener.java プロジェクト: Rednjak/Android
  // To detect an event and return a response if a condition is met
  @Override
  public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

    View childView = rv.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && listener != null && gestureDetector.onTouchEvent(e)) {
      listener.onItemClick(
          childView,
          rv.getChildAdapterPosition(
              childView)); // Send data to activity. We send position of the element
      return true;
    }
    return false;
  }
コード例 #11
0
  @Override
  public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    int position = view.getChildAdapterPosition(childView);
    if (childView != null) {
      // Check Preferences
      SharedPreferences sharedPref =
          PreferenceManager.getDefaultSharedPreferences(view.getContext());
      int browseType = Integer.parseInt(sharedPref.getString("pref_browseType", "0"));

      Intent intent = new Intent(view.getContext(), DisplayCardActivity.class);
      Bundle extras = ((Activity) context).getIntent().getExtras();
      ArrayList<String> tagsList = new ArrayList<>();

      intent.putStringArrayListExtra("TAGS", tagsList);
      view.getContext().startActivity(intent);
    }
    return false;
  }
コード例 #12
0
  /*
   *  Detects touch/motion event and fires click listener if onSingleTapUp return true.
   */
  @Override
  public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent event) {

    /*
     *  We get the recycler item view on that position because we can't get the view by the index position
     *  due to the logic of the recycler view... because it recycles views...
     */
    View item = view.findChildViewUnder(event.getX(), event.getY());
    int res = this.getResult(event);
    if (item != null && res != PairedDeviceItemClickListener.GESTURE_NONE) {

      /*
       *  We handle each event.
       */
      if (res == PairedDeviceItemClickListener.GESTURE_TAP_UP) {
        this.listener.onItemClick(item, view.getChildPosition(item));
      } else if (res == PairedDeviceItemClickListener.GESTURE_LONG_PRESS) {
        this.listener.onItemLongClick(item, view.getChildPosition(item));
      }
    }
    return false;
  }
コード例 #13
0
  @SuppressWarnings("SameReturnValue")
  private boolean down(MotionEvent motionEvent) {
    if (mPaused) {
      return false;
    }

    mDownX = motionEvent.getRawX();
    mDownY = motionEvent.getRawY();
    mSwipeView = mRecyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
    if (mSwipeView == null) {
      return false;
    }
    int pos = mRecyclerView.getChildAdapterPosition(mSwipeView);
    mAllowedSwipeDirection = mCallbacks.canDismiss(pos);
    if (mAllowedSwipeDirection != SwipeDirection.NONE) {

      mVelocityTracker = VelocityTracker.obtain();
      mVelocityTracker.addMovement(motionEvent);
      return false;
    }
    resetMotion();
    return false;
  }
コード例 #14
0
ファイル: DragSortRecycler.java プロジェクト: jsveiga/Slide
  @Override
  public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onInterceptTouchEvent");

    // if (e.getAction() == MotionEvent.ACTION_DOWN)
    {
      View itemView = rv.findChildViewUnder(e.getX(), e.getY());

      if (itemView == null) return false;

      boolean dragging = false;

      if ((dragHandleWidth > 0) && (e.getX() < dragHandleWidth)) {
        dragging = true;
      } else if (viewHandleId != -1) {
        // Find the handle in the list item
        View handleView = itemView.findViewById(viewHandleId);

        if (handleView == null) {
          Log.e(TAG, "The view ID " + viewHandleId + " was not found in the RecycleView item");
          return false;
        }

        // View should be visible to drag
        if (handleView.getVisibility() != View.VISIBLE) {
          return false;
        }

        // We need to find the relative position of the handle to the parent view
        // Then we can work out if the touch is within the handle
        int[] parentItemPos = new int[2];
        itemView.getLocationInWindow(parentItemPos);

        int[] handlePos = new int[2];
        handleView.getLocationInWindow(handlePos);

        int xRel = handlePos[0] - parentItemPos[0];
        int yRel = handlePos[1] - parentItemPos[1];

        Rect touchBounds =
            new Rect(
                itemView.getLeft() + xRel,
                itemView.getTop() + yRel,
                itemView.getLeft() + xRel + handleView.getWidth(),
                itemView.getTop() + yRel + handleView.getHeight());

        if (touchBounds.contains((int) e.getX(), (int) e.getY())) dragging = true;

        debugLog("parentItemPos = " + parentItemPos[0] + " " + parentItemPos[1]);
        debugLog("handlePos = " + handlePos[0] + " " + handlePos[1]);
      }

      if (dragging) {
        debugLog("Started Drag");

        setIsDragging(true);

        floatingItem = createFloatingBitmap(itemView);

        fingerAnchorY = (int) e.getY();
        fingerOffsetInViewY = fingerAnchorY - itemView.getTop();
        fingerY = fingerAnchorY;

        selectedDragItemPos = rv.getChildPosition(itemView);
        debugLog("selectedDragItemPos = " + selectedDragItemPos);

        return true;
      }
    }
    return false;
  }
コード例 #15
0
 public int getChildItemPosition(float x, float y) {
   View child = recyclerView2.findChildViewUnder(x, y);
   if (child != null) return recyclerView2.getChildAdapterPosition(child);
   return -1;
 }