List of usage examples for android.view.animation Animation.AnimationListener Animation.AnimationListener
Animation.AnimationListener
From source file:cn.finalteam.loadingviewfinal.header.MaterialProgressDrawable.java
private void setupAnimators() { final Ring ring = mRing; final Animation finishRingAnimation = new Animation() { public void applyTransformation(float interpolatedTime, Transformation t) { // shrink back down and complete a full rotation before starting other circles // Rotation goes between [0..1]. float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC) + 1f); final float startTrim = ring.getStartingStartTrim() + (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime; ring.setStartTrim(startTrim); final float rotation = ring.getStartingRotation() + ((targetRotation - ring.getStartingRotation()) * interpolatedTime); ring.setRotation(rotation);//from www. j a va 2 s .c om ring.setArrowScale(1 - interpolatedTime); } }; finishRingAnimation.setInterpolator(EASE_INTERPOLATOR); finishRingAnimation.setDuration(ANIMATION_DURATION / 2); finishRingAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { ring.goToNextColor(); ring.storeOriginals(); ring.setShowArrow(false); mParent.startAnimation(mAnimation); } @Override public void onAnimationRepeat(Animation animation) { } }); final Animation animation = new Animation() { @Override public void applyTransformation(float interpolatedTime, Transformation t) { // The minProgressArc is calculated from 0 to create an angle that // matches the stroke width. final float minProgressArc = (float) Math .toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius())); final float startingEndTrim = ring.getStartingEndTrim(); final float startingTrim = ring.getStartingStartTrim(); final float startingRotation = ring.getStartingRotation(); // Offset the minProgressArc to where the endTrim is located. final float minArc = MAX_PROGRESS_ARC - minProgressArc; final float endTrim = startingEndTrim + (minArc * START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime)); ring.setEndTrim(endTrim); final float startTrim = startingTrim + (MAX_PROGRESS_ARC * END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime)); ring.setStartTrim(startTrim); final float rotation = startingRotation + (0.25f * interpolatedTime); ring.setRotation(rotation); float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime) + (720.0f * (mRotationCount / NUM_POINTS)); setRotation(groupRotation); } }; animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.RESTART); animation.setInterpolator(LINEAR_INTERPOLATOR); animation.setDuration(ANIMATION_DURATION); 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()); mRotationCount = (mRotationCount + 1) % (NUM_POINTS); } }); mFinishAnimation = finishRingAnimation; mAnimation = animation; }
From source file:com.juick.android.ThreadFragment.java
private void closeNavigationMenu() { navigationMenuShown = false;/*from w w w . j a va 2 s . c o m*/ for (int i = 0; i < flyingItems.length; i++) { final FlyingItem item = flyingItems[i]; item.setVisibility(View.VISIBLE); item.ani = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -item.designedX + item.widget.getWidth() * 1.5f, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -item.designedY); item.ani.setDuration(500); item.ani.setInterpolator(new AccelerateInterpolator(1)); item.ani.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { item.setVisibility(View.GONE); item.widget.clearAnimation(); item.widget.disableReposition = false; item.widget.layout(item.originalHitRect.left, item.originalHitRect.top, item.originalHitRect.right, item.originalHitRect.bottom); if (item == flyingItems[0]) { TranslateAnimation aniIn = new TranslateAnimation(Animation.ABSOLUTE, 600, Animation.ABSOLUTE, initNavMenuTranslationX, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); aniIn.setInterpolator(new DecelerateInterpolator(1)); item.ani.setDuration(500); aniIn.setFillAfter(true); navMenu.startAnimation(aniIn); } } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); item.ani.setFillAfter(true); item.widget.startAnimation(item.ani); } }
From source file:com.juick.android.ThreadFragment.java
private void openNavigationMenu(float currentTranslation) { try {/* www. ja v a2 s . co m*/ navigationMenuShown = true; for (final FlyingItem item : flyingItems) { item.setVisibility(View.VISIBLE); item.ani = new TranslateAnimation(Animation.ABSOLUTE, 300, Animation.ABSOLUTE, item.designedX, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, item.designedY); item.ani.setInterpolator(new OvershootInterpolator(2)); item.ani.setDuration(500); item.ani.setFillAfter(true); item.ani.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } @Override public void onAnimationEnd(Animation animation) { // this code is very ugly because it's all android 2.3 animations. item.widget.getHitRect(item.originalHitRect); item.widget.clearAnimation(); item.widget.layout(item.originalHitRect.left + (int) item.widget.initialTranslationX, item.originalHitRect.top + (int) item.widget.initialTranslationY, item.originalHitRect.right + (int) item.widget.initialTranslationX, item.originalHitRect.bottom + (int) item.widget.initialTranslationY); item.widget.disableReposition = true; } @Override public void onAnimationRepeat(Animation animation) { //To change body of implemented methods use File | Settings | File Templates. } }); item.widget.startAnimation(item.ani); } TranslateAnimation aniOut = new TranslateAnimation(Animation.ABSOLUTE, currentTranslation, Animation.ABSOLUTE, -1.2f * getActivity().getWindowManager().getDefaultDisplay().getWidth(), Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 0); aniOut.setInterpolator(new DecelerateInterpolator(1)); aniOut.setDuration(700); aniOut.setFillAfter(true); navMenu.startAnimation(aniOut); getListView().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } catch (Throwable e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }