@Override
 public boolean onTouchEvent(MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       mMoveOutside = false;
       mFingerRect = new Rect(getLeft(), getTop(), getRight(), getBottom());
       mTouchPoint.set(Math.round(event.getX()), Math.round(event.getY()));
       mState = StateTouchDown;
       mStartTime = System.currentTimeMillis();
       invalidate();
       break;
     case MotionEvent.ACTION_MOVE:
       if (!mFingerRect.contains(getLeft() + (int) event.getX(), getTop() + (int) event.getY())) {
         mMoveOutside = true;
         mState = StateNormal;
         invalidate();
       }
       break;
     case MotionEvent.ACTION_UP:
       if (!mMoveOutside) {
         mState = StateTouchUp;
         mStartTime = System.currentTimeMillis();
         invalidate();
         performClick();
       }
       break;
     case MotionEvent.ACTION_CANCEL:
       mState = StateNormal;
       invalidate();
       break;
   }
   return true;
 }
  private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
    final Rect r = mRectTemp;

    final ArrayList<DropTarget> dropTargets = mDropTargets;
    final int count = dropTargets.size();
    for (int i = 0; i < count; i++) {
      final DropTarget target = dropTargets.get(i);
      target.getHitRect(r);
      target.getLocationOnScreen(dropCoordinates);
      r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
      if (r.contains(x, y)) {
        dropCoordinates[0] = x - dropCoordinates[0];
        dropCoordinates[1] = y - dropCoordinates[1];
        return target;
      }
    }

    // Check for default hit if all others failed
    final DropTarget target = mDefaultDrop;
    target.getHitRect(r);
    target.getLocationOnScreen(dropCoordinates);
    r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
    if (r.contains(x, y)) {
      dropCoordinates[0] = x - dropCoordinates[0];
      dropCoordinates[1] = y - dropCoordinates[1];
      return target;
    }

    return null;
  }
示例#3
0
 @Override
 public boolean onTouch(View view, MotionEvent motionEvent) {
   switch (motionEvent.getAction()) {
     case MotionEvent.ACTION_DOWN:
       updateBackground(pressedDrawable);
       this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom);
       break;
     case MotionEvent.ACTION_MOVE:
       Rect r = new Rect();
       view.getLocalVisibleRect(r);
       if (!r.contains((int) motionEvent.getX(), (int) motionEvent.getY() + 3 * mShadowHeight)
           && !r.contains(
               (int) motionEvent.getX(), (int) motionEvent.getY() - 3 * mShadowHeight)) {
         updateBackground(unpressedDrawable);
         this.setPadding(
             mPaddingLeft,
             mPaddingTop + mShadowHeight,
             mPaddingRight,
             mPaddingBottom + mShadowHeight);
       }
       break;
     case MotionEvent.ACTION_OUTSIDE:
     case MotionEvent.ACTION_CANCEL:
     case MotionEvent.ACTION_UP:
       updateBackground(unpressedDrawable);
       this.setPadding(
           mPaddingLeft,
           mPaddingTop + mShadowHeight,
           mPaddingRight,
           mPaddingBottom + mShadowHeight);
       break;
   }
   return false;
 }
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

      if (distanceY != 0 && distanceX != 0) {}

      if (null != bannerView) {
        Rect rect = new Rect();
        bannerView.getHitRect(rect);

        if (null != e1) {
          if (rect.contains((int) e1.getX(), (int) e1.getY())) {
            return false;
          }
        }

        if (null != e2) {
          if (rect.contains((int) e2.getX(), (int) e2.getY())) {
            return false;
          }
        }
      }
      //            if(Math.abs(distanceY) >= Math.abs(distanceX))
      //            {
      //                Log.e("listview", "********************** distanceX :" + distanceX + "
      // distanceY" + distanceY + "\n");
      //                return true;
      //            }
      //            Log.e("listview", "-------------------------- distanceX :" + distanceX + "
      // distanceY" + distanceY + "\n");
      return true;
    }
示例#5
0
 public boolean contains(Rect r) {
   boolean ret = r.contains(zone);
   if (ret) return ret;
   else
     return r.contains(zone.left, zone.top)
         || r.contains(zone.left, ab)
         || r.contains(ar, zone.top)
         || r.contains(ar, ab);
 }
  private static boolean isCurrentLocationVisible(GeoPoint start, GeoPoint end, MapView mapView) {
    if (start == null || end == null) return false;
    Rect currentMapBoundsRect = new Rect();
    Point startPosition = mapView.getProjection().toPixels(start, null);
    Point endPosition = mapView.getProjection().toPixels(end, null);

    mapView.getDrawingRect(currentMapBoundsRect);

    boolean result =
        currentMapBoundsRect.contains(startPosition.x, startPosition.y)
            || currentMapBoundsRect.contains(endPosition.x, endPosition.y);

    return result;
  }
  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    final float x = event.getX();
    final float y = event.getY();

    if (mAnimating) {
      return false;
    }

    View leftHandle = mLeftSlider.tab;
    leftHandle.getHitRect(mTmpRect);
    boolean leftHit = mTmpRect.contains((int) x, (int) y);

    View rightHandle = mRightSlider.tab;
    rightHandle.getHitRect(mTmpRect);
    boolean rightHit = mTmpRect.contains((int) x, (int) y);

    if (!mTracking && !(leftHit || rightHit)) {
      return false;
    }

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        {
          mTracking = true;
          mTriggered = false;
          vibrate(VIBRATE_SHORT);
          if (leftHit) {
            mCurrentSlider = mLeftSlider;
            mOtherSlider = mRightSlider;
            mThreshold = isHorizontal() ? THRESHOLD : 1.0f - THRESHOLD;
            setGrabbedState(OnTriggerListener.LEFT_HANDLE);
          } else {
            mCurrentSlider = mRightSlider;
            mOtherSlider = mLeftSlider;
            mThreshold = isHorizontal() ? 1.0f - THRESHOLD : THRESHOLD;
            setGrabbedState(OnTriggerListener.RIGHT_HANDLE);
          }
          mCurrentSlider.setState(Slider.STATE_PRESSED);
          mCurrentSlider.showTarget();
          mOtherSlider.hide();
          break;
        }
    }

    return true;
  }
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mHeaderView == null) return super.dispatchTouchEvent(ev);

    if (mHeaderViewVisible) {
      final int x = (int) ev.getX();
      final int y = (int) ev.getY();
      mHeaderView.getLocationOnScreen(mLocation);
      mRect.left = mLocation[0];
      mRect.top = mLocation[1];
      mRect.right = mLocation[0] + mHeaderView.getWidth();
      mRect.bottom = mLocation[1] + mHeaderView.getHeight();

      if (mRect.contains(x, y)) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
          performViewClick(x, y);
        }
        return true;
      } else {
        return super.dispatchTouchEvent(ev);
      }
    } else {
      return super.dispatchTouchEvent(ev);
    }
  }
  private void performViewClick(int x, int y) {
    if (null == mHeaderView) return;

    final ViewGroup container = (ViewGroup) mHeaderView;
    for (int i = 0; i < container.getChildCount(); i++) {
      View view = container.getChildAt(i);

      /**
       * transform coordinate to find the child view we clicked getGlobalVisibleRect used for
       * android 2.x, getLocalVisibleRect user for 3.x or above, maybe it's a bug
       */
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        view.getGlobalVisibleRect(mRect);
      } else {
        view.getLocalVisibleRect(mRect);
        int width = mRect.right - mRect.left;
        mRect.left = Math.abs(mRect.left);
        mRect.right = mRect.left + width;
      }

      if (mRect.contains(x, y)) {
        view.performClick();
        break;
      }
    }
  }
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    if (mScrollDisabled) return true;

    View v = mChildViews.get(mCurrent);
    if (v != null) {
      Rect bounds = getScrollBounds(v);
      switch (directionOfTravel(velocityX, velocityY)) {
        case MOVING_LEFT:
          if (bounds.left >= 0) {
            // Fling off to the left bring next view onto screen
            View vl = mChildViews.get(mCurrent + 1);

            if (vl != null) {
              slideViewOntoScreen(vl);
              return true;
            }
          }
          break;
        case MOVING_RIGHT:
          if (bounds.right <= 0) {
            // Fling off to the right bring previous view onto screen
            View vr = mChildViews.get(mCurrent - 1);

            if (vr != null) {
              slideViewOntoScreen(vr);
              return true;
            }
          }
          break;
      }
      mScrollerLastX = mScrollerLastY = 0;
      // If the page has been dragged out of bounds then we want to spring back
      // nicely. fling jumps back into bounds instantly, so we don't want to use
      // fling in that case. On the other hand, we don't want to forgo a fling
      // just because of a slightly off-angle drag taking us out of bounds other
      // than in the direction of the drag, so we test for out of bounds only
      // in the direction of travel.
      //
      // Also don't fling if out of bounds in any direction by more than fling
      // margin
      Rect expandedBounds = new Rect(bounds);
      expandedBounds.inset(-FLING_MARGIN, -FLING_MARGIN);

      if (withinBoundsInDirectionOfTravel(bounds, velocityX, velocityY)
          && expandedBounds.contains(0, 0)) {
        mScroller.fling(
            0,
            0,
            (int) velocityX,
            (int) velocityY,
            bounds.left,
            bounds.right,
            bounds.top,
            bounds.bottom);
        post(this);
      }
    }

    return true;
  }
示例#11
0
  private static void testProgressValues(ProgressValues progress, Rect bounds) {
    // Ensure that the percent progress is valid.
    assertTrue(progress.getPercent() >= 0);
    assertTrue(progress.getPercent() <= 100);

    // Ensure that the text rect is valid.
    final Rect textRect = progress.getCurrentRect();
    assertTrue(textRect.left <= textRect.right);
    assertTrue(textRect.top <= textRect.bottom);

    // Text rect must match the bounds of the image or sub-rectangle used.
    assertEquals(textRect.height(), bounds.height());
    assertEquals(textRect.width(), bounds.width());

    // Ensure that the word rect is valid.
    final Rect wordRect = progress.getCurrentWordRect();
    assertTrue(textRect.left <= textRect.right);
    assertTrue(textRect.top <= textRect.bottom);

    // Ensure the word rect falls within the text rect.
    final Rect absoluteWordRect =
        new Rect(
            textRect.left + wordRect.left,
            textRect.top + wordRect.top,
            textRect.left + wordRect.right,
            textRect.top + wordRect.bottom);
    assertTrue(textRect.contains(absoluteWordRect));
  }
示例#12
0
 @Override
 public boolean onTouch(View view, MotionEvent motionEvent) {
   switch (motionEvent.getAction()) {
     case MotionEvent.ACTION_DOWN:
       this.setPadding(mPaddingLeft, mPaddingTop + mShadowHeight, mPaddingRight, mPaddingBottom);
       break;
     case MotionEvent.ACTION_MOVE: // 触点坐标移动到View外时,View恢复至未按下时的状态
       Rect r = new Rect();
       view.getLocalVisibleRect(r);
       if (!r.contains((int) motionEvent.getX(), (int) motionEvent.getY())) {
         this.setPadding(
             mPaddingLeft,
             mPaddingTop + mShadowHeight,
             mPaddingRight,
             mPaddingBottom + mShadowHeight);
       }
       break;
     case MotionEvent.ACTION_OUTSIDE:
     case MotionEvent.ACTION_CANCEL:
     case MotionEvent.ACTION_UP:
       this.setPadding(
           mPaddingLeft,
           mPaddingTop + mShadowHeight,
           mPaddingRight,
           mPaddingBottom + mShadowHeight);
       break;
   }
   return false;
 }
示例#13
0
  public boolean onTestReceive(MotionEvent e) {

    if (e.getAction() == MotionEvent.ACTION_UP) {
      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() + this.getTop();
        int bottom = child.getBottom() + this.getBottom();
        int x = (int) e.getX();
        int y = (int) e.getY();
        viewRect.set(left, top, right, bottom);
        if (viewRect.contains(x, y)) {
          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;
    }
    return false;
  }
示例#14
0
        @Override
        public void onLongPress(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 (mOnItemLongClickListener != null) {
                mOnItemLongClickListener.onItemLongClick(
                    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;
            }
          }
        }
 private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
   final Rect bounds = mTempRect;
   mThumb.copyBounds(bounds);
   // Grow the current thumb rect for a bigger touch area
   bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
   mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));
   if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
     // If the user clicked outside the thumb, we compute the current position
     // and force an immediate drag to it.
     mIsDragging = true;
     mDragOffset = (bounds.width() / 2) - mAddedTouchBounds;
     updateDragging(ev);
     // As the thumb may have moved, get the bounds again
     mThumb.copyBounds(bounds);
     bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
   }
   if (mIsDragging) {
     setPressed(true);
     attemptClaimDrag();
     setHotspot(ev.getX(), ev.getY());
     mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
     if (mPublicChangeListener != null) {
       mPublicChangeListener.onStartTrackingTouch(this);
     }
   }
   return mIsDragging;
 }
示例#16
0
  private boolean handleTouchDown(MotionEvent ev, boolean intercept) {
    Rect hitRect = new Rect();
    int x = (int) ev.getX();
    int y = (int) ev.getY();

    for (AppWidgetResizeFrame child : mResizeFrames) {
      child.getHitRect(hitRect);
      if (hitRect.contains(x, y)) {
        if (child.beginResizeIfPointInRegion(x - child.getLeft(), y - child.getTop())) {
          mCurrentResizeFrame = child;
          mXDown = x;
          mYDown = y;
          requestDisallowInterceptTouchEvent(true);
          return true;
        }
      }
    }

    Folder currentFolder = mLauncher.getWorkspace().getOpenFolder();
    if (currentFolder != null && !mLauncher.isFolderClingVisible() && intercept) {
      if (currentFolder.isEditingName()) {
        if (!isEventOverFolderTextRegion(currentFolder, ev)) {
          currentFolder.dismissEditingName();
          return true;
        }
      }

      getDescendantRectRelativeToSelf(currentFolder, hitRect);
      if (!isEventOverFolder(currentFolder, ev)) {
        mLauncher.closeFolder();
        return true;
      }
    }
    return false;
  }
示例#17
0
 private static boolean isTouchEventHandled(final View view, final MotionEvent event) {
   if (view instanceof RightPaneBackgroundView) return false;
   if (!(view instanceof ViewGroup)) return true;
   final MotionEvent ev = MotionEvent.obtain(event);
   final float xf = ev.getX();
   final float yf = ev.getY();
   final float scrolledXFloat = xf + view.getScrollX();
   final float scrolledYFloat = yf + view.getScrollY();
   final Rect frame = new Rect();
   final int scrolledXInt = (int) scrolledXFloat;
   final int scrolledYInt = (int) scrolledYFloat;
   final int count = ((ViewGroup) view).getChildCount();
   for (int i = count - 1; i >= 0; i--) {
     final View child = ((ViewGroup) view).getChildAt(i);
     if (child.isShown() || child.getAnimation() != null) {
       child.getHitRect(frame);
       if (frame.contains(scrolledXInt, scrolledYInt)) {
         // offset the event to the view's coordinate system
         final float xc = scrolledXFloat - child.getLeft();
         final float yc = scrolledYFloat - child.getTop();
         ev.setLocation(xc, yc);
         if (isTouchEventHandled(child, ev)) return true;
       }
     }
   }
   return false;
 }
 /**
  * Duplicate touch events to child views. We want to dispatch a down motion event and the move
  * events to child views, but calling dispatchTouchEvent() causes StackOverflowError. Therefore we
  * do it manually.
  *
  * @param ev motion event to be passed to children
  * @param pendingEvents pending events like ACTION_DOWN. This will be passed to the children
  *     before ev
  */
 private void duplicateTouchEventForChildren(MotionEvent ev, MotionEvent... pendingEvents) {
   if (ev == null) {
     return;
   }
   for (int i = getChildCount() - 1; 0 <= i; i--) {
     View childView = getChildAt(i);
     if (childView != null) {
       Rect childRect = new Rect();
       childView.getHitRect(childRect);
       MotionEvent event = MotionEvent.obtainNoHistory(ev);
       if (!childRect.contains((int) event.getX(), (int) event.getY())) {
         continue;
       }
       float offsetX = -childView.getLeft();
       float offsetY = -childView.getTop();
       boolean consumed = false;
       if (pendingEvents != null) {
         for (MotionEvent pe : pendingEvents) {
           if (pe != null) {
             MotionEvent peAdjusted = MotionEvent.obtainNoHistory(pe);
             peAdjusted.offsetLocation(offsetX, offsetY);
             consumed |= childView.dispatchTouchEvent(peAdjusted);
           }
         }
       }
       event.offsetLocation(offsetX, offsetY);
       consumed |= childView.dispatchTouchEvent(event);
       if (consumed) {
         break;
       }
     }
   }
 }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
      //			boolean handled = false;

      switch (event.getAction()) {
        case MotionEvent.ACTION_MOVE:
          if (!mScrollingEnabled) {
            return false;
          }
          break;
        case MotionEvent.ACTION_UP:
          {
            // In Android WebView, all the click events are directly sent to WebKit. As a result,
            // OnClickListener() is
            // never called. Therefore, we have to manually call performClick() when a click event
            // is detected.
            //
            // In native Android and in the Ti world, it's possible to to have a touchEvent click on
            // a link in a webview and
            // also to be detected as a click on the webview.  So we cannot let handling of the
            // event one way block
            // the handling the other way -- it must be passed to both in all cases for everything
            // to work correctly.
            //
            if (hierarchyHasListener(TiC.EVENT_CLICK)) {
              Rect r = new Rect(0, 0, getWidth(), getHeight());
              if (r.contains((int) event.getX(), (int) event.getY())) {
                proxy.fireEvent(TiC.EVENT_CLICK, dictFromEvent(event), true, false);
              }
            }
            break;
          }
      }
      return super.onTouchEvent(event);
    }
示例#20
0
 private boolean isEventOverFolder(Folder folder, MotionEvent ev) {
   getDescendantRectRelativeToSelf(folder, mHitRect);
   if (mHitRect.contains((int) ev.getX(), (int) ev.getY())) {
     return true;
   }
   return false;
 }
示例#21
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;
    }
 @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;
 }
示例#23
0
  public void setMaskRect(int pl, int pt, int pr, int pb) {
    Rect rcMask = new Rect(0x0, 0x0, 0x0, 0x0);
    if (pl < 0) {
      pl = 0x0;
    }
    if (pt < 0) {
      pt = 0x0;
    }
    if (pr > 0x400) {
      pl = 0x400;
    }
    if (pl > 0x3e8) {
      pl = 0x3e8;
    }
    rcMask.set(pl, pt, pr, pb);
    for (int i = 0x0; i < pListMaskRect.size(); i = i + 0x1) {

      Rect rcTemp = (Rect) pListMaskRect.get(i);
      if (!rcTemp.contains(rcMask.left, rcMask.top, rcMask.right, rcMask.bottom)) {
        pListMaskRect.add(rcMask);
      }
    }

    if (pListMaskRect.size() == 0) {
      pListMaskRect.add(rcMask);
    }
  }
  // Determines which edges are hit by touching at (x, y)
  public int getHit(float x, float y) {
    Rect r = computeLayout();
    final float hysteresis = 20F;
    int retval = GROW_NONE;

    // verticalCheck makes sure the position is between the top and
    // the bottom edge (with some tolerance). Similar for horizCheck.
    boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis);
    boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis);

    // Check whether the position is near some edge(s)
    if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) {
      retval |= GROW_LEFT_EDGE;
    }
    if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) {
      retval |= GROW_RIGHT_EDGE;
    }
    if ((Math.abs(r.top - y) < hysteresis) && horizCheck) {
      retval |= GROW_TOP_EDGE;
    }
    if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) {
      retval |= GROW_BOTTOM_EDGE;
    }

    // Not near any edge but inside the rectangle: move
    if (retval == GROW_NONE && r.contains((int) x, (int) y)) {
      retval = MOVE;
    }
    return retval;
  }
  /** Handles the onLongPress event */
  @Override
  public void onLongPress(MotionEvent ev) {
    Log.i("misc", "longPress: " + ev.getAction());

    int x = (int) ev.getX();
    int y = (int) ev.getY();

    List<Overlay> overlays = this.maps.getOverlays();

    // All Overlays
    for (Overlay overlay : overlays) {
      // Only MapOverlays
      if (overlay instanceof MapsOverlay) {
        MapsOverlay mOverlay = (MapsOverlay) overlay;
        // Only Overlays, that are visible and longclickable
        if (mOverlay.isVisible() && mOverlay.isLongClick()) {
          for (int i = 0; i < mOverlay.size(); i++) {
            AbstractOverlayItem item = mOverlay.getAbstractItem(i);
            Rect lRect = item.getLongPressableRect();
            if (lRect.contains(x, y)) {
              item.longPress(this.maps);
              return;
            }
          }
        }
      }
    }
  }
示例#26
0
 private boolean isInIgnoredView(MotionEvent ev) {
   Rect rect = new Rect();
   for (View v : mIgnoredViews) {
     v.getHitRect(rect);
     if (rect.contains((int) ev.getX(), (int) ev.getY())) return true;
   }
   return false;
 }
示例#27
0
 public void setPos(int x, int y) {
   if (mov || !minizone.contains(x + w / 2, y + w / 2)) {
     zone.set(x, y, x + w, y + h);
     correctAbsoluteCoords();
     updateMinizone();
     mov = true;
   }
 }
示例#28
0
  // Determines which edges are hit by touching at (x, y).
  public int getHit(float x, float y) {

    Rect r = computeLayout();
    final float hysteresis = 20F;
    int retval = GROW_NONE;

    if (mCircle) {
      float distX = x - r.centerX();
      float distY = y - r.centerY();
      int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY);
      int radius = mDrawRect.width() / 2;
      int delta = distanceFromCenter - radius;
      if (Math.abs(delta) <= hysteresis) {
        if (Math.abs(distY) > Math.abs(distX)) {
          if (distY < 0) {
            retval = GROW_TOP_EDGE;
          } else {
            retval = GROW_BOTTOM_EDGE;
          }
        } else {
          if (distX < 0) {
            retval = GROW_LEFT_EDGE;
          } else {
            retval = GROW_RIGHT_EDGE;
          }
        }
      } else if (distanceFromCenter < radius) {
        retval = MOVE;
      } else {
        retval = GROW_NONE;
      }
    } else {
      // verticalCheck makes sure the position is between the top and
      // the bottom edge (with some tolerance). Similar for horizCheck.
      boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis);
      boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis);

      // Check whether the position is near some edge(s).
      if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) {
        retval |= GROW_LEFT_EDGE;
      }
      if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) {
        retval |= GROW_RIGHT_EDGE;
      }
      if ((Math.abs(r.top - y) < hysteresis) && horizCheck) {
        retval |= GROW_TOP_EDGE;
      }
      if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) {
        retval |= GROW_BOTTOM_EDGE;
      }

      // Not near any edge but inside the rectangle: move.
      if (retval == GROW_NONE && r.contains((int) x, (int) y)) {
        retval = MOVE;
      }
    }
    return retval;
  }
示例#29
0
  public boolean isTransformedTouchPointInView(float x, float y, View child) {
    // TODO: confirm if this is the right approach
    if (child == null) return false;

    final Rect frame = new Rect();
    child.getHitRect(frame);

    return frame.contains((int) x, (int) y);
  }
示例#30
0
 private boolean isDeletingExistingShape(int x, int y) {
   for (ShapeDrawable shape : shapes) {
     Rect bounds = shape.getBounds();
     if (bounds.contains(x, y)) {
       shapes.remove(shape);
       return (true);
     }
   }
   return (false);
 }