Java Code Examples for android.view.animation.Animation#setDuration()

The following examples show how to use android.view.animation.Animation#setDuration() . 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: AndroidTreeView.java    From AndroidTreeView with Apache License 2.0 6 votes vote down vote up
private static void collapse(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

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

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 2
Source File: SummaryView.java    From px-android with MIT License 6 votes vote down vote up
public void animateExit(final int duration) {
    final Animation fadeOut = AnimationUtils.loadAnimation(getContext(), R.anim.px_fade_out);
    fadeOut.setDuration(duration);

    if (showingBigLogo) {
        bigHeaderDescriptor.startAnimation(fadeOut);
    } else {
        toolbarElementDescriptor.startAnimation(
            AnimationUtils.loadAnimation(getContext(), R.anim.px_summary_slide_up_out));
    }

    detailRecyclerView.startAnimation(fadeOut);

    findViewById(R.id.separator).startAnimation(fadeOut);

    startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.px_summary_translate_out));

    totalAmountDescriptor.startAnimation(fadeOut);
}
 
Example 3
Source File: BothWaySwipeRefreshLayout.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void startScaleUpAnimation(final int dir, Animation.AnimationListener listener) {
    mCircleViews[dir].setVisibility(View.VISIBLE);
    // Pre API 11, alpha is used in place of scale up to show the
    // progress circle appearing.
    // Don't adjust the alpha during appearance otherwise.
    mProgress[dir].setAlpha(MAX_ALPHA);
    mScaleAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(dir, interpolatedTime);
        }
    };
    mScaleAnimation.setDuration(mMediumAnimationDuration);
    if (listener != null) {
        mCircleViews[dir].setAnimationListener(listener);
    }
    mCircleViews[dir].clearAnimation();
    mCircleViews[dir].startAnimation(mScaleAnimation);
}
 
Example 4
Source File: GalleryView.java    From Nimbus with GNU General Public License v3.0 6 votes vote down vote up
public void expand(final View v) {
    v.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

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

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}
 
Example 5
Source File: MorphyToolbarUtils.java    From morphy-toolbar with MIT License 6 votes vote down vote up
/**
 * Animate the inner layout to the given margins
 *
 * @param endMargins array of margins at animation end
 * @return Animation to run
 */
public Animation animateInnerLayout(int[] endMargins) {
    final View innerLayout = morphyToolbar.getInnerLayout();
    final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) innerLayout.getLayoutParams();
    final int[] startMargins = {layoutParams.leftMargin, layoutParams.topMargin, layoutParams.rightMargin, layoutParams.bottomMargin};
    final int[] deltaMargins = {endMargins[0] - startMargins[0], endMargins[1] - startMargins[1],
                                endMargins[2] - startMargins[2], endMargins[3] - startMargins[3]};
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            layoutParams.setMargins(startMargins[0] + (int) (deltaMargins[0] * interpolatedTime),
                                    startMargins[1] + (int) (deltaMargins[1] * interpolatedTime),
                                    startMargins[2] + (int) (deltaMargins[2] * interpolatedTime),
                                    startMargins[3] + (int) (deltaMargins[3] * interpolatedTime));
            innerLayout.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };
    a.setInterpolator(new DecelerateInterpolator());
    a.setDuration(builder.animationDuration);
    return a;
}
 
Example 6
Source File: AnimationUtils.java    From patrol-android with GNU General Public License v3.0 5 votes vote down vote up
public static Animation getBlinkAnimation(){
    Animation animation = new AlphaAnimation(1, 0);         // Change alpha from fully visible to invisible
    animation.setDuration(300);                             // duration - half a second
    animation.setInterpolator(new LinearInterpolator());    // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE);                            // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE);             // Reverse animation at the end so the button will fade back in

    return animation;
}
 
Example 7
Source File: ArcLayout.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private static Animation createExpandAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
        long startOffset, long duration, Interpolator interpolator) {
    Animation animation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 0, 720);
    animation.setStartOffset(startOffset);
    animation.setDuration(duration);
    animation.setInterpolator(interpolator);
    animation.setFillAfter(true);

    return animation;
}
 
Example 8
Source File: BothWaySwipeRefreshLayout.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void startScaleDownAnimation(final int dir, Animation.AnimationListener listener) {
    mScaleDownAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(dir, 1 - interpolatedTime);
        }
    };
    mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mCircleViews[dir].setAnimationListener(listener);
    mCircleViews[dir].clearAnimation();
    mCircleViews[dir].startAnimation(mScaleDownAnimation);
}
 
Example 9
Source File: VoiceRecodingPanel.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public void moveTo(float x) {
    float offset = getOffset(x);
    Animation animation = new TranslateAnimation(Animation.ABSOLUTE, offset,
            Animation.ABSOLUTE, offset,
            Animation.RELATIVE_TO_SELF, 0,
            Animation.RELATIVE_TO_SELF, 0);

    animation.setDuration(0);
    animation.setFillAfter(true);
    animation.setFillBefore(true);

    slideToCancelView.startAnimation(animation);
}
 
Example 10
Source File: SwipeRefresh.java    From Android-Application-ZJB with Apache License 2.0 5 votes vote down vote up
private void startScaleDownAnimation(Animation.AnimationListener listener) {
    mScaleDownAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            setAnimationProgress(1 - interpolatedTime);
        }
    };
    mScaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mCircleView.setAnimationListener(listener);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(mScaleDownAnimation);
}
 
Example 11
Source File: CollapseView.java    From AndroidProjects with MIT License 5 votes vote down vote up
/**
 * 展开
 *
 * @param view 视图
 */
private void expand(final View view) {
    view.measure(parentWidthMeasureSpec, parentHeightMeasureSpec);
    final int measuredHeight = view.getMeasuredHeight();
    view.setVisibility(View.VISIBLE);

    Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            Log.e("TAG", "interpolatedTime = " + interpolatedTime);
            if (interpolatedTime == 1) {
                view.getLayoutParams().height = measuredHeight;
            } else {
                view.getLayoutParams().height = (int) (measuredHeight * interpolatedTime);
            }
            view.requestLayout();
        }

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

    };
    animation.setDuration(duration);
    view.startAnimation(animation);
}
 
Example 12
Source File: RepostWeiboWithAppSrcActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
private void showViewWithAnim(View view) {
        mSmileyPicker.setVisibility(View.VISIBLE);

        Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0);
        animation.setDuration(150);
//        animation.setFillAfter(true);

        view.startAnimation(animation);

    }
 
Example 13
Source File: BrowserActivity.java    From JumpGo with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Display the ActionBar using an animation if we are in full-screen
 * mode. This method also re-parents the ActionBar if its parent is
 * incorrect so that the animation can happen correctly.
 */
@Override
public void showActionBar() {
    if (mFullScreen) {
        Log.d(TAG, "showActionBar");
        if (mToolbarLayout == null)
            return;

        int height = mToolbarLayout.getHeight();
        if (height == 0) {
            mToolbarLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
            height = mToolbarLayout.getMeasuredHeight();
        }

        final int totalHeight = height;
        if (mToolbarLayout.getTranslationY() < -(height - 0.01f)) {
            Animation show = new Animation() {
                @Override
                protected void applyTransformation(float interpolatedTime, Transformation t) {
                    float trans = interpolatedTime * totalHeight;
                    mToolbarLayout.setTranslationY(trans - totalHeight);
                    setWebViewTranslation(trans);
                }
            };
            show.setDuration(250);
            show.setInterpolator(new BezierDecelerateInterpolator());
            mBrowserFrame.startAnimation(show);
        }
    }
}
 
Example 14
Source File: ContainerViewManager.java    From Paginize with MIT License 5 votes vote down vote up
private Animation createAnimation(
    int fromXType, float fromXValue,
    int toXType, float toXValue,
    Animation.AnimationListener animationListener) {
  Animation animation = new TranslateAnimation(fromXType, fromXValue, toXType,
      toXValue, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
  animation.setDuration(mPageManager.getTransitionAnimationDuration());
  animation.setInterpolator(new DecelerateInterpolator(2.0f));
  animation.setAnimationListener(animationListener);
  return animation;
}
 
Example 15
Source File: MaterialRefreshLayout.java    From NestRefreshLayout with MIT License 5 votes vote down vote up
/**
 * @param listener {@link Animation.AnimationListener}
 */
private void startScaleDownAnimation(Animation.AnimationListener listener) {
    Animation scaleDownAnimation = new Animation() {
        @Override
        public void applyTransformation(float interpolatedTime, Transformation t) {
            mCircleView.scaleWithKeepingAspectRatio(1 - interpolatedTime);
        }
    };

    scaleDownAnimation.setDuration(SCALE_DOWN_DURATION);
    mCircleView.setAnimationListener(listener);
    mCircleView.clearAnimation();
    mCircleView.startAnimation(scaleDownAnimation);
}
 
Example 16
Source File: ClearWriteEditText.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 晃动动画
 * @param counts 半秒钟晃动多少下
 * @return
 */
public static Animation shakeAnimation(int counts) {
    Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
    translateAnimation.setInterpolator(new CycleInterpolator(counts));
    translateAnimation.setDuration(500);
    return translateAnimation;
}
 
Example 17
Source File: CleanEditText.java    From A-week-to-develop-android-app-plan with Apache License 2.0 4 votes vote down vote up
public static Animation shakeAnimation(int counts) {
	Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);
	translateAnimation.setInterpolator(new CycleInterpolator(counts));
	translateAnimation.setDuration(500);
	return translateAnimation;
}
 
Example 18
Source File: AttachmentTypeSelector.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
private void animateWindowInTranslate(@NonNull View contentView) {
  Animation animation = new TranslateAnimation(0, 0, contentView.getHeight(), 0);
  animation.setDuration(ANIMATION_DURATION);

  getContentView().startAnimation(animation);
}
 
Example 19
Source File: ViewUtil.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static Animation getAlphaAnimation(float from, float to, int duration) {
  final Animation anim = new AlphaAnimation(from, to);
  anim.setInterpolator(new FastOutSlowInInterpolator());
  anim.setDuration(duration);
  return anim;
}
 
Example 20
Source File: Animations.java    From WaniKani-for-Android with GNU General Public License v3.0 4 votes vote down vote up
public static Animation FadeOut() {
    Animation anim = new AlphaAnimation(1 ,0);
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(500);
    return anim;
}