List of usage examples for android.support.v4.widget EdgeEffectCompat EdgeEffectCompat
public EdgeEffectCompat(Context context)
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 . ja v 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:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java
void initViewPager() { setWillNotDraw(false);/*from ww w. j av a 2s . c o m*/ setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate()); // TODO: Could restore these lines after ActionBarSherlock is upgraded to support library v9 // if (ViewCompat.getImportantForAccessibility(this) // == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { // ViewCompat.setImportantForAccessibility(this, // ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); // } }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
/** * ?View Pager/*from w ww. jav a 2 s . co m*/ */ void initViewPager() { setWillNotDraw(false); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); //XXX mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); }
From source file:com.bloomimpact.bancus.ui.views.VerticalViewPager.java
void initViewPager() { setWillNotDraw(false);/*from w w w .java 2 s . c o m*/ setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } }
From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView3.java
public StaggeredGridView3(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (attrs != null) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StgStaggeredGridView); mColCount = a.getInteger(R.styleable.StgStaggeredGridView_stgNumColumns, 2); mDrawSelectorOnTop = a.getBoolean(R.styleable.StgStaggeredGridView_stgDrawSelectorOnTop, false); } else {/*from ww w .j a va 2 s .c o m*/ mColCount = 2; mDrawSelectorOnTop = false; } final ViewConfiguration vc = ViewConfiguration.get(context); mTouchSlop = vc.getScaledTouchSlop(); mMaximumVelocity = vc.getScaledMaximumFlingVelocity(); mFlingVelocity = vc.getScaledMinimumFlingVelocity(); //mScroller=ScrollerCompat.from(context); mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); setWillNotDraw(false); setClipToPadding(false); this.setFocusableInTouchMode(false); if (mSelector == null) { useDefaultSelector(); } mMinimumVelocity = vc.getScaledMinimumFlingVelocity(); mMaximumVelocity = vc.getScaledMaximumFlingVelocity(); }
From source file:com.bluetoothlamp.tiny.view.verticalview.VerticalViewPager.java
/** * ??iew Pager//from ww w. j ava 2 s . c o m */ void initViewPager() { setWillNotDraw(false); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); //XXX ? mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); }
From source file:com.example.view.VerticalViewPager.java
/** * /*from w w w .jav a 2s .co m*/ */ void initViewPager() { setWillNotDraw(false); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); // mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); }
From source file:com.android.backups.StaggeredGridViewByJaumo.java
public StaggeredGridViewByJaumo(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (attrs != null) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StaggeredGridView); mColCount = a.getInteger(R.styleable.StaggeredGridView_numColumns, 2); mDrawSelectorOnTop = a.getBoolean(R.styleable.StaggeredGridView_drawSelectorOnTop, false); } else {//from w w w.j a v a 2s.c o m mColCount = 2; mDrawSelectorOnTop = false; } final ViewConfiguration vc = ViewConfiguration.get(context); mTouchSlop = vc.getScaledTouchSlop(); mMaximumVelocity = vc.getScaledMaximumFlingVelocity(); mFlingVelocity = vc.getScaledMinimumFlingVelocity(); mScroller = ScrollerCompat.from(context); mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); setWillNotDraw(false); setClipToPadding(false); this.setFocusableInTouchMode(false); if (mSelector == null) { useDefaultSelector(); } }
From source file:interactive.view.pagereader.VerticalViewPager.java
/** * ?iew Pager// w ww . ja va2 s . c o m */ void initViewPager() { setWillNotDraw(false); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); // XXX mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); }
From source file:com.baiiu.autoloopviewpager.loopvp.LoopViewPager.java
void initViewPager() { setWillNotDraw(false);//from www . j a v a 2 s.c om setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } }