Example usage for android.view ScaleGestureDetector getPreviousSpan

List of usage examples for android.view ScaleGestureDetector getPreviousSpan

Introduction

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

Prototype

public float getPreviousSpan() 

Source Link

Document

Return the previous average distance between each of the pointers forming the gesture in progress through the focal point.

Usage

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 w ww  .  ja v a  2 s .c om*/
    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.gmail.walles.johan.batterylogger.BatteryPlotFragment.java

private ScaleGestureDetector getTwoFingerGestureDetector(final XYPlot plot) {
    ScaleGestureDetector.SimpleOnScaleGestureListener gestureListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        @Override//  ww  w  .  j  a  v  a  2 s.  co  m
        public boolean onScale(ScaleGestureDetector detector) {
            float factor = detector.getPreviousSpan() / detector.getCurrentSpan();
            float pixelX = detector.getFocusX();
            RectF gridRect = plot.getGraphWidget().getGridRect();
            // getXVal throws IAE if the X value is outside of the rectangle
            if (gridRect.contains(pixelX, gridRect.top)) {
                double pivot = plot.getGraphWidget().getXVal(pixelX);
                zoom(factor, pivot);
            }

            plot.setDomainBoundaries(minX, maxX, BoundaryMode.FIXED);
            redrawPlot(plot);
            return true;
        }
    };

    return new ScaleGestureDetector(getActivity(), gestureListener);
}

From source file:com.example.nitish.welcomapp.widgetpt.PeriodicTableView.java

/**
 * Create the listener for the ScaleGestureDetector.
 *
 * @return The OnScaleGestureListener/* w  w  w  . j av  a  2s . c om*/
 */
@NonNull
private ScaleGestureDetector.OnScaleGestureListener getOnScaleGestureListener() {
    return new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        /**
         * The initial span of the scale gesture
         */
        private float mStartSpan;

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            clearSelection();
            mScaleRect.set(mContentRect);
            mStartSpan = detector.getCurrentSpan();

            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            mScaleFocalPoint.set(detector.getFocusX() / getWidth(), detector.getFocusY() / getHeight());
            setZoom(mCurrentZoom
                    + mCurrentZoom * (detector.getCurrentSpan() - detector.getPreviousSpan()) / mStartSpan);

            return true;
        }

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            if (mPeriodicTableListener != null) {
                mPeriodicTableListener.onZoomEnd(PeriodicTableView.this);
            }
        }
    };
}

From source file:com.ultramegatech.ey.widget.PeriodicTableView.java

/**
 * Create the listener for the ScaleGestureDetector.
 *
 * @return The OnScaleGestureListener/*  ww  w  .  j  ava2 s  .c  o  m*/
 */
@NonNull
private ScaleGestureDetector.OnScaleGestureListener getOnScaleGestureListener() {
    //noinspection MethodDoesntCallSuperMethod
    return new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        /**
         * The initial span of the scale gesture
         */
        private float mStartSpan;

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            clearSelection();
            mScaleRect.set(mContentRect);
            mStartSpan = detector.getCurrentSpan();

            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            mScaleFocalPoint.set(detector.getFocusX() / getWidth(), detector.getFocusY() / getHeight());
            setZoom(mCurrentZoom
                    + mCurrentZoom * (detector.getCurrentSpan() - detector.getPreviousSpan()) / mStartSpan);

            return true;
        }

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            if (mPeriodicTableListener != null) {
                mPeriodicTableListener.onZoomEnd(PeriodicTableView.this);
            }
        }
    };
}