Example usage for android.view.animation DecelerateInterpolator DecelerateInterpolator

List of usage examples for android.view.animation DecelerateInterpolator DecelerateInterpolator

Introduction

In this page you can find the example usage for android.view.animation DecelerateInterpolator DecelerateInterpolator.

Prototype

public DecelerateInterpolator(float factor) 

Source Link

Document

Constructor

Usage

From source file:com.aniruddhc.acemusic.player.NowPlayingActivity.NowPlayingActivity.java

/**
 * Initializes the view pager.//  w  w w . j  ava2 s .c om
 */
private void initViewPager() {

    try {
        mViewPager.setVisibility(View.INVISIBLE);
        mViewPagerAdapter = new PlaylistPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(mViewPagerAdapter);
        mViewPager.setOffscreenPageLimit(0);
        mViewPager.setOnPageChangeListener(mPageChangeListener);
        mViewPager.setCurrentItem(mApp.getService().getCurrentSongIndex(), false);

        FadeAnimation fadeAnimation = new FadeAnimation(mViewPager, 600, 0.0f, 1.0f,
                new DecelerateInterpolator(2.0f));

        fadeAnimation.animate();

    } catch (IllegalStateException e) {
        /*
         * Catches any exceptions that may occur
         * as a result of the user rapidly changing
         * their device's orientation.
         */
    }

    //Delay loading extra fragments by 1000ms.
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            mViewPager.setOffscreenPageLimit(10);
        }

    }, 1000);

}

From source file:net.globide.coloring_book.MainActivity.java

/**
 * Initialize the fragments to be paged.
 *//*w  ww.java  2 s.  c  o m*/
private void initializePaging() {

    // TODO: Use the image width attribute from within each fragment to
    // determine the width of the ViewPager.

    // If more than one category is available, enable the pagerRight button
    if (mCategoryLength > 1) {
        mIbPagerRight.setImageResource(R.drawable.button_next);
        mIbPagerRight.setEnabled(true);
    }

    // Create a new drawable object to retrieve the cover size.
    Drawable image = this.getResources().getDrawable(R.drawable.cover_1);

    // Store the width locally
    int coverSize = image.getIntrinsicWidth();

    List<Fragment> fragments = new Vector<Fragment>();

    // For each available coloring book (category)...
    for (Category category : mCategoryData) {

        // Bundle for category data to pass to each instantiated fragment
        // (one set per available category). We only pass the category name.
        // Currently, the Touch Listener passes the cid so ColorActivity
        // knows which image set to load.
        Bundle extraArgs = new Bundle();
        extraArgs.putString("category", category.category);
        extraArgs.putInt("id", category.id);

        // Add a fragment to the fragment list.
        fragments.add(Fragment.instantiate(this, MainPanelFragment.class.getName(), extraArgs));
    }

    // Add the list of fragments to the pager adapter.
    this.mPagerAdapter = new MainPagerAdapter(super.getSupportFragmentManager(), fragments);

    // Attach the VP to it's corresponding resource id.
    mPager = (ViewPager) super.findViewById(R.id.vpMain);

    // Set the viewpager size dynamically.
    ViewGroup.LayoutParams params = mPager.getLayoutParams();
    params.width = coverSize;
    mPager.setLayoutParams(params);

    // Insert our adapter into this VP.
    mPager.setAdapter(this.mPagerAdapter);

    // Set pager animation speed
    try {
        Field mScroller;
        mScroller = ViewPager.class.getDeclaredField("mScroller");
        mScroller.setAccessible(true);
        DecelerateInterpolator sInterpolator = new DecelerateInterpolator(1.0f);
        FixedSpeedScroller scroller = new FixedSpeedScroller(mPager.getContext(), sInterpolator);
        mScroller.set(mPager, scroller);
    } catch (NoSuchFieldException noSuchFieldException) {
        // If the field does not exist, ignore the error and create the
        // default ViewPager. This exception does not need to be handled.
    } catch (IllegalAccessException illegalAccessException) {
        // This exception means our custom scroller could not be attached to
        // the view pager. If this happens, we can ignore it and the default
        // animation will remain unchanged.
    }

    // Set the swipe listener on the pager.
    mPager.setOnPageChangeListener(this);
}

From source file:com.android.launcher3.folder.FolderIcon.java

private void onDrop(final ShortcutInfo item, DragView animateView, Rect finalRect,
        float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable) {
    item.cellX = -1;/*from   w  w  w  . ja va 2s  . c o m*/
    item.cellY = -1;

    // Typically, the animateView corresponds to the DragView; however, if this is being done
    // after a configuration activity (ie. for a Shortcut being dragged from AllApps) we
    // will not have a view to animate
    if (animateView != null) {
        DragLayer dragLayer = mLauncher.getDragLayer();
        Rect from = new Rect();
        dragLayer.getViewRectRelativeToSelf(animateView, from);
        Rect to = finalRect;
        if (to == null) {
            to = new Rect();
            Workspace workspace = mLauncher.getWorkspace();
            // Set cellLayout and this to it's final state to compute final animation locations
            workspace.setFinalTransitionTransform((CellLayout) getParent().getParent());
            float scaleX = getScaleX();
            float scaleY = getScaleY();
            setScaleX(1.0f);
            setScaleY(1.0f);
            scaleRelativeToDragLayer = dragLayer.getDescendantRectRelativeToSelf(this, to);
            // Finished computing final animation locations, restore current state
            setScaleX(scaleX);
            setScaleY(scaleY);
            workspace.resetTransitionTransform((CellLayout) getParent().getParent());
        }

        int[] center = new int[2];
        float scale = getLocalCenterForIndex(index, index + 1, center);
        center[0] = (int) Math.round(scaleRelativeToDragLayer * center[0]);
        center[1] = (int) Math.round(scaleRelativeToDragLayer * center[1]);

        to.offset(center[0] - animateView.getMeasuredWidth() / 2,
                center[1] - animateView.getMeasuredHeight() / 2);

        float finalAlpha = index < mPreviewLayoutRule.numItems() ? 0.5f : 0f;

        float finalScale = scale * scaleRelativeToDragLayer;
        dragLayer.animateView(animateView, from, to, finalAlpha, 1, 1, finalScale, finalScale,
                DROP_IN_ANIMATION_DURATION, new DecelerateInterpolator(2), new AccelerateInterpolator(2),
                postAnimationRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
        addItem(item);
        mFolder.hideItem(item);

        final PreviewItemDrawingParams params = index < mDrawingParams.size() ? mDrawingParams.get(index)
                : null;
        if (params != null)
            params.hidden = true;
        postDelayed(new Runnable() {
            public void run() {
                if (params != null)
                    params.hidden = false;
                mFolder.showItem(item);
                invalidate();
            }
        }, DROP_IN_ANIMATION_DURATION);
    } else {
        addItem(item);
    }
}

From source file:org.alex.refreshlayout.RefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//w  w w .ja  v  a2  s .com
 * @param attrs
 */
public RefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    isLoadingMore = false;
    loadMoreEnabled = true;
    loadMoreMinDistance = (int) dp2px(72);
    touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
    setWillNotDraw(false);
    decelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    circleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    spinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density);
    refreshMaxDragDistance = spinnerOffsetEnd;
    nestedScrollingParentHelper = new NestedScrollingParentHelper(this);
    nestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

    originalOffsetTop = currentTargetOffsetTop = -circleDiameter;
    //LogUtil.e("originalOffsetTop = " + originalOffsetTop);
    moveToStart(1.0f);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    setColorSchemeColors(Color.parseColor("#ffff4444"), Color.parseColor("#ff33b5e5"),
            Color.parseColor("#ffff4444"), Color.parseColor("#ffffbb33"), Color.parseColor("#ff99cc00"));
}

From source file:org.alex.swiperefreshlayout.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from   www .ja va  2s .  c  o  m
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    isLoadingMore = false;
    loadMoreEnabled = true;
    loadMoreMinDistance = (int) dp2px(72);
    touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
    setWillNotDraw(false);
    decelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    circleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    spinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density);
    refreshMaxDragDistance = spinnerOffsetEnd;
    nestedScrollingParentHelper = new NestedScrollingParentHelper(this);
    nestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

    originalOffsetTop = currentTargetOffsetTop = -circleDiameter;
    LogUtil.e("originalOffsetTop = " + originalOffsetTop);
    moveToStart(1.0f);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SwipeRefreshLayout);
    footType = typedArray.getInteger(R.styleable.SwipeRefreshLayout_srl_footType, 100);
    typedArray.recycle();
    a.recycle();
    setColorSchemeColors(0xff99cc00, 0xffffbb33, 0xffff4444);
}

From source file:com.kido.ucmaindemo.widget.refresh.KSwipeRefreshLayout.java

/**
 * Constructor that is called when inflating CustomSwipeRefreshLayout from XML.
 *
 * @param context//w  w  w . j  a v a  2s. c  om
 * @param attrs
 */
public KSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleDiameter = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerOffsetEnd = (int) (DEFAULT_CIRCLE_TARGET * metrics.density);
    mTotalDragDistance = mSpinnerOffsetEnd;
    mNestedScrollingParentHelper = new NestedScrollingParentHelper(this);

    mNestedScrollingChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);

    mOriginalOffsetTop = mCurrentTargetOffsetTop = -mCircleDiameter;
    moveToStart(1.0f);

    final TypedArray a1 = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a1.getBoolean(0, true));
    a1.recycle();

    TypedArray a2 = context.obtainStyledAttributes(attrs, R.styleable.KSwipeRefreshLayout);
    mIndicatorNormalBackground = a2.getColor(R.styleable.KSwipeRefreshLayout_ksrl_indicator_normal_background,
            DEFAULT_INDICATOR_NORMAL_BACKGROUND);
    mIndicatorNormalForeground = a2.getColor(R.styleable.KSwipeRefreshLayout_ksrl_indicator_normal_foreground,
            DEFAULT_INDICATOR_NORMAL_FOREGROUND);
    mIndicatorTerminalBackground = a2.getColor(
            R.styleable.KSwipeRefreshLayout_ksrl_indicator_terminal_background,
            DEFAULT_INDICATOR_TERMINAL_BACKGROUND);
    mIndicatorTerminalForeground = a2.getColor(
            R.styleable.KSwipeRefreshLayout_ksrl_indicator_terminal_foreground,
            DEFAULT_INDICATOR_TERMINAL_FOREGROUND);
    mTerminalEnable = a2.getBoolean(R.styleable.KSwipeRefreshLayout_ksrl_terminal_enable, false);
    int terminalIconResId = a2.getResourceId(R.styleable.KSwipeRefreshLayout_ksrl_terminal_icon, -1);
    if (terminalIconResId != -1) {
        mTerminalIconDrawable = getResources().getDrawable(terminalIconResId);
    }
    a2.recycle();

    init();
}

From source file:com.hippo.widget.refreshlayout.RefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context// ww w. j  a v a 2  s.c  o  m
 * @param attrs
 */
public RefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mHeaderTotalDragDistance = mSpinnerFinalOffset;

    mProgressBar = new SwipeProgressBar(this);
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
}

From source file:com.cyan.widget.refreshlayout.RefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*from  www  . j ava  2 s . co m*/
 * @param attrs
 */
public RefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mHeaderTotalDragDistance = mSpinnerFinalOffset;

    mProgressBar = new SwipeProgressBar(this);
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);

}

From source file:com.callba.phone.widget.refreshlayout.RefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from  ww  w .  j  a v  a 2 s  .  c o  m
 * @param attrs
 */
public RefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the community starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mHeaderTotalDragDistance = mSpinnerFinalOffset;

    mProgressBar = new SwipeProgressBar(this);
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);

}

From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java

@Override
public void onScrollChanged(int deltaX, int deltaY) {
    final BaseActivity activity = (BaseActivity) getActivity();
    if (activity == null) {
        return;/*from  ww  w . ja va 2 s .c o  m*/
    }

    // Reposition the header bar -- it's normally anchored to the top of the content,
    // but locks to the top of the screen on scroll
    int scrollY = mScrollView.getScrollY();

    float newTop = Math.max(mPhotoHeightPixels, scrollY + mHeaderTopClearance);
    mHeaderBox.setTranslationY(newTop);
    mAddScheduleButton.setTranslationY(newTop + mHeaderHeightPixels - mAddScheduleButtonHeightPixels / 2);

    mHeaderBackgroundBox.setPivotY(mHeaderHeightPixels);
    int gapFillDistance = (int) (mHeaderTopClearance * GAP_FILL_DISTANCE_MULTIPLIER);
    boolean showGapFill = !mHasPhoto || (scrollY > (mPhotoHeightPixels - gapFillDistance));
    float desiredHeaderScaleY = showGapFill
            ? ((mHeaderHeightPixels + gapFillDistance + 1) * 1f / mHeaderHeightPixels)
            : 1f;
    if (!mHasPhoto) {
        mHeaderBackgroundBox.setScaleY(desiredHeaderScaleY);
    } else if (mGapFillShown != showGapFill) {
        mHeaderBackgroundBox.animate().scaleY(desiredHeaderScaleY)
                .setInterpolator(new DecelerateInterpolator(2f)).setDuration(250).start();
    }
    mGapFillShown = showGapFill;

    LPreviewUtilsBase lpu = activity.getLPreviewUtils();

    mHeaderShadow.setVisibility(lpu.hasLPreviewAPIs() ? View.GONE : View.VISIBLE);

    if (mHeaderTopClearance != 0) {
        // Fill the gap between status bar and header bar with color
        float gapFillProgress = Math.min(Math.max(UIUtils.getProgress(scrollY,
                mPhotoHeightPixels - mHeaderTopClearance * 2, mPhotoHeightPixels - mHeaderTopClearance), 0), 1);
        lpu.setViewElevation(mHeaderBackgroundBox, gapFillProgress * mMaxHeaderElevation);
        lpu.setViewElevation(mHeaderContentBox, gapFillProgress * mMaxHeaderElevation + 0.1f);
        lpu.setViewElevation(mAddScheduleButton, gapFillProgress * mMaxHeaderElevation + mFABElevation);
        if (!lpu.hasLPreviewAPIs()) {
            mHeaderShadow.setAlpha(gapFillProgress);
        }
    }

    // Move background photo (parallax effect)
    mPhotoViewContainer.setTranslationY(scrollY * 0.5f);
}