Java Code Examples for android.view.ScaleGestureDetector#getFocusX()
The following examples show how to use
android.view.ScaleGestureDetector#getFocusX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapViewScaleGestureDetectorListener.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public boolean onScale(ScaleGestureDetector detector) { if (!scaling) { return true; } currentScale = detector.getCurrentSpan() / firstSpan; float focusX = detector.getFocusX(); float focusY = detector.getFocusY(); this.mapView.setScale(currentScale); this.mapView.getController().offsetDeltaScroll(lastFocusX - focusX, lastFocusY - focusY); this.mapView.getController().panBy(lastFocusX - focusX, lastFocusY - focusY, true); lastFocusX = focusX; lastFocusY = focusY; return true; }
Example 2
Source File: GestureController.java From GestureViews with Apache License 2.0 | 6 votes |
@SuppressWarnings("WeakerAccess") // Public API (can be overridden) protected boolean onScale(ScaleGestureDetector detector) { if (!settings.isZoomEnabled() || isAnimatingState()) { return false; // Ignoring scroll if animation is in progress } final float scaleFactor = detector.getScaleFactor(); boolean scaleConsumed = exitController.onScale(scaleFactor); if (scaleConsumed) { return true; } pivotX = detector.getFocusX(); pivotY = detector.getFocusY(); state.zoomBy(scaleFactor, pivotX, pivotY); isStateChangedDuringTouch = true; return true; }
Example 3
Source File: CropOverlayView.java From timecat with Apache License 2.0 | 6 votes |
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onScale(ScaleGestureDetector detector) { RectF rect = mCropWindowHandler.getRect(); float x = detector.getFocusX(); float y = detector.getFocusY(); float dY = detector.getCurrentSpanY() / 2; float dX = detector.getCurrentSpanX() / 2; float newTop = y - dY; float newLeft = x - dX; float newRight = x + dX; float newBottom = y + dY; if (newLeft < newRight && newTop <= newBottom && newLeft >= 0 && newRight <= mCropWindowHandler.getMaxCropWidth() && newTop >= 0 && newBottom <= mCropWindowHandler.getMaxCropHeight()) { rect.set(newLeft, newTop, newRight, newBottom); mCropWindowHandler.setRect(rect); invalidate(); } return true; }
Example 4
Source File: ScaleImageView.java From ViewPagerHelper with Apache License 2.0 | 6 votes |
@Override public boolean onScale(ScaleGestureDetector detector) { //拿到缩放比例 float scale = getScale(); float scaleFactor = detector.getScaleFactor(); //拿到缩放中心 float focusX = detector.getFocusX(); float focusY = detector.getFocusY(); //默认不能缩放至屏幕控件大小 if (mIsLimitBroad) { if (scale * scaleFactor < mDeflautScale) { //重新复制,让它逼近于最小值 scaleFactor = mDeflautScale / scale; } if (scale * scaleFactor > mMaxScale) { scaleFactor = mMaxScale / scale; } } mMatrix.postScale(scaleFactor,scaleFactor,focusX,focusY); checkBroad(); setImageMatrix(mMatrix); return true; }
Example 5
Source File: MultiTouchHandler.java From Alite with GNU General Public License v3.0 | 6 votes |
@Override public boolean onScale(ScaleGestureDetector detector) { zoomFactor *= detector.getScaleFactor(); // Don't let the object get too small or too large. zoomFactor = Math.max(1.0f, Math.min(zoomFactor, 8.0f)); TouchEvent touchEvent = touchEventPool.newObject(); touchEvent.type = TouchEvent.TOUCH_SCALE; touchEvent.x2 = (int) ((detector.getFocusX() - offsetX) * scaleX); touchEvent.y2 = (int) ((detector.getFocusY() - offsetY) * scaleY); touchEvent.zoomFactor = zoomFactor; touchEventsBuffer.add(touchEvent); return true; }
Example 6
Source File: DocViewBase.java From Mupdf with Apache License 2.0 | 5 votes |
public boolean onScale(ScaleGestureDetector detector) { // new scale factor float previousScale = mScale; mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE); // did we really scale? if (mScale == previousScale) return true; // scale children scaleChildren(); // maintain focus while scaling double scale = mScale / previousScale; double currentFocusX = detector.getFocusX(); double currentFocusY = detector.getFocusY(); double viewFocusX = (int) currentFocusX + getScrollX(); double viewFocusY = (int) currentFocusY + getScrollY(); int diffX = (int) (viewFocusX * (1 - scale)); int diffY = (int) (viewFocusY * (1 - scale)); mXScroll += diffX; mYScroll += diffY; requestLayout(); return true; }
Example 7
Source File: CropOverlayView.java From Lassi-Android with MIT License | 5 votes |
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onScale(ScaleGestureDetector detector) { RectF rect = mCropWindowHandler.getRect(); float x = detector.getFocusX(); float y = detector.getFocusY(); float dY = detector.getCurrentSpanY() / 2; float dX = detector.getCurrentSpanX() / 2; float newTop = y - dY; float newLeft = x - dX; float newRight = x + dX; float newBottom = y + dY; if (newLeft < newRight && newTop <= newBottom && newLeft >= 0 && newRight <= mCropWindowHandler.getMaxCropWidth() && newTop >= 0 && newBottom <= mCropWindowHandler.getMaxCropHeight()) { rect.set(newLeft, newTop, newRight, newBottom); mCropWindowHandler.setRect(rect); invalidate(); } return true; }
Example 8
Source File: ReaderView.java From Mupdf with Apache License 2.0 | 5 votes |
public boolean onScale(ScaleGestureDetector detector) { float previousScale = mScale; mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE); { float factor = mScale/previousScale; View v = mChildViews.get(mCurrent); if (v != null) { float currentFocusX = detector.getFocusX(); float currentFocusY = detector.getFocusY(); // Work out the focus point relative to the view top left int viewFocusX = (int)currentFocusX - (v.getLeft() + mXScroll); int viewFocusY = (int)currentFocusY - (v.getTop() + mYScroll); // Scroll to maintain the focus point mXScroll += viewFocusX - viewFocusX * factor; mYScroll += viewFocusY - viewFocusY * factor; if (mLastScaleFocusX>=0) mXScroll+=currentFocusX-mLastScaleFocusX; if (mLastScaleFocusY>=0) mYScroll+=currentFocusY-mLastScaleFocusY; mLastScaleFocusX=currentFocusX; mLastScaleFocusY=currentFocusY; requestLayout(); } } return true; }
Example 9
Source File: ValueLineChart.java From EazeGraph with Apache License 2.0 | 5 votes |
@Override public boolean onScale(ScaleGestureDetector scaleGestureDetector) { mIsInteracting = true; Matrix transformationMatrix = new Matrix(); float focusX = scaleGestureDetector.getFocusX(); float focusY = scaleGestureDetector.getFocusY(); float scaleX = ScaleGestureDetectorCompat.getCurrentSpanX(scaleGestureDetector) / ScaleGestureDetectorCompat.getPreviousSpanX(scaleGestureDetector); float scaleY = ScaleGestureDetectorCompat.getCurrentSpanY(scaleGestureDetector) / ScaleGestureDetectorCompat.getPreviousSpanY(scaleGestureDetector); //Zoom focus is where the fingers are centered, transformationMatrix.postTranslate(-focusX, -focusY); transformationMatrix.postScale(scaleX, scaleY); float focusShiftX = focusX - mLastFocusX; float focusShiftY = focusY - mLastFocusY; transformationMatrix.postTranslate(focusX + focusShiftX, focusY + focusShiftY); mDrawMatrix.postConcat(transformationMatrix); constrainView(); recalculateXCoordinates(mGraphWidth * mDrawMatrixValues[0]); if(calculateLegendBounds()) Utils.calculateLegendInformation(mSeries.get(0).getSeries(), 0, mGraphWidth * mDrawMatrixValues[0], mLegendPaint); mLastFocusX = focusX; mLastFocusY = focusY; if(mFocusedPoint != null) { calculateValueTextHeight(); } invalidateGlobal(); return true; }
Example 10
Source File: MapViewScaleGestureDetectorListener.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public boolean onScaleBegin(ScaleGestureDetector detector) { lastFocusX = detector.getFocusX(); lastFocusY = detector.getFocusY(); firstSpan = detector.getCurrentSpan(); currentScale = 1.0f; if (!this.mapView.isAnimating()) { this.mapView.setIsAnimating(true); this.mapView.getController().aboutToStartAnimation(lastFocusX, lastFocusY); scaling = true; } return true; }
Example 11
Source File: DrawingView.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean onScale(ScaleGestureDetector detector) { mScaleFactor *= detector.getScaleFactor(); mScalePointX = detector.getFocusX(); mScalePointY = detector.getFocusY(); // Don't let the object get too small or too large. mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f)); invalidate(); return true; }
Example 12
Source File: CropOverlayView.java From Android-Image-Cropper with Apache License 2.0 | 5 votes |
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onScale(ScaleGestureDetector detector) { RectF rect = mCropWindowHandler.getRect(); float x = detector.getFocusX(); float y = detector.getFocusY(); float dY = detector.getCurrentSpanY() / 2; float dX = detector.getCurrentSpanX() / 2; float newTop = y - dY; float newLeft = x - dX; float newRight = x + dX; float newBottom = y + dY; if (newLeft < newRight && newTop <= newBottom && newLeft >= 0 && newRight <= mCropWindowHandler.getMaxCropWidth() && newTop >= 0 && newBottom <= mCropWindowHandler.getMaxCropHeight()) { rect.set(newLeft, newTop, newRight, newBottom); mCropWindowHandler.setRect(rect); invalidate(); } return true; }
Example 13
Source File: Chart.java From JZAndroidChart with Apache License 2.0 | 5 votes |
@Override public boolean onScale(ScaleGestureDetector scaleGestureDetector) { if (!mScaleXEnable) return false; if (!mScaleGestureEnable) return super.onScale(scaleGestureDetector); float spanX = scaleGestureDetector.getCurrentSpanX(); float newWidth = lastSpanX / spanX * mCurrentViewport.width(); if (newWidth < mCurrentViewport.width() && mCurrentViewport.width() < 0.001) { return true; } float focusX = scaleGestureDetector.getFocusX(); float focusY = scaleGestureDetector.getFocusY(); hitTest(focusX, focusY, viewportFocus); mCurrentViewport.left = viewportFocus.x - newWidth * (focusX - mContentRect.left) / mContentRect.width(); mCurrentViewport.right = mCurrentViewport.left + newWidth; mCurrentViewport.constrainViewport(); triggerViewportChange(); lastSpanX = spanX; return true; }
Example 14
Source File: ReaderView.java From AndroidMuPDF with Apache License 2.0 | 5 votes |
public boolean onScale(ScaleGestureDetector detector) { float previousScale = mScale; mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE); { float factor = mScale/previousScale; View v = mChildViews.get(mCurrent); if (v != null) { float currentFocusX = detector.getFocusX(); float currentFocusY = detector.getFocusY(); // Work out the focus point relative to the view top left int viewFocusX = (int)currentFocusX - (v.getLeft() + mXScroll); int viewFocusY = (int)currentFocusY - (v.getTop() + mYScroll); // Scroll to maintain the focus point mXScroll += viewFocusX - viewFocusX * factor; mYScroll += viewFocusY - viewFocusY * factor; if (mLastScaleFocusX>=0) mXScroll+=currentFocusX-mLastScaleFocusX; if (mLastScaleFocusY>=0) mYScroll+=currentFocusY-mLastScaleFocusY; mLastScaleFocusX=currentFocusX; mLastScaleFocusY=currentFocusY; requestLayout(); } } return true; }
Example 15
Source File: ReaderView.java From AndroidDocumentViewer with MIT License | 5 votes |
public boolean onScale(ScaleGestureDetector detector) { float previousScale = mScale; mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE); { float factor = mScale / previousScale; View v = mChildViews.get(mCurrent); if (v != null) { float currentFocusX = detector.getFocusX(); float currentFocusY = detector.getFocusY(); // Work out the focus point relative to the view top left int viewFocusX = (int) currentFocusX - (v.getLeft() + mXScroll); int viewFocusY = (int) currentFocusY - (v.getTop() + mYScroll); // Scroll to maintain the focus point mXScroll += viewFocusX - viewFocusX * factor; mYScroll += viewFocusY - viewFocusY * factor; if (mLastScaleFocusX >= 0) mXScroll += currentFocusX - mLastScaleFocusX; if (mLastScaleFocusY >= 0) mYScroll += currentFocusY - mLastScaleFocusY; mLastScaleFocusX = currentFocusX; mLastScaleFocusY = currentFocusY; requestLayout(); } } return true; }
Example 16
Source File: ReaderView.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
public boolean onScale(ScaleGestureDetector detector) { float previousScale = mScale; mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), MIN_SCALE), MAX_SCALE); { float factor = mScale / previousScale; View v = mChildViews.get(mCurrent); if (v != null) { float currentFocusX = detector.getFocusX(); float currentFocusY = detector.getFocusY(); // Work out the focus point relative to the view top left int viewFocusX = (int)currentFocusX - (v.getLeft() + mXScroll); int viewFocusY = (int)currentFocusY - (v.getTop() + mYScroll); // Scroll to maintain the focus point mXScroll += viewFocusX - viewFocusX * factor; mYScroll += viewFocusY - viewFocusY * factor; if (mLastScaleFocusX >= 0) mXScroll += currentFocusX - mLastScaleFocusX; if (mLastScaleFocusY >= 0) mYScroll += currentFocusY - mLastScaleFocusY; mLastScaleFocusX = currentFocusX; mLastScaleFocusY = currentFocusY; requestLayout(); } } return true; }
Example 17
Source File: BaseDocView.java From Reader with Apache License 2.0 | 5 votes |
public boolean onScale(ScaleGestureDetector detector) { LogUtils.d(TAG, "ReaderView onScale detector.getScaleFactor()="+detector.getScaleFactor()); float previousScale = mScale; float scale_factor = 1.0f; float min_scale = MIN_SCALE * scale_factor; float max_scale = MAX_SCALE * scale_factor; mScale = Math.min(Math.max(mScale * detector.getScaleFactor(), min_scale), max_scale); mScaleCache.addFirst(detector.getScaleFactor()); float factor = mScale / previousScale; View v = mChildViews.get(mCurrent); if (v != null) { float currentFocusX = detector.getFocusX(); float currentFocusY = detector.getFocusY(); // Work out the focus point relative to the view top left int viewFocusX = (int) currentFocusX - (v.getLeft() + mXScroll); int viewFocusY = (int) currentFocusY - (v.getTop() + mYScroll); LogUtils.d(TAG, "previousScale=" + previousScale + " mScale=" + mScale + " factor=" + factor + " currentFocusX=" + currentFocusX + " currentFocusY=" + currentFocusY + " mXScroll=" + mXScroll + " mYScroll=" + mYScroll + " viewFocusX=" + viewFocusX + " viewFocusY=" + viewFocusY + " mLastScaleFocusX=" + mLastScaleFocusX + " mLastScaleFocusY=" + mLastScaleFocusY ); // Scroll to maintain the focus point mXScroll += viewFocusX - viewFocusX * factor; mYScroll += viewFocusY - viewFocusY * factor; if (mLastScaleFocusX >= 0) mXScroll += currentFocusX - mLastScaleFocusX; if (mLastScaleFocusY >= 0) mYScroll += currentFocusY - mLastScaleFocusY; mLastScaleFocusX = currentFocusX; mLastScaleFocusY = currentFocusY; requestLayout(); } return true; }
Example 18
Source File: CropOverlayView.java From giffun with Apache License 2.0 | 5 votes |
@Override @TargetApi(Build.VERSION_CODES.HONEYCOMB) public boolean onScale(ScaleGestureDetector detector) { RectF rect = mCropWindowHandler.getRect(); float x = detector.getFocusX(); float y = detector.getFocusY(); float dY = detector.getCurrentSpanY() / 2; float dX = detector.getCurrentSpanX() / 2; float newTop = y - dY; float newLeft = x - dX; float newRight = x + dX; float newBottom = y + dY; if (newLeft < newRight && newTop <= newBottom && newLeft >= 0 && newRight <= mCropWindowHandler.getMaxCropWidth() && newTop >= 0 && newBottom <= mCropWindowHandler.getMaxCropHeight()) { rect.set(newLeft, newTop, newRight, newBottom); mCropWindowHandler.setRect(rect); invalidate(); } return true; }
Example 19
Source File: ValueLineChart.java From EazeGraph with Apache License 2.0 | 4 votes |
@Override public boolean onScaleBegin(ScaleGestureDetector detector) { mLastFocusX = detector.getFocusX(); mLastFocusY = detector.getFocusY(); return true; }
Example 20
Source File: Chart.java From InteractiveChart with Apache License 2.0 | 4 votes |
@Override public boolean onScaleBegin(ScaleGestureDetector detector) { scaleFocusX = detector.getFocusX(); return super.onScaleBegin(detector); }