android.widget.Scroller Java Examples
The following examples show how to use
android.widget.Scroller.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlipView.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void init() { final Context context = getContext(); final ViewConfiguration configuration = ViewConfiguration.get(context); mScroller = new Scroller(context, flipInterpolator); mTouchSlop = configuration.getScaledPagingTouchSlop(); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mShadowPaint.setColor(Color.BLACK); mShadowPaint.setStyle(Style.FILL); mShadePaint.setColor(Color.BLACK); mShadePaint.setStyle(Style.FILL); mShinePaint.setColor(Color.WHITE); mShinePaint.setStyle(Style.FILL); }
Example #2
Source File: ViewDragHelper.java From Dashchan with Apache License 2.0 | 6 votes |
/** * Apps should use ViewDragHelper.create() to get a new instance. * This will allow VDH to use internal compatibility implementations for different * platform versions. * * @param context Context to initialize config-dependent params from * @param forParent Parent view to monitor */ private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) { if (forParent == null) { throw new IllegalArgumentException("Parent view may not be null"); } if (cb == null) { throw new IllegalArgumentException("Callback may not be null"); } mParentView = forParent; mCallback = cb; final ViewConfiguration vc = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mEdgeSize = (int) (EDGE_SIZE * density + 0.5f); mTouchSlop = vc.getScaledTouchSlop(); mMaxVelocity = vc.getScaledMaximumFlingVelocity(); mMinVelocity = vc.getScaledMinimumFlingVelocity(); mScroller = new Scroller(context, sInterpolator); }
Example #3
Source File: FlipView.java From AndroidAnimationExercise with Apache License 2.0 | 6 votes |
private void init() { final Context context = getContext(); final ViewConfiguration configuration = ViewConfiguration.get(context); mScroller = new Scroller(context, flipInterpolator); mTouchSlop = configuration.getScaledPagingTouchSlop(); mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mShadowPaint.setColor(Color.BLACK); mShadowPaint.setStyle(Style.FILL); mShadePaint.setColor(Color.BLACK); mShadePaint.setStyle(Style.FILL); mShinePaint.setColor(Color.WHITE); mShinePaint.setStyle(Style.FILL); }
Example #4
Source File: NumberPicker.java From NewXmPluginSDK with Apache License 2.0 | 6 votes |
/** * Move to the final position of a scroller. Ensures to force finish the scroller * and if it is not at its final position a scroll of the selector wheel is * performed to fast forward to the final position. * * @param scroller The scroller to whose final position to get. * @return True of the a move was performed, i.e. the scroller was not in final position. */ private boolean moveToFinalScrollerPosition(Scroller scroller) { scroller.forceFinished(true); int amountToScroll = scroller.getFinalY() - scroller.getCurrY(); int futureScrollOffset = (mCurrentScrollOffset + amountToScroll) % mSelectorElementHeight; int overshootAdjustment = mInitialScrollOffset - futureScrollOffset; if (overshootAdjustment != 0) { if (Math.abs(overshootAdjustment) > mSelectorElementHeight / 2) { if (overshootAdjustment > 0) { overshootAdjustment -= mSelectorElementHeight; } else { overshootAdjustment += mSelectorElementHeight; } } amountToScroll += overshootAdjustment; scrollBy(0, amountToScroll); return true; } return false; }
Example #5
Source File: Utils.java From timecat with Apache License 2.0 | 6 votes |
/** * 通过scrollTo方法完成协调布局的滑动,其中主要使用了ViewCompat.postOnAnimation * * @param parent 协调布局parent * @param child 协调布局协调滑动的child * @param y 滑动目标位置y轴数值 * @param duration 滑动执行时间 * @return void */ public static void scrollTo(final CoordinatorLayout parent, final RecyclerView child, final int y, int duration) { final Scroller scroller = new Scroller(parent.getContext()); scroller.startScroll(0, top, 0, y - top, duration); //设置scroller的滚动偏移量 ViewCompat.postOnAnimation(child, new Runnable() { @Override public void run() { //返回值为boolean,true说明滚动尚未完成,false说明滚动已经完成。 // 这是一个很重要的方法,通常放在View.computeScroll()中,用来判断是否滚动是否结束。 if (scroller.computeScrollOffset()) { int delta = scroller.getCurrY() - child.getTop(); child.offsetTopAndBottom(delta); saveTop(child.getTop()); parent.dispatchDependentViewsChanged(child); ViewCompat.postOnAnimation(child, this); } } }); }
Example #6
Source File: SnapHelper.java From GridPagerSnapHelper with Apache License 2.0 | 6 votes |
/** * Attaches the {@link android.support.v7.widget.SnapHelper} to the provided RecyclerView, by calling * {@link RecyclerView#setOnFlingListener(RecyclerView.OnFlingListener)}. * You can call this method with {@code null} to detach it from the current RecyclerView. * * @param recyclerView The RecyclerView instance to which you want to add this helper or * {@code null} if you want to remove SnapHelper from the current * RecyclerView. * @throws IllegalArgumentException if there is already a {@link RecyclerView.OnFlingListener} * attached to the provided {@link RecyclerView}. */ public void attachToRecyclerView(@Nullable RecyclerView recyclerView) throws IllegalStateException { if (mRecyclerView == recyclerView) { return; // nothing to do } if (mRecyclerView != null) { destroyCallbacks(); } mRecyclerView = recyclerView; if (mRecyclerView != null) { setupCallbacks(); mGravityScroller = new Scroller(mRecyclerView.getContext(), new DecelerateInterpolator()); snapToTargetExistingView(); } }
Example #7
Source File: PageWidget.java From nono-android with GNU General Public License v3.0 | 6 votes |
public PageWidget(Context context) { super(context); // TODO Auto-generated constructor stub mPath0 = new Path(); mPath1 = new Path(); createDrawable(); mPaint = new Paint(); mPaint.setStyle(Paint.Style.FILL); ColorMatrix cm = new ColorMatrix(); float array[] = { 0.55f, 0, 0, 0, 80.0f, 0, 0.55f, 0, 0, 80.0f, 0, 0, 0.55f, 0, 80.0f, 0, 0, 0, 0.2f, 0 }; cm.set(array); mColorMatrixFilter = new ColorMatrixColorFilter(cm); mMatrix = new Matrix(); mScroller = new Scroller(getContext()); mTouch.x = 0.01f; mTouch.y = 0.01f; }
Example #8
Source File: HorizontalViewPager.java From DoubleViewPager with Apache License 2.0 | 6 votes |
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(); 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); } }
Example #9
Source File: SnapHelper.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Attaches the {@link SnapHelper} to the provided RecyclerView, by calling * {@link RecyclerView#setOnFlingListener(RecyclerView.OnFlingListener)}. * You can call this method with {@code null} to detach it from the current RecyclerView. * * @param recyclerView The RecyclerView instance to which you want to add this helper or * {@code null} if you want to remove SnapHelper from the current * RecyclerView. * * @throws IllegalArgumentException if there is already a {@link RecyclerView.OnFlingListener} * attached to the provided {@link RecyclerView}. * */ public void attachToRecyclerView(@Nullable RecyclerView recyclerView) throws IllegalStateException { if (mRecyclerView == recyclerView) { return; // nothing to do } if (mRecyclerView != null) { destroyCallbacks(); } mRecyclerView = recyclerView; if (mRecyclerView != null) { setupCallbacks(); mGravityScroller = new Scroller(mRecyclerView.getContext(), new DecelerateInterpolator()); snapToTargetExistingView(); } }
Example #10
Source File: BaseReadView.java From BookReader with Apache License 2.0 | 6 votes |
public BaseReadView(Context context, String bookId, List<BookMixAToc.mixToc.Chapters> chaptersList, OnReadStateChangeListener listener) { super(context); this.listener = listener; this.bookId = bookId; mScreenWidth = ScreenUtils.getScreenWidth(); mScreenHeight = ScreenUtils.getScreenHeight(); mCurPageBitmap = Bitmap.createBitmap(mScreenWidth, mScreenHeight, Bitmap.Config.ARGB_8888); mNextPageBitmap = Bitmap.createBitmap(mScreenWidth, mScreenHeight, Bitmap.Config.ARGB_8888); mCurrentPageCanvas = new Canvas(mCurPageBitmap); mNextPageCanvas = new Canvas(mNextPageBitmap); mScroller = new Scroller(getContext()); pagefactory = new PageFactory(getContext(), bookId, chaptersList); pagefactory.setOnReadStateChangeListener(listener); }
Example #11
Source File: ViewPager.java From MiBandDecompiled with Apache License 2.0 | 6 votes |
void a() { setWillNotDraw(false); setDescendantFocusability(0x40000); setFocusable(true); Context context = getContext(); u = new Scroller(context, l); ViewConfiguration viewconfiguration = ViewConfiguration.get(context); float f1 = context.getResources().getDisplayMetrics().density; N = ViewConfigurationCompat.getScaledPagingTouchSlop(viewconfiguration); V = (int)(400F * f1); W = viewconfiguration.getScaledMaximumFlingVelocity(); ae = new EdgeEffectCompat(context); af = new EdgeEffectCompat(context); Z = (int)(25F * f1); aa = (int)(2.0F * f1); L = (int)(16F * f1); ViewCompat.setAccessibilityDelegate(this, new aD(this)); if (ViewCompat.getImportantForAccessibility(this) == 0) { ViewCompat.setImportantForAccessibility(this, 1); } }
Example #12
Source File: SearchListViewNoText.java From SearchListView with MIT License | 6 votes |
private void init() { scroller = new Scroller(getContext(), new DecelerateInterpolator()); measureView(getHeaderView()); headHeight = getHeaderView().getMeasuredHeight(); getHeaderView().setPadding(0, -1 * headHeight, 0, 0); getHeaderView().invalidate(); // this.setBackgroundResource(R.color.stand_default_bg_color); //添加头部视图 super.addHeaderView(getHeaderView(), null, false); setOnScrollListener(this); super.setOnItemClickListener(this); super.setOnItemLongClickListener(this); super.setOnItemSelectedListener(this); }
Example #13
Source File: JelloToggle.java From JelloToggle with MIT License | 6 votes |
private void init() { mJelloPaint = new Paint(); mJelloPaint.setAntiAlias(true); mCheckedDrawable = getResources().getDrawable(R.drawable.checked); mOnCheckDrawable = getResources().getDrawable(R.drawable.check_on); mUnCheckedDrawable = getResources().getDrawable(R.drawable.uncheck); setJelloState(); mJelloRect = new Rect(); mScroller = new Scroller(getContext()); mJelloPath = new Path(); mInterpolator = new EaseOutElasticInterpolator(); mDuration = DEFAULT_DURATION; }
Example #14
Source File: VelocityViewPager.java From CoverFlowPager with MIT License | 6 votes |
@Override public void run() { final Scroller scroller = mScroller; boolean animationNotFinished = scroller.computeScrollOffset(); final int x = scroller.getCurrX(); int delta = x - mLastFlingX; trackMotion(delta); if (animationNotFinished) { mLastFlingX = x; post(this); } else { endFling(); } }
Example #15
Source File: TouchImageView.java From ScaleLayout with Apache License 2.0 | 5 votes |
public CompatScroller(Context context) { if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) { isPreGingerbread = true; scroller = new Scroller(context); } else { isPreGingerbread = false; overScroller = new OverScroller(context); } }
Example #16
Source File: HorizontalListView.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
private synchronized void initView() { mLeftViewIndex = -1; mRightViewIndex = 0; mDisplayOffset = 0; mCurrentX = 0; mNextX = 0; mMaxX = Integer.MAX_VALUE; mScroller = new Scroller(getContext()); mGesture = new GestureDetector(getContext(), mOnGesture); }
Example #17
Source File: RefreshLayout.java From SimpleProject with MIT License | 5 votes |
private void initView(Context context) { setOrientation(VERTICAL); mRefreshStatus = REFRESH_STATUS_NONE; mScroller = new Scroller(context); mScreenHeight = Resources.getSystem().getDisplayMetrics().heightPixels; mVelocityTracker = VelocityTracker.obtain(); ViewConfiguration configuration = ViewConfiguration.get(context); mMinVelocity = configuration.getScaledMinimumFlingVelocity(); }
Example #18
Source File: TouchImageView.java From IndiaSatelliteWeather with GNU General Public License v2.0 | 5 votes |
public CompatScroller(Context context) { if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) { isPreGingerbread = true; scroller = new Scroller(context); } else { isPreGingerbread = false; overScroller = new OverScroller(context); } }
Example #19
Source File: FanLayout.java From FanLayout with Apache License 2.0 | 5 votes |
public FanLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); initAttrs(context, attrs, defStyleAttr); mScrollAvailabilityRatio = .3F; final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); mScroller = new Scroller(getContext()); mVelocityTracker = VelocityTracker.obtain(); }
Example #20
Source File: FilmstripView.java From Camera2 with Apache License 2.0 | 5 votes |
public FilmstripScrollGesture(Context ctx, Handler handler, Listener listener, TimeInterpolator interpolator) { mHandler = handler; mListener = listener; mScroller = new Scroller(ctx); mXScrollAnimator = new ValueAnimator(); mXScrollAnimator.addUpdateListener(mXScrollAnimatorUpdateListener); mXScrollAnimator.addListener(mXScrollAnimatorListener); mXScrollAnimator.setInterpolator(interpolator); }
Example #21
Source File: CustomViewAbove.java From BigApp_WordPress_Android with Apache License 2.0 | 5 votes |
void initCustomViewAbove() { 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(); setInternalPageChangeListener(new SimpleOnPageChangeListener() { public void onPageSelected(int position) { if (mViewBehind != null) { switch (position) { case 0: case 2: mViewBehind.setChildrenEnabled(true); break; case 1: mViewBehind.setChildrenEnabled(false); break; } } } }); final float density = context.getResources().getDisplayMetrics().density; mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); }
Example #22
Source File: VerticalViewPager.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
void initVerticalViewPager() { setWillNotDraw(false); 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); } }
Example #23
Source File: TouchImageView.java From meizhi with Apache License 2.0 | 5 votes |
public CompatScroller(Context context) { if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) { isPreGingerbread = true; scroller = new Scroller(context); } else { isPreGingerbread = false; overScroller = new OverScroller(context); } }
Example #24
Source File: ViewPager.java From guideshow with MIT License | 5 votes |
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); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = 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); } }
Example #25
Source File: FlingViewGroup.java From VCL-Android with Apache License 2.0 | 5 votes |
public FlingViewGroup(Context context, AttributeSet attrs) { super(context, attrs); this.setLayoutParams(new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); mScroller = new Scroller(context); ViewConfiguration config = ViewConfiguration.get(getContext()); mTouchSlop = config.getScaledTouchSlop(); mMaximumVelocity = config.getScaledMaximumFlingVelocity(); }
Example #26
Source File: WheelScroller.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
/** * Constructor * @param context the current context * @param listener the scrolling listener */ public WheelScroller(Context context, ScrollingListener listener) { gestureDetector = new GestureDetector(context, gestureListener); gestureDetector.setIsLongpressEnabled(false); scroller = new Scroller(context); this.listener = listener; this.context = context; }
Example #27
Source File: TouchImageView.java From cordova-plugin-video-picture-preview-picker-V2 with MIT License | 5 votes |
public CompatScroller(Context context) { if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) { isPreGingerbread = true; scroller = new Scroller(context); } else { isPreGingerbread = false; overScroller = new OverScroller(context); } }
Example #28
Source File: TouchImageView.java From Ecommerce-Morningmist-Android with Creative Commons Zero v1.0 Universal | 5 votes |
public CompatScroller(Context context) { if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) { isPreGingerbread = true; scroller = new Scroller(context); } else { isPreGingerbread = false; overScroller = new OverScroller(context); } }
Example #29
Source File: MyScrollView.java From palmsuda with Apache License 2.0 | 5 votes |
public MyScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mWallpaperManager = WallpaperManager.getInstance(context); mScroller = new Scroller(context); mCurScreen = mDefaultScreen; mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); }
Example #30
Source File: ScrollRefreshLayout.java From easyweather with MIT License | 5 votes |
private void init(Context context) { WindowManager wm = (WindowManager) context.getSystemService( Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); mScreenHeight = dm.heightPixels; mScroller = new Scroller(context); }