Java Code Examples for android.view.animation.TranslateAnimation#setFillEnabled()

The following examples show how to use android.view.animation.TranslateAnimation#setFillEnabled() . 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: Animate.java    From Simple-Solitaire with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Same as moveCard, but without the user specified speed factor. Used for the win animation.
 *
 * @param card The card to move
 * @param pX   X-coordinate of the destination
 * @param pY   Y-coordinate of the destination
 */
public void moveCardSlow(final Card card, final float pX, final float pY) {
    final CustomImageView view = card.view;

    if (card.isInvisible()) {
        return;
    }

    int distance = (int) Math.sqrt(Math.pow(pX - view.getX(), 2) + Math.pow(pY - view.getY(), 2));

    TranslateAnimation animation = new TranslateAnimation(0, pX - view.getX(), 0, pY - view.getY());

    try {
        animation.setDuration((long) (distance * 100 / Card.width));
    } catch (ArithmeticException e) {
        animation.setDuration(200);
        Log.e("Animate moveCard()", e.toString());
    }

    animation.setFillEnabled(true);

    view.setDestination(pX, pY);
    view.startAnimation(animation);
}
 
Example 2
Source File: Animate.java    From Simple-Solitaire with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Moves a card to a new destination. FillEnabled is necessary, or else flickering will occur.
 * The location is updated when the animation finishes, which happens in the onAnimationEnd()
 * method of the custom image view.
 *
 * @param card The card to move
 * @param pX   X-coordinate of the destination
 * @param pY   Y-coordinate of the destination
 */
public void moveCard(final Card card, final float pX, final float pY) {
    final CustomImageView view = card.view;
    int distance = (int) Math.sqrt(Math.pow(pX - view.getX(), 2) + Math.pow(pY - view.getY(), 2));

    TranslateAnimation animation = new TranslateAnimation(0, pX - view.getX(), 0, pY - view.getY());

    //there were some reports about an exception here, so simply set duration with a fixed value
    //if the exception occurs
    try {
        animation.setDuration((long) (distance * 100 / Card.width / speedFactor));
    } catch (ArithmeticException e) {
        animation.setDuration(100);
        Log.e("Animate moveCard()", e.toString());
    }

    animation.setFillEnabled(true);

    view.setDestination(pX, pY);
    view.startAnimation(animation);
}
 
Example 3
Source File: ClassTabWidget.java    From iSCAU-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * true the underline control to the click position
 * @param position
 */
public void changeWeekDay(int position){

    float offset = (float) (getWidth() - getPaddingLeft() - getPaddingRight()) / 7;

    LinearLayout.LayoutParams params = (LayoutParams) iv_underline.getLayoutParams();
    params.width = (int) offset;
    iv_underline.setLayoutParams(params);

    TranslateAnimation animation = new TranslateAnimation(
            offset * currentPosition ,position * offset,0,0);

    animation.setFillAfter(true);
    animation.setFillEnabled(true);
    animation.setDuration(300);
    iv_underline.startAnimation(animation);

    setTabTextStyle(currentPosition,false);
    setTabTextStyle(position,true);
    currentPosition = position;
}
 
Example 4
Source File: UIHelpers.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("NewApi")
public static void translateY(final View view, float fromY, float toY, long duration)
{
	if (Build.VERSION.SDK_INT >= 12)
	{
		if (duration == 0)
			view.setTranslationY(toY);
		else
			view.animate().translationY(toY).setDuration(duration).start();
	}
	else
	{
		TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY);
		translate.setDuration(duration);
		translate.setFillEnabled(true);
		translate.setFillBefore(true);
		translate.setFillAfter(true);
		addAnimation(view, translate);
	}
}
 
Example 5
Source File: MultiColumnPullToRefreshListView.java    From EverMemo with MIT License 6 votes vote down vote up
private void bounceBackHeader(){
	int yTranslate = state == State.REFRESHING ?
			header.getHeight() - headerContainer.getHeight() :
				-headerContainer.getHeight() - headerContainer.getTop();

			bounceAnimation = new TranslateAnimation(
					TranslateAnimation.ABSOLUTE, 0,
					TranslateAnimation.ABSOLUTE, 0,
					TranslateAnimation.ABSOLUTE, 0,
					TranslateAnimation.ABSOLUTE, yTranslate);

			bounceAnimation.setDuration(BOUNCE_ANIMATION_DURATION);
			bounceAnimation.setFillEnabled(true);
			bounceAnimation.setFillAfter(false);
			bounceAnimation.setFillBefore(true);
			//bounceAnimation.setInterpolator(new OvershootInterpolator(BOUNCE_OVERSHOOT_TENSION));
			bounceAnimation.setAnimationListener(new HeaderAnimationListener(yTranslate));
			startAnimation(bounceAnimation);
}
 
Example 6
Source File: AnimUtils.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
public static TranslateAnimation getPortraitTranslateAnimation(int start, int end, int durationMillis) {
    TranslateAnimation translateAnimation = new TranslateAnimation(0.0F, 0.0F, (float) start, (float) end);
    translateAnimation.setDuration((long) durationMillis);
    translateAnimation.setFillEnabled(true);
    translateAnimation.setFillAfter(true);
    return translateAnimation;
}
 
Example 7
Source File: DragDropGrid.java    From android-draggable-viewpager with Apache License 2.0 5 votes vote down vote up
private TranslateAnimation createTranslateAnimation(Point oldOffset, Point newOffset) {
    TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, oldOffset.x,
            Animation.ABSOLUTE, newOffset.x,
            Animation.ABSOLUTE, oldOffset.y,
            Animation.ABSOLUTE, newOffset.y);
    translate.setDuration(ANIMATION_DURATION);
    translate.setFillEnabled(true);
    translate.setFillAfter(true);
    translate.setInterpolator(new AccelerateDecelerateInterpolator());
    return translate;
}
 
Example 8
Source File: AnimationHelpers.java    From ripple with GNU General Public License v3.0 5 votes vote down vote up
public static void translateY(final View view, float fromY, float toY, long duration) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0)
            view.setTranslationY(toY);
        else
            view.animate().translationY(toY).setDuration(duration).start();
    } else {
        TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY);
        translate.setDuration(duration);
        translate.setFillEnabled(true);
        translate.setFillBefore(true);
        translate.setFillAfter(true);
        addAnimation(view, translate);
    }
}
 
Example 9
Source File: SpanVariableGridView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected final void translateChild(View v, Point prev, Point now) {

        TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, -now.x + prev.x, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -now.y
                + prev.y, Animation.ABSOLUTE, 0);
        translate.setInterpolator(new AccelerateInterpolator(4f));
        translate.setDuration(350);
        translate.setFillEnabled(false);
        translate.setFillAfter(false);

        v.clearAnimation();
        v.startAnimation(translate);
    }
 
Example 10
Source File: SpanVariableGridView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected final void translateChild(View v, Point prev, Point now) {

        TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, -now.x + prev.x, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -now.y
                + prev.y, Animation.ABSOLUTE, 0);
        translate.setInterpolator(new AccelerateInterpolator(4f));
        translate.setDuration(350);
        translate.setFillEnabled(false);
        translate.setFillAfter(false);

        v.clearAnimation();
        v.startAnimation(translate);
    }
 
Example 11
Source File: SpanVariableGridView.java    From XMouse with MIT License 5 votes vote down vote up
protected final void translateChild(View v, Point prev, Point now) {

		TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, -now.x + prev.x, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -now.y
				+ prev.y, Animation.ABSOLUTE, 0);
		translate.setInterpolator(new AccelerateInterpolator(4f));
		translate.setDuration(350);
		translate.setFillEnabled(false);
		translate.setFillAfter(false);

		v.clearAnimation();
		v.startAnimation(translate);
	}
 
Example 12
Source File: DraggableGridViewPager.java    From Android-DraggableGridViewPager with MIT License 4 votes vote down vote up
private void animateGap(int target) {
	for (int i = 0; i < getChildCount(); i++) {
		View v = getChildAt(i);
		if (i == mLastDragged) {
			continue;
		}

		int newPos = i;
		if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
			newPos--;
		} else if (target < mLastDragged && i >= target && i < mLastDragged) {
			newPos++;
		}

		int oldPos = i;
		if (newPositions.get(i) != -1) {
			oldPos = newPositions.get(i);
		}

		if (oldPos == newPos) {
			continue;
		}

		// animate
		DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos);
		final Rect oldRect = getRectByPosition(oldPos);
		final Rect newRect = getRectByPosition(newPos);
		oldRect.offset(-v.getLeft(), -v.getTop());
		newRect.offset(-v.getLeft(), -v.getTop());

		TranslateAnimation translate = new TranslateAnimation(
				oldRect.left, newRect.left,
				oldRect.top, newRect.top);
		translate.setDuration(ANIMATION_DURATION);
		translate.setFillEnabled(true);
		translate.setFillAfter(true);
		v.clearAnimation();
		v.startAnimation(translate);

		newPositions.set(i, newPos);
	}
}
 
Example 13
Source File: DraggableGridViewPager.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private void animateGap(int target) {
	for (int i = 0; i < getChildCount(); i++) {
		View v = getChildAt(i);
		if (i == mLastDragged) {
			continue;
		}

		int newPos = i;
		if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
			newPos--;
		} else if (target < mLastDragged && i >= target && i < mLastDragged) {
			newPos++;
		}

		int oldPos = i;
		if (newPositions.get(i) != -1) {
			oldPos = newPositions.get(i);
		}

		if (oldPos == newPos) {
			continue;
		}

		// animate
		DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos);
		final Rect oldRect = getRectByPosition(oldPos);
		final Rect newRect = getRectByPosition(newPos);
		oldRect.offset(-v.getLeft(), -v.getTop());
		newRect.offset(-v.getLeft(), -v.getTop());

		TranslateAnimation translate = new TranslateAnimation(
				oldRect.left, newRect.left,
				oldRect.top, newRect.top);
		translate.setDuration(ANIMATION_DURATION);
		translate.setFillEnabled(true);
		translate.setFillAfter(true);
		v.clearAnimation();
		v.startAnimation(translate);

		newPositions.set(i, newPos);
	}
}
 
Example 14
Source File: DraggableGridViewPager.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private void animateGap(int target) {
	for (int i = 0; i < getChildCount(); i++) {
		View v = getChildAt(i);
		if (i == mLastDragged) {
			continue;
		}

		int newPos = i;
		if (mLastDragged < target && i >= mLastDragged + 1 && i <= target) {
			newPos--;
		} else if (target < mLastDragged && i >= target && i < mLastDragged) {
			newPos++;
		}

		int oldPos = i;
		if (newPositions.get(i) != -1) {
			oldPos = newPositions.get(i);
		}

		if (oldPos == newPos) {
			continue;
		}

		// animate
		DEBUG_LOG("animateGap from=" + oldPos + ", to=" + newPos);
		final Rect oldRect = getRectByPosition(oldPos);
		final Rect newRect = getRectByPosition(newPos);
		oldRect.offset(-v.getLeft(), -v.getTop());
		newRect.offset(-v.getLeft(), -v.getTop());

		TranslateAnimation translate = new TranslateAnimation(
				oldRect.left, newRect.left,
				oldRect.top, newRect.top);
		translate.setDuration(ANIMATION_DURATION);
		translate.setFillEnabled(true);
		translate.setFillAfter(true);
		v.clearAnimation();
		v.startAnimation(translate);

		newPositions.set(i, newPos);
	}
}