Java Code Examples for android.view.ScaleGestureDetector#getScaleFactor()

The following examples show how to use android.view.ScaleGestureDetector#getScaleFactor() . 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: ScaleImageView.java    From Tok-Android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    float scale = getScale();
    float scaleFactor = detector.getScaleFactor();
    Log.e("ScaleGestrueDetector", "scaleFactor:" + scaleFactor);
    if (getDrawable() == null) {
        return true;
    }
    if ((scale < mMaxScale && scaleFactor > 1.0f) || (scale > mInitScale
        && scaleFactor < 1.0f)) {
        if (scale * scaleFactor > mMaxScale) {
            scaleFactor = mMaxScale / scale;
        }
        if (scale * scaleFactor < mInitScale) {
            scaleFactor = mInitScale / scale;
        }

        mMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
        checkBorderAndCenterWhenScale();
        setImageMatrix(mMatrix);
    }

    return true;
}
 
Example 2
Source File: PinchScaleDetector.java    From sensey with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector scaleGestureDetector) {

    float scaleFactor = scaleGestureDetector.getScaleFactor();
    if (scaleFactor > 1) {
        countOfScaleIn += 1;
        if (eventOccurred != 1 && countOfScaleIn > 2) {
            eventOccurred = 1;
            pinchScaleListener.onScale(scaleGestureDetector, true);
        }
    } else {
        countOfScaleOut += 1;
        if (eventOccurred != 2 && countOfScaleOut > 2) {
            eventOccurred = 2;
            pinchScaleListener.onScale(scaleGestureDetector, false);
        }
    }
    return true;
}
 
Example 3
Source File: PinchGestureLayout.java    From Lassi-Android with MIT License 6 votes vote down vote up
@Override
protected void onInitialize(@NonNull Context context) {
    super.onInitialize(context);
    mPoints = new PointF[]{new PointF(0, 0), new PointF(0, 0)};
    mDetector = new ScaleGestureDetector(context, new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            mNotify = true;
            mFactor = ((detector.getScaleFactor() - 1) * ADD_SENSITIVITY);
            return true;
        }
    });

    if (Build.VERSION.SDK_INT >= 19) {
        mDetector.setQuickScaleEnabled(false);
    }

    // We listen only to the pinch type.
    setGestureType(Gesture.PINCH);
}
 
Example 4
Source File: LineScrollAndScaleView.java    From kAndroid with Apache License 2.0 6 votes vote down vote up
/******************************缩放手势*****************************************/
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (isClosePress) {
        if (!isScaleEnable()) {
            return false;
        }
        float oldScale = mScaleX;
        mScaleX *= detector.getScaleFactor();
        if (mScaleX < mScaleXMin) {
            mScaleX = mScaleXMin;

        } else if (mScaleX > mScaleXMax) {
            mScaleX = mScaleXMax;

        } else {
            onScaleChanged(mScaleX, oldScale);
        }

        Log.i("22222222222222", mScaleX + "");
        if (mScaleX >= 2.0f || mScaleX <= 0.5f) {
            isScale = true;
        }
    }
    return true;
}
 
Example 5
Source File: ZoomableTouchListener.java    From GoogleMapView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (mZoomableView == null) return false;

    mScaleFactor *= detector.getScaleFactor();

    // Don't let the object get too large.
    mScaleFactor = Math.max(MIN_SCALE_FACTOR, Math.min(mScaleFactor, MAX_SCALE_FACTOR));

    mZoomableView.setScaleX(mScaleFactor);
    mZoomableView.setScaleY(mScaleFactor);
    obscureDecorView(mScaleFactor);

    return true;
}
 
Example 6
Source File: SvgAndroidSampleActivity.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    float scale = detector.getScaleFactor();
    mMatrix.postScale(scale, scale);
    mImageView.setImageMatrix(mMatrix);
    return true;
}
 
Example 7
Source File: GestureManager.java    From XImageView with Apache License 2.0 5 votes vote down vote up
/*************************************缩放**************************************/

    @Override
    public boolean onScale(ScaleGestureDetector detector)
    {
        if (mBM == null) {
            return false;
        }

        float factor = detector.getScaleFactor();
        mBM.scale(detector.getFocusX(), detector.getFocusY(), factor);

        return true;
    }
 
Example 8
Source File: RemoteCamera.java    From GoFIT_SDK_Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    mScaleLevel = detector.getScaleFactor() > 1
            ? mScaleLevel + detector.getScaleFactor()
            : mScaleLevel - detector.getScaleFactor();
    mScaleLevel = Math.max(1f, Math.min(mScaleLevel, mMaxLevel + 1));
    CameraClass.cameraSetZoom((int) mScaleLevel - 1);
    return true;
}
 
Example 9
Source File: TouchImageView.java    From ChatApp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector)
{
    float mScaleFactor = detector.getScaleFactor();
    float origScale = saveScale;

    saveScale *= mScaleFactor;

    if(saveScale > maxScale)
    {
        saveScale = maxScale;
        mScaleFactor = maxScale / origScale;
    }
    else if(saveScale < minScale)
    {
        saveScale = minScale;
        mScaleFactor = minScale / origScale;
    }

    if(origWidth * saveScale <= viewWidth || origHeight * saveScale <= viewHeight)
    {
        matrix.postScale(mScaleFactor, mScaleFactor, viewWidth / 2, viewHeight / 2);
    }
    else
    {
        matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY());
    }

    fixTrans();

    return true;
}
 
Example 10
Source File: BaseGridScaler.java    From MultiView with Apache License 2.0 5 votes vote down vote up
@Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            Log.d("onScaleEnd: " + detector.getFocusX() + "/" + detector.getFocusY()
                    + " : " + detector.getCurrentSpan() + "/" + detector.getScaleFactor()
                    + "/" + factorOffset
                    + " : " + detector.getEventTime());

            float currFactor = detector.getScaleFactor() + factorOffset;

            if (currFactor > 1f + (1f / (float) (initSpanCount - 1)) / 2f) {
                if (initSpanCount == minSpan) {
                    //do nothing we reached our max span
                } else {
                    scale(1f, initSpanCount - 1, null);
                }
            } else if (currFactor < 1f - (1f / (float) (initSpanCount + 1)) / 2f) {
                scale(1f, initSpanCount + 1, null);
            } else {
                if (((GridLayoutManager) recyclerView.getLayoutManager()).getSpanCount() != initSpanCount) {
                    scale(1f, initSpanCount, null);
                }
            }


            if (initSpanCount != ((GridLayoutManager) recyclerView.getLayoutManager()).getSpanCount()) {
                //recyclerView.getLayoutManager().scrollToPosition(recyclerView.getChildAdapterPosition(currentView));
            }
            currScale = 1f;
            initSpanCount = 0;
//            recyclerView.getLayoutManager().requestLayout();
//            recyclerView.invalidate();

            currentView = null;
        }
 
Example 11
Source File: XYScrollView.java    From xpra-client with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
	Log.i("ads", "onScale(): " + detector.getScaleFactor());
	float scaleFactor = detector.getScaleFactor();
	getChildView().setScaleX(originScaleX * scaleFactor);
	getChildView().setScaleY(originScaleY * scaleFactor);
	return false;
}
 
Example 12
Source File: ChartTouchHandler.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    if (isZoomEnabled) {
        float scale = 2.0f - detector.getScaleFactor();
        if (Float.isInfinite(scale)) {
            scale = 1;
        }
        return chartZoomer.scale(computator, detector.getFocusX(), detector.getFocusY(), scale);
    }

    return false;
}
 
Example 13
Source File: CameraPreviewFrameView.java    From PLDroidRTCStreaming with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    // factor > 1, zoom
    // factor < 1, pinch
    mScaleFactor *= detector.getScaleFactor();

    // Don't let the object get too small or too large.
    mScaleFactor = Math.max(0.01f, Math.min(mScaleFactor, 1.0f));

    return mListener != null && mListener.onZoomValueChanged(mScaleFactor);
}
 
Example 14
Source File: OverlayPinchImageView.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onScale(@NonNull final ScaleGestureDetector detector) {
	mPupilOverlayScaleFactor *= detector.getScaleFactor();
	// Don't let the object get too small or too large.
	mPupilOverlayScaleFactor =
			Math.max(MIN_PUPIL_SCALE_FACTOR, Math.min(mPupilOverlayScaleFactor, MAX_PUPIL_SCALE_FACTOR));
	invalidate();
	return true;
}
 
Example 15
Source File: ImageSurfaceView.java    From WorldmapLibrary with MIT License 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    float scaleFactor = detector.getScaleFactor();
    if (scaleFactor!=0f && scaleFactor!=1.0f){
        scaleFactor = 1/scaleFactor;
        screenFocus.set(detector.getFocusX(),detector.getFocusY());
        scene.getViewport().zoom(
                scaleFactor,
                screenFocus);
        invalidate();
    }
    lastScaleTime = System.currentTimeMillis();
    return true;
}
 
Example 16
Source File: DragPinchManager.java    From AndroidPdfViewerV2 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    float dr = detector.getScaleFactor();
    float wantedZoom = pdfView.getZoom() * dr;
    if (wantedZoom < MINIMUM_ZOOM) {
        dr = MINIMUM_ZOOM / pdfView.getZoom();
    } else if (wantedZoom > MAXIMUM_ZOOM) {
        dr = MAXIMUM_ZOOM / pdfView.getZoom();
    }
    pdfView.zoomCenteredRelativeTo(dr, new PointF(detector.getFocusX(), detector.getFocusY()));
    return true;
}
 
Example 17
Source File: CameraPreviewFrameView.java    From react-native-pili with MIT License 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    // factor > 1, zoom
    // factor < 1, pinch
    mScaleFactor *= detector.getScaleFactor();

    // Don't let the object get too small or too large.
    mScaleFactor = Math.max(0.01f, Math.min(mScaleFactor, 1.0f));

    return mListener != null && mListener.onZoomValueChanged(mScaleFactor);
}
 
Example 18
Source File: ZoomImageView.java    From Android-ImagesPickers with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {

    float scale = getScale();
    // 获得手势缩放的值
    float scaleFactor = detector.getScaleFactor();
    if (getDrawable() == null) {
        return true;
    }
    // 当前图片的缩放值小于最大的缩放值且检测到手势想放大,或者当前图片的缩放值大于最小的缩放值且检测到手势想缩小
    if ((scale < mMaxScale && scaleFactor > 1.0f)
            || (scale > mInitScale && scaleFactor < 1.0f)) {
        if (scale * scaleFactor < mInitScale) {
            scaleFactor = mInitScale / scale;
        }
        if (scale * scaleFactor > mMaxScale) {
            scaleFactor = mMaxScale / scale;
        }

        // detector.getFocusX(),detector.getFocusY()获取缩放时的中心坐标
        matrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(),
                detector.getFocusY());

        checkBorderAndCenterWhenScale();

        setImageMatrix(matrix);
    }
    return true;
}
 
Example 19
Source File: ScaleDragDetector.java    From PhotoDraweeView with Apache License 2.0 5 votes vote down vote up
@Override public boolean onScale(ScaleGestureDetector detector) {
    float scaleFactor = detector.getScaleFactor();

    if (Float.isNaN(scaleFactor) || Float.isInfinite(scaleFactor)) {
        return false;
    }

    mScaleDragGestureListener.onScale(scaleFactor, detector.getFocusX(), detector.getFocusY());
    return true;
}
 
Example 20
Source File: OverlayDisplayWindow.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
@Override
public boolean onScale(ScaleGestureDetector detector) {
    mLiveScale *= detector.getScaleFactor();
    relayout();
    return true;
}