Java Code Examples for android.view.animation.AlphaAnimation#setAnimationListener()

The following examples show how to use android.view.animation.AlphaAnimation#setAnimationListener() . 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: AnimUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
/**
 * <p>对 View 做透明度变化的进场动画。</p>
 * <p>相关方法 {@link #fadeOut(View, int, Animation.AnimationListener, boolean)}</p>
 *
 * @param view            做动画的 View
 * @param duration        动画时长(毫秒)
 * @param listener        动画回调
 * @param isNeedAnimation 是否需要动画
 */
public static AlphaAnimation fadeIn(View view, int duration, Animation.AnimationListener listener, boolean isNeedAnimation) {
    if (view == null) {
        return null;
    }
    if (isNeedAnimation) {
        view.setVisibility(View.VISIBLE);
        AlphaAnimation alpha = new AlphaAnimation(0, 1);
        alpha.setInterpolator(new DecelerateInterpolator());
        alpha.setDuration(duration);
        alpha.setFillAfter(true);
        if (listener != null) {
            alpha.setAnimationListener(listener);
        }
        view.startAnimation(alpha);
        return alpha;
    } else {
        view.setAlpha(1);
        view.setVisibility(View.VISIBLE);
        return null;
    }
}
 
Example 2
Source File: ViewHelper.java    From Common with Apache License 2.0 6 votes vote down vote up
/**
 * <p>对 View 做透明度变化的进场动画。</p>
 * <p>相关方法 {@link #fadeOut(View, int, Animation.AnimationListener, boolean)}</p>
 *
 * @param view            做动画的 View
 * @param duration        动画时长(毫秒)
 * @param listener        动画回调
 * @param isNeedAnimation 是否需要动画
 */
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
public static AlphaAnimation fadeIn(View view, int duration, Animation.AnimationListener listener, boolean isNeedAnimation) {
    if (view == null) {
        return null;
    }
    if (isNeedAnimation) {
        view.setVisibility(View.VISIBLE);
        AlphaAnimation alpha = new AlphaAnimation(0, 1);
        alpha.setInterpolator(new DecelerateInterpolator());
        alpha.setDuration(duration);
        alpha.setFillAfter(true);
        if (listener != null) {
            alpha.setAnimationListener(listener);
        }
        view.startAnimation(alpha);
        return alpha;
    } else {
        view.setAlpha(1);
        view.setVisibility(View.VISIBLE);
        return null;
    }
}
 
Example 3
Source File: ViewHelper.java    From DMusic with Apache License 2.0 6 votes vote down vote up
/**
 * <p>对 View 做透明度变化的进场动画。</p>
 * <p>相关方法 {@link #fadeOut(View, int, Animation.AnimationListener, boolean)}</p>
 *
 * @param view            做动画的 View
 * @param duration        动画时长(毫秒)
 * @param listener        动画回调
 * @param isNeedAnimation 是否需要动画
 */
public static AlphaAnimation fadeIn(View view, int duration, Animation.AnimationListener listener, boolean isNeedAnimation) {
    if (view == null) {
        return null;
    }
    if (isNeedAnimation) {
        view.setVisibility(View.VISIBLE);
        AlphaAnimation alpha = new AlphaAnimation(0, 1);
        alpha.setInterpolator(new DecelerateInterpolator());
        alpha.setDuration(duration);
        alpha.setFillAfter(true);
        if (listener != null) {
            alpha.setAnimationListener(listener);
        }
        view.startAnimation(alpha);
        return alpha;
    } else {
        view.setAlpha(1);
        view.setVisibility(View.VISIBLE);
        return null;
    }
}
 
Example 4
Source File: BootstrapAlert.java    From Android-Bootstrap with MIT License 5 votes vote down vote up
private void setupAnimations() {
    fadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
    fadeInAnimation.setDuration(300);
    fadeInAnimation.setInterpolator(new AccelerateInterpolator());
    fadeInAnimation.setAnimationListener(this);

    fadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
    fadeOutAnimation.setDuration(300);
    fadeOutAnimation.setInterpolator(new AccelerateInterpolator());
    fadeOutAnimation.setAnimationListener(this);
}
 
Example 5
Source File: DotWidget.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
private void buildDefaultAnima() {
    fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setInterpolator(new DecelerateInterpolator());
    fadeIn.setDuration(450);
    fadeIn.setAnimationListener(animaListener);

    fadeOut = new AlphaAnimation(1, 0);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.setDuration(450);
    fadeOut.setAnimationListener(animaListener);
}
 
Example 6
Source File: ConnectActivity.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
private void initializeUi() {
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    // Get the Layoutelements
    mBtnConnect = (Button) findViewById(R.id.btnConnect);
    mBtnConnect.setOnClickListener(oclConnect);
    mBtnConnect.requestFocus();

    mBtnClementine = (ImageButton) findViewById(R.id.btnClementineIcon);
    mBtnClementine.setOnClickListener(oclClementine);

    // Setup the animation for the Clementine icon
    mAlphaDown = new AlphaAnimation(1.0f, 0.3f);
    mAlphaUp = new AlphaAnimation(0.3f, 1.0f);
    mAlphaDown.setDuration(ANIMATION_DURATION);
    mAlphaUp.setDuration(ANIMATION_DURATION);
    mAlphaDown.setFillAfter(true);
    mAlphaUp.setFillAfter(true);
    mAlphaUp.setAnimationListener(mAnimationListener);
    mAlphaDown.setAnimationListener(mAnimationListener);
    mAnimationCancel = false;

    // Ip and Autoconnect
    mEtIp = (AutoCompleteTextView) findViewById(R.id.etIp);
    mEtIp.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    mEtIp.setThreshold(3);

    // Get old ip and auto-connect from shared prefences
    mEtIp.setText(mSharedPref.getString(SharedPreferencesKeys.SP_KEY_IP, ""));
    mEtIp.setSelection(mEtIp.length());

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, mKnownIps.toArray(new String[0]));
    mEtIp.setAdapter(adapter);

    // Get the last auth code
    mAuthCode = mSharedPref.getInt(SharedPreferencesKeys.SP_LAST_AUTH_CODE, 0);
}
 
Example 7
Source File: AnimateImageView.java    From barterli_android with 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 8
Source File: TileManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
void renderIndividualTile( Tile tile ) {
	// if it's already rendered, quit now
	if ( alreadyRendered.contains( tile ) ) {
		return;
	}
	// create the image view if needed, with default settings
	tile.render( getContext() );
	// add it to the list of those rendered
	alreadyRendered.add( tile );
	// get reference to the actual image view
	ImageView imageView = tile.getImageView();
	// get layout params from the tile's predefined dimensions
	LayoutParams layoutParams = getLayoutFromTile( tile );
	// add it to the appropriate set (which is already scaled)
	currentTileGroup.addView( imageView, layoutParams );
	// shouldn't be necessary, but is
	postInvalidate();
	// do we want to animate in tiles?
	if( transitionsEnabled){
		// do we have an appropriate duration?
		if( transitionDuration > 0 ) {
			// create the animation (will be cleared by tile.destroy).  do this here for the postInvalidate listener
			AlphaAnimation fadeIn = new AlphaAnimation( 0f, 1f );
			// set duration
			fadeIn.setDuration( transitionDuration );
			// this listener posts invalidate on complete, again should not be necessary but is
			fadeIn.setAnimationListener( transitionListener );
			// start it up
			imageView.startAnimation( fadeIn );
		}
	}
}
 
Example 9
Source File: WelcomeActivity.java    From qingyang with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	final View view = View.inflate(this, R.layout.welcome_actvivity, null);
	setContentView(view);

	FrameLayout frameLayout = (FrameLayout) findViewById(R.id.welcome_frame);

	BaseApplication application = (BaseApplication) getApplication();

	if (application.isTablet()) {
		frameLayout
				.setBackgroundResource(R.drawable.wecome_tablet_background);
	} else {
		frameLayout.setBackgroundResource(R.drawable.wecome_background);
	}

	// 渐变启动 从x透明度到x透明度渐变启动
	AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
	// 持续时间
	alphaAnimation.setDuration(2000);

	alphaAnimation.setAnimationListener(new MyAnimationListener());

	view.setAnimation(alphaAnimation);

}
 
Example 10
Source File: FadeAnimator.java    From px-android with MIT License 5 votes vote down vote up
public void fadeOutFast(@NonNull final View viewToAnimate) {
    if (shouldGoneAnim(viewToAnimate)) {
        viewToAnimate.setVisibility(View.VISIBLE);
        final AlphaAnimation fade = createFade(1, 0);
        fade.setAnimationListener(new FadeAnimationListener(viewToAnimate, View.INVISIBLE));
        fade.setDuration(fastDuration);
        viewToAnimate.startAnimation(fade);
    } else {
        cancelAnimation(viewToAnimate);
        viewToAnimate.clearAnimation();
        viewToAnimate.setVisibility(View.INVISIBLE);
    }
}
 
Example 11
Source File: FadeAnimator.java    From px-android with MIT License 5 votes vote down vote up
public void fadeOut(@NonNull final View viewToAnimate) {
    if (shouldGoneAnim(viewToAnimate)) {
        viewToAnimate.clearAnimation();
        viewToAnimate.setVisibility(View.VISIBLE);
        final AlphaAnimation fade = createFade(1, 0);
        fade.setAnimationListener(new FadeAnimationListener(viewToAnimate, View.INVISIBLE));
        fade.setDuration(normalDuration);
        viewToAnimate.startAnimation(fade);
    } else {
        cancelAnimation(viewToAnimate);
        viewToAnimate.clearAnimation();
        viewToAnimate.setVisibility(View.INVISIBLE);
    }
}
 
Example 12
Source File: DSListView.java    From direct-select-android with MIT License 5 votes vote down vote up
private void showListView() {
    if (animationInProgress || scrollInProgress || listViewIsShown) return;
    listView.setEnabled(true);
    animationInProgress = true;

    this.setVisibility(View.VISIBLE);
    this.bringToFront();
    this.readyToHide = false;

    // Scale picker box if animations enabled
    if (selectorAnimationsEnabled && null != this.pickerBox) {
        ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1f + scaleFactorDelta, 1f, 1f + scaleFactorDelta,
                Animation.RELATIVE_TO_SELF, selectorAnimationCenterPivot ? 0.5f : 0f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setInterpolator(new AccelerateInterpolator());
        scaleAnimation.setDuration(100);
        scaleAnimation.setFillAfter(true);
        this.pickerBox.getCellRoot().startAnimation(scaleAnimation);
    }

    // Show picker view animation
    AlphaAnimation showAnimation = new AlphaAnimation(0f, 1f);
    showAnimation.setDuration(200);
    showAnimation.setInterpolator(new AccelerateInterpolator());
    showAnimation.setAnimationListener(new AnimationListenerAdapter() {
        @Override
        public void onAnimationEnd(Animation animation) {
            animationInProgress = false;
            listViewIsShown = true;
            hideListView();
        }
    });

    this.startAnimation(showAnimation);
}
 
Example 13
Source File: DSListView.java    From direct-select-android with MIT License 5 votes vote down vote up
private void hideListView() {
    if (!readyToHide || animationInProgress || scrollInProgress || !listViewIsShown || adapter == null) return;

    readyToHide = false;
    animationInProgress = true;
    listView.setEnabled(false);

    this.setVisibility(View.INVISIBLE);

    this.pickerBox.onSelect(adapter.getItem(selectedItem), selectedItem);

    AlphaAnimation hideAnimation = new AlphaAnimation(1f, 0f);
    hideAnimation.setStartOffset(subScrollDuration);
    hideAnimation.setDuration(200);
    hideAnimation.setInterpolator(new DecelerateInterpolator());
    hideAnimation.setAnimationListener(new AnimationListenerAdapter() {
        @Override
        public void onAnimationEnd(Animation animation) {
            listViewIsShown = false;
            animationInProgress = false;
        }
    });
    DSListView.this.startAnimation(hideAnimation);

    // Scale picker box text animation if animations enabled
    if (selectorAnimationsEnabled && null != this.pickerBox) {
        ScaleAnimation scaleAnimation = new ScaleAnimation(1f + scaleFactorDelta, 1f, 1f + scaleFactorDelta, 1f,
                Animation.RELATIVE_TO_SELF, selectorAnimationCenterPivot ? 0.5f : 0f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setInterpolator(new DecelerateInterpolator());
        scaleAnimation.setStartOffset(100 + subScrollDuration);
        scaleAnimation.setDuration(100);
        scaleAnimation.setFillAfter(true);
        this.pickerBox.getCellRoot().startAnimation(scaleAnimation);
    }
}
 
Example 14
Source File: AnimationUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取一个透明度渐变动画
 * @param fromAlpha         开始时的透明度
 * @param toAlpha           结束时的透明度
 * @param durationMillis    动画持续时间
 * @param animationListener 动画监听器
 * @return 一个透明度渐变动画
 */
public static AlphaAnimation getAlphaAnimation(final float fromAlpha, final float toAlpha, final long durationMillis,
                                               final AnimationListener animationListener) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
    alphaAnimation.setDuration(durationMillis);
    if (animationListener != null) {
        alphaAnimation.setAnimationListener(animationListener);
    }
    return alphaAnimation;
}
 
Example 15
Source File: PlayerPageFragment.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_player_control,
            container, false);

    // Get the Views
    mTvArtist = (TextView) view.findViewById(R.id.tvArtist);
    mTvTitle = (TextView) view.findViewById(R.id.tvTitle);
    mTvAlbum = (TextView) view.findViewById(R.id.tvAlbum);

    mTvGenre = (TextView) view.findViewById(R.id.tvGenre);
    mTvYear = (TextView) view.findViewById(R.id.tvYear);
    mTvLength = (TextView) view.findViewById(R.id.tvLength);

    mSbPosition = (SeekBar) view.findViewById(R.id.sbPosition);

    mImgArt = (ImageView) view.findViewById(R.id.imgArt);

    mImgArt.setOnClickListener(oclControl);

    mSbPosition.setOnSeekBarChangeListener(onSeekBarChanged);

    // Animation for track change
    mAlphaDown = new AlphaAnimation(1.0f, 0.0f);
    mAlphaUp = new AlphaAnimation(0.0f, 1.0f);
    mAlphaDown.setDuration(ANIMATION_DURATION);
    mAlphaUp.setDuration(ANIMATION_DURATION);
    mAlphaDown.setFillAfter(true);
    mAlphaUp.setFillAfter(true);
    mAlphaUp.setAnimationListener(mAnimationListener);
    mAlphaDown.setAnimationListener(mAnimationListener);
    mAlphaDown.setInterpolator(new AccelerateInterpolator());
    mAlphaUp.setInterpolator(new AccelerateInterpolator());

    // Initialize interface
    updateTrackMetadata();
    updateTrackPosition();

    return view;
}
 
Example 16
Source File: AnimationUtils.java    From SprintNBA with Apache License 2.0 3 votes vote down vote up
/**
 * 获取一个透明度渐变动画
 *
 * @param fromAlpha         开始时的透明度
 * @param toAlpha           结束时的透明度都
 * @param durationMillis    持续时间
 * @param animationListener 动画监听器
 * @return 一个透明度渐变动画
 */
public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis, Animation.AnimationListener animationListener) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
    alphaAnimation.setDuration(durationMillis);
    if (animationListener != null) {
        alphaAnimation.setAnimationListener(animationListener);
    }
    return alphaAnimation;
}
 
Example 17
Source File: AnimationUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 获取一个透明度渐变动画
 *
 * @param fromAlpha         开始时的透明度
 * @param toAlpha           结束时的透明度都
 * @param durationMillis    持续时间
 * @param animationListener 动画监听器
 * @return 一个透明度渐变动画
 */
public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis, AnimationListener animationListener) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
    alphaAnimation.setDuration(durationMillis);
    if (animationListener != null) {
        alphaAnimation.setAnimationListener(animationListener);
    }
    return alphaAnimation;
}
 
Example 18
Source File: CustomAnim.java    From Utils with Apache License 2.0 3 votes vote down vote up
/**
 * get an alpha animation.
 *
 * @param fromAlpha      Starting alpha value for the animation, where 1.0 means
 *                       fully opaque and 0.0 means fully transparent.
 * @param toAlpha        Ending alpha value for the animation.
 * @param durationMillis Duration in milliseconds
 * @param listener       the animation listener to be notified
 * @return An animation that controls the alpha level of an object.
 */
public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis,
                                               Animation.AnimationListener listener) {
    AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
    alphaAnimation.setDuration(durationMillis);
    if (listener != null) {
        alphaAnimation.setAnimationListener(listener);
    }
    return alphaAnimation;
}