private HitTestResult hitTest(MotionEvent event) { float x = event.getX(); float y = event.getY(); RectF area = generateRect(m_leftTop, HitRadius, HitRadius); if (area.contains(x, y)) { return HitTestResult.TopLeft; } area = generateRect(m_rightBottom, HitRadius, HitRadius); if (area.contains(x, y)) { return HitTestResult.BottomRight; } area = generateRect(m_leftBottom, HitRadius, HitRadius); if (area.contains(x, y)) { return HitTestResult.BottomLeft; } area = generateRect(m_rightTop, HitRadius, HitRadius); if (area.contains(x, y)) { return HitTestResult.TopRight; } return HitTestResult.Outside; }
@Override public boolean onTouchEvent(PointF point) { if (routeLayer != null && routeLayer.getHelper().isRouterEnabled()) { if (boundsForMiniRoute.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) { showMiniMap = !showMiniMap; view.refreshMap(); return true; } if (boundsForLeftTime.contains(point.x, point.y) && routeLayer.getHelper().isFollowingMode()) { showArrivalTime = !showArrivalTime; view.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME.set(showArrivalTime); view.refreshMap(); return true; } } if (cachedDistString != null && boundsForDist.contains(point.x, point.y)) { AnimateDraggingMapThread thread = view.getAnimatedDraggingThread(); LatLon pointToNavigate = view.getSettings().getPointToNavigate(); if (pointToNavigate != null) { int fZoom = view.getZoom() < 15 ? 15 : view.getZoom(); thread.startMoving( pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true); } } return false; }
// Returns true if the line segment defined by the given two points intersects the given // rectangle. public static boolean lineSegmentIntersectsRect(PointF p1, PointF p2, RectF r2) { RectF line = new RectF( Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.max(p1.x, p2.x), Math.max(p1.y, p2.y)); // If the bounding box of the line segment intersects the rectangle or one contains the other, // the line segment intersects the rectangle. return RectF.intersects(line, r2) || line.contains(r2) || r2.contains(line); }
public final boolean onSingleTapConfirmed(MotionEvent e) { ImageView imageView = getImageView(); if (null != imageView) { if (null != mPhotoTapListener) { final RectF displayRect = getDisplayRect(); if (null != displayRect) { final float x = e.getX(), y = e.getY(); // Check to see if the user tapped on the photo if (displayRect.contains(x, y)) { float xResult = (x - displayRect.left) / displayRect.width(); float yResult = (y - displayRect.top) / displayRect.height(); mPhotoTapListener.onPhotoTap(imageView, xResult, yResult); return true; } } } if (null != mViewTapListener) { mViewTapListener.onViewTap(imageView, e.getX(), e.getY()); } } return false; }
@Override public boolean onSingleTapConfirmed(MotionEvent e) { if (this.photoViewAttacher == null) return false; ImageView imageView = photoViewAttacher.getImageView(); if (null != photoViewAttacher.getOnPhotoTapListener()) { final RectF displayRect = photoViewAttacher.getDisplayRect(); if (null != displayRect) { final float x = e.getX(), y = e.getY(); // Check to see if the user tapped on the photo if (displayRect.contains(x, y)) { float xResult = (x - displayRect.left) / displayRect.width(); float yResult = (y - displayRect.top) / displayRect.height(); photoViewAttacher.getOnPhotoTapListener().onPhotoTap(imageView, xResult, yResult); return true; } } } if (null != photoViewAttacher.getOnViewTapListener()) { photoViewAttacher.getOnViewTapListener().onViewTap(imageView, e.getX(), e.getY()); } return false; }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { for (int i = getChildCount() - 1; i >= 0; i--) { View v = getChildAt(i); if (v.getVisibility() != View.VISIBLE) continue; Matrix m = getViewMatrix(v); if (m != null) { float[] points = new float[] {ev.getX(), ev.getY()}; RectF rect = new RectF(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); Matrix realM = new Matrix(m); realM.preTranslate(-rect.left, -rect.top); realM.postTranslate(rect.left, rect.top); realM.mapRect(rect); if (rect.contains((int) points[0], (int) points[1])) { Matrix mi = new Matrix(); realM.invert(mi); if (mi != null) { mi.mapPoints(points); ev.setEdgeFlags( ev.getEdgeFlags() | FLAG_TRANSFORMED); // a trick to mark the event as transformed ev.setLocation( points[0], points[1]); // without the transform point the view wont receive it return super.dispatchTouchEvent(ev); } } } } Matrix m = getMyViewMatrix(); int flag = ev.getEdgeFlags(); if (m != null && ((flag & FLAG_TRANSFORMED) != FLAG_TRANSFORMED)) { float[] points = new float[] {ev.getX(), ev.getY()}; // untransformed point RectF rect = new RectF(getLeft(), getTop(), getRight(), getBottom()); // untransformed rect Matrix realM = new Matrix(m); realM.preTranslate(-rect.left, -rect.top); realM.postTranslate(rect.left, rect.top); realM.mapRect(rect); points[0] += getLeft(); points[1] += getTop(); if (!rect.contains(points[0], points[1]) && ev.getAction() == MotionEvent.ACTION_DOWN) { Log.d("FreeLayout", this + "not dispatching"); return false; } } return super.dispatchTouchEvent(ev); }
public int checkUnitChange(float x, float y) { if (!DIMENSIONS.contains(x, y)) return -1; if (y < UNIT_HEIGHT) { return 0; } else { return 1; } }
@Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 獲取按下點坐標 mDownX = event.getX(); mDownY = event.getY(); break; case MotionEvent.ACTION_MOVE: // 判斷是否為下游標 if (mCursorBottomDstRect.contains(mDownX, mDownY)) { float offSetX = event.getX() - mDownX; mCursorBottomDstRect.left = mCursorBottomDstRect.left + offSetX; mCursorBottomDstRect.right = mCursorBottomDstRect.left + offSetX + mBitmap.getWidth(); mDownX = event.getX(); mDownY = event.getY(); invalidate(); } // 判斷是否為上游標 if (mCursorTopDstRect.contains(mDownX, mDownY)) { float offSetX = event.getX() - mDownX; mCursorTopDstRect.left = mCursorTopDstRect.left + offSetX; mCursorTopDstRect.right = mCursorTopDstRect.left + offSetX + mBitmap.getWidth(); mDownX = event.getX(); mDownY = event.getY(); invalidate(); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: // 手指抬起,校正游標位置 setCursorPositon(mTopCalibration, mCursorTopDstRect); setCursorPositon(mBottomCalibration, mCursorBottomDstRect); invalidate(); break; default: break; } return true; }
private boolean moveTrackersIfNeeded(MotionEvent event) { if (mStartTouchPoint == null) return false; boolean update = false; int startX = mStartTouchPoint.x; int startY = mStartTouchPoint.y; if (mHueRect.contains(startX, startY)) { mLastTouchedPanel = PANEL_HUE; mHue = pointToHue(event.getY()); update = true; } else if (mSatValRect.contains(startX, startY)) { mLastTouchedPanel = PANEL_SAT_VAL; float[] result = pointToSatVal(event.getX(), event.getY()); mSat = result[0]; mVal = result[1]; update = true; } return update; }
public boolean onTouchEvent(MotionEvent paramMotionEvent) { if ((a.b()) || (!m)) { return super.onTouchEvent(paramMotionEvent); } int n = paramMotionEvent.getAction(); float f1 = paramMotionEvent.getX(); float f2 = paramMotionEvent.getY(); switch (n) { } for (; ; ) { return super.onTouchEvent(paramMotionEvent); n = 0; for (; ; ) { if (n < e) { RectF localRectF = (RectF) b.get(n); if (localRectF.contains(f1, f2)) { a(n); c = localRectF; } } else { invalidate(); break; } n += 1; } if ((c != null) && (!c.contains(f1, f2))) { c(); continue; if ((d != -1) && (f != null)) { f.a(this, d, e); } c(); continue; c(); } } }
@Override public boolean onTouchEvent(MotionEvent event) { if (mController.isIgnoringTouchEvents()) return false; // prevent ray cast of touch events to actions container getHitRect(mHitRect); mHitRect.offset(-getScrollX(), -getScrollY()); // applying effects mEffectedHitRect.set(mHitRect); mController.getEffectsMatrix().mapRect(mEffectedHitRect); if (mEffectedHitRect.contains((int) event.getX(), (int) event.getY())) { return true; } return super.onTouchEvent(event); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public int onTestSize(int suggestedSize, RectF availableSPace) { mPaint.setTextSize(suggestedSize); String text = getText().toString(); boolean singleline = getMaxLines() == 1; if (singleline) { mTextRect.bottom = mPaint.getFontSpacing(); mTextRect.right = mPaint.measureText(text); } else { StaticLayout layout = new StaticLayout( text, mPaint, mWidthLimit, Alignment.ALIGN_NORMAL, mSpacingMult, mSpacingAdd, true); // return early if we have more lines if (getMaxLines() != NO_LINE_LIMIT && layout.getLineCount() > getMaxLines()) { return 1; } mTextRect.bottom = layout.getHeight(); int maxWidth = -1; for (int i = 0; i < layout.getLineCount(); i++) { if (maxWidth < layout.getLineWidth(i)) { maxWidth = (int) layout.getLineWidth(i); } } mTextRect.right = maxWidth; } mTextRect.offsetTo(0, 0); if (availableSPace.contains(mTextRect)) { // may be too small, don't worry we will find the best match return -1; } else { // too big return 1; } }
/** Test whether an information balloon should be displayed or a prior balloon hidden. */ private MapLocation getHitMapLocation(MapView mapView, GeoPoint tapPoint) { /** Tracking the clicks on MapLocation */ MapLocation hitMapLocation = null; RectF hitTestRecr = new RectF(); Point screenCoords = new Point(); Iterator<MapLocation> iterator = mLocationViewers.getMapLocations().iterator(); while (iterator.hasNext()) { MapLocation testLocation = iterator.next(); Bitmap bubbleIcon = testLocation.isSpecial() ? mBubbleIconSpecial : mBubbleIcon; /** This is used to translate the map's lat/long coordinates to screen's coordinates */ mapView .getProjection() .toPixels( new GeoPoint(testLocation.getLatitude(), testLocation.getLongitude()), screenCoords); // Create a testing Rectangle with the size and coordinates of our icon // Set the testing Rectangle with the size and coordinates of our on screen icon hitTestRecr.set( -bubbleIcon.getWidth() / 2, -bubbleIcon.getHeight(), bubbleIcon.getWidth() / 2, 0); hitTestRecr.offset(screenCoords.x, screenCoords.y); // At last test for a match between our Rectangle and the location clicked by the user mapView.getProjection().toPixels(tapPoint, screenCoords); if (hitTestRecr.contains(screenCoords.x, screenCoords.y)) { hitMapLocation = testLocation; break; } } // Finally clear the new MouseSelection as its process finished tapPoint = null; return hitMapLocation; }
private GeoTrack getHitMapLocation(MapView mapView, IGeoPoint tapPoint) { // Track which MapLocation was hit...if any GeoTrack result = null; RectF tapPointHitTestRect = new RectF(); Point tapPointTestScreenCoords = new Point(); int zoonLevel = mapView.getZoomLevel(); int selectRadius = zoonLevel + 6; Projection pj = mapView.getProjection(); for (GeoTrack testLocation : geoTracks) { if (!seletedRangeActivated || (testLocation.time >= seletedRangeBeginTimeInMs && testLocation.time <= seletedRangeEndTimeInMs)) { // Translate the MapLocation's lat/long coordinates to screen // coordinates pj.toPixels(testLocation.asGeoPoint(), tapPointTestScreenCoords); // Create a 'hit' testing Rectangle w/size and coordinates of // our // icon // Set the 'hit' testing Rectangle with the size and coordinates // of // our on screen icon tapPointHitTestRect.set(-selectRadius, -selectRadius, selectRadius, selectRadius); tapPointHitTestRect.offset(tapPointTestScreenCoords.x, tapPointTestScreenCoords.y); // Finally test for a match between our 'hit' Rectangle and the // location clicked by the user pj.toPixels(tapPoint, tapPointTestScreenCoords); if (tapPointHitTestRect.contains(tapPointTestScreenCoords.x, tapPointTestScreenCoords.y)) { result = testLocation; // break; } } } return result; }
@Override public boolean onSingleTapConfirmed(MotionEvent event) { if (photoTapListener != null) { final RectF displayRect = getDisplayRect(); if (null != displayRect) { final float x = event.getX(), y = event.getY(); // Check to see if the user tapped on the photo if (displayRect.contains(x, y)) { float xResult = (x - displayRect.left) / displayRect.width(); float yResult = (y - displayRect.top) / displayRect.height(); photoTapListener.onPhotoTap(ZoomImageView.this, xResult, yResult); return true; } } } if (viewTapListener != null) { viewTapListener.onViewTap(ZoomImageView.this, event.getX(), event.getY()); } return false; }
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mDragging) { return false; } final int action = ev.getAction(); final float x = ev.getX(); final float y = ev.getY(); switch (action) { case MotionEvent.ACTION_DOWN: // Remember where the motion event started mLastMotionX = x; mLastMotionY = y; if ((x < SCROLL_ZONE) || (x > getWidth() - SCROLL_ZONE)) { mScrollState = SCROLL_WAITING_IN_ZONE; postDelayed(mScrollRunnable, SCROLL_DELAY); } else { mScrollState = SCROLL_OUTSIDE_ZONE; } break; case MotionEvent.ACTION_MOVE: final int scrollX = mScrollX; final int scrollY = mScrollY; final float touchX = mTouchOffsetX; final float touchY = mTouchOffsetY; final int offsetX = mBitmapOffsetX; final int offsetY = mBitmapOffsetY; int left = (int) (scrollX + mLastMotionX - touchX - offsetX); int top = (int) (scrollY + mLastMotionY - touchY - offsetY); int width; int height; if (mDrawModeBitmap && mDragBitmap != null) { final Bitmap dragBitmap = mDragBitmap; width = dragBitmap.getWidth(); height = dragBitmap.getHeight(); } else { width = mDrawWidth; height = mDrawHeight; } final Rect rect = mRect; rect.set(left - 1, top - 1, left + width + 1, top + height + 1); mLastMotionX = x; mLastMotionY = y; left = (int) (scrollX + x - touchX - offsetX); top = (int) (scrollY + y - touchY - offsetY); // Invalidate current icon position rect.union(left - 1, top - 1, left + width + 1, top + height + 1); final int[] coordinates = mDropCoordinates; DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates); if (dropTarget != null) { if (mLastDropTarget == dropTarget) { dropTarget.onDragOver( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragInfo); } else { if (mLastDropTarget != null) { mLastDropTarget.onDragExit( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragInfo); } dropTarget.onDragEnter( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragInfo); } } else { if (mLastDropTarget != null) { mLastDropTarget.onDragExit( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragInfo); } } invalidate(rect); mLastDropTarget = dropTarget; if (mTagPopup != null) { if (Math.abs(mOriginalX - mLastMotionX) > SCROLL_ZONE || Math.abs(mOriginalY - mLastMotionY) > SCROLL_ZONE) { final QuickActionWindow qa = (QuickActionWindow) mTagPopup; qa.dismiss(); mTagPopup = null; } } boolean inDragRegion = false; if (mDragRegion != null) { final RectF region = mDragRegion; final boolean inRegion = region.contains(ev.getRawX(), ev.getRawY()); if (!mEnteredRegion && inRegion) { mDragPaint = mTrashPaint; mRectPaint.setColor(COLOR_TRASH); mEnteredRegion = true; inDragRegion = true; } else if (mEnteredRegion && !inRegion) { mDragPaint = null; mRectPaint.setColor(COLOR_NORMAL); mEnteredRegion = false; } } if (!inDragRegion && x < SCROLL_ZONE) { if (mScrollState == SCROLL_OUTSIDE_ZONE) { mScrollState = SCROLL_WAITING_IN_ZONE; mScrollRunnable.setDirection(SCROLL_LEFT); postDelayed(mScrollRunnable, SCROLL_DELAY); } } else if (!inDragRegion && x > getWidth() - SCROLL_ZONE) { if (mScrollState == SCROLL_OUTSIDE_ZONE) { mScrollState = SCROLL_WAITING_IN_ZONE; mScrollRunnable.setDirection(SCROLL_RIGHT); postDelayed(mScrollRunnable, SCROLL_DELAY); } } else { if (mScrollState == SCROLL_WAITING_IN_ZONE) { mScrollState = SCROLL_OUTSIDE_ZONE; mScrollRunnable.setDirection(SCROLL_RIGHT); removeCallbacks(mScrollRunnable); } } break; case MotionEvent.ACTION_UP: removeCallbacks(mScrollRunnable); if (mShouldDrop) { drop(x, y); mShouldDrop = false; } endDrag(); break; case MotionEvent.ACTION_CANCEL: endDrag(); } return true; }
/** * Handles the touch event. * * @param event the touch event */ public boolean handleTouch(MotionEvent event) { int action = event.getAction(); if (mRenderer != null && action == MotionEvent.ACTION_MOVE) { if (oldX >= 0 || oldY >= 0) { float newX = event.getX(0); float newY = event.getY(0); if (event.getPointerCount() > 1 && (oldX2 >= 0 || oldY2 >= 0) && mRenderer.isZoomEnabled()) { float newX2 = event.getX(1); float newY2 = event.getY(1); float newDeltaX = Math.abs(newX - newX2); float newDeltaY = Math.abs(newY - newY2); float oldDeltaX = Math.abs(oldX - oldX2); float oldDeltaY = Math.abs(oldY - oldY2); float zoomRate = 1; float tan1 = Math.abs(newY - oldY) / Math.abs(newX - oldX); float tan2 = Math.abs(newY2 - oldY2) / Math.abs(newX2 - oldX2); if (tan1 <= 0.25 && tan2 <= 0.25) { // horizontal pinch zoom, |deltaY| / |deltaX| is [0 ~ 0.25], 0.25 is // the approximate value of tan(PI / 12) zoomRate = newDeltaX / oldDeltaX; applyZoom(zoomRate, Zoom.ZOOM_AXIS_X); } else if (tan1 >= 3.73 && tan2 >= 3.73) { // pinch zoom vertically, |deltaY| / |deltaX| is [3.73 ~ infinity], // 3.732 is the approximate value of tan(PI / 2 - PI / 12) zoomRate = newDeltaY / oldDeltaY; applyZoom(zoomRate, Zoom.ZOOM_AXIS_Y); } else { // pinch zoom diagonally if (Math.abs(newX - oldX) >= Math.abs(newY - oldY)) { zoomRate = newDeltaX / oldDeltaX; } else { zoomRate = newDeltaY / oldDeltaY; } applyZoom(zoomRate, Zoom.ZOOM_AXIS_XY); } oldX2 = newX2; oldY2 = newY2; } else if (mRenderer.isPanEnabled()) { mPan.apply(oldX, oldY, newX, newY); oldX2 = 0; oldY2 = 0; } oldX = newX; oldY = newY; graphicalView.repaint(); return true; } } else if (action == MotionEvent.ACTION_DOWN) { oldX = event.getX(0); oldY = event.getY(0); if (mRenderer != null && mRenderer.isZoomEnabled() && zoomR.contains(oldX, oldY)) { if (oldX < zoomR.left + zoomR.width() / 3) { graphicalView.zoomIn(); } else if (oldX < zoomR.left + zoomR.width() * 2 / 3) { graphicalView.zoomOut(); } else { graphicalView.zoomReset(); } return true; } } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { oldX = 0; oldY = 0; oldX2 = 0; oldY2 = 0; if (action == MotionEvent.ACTION_POINTER_UP) { oldX = -1; oldY = -1; } } return !mRenderer.isClickEnabled(); }
@Override public boolean onTouchEvent(MotionEvent event) { boolean handled = true; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { // 删除按钮接收事件 if (mShowDashBorder && mDelDrawRectF.contains(event.getX(), event.getY())) { if (getParent() instanceof ViewGroup) { ((ViewGroup) getParent()).removeView(DashFrameLayout.this); } break; } // 拖放按钮接收事件 if (mShowDashBorder && mDragDrawRectF.contains(event.getX(), event.getY())) { mode = SINGLE_ZOOM; showDashBorder(true); mPreDistance = Utils.calcDistance(mCenterPoint[0], mCenterPoint[1], event.getX(), event.getY()); mPreRotation = Utils.calcRotation(mCenterPoint[0], mCenterPoint[1], event.getX(), event.getY()); break; } /** 判断虚线框是否接收事件; 因旋转后无法直接判断事件是否在rect内, 可将坐标点反向旋转后再与未进行旋转的rect进行比较判断 */ mDashDrawRectF.set(mDashRectF); mViewNoRotateMatrix.mapRect(mDashDrawRectF); Matrix inverseMatrix = new Matrix(); // 获取反向旋转矩阵 inverseMatrix.postRotate(360 - mCurRotation, mCenterPoint[0], mCenterPoint[1]); // 将当前坐标反向旋转,再进行判断 float[] eventPoint = {event.getX(), event.getY()}; inverseMatrix.mapPoints(eventPoint); if (mDashDrawRectF.contains(eventPoint[0], eventPoint[1])) { mode = DRAG; mInitTouchX = event.getX(); mInitTouchY = event.getY(); mLastTouchX = event.getX(); mLastTouchY = event.getY(); } else { handled = false; } showDashBorder(handled); if (handled && mListener != null) { mListener.onFocus(); mAlwaysInTapRegion = true; } break; } case MotionEvent.ACTION_MOVE: { if (mAlwaysInTapRegion) { float deltaX = event.getX() - mInitTouchX; float deltaY = event.getY() - mInitTouchY; // 判断是否在点击区域内 if ((deltaX * deltaX) + (deltaY * deltaY) > mTouchSlopSquare) { mAlwaysInTapRegion = false; } } if (mode == SINGLE_ZOOM || mode == DOUBLE_ZOOM) { float curDistance, endRotation; if (mode == SINGLE_ZOOM) { // 单指缩放、旋转 curDistance = Utils.calcDistance(mCenterPoint[0], mCenterPoint[1], event.getX(), event.getY()); endRotation = Utils.calcRotation(mCenterPoint[0], mCenterPoint[1], event.getX(), event.getY()); } else { // 双指缩放、旋转 curDistance = Utils.calcDistance(event); endRotation = Utils.calcRotation(event); } scale(curDistance / mPreDistance); mPreDistance = curDistance; rotate(endRotation - mPreRotation); mPreRotation = endRotation; } else if (mode == DRAG) { translate(event.getX() - mLastTouchX, event.getY() - mLastTouchY); mLastTouchX = event.getX(); mLastTouchY = event.getY(); } invalidate(); break; } case MotionEvent.ACTION_POINTER_DOWN: { mAlwaysInTapRegion = false; if (mode != SINGLE_ZOOM) { mode = DOUBLE_ZOOM; mPreDistance = Utils.calcDistance(event); mPreRotation = Utils.calcRotation(event); } break; } case MotionEvent.ACTION_UP: { mode = NONE; mPreRotation = 0.f; if (mAlwaysInTapRegion && mPreShowDashBorder && mListener != null) { mListener.onClick(); } mAlwaysInTapRegion = false; break; } case MotionEvent.ACTION_POINTER_UP: { if (mode != SINGLE_ZOOM) { mode = NONE; mPreRotation = 0.f; } break; } } return handled; }
final boolean hitTest(float x, float y) { return bounds.contains(x, y); }
/** Call this from a drag source view. */ public boolean onTouchEvent(MotionEvent ev) { View scrollView = mScrollView; if (!mDragging) { return false; } final int action = ev.getAction(); final int screenX = clamp((int) ev.getRawX(), 0, mDisplayMetrics.widthPixels); final int screenY = clamp((int) ev.getRawY(), 0, mDisplayMetrics.heightPixels); switch (action) { case MotionEvent.ACTION_DOWN: // Remember where the motion event started mMotionDownX = screenX; mMotionDownY = screenY; mScrollState = SCROLL_OUTSIDE_ZONE; /* * if ((screenX < mScrollZone) || (screenX > scrollView.getWidth() - mScrollZone)) { * mScrollState = SCROLL_WAITING_IN_ZONE; * mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); * } else { * mScrollState = SCROLL_OUTSIDE_ZONE; * } */ break; case MotionEvent.ACTION_MOVE: // Update the drag view. Don't use the clamped pos here so the dragging looks // like it goes off screen a little, intead of bumping up against the edge. mDragView.move((int) ev.getRawX(), (int) ev.getRawY()); // Drop on someone? final int[] coordinates = mCoordinatesTemp; DropTarget dropTarget = findDropTarget(screenX, screenY, coordinates); if (dropTarget != null) { if (mLastDropTarget == dropTarget) { dropTarget.onDragOver( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); } else { if (mLastDropTarget != null) { mLastDropTarget.onDragExit( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); } dropTarget.onDragEnter( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); } } else { if (mLastDropTarget != null) { mLastDropTarget.onDragExit( mDragSource, coordinates[0], coordinates[1], (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); } } mLastDropTarget = dropTarget; // Scroll, maybe, but not if we're in the delete region. boolean inDeleteRegion = false; if (mDeleteRegion != null) { inDeleteRegion = mDeleteRegion.contains(screenX, screenY); } /* * if(screenY < 100) { * mDragScroller.scrollUp(); * } else if(screenY > mDisplayMetrics.heightPixels - 100) { * mDragScroller.scrollDown(); * } */ /* * //Log.d(Launcher.TAG, "inDeleteRegion=" + inDeleteRegion + " screenX=" + screenX * // + " mScrollZone=" + mScrollZone); * if (!inDeleteRegion && screenX < mScrollZone) { * if (mScrollState == SCROLL_OUTSIDE_ZONE) { * mScrollState = SCROLL_WAITING_IN_ZONE; * mScrollRunnable.setDirection(SCROLL_LEFT); * mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); * } * } else if (!inDeleteRegion && screenX > scrollView.getWidth() - mScrollZone) { * if (mScrollState == SCROLL_OUTSIDE_ZONE) { * mScrollState = SCROLL_WAITING_IN_ZONE; * mScrollRunnable.setDirection(SCROLL_RIGHT); * mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); * } * } else { * if (mScrollState == SCROLL_WAITING_IN_ZONE) { * mScrollState = SCROLL_OUTSIDE_ZONE; * mScrollRunnable.setDirection(SCROLL_RIGHT); * mHandler.removeCallbacks(mScrollRunnable); * } * } */ break; case MotionEvent.ACTION_UP: mHandler.removeCallbacks(mScrollRunnable); if (mDragging) { drop(screenX, screenY); } endDrag(); break; case MotionEvent.ACTION_CANCEL: cancelDrag(); } return true; }
private void drawGreyFrame(Canvas canvas, RectF bBox, Transformation t) { paper.set( t.offset_x, t.offset_y, t.offset_x + aspectRatio.ratio * t.scale, t.offset_y + t.scale); if (!paper.contains(bBox)) canvas.drawARGB(0xff, 0xaa, 0xaa, 0xaa); }