List of usage examples for android.widget OverScroller OverScroller
public OverScroller(Context context)
From source file:com.commonsware.cwac.crossport.design.widget.HeaderBehavior.java
final boolean fling(CoordinatorLayout coordinatorLayout, V layout, int minOffset, int maxOffset, float velocityY) { if (mFlingRunnable != null) { layout.removeCallbacks(mFlingRunnable); mFlingRunnable = null;/*from w w w . j av a 2s . c o m*/ } if (mScroller == null) { mScroller = new OverScroller(layout.getContext()); } mScroller.fling(0, getTopAndBottomOffset(), // curr 0, Math.round(velocityY), // velocity. 0, 0, // x minOffset, maxOffset); // y if (mScroller.computeScrollOffset()) { mFlingRunnable = new FlingRunnable(coordinatorLayout, layout); ViewCompat.postOnAnimation(layout, mFlingRunnable); return true; } else { onFlingFinished(coordinatorLayout, layout); return false; } }
From source file:com.comcast.freeflow.core.FreeFlowContainer.java
@Override protected void init(Context context) { // usedViews = new HashMap<Object, FreeFlowItem>(); // usedHeaderViews = new HashMap<Object, FreeFlowItem>(); setWillNotDraw(false);//from w ww .java 2s. c o m viewpool = new ViewPool(); frames = new HashMap<Object, FreeFlowItem>(); ViewConfiguration configuration = ViewConfiguration.get(context); maxFlingVelocity = configuration.getScaledMaximumFlingVelocity(); minFlingVelocity = configuration.getScaledMinimumFlingVelocity(); overflingDistance = configuration.getScaledOverflingDistance(); overscrollDistance = configuration.getScaledOverscrollDistance(); touchSlop = configuration.getScaledTouchSlop(); scroller = new OverScroller(context); mLeftEdge = new EdgeEffect(context); mRightEdge = new EdgeEffect(context); mTopEdge = new EdgeEffect(context); mBottomEdge = new EdgeEffect(context); }
From source file:com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.java
@Override protected void init(Context context) { viewpool = new ViewPool(); frames = new LinkedHashMap<Object, FreeFlowItem>(); ViewConfiguration configuration = ViewConfiguration.get(context); maxFlingVelocity = configuration.getScaledMaximumFlingVelocity(); minFlingVelocity = configuration.getScaledMinimumFlingVelocity(); overflingDistance = configuration.getScaledOverflingDistance(); /*overscrollDistance = configuration.getScaledOverscrollDistance();*/ touchSlop = configuration.getScaledTouchSlop(); scroller = new OverScroller(context); setEdgeEffectsEnabled(true);// w ww .j a va 2s .co m }
From source file:com.xuejian.client.lxp.common.widget.freeflow.core.FreeFlowContainer.java
@Override protected void init(Context context) { viewpool = new ViewPool(); frames = new LinkedHashMap<Object, FreeFlowItem>(); ViewConfiguration configuration = ViewConfiguration.get(context); maxFlingVelocity = configuration.getScaledMaximumFlingVelocity(); minFlingVelocity = configuration.getScaledMinimumFlingVelocity(); overflingDistance = configuration.getScaledOverflingDistance(); overflingDistance = 0;//from ww w .j ava 2 s . c o m /*overscrollDistance = configuration.getScaledOverscrollDistance();*/ touchSlop = configuration.getScaledTouchSlop(); scroller = new OverScroller(context); setEdgeEffectsEnabled(true); }
From source file:com.acbelter.scheduleview.ScheduleView.java
private void init(Context context) { if (!isInEditMode()) { mOverScroller = new OverScroller(context); mGestureListener = new GestureDetector.SimpleOnGestureListener() { @Override//from ww w.j ava 2 s. c o m public boolean onDown(MotionEvent e) { if (DEBUG) { Log.d(TAG, "onDown() y=" + mListY); } releaseEdgeEffects(); mOverScroller.forceFinished(true); return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (DEBUG) { Log.d(TAG, "onFling() y=" + mListY); } // Fling isn't needed if (mDeltaHeight < 0) { return true; } mScrollDirection = velocityY > 0 ? 1 : -1; mOverScroller.fling(0, mListY, 0, (int) velocityY, 0, 0, -mDeltaHeight, 0); if (!awakenScrollBars()) { ViewCompat.postInvalidateOnAnimation(ScheduleView.this); } return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { for (int i = 0; i < getChildCount(); i++) { getChildAt(i).setPressed(false); } mListY -= (int) distanceY; recalculateOffset(); positionItemViews(); if (mListY == 0) { mTopEdgeEffect.onPull(distanceY / (float) getHeight()); mTopEdgeEffectActive = true; } if (mListY == -mDeltaHeight) { mBottomEdgeEffect.onPull(distanceY / (float) getHeight()); mBottomEdgeEffectActive = true; } if (!awakenScrollBars()) { invalidate(); } return true; } @Override public void onLongPress(MotionEvent e) { if (DEBUG) { Log.d(TAG, "onLongPress() y=" + mListY); } View child; for (int i = 0; i < getChildCount(); i++) { child = getChildAt(i); child.getHitRect(mClickedViewBounds); if (mClickedViewBounds.contains((int) e.getX(), (int) e.getY())) { if (!mIsActionMode) { mActionMode = startActionMode(mActionModeCallback); mIsActionMode = true; } if (!child.isSelected()) { mSelectedIds.add(mAdapter.getItemId(i)); child.setSelected(true); } else { mSelectedIds.remove(mAdapter.getItemId(i)); child.setSelected(false); } if (mSelectedIds.isEmpty()) { finishActionMode(); } invalidate(); return; } } } @Override public boolean onSingleTapUp(MotionEvent e) { if (DEBUG) { Log.d(TAG, "onSingleTapConfirmed() y=" + mListY); } View child; for (int i = 0; i < getChildCount(); i++) { child = getChildAt(i); child.getHitRect(mClickedViewBounds); if (mClickedViewBounds.contains((int) e.getX(), (int) e.getY())) { if (!mIsActionMode) { OnItemClickListener callback = getOnItemClickListener(); if (callback != null) { callback.onItemClick(ScheduleView.this, child, i, mAdapter.getItemId(i)); } } else { if (!child.isSelected()) { mSelectedIds.add(mAdapter.getItemId(i)); child.setSelected(true); } else { mSelectedIds.remove(mAdapter.getItemId(i)); child.setSelected(false); } if (mSelectedIds.isEmpty()) { finishActionMode(); } invalidate(); } break; } } return true; } }; mGestureDetector = new GestureDetector(context, mGestureListener); } }
From source file:freeflow.core.FreeFlowContainer.java
@Override protected void init(Context context) { viewpool = new ViewPool(); frames = new LinkedHashMap<Object, FreeFlowItem>(); ViewConfiguration configuration = ViewConfiguration.get(context); maxFlingVelocity = configuration.getScaledMaximumFlingVelocity(); minFlingVelocity = configuration.getScaledMinimumFlingVelocity(); overflingDistance = configuration.getScaledOverflingDistance(); overscrollDistance = configuration.getScaledOverscrollDistance(); touchSlop = configuration.getScaledTouchSlop(); scroller = new OverScroller(context); setEdgeEffectsEnabled(true);// ww w . j av a 2s.c o m }
From source file:com.ickphum.android.isoview.InteractiveLineGraphView.java
public InteractiveLineGraphView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.InteractiveLineGraphView, defStyle, defStyle);/*from w w w .j av a2 s. c o m*/ try { mLabelTextColor = a.getColor(R.styleable.InteractiveLineGraphView_labelTextColor, mLabelTextColor); mLabelTextSize = a.getDimension(R.styleable.InteractiveLineGraphView_labelTextSize, mLabelTextSize); mLabelSeparation = a.getDimensionPixelSize(R.styleable.InteractiveLineGraphView_labelSeparation, mLabelSeparation); mGridThickness = a.getDimension(R.styleable.InteractiveLineGraphView_gridThickness, mGridThickness); mGridColor = a.getColor(R.styleable.InteractiveLineGraphView_gridColor, mGridColor); mAxisThickness = a.getDimension(R.styleable.InteractiveLineGraphView_axisThickness, mAxisThickness); mAxisColor = a.getColor(R.styleable.InteractiveLineGraphView_axisColor, mAxisColor); mDataThickness = a.getDimension(R.styleable.InteractiveLineGraphView_dataThickness, mDataThickness); mDataColor = a.getColor(R.styleable.InteractiveLineGraphView_dataColor, mDataColor); } finally { a.recycle(); } initPaints(); // Sets up interactions if (!this.isInEditMode()) { mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener); mGestureDetector = new GestureDetectorCompat(context, mGestureListener); } 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); }
From source file:cn.androidy.androiddevelopmentpatterns.interactivechart.InteractiveLineGraphView.java
public InteractiveLineGraphView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.InteractiveLineGraphView, defStyle, defStyle);//from w w w . j a v a 2s. c om try { mLabelTextColor = a.getColor(R.styleable.InteractiveLineGraphView_labelTextColor, mLabelTextColor); mLabelTextSize = a.getDimension(R.styleable.InteractiveLineGraphView_labelTextSize, mLabelTextSize); mLabelSeparation = a.getDimensionPixelSize(R.styleable.InteractiveLineGraphView_labelSeparation, mLabelSeparation); mGridThickness = a.getDimension(R.styleable.InteractiveLineGraphView_gridThickness, mGridThickness); mGridColor = a.getColor(R.styleable.InteractiveLineGraphView_gridColor, mGridColor); mAxisThickness = a.getDimension(R.styleable.InteractiveLineGraphView_axisThickness, mAxisThickness); mAxisColor = a.getColor(R.styleable.InteractiveLineGraphView_axisColor, mAxisColor); mDataThickness = a.getDimension(R.styleable.InteractiveLineGraphView_dataThickness, mDataThickness); mDataColor = a.getColor(R.styleable.InteractiveLineGraphView_dataColor, mDataColor); } finally { a.recycle(); } initPaints(); // Sets up interactions mScaleGestureDetector = new ScaleGestureDetector(context, mScaleGestureListener); mGestureDetector = new GestureDetectorCompat(context, mGestureListener); 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); }
From source file:org.gdg.frisbee.android.view.MasonryView.java
public MasonryView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (attrs != null) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MasonryView); mColCount = a.getInteger(R.styleable.MasonryView_numColumns, 2); mDrawSelectorOnTop = a.getBoolean(R.styleable.MasonryView_drawSelectorOnTop, false); } else {//from w w w . java 2s. c o m mColCount = 2; mDrawSelectorOnTop = false; } final ViewConfiguration vc = ViewConfiguration.get(context); mTouchSlop = vc.getScaledTouchSlop(); mMaximumVelocity = vc.getScaledMaximumFlingVelocity(); mFlingVelocity = vc.getScaledMinimumFlingVelocity(); mScroller = new OverScroller(getContext()); this.setOverScrollMode(OVER_SCROLL_ALWAYS); mTopEdge = new EdgeEffectCompat(context); mBottomEdge = new EdgeEffectCompat(context); setWillNotDraw(false); setClipToPadding(false); this.setFocusableInTouchMode(false); if (mSelector == null) { useDefaultSelector(); } }
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 w w. ja v a 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); }