Java Code Examples for android.animation.ObjectAnimator#addListener()

The following examples show how to use android.animation.ObjectAnimator#addListener() . 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 Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void animHide(final View v, int duration, float from, float to, final boolean gone) {
    v.clearAnimation();
    if (from != to) {
        ObjectAnimator anim = ObjectAnimator
                .ofFloat(v, "alpha", from, to)
                .setDuration(duration);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                if (gone) {
                    v.setVisibility(View.GONE);
                }
            }
        });
        anim.start();
    }
}
 
Example 2
Source File: EnterScreenAnimations.java    From YCGallery with Apache License 2.0 6 votes vote down vote up
/**
 * This method creates an animator that changes ImageView position on the screen.
 * It will look like view is translated from its position on previous screen to its new position on this screen
 */
@NonNull
private ObjectAnimator createEnteringImagePositionAnimator() {
    PropertyValuesHolder propertyLeft = PropertyValuesHolder.ofInt("left", mAnimatedImage.getLeft(), mToLeft);
    PropertyValuesHolder propertyTop = PropertyValuesHolder.ofInt("top", mAnimatedImage.getTop(), mToTop - getStatusBarHeight());

    PropertyValuesHolder propertyRight = PropertyValuesHolder.ofInt("right", mAnimatedImage.getRight(), mToLeft + mToWidth);
    PropertyValuesHolder propertyBottom = PropertyValuesHolder.ofInt("bottom", mAnimatedImage.getBottom(), mToTop + mToHeight - getStatusBarHeight());

    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mAnimatedImage, propertyLeft, propertyTop, propertyRight, propertyBottom);
    animator.addListener(new SimpleAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // set new parameters of animated ImageView. This will prevent blinking of view when set visibility to visible in Exit animation
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mAnimatedImage.getLayoutParams();
            layoutParams.height = mImageTo.getHeight();
            layoutParams.width = mImageTo.getWidth();
            layoutParams.setMargins(mToLeft, mToTop - getStatusBarHeight(), 0, 0);
        }
    });
    return animator;
}
 
Example 3
Source File: MainActivity.java    From FileTransfer with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.fab)
public void onClick(View view) {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            == PackageManager.PERMISSION_GRANTED) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mFab, "translationY", 0, mFab
                .getHeight() * 2).setDuration(200L);
        objectAnimator.setInterpolator(new AccelerateInterpolator());
        objectAnimator.addListener(this);
        objectAnimator.start();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.permission_setting);
        builder.setMessage(R.string.permission_need_des);
        builder.setPositiveButton(R.string.permission_go, (dialog, which) -> {
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            Uri uri = Uri.fromParts("package", getPackageName(), null);
            intent.setData(uri);
            startActivity(intent);
        });
        builder.setNegativeButton(R.string.cancel, null);
        builder.show();
    }
}
 
Example 4
Source File: AnimUtils.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void translationYInitShow(final View v, int delay) {
    v.setVisibility(View.INVISIBLE);
    DisplayUtils utils = new DisplayUtils(v.getContext());
    ObjectAnimator anim = ObjectAnimator
            .ofFloat(v, "translationY", utils.dpToPx(72), 0)
            .setDuration(300);

    anim.setInterpolator(new DecelerateInterpolator());
    anim.setStartDelay(delay);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            v.setVisibility(View.VISIBLE);
        }
    });
    anim.start();
}
 
Example 5
Source File: CardStreamLinearLayout.java    From sensors-samples with Apache License 2.0 6 votes vote down vote up
private void handleViewSwipingIn(final View child, float deltaX, float deltaY) {
    ObjectAnimator animator = mAnimators.getSwipeInAnimator(child, deltaX, deltaY);
    if( animator != null ){
        animator.addListener(new EndAnimationWrapper() {
            @Override
            public void onAnimationEnd(Animator animation) {
                child.setTranslationY(0.f);
                child.setTranslationX(0.f);
            }
        });
    } else {
        child.setTranslationY(0.f);
        child.setTranslationX(0.f);
    }

    if( animator != null ){
        animator.setTarget(child);
        animator.start();
    }
}
 
Example 6
Source File: BossTransferView.java    From BlogDemo with Apache License 2.0 6 votes vote down vote up
/**
     * 淡出
     */
    private void fade() {
        mPb.setVisibility(GONE);
        ObjectAnimator animator = ObjectAnimator.ofFloat(mTemp, "alpha", 1f, 0f);
        animator.setDuration(800);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                mTemp.setVisibility(GONE);
//                mTemp.setScaleY(1f);
                mPb.setVisibility(GONE);
                mWm.removeView(BossTransferView.this);
            }
        });
        animator.start();
    }
 
Example 7
Source File: PreviewActivity.java    From ImageSelector with Apache License 2.0 6 votes vote down vote up
/**
 * 隐藏头部和尾部栏
 */
private void hideBar() {
    isShowBar = false;
    ObjectAnimator animator = ObjectAnimator.ofFloat(rlTopBar, "translationY",
            0, -rlTopBar.getHeight()).setDuration(300);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (rlTopBar != null) {
                rlTopBar.setVisibility(View.GONE);
                //添加延时,保证rlTopBar完全隐藏后再隐藏StatusBar。
                rlTopBar.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        setStatusBarVisible(false);
                    }
                }, 5);
            }
        }
    });
    animator.start();
    ofFloat(rlBottomBar, "translationY", 0, rlBottomBar.getHeight())
            .setDuration(300).start();
}
 
Example 8
Source File: RevealView.java    From PracticeDemo with Apache License 2.0 6 votes vote down vote up
public void startReveal() {
    setVisibility(VISIBLE);
    //计算对角线 sqrt 开平方,pow 计算x的n次方
    int maxRadius = (int) (Math.sqrt(Math.pow(getHeight(), 2)+ Math.pow(getWidth(), 2)));
    ObjectAnimator revealAnimator = ObjectAnimator.ofInt(this, "radius", 0,maxRadius).setDuration(300);
    revealAnimator.setInterpolator(new AccelerateInterpolator());
    revealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (null != callback) {
                callback.onRevealEnd();
            }
        }
    });
    revealAnimator.start();
}
 
Example 9
Source File: BlogReaderAnim.java    From Cotable with Apache License 2.0 5 votes vote down vote up
private static ObjectAnimator getFadeOutAnim(final View target, Duration duration) {
    ObjectAnimator fadeOut = ObjectAnimator.ofFloat(target, View.ALPHA, 1.0f, 0.0f);
    fadeOut.setDuration(duration.toMillis(target.getContext()));
    fadeOut.setInterpolator(new LinearInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            target.setVisibility(View.GONE);
        }
    });
    return fadeOut;
}
 
Example 10
Source File: AnimationsUtils.java    From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void showView(final View view, long duration) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f);
    animator.setDuration(duration);
    animator.setInterpolator(new LinearInterpolator());
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            view.setVisibility(View.VISIBLE);
        }
    });

    animator.start();
}
 
Example 11
Source File: NoteMainActivity.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void showBottomBar() {
    mRlBottomBar.setVisibility(View.VISIBLE);
    //        bottombar进行一个上移的动画
    ObjectAnimator animator = ObjectAnimator.ofFloat(mRlBottomBar, "translationY", SizeUtils.dp2px(56), 0);
    animator.setDuration(300);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
        }
    });
    animator.start();
}
 
Example 12
Source File: CardNumHolder.java    From PaymentKit-Droid with Apache License 2.0 5 votes vote down vote up
public void indicateInvalidCardNum() {
	getCardField().setTextColor(Color.RED);
	mTopItem = mCardNumberEditText;
	ObjectAnimator shakeAnim = ObjectAnimator.ofFloat(getCardField(), "translationX", -16);
	shakeAnim.setDuration(SHAKE_DURATION);
	shakeAnim.setInterpolator(new CycleInterpolator(2.0f));
	shakeAnim.addListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator anim) {
			mTopItem = null;
		}
	});
	shakeAnim.start();
}
 
Example 13
Source File: Launcher.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
private void shrinkAndFadeInFolderIcon(final FolderIcon fi) {
	if (fi == null)
		return;
	PropertyValuesHolder alpha = PropertyValuesHolder
			.ofFloat("alpha", 1.0f);
	PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX",
			1.0f);
	PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY",
			1.0f);

	final CellLayout cl = (CellLayout) fi.getParent().getParent();

	// We remove and re-draw the FolderIcon in-case it has changed
	mDragLayer.removeView(mFolderIconImageView);
	copyFolderIconToImage(fi);
	ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(
			mFolderIconImageView, alpha, scaleX, scaleY);
	oa.setDuration(getResources().getInteger(
			R.integer.config_folderAnimDuration));
	oa.addListener(new AnimatorListenerAdapter() {
		@Override
		public void onAnimationEnd(Animator animation) {
			if (cl != null) {
				cl.clearFolderLeaveBehind();
				// Remove the ImageView copy of the FolderIcon and make the
				// original visible.
				mDragLayer.removeView(mFolderIconImageView);
				fi.setVisibility(View.VISIBLE);
			}
		}
	});
	oa.start();
}
 
Example 14
Source File: NoteMainActivity.java    From SuperNote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void hideBottomBar() {
    // 下移动画
    ObjectAnimator animator = ObjectAnimator.ofFloat(mRlBottomBar, "translationY", SizeUtils.dp2px(56));
    animator.setDuration(300);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mRlBottomBar.setVisibility(View.GONE);
        }
    });
    animator.start();
}
 
Example 15
Source File: SwipeRefreshRecyclerView.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
private Animator createDefaultLoadingAnimator() {
    ObjectAnimator animator = ObjectAnimator.ofFloat(loadMoreView, TRANSLATION_Y, loadMoreView.getTranslationY(), 0);
    animator.setDuration(300);
    animator.addListener(new SimpleAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (onRefreshListener != null) {
                currentPageNumber++;
                onRefreshListener.onLoadMore(currentPageNumber, pageSize);
            }
        }
    });
    return animator;
}
 
Example 16
Source File: SwipeRefreshRecyclerView.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
private Animator createDefaultLoadedAnimator() {
    ObjectAnimator animator = ObjectAnimator.ofFloat(loadMoreView, TRANSLATION_Y, loadMoreView.getTranslationY(), translationDistance);
    animator.setDuration(300);
    animator.addListener(new SimpleAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            setLoading(false);
            swipeRefreshLayout.setEnabled(true
            );
        }
    });
    return animator;
}
 
Example 17
Source File: Ripple.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
private void exitSoftware(int radiusDuration, int opacityDuration) {
    final ObjectAnimator radiusAnim = ObjectAnimator.ofFloat(this, "radiusGravity", 1);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        radiusAnim.setAutoCancel(true);
    radiusAnim.setDuration(radiusDuration);
    radiusAnim.setInterpolator(DECEL_INTERPOLATOR);

    final ObjectAnimator xAnim = ObjectAnimator.ofFloat(this, "xGravity", 1);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) xAnim.setAutoCancel(true);
    xAnim.setDuration(radiusDuration);
    xAnim.setInterpolator(DECEL_INTERPOLATOR);

    final ObjectAnimator yAnim = ObjectAnimator.ofFloat(this, "yGravity", 1);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) yAnim.setAutoCancel(true);
    yAnim.setDuration(radiusDuration);
    yAnim.setInterpolator(DECEL_INTERPOLATOR);

    final ObjectAnimator opacityAnim = ObjectAnimator.ofFloat(this, "opacity", 0);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)
        opacityAnim.setAutoCancel(true);
    opacityAnim.setDuration(opacityDuration);
    opacityAnim.setInterpolator(LINEAR_INTERPOLATOR);
    opacityAnim.addListener(mAnimationListener);

    mAnimRadius = radiusAnim;
    mAnimOpacity = opacityAnim;
    mAnimX = xAnim;
    mAnimY = yAnim;

    radiusAnim.start();
    opacityAnim.start();
    xAnim.start();
    yAnim.start();
}
 
Example 18
Source File: LauncherExtension.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public void onScrollInteractionEnd() {
    if (mProgress > 25 && mLauncherOverlayCallbacks.enterFullImmersion()) {
        ObjectAnimator oa = LauncherAnimUtils.ofFloat(mSearchOverlay, "translationX", 0);
        oa.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                mSearchOverlay.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        });
        oa.start();
        mOverlayPanelShowing = true;
        mShowOverlayFeedback = false;
    }
}
 
Example 19
Source File: LauncherExtension.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onScrollInteractionEnd() {
    if (mProgress > 25 && mLauncherOverlayCallbacks.enterFullImmersion()) {
        ObjectAnimator oa = LauncherAnimUtils.ofFloat(mSearchOverlay, "translationX", 0);
        oa.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                mSearchOverlay.setLayerType(View.LAYER_TYPE_NONE, null);
            }
        });
        oa.start();
        mOverlayPanelShowing = true;
        mShowOverlayFeedback = false;
    }
}
 
Example 20
Source File: BottomSheetHelper.java    From SingleDateAndTimePicker with Apache License 2.0 5 votes vote down vote up
private void animateBottomSheet() {
  final ObjectAnimator objectAnimator =
      ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, view.getHeight(), 0);
  objectAnimator.addListener(new AnimatorListenerAdapter() {

    @Override
    public void onAnimationEnd(Animator animation) {
      if (listener != null) {
        listener.onOpen();
      }
    }
  });
  objectAnimator.start();
}