Example usage for android.view.animation Animation setDuration

List of usage examples for android.view.animation Animation setDuration

Introduction

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

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * Creates the animation set for next ViewFlippers when loaded.
 * @return a customized animation for mViewFlippers
 *//*from w  ww  .jav  a 2s . c  o m*/
private static Animation nextAnim() {
    Animation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT,
            0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(100);
    anim.setInterpolator(new AccelerateInterpolator());
    return anim;
}

From source file:org.anurag.file.quest.TaskerActivity.java

/**
 * Creates the animation set for previous ViewFlippers when loaded.
 * @return a customized animation for mViewFlippers
 *///from w  w  w .j  a v a  2 s .  co  m
private static Animation prevAnim() {
    Animation anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT,
            0.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    anim.setDuration(100);
    anim.setInterpolator(new AccelerateInterpolator());
    return anim;
}

From source file:com.audiokernel.euphonyrmt.fragments.NowPlayingFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    final Animation fadeIn = AnimationUtils.loadAnimation(mActivity, android.R.anim.fade_in);
    final Animation fadeOut = AnimationUtils.loadAnimation(mActivity, android.R.anim.fade_out);
    final int viewLayout;
    final View view;

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mActivity);

    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mApp.isTabletUiEnabled()) {
        viewLayout = R.layout.main_fragment_tablet;
    } else {//from  w  w w .  j  ava2 s .  c  o m
        viewLayout = R.layout.main_fragment;
    }

    view = inflater.inflate(viewLayout, container, false);

    mTrackTime = (TextView) view.findViewById(R.id.trackTime);
    mTrackTotalTime = (TextView) view.findViewById(R.id.trackTotalTime);
    mVolumeIcon = (ImageView) view.findViewById(R.id.volume_icon);

    /** These load the TextView resource, and set it as selected. */
    mAlbumNameText = findSelected(view, R.id.albumName);
    mArtistNameText = findSelected(view, R.id.artistName);
    mAudioNameText = findSelected(view, R.id.audioName);
    mSongNameText = findSelected(view, R.id.songName);
    mSongNameText.setText(R.string.notConnected);
    mYearNameText = findSelected(view, R.id.yearName);
    applyViewVisibility(mYearNameText, "enableAlbumYearText");
    mSongRating = (RatingBar) view.findViewById(R.id.songRating);
    mSongRating.setOnRatingBarChangeListener(new RatingChangedHandler());
    mSongRating.setVisibility(View.GONE);

    /** These get the event button, then setup listeners for them. */
    mPlayPauseButton = getEventButton(view, R.id.playpause, true);
    mRepeatButton = getEventButton(view, R.id.repeat, false);
    mShuffleButton = getEventButton(view, R.id.shuffle, false);
    mStopButton = getEventButton(view, R.id.stop, true);
    applyViewVisibility(mStopButton, "enableStopButton");

    /** Same as above, but these don't require a stored field. */
    getEventButton(view, R.id.next, false);
    getEventButton(view, R.id.prev, false);

    /** These have methods to initialize everything required to get them setup. */
    mCoverArt = getCoverArt(view);
    mCoverAsyncHelper = getCoverAsyncHelper(view);
    mSongInfo = getSongInfo(view);
    mTrackSeekBar = getTrackSeekBar(view);
    mVolumeSeekBar = getVolumeSeekBar(view);

    fadeIn.setDuration(ANIMATION_DURATION);
    fadeOut.setDuration(ANIMATION_DURATION);

    Log.i(TAG, "Initialization succeeded");

    return view;
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Shows LocalImageFragment to view images
 *
 * @param view  source card which was selected
 * @param index position of source in listAdapter
 *//*from   w w w.jav  a  2  s.  c om*/
private void showViewImageFragment(final View view, final int index) {
    sourceList.setOnItemClickListener(null);
    sourceList.setEnabled(false);

    listAdapter.saveData();
    Source item = listAdapter.getItem(index);
    String type = item.getType();
    String directory;
    if (type.equals(AppSettings.FOLDER)) {
        directory = item.getData().split(AppSettings.DATA_SPLITTER)[0];
    } else {
        directory = AppSettings.getDownloadPath() + "/" + item.getTitle() + " " + AppSettings.getImagePrefix();
    }

    Log.i(TAG, "Directory: " + directory);

    final RelativeLayout sourceContainer = (RelativeLayout) view.findViewById(R.id.source_container);
    final ImageView sourceImage = (ImageView) view.findViewById(R.id.source_image);
    final View imageOverlay = view.findViewById(R.id.source_image_overlay);
    final EditText sourceTitle = (EditText) view.findViewById(R.id.source_title);
    final ImageView deleteButton = (ImageView) view.findViewById(R.id.source_delete_button);
    final ImageView viewButton = (ImageView) view.findViewById(R.id.source_view_image_button);
    final ImageView editButton = (ImageView) view.findViewById(R.id.source_edit_button);
    final LinearLayout sourceExpandContainer = (LinearLayout) view.findViewById(R.id.source_expand_container);

    final float viewStartHeight = sourceContainer.getHeight();
    final float viewStartY = view.getY();
    final float overlayStartAlpha = imageOverlay.getAlpha();
    final float listHeight = sourceList.getHeight();
    Log.i(TAG, "listHeight: " + listHeight);
    Log.i(TAG, "viewStartHeight: " + viewStartHeight);

    final LocalImageFragment localImageFragment = new LocalImageFragment();
    Bundle arguments = new Bundle();
    arguments.putString("view_path", directory);
    localImageFragment.setArguments(arguments);

    Animation animation = new Animation() {

        private boolean needsFragment = true;

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            if (needsFragment && interpolatedTime >= 1) {
                needsFragment = false;
                getFragmentManager().beginTransaction()
                        .add(R.id.content_frame, localImageFragment, "image_fragment").addToBackStack(null)
                        .setTransition(FragmentTransaction.TRANSIT_NONE).commit();
            }
            ViewGroup.LayoutParams params = sourceContainer.getLayoutParams();
            params.height = (int) (viewStartHeight + (listHeight - viewStartHeight) * interpolatedTime);
            sourceContainer.setLayoutParams(params);
            view.setY(viewStartY - interpolatedTime * viewStartY);
            deleteButton.setAlpha(1.0f - interpolatedTime);
            viewButton.setAlpha(1.0f - interpolatedTime);
            editButton.setAlpha(1.0f - interpolatedTime);
            sourceTitle.setAlpha(1.0f - interpolatedTime);
            imageOverlay.setAlpha(overlayStartAlpha - overlayStartAlpha * (1.0f - interpolatedTime));
            sourceExpandContainer.setAlpha(1.0f - interpolatedTime);
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            if (needsListReset) {
                Parcelable state = sourceList.onSaveInstanceState();
                sourceList.setAdapter(null);
                sourceList.setAdapter(listAdapter);
                sourceList.onRestoreInstanceState(state);
                sourceList.setOnItemClickListener(SourceListFragment.this);
                sourceList.setEnabled(true);
                needsListReset = false;
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    ValueAnimator cardColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
            AppSettings.getDialogColor(appContext),
            getResources().getColor(AppSettings.getBackgroundColorResource()));
    cardColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sourceContainer.setBackgroundColor((Integer) animation.getAnimatedValue());
        }

    });

    DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(1.5f);

    animation.setDuration(INFO_ANIMATION_TIME);
    cardColorAnimation.setDuration(INFO_ANIMATION_TIME);

    animation.setInterpolator(decelerateInterpolator);
    cardColorAnimation.setInterpolator(decelerateInterpolator);

    needsListReset = true;
    cardColorAnimation.start();
    view.startAnimation(animation);

}

From source file:com.mobility.android.ui.widget.MaterialProgressDrawable.java

private void setupAnimators() {
    Ring ring = mRing;//from www .ja v  a  2s. c  o  m
    Animation animation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                float minProgressArc = getMinProgressArc(ring);
                float startingEndTrim = ring.getStartingEndTrim();
                float startingTrim = ring.getStartingStartTrim();
                float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    float scaledTime = interpolatedTime / (1.0f - START_TRIM_DURATION_OFFSET);
                    float startTrim = startingTrim + (MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime);
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    float endTrim = startingEndTrim
                            + minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime);
                    ring.setEndTrim(endTrim);
                }

                float rotation = startingRotation + 0.25f * interpolatedTime;
                ring.setRotation(rotation);

                float groupRotation = FULL_ROTATION / NUM_POINTS * interpolatedTime
                        + FULL_ROTATION * mRotationCount / NUM_POINTS;
                setRotation(groupRotation);
            }
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % NUM_POINTS;
            }
        }
    });
    mAnimation = animation;
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

@Override
public void onClick(final View v) {

    switch (v.getId()) {

    case R.id.set_button:
        setWallpaper();/* w w  w. j  a  v  a 2s  . c o  m*/
        break;
    case R.id.floating_button_icon:
        final GradientDrawable circleDrawable = (GradientDrawable) getResources()
                .getDrawable(R.drawable.floating_button_circle);
        final float scale = (float) ((Math.hypot(addButtonBackground.getX(), addButtonBackground.getY())
                + addButtonBackground.getWidth()) / addButtonBackground.getWidth() * 2);

        Animation animation = new Animation() {

            private boolean needsFragment = true;
            private float pivot;

            @Override
            public void initialize(int width, int height, int parentWidth, int parentHeight) {
                super.initialize(width, height, parentWidth, parentHeight);

                pivot = resolveSize(RELATIVE_TO_SELF, 0.5f, width, parentWidth);
            }

            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {

                if (needsFragment && interpolatedTime >= 1) {
                    needsFragment = false;
                    showSourceAddFragment();
                } else {
                    float scaleFactor = 1.0f + ((scale - 1.0f) * interpolatedTime);
                    t.getMatrix().setScale(scaleFactor, scaleFactor, pivot, pivot);
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }

        };

        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                addButtonBackground.setImageDrawable(circleDrawable);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (needsButtonReset) {
                            addButton.setOnClickListener(SourceListFragment.this);
                            addButtonBackground.setScaleX(1.0f);
                            addButtonBackground.setScaleY(1.0f);
                            addButtonBackground.clearAnimation();
                            circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                            addButtonBackground.setImageDrawable(circleDrawable);
                            addButton.setVisibility(View.VISIBLE);
                        }
                    }
                }, 100);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

        });

        ValueAnimator buttonColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                getResources().getColor(R.color.ACCENT_OPAQUE),
                getResources().getColor(AppSettings.getBackgroundColorResource()));
        buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                circleDrawable.setColor((Integer) animation.getAnimatedValue());
                addButtonBackground.setImageDrawable(circleDrawable);
            }

        });

        DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();

        animation.setDuration(ADD_ANIMATION_TIME);
        buttonColorAnimation.setDuration((long) (ADD_ANIMATION_TIME * 0.9));
        buttonColorAnimation.setInterpolator(decelerateInterpolator);
        animation.setInterpolator(decelerateInterpolator);

        // Post a delayed Runnable to ensure reset even if animation is interrupted
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (needsButtonReset) {
                    addButtonBackground.setScaleX(1.0f);
                    addButtonBackground.setScaleY(1.0f);
                    addButtonBackground.clearAnimation();
                    circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE));
                    addButtonBackground.setImageDrawable(circleDrawable);
                    addButton.setVisibility(View.VISIBLE);
                    needsButtonReset = false;
                }
            }
        }, (long) (ADD_ANIMATION_TIME * 1.1f));

        needsButtonReset = true;
        addButton.setVisibility(View.GONE);
        buttonColorAnimation.start();
        addButtonBackground.startAnimation(animation);
        break;
    default:
    }
}

From source file:com.congxiaoyao.xber_admin.widget.MaterialProgressDrawable.java

private void setupAnimators() {
    final MaterialProgressDrawable.Ring ring = mRing;
    final Animation animation = new Animation() {
        @Override//from   w ww . ja  v  a  2  s .com
        public void applyTransformation(float interpolatedTime, Transformation t) {
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime)
                        + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                setRotation(groupRotation);
            }
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animation;
}

From source file:cn.spinsoft.wdq.widget.swipe.MaterialProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final Animation animation = new Animation() {
        @Override/* w  w w.  ja  v  a 2  s  .  c om*/
        public void applyTransformation(float interpolatedTime, Transformation t) {
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime)
                        + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                setRotation(groupRotation);
            }
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animation;
}

From source file:com.androidhuman.circlerefreshlayout.MaterialProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final Animation animation = new Animation() {
        @Override// w ww.j  a v  a2  s .c  o  m
        public void applyTransformation(float interpolatedTime, Transformation t) {
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = interpolatedTime / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + (MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime);
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = (FULL_ROTATION / NUM_POINTS) * interpolatedTime
                        + FULL_ROTATION * (mRotationCount / NUM_POINTS);
                setRotation(groupRotation);
            }
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % NUM_POINTS;
            }
        }
    });
    mAnimation = animation;
}

From source file:com.xfzbd.cqi.widget.srl.ShyaringanProgressDrawable.java

private void setupAnimators() {
    final Shyaringan ring = mRing;
    final Animation animation = new Animation() {
        @Override//  www  . jav a2s  .  co  m
        public void applyTransformation(float interpolatedTime, Transformation t) {
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                // if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                // scale the interpolatedTime so that the full
                // transformation from 0 - 1 takes place in the
                // remaining time
                // final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                // final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                // * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                // ring.setStartTrim(startTrim);
                // }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                // if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                // scale the interpolatedTime so that the full
                // transformation from 0 - 1 takes place in the
                // remaining time
                // final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                // float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET) / (1.0f - START_TRIM_DURATION_OFFSET);
                // final float endTrim = startingEndTrim + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                // ring.setEndTrim(endTrim);
                // }

                final float rotation = (startingRotation + (500f * interpolatedTime)) % 360f;
                XLog.e("srl --> rotation - %f - setRotation - shyaringan", rotation);
                ring.setRotation(rotation);

                // float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime) + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                // setRotation(groupRotation);
            }
        }
    };
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.RESTART);
    animation.setInterpolator(LINEAR_INTERPOLATOR);
    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            XLog.e("srl --> refresh 1 - " + System.currentTimeMillis());
            mRotationCount = 0;
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // do nothing
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animation;
}