Search in sources :

Example 76 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project commons-gdx by gemserk.

the class AdViewHandler method showAds.

private void showAds(Message msg) {
    AdsParameters adsParameters = (AdsParameters) msg.obj;
    if (adsParameters != null) {
        updateAligns(adsParameters);
        RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        adParams.addRule(verticalAlign);
        adParams.addRule(horizontalAlign);
        layout.removeView(adView);
        layout.addView(adView, adParams);
        if (adsParameters.animationsEnabled) {
            ArrayList<AdsAnimation> animations = adsParameters.animations;
            int size = animations.size();
            for (int i = 0; i < size; i++) {
                AdsAnimation adsAnimation = animations.get(i);
                if (adsAnimation.type == AdsAnimation.Type.Alpha) {
                    AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
                    animation.setDuration(adsAnimation.duration);
                    animation.setFillAfter(false);
                    animation.setInterpolator(new LinearInterpolator());
                    animation.setAnimationListener(new ShowAnimationListener(adView));
                    adView.startAnimation(animation);
                // System.out.println("showing with animation alpha");
                } else if (adsAnimation.type == Type.Translation) {
                    float yDelta = verticalAlign == RelativeLayout.ALIGN_PARENT_TOP ? -75f : 75f;
                    TranslateAnimation animation = new TranslateAnimation(0, 0, yDelta, 0);
                    animation.setDuration(adsAnimation.duration);
                    animation.setInterpolator(new LinearInterpolator());
                    animation.setAnimationListener(new ShowAnimationListener(adView));
                    adView.startAnimation(animation);
                // System.out.println("showing with animation translation");
                } else {
                    adView.setVisibility(View.VISIBLE);
                }
            }
        } else {
            adView.setVisibility(View.VISIBLE);
        }
    } else {
        adView.setVisibility(View.VISIBLE);
    }
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) RelativeLayout(android.widget.RelativeLayout) TranslateAnimation(android.view.animation.TranslateAnimation) AlphaAnimation(android.view.animation.AlphaAnimation)

Example 77 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project SunDay by iQuick.

the class DefaultAnimationsBuilder method buildDefaultSlideInDownAnimation.

/**
 * @param croutonView
 *   The croutonView which gets animated.
 *
 * @return The default Animation for a showing {@link Crouton}.
 */
static Animation buildDefaultSlideInDownAnimation(View croutonView) {
    if (!areLastMeasuredInAnimationHeightAndCurrentEqual(croutonView) || (null == slideInDownAnimation)) {
        slideInDownAnimation = new TranslateAnimation(// X: from, to
        0, // X: from, to
        0, // Y: from, to
        -croutonView.getMeasuredHeight(), // Y: from, to
        0);
        slideInDownAnimation.setDuration(DURATION);
        setLastInAnimationHeight(croutonView.getMeasuredHeight());
    }
    return slideInDownAnimation;
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation)

Example 78 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project android-satellite-menu by siyamed.

the class SatelliteAnimationCreator method createItemOutAnimation.

public static Animation createItemOutAnimation(Context context, int index, long expandDuration, int x, int y) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);
    long alphaDuration = 60;
    if (expandDuration < 60) {
        alphaDuration = expandDuration / 4;
    }
    alphaAnimation.setDuration(alphaDuration);
    alphaAnimation.setStartOffset(0);
    TranslateAnimation translate = new TranslateAnimation(0, x, 0, y);
    translate.setStartOffset(0);
    translate.setDuration(expandDuration);
    translate.setInterpolator(context, R.anim.sat_item_overshoot_interpolator);
    RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    rotate.setInterpolator(context, R.anim.sat_item_out_rotate_interpolator);
    long duration = 100;
    if (expandDuration <= 150) {
        duration = expandDuration / 3;
    }
    rotate.setDuration(expandDuration - duration);
    rotate.setStartOffset(duration);
    AnimationSet animationSet = new AnimationSet(false);
    animationSet.setFillAfter(false);
    animationSet.setFillBefore(true);
    animationSet.setFillEnabled(true);
    // animationSet.addAnimation(alphaAnimation);
    // animationSet.addAnimation(rotate);
    animationSet.addAnimation(translate);
    animationSet.setStartOffset(30 * index);
    return animationSet;
}
Also used : RotateAnimation(android.view.animation.RotateAnimation) TranslateAnimation(android.view.animation.TranslateAnimation) AnimationSet(android.view.animation.AnimationSet) AlphaAnimation(android.view.animation.AlphaAnimation)

Example 79 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project robolectric by robolectric.

the class ShadowAnimationUtils method loadLayoutAnimation.

@Implementation
protected static LayoutAnimationController loadLayoutAnimation(Context context, int id) {
    Animation anim = new TranslateAnimation(0, 0, 30, 0);
    LayoutAnimationController layoutAnim = new LayoutAnimationController(anim);
    ShadowLayoutAnimationController shadowLayoutAnimationController = Shadow.extract(layoutAnim);
    shadowLayoutAnimationController.setLoadedFromResourceId(id);
    return layoutAnim;
}
Also used : LayoutAnimationController(android.view.animation.LayoutAnimationController) TranslateAnimation(android.view.animation.TranslateAnimation) Animation(android.view.animation.Animation) TranslateAnimation(android.view.animation.TranslateAnimation) Implementation(org.robolectric.annotation.Implementation)

Example 80 with TranslateAnimation

use of android.view.animation.TranslateAnimation in project smartmodule by carozhu.

the class ReboundScrollView method dispatchTouchEvent.

/**
 * 在触摸事件中, 处理上拉和下拉的逻辑
 */
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (contentView == null) {
        return super.dispatchTouchEvent(ev);
    }
    int action = ev.getAction();
    switch(action) {
        case MotionEvent.ACTION_DOWN:
            // 判断是否可以上拉和下拉
            canPullDown = isCanPullDown();
            canPullUp = isCanPullUp();
            // 记录按下时的Y值
            startY = ev.getY();
            break;
        case MotionEvent.ACTION_UP:
            // 如果没有移动布局, 则跳过执行
            if (!isMoved)
                break;
            // 开启动画
            TranslateAnimation anim = new TranslateAnimation(0, 0, contentView.getTop(), originalRect.top);
            anim.setDuration(ANIM_TIME);
            contentView.startAnimation(anim);
            // 设置回到正常的布局位置
            contentView.layout(originalRect.left, originalRect.top, originalRect.right, originalRect.bottom);
            // 将标志位设回false
            canPullDown = false;
            canPullUp = false;
            isMoved = false;
            break;
        case MotionEvent.ACTION_MOVE:
            // 在移动的过程中, 既没有滚动到可以上拉的程度, 也没有滚动到可以下拉的程度
            if (!canPullDown && !canPullUp) {
                startY = ev.getY();
                canPullDown = isCanPullDown();
                canPullUp = isCanPullUp();
                break;
            }
            // 计算手指移动的距离
            float nowY = ev.getY();
            int deltaY = (int) (nowY - startY);
            // 是否应该移动布局
            boolean shouldMove = // 可以下拉, 并且手指向下移动
            (canPullDown && deltaY > 0) || // 可以上拉, 并且手指向上移动
            (canPullUp && deltaY < 0) || // 既可以上拉也可以下拉(这种情况出现在ScrollView包裹的控件比ScrollView还小)
            (canPullUp && canPullDown);
            if (shouldMove) {
                // 计算偏移量
                int offset = (int) (deltaY * MOVE_FACTOR);
                // 随着手指的移动而移动布局
                contentView.layout(originalRect.left, originalRect.top + offset, originalRect.right, originalRect.bottom + offset);
                // 记录移动了布局
                isMoved = true;
            }
            break;
        default:
            break;
    }
    return super.dispatchTouchEvent(ev);
}
Also used : TranslateAnimation(android.view.animation.TranslateAnimation)

Aggregations

TranslateAnimation (android.view.animation.TranslateAnimation)229 Animation (android.view.animation.Animation)109 AlphaAnimation (android.view.animation.AlphaAnimation)90 AnimationSet (android.view.animation.AnimationSet)69 ScaleAnimation (android.view.animation.ScaleAnimation)44 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)30 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)27 View (android.view.View)22 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)22 TextView (android.widget.TextView)18 AnimationListener (android.view.animation.Animation.AnimationListener)17 LinearInterpolator (android.view.animation.LinearInterpolator)13 RotateAnimation (android.view.animation.RotateAnimation)13 ClipRectAnimation (android.view.animation.ClipRectAnimation)12 ListView (android.widget.ListView)12 CurvedTranslateAnimation (com.android.server.wm.animation.CurvedTranslateAnimation)12 ImageView (android.widget.ImageView)11 LayoutAnimationController (android.view.animation.LayoutAnimationController)8 WindowAnimation_activityCloseEnterAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseEnterAnimation)8 WindowAnimation_activityCloseExitAnimation (com.android.internal.R.styleable.WindowAnimation_activityCloseExitAnimation)8