Java Code Examples for android.view.animation.AlphaAnimation

The following examples show how to use android.view.animation.AlphaAnimation. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: scene   Source File: AnimatorUtilityTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResetViewStatus() {
    ActivityController<NavigationSourceUtility.TestActivity> controller = Robolectric.buildActivity(NavigationSourceUtility.TestActivity.class).create().start().resume();
    NavigationSourceUtility.TestActivity testActivity = controller.get();
    View view = new View(testActivity);
    view.setTranslationX(1);
    view.setTranslationY(1);
    view.setScaleX(2.0f);
    view.setScaleY(2.0f);
    view.setRotation(1.0f);
    view.setRotationX(1.0f);
    view.setRotationY(1.0f);
    view.setAlpha(0.5f);
    view.startAnimation(new AlphaAnimation(0.0f, 1.0f));

    AnimatorUtility.resetViewStatus(view);
    assertEquals(0.0f, view.getTranslationX(), 0.0f);
    assertEquals(0.0f, view.getTranslationY(), 0.0f);
    assertEquals(1.0f, view.getScaleX(), 0.0f);
    assertEquals(1.0f, view.getScaleY(), 0.0f);
    assertEquals(0.0f, view.getRotation(), 0.0f);
    assertEquals(0.0f, view.getRotationX(), 0.0f);
    assertEquals(0.0f, view.getRotationY(), 0.0f);
    assertEquals(1.0f, view.getAlpha(), 0.0f);
    assertNull(view.getAnimation());
}
 
Example 2
public void showLogo() {
    _isLogoVisible = true;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Animation fadeIn = new AlphaAnimation(0, 0.8f);
            fadeIn.setInterpolator(new AccelerateInterpolator()); //and this
            fadeIn.setStartOffset(0);
            fadeIn.setDuration(500);
            //
            AnimationSet animation = new AnimationSet(false); //change to false
            animation.addAnimation(fadeIn);
            animation.setFillAfter(true);
            RelativeLayout ivLogo = (RelativeLayout) findViewById(R.id.logo);
            ivLogo.startAnimation(animation);
        }
    });
}
 
Example 3
Source Project: OpenEyes   Source File: ViewHolder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 设置透明度
 * @param viewId
 * @param value
 * @return
 */
@SuppressLint("NewApi")
public ViewHolder setAlpha(int viewId, float value)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
        getView(viewId).setAlpha(value);
    } else
    {
        // Pre-honeycomb hack to set Alpha value
        AlphaAnimation alpha = new AlphaAnimation(value, value);
        alpha.setDuration(0);
        alpha.setFillAfter(true);
        getView(viewId).startAnimation(alpha);
    }
    return this;
}
 
Example 4
Source Project: Gazetti_Newspaper_Reader   Source File: HomeScreenActivity.java    License: MIT License 6 votes vote down vote up
private AnimationSet getEntryAnimation(int inAnimationDuration) {
    //In
    AnimationSet mInAnimationSet = new AnimationSet(false);

    TranslateAnimation mSlideInAnimation = new TranslateAnimation(
            TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
            TranslateAnimation.RELATIVE_TO_PARENT, 0.0f,
            TranslateAnimation.RELATIVE_TO_SELF, -1.0f,
            TranslateAnimation.RELATIVE_TO_SELF, 0.0f);
    mSlideInAnimation.setFillAfter(true);

    AlphaAnimation mFadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
    mFadeInAnimation.setFillAfter(true);

    mInAnimationSet.addAnimation(mSlideInAnimation);
    mInAnimationSet.addAnimation(mFadeInAnimation);

    mInAnimationSet.setDuration(inAnimationDuration);

    return mInAnimationSet;

}
 
Example 5
Source Project: Paginize   Source File: ZoomPageAnimator.java    License: MIT License 6 votes vote down vote up
private void initAnimations() {
  Animation inScaleAnimation = new ScaleAnimation( 1.2f, 1, 1.2f, 1,
      Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
  Animation inAlphaAnimation = new AlphaAnimation(0.0f, 1f);
  AnimationSet inAnimationSet = new AnimationSet(true);
  inAnimationSet.setDuration(ANIMATION_DURATION);
  inAnimationSet.addAnimation(inScaleAnimation);
  inAnimationSet.addAnimation(inAlphaAnimation);
  mInAnimation = inAnimationSet;

  Animation outScaleAnimation = new ScaleAnimation(1, 1.4f, 1, 1.4f,
      Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
  Animation outAlphaAnimation = new AlphaAnimation(1f, 0f);
  AnimationSet outAnimationSet = new AnimationSet(true);
  outAnimationSet.setDuration(ANIMATION_DURATION);
  outAnimationSet.addAnimation(outScaleAnimation);
  outAnimationSet.addAnimation(outAlphaAnimation);
  mOutAnimation = outAnimationSet;
}
 
Example 6
public static void setAdapterInsertAnimation(final View aCard, int row, int height) {
	final int ANIMATION_DURATION = 650;
	final int BASE_DELAY = 50;

	TranslateAnimation translationAnimation = new TranslateAnimation(0,0, height,0);

	AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1f);

	final AnimationSet animationSet = new AnimationSet(true);
	animationSet.addAnimation(translationAnimation);
	animationSet.addAnimation(alphaAnimation);
	animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
	animationSet.setFillAfter(true);
	animationSet.setFillBefore(true);
	animationSet.setDuration(ANIMATION_DURATION + row * BASE_DELAY);

	aCard.setAnimation(animationSet);
}
 
Example 7
Source Project: YMenuView   Source File: TreeYMenu.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Animation createOptionDisappearAnimation(OptionButton optionButton, int index) {

    AnimationSet animationSet = new AnimationSet(true);
    TranslateAnimation translateAnimation= new TranslateAnimation(
            0
            ,getYMenuButton().getX() - optionButton.getX()
            ,0
            ,getYMenuButton().getY() - optionButton.getY()
    );
    translateAnimation.setDuration(getOptionSD_AnimationDuration());
    AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
    alphaAnimation.setDuration(getOptionSD_AnimationDuration());

    animationSet.addAnimation(translateAnimation);
    animationSet.addAnimation(alphaAnimation);
    //设置动画延时
    animationSet.setStartOffset(60*(getOptionPositionCount() - index));
    return animationSet;
}
 
Example 8
public void hideLogo() {
    _isLogoVisible = false;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Animation fadeOut = new AlphaAnimation(0.8f, 0);
            fadeOut.setInterpolator(new AccelerateInterpolator()); //and this
            fadeOut.setStartOffset(0);
            fadeOut.setDuration(500);
            //
            AnimationSet animation = new AnimationSet(false); //change to false
            animation.addAnimation(fadeOut);
            animation.setFillAfter(true);
            RelativeLayout ivLogo = (RelativeLayout) findViewById(R.id.logo);
            ivLogo.startAnimation(animation);
        }
    });
}
 
Example 9
Source Project: mobile-sdk-android   Source File: Reveal.java    License: Apache License 2.0 6 votes vote down vote up
private void setOutAnimation(float[] direction, Interpolator interpolator, long duration) {
    Animation push = new TranslateAnimation(
            Animation.RELATIVE_TO_PARENT, direction[0], Animation.RELATIVE_TO_PARENT, direction[1],
            Animation.RELATIVE_TO_PARENT, direction[2], Animation.RELATIVE_TO_PARENT, direction[3]
    );
    push.setInterpolator(interpolator);
    push.setDuration(duration);

    Animation fade = new AlphaAnimation(1, 0);
    fade.setDuration(duration);
    fade.setInterpolator(interpolator);

    AnimationSet set = new AnimationSet(false);
    set.addAnimation(push);
    set.addAnimation(fade);

    outAnimation = set;
}
 
Example 10
Source Project: candybar   Source File: FadeInBitmapDisplayer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Animates {@link ImageView} with "fade-in" effect
 *
 * @param imageView      {@link ImageView} which display image in
 * @param durationMillis The length of the animation in milliseconds
 */
public static void animate(View imageView, int durationMillis) {
    if (imageView != null) {
        AlphaAnimation fadeImage = new AlphaAnimation(0, 1);
        fadeImage.setDuration(durationMillis);
        fadeImage.setInterpolator(new DecelerateInterpolator());
        imageView.startAnimation(fadeImage);
    }
}
 
Example 11
private void fadeOnAck(@Order.Status String status, View view) {

        clearAnimation(view);

        if (status.equals(ACKNOWLEDGED)) {

            AlphaAnimation alphaAnimation = new AlphaAnimation(0.3f, 0.9f);
            alphaAnimation.setDuration(700);
            alphaAnimation.setRepeatMode(Animation.REVERSE);
            alphaAnimation.setRepeatCount(Animation.INFINITE);
            view.setAnimation(alphaAnimation);
            alphaAnimation.start();



            // color animation
/*        ObjectAnimator slide = ObjectAnimator.ofObject(view,
                "backgroundColor",
                new ArgbEvaluator(),
                ContextCompat.getColor(App.getContext(), R.color.white),
                ContextCompat.getColor(App.getContext(), R.color.md_deep_orange_50));*/

            /*     ObjectAnimator slide = ObjectAnimator.ofFloat(view,
                    "alpha", 0.3f, 0.9f);
            slide.setInterpolator(new AccelerateDecelerateInterpolator());
            slide.setDuration(700);
            slide.setRepeatCount(ValueAnimator.INFINITE);
            slide.setRepeatMode(ValueAnimator.REVERSE);
            slide.start();*/
        }
    }
 
Example 12
Source Project: bither-android   Source File: SensorVisualizerView.java    License: Apache License 2.0 5 votes vote down vote up
public void onSensorData(final Sensor sensor) {
    if (animatingSensors.contains(sensor.getType()) || holdingBackNextFlash) {
        return;
    }
    holdingBackNextFlash = true;
    
    postDelayed(new Runnable() {
        @Override
        public void run() {
            holdingBackNextFlash = false;
        }
    }, FlashDuration / 2);

    post(new Runnable() {
        @Override
        public void run() {
            Integer id = ViewIds.get(sensor.getType());
            if (id == null) {
                return;
            }
            View v = findViewById(id);
            if (v == null) {
                return;
            }
            animatingSensors.add(sensor.getType());
            AlphaAnimation fadeIn = new AlphaAnimation(FadeAlpha, FlashAlpha);
            fadeIn.setDuration(FlashDuration);
            AlphaAnimation fadeOut = new AlphaAnimation(FlashAlpha, FadeAlpha);
            fadeOut.setDuration(FlashDuration);
            fadeOut.setStartOffset(fadeIn.getDuration() + FlashDuration / 2);
            AnimationSet set = new AnimationSet(false);
            set.addAnimation(fadeIn);
            set.addAnimation(fadeOut);
            set.setAnimationListener(new FadeAnimListener(sensor.getType()));
            set.setFillAfter(true);
            v.startAnimation(set);
        }
    });
}
 
Example 13
Source Project: KJFrameForAndroid   Source File: KJAnimations.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 透明度 Alpha
 */
public static Animation getAlphaAnimation(float fromAlpha, float toAlpha,
        long durationMillis) {
    AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha);
    alpha.setDuration(durationMillis);
    alpha.setFillAfter(true);
    return alpha;
}
 
Example 14
private void setAlpha(View view, float alpha, long durationMillis) {
    if (Build.VERSION.SDK_INT < 11) {
        final AlphaAnimation animation = new AlphaAnimation(alpha, alpha);
        animation.setDuration(durationMillis);
        animation.setFillAfter(true);
        view.startAnimation(animation);
    } else {
        view.setAlpha(alpha);
    }
}
 
Example 15
Source Project: VIA-AI   Source File: LoadingWrapper.java    License: MIT License 5 votes vote down vote up
/**
 @brief Hide the wrapper.
 */
public void hide()
{
    mUI_LoadingProgress.stop();
    AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f);
    anim.setDuration(1000);
    anim.setRepeatCount(0);
    this.startAnimation(anim);
    this.setVisibility(View.INVISIBLE);
}
 
Example 16
/**
 * Animates {@link ImageView} with "fade-in" effect
 *
 * @param imageView      {@link ImageView} which display image in
 * @param durationMillis The length of the animation in milliseconds
 */
public static void animate(View imageView, int durationMillis) {
	if (imageView != null) {
		AlphaAnimation fadeImage = new AlphaAnimation(0, 1);
		fadeImage.setDuration(durationMillis);
		fadeImage.setInterpolator(new DecelerateInterpolator());
		imageView.startAnimation(fadeImage);
	}
}
 
Example 17
Source Project: star-zone-android   Source File: AnimUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static AlphaAnimation getAlphaAnimation(float start, float end, long durationMillis) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(start, end);
    alphaAnimation.setDuration(durationMillis);
    alphaAnimation.setFillEnabled(true);
    alphaAnimation.setFillAfter(true);
    return alphaAnimation;
}
 
Example 18
Source Project: Android-Notification   Source File: AnimationFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create push down animation for entering.
 *
 * @return Animation
 */
public static Animation pushDownIn() {
    AnimationSet animationSet = new AnimationSet(true);
    animationSet.setFillAfter(true);
    animationSet.addAnimation(new TranslateAnimation(0, 0, -100, 0));
    animationSet.addAnimation(new AlphaAnimation(0.0f, 1.0f));
    return animationSet;
}
 
Example 19
Source Project: star-zone-android   Source File: PopupProgress.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Animation initExitAnimation() {
    AlphaAnimation alphaAnimation = new AlphaAnimation(1.0F, 0.0F);
    alphaAnimation.setDuration(300L);
    alphaAnimation.setInterpolator(new AccelerateInterpolator());
    return alphaAnimation;
}
 
Example 20
Source Project: adt-leanback-support   Source File: FragmentManager.java    License: Apache License 2.0 5 votes vote down vote up
static Animation makeOpenCloseAnimation(Context context, float startScale,
        float endScale, float startAlpha, float endAlpha) {
    AnimationSet set = new AnimationSet(false);
    ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
            Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
    scale.setInterpolator(DECELERATE_QUINT);
    scale.setDuration(ANIM_DUR);
    set.addAnimation(scale);
    AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
    alpha.setInterpolator(DECELERATE_CUBIC);
    alpha.setDuration(ANIM_DUR);
    set.addAnimation(alpha);
    return set;
}
 
Example 21
Source Project: YuanNewsForAndroid   Source File: AnimationLoader.java    License: Apache License 2.0 5 votes vote down vote up
public static AnimationSet getOutAnimation(Context context) {
    AnimationSet out = new AnimationSet(context, null);
    AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f);
    alpha.setDuration(150);
    ScaleAnimation scale = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    scale.setDuration(150);
    out.addAnimation(alpha);
    out.addAnimation(scale);
    return out;
}
 
Example 22
Source Project: ShowCaseView   Source File: GuideView.java    License: Apache License 2.0 5 votes vote down vote up
public void show() {
    this.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    this.setClickable(false);

    ((ViewGroup) ((Activity) getContext()).getWindow().getDecorView()).addView(this);
    AlphaAnimation startAnimation = new AlphaAnimation(0.0f, 1.0f);
    startAnimation.setDuration(APPEARING_ANIMATION_DURATION);
    startAnimation.setFillAfter(true);
    this.startAnimation(startAnimation);
    mIsShowing = true;
}
 
Example 23
Source Project: zen4android   Source File: IcsProgressBar.java    License: MIT License 5 votes vote down vote up
/**
 * <p>
 * Initialize the progress bar's default values:
 * </p>
 * <ul>
 * <li>progress = 0</li>
 * <li>max = 100</li>
 * <li>animation duration = 4000 ms</li>
 * <li>indeterminate = false</li>
 * <li>behavior = repeat</li>
 * </ul>
 */
private void initProgressBar() {
    mMax = 100;
    mProgress = 0;
    mSecondaryProgress = 0;
    mIndeterminate = false;
    mOnlyIndeterminate = false;
    mDuration = 4000;
    mBehavior = AlphaAnimation.RESTART;
    mMinWidth = 24;
    mMaxWidth = 48;
    mMinHeight = 24;
    mMaxHeight = 48;
}
 
Example 24
Source Project: barterli_android   Source File: AnimateImageView.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {

        if(attrs == null) {
            initializeWithDefaults();
        } else {
            TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.AnimateImageView);

            if(attributes == null) {
                initializeWithDefaults();
            }

            else {
                mShouldAnimateChanges = attributes.getBoolean(R.styleable.AnimateImageView_animate_changes, false);
                int inAnimationResId = attributes.getResourceId(R.styleable.AnimateImageView_in_animation, 0);
                int outAnimationResId = attributes.getResourceId(R.styleable.AnimateImageView_out_animation, 0);
                attributes.recycle();

                if(inAnimationResId == 0) {
                    mInAnimation = new AlphaAnimation(0.0f, 1.0f);
                    mInAnimation.setDuration(400);
                    mInAnimation.setFillAfter(true);
                } else {
                    mInAnimation = AnimationUtils.loadAnimation(context, inAnimationResId);
                }

                if(outAnimationResId == 0) {
                    mOutAnimation = new AlphaAnimation(1.0f, 0.0f);
                    mOutAnimation.setDuration(150);
                    mOutAnimation.setFillAfter(true);
                } else {
                    mOutAnimation = AnimationUtils.loadAnimation(context, outAnimationResId);
                }

                mInAnimation.setAnimationListener(this);
                mOutAnimation.setAnimationListener(this);
            }
        }
    }
 
Example 25
Source Project: PianoTiles   Source File: CountDownView.java    License: Apache License 2.0 5 votes vote down vote up
private void initAnim() {
    AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
    ScaleAnimation scaleAnim = new ScaleAnimation(1,2,1,2, Animation.RELATIVE_TO_SELF,0.5f,
            Animation.RELATIVE_TO_SELF,0.5f);
    mAnimationSet = new AnimationSet(true);
    mAnimationSet.addAnimation(alphaAnimation);
    mAnimationSet.addAnimation(scaleAnim);
    mAnimationSet.setDuration(DURATION);
}
 
Example 26
Source Project: RecordView   Source File: AnimationHelper.java    License: Apache License 2.0 5 votes vote down vote up
public void animateSmallMicAlpha() {
    alphaAnimation = new AlphaAnimation(0.0f, 1.0f);
    alphaAnimation.setDuration(500);
    alphaAnimation.setRepeatMode(Animation.REVERSE);
    alphaAnimation.setRepeatCount(Animation.INFINITE);
    smallBlinkingMic.startAnimation(alphaAnimation);
}
 
Example 27
Source Project: android-project-wo2b   Source File: BadgeView.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context, View target, int tabIndex)
{

	this.context = context;
	this.target = target;
	this.targetTabIndex = tabIndex;

	// apply defaults
	badgePosition = DEFAULT_POSITION;
	badgeMarginH = dipToPixels(DEFAULT_MARGIN_DIP);
	badgeMarginV = badgeMarginH;
	badgeColor = DEFAULT_BADGE_COLOR;

	setTypeface(Typeface.DEFAULT_BOLD);
	int paddingPixels = dipToPixels(DEFAULT_LR_PADDING_DIP);
	setPadding(paddingPixels, 0, paddingPixels, 0);
	setTextColor(DEFAULT_TEXT_COLOR);

	fadeIn = new AlphaAnimation(0, 1);
	fadeIn.setInterpolator(new DecelerateInterpolator());
	fadeIn.setDuration(200);

	fadeOut = new AlphaAnimation(1, 0);
	fadeOut.setInterpolator(new AccelerateInterpolator());
	fadeOut.setDuration(200);

	isShown = false;

	if (this.target != null)
	{
		applyTo(this.target);
	}
	else
	{
		show();
	}

}
 
Example 28
Source Project: BookReader   Source File: EasyLVHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public EasyLVHolder setAlpha(int viewId, float value) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getView(viewId).setAlpha(value);
    } else {
        AlphaAnimation alpha = new AlphaAnimation(value, value);
        alpha.setDuration(0);
        alpha.setFillAfter(true);
        getView(viewId).startAnimation(alpha);
    }
    return this;
}
 
Example 29
Source Project: WliveTV   Source File: FadeInBitmapDisplayer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Animates {@link ImageView} with "fade-in" effect
 *
 * @param imageView      {@link ImageView} which display image in
 * @param durationMillis The length of the animation in milliseconds
 */
public static void animate(View imageView, int durationMillis) {
	if (imageView != null) {
		AlphaAnimation fadeImage = new AlphaAnimation(0, 1);
		fadeImage.setDuration(durationMillis);
		fadeImage.setInterpolator(new DecelerateInterpolator());
		imageView.startAnimation(fadeImage);
	}
}
 
Example 30
private void setup(@NonNull View bubble) {
    float startAlpha = toVisible ? 0 : 1;
    float endAlpha = toVisible ? 1 : 0;

    AlphaAnimation alphaAnimation = new AlphaAnimation(startAlpha, endAlpha);
    alphaAnimation.setDuration(DURATION);
    addAnimation(alphaAnimation);

    setAnimationListener(new BubbleVisibilityAnimationListener(bubble, toVisible));

    //Works around the issue of the animation never starting because the view is GONE
    if (bubble.getVisibility() == View.GONE) {
        bubble.setVisibility(View.INVISIBLE);
    }
}