Пример #1
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        path.reset();
        path.moveTo(event.getX(), event.getY());
        break;
      case MotionEvent.ACTION_MOVE:
        path.lineTo(event.getX(), event.getY());
        break;
    }

    return super.onTouchEvent(event);
  }
Пример #2
0
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   builder.setLength(0);
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       builder.append("down, ");
       break;
     case MotionEvent.ACTION_MOVE:
       builder.append("move, ");
       break;
     case MotionEvent.ACTION_CANCEL:
       builder.append("cancel, ");
       break;
     case MotionEvent.ACTION_UP:
       builder.append("up, ");
       break;
   }
   builder.append(event.getX());
   builder.append(", ");
   builder.append(event.getY());
   String text = builder.toString();
   Log.d("TouchTest", text);
   textView.setText(text);
   return true;
 }
Пример #3
0
 @Override
 public boolean onSingleTapUp(MotionEvent e) {
   boolean toLeft = e.getX() < getWidth() / 2;
   if (toLeft) swipeRight();
   else swipeLeft();
   return true;
 }
Пример #4
0
 /**
  * If the motion event was relative to the view which in ignored view list,return true;
  *
  * @param ev
  * @return
  */
 private boolean isInIgnoredView(MotionEvent ev) {
   Rect rect = new Rect();
   for (View v : ignoredViews) {
     v.getGlobalVisibleRect(rect);
     if (rect.contains((int) ev.getX(), (int) ev.getY())) return true;
   }
   return false;
 }
Пример #5
0
  public boolean onTouchEvent(MotionEvent e) {
    x = e.getX();
    y = e.getY();

    // 更新を有効にする
    this.invalidate();
    return true;
  }
Пример #6
0
 @Override
 public boolean onTouch(View view, MotionEvent event) {
   String str = null;
   int i = 0;
   str =
       "x="
           + event.getX(i) / view.getMeasuredWidth()
           + ",y="
           + event.getY(i) / view.getMeasuredHeight();
   textView.setText(str);
   return false;
 }
Пример #7
0
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

      float dX = e2.getX() - e1.getX();

      float dY = e1.getY() - e2.getY();

      if (Math.abs(dY) < SWIPE_MAX_OFF_PATH
          && Math.abs(velocityX) >= SWIPE_THRESHOLD_VELOCITY
          && Math.abs(dX) >= SWIPE_MIN_DISTANCE) {

        if (dX > 0) {
          swipeRight();

        } else {
          swipeLeft();
        }

        return true;
      }

      return false;
    }
Пример #8
0
  /** 当屏幕被触摸时调用 */
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    // 设置贝塞尔曲线的坐标为触摸时坐标
    qStartX = (int) event.getX();
    qStartY = (int) event.getY();

    // 设置贝塞尔曲线的控制点坐标为终点坐标与起点坐标对应的差值的一半,注意这里不是曲线的中点
    qControlX = Math.abs(qEndX - qStartX) / 2;
    qCOntrolY = Math.abs(qEndY - qStartY) / 2;

    // 设置控制点的横坐标不返回
    cReturn = false;
    return super.onTouchEvent(event);
  }
Пример #9
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentActivityScaleX = ViewHelper.getScaleX(viewActivity);
    if (currentActivityScaleX == 1.0f) setScaleDirectionByRawX(ev.getRawX());

    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        lastActionDownX = ev.getX();
        lastActionDownY = ev.getY();
        isInIgnoredView = isInIgnoredView(ev) && !isOpened();
        pressedState = PRESSED_DOWN;
        break;

      case MotionEvent.ACTION_MOVE:
        if (isInIgnoredView || isInDisableDirection(scaleDirection)) break;

        if (pressedState != PRESSED_DOWN && pressedState != PRESSED_MOVE_HORIZONTAL) break;

        int xOffset = (int) (ev.getX() - lastActionDownX);
        int yOffset = (int) (ev.getY() - lastActionDownY);

        if (pressedState == PRESSED_DOWN) {
          if (yOffset > 25 || yOffset < -25) {
            pressedState = PRESSED_MOVE_VERTICAL;
            break;
          }
          if (xOffset < -50 || xOffset > 50) {
            pressedState = PRESSED_MOVE_HORIZONTAL;
            ev.setAction(MotionEvent.ACTION_CANCEL);
          }
        } else if (pressedState == PRESSED_MOVE_HORIZONTAL) {
          if (currentActivityScaleX < 0.95) showScrollViewMenu(scrollViewMenu);

          float targetScale = getTargetScale(ev.getRawX());
          if (mUse3D) {
            int angle = scaleDirection == DIRECTION_LEFT ? -ROTATE_Y_ANGLE : ROTATE_Y_ANGLE;
            angle *= (1 - targetScale) * 2;
            ViewHelper.setRotationY(viewActivity, angle);

            ViewHelper.setScaleX(imageViewShadow, targetScale - shadowAdjustScaleX);
            ViewHelper.setScaleY(imageViewShadow, targetScale - shadowAdjustScaleY);
          } else {
            ViewHelper.setScaleX(imageViewShadow, targetScale + shadowAdjustScaleX);
            ViewHelper.setScaleY(imageViewShadow, targetScale + shadowAdjustScaleY);
          }
          ViewHelper.setScaleX(viewActivity, targetScale);
          ViewHelper.setScaleY(viewActivity, targetScale);
          ViewHelper.setAlpha(scrollViewMenu, (1 - targetScale) * 2.0f);

          lastRawX = ev.getRawX();
          return true;
        }

        break;

      case MotionEvent.ACTION_UP:
        if (isInIgnoredView) break;
        if (pressedState != PRESSED_MOVE_HORIZONTAL) break;

        pressedState = PRESSED_DONE;
        if (isOpened()) {
          if (currentActivityScaleX > 0.56f) closeMenu();
          else openMenu(scaleDirection);
        } else {
          if (currentActivityScaleX < 0.94f) {
            openMenu(scaleDirection);
          } else {
            closeMenu();
          }
        }

        break;
    }
    lastRawX = ev.getRawX();
    return super.dispatchTouchEvent(ev);
  }
Пример #10
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;
  }
Пример #11
0
  public boolean onTouchEvent(MotionEvent ev) {
    if (mapThreadRunning) return false; // no updates when download is running
    if (gestureDetector.onTouchEvent(ev)) return true;

    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        {
          mLastTouchX = ev.getX();
          mLastTouchY = ev.getY();
          mActivePointerId = ev.getPointerId(0);
          break;
        }
      case MotionEvent.ACTION_POINTER_DOWN:
        {
          mLastTouchX2 = ev.getX();
          mLastTouchY2 = ev.getY();
          if (ev.getPointerCount() > 1) mActivePointerId2 = ev.getPointerId(1);
          break;
        }
      case MotionEvent.ACTION_MOVE:
        {
          int pointerIndex;
          float x = 0.0f, y = 0.0f;

          try {
            if ((mActivePointerId != INVALID_POINTER_ID)
                || (mActivePointerId2 != INVALID_POINTER_ID)) {
              pointerIndex = ev.findPointerIndex(mActivePointerId);
              x = ev.getX(pointerIndex);
              y = ev.getY(pointerIndex);
            }
            if ((mActivePointerId != INVALID_POINTER_ID)
                && (mActivePointerId2 != INVALID_POINTER_ID)) {
              double d1, d2;

              pointerIndex = ev.findPointerIndex(mActivePointerId2);
              if (pointerIndex < 0) return false;
              float x2 = ev.getX(pointerIndex);
              float y2 = ev.getY(pointerIndex);

              d1 = java.lang.Math.sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
              d2 =
                  java.lang.Math.sqrt(
                      (mLastTouchX - mLastTouchX2) * (mLastTouchX - mLastTouchX2)
                          + (mLastTouchY - mLastTouchY2) * (mLastTouchY - mLastTouchY2));

              /*                  if ((Math.abs(d1)>300) || (Math.abs(d2)>300))
              {
                 int i=0;
                 i=i;
              }*/

              if ((d1 > 0) && (d2 > 0)) {
                float w, h, s;

                s = (float) (d1 / d2);
                mScaleFactor *= s;
                matrix.postScale(s, s);
                w = scrWidth / 2.0f;
                h = scrHeight / 2.0f;

                matrix.postTranslate(w, h);
                imgOffsetX += w;
                imgOffsetY += h;
              }

              mLastTouchX2 = x2;
              mLastTouchY2 = y2;
            } else if (mScaleFactor == 1.0) {
              mScaleFactor = 1.0f;
              imgOffsetX += (x - mLastTouchX);
              imgOffsetY += (y - mLastTouchY);
              matrix.setTranslate(imgOffsetX, imgOffsetY);
            }

            if ((mActivePointerId != INVALID_POINTER_ID)
                || (mActivePointerId2 != INVALID_POINTER_ID)) {
              mLastTouchX = x;
              mLastTouchY = y;
            }
          } catch (Exception e) {
            // can be caused by
            // pointerIndex= ev.findPointerIndex(mActivePointerId);
            // x= ev.getX(pointerIndex);
            // above which seems to be a Android bug
          }
          invalidate();
          break;
        }
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_POINTER_UP:
        {
          breakMapThread = true;
          mActivePointerId = INVALID_POINTER_ID;
          mActivePointerId2 = INVALID_POINTER_ID;
          restartMap();
          break;
        }
    }
    return true;
  }