List of usage examples for android.animation Animator addListener
public void addListener(AnimatorListener listener)
From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java
@Override public void endSearchMode(boolean animate) { Utils.hideKeyboard(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (animate) { // If the device has rotated, we need to calculate a new center for the animation. if (searchButtonCenter == null) { final View actionMenuView = searchToolbar.getChildAt(2); final ViewGroup actionMenuViewGroup = (ViewGroup) actionMenuView; final View button = actionMenuViewGroup.getChildAt(0); System.out.println(button.getClass()); searchButtonCenter = new Point( (int) (button.getX() + actionMenuView.getX() - button.getWidth() / 2), (int) (button.getY() + actionMenuView.getY() + button.getHeight() / 2)); }/*from ww w . ja v a 2 s. com*/ final Animator animator = ViewAnimationUtils.createCircularReveal(searchToolbar, searchButtonCenter.x, searchButtonCenter.y, searchToolbar.getWidth(), 0); animator.setDuration(revealStatusBarDuration); animator.addListener(new EndSearchModeAnimationListener(searchToolbar)); toolbar.setVisibility(View.VISIBLE); animator.start(); } else { searchToolbar.setVisibility(View.INVISIBLE); } setSupportActionBar(toolbar); } else { toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.primary)); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setCustomView(R.layout.toolbar_search); actionBar.setDisplayShowCustomEnabled(false); actionBar.setDisplayShowTitleEnabled(true); } } viewPager.setVisibility(View.VISIBLE); if (animate) { searchResults.animate().alpha(0).setDuration(crossfadeViewPagerSearchDuration) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { searchResults.setVisibility(View.GONE); } }); viewPager.animate().alpha(1).setDuration(crossfadeViewPagerSearchDuration).setListener(null); } else { viewPager.setAlpha(1); searchResults.setAlpha(0); searchResults.setVisibility(View.GONE); } searchInputSub.unsubscribe(); searchInputLengthSub.unsubscribe(); invalidateOptionsMenu(); }
From source file:com.android.deskclock.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *///from www. j a v a 2s. com private void animateTimerRemove(final Timer timerToRemove) { final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0); fadeOut.setDuration(mShortAnimationDuration); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(R.string.action_delete, R.string.label_deskclock); } }); final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1); fadeIn.setDuration(mShortAnimationDuration); fadeIn.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(fadeOut).before(fadeIn); animatorSet.start(); }
From source file:com.stasbar.knowyourself.timer.TimerFragment.java
/** * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView} * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer * should be removed *//*from w ww . j ava 2 s.c o m*/ private void animateToView(View toView, final Timer timerToRemove) { if (mCurrentView == toView) { return; } final boolean toTimers = toView == mTimersView; final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0); rotateFrom.setDuration(duration); rotateFrom.setInterpolator(new DecelerateInterpolator()); rotateFrom.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); ((MainActivity) getActivity()).stopActivity(activityItem, timerToRemove); } mCurrentView.setScaleX(1); if (toTimers) { showTimersView(); } else { showCreateTimerView(); } } }); final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1); rotateTo.setDuration(duration); rotateTo.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(rotateFrom).before(rotateTo); animatorSet.start(); }
From source file:com.solera.defrag.ViewStack.java
void runAnimation(@NonNull final View from, @NonNull final View to, @TraversingOperation int operation) { final TraversalAnimation traversalAnimation = createAnimation(from, to, operation); if (traversalAnimation == null) { removeView(from);/*from w ww .ja v a 2 s. com*/ setTraversingState(TraversingState.IDLE); } else { final Animator animator = traversalAnimation.animator(); setChildrenDrawingOrderEnabled(traversalAnimation.drawOrder() == TraversalAnimation.BELOW); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { removeView(from); setTraversingState(TraversingState.IDLE); setChildrenDrawingOrderEnabled(false); } }); animator.start(); } }
From source file:de.janniskilian.xkcdreader.presentation.components.showcomics.ShowComicsActivity.java
@Override public void startSearchMode(boolean animate) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (animate) { final View actionMenuView = toolbar.getChildAt(1); final ViewGroup actionMenuViewGroup = (ViewGroup) actionMenuView; final View addButton = actionMenuViewGroup.getChildAt(0); searchButtonCenter = new Point( (int) (addButton.getX() + actionMenuView.getX() + addButton.getWidth() / 2), (int) (addButton.getY() + actionMenuView.getY() + addButton.getHeight() / 2)); final Animator animator = ViewAnimationUtils.createCircularReveal(searchToolbar, searchButtonCenter.x, searchButtonCenter.y, 0, searchToolbar.getWidth()); animator.setDuration(revealStatusBarDuration); animator.addListener(new StartSearchModeAnimationListener(toolbar)); searchToolbar.setVisibility(View.VISIBLE); animator.start();/*from ww w .j av a 2s .c om*/ } else { searchToolbar.setVisibility(View.VISIBLE); } setSupportActionBar(searchToolbar); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeAsUpIndicator(tintedBackArrow); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(R.layout.toolbar_search); } } else { toolbar.setBackgroundColor(ContextCompat.getColor(this, R.color.background)); final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeAsUpIndicator(tintedBackArrow); actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(R.layout.toolbar_search); } invalidateOptionsMenu(); } searchInput = (EditText) findViewById(R.id.search_input); searchInput.requestFocus(); searchInputSub = RxTextView.textChangeEvents(searchInput) .debounce(searchInputDebounceDuration, TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()).subscribe(textViewTextChangeEvent -> { presenter.onSearchInputChanged(textViewTextChangeEvent.text().toString()); }); searchInputLengthSub = RxTextView.textChangeEvents(searchInput).observeOn(AndroidSchedulers.mainThread()) .subscribe(textViewTextChangeEvent -> { presenter.onSearchInputLengthChanged(textViewTextChangeEvent.text().toString(), textViewTextChangeEvent.count()); }); searchInput.setOnEditorActionListener((textView, actionId, keyEvent) -> { if (actionId == EditorInfo.IME_ACTION_SEARCH) { Utils.hideKeyboard(ShowComicsActivity.this); return true; } return false; }); Utils.showKeyboard(this); searchResults.setVisibility(View.VISIBLE); if (animate) { searchResults.animate().alpha(1).setDuration(crossfadeViewPagerSearchDuration).setListener(null); viewPager.animate().alpha(0).setDuration(crossfadeViewPagerSearchDuration) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { viewPager.setVisibility(View.GONE); } }); } else { searchResults.setAlpha(1); viewPager.setAlpha(0); viewPager.setVisibility(View.GONE); } }
From source file:com.android.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);//from ww w.j a va 2s. co m containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.announceForAccessibility(accessibilityText); mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
void animateAddImpl(final RecyclerView.ViewHolder holder) { Logger.e(TAG, "<<<animateAddImpl>>" + holder); final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mAddAnimations.add(holder);//from www. jav a 2 s . c o m // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; Logger.e(TAG, "cx=" + cx + ",cy=" + cy); // get the final radius for the clipping circle int finalRadius = Math.max(view.getWidth(), view.getHeight()); Logger.e(TAG, "width=" + view.getWidth() + ",height=" + view.getHeight() + ",finalRadius=" + finalRadius); // create the animator for this view (the start radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); anim.setDuration(getAddDuration()); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); dispatchAddFinished(holder); mAddAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // make the view visible and start the animation view.setVisibility(View.VISIBLE); anim.start(); // animation.alpha(1).setDuration(getAddDuration()). // setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchAddStarting(holder); // } // @Override // public void onAnimationCancel(View view) { // ViewCompat.setAlpha(view, 1); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // dispatchAddFinished(holder); // mAddAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:io.plaidapp.ui.SearchActivity.java
@OnClick({ R.id.scrim, R.id.searchback }) protected void dismiss() { // translate the icon to match position in the launching activity searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in)) .setListener(new AnimatorListenerAdapter() { @Override/* ww w .j av a 2s . c o m*/ public void onAnimationEnd(Animator animation) { finishAfterTransition(); } }).start(); // transform from back icon to search icon AnimatedVectorDrawable backToSearch = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_back_to_search); searchBack.setImageDrawable(backToSearch); // clear the background else the touch ripple moves with the translation which looks bad searchBack.setBackground(null); backToSearch.start(); // fade out the other search chrome searchView.animate().alpha(0f).setStartDelay(0L).setDuration(120L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); // if we're showing search results, circular hide them if (resultsContainer.getHeight() > 0) { Animator closeResults = ViewAnimationUtils.createCircularReveal(resultsContainer, searchIconCenterX, 0, (float) Math.hypot(searchIconCenterX, resultsContainer.getHeight()), 0f); closeResults.setDuration(500L); closeResults.setInterpolator( AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); closeResults.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { resultsContainer.setVisibility(View.INVISIBLE); } }); closeResults.start(); } // fade out the scrim scrim.animate().alpha(0f).setDuration(400L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); }
From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);/*from w ww .j a va 2 s.c o m*/ containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { if (Build.VERSION.SDK_INT >= 16) { mAlertView.announceForAccessibility(accessibilityText); } mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:io.plaidapp.ui.SearchActivity.java
@OnClick({ R.id.scrim, R.id.searchback }) protected void dismiss() { // translate the icon to match position in the launching activity searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in)) .setListener(new AnimatorListenerAdapter() { @Override//from ww w . j a v a2 s. c o m public void onAnimationEnd(Animator animation) { finishAfterTransition(); } }).start(); // transform from back icon to search icon AnimatedVectorDrawable backToSearch = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_back_to_search); searchBack.setImageDrawable(backToSearch); // clear the background else the touch ripple moves with the translation which looks bad searchBack.setBackground(null); backToSearch.start(); // fade out the other search chrome searchView.animate().alpha(0f).setStartDelay(0L).setDuration(120L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); if (searchToolbar.getZ() != 0f) { searchToolbar.animate().z(0f).setDuration(600L) .setInterpolator( AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .start(); } // if we're showing search results, circular hide them if (resultsContainer.getHeight() > 0) { Animator closeResults = ViewAnimationUtils.createCircularReveal(resultsContainer, searchIconCenterX, 0, (float) Math.hypot(searchIconCenterX, resultsContainer.getHeight()), 0f); closeResults.setDuration(500L); closeResults.setInterpolator( AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); closeResults.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { resultsContainer.setVisibility(View.INVISIBLE); } }); closeResults.start(); } // fade out the scrim scrim.animate().alpha(0f).setDuration(400L) .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in)) .setListener(null).start(); }