Android Open Source - Aviary-Android-SDK Scroller Runnable






From Project

Back to project page Aviary-Android-SDK.

License

The source code is released under:

AVIARY API TERMS OF USE Full Legal Agreement The following terms and conditions and the terms and conditions at http://www.aviary.com/terms (collectively, the ?Terms??) govern your use of any and ...

If you think the Android project Aviary-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.aviary.android.feather.widget;
/*from  w w  w  .  j a va2s . c om*/
import android.annotation.TargetApi;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.OverScroller;
import android.widget.Scroller;

public class ScrollerRunnable implements Runnable {

  public static interface ScrollableView {

    boolean removeCallbacks( Runnable action );

    boolean post( Runnable action );

    void scrollIntoSlots();

    void trackMotionScroll( int newX );

    int getMinX();

    int getMaxX();
  }

  protected int mLastFlingX;
  protected boolean mShouldStopFling;
  protected ScrollableView mParent;
  protected int mAnimationDuration;
  protected int mPreviousX;
  protected boolean mHasMore;

  private OverScroller mScroller;
  private int mOverscrollDistance;

  /**
   * ScrollerRunnable acts like a {@link Scroller} adding some help methods
   * 
   * @param parent
   *            the parent view
   * @param animationDuration
   *            the default animation duration
   * @param overscrollDistance
   *            the overscroller distance
   * @param interpolator
   *            the default interpolator, can be null
   */
  public ScrollerRunnable ( ScrollableView parent, int animationDuration, int overscrollDistance, Interpolator interpolator ) {
    if ( null == interpolator ) {
      mScroller = new OverScroller( ( (View) parent ).getContext() );
    } else {
      mScroller = new OverScroller( ( (View) parent ).getContext(), interpolator );
    }

    mOverscrollDistance = overscrollDistance;
    mParent = parent;
    mAnimationDuration = animationDuration;
  }

  public int getLastFlingX() {
    return mLastFlingX;
  }

  protected void startCommon() {
    mParent.removeCallbacks( this );
  }

  public void stop( boolean scrollIntoSlots ) {
    mParent.removeCallbacks( this );
    endFling( scrollIntoSlots );
  }

  public void endFling( boolean scrollIntoSlots ) {
    abortAnimation();
    mLastFlingX = 0;
    mHasMore = false;

    if ( scrollIntoSlots ) {
      mParent.scrollIntoSlots();
    }
  }

  public void startUsingDistance( int initialX, int distance ) {
    if ( distance == 0 ) return;
    startCommon();
    mLastFlingX = initialX;
    mScroller.startScroll( initialX, 0, distance, 0, mAnimationDuration );
    mParent.post( this );
  }

  public void startUsingVelocity( int initialX, int initialVelocity ) {
    if ( initialVelocity == 0 ) return;
    startCommon();
    mLastFlingX = initialX;
    mScroller.fling( initialX, 0, initialVelocity, 0, mParent.getMinX(), mParent.getMaxX(), 0, Integer.MAX_VALUE, mOverscrollDistance, 0 );
    mParent.post( this );
  }

  public int getPreviousX() {
    return mPreviousX;
  }

  public boolean hasMore() {
    return mHasMore;
  }

  @TargetApi ( 14 )
  public float getCurrVelocity() {
    return mScroller.getCurrVelocity();
  }

  public boolean isFinished() {
    return mScroller.isFinished();
  }

  public boolean springBack( int startX, int startY, int minX, int maxX, int minY, int maxY ) {
    return mScroller.springBack( startX, startY, minX, maxX, minY, maxY );
  }

  public boolean computeScrollOffset() {
    return mScroller.computeScrollOffset();
  }

  public int getCurrX() {
    return mScroller.getCurrX();
  }

  protected void abortAnimation() {
    mScroller.abortAnimation();
  }

  @Override
  public void run() {
    mShouldStopFling = false;
    mPreviousX = getCurrX();
    mHasMore = computeScrollOffset();
    int x = getCurrX();
    mParent.trackMotionScroll( x );

    if ( mHasMore && !mShouldStopFling ) {
      mLastFlingX = x;
      mParent.post( this );
    } else {
      endFling( true );
    }
  }

}




Java Source Code List

com.aviary.android.feather.AlertActivity.java
com.aviary.android.feather.AviaryMainController.java
com.aviary.android.feather.FeatherActivity.java
com.aviary.android.feather.async_tasks.AsyncImageManager.java
com.aviary.android.feather.async_tasks.DownloadImageAsyncTask.java
com.aviary.android.feather.async_tasks.ExifTask.java
com.aviary.android.feather.effects.AbstractContentPanel.java
com.aviary.android.feather.effects.AbstractOptionPanel.java
com.aviary.android.feather.effects.AbstractPanelLoaderService.java
com.aviary.android.feather.effects.AbstractPanel.java
com.aviary.android.feather.effects.AdjustEffectPanel.java
com.aviary.android.feather.effects.BordersPanel.java
com.aviary.android.feather.effects.ColorSplashPanel.java
com.aviary.android.feather.effects.CropPanel.java
com.aviary.android.feather.effects.DelayedSpotDrawPanel.java
com.aviary.android.feather.effects.DrawingPanel.java
com.aviary.android.feather.effects.EffectsPanel.java
com.aviary.android.feather.effects.EnhanceEffectPanel.java
com.aviary.android.feather.effects.MemePanel.java
com.aviary.android.feather.effects.NativeEffectRangePanel.java
com.aviary.android.feather.effects.SimpleStatusMachine.java
com.aviary.android.feather.effects.SliderEffectPanel.java
com.aviary.android.feather.effects.StickersPanel.java
com.aviary.android.feather.effects.TextPanel.java
com.aviary.android.feather.effects.TiltShiftPanel.java
com.aviary.android.feather.graphics.CdsPreviewTransformer.java
com.aviary.android.feather.graphics.GalleryBottomIndicatorDrawable.java
com.aviary.android.feather.graphics.GalleryTopIndicatorDrawable.java
com.aviary.android.feather.graphics.GlowBitmapDrawable.java
com.aviary.android.feather.graphics.GlowDrawable.java
com.aviary.android.feather.graphics.PluginDividerDrawable.java
com.aviary.android.feather.graphics.PreviewFillColorDrawable.java
com.aviary.android.feather.graphics.PreviewSpotDrawable.java
com.aviary.android.feather.graphics.RepeatableHorizontalDrawable.java
com.aviary.android.feather.opengl.AviaryGLSurfaceView.java
com.aviary.android.feather.utils.PackIconCallable.java
com.aviary.android.feather.utils.SimpleBitmapCache.java
com.aviary.android.feather.utils.ThreadUtils.java
com.aviary.android.feather.utils.TypefaceUtils.java
com.aviary.android.feather.utils.UIUtils.java
com.aviary.android.feather.widget.AdjustImageView.java
com.aviary.android.feather.widget.AviaryAbsSpinner.java
com.aviary.android.feather.widget.AviaryAdapterView.java
com.aviary.android.feather.widget.AviaryBadgeToolLayout.java
com.aviary.android.feather.widget.AviaryBottomBarViewFlipper.java
com.aviary.android.feather.widget.AviaryButton.java
com.aviary.android.feather.widget.AviaryEdgeEffect.java
com.aviary.android.feather.widget.AviaryGalleryTopIndicatorView.java
com.aviary.android.feather.widget.AviaryGallery.java
com.aviary.android.feather.widget.AviaryHighlightImageButton.java
com.aviary.android.feather.widget.AviaryImageRestoreSwitcher.java
com.aviary.android.feather.widget.AviaryImageSwitcher.java
com.aviary.android.feather.widget.AviaryNavBarViewFlipper.java
com.aviary.android.feather.widget.AviarySeekBar.java
com.aviary.android.feather.widget.AviaryTextView.java
com.aviary.android.feather.widget.AviaryToast.java
com.aviary.android.feather.widget.AviaryToggleButton.java
com.aviary.android.feather.widget.AviaryWheel.java
com.aviary.android.feather.widget.AviaryWorkspaceIndicator.java
com.aviary.android.feather.widget.AviaryWorkspace.java
com.aviary.android.feather.widget.CellLayout.java
com.aviary.android.feather.widget.CropImageView.java
com.aviary.android.feather.widget.DrawableHighlightView.java
com.aviary.android.feather.widget.EffectThumbLayout.java
com.aviary.android.feather.widget.HighlightView.java
com.aviary.android.feather.widget.IAPBuyButton.java
com.aviary.android.feather.widget.IAPDialogDetail.java
com.aviary.android.feather.widget.IAPDialogList.java
com.aviary.android.feather.widget.IAPDialogMain.java
com.aviary.android.feather.widget.ImageViewDrawableOverlay.java
com.aviary.android.feather.widget.ImageViewSpotDraw.java
com.aviary.android.feather.widget.ImageViewTiltiShiftTouch.java
com.aviary.android.feather.widget.ImageViewTouchAndDraw.java
com.aviary.android.feather.widget.PointCloud.java
com.aviary.android.feather.widget.ScrollerRunnable.java
com.aviary.android.feather.widget.VibrationHelper.java
com.aviary.android.feather.widget.VibrationWidget.java