Example usage for android.view ScaleGestureDetector getScaleFactor

List of usage examples for android.view ScaleGestureDetector getScaleFactor

Introduction

In this page you can find the example usage for android.view ScaleGestureDetector getScaleFactor.

Prototype

public float getScaleFactor() 

Source Link

Document

Return the scaling factor from the previous scale event to the current event.

Usage

From source file:com.yek.keyboard.devicespecific.AskV8GestureDetector.java

public AskV8GestureDetector(Context context, AskOnGestureListener listener) {
    super(context, listener, null, true/*ignore multi-touch*/);

    mListener = listener;//w  w  w .j a  v a 2s .  c  om

    mScaleGestureDetector = new ScaleGestureDetector(context,
            new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                @Override
                public boolean onScale(ScaleGestureDetector detector) {
                    final float factor = detector.getScaleFactor();
                    if (factor > 1.1)
                        return mListener.onSeparate(factor);
                    else if (factor < 0.9)
                        return mListener.onPinch(factor);

                    return false;
                }
            });
}

From source file:com.anysoftkeyboard.devicespecific.AskV8GestureDetector.java

public AskV8GestureDetector(Context context, AskOnGestureListener listener) {
    super(context, listener, null, true/*ignore multi-touch*/);

    mListener = listener;/*from w  w w. j a  va 2s.co m*/

    mScaleGestureDetector = new ScaleGestureDetector(context,
            new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                @Override
                public boolean onScale(ScaleGestureDetector detector) {
                    final float factor = detector.getScaleFactor();
                    Log.d(TAG, "onScale factor " + factor);

                    if (factor > 1.1)
                        return mListener.onSeparate(factor);
                    else if (factor < 0.9)
                        return mListener.onPinch(factor);

                    return false;
                }
            });
}

From source file:org.videolan.vlc.gui.view.PopupLayout.java

@Override
public boolean onScale(ScaleGestureDetector detector) {
    mScaleFactor *= detector.getScaleFactor();

    mScaleFactor = Math.max(0.1d, Math.min(mScaleFactor, 5.0d));
    mPopupWidth = (int) (getWidth() * mScaleFactor);
    mPopupHeight = (int) (getHeight() * mScaleFactor);
    return true;//from www.j  ava 2  s  . c  om
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

@Override
public boolean onScale(ScaleGestureDetector detector) {
    float scaleFactor = detector.getScaleFactor();

    if (Float.isNaN(scaleFactor) || Float.isInfinite(scaleFactor)) {
        return false;
    }/*from  ww w  . ja  v  a2 s .c  o m*/

    mScaleDragGestureListener.onScale(scaleFactor, detector.getFocusX(), detector.getFocusY());
    return true;
}

From source file:com.hippo.largeimageview.GestureRecognizer.java

@Override
public boolean onScale(ScaleGestureDetector detector) {
    mScale = true;/*from   w ww  .j a  v  a2s.c om*/
    mListener.onScale(detector.getFocusX(), detector.getFocusY(), detector.getScaleFactor());
    return true;
}

From source file:com.maxwen.wallpaper.board.fragments.BaseFragment.java

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ViewHelper.resetViewBottomPadding(mRecyclerView, ((WallpaperBoardActivity) getActivity()).getNavBarHeight(),
            true);//from www . j av a2s.  c o  m
    setHasOptionsMenu(true);

    mDefaultSpan = getActivity().getResources().getInteger(R.integer.wallpapers_column_count);
    mMaxSpan = getActivity().getResources().getInteger(R.integer.wallpapers_max_column_count);
    mMinSpan = getActivity().getResources().getInteger(R.integer.wallpapers_min_column_count);
    mCurrentSpan = Math.min(Preferences.getPreferences(getActivity()).getColumnSpanCount(mDefaultSpan),
            mMaxSpan);

    //mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setItemAnimator(new SlideInLeftAnimator());
    mRecyclerView.setLayoutManager(new WallpaperGridLayoutManager(getActivity(), mCurrentSpan));
    mRecyclerView.setHasFixedSize(false);

    //set scale gesture detector
    mScaleGestureDetector = new ScaleGestureDetector(getActivity(),
            new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                @Override
                public boolean onScale(ScaleGestureDetector detector) {
                    final float sf = detector.getScaleFactor();
                    if (detector.getTimeDelta() > 200
                            && Math.abs(detector.getCurrentSpan() - detector.getPreviousSpan()) > 100) {
                        if (detector.getCurrentSpan() - detector.getPreviousSpan() < -1) {
                            int span = Math.min(mCurrentSpan + 1, mMaxSpan);
                            if (span != mCurrentSpan) {
                                mCurrentSpan = span;
                                ViewHelper.setSpanCountToColumns(getActivity(), mRecyclerView, mCurrentSpan);
                                Preferences.getPreferences(getActivity()).setColumnSpanCount(mCurrentSpan);
                                onSpanCountChanged();
                            }
                            return true;
                        } else if (detector.getCurrentSpan() - detector.getPreviousSpan() > 1) {
                            int span = Math.max(mCurrentSpan - 1, mMinSpan);
                            if (span != mCurrentSpan) {
                                mCurrentSpan = span;
                                ViewHelper.setSpanCountToColumns(getActivity(), mRecyclerView, mCurrentSpan);
                                Preferences.getPreferences(getActivity()).setColumnSpanCount(mCurrentSpan);
                                onSpanCountChanged();
                            }
                            ViewHelper.setSpanCountToColumns(getActivity(), mRecyclerView, mCurrentSpan);
                            return true;
                        }
                    }
                    return false;
                }

                @Override
                public void onScaleEnd(ScaleGestureDetector detector) {
                    mRecyclerView.setNestedScrollingEnabled(true);
                }

                @Override
                public boolean onScaleBegin(ScaleGestureDetector detector) {
                    mRecyclerView.setNestedScrollingEnabled(false);
                    return true;
                }
            });
    mRecyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mScaleGestureDetector.onTouchEvent(event);
            return mScaleGestureDetector.isInProgress();
        }
    });
}

From source file:com.apptentive.android.sdk.util.image.PreviewImageView.java

@Override
public boolean onScale(ScaleGestureDetector detector) {
    float scale = getScale();
    float scaleFactor = detector.getScaleFactor();

    if (getDrawable() == null)
        return true;

    /**/*from ww  w.  ja v  a2s.co m*/
     * Scale range check
     */
    if ((scale < SCALE_MAX && scaleFactor > 1.0f) || (scale >= initScale && scaleFactor < 1.0f)) {

        if (scaleFactor * scale < initScale) {
            scaleFactor = initScale / scale;
        }
        if (scaleFactor * scale > SCALE_MAX) {
            scaleFactor = SCALE_MAX / scale;
        }
        /**
         * Set scaling into matrix
         */
        scaleMatrix.postScale(scaleFactor, scaleFactor, detector.getFocusX(), detector.getFocusY());
        checkBorderAndCenterWhenScale();
        setImageMatrix(scaleMatrix);
    }
    return true;

}

From source file:org.ros.android.view.visualization.layer.CameraControlLayer.java

@Override
public void onStart(final VisualizationView view, ConnectedNode connectedNode) {
    view.post(new Runnable() {
        @Override//  w ww .  j a v a 2s  .  com
        public void run() {
            translateGestureDetector = new GestureDetectorCompat(view.getContext(),
                    new GestureDetector.SimpleOnGestureListener() {
                        @Override
                        public boolean onDown(MotionEvent e) {
                            // This must return true in order for onScroll() to trigger.
                            return true;
                        }

                        @Override
                        public boolean onScroll(MotionEvent event1, MotionEvent event2, final float distanceX,
                                final float distanceY) {
                            view.getCamera().translate(-distanceX, distanceY);
                            listeners.signal(new SignalRunnable<CameraControlListener>() {
                                @Override
                                public void run(CameraControlListener listener) {
                                    listener.onTranslate(-distanceX, distanceY);
                                }
                            });
                            return true;
                        }

                        @Override
                        public boolean onDoubleTap(final MotionEvent e) {
                            listeners.signal(new SignalRunnable<CameraControlListener>() {
                                @Override
                                public void run(CameraControlListener listener) {
                                    listener.onDoubleTap(e.getX(), e.getY());
                                }
                            });
                            return true;
                        }
                    });
            rotateGestureDetector = new RotateGestureDetector(
                    new RotateGestureDetector.OnRotateGestureListener() {
                        @Override
                        public boolean onRotate(MotionEvent event1, MotionEvent event2,
                                final double deltaAngle) {
                            final float focusX = (event1.getX(0) + event1.getX(1)) / 2;
                            final float focusY = (event1.getY(0) + event1.getY(1)) / 2;
                            view.getCamera().rotate(focusX, focusY, deltaAngle);
                            listeners.signal(new SignalRunnable<CameraControlListener>() {
                                @Override
                                public void run(CameraControlListener listener) {
                                    listener.onRotate(focusX, focusY, deltaAngle);
                                }
                            });
                            return true;
                        }
                    });
            zoomGestureDetector = new ScaleGestureDetector(view.getContext(),
                    new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                        @Override
                        public boolean onScale(ScaleGestureDetector detector) {
                            if (!detector.isInProgress()) {
                                return false;
                            }
                            final float focusX = detector.getFocusX();
                            final float focusY = detector.getFocusY();
                            final float factor = detector.getScaleFactor();
                            view.getCamera().zoom(focusX, focusY, factor);
                            listeners.signal(new SignalRunnable<CameraControlListener>() {
                                @Override
                                public void run(CameraControlListener listener) {
                                    listener.onZoom(focusX, focusY, factor);
                                }
                            });
                            return true;
                        }
                    });
        }
    });
}

From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java

/**
 * ?/*from   w  w  w . j  av a2 s  .  c  o  m*/
 *
 * @param detector 
 * @return ??
 */
protected boolean dispatchScale(ScaleGestureDetector detector) {
    onScale(mScale * detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
    return true;
}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaVRModeFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mStorage = new ThetaObjectStorage(getContext());
    setRetainInstance(true);//from  www. j  a va 2 s .  c  om
    ThetaDeviceApplication app = (ThetaDeviceApplication) getActivity().getApplication();
    mDataCache = app.getCache();
    View rootView = inflater.inflate(R.layout.theta_vr_mode, null);
    mRightLayout = (RelativeLayout) rootView.findViewById(R.id.right_ui);
    mSphereView = (SphericalImageView) rootView.findViewById(R.id.vr_view);

    SphericalViewApi api = app.getSphericalViewApi();
    mSphereView.setViewApi(api);

    mSphereView.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) {
                    mSphereView.resetCameraDirection();
                }
            } else {
                mIsEnabledLongTouch = false;
                mScaleDetector.onTouchEvent(motionEvent);
            }
            return true;
        }
    });
    init3DButtons(rootView);
    enableView();
    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;
                    }
                    mSphereView.setFOV(scale);

                    return true;
                }
            });
    return rootView;
}