List of usage examples for android.animation Animator setDuration
public abstract Animator setDuration(long duration);
From source file:me.zchang.onchart.ui.MainActivity.java
private void popupThisWeek(int weekNum) { popupWeekText.setText(String.format(getString(R.string.weekday_week), weekNum)); popupWeekText.setVisibility(View.VISIBLE); popupWeekText.setScaleX(.3f);//from ww w .ja v a 2s . c om popupWeekText.setScaleY(.3f); popupWeekText.setAlpha(.7f); Animator scaleAnimator = ObjectAnimator.ofFloat(popupWeekText, "scaleX", 1f); Animator scaleAnimator2 = ObjectAnimator.ofFloat(popupWeekText, "scaleY", 1f); scaleAnimator.setDuration(150); scaleAnimator2.setDuration(150); Animator alphaAnimator = ObjectAnimator.ofFloat(popupWeekText, "alpha", 0f); alphaAnimator.setStartDelay(120); alphaAnimator.setDuration(500); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(scaleAnimator).with(scaleAnimator2).with(alphaAnimator); animatorSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { popupWeekText.setVisibility(View.GONE); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorSet.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 w w w. j av a2 s. c o m*/ } 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.hannesdorfmann.search.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/*w w w .ja v a2s .co 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(); }
From source file:com.androidinspain.deskclock.timer.TimerFragment.java
/** * @param timerToRemove the timer to be removed during the animation *///from ww w .j a v a2s. com private void animateTimerRemove(final Timer timerToRemove) { final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0); fadeOut.setDuration(duration); fadeOut.setInterpolator(new DecelerateInterpolator()); fadeOut.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.deskclock.R.string.label_deskclock); } }); final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1); fadeIn.setDuration(duration); fadeIn.setInterpolator(new AccelerateInterpolator()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(fadeOut).before(fadeIn); animatorSet.start(); }
From source file:babbq.com.searchplace.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 w w 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 (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(); }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void animateRemoveImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder);/* w w w .ja v a 2s . c om*/ // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; // get the initial radius for the clipping circle int initialRadius = view.getWidth(); // create the animation (the final radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0); anim.setDuration(getRemoveDuration()); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); view.setVisibility(View.VISIBLE); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // start the animation anim.start(); // animation.setDuration(getRemoveDuration()) // .alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchRemoveStarting(holder); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // ViewCompat.setAlpha(view, 1); // dispatchRemoveFinished(holder); // mRemoveAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
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 ww w .j a v a 2 s .co 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:arun.com.chromer.shared.views.TabView.java
private Animator getIconSelectionAnimator() { Animator animator = null; switch (mTabType) { case TAB_TYPE_OPTIONS: animator = ObjectAnimator.ofFloat(tabIcon, "rotation", 180); break;/*from w w w .j av a 2 s. c o m*/ case TAB_TYPE_WEB_HEADS: animator = ObjectAnimator.ofFloat(tabIcon, "rotation", 125); break; case TAB_TYPE_CUSTOMIZE: animator = ObjectAnimator.ofFloat(tabIcon, "scaleY", 1.2f); ((ObjectAnimator) animator).setRepeatMode(ValueAnimator.REVERSE); ((ObjectAnimator) animator).setRepeatCount(3); animator.setInterpolator(new LinearInterpolator()); break; } if (animator != null) animator.setDuration(250); return animator; }
From source file:com.gdgdevfest.android.apps.devfestbcn.ui.SessionDetailFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) { if (UIUtils.hasICS() && imageView.getTag() != null) { if (imageView.getTag() instanceof Animator) { Animator anim = (Animator) imageView.getTag(); anim.end();/*www . j a v a 2 s . c om*/ imageView.setAlpha(1f); } } animate = animate && UIUtils.hasICS(); if (animate) { int duration = getResources().getInteger(android.R.integer.config_shortAnimTime); Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f); outAnimator.setDuration(duration / 2); outAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageResource(imageResId); } }); AnimatorSet inAnimator = new AnimatorSet(); outAnimator.setDuration(duration); inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f), ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f)); AnimatorSet set = new AnimatorSet(); set.playSequentially(outAnimator, inAnimator); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setTag(null); } }); imageView.setTag(set); set.start(); } else { mHandler.post(new Runnable() { @Override public void run() { imageView.setImageResource(imageResId); } }); } }
From source file:com.hannesdorfmann.search.SearchActivity.java
@OnClick(R.id.fab) protected void save() { // show the save confirmation bubble fab.setVisibility(View.INVISIBLE); confirmSaveContainer.setVisibility(View.VISIBLE); resultsScrim.setVisibility(View.VISIBLE); // expand it once it's been measured and show a scrim over the search results confirmSaveContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override//ww w. j av a 2 s . co m public boolean onPreDraw() { // expand the confirmation confirmSaveContainer.getViewTreeObserver().removeOnPreDrawListener(this); Animator reveal = ViewAnimationUtils.createCircularReveal(confirmSaveContainer, confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2, fab.getWidth() / 2, confirmSaveContainer.getWidth() / 2); reveal.setDuration(250L); reveal.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in)); reveal.start(); // show the scrim int centerX = (fab.getLeft() + fab.getRight()) / 2; int centerY = (fab.getTop() + fab.getBottom()) / 2; Animator revealScrim = ViewAnimationUtils.createCircularReveal(resultsScrim, centerX, centerY, 0, (float) Math.hypot(centerX, centerY)); revealScrim.setDuration(400L); revealScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); revealScrim.start(); ObjectAnimator fadeInScrim = ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim)); fadeInScrim.setDuration(800L); fadeInScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); fadeInScrim.start(); // ease in the checkboxes saveDribbble.setAlpha(0.6f); saveDribbble.setTranslationY(saveDribbble.getHeight() * 0.4f); saveDribbble.animate().alpha(1f).translationY(0f).setDuration(200L).setInterpolator(AnimationUtils .loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); saveDesignerNews.setAlpha(0.6f); saveDesignerNews.setTranslationY(saveDesignerNews.getHeight() * 0.5f); saveDesignerNews.animate().alpha(1f).translationY(0f).setDuration(200L) .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in)); return false; } }); }