コード例 #1
1
ファイル: Game.java プロジェクト: rabaut/project1
  /**
   * Handle a touch event from the view.
   *
   * @param view The view that is the source of the touch
   * @param event The motion event describing the touch
   * @return true if the touch is handled.
   */
  public boolean onTouchEvent(View view, MotionEvent event) {
    float relX = event.getX() / width;
    float relY = event.getY() / height;

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        return onTouched(relX, relY);

      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (dragging) {
          dragging = false;
          return true;
        }
        break;

      case MotionEvent.ACTION_MOVE:
        // If we are dragging, move the piece and force a redraw
        if (dragging) {
          tempBlock.move(relX - lastRelX);
          lastRelX = relX;
          view.invalidate();
          return true;
        } else {
          scrollOffset += (relY - lastRelY);
          if (scrollOffset < 0) scrollOffset = 0;
          lastRelY = relY;
          view.invalidate();
          return true;
        }
    }

    return false;
  }
コード例 #2
0
    /**
     * Update the prevent touch stream.
     *
     * @param event The event that webkit had handled, or null to drop it.
     * @param preventDefault Prevent Ui to handle this event or not.
     * @return true If last event if prevented or false if not..
     */
    public boolean update(MotionEvent event, boolean preventDefault) {
      // Don't prevent null event.
      if (event == null) {
        Log.e(TAG, "PreventTouchStream has null event.");
        return false;
      }

      if (DEBUG) {
        Log.d(TAG, "event action=" + event.getActionMasked() + " preventDefault=" + preventDefault);
      }

      boolean prevent = mLastPreventDefault;
      mLastPreventDefault = preventDefault;
      switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_POINTER_DOWN:
        case MotionEvent.ACTION_POINTER_UP:
          return prevent;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          mLastPreventDefault = false;
          return prevent;
        default:
          return preventDefault;
      }
    }
コード例 #3
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    mScaleGestureDetector.onTouchEvent(event);

    if (!mScaling) mGestureDetector.onTouchEvent(event);

    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
      mUserInteracting = true;
    }
    if (event.getActionMasked() == MotionEvent.ACTION_UP) {
      mScrollDisabled = false;
      mUserInteracting = false;

      View v = mChildViews.get(mCurrent);
      if (v != null) {
        if (mScroller.isFinished()) {
          // If, at the end of user interaction, there is no
          // current inertial scroll in operation then animate
          // the view onto screen if necessary
          slideViewOntoScreen(v);
        }

        if (mScroller.isFinished()) {
          // If still there is no inertial scroll in operation
          // then the layout is stable
          postSettle(v);
        }
      }
    }

    requestLayout();
    return true;
  }
コード例 #4
0
ファイル: Remote.java プロジェクト: maduhu/ga-worldwind-suite
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (controlling) {
      velocityTracker.addMovement(event);
      velocityTracker.computeCurrentVelocity(1);

      boolean down =
          event.getActionMasked() == MotionEvent.ACTION_DOWN
              || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
      boolean up =
          event.getActionMasked() == MotionEvent.ACTION_UP
              || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP;
      Finger[] fingers = new Finger[event.getPointerCount()];
      for (int i = 0; i < event.getPointerCount(); i++) {
        fingers[i] =
            new Finger(
                event.getPointerId(i),
                event.getX(i),
                event.getY(i),
                velocityTracker.getXVelocity(i),
                velocityTracker.getYVelocity(i),
                !(event.getActionIndex() == i && up));
      }

      FingerMessage<?> message =
          up ? new UpMessage(fingers) : down ? new DownMessage(fingers) : new MoveMessage(fingers);
      communicator.sendMessage(message);
    }
    return super.onTouchEvent(event);
  }
コード例 #5
0
ファイル: CircleView.java プロジェクト: GermainZ/AcDisplay
  public boolean onTouchEvent2(MotionEvent event) {
    // Cancel current circle on two-fingers touch (or more.)
    if (event.getPointerCount() > 1) {
      cancelCircle(false);
      return false;
    }

    // If current circle is canceled then
    // ignore all actions except of touch down (to reset state.)
    if (mCanceled && event.getActionMasked() != MotionEvent.ACTION_DOWN) return false;

    final float x = event.getX();
    final float y = event.getY();
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        clearAnimation();

        // Initialize circle
        mRadiusMax = 0;
        mPoint[0] = x;
        mPoint[1] = y;
        mCanceled = false;

        mHandler.removeCallbacks(mDelayedCancel);
        mHandler.postDelayed(mDelayedCancel, 1000);
        mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_START);
      case MotionEvent.ACTION_MOVE:
        setRadius((float) Math.hypot(x - mPoint[0], y - mPoint[1]));

        // Cancel the circle if it's decreasing.
        if (mRadiusMax - mRadius > mRadiusDecreaseThreshold) {
          mRadiusAimed = false;
          cancelCircle(false);
          break;
        }

        if (calculateRatio() == 1) {
          if (!mRadiusAimed) {
            mRadiusAimed = true;
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
          }
        } else if (mRadiusAimed) {
          mRadiusAimed = false;
          performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mRadiusAimed) {
          mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_UNLOCK);
        }
      case MotionEvent.ACTION_CANCEL:
        mHandler.removeCallbacks(mDelayedCancel);
        cancelCircle(mRadiusAimed);
        break;
      default:
        return super.onTouchEvent(event);
    }
    return false;
  }
コード例 #6
0
ファイル: TouchPoint.java プロジェクト: paul99/clank
  // returns the WebTouchEvent::Type for the MotionEvent and -1 for failure
  public static int createTouchPoints(MotionEvent event, TouchPoint[] pts) {

    int type;
    int defaultState;

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        type = TOUCH_EVENT_TYPE_START;
        defaultState = TOUCH_POINT_STATE_PRESSED;
        break;
      case MotionEvent.ACTION_MOVE:
        type = TOUCH_EVENT_TYPE_MOVE;
        defaultState = TOUCH_POINT_STATE_MOVED;
        break;
      case MotionEvent.ACTION_UP:
        type = TOUCH_EVENT_TYPE_END;
        defaultState = TOUCH_POINT_STATE_RELEASED;
        break;
      case MotionEvent.ACTION_CANCEL:
        type = TOUCH_EVENT_TYPE_CANCEL;
        defaultState = TOUCH_POINT_STATE_CANCELLED;
        break;
      case MotionEvent.ACTION_POINTER_DOWN: // fall through.
      case MotionEvent.ACTION_POINTER_UP:
        type = TOUCH_EVENT_TYPE_MOVE;
        defaultState = TOUCH_POINT_STATE_STATIONARY;
        break;
      default:
        Log.e("Chromium", "Unknown motion event action: " + event.getActionMasked());
        return CONVERSION_ERROR;
    }

    for (int i = 0; i < pts.length; ++i) {
      int state = defaultState;
      if (defaultState == TOUCH_POINT_STATE_STATIONARY && event.getActionIndex() == i) {
        // An additional pointer has started or ended. Map this pointer state as
        // required, and all other pointers as "stationary".
        state =
            event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN
                ? TOUCH_POINT_STATE_PRESSED
                : TOUCH_POINT_STATE_RELEASED;
      }
      pts[i] =
          new TouchPoint(
              state,
              event.getPointerId(i),
              event.getX(i),
              event.getY(i),
              event.getSize(i),
              event.getPressure(i));
    }

    return type;
  }
コード例 #7
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   if (event.getActionMasked() == MotionEvent.ACTION_UP) {
     // Hack to prevent keyboard and insertion handle from showing.
     cancelLongPress();
   }
   if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
     Selection.setSelection(getText(), getOffsetForPosition(event.getX(), event.getY()));
   }
   return super.onTouchEvent(event);
 }
コード例 #8
0
ファイル: dr.java プロジェクト: BinSlashBash/xcrumby
 public void c(MotionEvent paramMotionEvent) {
   int j = paramMotionEvent.getHistorySize();
   int i = 0;
   while (i < j) {
     a(
         paramMotionEvent.getActionMasked(),
         paramMotionEvent.getHistoricalX(0, i),
         paramMotionEvent.getHistoricalY(0, i));
     i += 1;
   }
   a(paramMotionEvent.getActionMasked(), paramMotionEvent.getX(), paramMotionEvent.getY());
 }
コード例 #9
0
ファイル: NextScrollView.java プロジェクト: angcyo/RJcenter
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
      eventDownY = ev.getY();
      moveLength = curItem == 1 ? 0 : -firstViewHeight;
      handleEvent = checkHandleEvent(); // 按下之后,是否要处理move 和 up 事件
    }

    // 处理move 和 up 事件
    if (handleEvent) {
      if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
        eventMoveY = ev.getY();
        interceptEvent = checkInterceptEvent(eventDownY, eventMoveY);

        // 拦截之后的move 和 up 事件
        if (interceptEvent) {
          moveLength += eventMoveY - eventDownY;
          eventDownY = eventMoveY;
          offsetTop = moveLength;

          checkBorder();
          requestLayout();

          return true;
        }
      }

      // 处理up事件,自动滑动
      if (interceptEvent) {
        if (ev.getActionMasked() == MotionEvent.ACTION_UP) {
          if (curItem == 1) {
            if (Math.abs(moveLength) > viewHeight / 3) { // 移动超过了一半
              smoothTo(2);
            } else {
              smoothTo(1);
            }
          } else {
            if (Math.abs(moveLength + firstViewHeight) > viewHeight / 3) { // 移动超过了一半
              smoothTo(1);
            } else {
              smoothTo(2);
            }
          }
          interceptEvent = false;
        }
      }
    }

    return super.dispatchTouchEvent(ev);
  }
コード例 #10
0
    @Override
    public boolean onInterceptTouchEvent(View view, MotionEvent event) {
      // We need to account for scroll state for the touched view otherwise
      // tapping on an "empty" part of the view will still be considered a
      // valid touch event.
      if (view.getScrollX() != 0 || view.getScrollY() != 0) {
        Rect rect = new Rect();
        view.getHitRect(rect);
        rect.offset(-view.getScrollX(), -view.getScrollY());

        int[] viewCoords = new int[2];
        view.getLocationOnScreen(viewCoords);

        int x = (int) event.getRawX() - viewCoords[0];
        int y = (int) event.getRawY() - viewCoords[1];

        if (!rect.contains(x, y)) return false;
      }

      // If the tab tray is showing, hide the tab tray and don't send the event to content.
      if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
        mIsHidingTabs = true;
        return true;
      }
      return false;
    }
コード例 #11
0
  public boolean onTouch(View v, MotionEvent event) {
    GiderosApplication app = GiderosApplication.getInstance();
    if (app == null) return false;

    int size = event.getPointerCount();
    for (int i = 0; i < size; i++) {
      id[i] = event.getPointerId(i);
      x[i] = (int) event.getX(i);
      y[i] = (int) event.getY(i);
    }

    int actionMasked = event.getActionMasked();
    boolean isPointer =
        (actionMasked == MotionEvent.ACTION_POINTER_DOWN
            || actionMasked == MotionEvent.ACTION_POINTER_UP);
    int actionIndex = isPointer ? event.getActionIndex() : 0;

    if (actionMasked == MotionEvent.ACTION_DOWN
        || actionMasked == MotionEvent.ACTION_POINTER_DOWN) {
      app.onTouchesBegin(size, id, x, y, actionIndex);
    } else if (actionMasked == MotionEvent.ACTION_MOVE) {
      app.onTouchesMove(size, id, x, y);
    } else if (actionMasked == MotionEvent.ACTION_UP
        || actionMasked == MotionEvent.ACTION_POINTER_UP) {
      app.onTouchesEnd(size, id, x, y, actionIndex);
    } else if (actionMasked == MotionEvent.ACTION_CANCEL) {
      app.onTouchesCancel(size, id, x, y);
    }

    return true;
  }
コード例 #12
0
 private boolean isClickCandidateLocked(MotionEvent event) {
   if (event == null || event.getActionMasked() != MotionEvent.ACTION_UP || !mIsTapCandidate) {
     return false;
   }
   long downDuration = event.getEventTime() - event.getDownTime();
   return downDuration < LONG_PRESS_TIMEOUT;
 }
コード例 #13
0
 public boolean onTouchEvent(MotionEvent ev) {
   int action = ev.getActionMasked();
   ViewParent parent = getParent(); // LinearLayout
   gestureDetector.onTouchEvent(ev);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       this.mDragHelper.processTouchEvent(ev);
       parent.requestDisallowInterceptTouchEvent(true);
       sX = ev.getRawX();
       sY = ev.getRawY();
       return true;
     case MotionEvent.ACTION_MOVE:
       float distanceX = ev.getRawX() - sX;
       float distanceY = ev.getRawY() - sY;
       sX = ev.getRawX();
       sY = ev.getRawY();
       float angle = Math.abs(distanceY / distanceX);
       angle = (float) Math.toDegrees(Math.atan(angle));
       if (angle > 30) {
         parent.requestDisallowInterceptTouchEvent(false);
         return false;
       }
       parent.requestDisallowInterceptTouchEvent(true);
       mDragHelper.processTouchEvent(ev);
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
     default:
       parent.requestDisallowInterceptTouchEvent(true);
       mDragHelper.processTouchEvent(ev);
   }
   return true; // 必须返回true,表示已经正确处理touch事件,才能继续后续的拖动*/
 }
コード例 #14
0
  private boolean processTouch(MotionEvent event) {
    // Checking if that event was already processed
    // (by onInterceptTouchEvent prior to onTouchEvent)
    long eventTime = event.getEventTime();
    int action = event.getActionMasked();

    if (lastTouchEventTime == eventTime && lastTouchEventAction == action) {
      return lastTouchEventResult;
    }

    lastTouchEventTime = eventTime;
    lastTouchEventAction = action;

    if (getCount() > 0) {
      // Fixing event's Y position due to performed translation
      MotionEvent eventCopy = MotionEvent.obtain(event);
      eventCopy.offsetLocation(0, getTranslationY());
      lastTouchEventResult = gestureDetector.onTouchEvent(eventCopy);
      eventCopy.recycle();
    } else {
      lastTouchEventResult = false;
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
      onUpOrCancel();
    }

    return lastTouchEventResult;
  }
コード例 #15
0
  private boolean PopupTouchEvent(final MotionEvent event) {
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
          // mScrollIndicatorText.setVisibility(View.VISIBLE);
          toggleVisibilityCompat(false);
        else mScrollIndicatorText.startAnimation(mFadeIn);
        mScrolling = true;
        scroll(event.getY());
        return true;
      case MotionEvent.ACTION_MOVE:
        scroll(event.getY());
        return true;
      case MotionEvent.ACTION_UP:
        if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
          mHandlebar.setSelected(false);

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
          mScrolling = false;
          toggleVisibilityCompat(true);
        } else mScrollIndicatorText.startAnimation(mFadeOut);
        return true;
      default:
        break;
    }
    return false;
  }
コード例 #16
0
 @Override
 public boolean handleMotionEvent(MotionEvent event) {
   if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
     int actionPointerIndex = event.getActionIndex();
     int action = event.getActionMasked();
     switch (action) {
       case MotionEvent.ACTION_MOVE:
         SDLJoystick joystick = getJoystick(event.getDeviceId());
         if (joystick != null) {
           for (int i = 0; i < joystick.axes.size(); i++) {
             InputDevice.MotionRange range = joystick.axes.get(i);
             /* Normalize the value to -1...1 */
             float value =
                 (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin())
                         / range.getRange()
                         * 2.0f
                     - 1.0f;
             SDLActivity.onNativeJoy(joystick.device_id, i, value);
           }
         }
         break;
       default:
         break;
     }
   }
   return true;
 }
コード例 #17
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // Avoid short-circuit logic evaluation - ensure all gesture detectors see all events so
    // that they generate correct notifications.
    boolean handled = mScroller.onTouchEvent(event);
    handled |= mZoomer.onTouchEvent(event);
    handled |= mTapDetector.onTouchEvent(event);
    mSwipePinchDetector.onTouchEvent(event);

    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mViewer.setAnimationEnabled(false);
        mSuppressCursorMovement = false;
        mSuppressFling = false;
        mSwipeCompleted = false;
        break;

      case MotionEvent.ACTION_POINTER_DOWN:
        mTotalMotionY = 0;
        break;

      case MotionEvent.ACTION_UP:
        releaseAnyHeldButton();
        break;

      default:
        break;
    }
    return handled;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (mTouchInterceptionListener == null) {
      return false;
    }

    // In here, we must initialize touch state variables
    // and ask if we should intercept this event.
    // Whether we should intercept or not is kept for the later event handling.
    switch (ev.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        mInitialPoint = new PointF(ev.getX(), ev.getY());
        mPendingDownMotionEvent = MotionEvent.obtainNoHistory(ev);
        mDownMotionEventPended = true;
        mIntercepting = mTouchInterceptionListener.shouldInterceptTouchEvent(ev, false, 0, 0);
        mBeganFromDownMotionEvent = mIntercepting;
        mChildrenEventsCanceled = false;
        return mIntercepting;
      case MotionEvent.ACTION_MOVE:
        // ACTION_MOVE will be passed suddenly, so initialize to avoid exception.
        if (mInitialPoint == null) {
          mInitialPoint = new PointF(ev.getX(), ev.getY());
        }

        // diffX and diffY are the origin of the motion, and should be difference
        // from the position of the ACTION_DOWN event occurred.
        float diffX = ev.getX() - mInitialPoint.x;
        float diffY = ev.getY() - mInitialPoint.y;
        mIntercepting =
            mTouchInterceptionListener.shouldInterceptTouchEvent(ev, true, diffX, diffY);
        return mIntercepting;
    }
    return false;
  }
コード例 #19
0
  private void postLongPress() {
    synchronized (mLock) {
      if (!mPostLongPressScheduled) {
        return;
      }
      mPostLongPressScheduled = false;

      MotionEvent event = mPostTouchStream.getLastEvent();
      if (event == null) {
        return;
      }

      switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_POINTER_DOWN:
        case MotionEvent.ACTION_POINTER_UP:
          break;
        default:
          return;
      }

      MotionEvent eventToEnqueue = MotionEvent.obtainNoHistory(event);
      eventToEnqueue.setAction(MotionEvent.ACTION_MOVE);
      DispatchEvent d =
          obtainDispatchEventLocked(
              eventToEnqueue,
              EVENT_TYPE_LONG_PRESS,
              0,
              mPostLastWebKitXOffset,
              mPostLastWebKitYOffset,
              mPostLastWebKitScale);
      enqueueEventLocked(d);
    }
  }
コード例 #20
0
ファイル: SwipeableRVTL.java プロジェクト: keng42/Keep
 /** 处理触摸事件 */
 private boolean handleTouchEvent(MotionEvent motionEvent) {
   if (mViewWidth < 2) {
     mViewWidth = mRecyclerView.getWidth();
   }
   switch (motionEvent.getActionMasked()) {
     case MotionEvent.ACTION_DOWN:
       {
         actionDown(motionEvent);
         break;
       }
     case MotionEvent.ACTION_CANCEL:
       {
         actionCancel();
         break;
       }
     case MotionEvent.ACTION_UP:
       {
         actionUp(motionEvent);
         break;
       }
     case MotionEvent.ACTION_MOVE:
       {
         return actionMove(motionEvent);
       }
   }
   return false;
 }
コード例 #21
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
     thread.screenTouched();
   }
   return true;
 }
コード例 #22
0
  @Override
  public boolean onTouchEventInternal(MotionEvent e) {
    final int action = e.getActionMasked();

    // This path mimics the Android long press detection while still allowing
    // other touch events to come through the gesture detector.
    if (!mUseDefaultLongPress) {
      if (e.getPointerCount() > 1) {
        // If there's more than one pointer ignore the long press.
        if (mLongPressRunnable.isPending()) {
          cancelLongPress();
        }
      } else if (action == MotionEvent.ACTION_DOWN) {
        // If there was a pending event kill it off.
        if (mLongPressRunnable.isPending()) {
          cancelLongPress();
        }
        mLongPressRunnable.init(e);
        mLongPressHandler.postDelayed(mLongPressRunnable, mLongPressTimeoutMs);
      } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        cancelLongPress();
      } else if (mLongPressRunnable.isPending()) {
        // Allow for a little bit of touch slop.
        MotionEvent initialEvent = mLongPressRunnable.getInitialEvent();
        float distanceX = initialEvent.getX() - e.getX();
        float distanceY = initialEvent.getY() - e.getY();
        float distance = distanceX * distanceX + distanceY * distanceY;

        // Save a square root here by comparing to squared touch slop
        if (distance > mScaledTouchSlop * mScaledTouchSlop) {
          cancelLongPress();
        }
      }
    }

    // Sends the pinch event if two or more fingers touch the screen. According to test
    // Android handles the fingers order pretty consistently so always requesting
    // index 0 and 1 works here.
    // This might need some rework if 3 fingers event are supported.
    if (e.getPointerCount() > 1) {
      mHandler.onPinch(
          e.getX(0) * mPxToDp,
          e.getY(0) * mPxToDp,
          e.getX(1) * mPxToDp,
          e.getY(1) * mPxToDp,
          action == MotionEvent.ACTION_POINTER_DOWN);
      mDetector.setIsLongpressEnabled(false);
      mSingleInput = false;
    } else {
      mDetector.setIsLongpressEnabled(mUseDefaultLongPress);
      mSingleInput = true;
    }
    mDetector.onTouchEvent(e);

    // Propagate the up event after any gesture events.
    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
      mHandler.onUpOrCancel();
    }
    return true;
  }
コード例 #23
0
    @Override
    public boolean onTouch(View v, MotionEvent event) {

      //            opened_position     =   mListView.getPositionForView((View) v.getParent());
      switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
          {
            if (moptionsDisplay) {
              switch (v.getId()) {
                case 111111:
                  if (SwipeType == Dismiss) {
                    moptionsDisplay = false;
                    performDismiss(mDownView_parent, temp_position);
                  } else
                    //                                      if(old_mDownView!=null &&
                    // mDownView!=old_mDownView){
                    //                                          ResetListItem(old_mDownView);
                    //                                          old_mDownView=null;
                    //                                          mDownView=null;
                    //                                      }
                    tcallbacks.HalfSwipeListView(temp_position);
                  return true;
                case 222222:
                  tcallbacks.FullSwipeListView(temp_position);
                  return true;
              }
            }
          }
          return false;
      }

      return false;
    }
コード例 #24
0
  public static void dragVirtualButton(VirtualButton v, MotionEvent event) {
    float x, y;

    int action = event.getActionMasked();

    switch (action) {
      case (MotionEvent.ACTION_DOWN):
      case (MotionEvent.ACTION_MOVE):
        // Calculation of the new view position
        x =
            (v.getLeft() + event.getX() - v.getWidth() / 2)
                / v.getResources().getDisplayMetrics().widthPixels;
        y =
            (v.getTop() + event.getY() - v.getHeight() / 2)
                / v.getResources().getDisplayMetrics().heightPixels;

        Helper.setLayoutPosition((Activity) v.getContext(), v, x, y);

        v.setPosX(x);
        v.setPosY(y);

        return;
      default:
        return;
    }
  }
コード例 #25
0
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
      switch (ev.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
          if (DEBUG_EDGE_SWIPE) Log.d(TAG, "action down " + ev.getY());
          mFirstX = ev.getX();
          mFirstY = ev.getY();
          mConsuming = false;
          break;

        case MotionEvent.ACTION_MOVE:
          if (DEBUG_EDGE_SWIPE) Log.d(TAG, "action move " + ev.getY());
          final float dY = ev.getY() - mFirstY;
          final float daX = Math.abs(ev.getX() - mFirstX);
          final float daY = Math.abs(dY);
          if (!mConsuming && daX < daY && daY > mTouchSlop) {
            snooze();
            if (dY > 0) {
              if (DEBUG_EDGE_SWIPE) Log.d(TAG, "found an open");
              mBar.animateExpandNotificationsPanel();
            }
            mConsuming = true;
          }
          break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
          if (DEBUG_EDGE_SWIPE) Log.d(TAG, "action done");
          mConsuming = false;
          break;
      }
      return mConsuming;
    }
コード例 #26
0
ファイル: KView.java プロジェクト: prrt714/Kaleidoscope
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int action = event.getActionMasked();
    int P = event.getPointerCount();
    // int N = event.getHistorySize();
    if (action != MotionEvent.ACTION_MOVE) {
      if (action == MotionEvent.ACTION_DOWN) {
        // startX = mCurX * mScale; // event.getX();
        // startY = mCurY * mScale; // event.getY();
        sX1 = mCurX * mScale - event.getX(0);
        sY1 = mCurY * mScale - event.getY(0);
        return true;
      }
      if (action == MotionEvent.ACTION_POINTER_DOWN) {
        // Toast.makeText(mContext,
        // Float.toString(sX1)+"apd",
        // Toast.LENGTH_SHORT).show();

        if (P == 2) {
          float sX2 = event.getX(0) - event.getX(1);
          float sY2 = event.getY(0) - event.getY(1);
          sD = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2);
          mBitmapViewWidthInitial = mBitmapViewWidth;
          return true;
        } else if (P == 3) {
          sMx = (float) mCenterX - event.getX(2);
          sMy = (float) mCenterY - event.getY(2);
          return true;
        }
        return false;
      }
    } else {
      if (P == 1) {
        float a = Math.abs(sX1 + event.getX()) % mX;
        float b = Math.abs(sY1 + event.getY()) % mY;
        mCurX = (int) (a / mScale); // *(int)(event.getHistoricalX(0)-event.getHistoricalX(1));
        mCurY = (int) (b / mScale); // *(int)(event.getHistoricalY(0)-event.getHistoricalY(1));
      } else if (P == 2) {
        float sX2 = event.getX(0) - event.getX(1);
        float sY2 = event.getY(0) - event.getY(1);
        float sD2 = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2);

        int r = mBitmapViewWidthInitial + Math.round(sD2 - sD);
        if (r < mScreenRadius) r = mScreenRadius;
        setViewBitmapSizes(r);
      } else if (P == 3) {
        mCenterX = (int) (sMx + event.getX(2));
        mCenterY = (int) (sMy + event.getY(2));
      } else {
        return false;
      }

      drawIntoBitmap();
      invalidate();
      if (use3D) {
        updateTexture();
      }
    }
    return true;
  }
コード例 #27
0
ファイル: VirtualJoystick.java プロジェクト: ne0fhyk/AR-Glass
  @Override
  protected boolean onTouchImpl(View view, MotionEvent event) {
    boolean result = false;

    if (mJoystickLeft != null && mJoystickLeft.processTouch(view, event)) result = true;

    if (mJoystickRight != null && mJoystickRight.processTouch(view, event)) result = true;

    // check for double tap
    if (mSettings.isFlipEnabled() && event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
      long currTimestamp = event.getEventTime();

      if (event.getPointerCount() > 1) {
        if (currTimestamp - timestampLast < DOUBLE_TAP_TIMESTAMP_DELTA
            && Math.abs(event.getX(1) - xLast) < COORDINATE_DELTA
            && Math.abs(event.getY(1) - yLast) < COORDINATE_DELTA) {
          // Double tap detected.
          mDroneControl.doLeftFlip();
          result = true;
        }
      }
    }

    return result;
  }
コード例 #28
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   final int action = event.getActionMasked();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       downX = event.getX();
       downY = event.getY();
       break;
     case MotionEvent.ACTION_UP:
       // 先判断是否是点击事件
       if ((isClickable() || isLongClickable())
           && ((event.getX() - downX) < mTouchSlop || (event.getY() - downY) < mTouchSlop)) {
         // 这里我们得到了一个点击事件
         if (isFocusable() && isFocusableInTouchMode() && !isFocused()) requestFocus();
         if (event.getEventTime() - event.getDownTime() >= ViewConfiguration.getLongPressTimeout()
             && isLongClickable()) {
           // 是一个长按事件
           //                        performLongClick();
           Log.i("actiontype", "longClick");
         } else {
           // 点击事件
           performClick(event.getX());
         }
       }
       break;
   }
   return true;
 }
コード例 #29
0
 public boolean onTouchEvent(MotionEvent event) {
   if (event.getActionMasked() == MotionEvent.ACTION_UP) {
     if (mOnTouchUpListener != null) {
       return mOnTouchUpListener.onTouchUp(event);
     }
   }
   return true;
 }
コード例 #30
0
  /**
   * Handles forwarded events.
   *
   * @param activePointerId id of the pointer that activated forwarding
   * @return whether the event was handled
   */
  public boolean onForwardedEvent(MotionEvent event, int activePointerId) {
    boolean handledEvent = true;
    View vibrateView = null;

    final int actionMasked = event.getActionMasked();
    switch (actionMasked) {
      case MotionEvent.ACTION_CANCEL:
        handledEvent = false;
        break;
      case MotionEvent.ACTION_UP:
        handledEvent = false;
        // $FALL-THROUGH$
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_MOVE:
        final int activeIndex = event.findPointerIndex(activePointerId);
        if (activeIndex < 0) {
          handledEvent = false;
          break;
        }

        final int x = (int) event.getX(activeIndex);
        final int y = (int) event.getY(activeIndex);

        View pressedView = findViewByCoordinate(this, x, y, 0);
        if (mPressedChild != pressedView) {
          vibrateView = pressedView != null ? pressedView : mPressedChild;
          if (pressedView != null) pressedView.setPressed(true);
          if (mPressedChild != null) mPressedChild.setPressed(false);
          mPressedChild = pressedView;

          if (mOnForwardedEventListener != null) {
            mOnForwardedEventListener.onPressedView(event, activePointerId, mPressedChild);
          }
        }

        if (actionMasked == MotionEvent.ACTION_UP) {
          vibrateView = mPressedChild;
          clickPressedItem();
        }
        break;
    }

    // Failure to handle the event cancels forwarding.
    if (!handledEvent) {
      clearPressedItem();
    }

    if (vibrateView != null && mVibrateOnForwarded) {
      vibrateView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
    }

    if (mOnForwardedEventListener != null) {
      mOnForwardedEventListener.onForwardedEvent(event, activePointerId);
    }

    return handledEvent;
  }