List of usage examples for android.view ScaleGestureDetector getScaleFactor
public float getScaleFactor()
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
@Override public boolean onScale(ScaleGestureDetector detector) { if (!mIsZoomPanSupported) { return false; }// w w w. ja v a 2 s. com float scaleFactor = mMasterImage.getScaleFactor(); scaleFactor = scaleFactor * detector.getScaleFactor(); if (scaleFactor > mMasterImage.getMaxScaleFactor()) { scaleFactor = mMasterImage.getMaxScaleFactor(); } if (scaleFactor < 1.0f) { scaleFactor = 1.0f; } mMasterImage.setScaleFactor(scaleFactor); scaleFactor = mMasterImage.getScaleFactor(); float focusx = detector.getFocusX(); float focusy = detector.getFocusY(); float translateX = (focusx - mStartFocusX) / scaleFactor; float translateY = (focusy - mStartFocusY) / scaleFactor; Point translation = mMasterImage.getTranslation(); translation.x = (int) (mOriginalTranslation.x + translateX); translation.y = (int) (mOriginalTranslation.y + translateY); mMasterImage.setTranslation(translation); invalidate(); return true; }
From source file:com.jsibbold.zoomage.ZoomageView.java
@Override public boolean onScale(ScaleGestureDetector detector) { //calculate value we should scale by, ultimately the scale will be startScale*scaleFactor scaleBy = (startScale * detector.getScaleFactor()) / mValues[Matrix.MSCALE_X]; //what the scaling should end up at after the transformation final float projectedScale = scaleBy * mValues[Matrix.MSCALE_X]; //clamp to the min/max if it's going over if (projectedScale < minScale) { scaleBy = minScale / mValues[Matrix.MSCALE_X]; } else if (projectedScale > maxScale) { scaleBy = maxScale / mValues[Matrix.MSCALE_X]; }/*from w w w .j a va2 s . com*/ return false; }
From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaShootingFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.theta_shooting_mode, null); ThetaDeviceApplication app = (ThetaDeviceApplication) getActivity().getApplication(); ThetaDeviceManager deviceMgr = app.getDeviceManager(); deviceMgr.registerDeviceEventListener(this); mDevice = deviceMgr.getConnectedDevice(); if (mDevice == null) { ThetaDialogFragment.showAlert(getActivity(), getString(R.string.theta_ssid_prefix), getString(R.string.theta_error_disconnect_dialog_message), new DialogInterface.OnClickListener() { @Override// w w w . j av a 2 s. c o m public void onClick(DialogInterface dialogInterface, int i) { getActivity().finish(); } }); return rootView; } mShootingTime = (TextView) rootView.findViewById(R.id.shooting_time); mLiveView = (SphericalImageLiveView) rootView.findViewById(R.id.shooting_preview); mApi = app.getSphericalViewApi(); mLiveView.setViewApi(mApi); mLiveView.setDeviceManager(deviceMgr); initShootingLayouts(rootView); mShootingMode = (Spinner) rootView.findViewById(R.id.theta_shooting_mode); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.theta_shooting_mode_adapter, getResources().getStringArray(R.array.theta_shooting_mode)); mShootingMode.setAdapter(adapter); setRetainInstance(true); if (mShootingTasker == null) { mShootingTasker = new DownloadThetaDataTask(); ShootingModeGetTask shootingGetTask = new ShootingModeGetTask(); mShootingTasker.execute(shootingGetTask); } mLiveView.setOnTouchListener(new View.OnTouchListener() { private boolean mIsEnabledLongTouch = true; @Override public boolean onTouch(final View view, final MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_UP) { mIsEnabledLongTouch = true; return true; } if (motionEvent.getPointerCount() == 1) { if (mIsEnabledLongTouch && motionEvent.getEventTime() - motionEvent.getDownTime() >= 300) { mLiveView.resetCameraDirection(); } } else { mIsEnabledLongTouch = false; mScaleDetector.onTouchEvent(motionEvent); } return true; } }); mScaleDetector = new ScaleGestureDetector(getActivity(), new ScaleGestureDetector.SimpleOnScaleGestureListener() { @Override public boolean onScale(final ScaleGestureDetector detector) { mScaleFactor /= detector.getScaleFactor(); double scale = mScaleFactor; if (scale > MAX_FOV) { scale = MAX_FOV; mScaleFactor = MAX_FOV; } if (scale < MIN_FOV) { scale = MIN_FOV; mScaleFactor = MIN_FOV; } mLiveView.setFOV(scale); return true; } }); rotateShootingButton(getActivity().getResources().getConfiguration()); return rootView; }
From source file:com.google.android.apps.santatracker.dasherdancer.DasherDancerActivity.java
@Override public void onScaleEnd(ScaleGestureDetector detector) { mScaling = false;/*w w w .j av a 2s . c o m*/ if (detector.getScaleFactor() > 1) { //Pinch in if (!mAnimPlaying) { mSoundId = mSoundIds[mPager.getCurrentItem()][Character.ANIM_PINCH_IN]; } AnalyticsManager.sendEvent(getString(R.string.analytics_category_interaction), sCharacters[mPager.getCurrentItem()].getCharacterName(), getString(R.string.analytics_action_pinch_in)); updateGestureAchievements(Character.ANIM_PINCH_IN); loadAnimation(false, sCharacters[mPager.getCurrentItem()].getDuration(Character.ANIM_PINCH_IN), sCharacters[mPager.getCurrentItem()].getFrameIndices(Character.ANIM_PINCH_IN), sCharacters[mPager.getCurrentItem()].getFrames(Character.ANIM_PINCH_IN)); } else if (detector.getScaleFactor() < 1) { //Pinch out if (!mAnimPlaying) { mSoundId = mSoundIds[mPager.getCurrentItem()][Character.ANIM_PINCH_OUT]; } AnalyticsManager.sendEvent(getString(R.string.analytics_category_interaction), sCharacters[mPager.getCurrentItem()].getCharacterName(), getString(R.string.analytics_action_pinch_out)); updateGestureAchievements(Character.ANIM_PINCH_OUT); loadAnimation(false, sCharacters[mPager.getCurrentItem()].getDuration(Character.ANIM_PINCH_OUT), sCharacters[mPager.getCurrentItem()].getFrameIndices(Character.ANIM_PINCH_OUT), sCharacters[mPager.getCurrentItem()].getFrames(Character.ANIM_PINCH_OUT)); } }
From source file:com.pdftron.pdf.controls.ReflowPagerAdapter.java
@Override public boolean onReflowWebViewScale(ScaleGestureDetector detector) { if (!Utils.isIceCreamSandwich()) { // not implement scale gesture for Android API prior to Ice Cream Sandwith return false; }/*from w w w . j a va 2 s.co m*/ mScaleFactor *= detector.getScaleFactor(); // avoid considering a small gesture as scaling if (Math.max(mLastScaleFactor / mScaleFactor, mScaleFactor / mLastScaleFactor) < TH_SCAlE_GESTURE) { return true; } if (mZoomInFlag && mScaleFactor > mLastScaleFactor && mScaleFactor / mLastScaleFactor < mThConsecutiveScales) { return true; } if (!mZoomInFlag && mLastScaleFactor > mScaleFactor && mLastScaleFactor / mScaleFactor < mThConsecutiveScales) { return true; } if (mLastScaleFactor > mScaleFactor) { if (mScaleIndex > 0) { mScaleIndex--; mLastScaleFactor = mScaleFactor = SCALES[mScaleIndex]; if (mZoomInFlag) { mThConsecutiveScales = TH_SCAlE_GESTURE; } mZoomInFlag = false; } } else { if (mScaleIndex < mMaxIndex) { mScaleIndex++; mLastScaleFactor = mScaleFactor = SCALES[mScaleIndex]; if (!mZoomInFlag) { mThConsecutiveScales = TH_SCAlE_GESTURE; } mZoomInFlag = true; } } int position = mViewPager.getCurrentItem(); Integer indexI = mViewIndexes.get(position); if (indexI == null) { AnalyticsHandlerAdapter.getInstance() .sendException(new Exception("Reflow: An error happened trying to retrieve a WebView")); Log.e(TAG, "An error happened trying to get WebView at position " + position); return false; } int index = indexI; ReflowWebView webView = mWebViewRepository.getWebView(index); if (webView == null || mWebViewRepository.isAvailable(index)) { AnalyticsHandlerAdapter.getInstance() .sendException(new Exception("Reflow: An error happened trying to retrieve a WebView")); Log.e(TAG, "An error happened trying to get WebView at position " + position); return false; } setTextZoom(webView); mThConsecutiveScales *= TH_SCAlE_GESTURE; return true; }
From source file:com.guodong.sun.guodong.widget.ZoomImageView.java
@Override public boolean onScale(ScaleGestureDetector detector) { // mMinScale~mMaxScale float scale = getScale(); float scaleFactor = detector.getScaleFactor(); if (getDrawable() == null) return true; // /* w ww .ja va 2s .c o m*/ if ((scale < mMaxScale && scaleFactor > 1.0f) || (scale > mMinScale && scaleFactor < 1.0f)) { if (scale * scaleFactor < mMinScale) { scaleFactor = mMinScale / scale; } if (scale * scaleFactor > mMaxScale) { scale = mMaxScale / scale; } // mScaleMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY()); checkBorderAndCenterWhenScale(); setImageMatrix(mScaleMatrix); } return true; }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
@Override public boolean onScale(ScaleGestureDetector detector) { MasterImage img = MasterImage.getImage(); float scaleFactor = img.getScaleFactor(); scaleFactor = scaleFactor * detector.getScaleFactor(); if (scaleFactor > MasterImage.getImage().getMaxScaleFactor()) { scaleFactor = MasterImage.getImage().getMaxScaleFactor(); }//from w ww. ja v a 2s. com if (scaleFactor < 1.0f) { scaleFactor = 1.0f; } MasterImage.getImage().setScaleFactor(scaleFactor); scaleFactor = img.getScaleFactor(); float focusx = detector.getFocusX(); float focusy = detector.getFocusY(); float translateX = (focusx - mStartFocusX) / scaleFactor; float translateY = (focusy - mStartFocusY) / scaleFactor; Point translation = MasterImage.getImage().getTranslation(); translation.x = (int) (mOriginalTranslation.x + translateX); translation.y = (int) (mOriginalTranslation.y + translateY); MasterImage.getImage().setTranslation(translation); invalidate(); return true; }
From source file:com.appunite.scroll.ScaleImageView.java
@SuppressWarnings("UnusedDeclaration") public ScaleImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final ViewConfiguration viewConfiguration = ViewConfiguration.get(context); mMinEdge = viewConfiguration.getScaledEdgeSlop(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScaleImageView, defStyle, defStyle); assert a != null; Drawable src = null;/* w ww . j av a 2 s.c o m*/ try { mMinWidth = a.getDimensionPixelSize(R.styleable.ScaleImageView_android_minWidth, 0); mMinHeight = a.getDimensionPixelSize(R.styleable.ScaleImageView_android_minHeight, 0); src = a.getDrawable(R.styleable.ScaleImageView_android_src); } finally { a.recycle(); } ScaleGestureDetector.OnScaleGestureListener scaleGestureListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() { /** * This is the active focal point in terms of the viewport. Could be a local * variable but kept here to minimize per-frame allocations. */ private PointF viewportFocus = new PointF(); @Override public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) { final ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } return true; } @Override public boolean onScale(ScaleGestureDetector scaleGestureDetector) { float focusX = scaleGestureDetector.getFocusX(); float focusY = scaleGestureDetector.getFocusY(); float scaleFactor = scaleGestureDetector.getScaleFactor(); float previousScale = mScale; mScale *= scaleFactor; doScale(focusX, focusY, scaleFactor); return true; } }; GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { releaseEdgeEffects(); mScroller.forceFinished(true); ViewCompat.postInvalidateOnAnimation(ScaleImageView.this); return true; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { return performClick(); } @Override public boolean onDoubleTap(MotionEvent e) { mZoomer.forceFinished(true); mZoomStartScale = mScale; mZoomFocalPoint.set(e.getX(), e.getY()); mZoomer.startZoom(ZOOM_AMOUNT); ViewCompat.postInvalidateOnAnimation(ScaleImageView.this); return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { getRealTranslation(mTranslation, mRealTranslation); mRealTranslation.offset(-distanceX, -distanceY); getTranslation(mRealTranslation, mTranslation); computeMaxScrollSize(mMaxScrollBuffer); getImageRect(mRectF); float scrolledX = -mRectF.left; float scrolledY = -mRectF.top; boolean canScrollX = mRectF.left > mContentRect.left || mRectF.right < mContentRect.right; boolean canScrollY = mRectF.top > mContentRect.top || mRectF.bottom < mContentRect.bottom; validateTranslation(); disallowParentInterceptWhenOnEdge(distanceX, distanceY); if (mScale > mMinScale) { if (canScrollX && scrolledX < 0) { mEdgeEffectLeft.onPull(scrolledX / (float) mContentRect.width()); mEdgeEffectLeftActive = true; } if (canScrollY && scrolledY < 0) { mEdgeEffectTop.onPull(scrolledY / (float) mContentRect.height()); mEdgeEffectTopActive = true; } if (canScrollX && scrolledX > mMaxScrollBuffer.x) { mEdgeEffectRight.onPull((scrolledX - mMaxScrollBuffer.x) / (float) mContentRect.width()); mEdgeEffectRightActive = true; } if (canScrollY && scrolledY > mMaxScrollBuffer.y) { mEdgeEffectBottom.onPull((scrolledY - mMaxScrollBuffer.y) / (float) mContentRect.height()); mEdgeEffectBottomActive = true; } } ViewCompat.postInvalidateOnAnimation(ScaleImageView.this); return true; } private void disallowParentInterceptWhenOnEdge(float directionX, float directionY) { final ViewParent parent = getParent(); if (parent != null && (mAllowParentHorizontalScroll || mAllowParentVerticalScroll)) { getImageRect(mRectF); if (mAllowParentHorizontalScroll) { if (directionX > 0 && Math.abs(mRectF.right - mContentRect.right) > mMinEdge) { parent.requestDisallowInterceptTouchEvent(true); } if (directionX < 0 && Math.abs(mRectF.left - mContentRect.left) > mMinEdge) { parent.requestDisallowInterceptTouchEvent(true); } } if (mAllowParentVerticalScroll) { if (directionY > 0 && Math.abs(mRectF.bottom - mContentRect.bottom) > mMinEdge) { parent.requestDisallowInterceptTouchEvent(true); } if (directionY < 0 && Math.abs(mRectF.top - mContentRect.top) > mMinEdge) { parent.requestDisallowInterceptTouchEvent(true); } } } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { disallowParentInterceptWhenOnEdge(velocityX, velocityY); fling((int) -velocityX, (int) -velocityY); return true; } }; mScaleGestureDetector = new ScaleGestureDetector(context, scaleGestureListener); mGestureDetector = new GestureDetectorCompat(context, gestureListener); mScroller = new OverScroller(context); mZoomer = new Zoomer(context); // Sets up edge effects mEdgeEffectLeft = new EdgeEffectCompat(context); mEdgeEffectTop = new EdgeEffectCompat(context); mEdgeEffectRight = new EdgeEffectCompat(context); mEdgeEffectBottom = new EdgeEffectCompat(context); setSrcDrawable(src); }
From source file:cl.monsoon.s1next.widget.PhotoView.java
@Override public boolean onScale(ScaleGestureDetector detector) { if (mTransformsEnabled) { mIsDoubleTouch = false;/*from w w w .ja v a 2s . com*/ float currentScale = getScale(); float newScale = currentScale * detector.getScaleFactor(); scale(newScale, detector.getFocusX(), detector.getFocusY()); } return true; }
From source file:martin.app.bitunion.widget.PhotoView.java
@Override public boolean onScale(@NonNull ScaleGestureDetector detector) { if (mTransformsEnabled) { mIsDoubleTouch = false;/*from w w w . j a v a 2s .c o m*/ float currentScale = getScale(); float newScale = currentScale * detector.getScaleFactor(); scale(newScale, detector.getFocusX(), detector.getFocusY()); } return true; }