List of usage examples for android.animation AnimatorSet AnimatorSet
public AnimatorSet()
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private AnimatorSet newCollapseLeftAnimator() { ObjectAnimator slTransX = ObjectAnimator.ofFloat(leftContainer, "translationX", 0, -leftWidth); ObjectAnimator tlTransX = ObjectAnimator.ofFloat(rightContainer, "translationX", 0, -leftWidth); AnimatorSet as = new AnimatorSet(); as.setDuration(durationMs).play(slTransX).with(tlTransX); as.addListener(new AnimatorListenerAdapter() { @Override/*w w w . j av a 2 s .co m*/ public void onAnimationStart(Animator animation) { leftContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); leftContainer.setVisibility(View.VISIBLE); rightContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); rightContainer.setVisibility(View.VISIBLE); thingContainer.setVisibility(View.GONE); } @Override public void onAnimationEnd(Animator animation) { leftContainer.setLayerType(View.LAYER_TYPE_NONE, null); leftContainer.setVisibility(View.GONE); rightContainer.setLayerType(View.LAYER_TYPE_NONE, null); rightContainer.setTranslationX(0); thingContainer.setVisibility(View.VISIBLE); } }); return as; }
From source file:com.android.settings.widget.DotsPageIndicator.java
private void startJoiningAnimations() { joiningAnimationSet = new AnimatorSet(); joiningAnimationSet.playTogether(joiningAnimations); joiningAnimationSet.start(); }
From source file:com.waz.zclient.pages.main.conversation.SingleImageFragment.java
private AnimatorSet getSaveImageAnimation(final ImageAsset image) { int totalAnimationDuration = getResources().getInteger(R.integer.framework_animation_duration_long); ObjectAnimator fadeOutAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.ALPHA, 1, 0); fadeOutAnimator.setDuration(totalAnimationDuration); ObjectAnimator scaleDownXAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.SCALE_X, 0f); ObjectAnimator scaleDownYAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.SCALE_Y, 0f); scaleDownXAnimator.setDuration(totalAnimationDuration); scaleDownYAnimator.setDuration(totalAnimationDuration); int moveY = ViewUtils.getOrientationIndependentDisplayHeight(getActivity()) / 2; int moveX;//from w w w .j a v a2 s .c om if (ViewUtils.isInLandscape(getActivity())) { moveX = ViewUtils.getOrientationIndependentDisplayWidth(getActivity()); } else { moveX = ViewUtils.getOrientationIndependentDisplayWidth(getActivity()) / 2; } ObjectAnimator moveXAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.TRANSLATION_X, -moveX); ObjectAnimator moveYAnimator = ObjectAnimator.ofFloat(saveImageViewContainer, View.TRANSLATION_Y, moveY); moveXAnimator.setDuration(totalAnimationDuration); moveYAnimator.setDuration(totalAnimationDuration); // Fade out top image view for blur effect ObjectAnimator fadeToBlurredAnimator = ObjectAnimator.ofFloat(saveImageView, View.ALPHA, 1, 0); fadeToBlurredAnimator.setDuration(getResources().getInteger(R.integer.framework_animation_duration_medium)); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setInterpolator(new Expo.EaseIn()); animatorSet.playTogether(fadeOutAnimator, scaleDownXAnimator, scaleDownYAnimator, moveXAnimator, moveYAnimator, fadeToBlurredAnimator); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (getStoreFactory() == null || getStoreFactory().isTornDown()) { return; } resetSaveImageView(); // Image saving is called here, as an image save triggers a notification which contains a bitmap; // currently that bitmap is quite large, android.app.Notification writes the bitmap to a parcel // on the main thread, dropping a large number of frames and breaking the save animation image.saveImageToGallery(SingleImageFragment.this); enableSaveImageButton(true); } }); return animatorSet; }
From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java
/** * Called when the page changes.// ww w . j a va2 s . c om */ private void onPageChangedInternal(int previousPage) { if (mAnimator != null) { mAnimator.end(); } mPageIndicator.onPageSelected(mCurrentPageIndex, true); List<Animator> animators = new ArrayList<>(); // Header animation Animator fadeAnimator = null; if (previousPage < getCurrentPageIndex()) { // sliding to left animators.add(createAnimator(mTitleView, false, Gravity.START, 0)); animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.START, DESCRIPTION_START_DELAY_MS)); animators.add(createAnimator(mTitleView, true, Gravity.END, HEADER_APPEAR_DELAY_MS)); animators.add(createAnimator(mDescriptionView, true, Gravity.END, HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS)); } else { // sliding to right animators.add(createAnimator(mTitleView, false, Gravity.END, 0)); animators.add(fadeAnimator = createAnimator(mDescriptionView, false, Gravity.END, DESCRIPTION_START_DELAY_MS)); animators.add(createAnimator(mTitleView, true, Gravity.START, HEADER_APPEAR_DELAY_MS)); animators.add(createAnimator(mDescriptionView, true, Gravity.START, HEADER_APPEAR_DELAY_MS + DESCRIPTION_START_DELAY_MS)); } final int currentPageIndex = getCurrentPageIndex(); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mTitleView.setText(getPageTitle(currentPageIndex)); mDescriptionView.setText(getPageDescription(currentPageIndex)); } }); // Animator for switching between page indicator and button. if (getCurrentPageIndex() == getPageCount() - 1) { mStartButton.setVisibility(View.VISIBLE); Animator navigatorFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_page_indicator_fade_out); navigatorFadeOutAnimator.setTarget(mPageIndicator); navigatorFadeOutAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mPageIndicator.setVisibility(View.GONE); } }); animators.add(navigatorFadeOutAnimator); Animator buttonFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_start_button_fade_in); buttonFadeInAnimator.setTarget(mStartButton); animators.add(buttonFadeInAnimator); } else if (previousPage == getPageCount() - 1) { mPageIndicator.setVisibility(View.VISIBLE); Animator navigatorFadeInAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_page_indicator_fade_in); navigatorFadeInAnimator.setTarget(mPageIndicator); animators.add(navigatorFadeInAnimator); Animator buttonFadeOutAnimator = AnimatorInflater.loadAnimator(getActivity(), R.animator.lb_onboarding_start_button_fade_out); buttonFadeOutAnimator.setTarget(mStartButton); buttonFadeOutAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mStartButton.setVisibility(View.GONE); } }); animators.add(buttonFadeOutAnimator); } mAnimator = new AnimatorSet(); mAnimator.playTogether(animators); mAnimator.start(); onPageChanged(mCurrentPageIndex, previousPage); }
From source file:trendoidtechnologies.com.navigationdrawerlibrary.DrawerView.java
private void animateToProfile(DrawerProfile profile) { if (loggingEnabled) Log.d(TAG, "animateToProfile(*" + profile.getId() + ")"); if (mProfileAdapter.getCount() > 1) { List<Animator> animators = new ArrayList<>(); List<Animator.AnimatorListener> listeners = new ArrayList<>(); final DrawerProfile oldProfile = mProfileAdapter.getItem(0); final DrawerProfile newProfile = profile; boolean isRtl = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LAYOUT_DIRECTION_RTL; int rtlSign = isRtl ? -1 : 1; /* Background animation */ AlphaSatColorMatrixEvaluator evaluator = new AlphaSatColorMatrixEvaluator(); final AnimatableColorMatrixColorFilter filter = new AnimatableColorMatrixColorFilter( evaluator.getColorMatrix()); ObjectAnimator backgroundAnimator = ObjectAnimator.ofObject(filter, "colorMatrix", evaluator, evaluator.getColorMatrix()); backgroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from ww w .j av a 2 s. c o m*/ public void onAnimationUpdate(ValueAnimator animation) { imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter()); } }); animators.add(backgroundAnimator); listeners.add(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { imageViewProfileBackground.setImageDrawable(oldProfile.getBackground()); imageViewProfileBackgroundOverlay.setImageDrawable(newProfile.getBackground()); imageViewProfileBackgroundOverlay.setColorFilter(filter.getColorFilter()); imageViewProfileBackgroundOverlay.setVisibility(VISIBLE); imageViewProfileAvatarSecondary.setClickable(false); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileBackground.setImageDrawable(newProfile.getBackground()); if (newProfile.getBackground() instanceof BitmapDrawable) { new Palette.Builder(((BitmapDrawable) newProfile.getBackground()).getBitmap()) .resizeBitmapSize(500).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); if (vibrantSwatch != null) { textViewProfileAvatarCount .setTextColor(vibrantSwatch.getTitleTextColor()); textViewProfileAvatarCount.getBackground() .setColorFilter(vibrantSwatch.getRgb(), PorterDuff.Mode.SRC_IN); } } }); } imageViewProfileBackgroundOverlay.setVisibility(GONE); if (hasOnProfileSwitchListener()) { onProfileSwitchListener.onSwitch(oldProfile, oldProfile.getId(), newProfile, newProfile.getId()); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); /* Text animation */ AnimatorSet textSet = new AnimatorSet(); AnimatorSet textOutSet = new AnimatorSet(); textOutSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 1, 0), ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", 0, getWidth() / 4 * rtlSign)); textOutSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { updateProfileTheme(); if (newProfile.hasName()) { textViewProfileName.setText(newProfile.getName()); textViewProfileName.setVisibility(VISIBLE); } else { textViewProfileName.setVisibility(GONE); } if (newProfile.hasDescription()) { textViewProfileDescription.setText(newProfile.getDescription()); textViewProfileDescription.setVisibility(VISIBLE); } else { textViewProfileDescription.setVisibility(GONE); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); AnimatorSet textInSet = new AnimatorSet(); textInSet.playTogether(ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "alpha", 0, 1), ObjectAnimator.ofFloat(linearLayoutProfileTextContainer, "translationX", -getWidth() / 4 * rtlSign, 0)); textSet.playSequentially(textOutSet, textInSet); animators.add(textSet); AnimatorSet profileSet = new AnimatorSet(); if (mProfileAdapter.getCount() == 2) { /* Avatar animation */ int translation = isRtl ? (relativeLayoutProfileContent.getWidth() - getResources().getDimensionPixelSize(R.dimen.md_big_avatar_size) - 2 * getResources().getDimensionPixelSize(R.dimen.md_baseline)) : (imageViewProfileAvatarSecondary.getLeft() - getResources().getDimensionPixelSize(R.dimen.md_baseline)); float scale = getResources().getDimension(R.dimen.md_avatar_size) / getResources().getDimension(R.dimen.md_big_avatar_size); float translationCorrect = (getResources().getDimension(R.dimen.md_avatar_size) - getResources().getDimension(R.dimen.md_big_avatar_size)) / 2; listeners.add(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { imageViewProfileAvatarSecondary.setPivotX(0); imageViewProfileAvatarSecondary.setPivotY(0); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileAvatar.setTranslationX(0); imageViewProfileAvatar.setTranslationY(0); imageViewProfileAvatar.setScaleX(1); imageViewProfileAvatar.setScaleY(1); imageViewProfileAvatarSecondary.setTranslationX(0); imageViewProfileAvatarSecondary.setScaleX(1); imageViewProfileAvatarSecondary.setScaleY(1); if (oldProfile.hasAvatar()) { imageViewProfileAvatarSecondary.setImageDrawable(oldProfile.getAvatar()); imageViewProfileAvatarSecondary.setVisibility(VISIBLE); } else { imageViewProfileAvatarSecondary.setVisibility(INVISIBLE); } if (newProfile.hasAvatar()) { imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar()); imageViewProfileAvatar.setVisibility(VISIBLE); imageViewProfileAvatarSecondary.setClickable(true); } else { imageViewProfileAvatar.setVisibility(INVISIBLE); imageViewProfileAvatarSecondary.setClickable(false); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); if (oldProfile.hasAvatar()) { ObjectAnimator stepTranslateXAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar, "translationX", 0, translation * rtlSign + translationCorrect); stepTranslateXAnimator.setInterpolator(new StepInterpolator()); animators.add(stepTranslateXAnimator); ObjectAnimator stepTranslateYAnimator = ObjectAnimator.ofFloat(imageViewProfileAvatar, "translationY", 0, translationCorrect); stepTranslateYAnimator.setInterpolator(new StepInterpolator()); animators.add(stepTranslateYAnimator); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0, 1)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f, scale)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f, scale)); } if (newProfile.hasAvatar()) { animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "translationX", 0, -translation * rtlSign)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleX", 1, 1 / scale)); animators.add(ObjectAnimator.ofFloat(imageViewProfileAvatarSecondary, "scaleY", 1, 1 / scale)); } } else { AnimatorSet profileOutSet = new AnimatorSet(); profileOutSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 1, 0), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 1, 0.5f), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 1, 0.5f)); profileOutSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() { @Override public void onItemClick(LinearListView parent, View view, int position, long id) { } }); } @Override public void onAnimationEnd(Animator animation) { imageViewProfileAvatar.setImageDrawable(newProfile.getAvatar()); linearListViewProfileList.setOnItemClickListener(new LinearListView.OnItemClickListener() { @Override public void onItemClick(LinearListView parent, View view, int position, long id) { if (position != 0) { selectProfile(mProfileAdapter.getItem(position)); } } }); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); AnimatorSet profileInSet = new AnimatorSet(); profileInSet.playTogether(ObjectAnimator.ofFloat(imageViewProfileAvatar, "alpha", 0, 1), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleX", 0.5f, 1), ObjectAnimator.ofFloat(imageViewProfileAvatar, "scaleY", 0.5f, 1)); profileSet.playSequentially(profileOutSet, profileInSet); animators.add(profileSet); } if (animators.size() > 0) { /* Play animation */ AnimatorSet set = new AnimatorSet(); set.playTogether(animators); set.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time)); textSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2); profileSet.setDuration(getResources().getInteger(R.integer.md_profile_switching_anim_time) / 2); for (Animator.AnimatorListener listener : listeners) { set.addListener(listener); } set.start(); } } }
From source file:com.aliyun.homeshell.Folder.java
public void showSelectApps(int[] pos) { if (mRunningAnimatorSet != null) { if (!mRunningIsShow) { mRunningAnimatorSet.end();//from ww w . j a v a 2 s . c o m } else { return; } } if (mAppsSelectView == null) { mAppsSelectView = (FolderAppsSelectView) LayoutInflater.from(getContext()) .inflate(R.layout.folder_apps_select, null); mAppsSelectView.init(this, mInfo, mLauncher); mLauncher.getDragLayer().addView(mAppsSelectView); } mAppsSelectView.initSelectedState(mInfo); mAppsSelectView.setScaleX(0); mAppsSelectView.setScaleY(0); mAppsSelectView.setPivotX(pos[0]); mAppsSelectView.setPivotY(pos[1]); ObjectAnimator visToInvis = ObjectAnimator.ofFloat(this, "alpha", 1, 0); visToInvis.setDuration(mAnimatorDuration); ObjectAnimator invisToVisX = ObjectAnimator.ofFloat(mAppsSelectView, "scaleX", 0, 1); invisToVisX.setDuration(mAnimatorDuration); ObjectAnimator invisToVisY = ObjectAnimator.ofFloat(mAppsSelectView, "scaleY", 0, 1); invisToVisY.setDuration(mAnimatorDuration); List<Animator> animList = new ArrayList<Animator>(); animList.add(visToInvis); animList.add(invisToVisX); animList.add(invisToVisY); final AnimatorSet as = new AnimatorSet(); as.setInterpolator(new LinearInterpolator()); as.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animator) { mAppsSelectView.setVisibility(View.VISIBLE); mRunningAnimatorSet = as; mRunningIsShow = true; } @Override public void onAnimationEnd(Animator animator) { mRunningAnimatorSet = null; mRunningIsShow = false; Folder.this.setVisibility(View.INVISIBLE); mAppsSelectView.setVisibility(View.VISIBLE); DisplayMetrics metric = new DisplayMetrics(); mLauncher.getWindowManager().getDefaultDisplay().getMetrics(metric); int width = metric.widthPixels; int height = metric.heightPixels; mAppsSelectView.setPivotX(width / 2); mAppsSelectView.setPivotY(height / 2); mAppsSelectView.setFocusableInTouchMode(true); mAppsSelectView.setFocusable(true); mAppsSelectView.requestFocus(); } }); as.playTogether(animList); as.start(); }
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private AnimatorSet newExpandLeftAnimator() { ObjectAnimator slTransX = ObjectAnimator.ofFloat(leftContainer, "translationX", -leftWidth, 0); ObjectAnimator tlTransX = ObjectAnimator.ofFloat(rightContainer, "translationX", -leftWidth, 0); AnimatorSet as = new AnimatorSet(); as.setDuration(durationMs).play(slTransX).with(tlTransX); as.addListener(new AnimatorListenerAdapter() { @Override/* w w w . j a va 2 s . com*/ public void onAnimationStart(Animator animation) { leftContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); leftContainer.setVisibility(View.VISIBLE); rightContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); rightContainer.setVisibility(View.VISIBLE); thingContainer.setVisibility(View.GONE); } @Override public void onAnimationEnd(Animator animation) { leftContainer.setLayerType(View.LAYER_TYPE_NONE, null); rightContainer.setLayerType(View.LAYER_TYPE_NONE, null); } }); return as; }
From source file:com.android.tv.menu.MenuLayoutManager.java
/** * Move the current selection to the given {@code position} with animation. * The animation specification is included in http://b/21069476 *//* w ww.ja v a 2 s. c om*/ public void setSelectedPositionSmooth(final int position) { if (DEBUG) { Log.d(TAG, "setSelectedPositionSmooth(position=" + position + ") {previousPosition=" + mSelectedPosition + "}"); } if (mMenuView.getVisibility() != View.VISIBLE) { setSelectedPosition(position); return; } if (mSelectedPosition == position) { return; } boolean oldIndexValid = Utils.isIndexValid(mMenuRowViews, mSelectedPosition); SoftPreconditions.checkState(oldIndexValid, TAG, "No previous selection: " + mSelectedPosition); if (!oldIndexValid) { return; } boolean newIndexValid = Utils.isIndexValid(mMenuRowViews, position); SoftPreconditions.checkArgument(newIndexValid, TAG, "position " + position); if (!newIndexValid) { return; } MenuRow row = mMenuRows.get(position); if (!row.isVisible()) { Log.e(TAG, "Moving to the invisible row: " + position); return; } if (mAnimatorSet != null) { // Do not cancel the animation here. The property values should be set to the end values // when the animation finishes. mAnimatorSet.end(); } if (mTitleFadeOutAnimator != null) { // Cancel the animation instead of ending it in order that the title animation starts // again from the intermediate state. mTitleFadeOutAnimator.cancel(); } final int oldPosition = mSelectedPosition; mSelectedPosition = position; if (DEBUG) dumpChildren("startRowAnimation()"); MenuRowView currentView = mMenuRowViews.get(position); // Show the children of the next row. currentView.getTitleView().setVisibility(View.VISIBLE); currentView.getContentsView().setVisibility(View.VISIBLE); // Request focus after the new contents view shows up. mMenuView.requestFocus(); if (mTempTitleViewForOld == null) { // Initialize here because we don't know when the views are inflated. mTempTitleViewForOld = (TextView) mMenuView.findViewById(R.id.temp_title_for_old); mTempTitleViewForCurrent = (TextView) mMenuView.findViewById(R.id.temp_title_for_current); } // Animations. mPropertyValuesAfterAnimation.clear(); List<Animator> animators = new ArrayList<>(); boolean scrollDown = position > oldPosition; List<Rect> layouts = getViewLayouts(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), mMenuView.getBottom()); // Old row. MenuRow oldRow = mMenuRows.get(oldPosition); MenuRowView oldView = mMenuRowViews.get(oldPosition); View oldContentsView = oldView.getContentsView(); // Old contents view. animators.add(createAlphaAnimator(oldContentsView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) .setDuration(mOldContentsFadeOutDuration)); final TextView oldTitleView = oldView.getTitleView(); setTempTitleView(mTempTitleViewForOld, oldTitleView); Rect oldLayoutRect = layouts.get(oldPosition); if (scrollDown) { // Old title view. if (oldRow.hideTitleWhenSelected() && oldTitleView.getVisibility() != View.VISIBLE) { // This case is not included in the animation specification. mTempTitleViewForOld.setScaleX(1.0f); mTempTitleViewForOld.setScaleY(1.0f); animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, oldView.getTitleViewAlphaDeselected(), mFastOutLinearIn)); int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop(); animators.add(createTranslationYAnimator(mTempTitleViewForOld, offset + mRowScrollUpAnimationOffset, offset)); } else { animators .add(createScaleXAnimator(mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f)); animators .add(createScaleYAnimator(mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f)); animators.add(createAlphaAnimator(mTempTitleViewForOld, oldTitleView.getAlpha(), oldView.getTitleViewAlphaDeselected(), mLinearOutSlowIn)); animators.add(createTranslationYAnimator(mTempTitleViewForOld, 0, oldLayoutRect.top - mTempTitleViewForOld.getTop())); } oldTitleView.setAlpha(oldView.getTitleViewAlphaDeselected()); oldTitleView.setVisibility(View.INVISIBLE); } else { Rect currentLayoutRect = new Rect(layouts.get(position)); // Old title view. // The move distance in the specification is 32dp(mRowScrollUpAnimationOffset). // But if the height of the upper row is small, the upper row will move down a lot. In // this case, this row needs to move more than the specification to avoid the overlap of // the two titles. // The maximum is to the top of the start position of mTempTitleViewForOld. int distanceCurrentTitle = currentLayoutRect.top - currentView.getTop(); int distance = Math.max(mRowScrollUpAnimationOffset, distanceCurrentTitle); int distanceToTopOfSecondTitle = oldLayoutRect.top - mRowScrollUpAnimationOffset - oldView.getTop(); animators.add( createTranslationYAnimator(oldTitleView, 0.0f, Math.min(distance, distanceToTopOfSecondTitle))); animators.add(createAlphaAnimator(oldTitleView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) .setDuration(mOldContentsFadeOutDuration)); animators.add(createScaleXAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f)); animators.add(createScaleYAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f)); mTempTitleViewForOld.setScaleX(1.0f); mTempTitleViewForOld.setScaleY(1.0f); animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, oldView.getTitleViewAlphaDeselected(), mFastOutLinearIn)); int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop(); animators.add( createTranslationYAnimator(mTempTitleViewForOld, offset - mRowScrollUpAnimationOffset, offset)); } // Current row. Rect currentLayoutRect = new Rect(layouts.get(position)); TextView currentTitleView = currentView.getTitleView(); View currentContentsView = currentView.getContentsView(); currentContentsView.setAlpha(0.0f); if (scrollDown) { // Current title view. setTempTitleView(mTempTitleViewForCurrent, currentTitleView); // The move distance in the specification is 32dp(mRowScrollUpAnimationOffset). // But if the height of the upper row is small, the upper row will move up a lot. In // this case, this row needs to start the move from more than the specification to avoid // the overlap of the two titles. // The maximum is to the top of the end position of mTempTitleViewForCurrent. int distanceOldTitle = oldView.getTop() - oldLayoutRect.top; int distance = Math.max(mRowScrollUpAnimationOffset, distanceOldTitle); int distanceTopOfSecondTitle = currentView.getTop() - mRowScrollUpAnimationOffset - currentLayoutRect.top; animators.add(createTranslationYAnimator(currentTitleView, Math.min(distance, distanceTopOfSecondTitle), 0.0f)); currentView.setTop(currentLayoutRect.top); ObjectAnimator animator = createAlphaAnimator(currentTitleView, 0.0f, 1.0f, mFastOutLinearIn) .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); currentTitleView.setAlpha(0.0f); animators.add(animator); animators.add(createScaleXAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); animators.add(createScaleYAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); animators.add(createTranslationYAnimator(mTempTitleViewForCurrent, 0.0f, -mRowScrollUpAnimationOffset)); animators.add(createAlphaAnimator(mTempTitleViewForCurrent, currentView.getTitleViewAlphaDeselected(), 0, mLinearOutSlowIn)); // Current contents view. animators.add(createTranslationYAnimator(currentContentsView, mRowScrollUpAnimationOffset, 0.0f)); animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); animators.add(animator); } else { currentView.setBottom(currentLayoutRect.bottom); // Current title view. int currentViewOffset = currentLayoutRect.top - currentView.getTop(); animators.add(createTranslationYAnimator(currentTitleView, 0, currentViewOffset)); animators.add(createAlphaAnimator(currentTitleView, currentView.getTitleViewAlphaDeselected(), 1.0f, mFastOutSlowIn)); animators.add(createScaleXAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); animators.add(createScaleYAnimator(currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); // Current contents view. animators.add(createTranslationYAnimator(currentContentsView, currentViewOffset - mRowScrollUpAnimationOffset, currentViewOffset)); ObjectAnimator animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); animators.add(animator); } // Next row. int nextPosition; if (scrollDown) { nextPosition = findNextVisiblePosition(position); if (nextPosition != -1) { MenuRowView nextView = mMenuRowViews.get(nextPosition); Rect nextLayoutRect = layouts.get(nextPosition); animators.add(createTranslationYAnimator(nextView, nextLayoutRect.top + mRowScrollUpAnimationOffset - nextView.getTop(), nextLayoutRect.top - nextView.getTop())); animators.add(createAlphaAnimator(nextView, 0.0f, 1.0f, mFastOutLinearIn)); } } else { nextPosition = findNextVisiblePosition(oldPosition); if (nextPosition != -1) { MenuRowView nextView = mMenuRowViews.get(nextPosition); animators.add(createTranslationYAnimator(nextView, 0, mRowScrollUpAnimationOffset)); animators.add(createAlphaAnimator(nextView, nextView.getTitleViewAlphaDeselected(), 0.0f, 1.0f, mLinearOutSlowIn)); } } // Other rows. int count = mMenuRowViews.size(); for (int i = 0; i < count; ++i) { MenuRowView view = mMenuRowViews.get(i); if (view.getVisibility() == View.VISIBLE && i != oldPosition && i != position && i != nextPosition) { Rect rect = layouts.get(i); animators.add(createTranslationYAnimator(view, 0, rect.top - view.getTop())); } } // Run animation. final List<ViewPropertyValueHolder> propertyValuesAfterAnimation = new ArrayList<>(); propertyValuesAfterAnimation.addAll(mPropertyValuesAfterAnimation); mAnimatorSet = new AnimatorSet(); mAnimatorSet.playTogether(animators); mAnimatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { if (DEBUG) dumpChildren("onRowAnimationEndBefore"); mAnimatorSet = null; // The property values which are different from the end values and need to be // changed after the animation are set here. // e.g. setting translationY to 0, alpha of the contents view to 1. for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) { holder.property.set(holder.view, holder.value); } oldTitleView.setVisibility(View.VISIBLE); mMenuRowViews.get(oldPosition).onDeselected(); mMenuRowViews.get(position).onSelected(true); mTempTitleViewForOld.setVisibility(View.GONE); mTempTitleViewForCurrent.setVisibility(View.GONE); layout(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), mMenuView.getBottom()); if (DEBUG) dumpChildren("onRowAnimationEndAfter"); MenuRow currentRow = mMenuRows.get(position); if (currentRow.hideTitleWhenSelected()) { View titleView = mMenuRowViews.get(position).getTitleView(); mTitleFadeOutAnimator = createAlphaAnimator(titleView, titleView.getAlpha(), 0.0f, mLinearOutSlowIn); mTitleFadeOutAnimator.setStartDelay(TITLE_SHOW_DURATION_BEFORE_HIDDEN_MS); mTitleFadeOutAnimator.addListener(new AnimatorListenerAdapter() { private boolean mCanceled; @Override public void onAnimationCancel(Animator animator) { mCanceled = true; } @Override public void onAnimationEnd(Animator animator) { mTitleFadeOutAnimator = null; if (!mCanceled) { mMenuRowViews.get(position).onSelected(false); } } }); mTitleFadeOutAnimator.start(); } } }); mAnimatorSet.start(); if (DEBUG) dumpChildren("startedRowAnimation()"); }
From source file:graphic.expand_graphic.ExpandingListView.java
/** * This method expands the view that was clicked and animates all the views * around it to make room for the expanding view. There are several steps * required to do this which are outlined below. * <p/>//from www . ja v a2 s. c om * 1. Store the current top and bottom bounds of each visible item in the * listview. 2. Update the layout parameters of the selected view. In the * context of this method, the view should be originally collapsed and set * to some custom height. The layout parameters are updated so as to wrap * the content of the additional text that is to be displayed. * <p/> * After invoking a layout to take place, the listview will order all the * items such that there is space for each view. This layout will be * independent of what the bounds of the items were prior to the layout so * two pre-draw passes will be made. This is necessary because after the * layout takes place, some views that were visible before the layout may * now be off bounds but a reference to these views is required so the * animation completes as intended. * <p/> * 3. The first predraw pass will set the bounds of all the visible items to * their original location before the layout took place and then force * another layout. Since the bounds of the cells cannot be set directly, the * method setSelectionFromTop can be used to achieve a very similar effect. * 4. The expanding view's bounds are animated to what the final values * should be from the original bounds. 5. The bounds above the expanding * view are animated upwards while the bounds below the expanding view are * animated downwards. 6. The extra text is faded in as its contents become * visible throughout the animation process. * <p/> * It is important to note that the listview is disabled during the * animation because the scrolling behaviour is unpredictable if the bounds * of the items within the listview are not constant during the scroll. */ private void expandView(final View view) { /* Store the original top and bottom bounds of all the cells. */ final int oldTop = view.getTop(); final int oldBottom = view.getBottom(); final HashMap<View, int[]> oldCoordinates = new HashMap<View, int[]>(); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); ViewCompat.setHasTransientState(v, true); oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() }); } /* Update the layout so the extra content becomes visible. */ final View expandingLayout = view.findViewById(R.id.expanding_layout); expandingLayout.setVisibility(View.VISIBLE); /* * Add an onPreDraw Listener to the listview. onPreDraw will get invoked * after onLayout and onMeasure have run but before anything has been * drawn. This means that the final post layout properties for all the * items have already been determined, but still have not been rendered * onto the screen. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { /* Determine if this is the first or second pass. */ if (!mShouldRemoveObserver) { mShouldRemoveObserver = true; /* * Calculate what the parameters should be for * setSelectionFromTop. The ListView must be offset in a * way, such that after the animation takes place, all the * cells that remain visible are rendered completely by the * ListView. */ int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int delta = newHeight - oldHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, delta, true); int currentTop = view.getTop(); int futureTop = oldTop - mTranslate[0]; int firstChildStartTop = getChildAt(0).getTop(); int firstVisiblePosition = getFirstVisiblePosition(); int deltaTop = currentTop - futureTop; int i; int childCount = getChildCount(); for (i = 0; i < childCount; i++) { View v = getChildAt(i); int height = v.getBottom() - Math.max(0, v.getTop()); if (deltaTop - height > 0) { firstVisiblePosition++; deltaTop -= height; } else { break; } } if (i > 0) { firstChildStartTop = 0; } setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop); /* * Request another layout to update the layout parameters of * the cells. */ requestLayout(); /* * Return false such that the ListView does not redraw its * contents on this layout but only updates all the * parameters associated with its children. */ return false; } /* * Remove the predraw listener so this method does not keep * getting called. */ mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; ArrayList<Animator> animations = new ArrayList<Animator>(); int index = indexOfChild(view); /* * Loop through all the views that were on the screen before the * cell was expanded. Some cells will still be children of the * ListView while others will not. The cells that remain * children of the ListView simply have their bounds animated * appropriately. The cells that are no longer children of the * ListView also have their bounds animated, but must also be * added to a list of views which will be drawn in dispatchDraw. */ for (View v : oldCoordinates.keySet()) { int[] old = oldCoordinates.get(v); v.setTop(old[0]); v.setBottom(old[1]); if (v.getParent() == null) { mViewsToDraw.add(v); int delta = old[0] < oldTop ? -yTranslateTop : yTranslateBottom; animations.add(getAnimation(v, delta, delta)); } else { int i = indexOfChild(v); if (v != view) { int delta = i > index ? yTranslateBottom : -yTranslateTop; animations.add(getAnimation(v, delta, delta)); } ViewCompat.setHasTransientState(v, false); } } /* Adds animation for expanding the cell that was clicked. */ animations.add(getAnimation(view, -yTranslateTop, yTranslateBottom)); /* Adds an animation for fading in the extra content. */ animations.add(ObjectAnimator.ofFloat(view.findViewById(R.id.expanding_layout), View.ALPHA, 0, 1)); /* Disabled the ListView for the duration of the animation. */ setEnabled(false); setClickable(false); /* * Play all the animations created above together at the same * time. */ AnimatorSet s = new AnimatorSet(); s.playTogether(animations); s.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { viewObject.setExpanded(true); setEnabled(true); setClickable(true); if (mViewsToDraw.size() > 0) { for (View v : mViewsToDraw) { ViewCompat.setHasTransientState(v, false); } } mViewsToDraw.clear(); } }); s.start(); return true; } }); }
From source file:com.android.tv.settings.dialog.DialogFragment.java
private Animator createDummyAnimator(final View v, ArrayList<Animator> animators) { final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(animators); return new UntargetableAnimatorSet(animatorSet); }