List of usage examples for android.animation ObjectAnimator addListener
public void addListener(AnimatorListener listener)
From source file:com.hannesdorfmann.FeedAdapter.java
private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) { final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView; Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() { @Override/*from ww w. jav a 2 s. c o m*/ public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (!shot.hasFadedIn) { iv.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( if (iv.getDrawable() != null) { iv.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm)); } } }); saturation.setDuration(2000); saturation.setInterpolator( AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { iv.setHasTransientState(false); } }); saturation.start(); shot.hasFadedIn = true; } return false; } @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.ALL).into(new DribbbleTarget(iv, false)); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { iv.setTransitionName(iv.getResources().getString(R.string.transition_shot)); iv.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light)); Intent intent = new Intent(); intent.setClass(host, DribbbleShot.class); intent.putExtra(DribbbleShot.EXTRA_SHOT, shot); ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(view, host.getString(R.string.transition_shot)), Pair.create(view, host.getString(R.string.transition_shot_background))); host.startActivity(intent, options.toBundle()); } }); }
From source file:com.android.launcher3.folder.Folder.java
public void animateClosed() { if (!(getParent() instanceof DragLayer)) return;//from ww w . j a va 2s . c om final ObjectAnimator oa = LauncherAnimUtils.ofViewAlphaAndScale(this, 0, 0.9f, 0.9f); oa.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setLayerType(LAYER_TYPE_NONE, null); close(true); } @Override public void onAnimationStart(Animator animation) { Utilities.sendCustomAccessibilityEvent(Folder.this, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getContext().getString(R.string.folder_closed)); mState = STATE_ANIMATING; } }); oa.setDuration(mExpandDuration); setLayerType(LAYER_TYPE_HARDWARE, null); oa.start(); }
From source file:com.android.calendar.AllInOneActivity.java
@Override public void handleEvent(EventInfo event) { long displayTime = -1; if (event.eventType == EventType.GO_TO) { if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) { mBackToPreviousView = true;//from w ww.j a v a 2 s . c o m } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) { // Clear the flag is change to a different view type mBackToPreviousView = false; } setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false); if (mSearchView != null) { mSearchView.clearFocus(); } if (mShowCalendarControls) { int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth : mControlsAnimateHeight; boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA; if (mControlsMenu != null) { mControlsMenu.setVisible(!noControlsView); mControlsMenu.setEnabled(!noControlsView); } if (noControlsView || mHideControls) { // hide minimonth and calendar frag mShowSideViews = false; if (!mHideControls) { final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0, animationSize); slideAnimation.addListener(mSlideAnimationDoneListener); slideAnimation.setDuration(mCalendarControlsAnimationTime); ObjectAnimator.setFrameDelay(0); slideAnimation.start(); } else { mMiniMonth.setVisibility(View.GONE); mCalendarsList.setVisibility(View.GONE); mMiniMonthContainer.setVisibility(View.GONE); } } else { // show minimonth and calendar frag mShowSideViews = true; mMiniMonth.setVisibility(View.VISIBLE); mCalendarsList.setVisibility(View.VISIBLE); mMiniMonthContainer.setVisibility(View.VISIBLE); if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH || mController.getPreviousViewType() == ViewType.AGENDA)) { final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", animationSize, 0); slideAnimation.setDuration(mCalendarControlsAnimationTime); ObjectAnimator.setFrameDelay(0); slideAnimation.start(); } } } displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true) : event.startTime.toMillis(true); if (!mIsTabletConfig) { refreshActionbarTitle(displayTime); } } else if (event.eventType == EventType.VIEW_EVENT) { // If in Agenda view and "show_event_details_with_agenda" is "true", // do not create the event info fragment here, it will be created by the Agenda // fragment if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) { if (event.startTime != null && event.endTime != null) { // Event is all day , adjust the goto time to local time if (event.isAllDay()) { Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone); Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone); } mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime, event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null); } else if (event.selectedTime != null) { mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id, ViewType.AGENDA); } } else { // TODO Fix the temp hack below: && mCurrentView != // ViewType.AGENDA if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) { mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1, ViewType.CURRENT); } int response = event.getResponse(); if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda) || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK) || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) { // start event info as activity Intent intent = new Intent(Intent.ACTION_VIEW); Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id); intent.setData(eventUri); intent.setClass(this, EventInfoActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false)); intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false)); intent.putExtra(ATTENDEE_STATUS, response); startActivity(intent); } else { // start event info as a dialog EventInfoFragment fragment = new EventInfoFragment(this, event.id, event.startTime.toMillis(false), event.endTime.toMillis(false), response, true, EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */); fragment.setDialogParams(event.x, event.y, mActionBar.getHeight()); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); // if we have an old popup replace it Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG); if (fOld != null && fOld.isAdded()) { ft.remove(fOld); } ft.add(fragment, EVENT_INFO_FRAGMENT_TAG); ft.commit(); } } displayTime = event.startTime.toMillis(true); } else if (event.eventType == EventType.UPDATE_TITLE) { setTitleInActionBar(event); if (!mIsTabletConfig) { refreshActionbarTitle(mController.getTime()); } } updateSecondaryTitleFields(displayTime); }
From source file:io.plaidapp.ui.FeedAdapter.java
private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder) { final int[] imageSize = shot.images.bestSize(); Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() { @Override/* ww w . jav a 2s.c o m*/ public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { if (!shot.hasFadedIn) { holder.image.setHasTransientState(true); final ObservableColorMatrix cm = new ObservableColorMatrix(); ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f); saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { // just animating the color matrix does not invalidate the // drawable so need this update listener. Also have to create a // new CMCF as the matrix is immutable :( if (holder.image.getDrawable() != null) { holder.image.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm)); } } }); saturation.setDuration(2000); saturation.setInterpolator( AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in)); saturation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.image.setHasTransientState(false); } }); saturation.start(); shot.hasFadedIn = true; } return false; } @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } }).placeholder(shotLoadingPlaceholders[holder.getAdapterPosition() % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1]) .into(new DribbbleTarget(holder.image, false)); }
From source file:com.klinker.android.sliding.MultiShrinkScroller.java
public void reverseExpansionAnimation() { final Interpolator interpolator; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in); } else {/*from w ww .jav a2 s . co m*/ interpolator = new DecelerateInterpolator(); } WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int screenHeight = size.y; int screenWidth = size.x; final ValueAnimator heightExpansion = ValueAnimator.ofInt(screenHeight, expansionViewHeight); heightExpansion.setInterpolator(interpolator); heightExpansion.setDuration(ANIMATION_DURATION); heightExpansion.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int val = (int) animation.getAnimatedValue(); ViewGroup.LayoutParams params = getLayoutParams(); params.height = val; setLayoutParams(params); } }); heightExpansion.start(); final ValueAnimator widthExpansion = ValueAnimator.ofInt(getWidth(), expansionViewWidth); widthExpansion.setInterpolator(interpolator); widthExpansion.setDuration(ANIMATION_DURATION); widthExpansion.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { int val = (int) animation.getAnimatedValue(); ViewGroup.LayoutParams params = getLayoutParams(); params.width = val; setLayoutParams(params); } }); widthExpansion.start(); ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, 0f, expansionLeftOffset); translationX.setInterpolator(interpolator); translationX.setDuration(ANIMATION_DURATION); translationX.start(); ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0f, expansionTopOffset); translationY.setInterpolator(interpolator); translationY.setDuration(ANIMATION_DURATION); translationY.addListener(exitAnimationListner); translationY.start(); }
From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java
public void toggleVisibleTitles() { // Use these for custom animations. final FragmentManager fm = getSupportFragmentManager(); final TitlesFragment f = (TitlesFragment) fm.findFragmentById(R.id.frag_title); final View titlesView = f.getView(); mLabelIndex = 1 - mLabelIndex;/* w w w .j a v a 2s . c o m*/ // Determine if we're in portrait, and whether we're showing or hiding the titles // with this toggle. final boolean isPortrait = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; final boolean shouldShow = f.isHidden() || mCurrentTitlesAnimator != null; // Cancel the current titles animation if there is one. if (mCurrentTitlesAnimator != null) mCurrentTitlesAnimator.cancel(); // Begin setting up the object animator. We'll animate the bottom or right edge of the // titles view, as well as its alpha for a fade effect. ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(titlesView, PropertyValuesHolder.ofInt(isPortrait ? "bottom" : "right", shouldShow ? getResources().getDimensionPixelSize(R.dimen.titles_size) : 0), PropertyValuesHolder.ofFloat("alpha", shouldShow ? 1 : 0)); // At each step of the animation, we'll perform layout by calling setLayoutParams. final ViewGroup.LayoutParams lp = titlesView.getLayoutParams(); objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator valueAnimator) { // *** WARNING ***: triggering layout at each animation frame highly impacts // performance so you should only do this for simple layouts. More complicated // layouts can be better served with individual animations on child views to // avoid the performance penalty of layout. if (isPortrait) { lp.height = (Integer) valueAnimator.getAnimatedValue(); } else { lp.width = (Integer) valueAnimator.getAnimatedValue(); } titlesView.setLayoutParams(lp); } }); if (shouldShow) { fm.beginTransaction().show(f).commit(); objectAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mCurrentTitlesAnimator = null; } }); } else { objectAnimator.addListener(new AnimatorListenerAdapter() { boolean canceled; @Override public void onAnimationCancel(Animator animation) { canceled = true; super.onAnimationCancel(animation); } @Override public void onAnimationEnd(Animator animator) { if (canceled) return; mCurrentTitlesAnimator = null; fm.beginTransaction().hide(f).commit(); } }); } // Start the animation. objectAnimator.start(); mCurrentTitlesAnimator = objectAnimator; invalidateOptionsMenu(); // Manually trigger onNewIntent to check for ACTION_DIALOG. onNewIntent(getIntent()); }
From source file:com.box.myview.MyTopSnackBar.TSnackbar.java
/** * @param drawable/* ww w . ja v a2s. com*/ * @param left * @param right * @return */ public TSnackbar addIconProgressLoading(Drawable drawable, boolean left, boolean right) { final ObjectAnimator animator = ObjectAnimator.ofInt(drawable, "level", 0, 10000); animator.setDuration(1000); animator.setInterpolator(new LinearInterpolator()); animator.setRepeatCount(ValueAnimator.INFINITE); animator.setRepeatMode(ValueAnimator.INFINITE); mView.setBackgroundColor(mContext.getResources().getColor(Prompt.SUCCESS.getBackgroundColor())); if (left) { mView.getMessageView().setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } if (right) { mView.getMessageView().setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null); } animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (mCallback != null) { mCallback.onShown(TSnackbar.this); } SnackbarManager.getInstance().onShown(mManagerCallback); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animator.start(); return this; }
From source file:com.klinker.android.sliding.MultiShrinkScroller.java
/** * Scroll the activity off the bottom of the screen. *//*from w w w . j a v a2 s .co m*/ public void scrollOffBottom() { isTouchDisabledForDismissAnimation = true; scroller.forceFinished(true); if (!willUseReverseExpansion()) { final Interpolator interpolator = new AcceleratingFlingInterpolator(EXIT_FLING_ANIMATION_DURATION_MS, getCurrentVelocity(), getScrollUntilOffBottom()); ObjectAnimator translateAnimation = ObjectAnimator.ofInt(this, "scroll", getScroll() - getScrollUntilOffBottom()); translateAnimation.setRepeatCount(0); translateAnimation.setInterpolator(interpolator); translateAnimation.setDuration(EXIT_FLING_ANIMATION_DURATION_MS); translateAnimation.addListener(exitAnimationListner); translateAnimation.start(); } else { reverseExpansionAnimation(); } if (listener != null) { listener.onStartScrollOffBottom(); } }
From source file:com.tengio.FloatingSearchView.java
private void transitionOutLeftSection(boolean withAnim) { switch (mLeftActionMode) { case LEFT_ACTION_MODE_SHOW_HAMBURGER: closeMenuDrawable(mMenuBtnDrawable, withAnim); break;//from w w w .j av a 2 s . co m case LEFT_ACTION_MODE_SHOW_SEARCH: changeIcon(mLeftAction, mIconSearch, withAnim); break; case LEFT_ACTION_MODE_SHOW_HOME: //do nothing break; case LEFT_ACTION_MODE_NO_LEFT_ACTION: mLeftAction.setImageDrawable(mIconBackArrow); if (withAnim) { ObjectAnimator searchInputTransXAnim = ViewPropertyObjectAnimator.animate(mSearchInputParent) .translationX(-Util.dpToPx(LEFT_MENU_WIDTH_AND_MARGIN_START)).get(); ObjectAnimator scaleXArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleX(0.5f).get(); ObjectAnimator scaleYArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).scaleY(0.5f).get(); ObjectAnimator fadeArrowAnim = ViewPropertyObjectAnimator.animate(mLeftAction).alpha(0.5f).get(); scaleXArrowAnim.setDuration(300); scaleYArrowAnim.setDuration(300); fadeArrowAnim.setDuration(300); scaleXArrowAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { //restore normal state mLeftAction.setScaleX(1.0f); mLeftAction.setScaleY(1.0f); mLeftAction.setAlpha(1.0f); mLeftAction.setVisibility(View.INVISIBLE); } }); AnimatorSet animSet = new AnimatorSet(); animSet.setDuration(350); animSet.playTogether(scaleXArrowAnim, scaleYArrowAnim, fadeArrowAnim, searchInputTransXAnim); animSet.start(); } else { mLeftAction.setVisibility(View.INVISIBLE); } break; } }
From source file:com.waz.zclient.pages.main.participants.ParticipantFragment.java
@Override public void onHidePickUser(IPickUserController.Destination destination, boolean closeWithoutSelectingPeople) { if (LayoutSpec.isPhone(getActivity())) { return;/*w w w .j a va 2 s . c o m*/ } if (!destination.equals(getCurrentPickerDestination())) { return; } // Workaround for animation bug with nested child fragments // Animating fragment container views and then popping stack at end of animation int showParticipantsDelay = getResources().getInteger(R.integer.framework_animation_delay_long); int hidePickUserAnimDuration = getResources().getInteger(R.integer.framework_animation_duration_medium); TimeInterpolator hidePickUserInterpolator = new Expo.EaseIn(); ObjectAnimator hidePickUserAnimator; // Fade animation in participants dialog on tablet if (LayoutSpec.isTablet(getActivity())) { hidePickUserAnimator = ObjectAnimator.ofFloat(pickUserContainerView, View.ALPHA, 1f, 0f); hidePickUserAnimator.setInterpolator(new Linear.EaseIn()); } else { hidePickUserAnimator = ObjectAnimator.ofFloat(pickUserContainerView, View.TRANSLATION_Y, 0f, pickUserContainerView.getMeasuredHeight()); hidePickUserAnimator.setInterpolator(hidePickUserInterpolator); hidePickUserAnimator.setDuration(hidePickUserAnimDuration); } hidePickUserAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (!isResumed()) { return; } getChildFragmentManager().popBackStackImmediate(PickUserFragment.TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); if (LayoutSpec.isTablet(getActivity())) { // Reset for fade animation in participants dialog on tablet pickUserContainerView.setAlpha(1f); } else { pickUserContainerView.setTranslationY(0f); } } }); participantsContainerView.setAlpha(0); participantsContainerView.setVisibility(View.VISIBLE); ObjectAnimator showParticipantsAnimator = ObjectAnimator.ofFloat(participantsContainerView, View.ALPHA, 0f, 1f); showParticipantsAnimator.setInterpolator(new Quart.EaseOut()); showParticipantsAnimator .setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium)); showParticipantsAnimator.setStartDelay(showParticipantsDelay); AnimatorSet hideSet = new AnimatorSet(); hideSet.playTogether(hidePickUserAnimator, showParticipantsAnimator); hideSet.start(); if (LayoutSpec.isPhone(getActivity()) && getControllerFactory().getNavigationController() .getPagerPosition() == NavigationController.SECOND_PAGE) { // TODO: https://wearezeta.atlassian.net/browse/AN-3081 if (getControllerFactory().getConversationScreenController().isShowingParticipant()) { getControllerFactory().getNavigationController().setRightPage(Page.PARTICIPANT, TAG); } else { getControllerFactory().getNavigationController().setRightPage(Page.MESSAGE_STREAM, TAG); } } }