Example usage for android.view ViewConfiguration getScaledEdgeSlop

List of usage examples for android.view ViewConfiguration getScaledEdgeSlop

Introduction

In this page you can find the example usage for android.view ViewConfiguration getScaledEdgeSlop.

Prototype

public int getScaledEdgeSlop() 

Source Link

Usage

From source file:com.dj.hacktor.nshiddenlayout.views.CustomNestedScrollView.java

private void init(Context context) {
    ViewConfiguration config = ViewConfiguration.get(context);
    slop = config.getScaledEdgeSlop();
}

From source file:mobi.cangol.mobile.navigation.PagerEnabledSlidingPaneLayout.java

public PagerEnabledSlidingPaneLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    ViewConfiguration config = ViewConfiguration.get(context);
    mEdgeSlop = config.getScaledEdgeSlop();
}

From source file:it.sephiroth.android.library.imagezoom.ScaleGestureDetector.java

public ScaleGestureDetector(final Context context, final OnScaleGestureListener listener) {
    final ViewConfiguration config = ViewConfiguration.get(context);
    mContext = context;/* w ww  .j  a  v  a  2 s  . c  o  m*/
    mListener = listener;
    mEdgeSlop = config.getScaledEdgeSlop();
}

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 a  va 2 s  . c om*/
    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:com.king.view.superslidingpanelayout.SuperSlidingPaneLayout.java

public SuperSlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = context.getResources().getDisplayMetrics().density;
    mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);

    final ViewConfiguration viewConfig = ViewConfiguration.get(context);

    mEdgeSlop = viewConfig.getScaledEdgeSlop();

    setWillNotDraw(false);/*from ww  w. j  ava2 s  .  c  o m*/

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SuperSlidingPaneLayout);
    mMode = Mode.getFromInt(a.getInt(R.styleable.SuperSlidingPaneLayout_mode, 0));

    mIsCompatSliding = a.getBoolean(R.styleable.SuperSlidingPaneLayout_compat_sliding, false);

    a.recycle();

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}