Java Code Examples for android.view.ScaleGestureDetector#SimpleOnScaleGestureListener
The following examples show how to use
android.view.ScaleGestureDetector#SimpleOnScaleGestureListener .
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: PinchGestureLayout.java From Lassi-Android with MIT License | 6 votes |
@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 2
Source File: NeopixelActivity.java From Bluefruit_LE_Connect_Android with MIT License | 6 votes |
private void setupZoomGesture() { mGestureDetector = new GestureDetector(this, new GestureListener()); mScaleDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(ScaleGestureDetector detector) { float scale = 1 - detector.getScaleFactor(); mBoardScale += scale; if (mBoardScale < kMinBoardScale) mBoardScale = kMinBoardScale; if (mBoardScale > kMaxBoardScale) mBoardScale = kMaxBoardScale; mBoardContentView.setScaleX(1f / mBoardScale); mBoardContentView.setScaleY(1f / mBoardScale); return true; } }); }
Example 3
Source File: NeopixelFragment.java From Bluefruit_LE_Connect_Android_V2 with MIT License | 5 votes |
private void setupGestures() { mGestureDetector = new GestureDetector(getContext(), new GestureListener()); mScaleDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(ScaleGestureDetector detector) { float scale = 1 - detector.getScaleFactor(); mBoardScale += scale; if (mBoardScale < kMinBoardScale) mBoardScale = kMinBoardScale; if (mBoardScale > kMaxBoardScale) mBoardScale = kMaxBoardScale; Log.d(TAG, "Board scale: " + mBoardScale); mBoardContentView.setScaleX(1f / mBoardScale); mBoardContentView.setScaleY(1f / mBoardScale); return true; } }); mCustomPanningView.setOnTouchListener((view, motionEvent) -> { // Make the GestureDetectors work: https://stackoverflow.com/questions/11421368/android-fragment-oncreateview-with-gestures/11421565#11421565 final boolean scaleResult = mGestureDetector.onTouchEvent(motionEvent); /*final boolean gestureResult = */ mScaleDetector.onTouchEvent(motionEvent); //Log.d(TAG, "scaleResult: " + scaleResult + " gestureResult: " + gestureResult); return scaleResult;// || gestureResult; }); }
Example 4
Source File: ImageViewerView.java From photo-viewer with Apache License 2.0 | 5 votes |
private void init() { inflate(getContext(), R.layout.image_viewer, this); backgroundView = findViewById(R.id.backgroundView); pager = (MultiTouchViewPager) findViewById(R.id.pager); dismissContainer = (ViewGroup) findViewById(R.id.container); swipeDismissListener = new SwipeToDismissListener(findViewById(R.id.dismissView), this, this); dismissContainer.setOnTouchListener(swipeDismissListener); directionDetector = new SwipeDirectionDetector(getContext()) { @Override public void onDirectionDetected(Direction direction) { ImageViewerView.this.direction = direction; } }; scaleDetector = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener()); gestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (pager.isScrolled()) { onClick(e, isOverlayWasClicked); } return false; } }); }
Example 5
Source File: PinchToZoomDraweeView.java From droidddle with Apache License 2.0 | 5 votes |
public PinchToZoomDraweeView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mScaleListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(ScaleGestureDetector detector) { float scaleFactor = detector.getScaleFactor(); float newScale = mCurrentScale * scaleFactor; // Prevent from zooming out more than original if (newScale > 1.0f) { // We initialize this lazily so that we don't have to register (and force the user // to unregister) a global layout listener on the view. if (mMidX == 0.0f) { mMidX = getWidth() / 2.0f; } if (mMidY == 0.0f) { mMidY = getHeight() / 2.0f; } mCurrentScale = newScale; mCurrentMatrix.postScale(scaleFactor, scaleFactor, mMidX, mMidY); invalidate(); } else { scaleFactor = 1.0f / mCurrentScale; reset(); } if (mListener != null && scaleFactor != 1.0f) { mListener.onZoomChange(mCurrentScale); } return true; } }; mScaleDetector = new ScaleGestureDetector(getContext(), mScaleListener); mCurrentMatrix = new Matrix(); }
Example 6
Source File: SimplePhotoView.java From droidddle with Apache License 2.0 | 4 votes |
public SimplePhotoView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); //initialize ScaleGestureDetector. Capture the mScaleListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(ScaleGestureDetector detector) { float scaleFactor = detector.getScaleFactor(); float newScale = mCurrentScale * scaleFactor; // LogUtils.d("scaleFactor=" + scaleFactor + ",newScale=" + newScale); // Prevent from zooming out more than original if (newScale > 1.0f && newScale < SCALE_MAX) { if (mMidX == 0.0f) { mMidX = getWidth() / 2;//from center to zoom } if (mMidY == 0.0f) { mMidY = getHeight() / 2;//from center to zoom } mCurrentScale = newScale; SimplePhotoView.this.postDelayed(new AutoRunableZoom(newScale), 16); } else if (newScale > SCALE_MAX) { newScale = SCALE_MAX; mCurrentScale = newScale; } return true; } }; mScaleDetector = new ScaleGestureDetector(getContext(), mScaleListener); mCurrentMatrix = new Matrix(); //initialize GestureDetector, Capture double tap event mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTap(MotionEvent e) { float newscale = 0.0f; if (mCurrentScale == 1.0f) { newscale = SCALE_MID; } else if (mCurrentScale >= SCALE_MID && mCurrentScale < SCALE_MAX) { newscale = SCALE_MAX; } else if (mCurrentScale >= SCALE_MAX) { newscale = 1.0f; } mCurrentScale = newscale; SimplePhotoView.this.postDelayed(new AutoRunableZoom(newscale), 16); isAutoScale = true; return true; } }); this.setOnTouchListener(this); }