Exemple #1
1
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    if (!activated) return true;
    if (!canSend()) return true;
    int viewWidth = mView.getWidth();
    int viewHeight = mView.getHeight();
    final int pointerCount = event.getPointerCount();
    Finger[] newFingers = new Finger[pointerCount];

    for (int p = 0; p < pointerCount; p++) {
      event.getPointerCoords(p, pc);
      Finger f = new Finger();
      float x = (float) pc.x / (float) viewWidth;
      float y = (float) pc.y / (float) viewHeight;
      f.setX(x);
      f.setY(y);
      f.setColor(randomColor);
      newFingers[p] = f;
    }
    FingerMessage msg = new FingerMessage();
    msg.setClientUUID(clientUUIDString);
    msg.setFingers(newFingers);
    msg.setColor(randomColor);
    String json = gson.toJson(msg);

    this.channel.publish(json.getBytes());
    lastSentTimestamp = System.currentTimeMillis();

    return true;
  }
  /**
   * 自定义移动距离
   *
   * @param event
   * @return
   */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_MOVE:
        int moveX = (int) event.getRawX();
        int deltaX = tempX - moveX;
        tempX = moveX;
        System.out.println("downX:" + downX);
        // downX为移动的最初点
        if (moveX - downX > mTouchSlop && Math.abs((int) event.getRawY() - downY) < mTouchSlop) {
          isSilding = true;
        }
        // 慢慢滑动看不到效果滑动??  设置项目的样式为半透明的样式,再设置布局的背景
        if (moveX - downX >= 0 && isSilding) {
          mContentView.scrollBy(deltaX, 0);
        }
        break;
      case MotionEvent.ACTION_UP:
        isSilding = false;
        System.out.println(mContentView.getScrollX());
        if (mContentView.getScrollX() <= -viewWidth / 20) {
          isFinish = true;
          scrollRight();
        } else {
          scrollOrigin();
          isFinish = false;
        }
        break;
    }

    return true;
  }
  /** @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent) */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (isEnabled() && touchListener.isSwipeEnabled()) {

      if (touchState == TOUCH_STATE_SCROLLING_X) {
        return touchListener.onTouch(this, ev);
      }

      switch (action) {
        case MotionEvent.ACTION_MOVE:
          checkInMoving(x, y);
          return touchState == TOUCH_STATE_SCROLLING_Y;
        case MotionEvent.ACTION_DOWN:
          touchListener.onTouch(this, ev);
          touchState = TOUCH_STATE_REST;
          lastMotionX = x;
          lastMotionY = y;
          return false;
        case MotionEvent.ACTION_CANCEL:
          touchState = TOUCH_STATE_REST;
          break;
        case MotionEvent.ACTION_UP:
          touchListener.onTouch(this, ev);
          return touchState == TOUCH_STATE_SCROLLING_Y;
        default:
          break;
      }
    }

    return super.onInterceptTouchEvent(ev);
  }
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   int action = event.getAction();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       oldX = event.getRawX();
       newX = event.getRawX();
       break;
     case MotionEvent.ACTION_MOVE:
       newX = event.getRawX();
       if (v != layout) {
         v.setTranslationX((newX - oldX) * 1.075f);
         if (v.getX() > v.getWidth() - 150 || v.getX() < -v.getWidth() + 150) {
           contentFrameLayout.removeView(v);
         }
       } else {
         if (newX - oldX > 50) {
           int distance = (int) (newX - oldX);
           if (distance > v.getWidth() / 2) ;
           {
             finish();
             overridePendingTransition(R.anim.side_in_left, R.anim.slide_out_right);
           }
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       if (v != layout) {
         v.setTranslationX(0);
       }
       break;
   }
   return true;
 }
 /**
  * Handles the touch event and determines whether to show the fast scroller (or updates it if it
  * is already showing).
  */
 private boolean handleTouchEvent(MotionEvent ev) {
   int action = ev.getAction();
   int x = (int) ev.getX();
   int y = (int) ev.getY();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       // Keep track of the down positions
       mDownX = x;
       mDownY = mLastY = y;
       if (shouldStopScroll(ev)) {
         stopScroll();
       }
       mScrollbar.handleTouchEvent(ev, mDownX, mDownY, mLastY);
       break;
     case MotionEvent.ACTION_MOVE:
       mLastY = y;
       mScrollbar.handleTouchEvent(ev, mDownX, mDownY, mLastY);
       break;
     case MotionEvent.ACTION_UP:
     case MotionEvent.ACTION_CANCEL:
       onFastScrollCompleted();
       mScrollbar.handleTouchEvent(ev, mDownX, mDownY, mLastY);
       break;
   }
   return mScrollbar.isDragging();
 }
  @Override
  public boolean onSingleTapUp(MotionEvent e) {

    if (myConnectFour != null) {
      //			Log.d("turn", "" + myConnectFour.getTurn());

      if (myConnectFour.getTurn()) {
        myConnectFour.update();
        if (myConnectFour.touch(e.getX(), e.getY())) {
          connect2.sendMsg("" + myConnectFour.getLastX());
          connect2.sendMsg("" + myConnectFour.getLastY());

          if (gameover = myConnectFour.getGameOver()) {
            if (myConnectFour.getWinner() == ConnectFourView.RED)
              myConnectFour.setText("Game Over: You win");
            else if (myConnectFour.getWinner() == ConnectFourView.GREEN)
              myConnectFour.setText("Game Over: You lose");
          }

          mRefreshHandler.sleep(50);
        }
      }
    }

    return true;
  }
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) {
      return false;
    }

    mDetector.onTouchEvent(ev);
    if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) {
      mFlingRemoveDetector.onTouchEvent(ev);
    }

    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mCurrX = (int) ev.getX();
        mCurrY = (int) ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (mRemoveEnabled && mIsRemoving) {
          int x = mPositionX >= 0 ? mPositionX : -mPositionX;
          int removePoint = mDslv.getWidth() / 2;
          if (x > removePoint) {
            mDslv.stopDragWithVelocity(true, 0);
          }
        }
      case MotionEvent.ACTION_CANCEL:
        mIsRemoving = false;
        mDragging = false;
        break;
    }

    return false;
  }
  /** 对拖拽图片不同的点击事件处理 */
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int X = (int) event.getX();

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        dragBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.lock_touch);
        heartView.setImageBitmap(dragBitmap);
        linearLayoutL.setBackgroundResource(R.drawable.left_bg_default);
        linearLayoutR.setBackgroundResource(R.drawable.left_bg_default);
        locationX = (int) event.getX();
        Log.i(TAG, "是否点击到位=" + isActionDown(event));
        return isActionDown(event); // 判断是否点击了滑动区�?

      case MotionEvent.ACTION_MOVE: // 保存x轴方向,绘制图画
        locationX = X;
        invalidate(); // 重新绘图
        return true;

      case MotionEvent.ACTION_UP: // 判断是否解锁成功
        dragBitmap =
            BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_slide_circle_n);
        heartView.setImageBitmap(dragBitmap);
        linearLayoutL.setBackgroundColor(getResources().getColor(R.color.transparent));
        linearLayoutR.setBackgroundResource(getResources().getColor(R.color.transparent));
        if (!unLockLeft() && !unLockRight()) { // 没有解锁成功,动画应该回滚
          flag = false;
          handleActionUpEvent(event); // 动画回滚
        }
        return true;
    }
    return super.onTouchEvent(event);
  }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   if (!refreshing && flag) {
     switch (event.getAction()) {
       case MotionEvent.ACTION_DOWN:
         downY = event.getY();
         break;
       case MotionEvent.ACTION_MOVE:
         if (lasty == 0) {
           lasty = event.getY();
         }
         float tem = event.getY() - lasty;
         LinearLayout.LayoutParams lp = (LayoutParams) topRefreshView.getLayoutParams();
         float mar = lp.topMargin + tem / 3;
         setTopMartgin(mar);
         lasty = event.getY();
         break;
       case MotionEvent.ACTION_CANCEL:
         animIsOver = true;
         isToRefreshing();
         startAnim();
         break;
       case MotionEvent.ACTION_UP:
         animIsOver = true;
         isToRefreshing();
         startAnim();
         break;
     }
   }
   return true;
 }
 @Override
 public boolean onInterceptTouchEvent(MotionEvent ev) {
   flag = listViewStatus();
   if (flag) {
     switch (ev.getAction()) {
       case MotionEvent.ACTION_DOWN:
         if (!isAnimDoing) {
           initAnimNow();
         }
         downY = ev.getY();
         break;
       case MotionEvent.ACTION_MOVE:
         float tem = ev.getY() - downY;
         switch (moveStatus) {
           case STATUS_REFRESH_TOP:
             if (tem > 0) {
               return true;
             }
             break;
           case STATUS_REFRESH_FOOTER:
             if (tem < 0) {
               return true;
             }
             break;
           case STATUS_REFRESH_NONE:
             break;
         }
         break;
     }
   }
   return super.onInterceptTouchEvent(ev);
 }
Exemple #11
0
 @Override
 public boolean dispatchTouchEvent(MotionEvent event) {
   final int action = event.getAction();
   final float y = event.getY();
   final int oldChoose = choose;
   final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener;
   final int c = (int) (y / getHeight() * b.length);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       showBkg = true;
       if (oldChoose != c && listener != null) {
         if (c >= 0 && c < b.length) {
           listener.onTouchingLetterChanged(b[c]);
           choose = c;
           invalidate();
         }
       }
       break;
     case MotionEvent.ACTION_MOVE:
       if (oldChoose != c && listener != null) {
         if (c >= 0 && c < b.length) {
           listener.onTouchingLetterChanged(b[c]);
           choose = c;
           invalidate();
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       showBkg = false;
       choose = -1;
       invalidate();
       break;
   }
   return true;
 }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    Log.e("mcoy", "McoyScrollView--onInterceptTouchEvent");
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        xDistance = yDistance = 0f;
        xLast = ev.getX();
        yLast = ev.getY();
        break;
      case MotionEvent.ACTION_MOVE:
        final float curX = ev.getX();
        final float curY = ev.getY();

        xDistance += Math.abs(curX - xLast);
        yDistance += Math.abs(curY - yLast);
        xLast = curX;
        yLast = curY;

        if (xDistance > yDistance) {
          return false;
        }
    }
    boolean onIntercept = super.onInterceptTouchEvent(ev);
    Log.e("mcoy", "McoyScrollView--onInterceptTouchEvent return " + onIntercept);

    return onIntercept;
  }
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    float currentTouchY = ev.getY();
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        mLastDispatchY = currentTouchY;
        break;
      case MotionEvent.ACTION_MOVE:
        float differentY = currentTouchY - mLastDispatchY;
        mLastDispatchY = currentTouchY;
        if (isContentViewToTop() && isHeaderViewCompleteInvisible()) {
          if (differentY >= 0 && !mIsInControl) {
            mIsInControl = true;

            return resetDispatchTouchEvent(ev);
          }

          if (differentY <= 0 && mIsInControl) {
            mIsInControl = false;

            return resetDispatchTouchEvent(ev);
          }
        }
        break;
    }
    return super.dispatchTouchEvent(ev);
  }
Exemple #14
0
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    // Ignore onScroll for a small time period after a double finger gesture has occured
    // Depending on how fingers are picked up after a double finger gesture, there could be a
    // residual "single"
    // finger pan which could also result in a fling. This check will ignore that.
    long time = e2.getEventTime();
    if (((time - mLastDoubleGestureTime) < SCROLL_TIME_THRESHOLD) && e2.getPointerCount() == 1) {
      return false;
    }

    if (mShoveHandled) {
      return false;
    }

    float x = 0, y = 0;
    int n = e2.getPointerCount();
    for (int i = 0; i < n; i++) {
      x += e2.getX(i) / n;
      y += e2.getY(i) / n;
    }

    handlePanGesture(x + distanceX, y + distanceY, x, y);

    return true;
  }
Exemple #15
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    int action = event.getAction();
    int x = (int) event.getX();
    int y = (int) event.getY();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mLastX = x;
        mLastY = y;
        mPath.moveTo(mLastX, mLastY);

        break;
      case MotionEvent.ACTION_MOVE:
        int dx = Math.abs(x - mLastX);
        int dy = Math.abs(y - mLastY);
        if (dx > 3 || dy > 3) {
          mPath.lineTo(x, y);
        }
        mLastX = x;
        mLastY = y;
        break;
      case MotionEvent.ACTION_UP:
        new Thread(mRunnable).start();
        break;
      default:
        break;
    }
    invalidate();
    return true;
  }
  /*该方法一般和ontouchEvent 一起用
   * (non-Javadoc)
   * @see android.view.ViewGroup#onInterceptTouchEvent(android.view.MotionEvent)
   */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent e) {
    // TODO Auto-generated method stub
    int action = e.getAction();
    int y = (int) e.getRawY();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        lastY = y;
        break;

      case MotionEvent.ACTION_MOVE:
        // y移动坐标
        int m = y - lastY;

        // 记录下此刻y坐标
        this.lastY = y;
        if (m > 6 && canScroll()) {
          return true;
        }
        break;
      case MotionEvent.ACTION_UP:
        break;

      case MotionEvent.ACTION_CANCEL:
        break;
    }
    return false;
  }
  /** 实现左右滑动切换校区 */
  @Override
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    float zoom = 17;
    if (e1.getX() - e2.getX() > 100) {
      if (flag < position_schoolLatLngs.length - 1) {
        flag++;
      } else {
        flag = 0;
      }
      this.flipper.setInAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_left_in));
      this.flipper.setOutAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_left_out));
    } else if (e1.getX() - e2.getX() < -100) {
      if (flag > 0) {
        flag--;
      } else {
        flag = position_schoolLatLngs.length - 1;
      }
      this.flipper.setInAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_right_in));
      this.flipper.setOutAnimation(
          AnimationUtils.loadAnimation(this.getActivity(), R.anim.push_right_out));
    }
    mMap.clear();
    loadMap(flag + 2, true);
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position_schoolLatLngs[flag], zoom));
    this.flipper.setDisplayedChild(flag);

    return false;
  }
 @Override
 public boolean onSingleTapConfirmed(MotionEvent e) {
   Rect viewRect = new Rect();
   for (int i = 0; i < getChildCount(); i++) {
     View child = getChildAt(i);
     int left = child.getLeft();
     int right = child.getRight();
     int top = child.getTop();
     int bottom = child.getBottom();
     viewRect.set(left, top, right, bottom);
     if (viewRect.contains((int) e.getX(), (int) e.getY())) {
       if (mOnItemClicked != null) {
         mOnItemClicked.onItemClick(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       if (mOnItemSelected != null) {
         mOnItemSelected.onItemSelected(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       break;
     }
   }
   return true;
 }
  public boolean onTouchEvent(MotionEvent event) {
    // Log.i("MySlideToDeleteListView","DisallowInterceptTouchEvent=true");
    // getParent().requestDisallowInterceptTouchEvent(true);
    boolean b = false;
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        {
          int x = (int) event.getX();
          int y = (int) event.getY();
          int position = pointToPosition(x, y);
          // Log.i(TAG, "postion=" + position);
          if (position != INVALID_POSITION) {
            XJNew data = (XJNew) getItemAtPosition(position);
            mFocusedItemView = data.slideView;
          }
        }
      default:
        break;
    }

    if (mFocusedItemView != null) {
      // mFocusedItemView.parent=getParent();
      // b=mFocusedItemView.onRequestTouchEvent(event);
    }
    Log.i(TAG, "onTouchEvent:" + Boolean.toString(b));
    // Log.i("MySlideToDeleteListView","DisallowInterceptTouchEvent=false");
    // getParent().requestDisallowInterceptTouchEvent(false);
    if (b) return true;
    return super.onTouchEvent(event);
  }
  @Override
  public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (!isShowing()) {
      float x = event.getX();
      float y = event.getY();
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          Touch_Down(x, y);
          invalidate();
          break;

        case MotionEvent.ACTION_MOVE:
          Touch_Move(x, y);
          invalidate();
          break;

        case MotionEvent.ACTION_UP:
          if (IsPaint) {
            Touch_Up(mPaint);
          } else {
            Touch_Up(mEraserPaint);
          }
          invalidate();
          break;
      }
    }
    return true;
  }
  @Override
  public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

    final int x1 = (int) e1.getX();
    final int y1 = (int) e1.getY();
    final int x2 = (int) e2.getX();
    final int y2 = (int) e2.getY();
    final int deltaX = x2 - mItemX;
    final int deltaY = y2 - mItemY;

    if (mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos != MISS)) {
      if (mHitPos != MISS) {
        if (mDragInitMode == ON_DRAG && Math.abs(y2 - y1) > mTouchSlop && mSortEnabled) {
          startDrag(mHitPos, deltaX, deltaY);
        } else if (mDragInitMode != ON_DOWN && Math.abs(x2 - x1) > mTouchSlop && mRemoveEnabled) {
          mIsRemoving = true;
          startDrag(mFlingHitPos, deltaX, deltaY);
        }
      } else if (mFlingHitPos != MISS) {
        if (Math.abs(x2 - x1) > mTouchSlop && mRemoveEnabled) {
          mIsRemoving = true;
          startDrag(mFlingHitPos, deltaX, deltaY);
        } else if (Math.abs(y2 - y1) > mTouchSlop) {
          mCanDrag = false; // if started to scroll the list then
          // don't allow sorting nor fling-removing
        }
      }
    }
    // return whatever
    return false;
  }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          return true;
        case MotionEvent.ACTION_UP:
          if (event.getRawX()
              >= (v.getRight() - ((TextView) v).getCompoundDrawables()[2].getBounds().width())) {
            // 响应右侧图标点击事件
            Intent intent = new Intent(context, TerminalSubmitActivity.class);
            intent.putExtra("operate", "modify");
            intent.putExtra("terminalid", ((String) v.getTag()).split(",")[0]);
            ((Activity) context).startActivityForResult(intent, 0);
          } else {
            // 响应自己的点击事件
            if (!v.performClick()) {
              // 响应ListView点击事件
              int position = Integer.parseInt(((String) v.getTag()).split(",")[1]) + 1;
              listView.performItemClick(
                  listView.getChildAt(position - listView.getFirstVisiblePosition()),
                  position,
                  listView.getItemIdAtPosition(position));
            }
          }
      }

      return false;
    }
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    if (!isEnable) return true;
    int y = (int) event.getY();
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        isScrolling = true;
        downY = (int) event.getY();
        downTime = System.currentTimeMillis();
        break;
      case MotionEvent.ACTION_MOVE:
        actionMove(y - downY);
        onSelectListener();
        break;
      case MotionEvent.ACTION_UP:

        // 移动距离的绝对值
        int move = (y - downY);
        move = move > 0 ? move : move * (-1);
        // 判断段时间移动的距离
        if (System.currentTimeMillis() - downTime < goonTime && move > goonDistence) {
          goonMove(y - downY);
        } else {
          actionUp(y - downY);
        }
        noEmpty();
        isScrolling = false;
        break;
      default:
        break;
    }
    return true;
  }
Exemple #24
0
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       init_x = event.getX();
       return true;
     case MotionEvent.ACTION_UP:
       float distance = init_x - event.getX();
       if (distance > 80) {
         viewFlipper.showNext();
         activeWindow++;
       }
       if (distance < -80) {
         viewFlipper.showPrevious();
         activeWindow--;
       }
       if (activeWindow < 0) activeWindow = 4;
       if (activeWindow > 4) activeWindow = 0;
       startPanel = activeWindow;
       updateTitleView();
     default:
       break;
   }
   return false;
 }
  public void onDragOver(DragObject d) {
    final DragView dragView = d.dragView;
    final int scrollOffset = mScrollView.getScrollY();
    final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
    r[0] -= getPaddingLeft();
    r[1] -= getPaddingTop();

    final long downTime = SystemClock.uptimeMillis();
    final MotionEvent translatedEv =
        MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);

    if (!mAutoScrollHelper.isEnabled()) {
      mAutoScrollHelper.setEnabled(true);
    }

    final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv);
    translatedEv.recycle();

    if (handled) {
      mReorderAlarm.cancelAlarm();
    } else {
      mTargetCell =
          mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
      if (isLayoutRtl()) {
        mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1;
      }
      if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) {
        mReorderAlarm.cancelAlarm();
        mReorderAlarm.setOnAlarmListener(mReorderAlarmListener);
        mReorderAlarm.setAlarm(REORDER_DELAY);
        mPreviousTargetCell[0] = mTargetCell[0];
        mPreviousTargetCell[1] = mTargetCell[1];
      }
    }
  }
 @Override
 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   boolean result = false;
   try {
     float diffY = e2.getY() - e1.getY();
     float diffX = e2.getX() - e1.getX();
     if (Math.abs(diffX) > Math.abs(diffY)) {
       if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
         if (diffX > 0) {
           onSwipeRight();
         } else {
           onSwipeLeft();
         }
       }
     } else {
       if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
         if (diffY > 0) {
           onSwipeBottom();
         } else {
           onSwipeTop();
         }
       }
     }
   } catch (Exception exception) {
     exception.printStackTrace();
   }
   return result;
 }
Exemple #27
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    float touchX = event.getX();
    float touchY = event.getY();

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        drawPath.moveTo(touchX, touchY);
        break;
      case MotionEvent.ACTION_MOVE:
        drawPath.lineTo(touchX, touchY);
        break;
      case MotionEvent.ACTION_UP:
        drawCanvas.drawPath(drawPath, drawPaint);
        drawPath.reset();
        break;
      default:
        return false;
    }

    // send the X & Y coordinates over bluetooth.
    sendPointToBluetooth(touchX, touchY);

    postInvalidate(); // Indicate view should be redrawn
    return true; // Indicate we've consumed the touch
    // detect user touch
  }
  public boolean onTouchEvent(MotionEvent event) {
    TEManagerInput inputManager = TEManagerInput.sharedManager();
    int pointerId;
    float x;
    float y;
    final int actionId = event.getAction();
    TEInputTouch touch;

    final int pointerCount = event.getPointerCount();
    for (int i = 0; i < pointerCount; ++i) {
      pointerId = event.getPointerId(i);
      x = event.getX(pointerId);
      y = mHeight - event.getY(pointerId);
      switch (actionId) {
        case MotionEvent.ACTION_DOWN:
          touch = new TEInputTouch(pointerId, x, y);
          inputManager.beginTouch(touch);
          break;
        case MotionEvent.ACTION_MOVE:
          touch = new TEInputTouch(pointerId, x, y);
          inputManager.moveTouch(touch);
          break;
        case MotionEvent.ACTION_UP:
          touch = new TEInputTouch(pointerId, x, y);
          inputManager.endTouch(touch);
          break;
        default:
          Log.v("info", "Couldn't identify " + String.valueOf(actionId));
          break;
      }
    }
    return false;
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {

    int y = (int) event.getRawY(); // 得到手势焦点相对于屏幕而言的Y轴坐标

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN: // 手势落下的时候回调
        Log.i(TAG, "ACTION_DOWN");
        // 记录下y坐标
        lastY = y;
        break;

      case MotionEvent.ACTION_MOVE: // 移动时回掉
        Log.i(TAG, "ACTION_MOVE");
        // y移动坐标
        int m = y - lastY; // 如果在移动距离大于-1小于6时,判断为需要执行滑动
        if (((m < 6) && (m > -1)) || (!isDragging)) {
          setLastRefreshTimeText();
          doMovement(m);
        }
        // 记录下此刻y坐标
        this.lastY = y;
        break;

      case MotionEvent.ACTION_UP:
        Log.i(TAG, "ACTION_UP");

        fling();

        break;
    }
    return true;
  }
  private void handleActionDown(MotionEvent event) {
    resetPattern();
    final float x = event.getX();
    final float y = event.getY();
    final Cell hitCell = detectAndAddHit(x, y);
    if (hitCell != null) {
      mPatternInProgress = true;
      mPatternDisplayMode = DisplayMode.Correct;
      notifyPatternStarted();
    } else {
      mPatternInProgress = false;
      notifyPatternCleared();
    }
    if (hitCell != null) {
      final float startX = getCenterXForColumn(hitCell.column);
      final float startY = getCenterYForRow(hitCell.row);

      final float widthOffset = mSquareWidth / 2f;
      final float heightOffset = mSquareHeight / 2f;

      invalidate(
          (int) (startX - widthOffset),
          (int) (startY - heightOffset),
          (int) (startX + widthOffset),
          (int) (startY + heightOffset));
    }
    mInProgressX = x;
    mInProgressY = y;
    if (PROFILE_DRAWING) {
      if (!mDrawingProfilingStarted) {
        Debug.startMethodTracing("LockPatternDrawing");
        mDrawingProfilingStarted = true;
      }
    }
  }