@Override
  public boolean onTouchEvent(MotionEvent event) {
    // Call the superclass onTouchEvent first, because sometimes it changes the state to
    // isPressed() on an ACTION_UP
    boolean result = super.onTouchEvent(event);

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // So that the pressed outline is visible immediately on setStayPressed(),
        // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time
        // to create it)
        if (mPressedBackground == null) {
          mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
        }

        mLongPressHelper.postCheckForLongPress();
        break;
      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        // If we've touched down and up on an item, and it's still not "pressed", then
        // destroy the pressed outline
        if (!isPressed()) {
          mPressedBackground = null;
        }

        mLongPressHelper.cancelLongPress();
        break;
      case MotionEvent.ACTION_MOVE:
        if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) {
          mLongPressHelper.cancelLongPress();
        }
        break;
    }
    return result;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    // Widgets are disabled. This widget is a system one
    // do not check for longpress events and let the
    // touch events fall through to the children
    if (mWidgetsDisabled) {
      return false;
    }

    // Watch for longpress events at this level to make sure
    // users can always pick up this widget
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mLongPressHelper.postCheckForLongPress(ev);
        break;
      case MotionEvent.ACTION_MOVE:
        mLongPressHelper.onMove(ev);
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mLongPressHelper.cancelLongPress();
        break;
    }

    // Otherwise continue letting touch events fall through to children
    return false;
  }
 @Override
 public void onTouchComplete() {
   if (!mLongPressHelper.hasPerformedLongPress()) {
     // If a long press has been performed, we don't want to clear the record of that since
     // we still may be receiving a touch up which we want to intercept
     mLongPressHelper.cancelLongPress();
   }
 }
 public boolean onTouchEvent(MotionEvent ev) {
   // If the widget does not handle touch, then cancel
   // long press when we release the touch
   switch (ev.getAction()) {
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
       mLongPressHelper.cancelLongPress();
       break;
     case MotionEvent.ACTION_MOVE:
       if (!Utilities.pointInView(this, ev.getX(), ev.getY(), mSlop)) {
         mLongPressHelper.cancelLongPress();
       }
       break;
   }
   return false;
 }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // Call the superclass onTouchEvent first, because sometimes it changes the state to
    // isPressed() on an ACTION_UP
    boolean result = super.onTouchEvent(event);

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // So that the pressed outline is visible immediately when isPressed() is true,
        // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time
        // to create it)
        if (mPressedOrFocusedBackground == null) {
          mPressedOrFocusedBackground =
              createGlowingOutline(mTempCanvas, mPressedGlowColor, mPressedOutlineColor);
        }
        // Invalidate so the pressed state is visible, or set a flag so we know that we
        // have to call invalidate as soon as the state is "pressed"
        if (isPressed()) {
          mDidInvalidateForPressedState = true;
          setCellLayoutPressedOrFocusedIcon();
        } else {
          mDidInvalidateForPressedState = false;
        }

        mLongPressHelper.postCheckForLongPress();
        break;
      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        // If we've touched down and up on an item, and it's still not "pressed", then
        // destroy the pressed outline
        if (!isPressed()) {
          mPressedOrFocusedBackground = null;
        }

        mLongPressHelper.cancelLongPress();
        break;
    }
    return result;
  }
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    // Widgets are disabled. This widget is a system one
    // do not check for longpress events
    if (mWidgetsDisabled) {
      return true;
    }
    // Watch for longpress events at this level to make sure
    // users can always pick up this widget
    switch (ev.getAction()) {
      case MotionEvent.ACTION_MOVE:
        mLongPressHelper.onMove(ev);
        break;
      case MotionEvent.ACTION_POINTER_DOWN:
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mLongPressHelper.cancelLongPress();
        break;
    }

    // We return true here to ensure that we will get cancel / up signal
    // even if none of our children have requested touch.
    return true;
  }
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    // Just in case the previous long press hasn't been cleared, we make sure to start fresh
    // on touch down.
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
      mLongPressHelper.cancelLongPress();
    }

    // Consume any touch events for ourselves after longpress is triggered
    if (mLongPressHelper.hasPerformedLongPress()) {
      mLongPressHelper.cancelLongPress();
      return true;
    }

    // Watch for longpress or stylus button press events at this level to
    // make sure users can always pick up this widget
    if (mStylusEventHelper.checkAndPerformStylusEvent(ev)) {
      mLongPressHelper.cancelLongPress();
      return true;
    }
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (!mStylusEventHelper.inStylusButtonPressed()) {
            mLongPressHelper.postCheckForLongPress();
          }
          mDragLayer.setTouchCompleteListener(this);
          break;
        }

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mLongPressHelper.cancelLongPress();
        break;
      case MotionEvent.ACTION_MOVE:
        if (!Utilities.pointInView(this, ev.getX(), ev.getY(), mSlop)) {
          mLongPressHelper.cancelLongPress();
        }
        break;
    }

    // Otherwise continue letting touch events fall through to children
    return false;
  }
  @Override
  public void cancelLongPress() {
    super.cancelLongPress();

    mLongPressHelper.cancelLongPress();
  }