Example usage for android.view.animation Animation Animation

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

Introduction

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

Prototype

public Animation() 

Source Link

Document

Creates a new animation with a duration of 0ms, the default interpolator, with fillBefore set to true and fillAfter set to false

Usage

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

private Animation startHeaderAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mHeaderScale && isAlphaUsedForScale()) {
        return null;
    }/*from w  w  w. j a v a  2s .  c  om*/
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha) * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}

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

@SuppressLint("NewApi")
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mScale && isAlphaUsedForScale()) {
        return null;
    }/* w w  w .  j  av a 2  s  . c o m*/
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha) * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}

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.j  av a2  s . co  m*/
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.hippo.refreshlayout.RefreshLayout.java

void startScaleDownAnimation(Animation.AnimationListener listener) {
    mHeaderScaleDownAnimation = new Animation() {
        @Override/*w ww.  jav  a  2s .  c om*/
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(1 - interpolatedTime);
        }
    };
    mHeaderScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mCircleView.setAnimationListener(listener);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mHeaderScaleDownAnimation);
}

From source file:com.jecelyin.android.common.widget.TabLayout.java

private void animateToTab(int newPosition) {
    clearAnimation();/*from  ww w.j a  v  a2  s  . c  o  m*/

    if (newPosition == Tab.INVALID_POSITION) {
        return;
    }

    if (getWindowToken() == null || !ViewCompat.isLaidOut(this)) {
        // If we don't have a window token, or we haven't been laid out yet just draw the new
        // position now
        setScrollPosition(newPosition, 0f, true);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);
    final int duration = ANIMATION_DURATION;

    if (startScrollX != targetScrollX) {
        final Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                final float value = lerp(startScrollX, targetScrollX, interpolatedTime);
                scrollTo((int) value, 0);
            }
        };
        animation.setInterpolator(INTERPOLATOR);
        animation.setDuration(duration);
        startAnimation(animation);
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, duration);
}

From source file:net.rossharper.coloredtablayout.TabLayout.java

private void animateToTab(int newPosition) {
    clearAnimation();//from  w w w.  j a  v a  2 s .  c o  m

    if (newPosition == Tab.INVALID_POSITION) {
        return;
    }

    if (getWindowToken() == null || !ViewCompat.isLaidOut(this)) {
        // If we don't have a window token, or we haven't been laid out yet just draw the new
        // position now
        setScrollPosition(newPosition, 0f);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);
    final int duration = ANIMATION_DURATION;

    if (startScrollX != targetScrollX) {
        final Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                final float value = lerp(startScrollX, targetScrollX, interpolatedTime);
                scrollTo((int) value, 0);
            }
        };
        animation.setInterpolator(INTERPOLATOR);
        animation.setDuration(duration);
        startAnimation(animation);
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, duration);
}

From source file:glas.bbsystem.views.widgets.TabLayout.java

private void animateToTab(int newPosition) {
    clearAnimation();//from   w  w w .j a  v a 2s  .  c  om

    if (newPosition == Tab.INVALID_POSITION) {
        return;
    }

    if (getWindowToken() == null || !ViewCompat.isLaidOut(this)) {
        // If we don't have a window token, or we haven't been laid out yet
        // just draw the new
        // position now
        setScrollPosition(newPosition, 0f);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);
    final int duration = ANIMATION_DURATION;

    if (startScrollX != targetScrollX) {
        final Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                final float value = lerp(startScrollX, targetScrollX, interpolatedTime);
                scrollTo((int) value, 0);
            }
        };
        animation.setInterpolator(INTERPOLATOR);
        animation.setDuration(duration);
        startAnimation(animation);
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, duration);
}

From source file:com.google.android.apps.gutenberg.widget.TabLayout.java

private void animateToTab(int newPosition) {
    clearAnimation();//from   w  w  w.  j  av a 2 s. c o m

    if (newPosition == Tab.INVALID_POSITION) {
        return;
    }

    if (getWindowToken() == null || !isViewLaidOut(this)) {
        // If we don't have a window token, or we haven't been laid out yet just draw the new
        // position now
        setScrollPosition(newPosition, 0f);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);
    final int duration = ANIMATION_DURATION;

    if (startScrollX != targetScrollX) {
        final Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                final float value = lerp(startScrollX, targetScrollX, interpolatedTime);
                scrollTo((int) value, 0);
            }
        };
        animation.setInterpolator(INTERPOLATOR);
        animation.setDuration(duration);
        startAnimation(animation);
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, duration);
}

From source file:android.support.v7.widget.SwitchCompat.java

private void animateThumbToCheckedState(boolean newCheckedState) {
    final float startPosition = mThumbPosition;
    final float targetPosition = newCheckedState ? 1 : 0;
    final float diff = targetPosition - startPosition;

    mPositionAnimator = new Animation() {
        @Override//from   w ww  .j a v a2  s.co m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            setThumbPosition(startPosition + (diff * interpolatedTime));
        }
    };
    mPositionAnimator.setDuration(THUMB_ANIMATION_DURATION);
    startAnimation(mPositionAnimator);
}

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

@SuppressLint("NewApi")
private Animation startAlphaAnimation(final int startingAlpha, final int endingAlpha) {
    // Pre API 11, alpha is used in place of scale. Don't also use it to
    // show the trigger point.
    if (mHeaderScale && isAlphaUsedForScale()) {
        return null;
    }//from   ww w.j a v a  2  s .c  o  m
    Animation alpha = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mProgress.setAlpha((int) (startingAlpha + ((endingAlpha - startingAlpha) * interpolatedTime)));
        }
    };
    alpha.setDuration(ALPHA_ANIMATION_DURATION);
    // Clear out the previous animation listeners.
    mCircleView.setAnimationListener(null);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(alpha);
    return alpha;
}