List of usage examples for android.view.animation DecelerateInterpolator DecelerateInterpolator
public DecelerateInterpolator()
From source file:com.dycody.android.idealnote.NavigationDrawerFragment.java
void animateBurger(int targetShape) { if (mDrawerToggle != null) { if (targetShape != BURGER && targetShape != ARROW) return; ValueAnimator anim = ValueAnimator.ofFloat((targetShape + 1) % 2, targetShape); anim.addUpdateListener(valueAnimator -> { float slideOffset = (Float) valueAnimator.getAnimatedValue(); mDrawerToggle.onDrawerSlide(mDrawerLayout, slideOffset); });//w ww.ja v a 2 s . c o m anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(500); anim.start(); } }
From source file:com.velli.passwordmanager.ActivityMain.java
public boolean lockDrawer(final boolean lock, boolean animate) { final DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); boolean locked = isDrawerLocked(); if (drawer != null && lock != locked) { if (lock) { drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } else {/* w w w . j ava 2 s . co m*/ drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); if (!animate) { initDrawer(); } } if (animate) { final ValueAnimator anim = ValueAnimator.ofFloat(lock ? 0 : 1, lock ? 1 : 0); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float slideOffset = (Float) valueAnimator.getAnimatedValue(); mToolbarDrawerToggle.onDrawerSlide(drawer, slideOffset); } }); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { anim.removeAllUpdateListeners(); if (!lock) { initDrawer(); } animation.removeAllListeners(); } }); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(500); anim.start(); } else { mToolbarDrawerToggle.onDrawerSlide(drawer, lock ? 1 : 0); } return true; } return false; }
From source file:cn.dev4mob.app.ui.animationsdemo.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically:/*w w w . j a v a2 s .c o m*/ * * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. */ private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image. final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). thumbView.getGlobalVisibleRect(startBounds); Timber.d("thumbview startBounds = %s", startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); Timber.d("thumbview finalBoundst = %s", finalBounds); Timber.d("thumbview globalOffset = %s", globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically startScale = (float) startBounds.width() / finalBounds.width(); Timber.d("startSCale = %f", startScale); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:com.example.kuassivi.material_avatar.feature.ChooseAvatarActivity.java
@Override public void onItemClick(View view, final ViewModel viewModel) { // Save the current image url, as our chosen avatar mAvatarUrl = viewModel.getImage();/*from w ww . j av a 2s . com*/ // Load the image, and then perform some cool animations on it Picasso.with(this).load(viewModel.getImage()).into(new TargetAdapter() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { updateSharedAvatarView(bitmap); /* * Scale down from a bigger image size * And flash it at its first shown */ long duration = getResources().getInteger(R.integer.bitmap_motion); ScalableBitmapAnimator bitmapAnimator = new ScalableBitmapAnimator( ScalableBitmapAnimator.SCALE_FROM); bitmapAnimator.setDuration(duration).setInterpolator(new DecelerateInterpolator()); mAvatarContainer.setImageBitmap(bitmap, true).setBitmapAnimators(bitmapAnimator) .startBitmapAnimation(); } }); // Once we have chosen at least one avatar, show the fab view to apply the selected choice showFabView(); }
From source file:com.example.imac.animationsdemo.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically://from www . ja v a 2 s .com * <p/> * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. */ private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image. final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). thumbView.getGlobalVisibleRect(startBounds); //? findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically startScale = (float) startBounds.width() / finalBounds.width(); float startHeight = startScale * finalBounds.height(); //?? float deltaHeight = (startHeight - startBounds.height()) / 2; //? ??? 2 ? startBounds.top -= deltaHeight; // startBounds.bottom += deltaHeight; // } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). Log.e("==startBounds===", startBounds.left + " " + startBounds.top); AnimatorSet set = new AnimatorSet(); Log.e("=====", startBounds.left + " " + startBounds.top + " " + thumbView.getLeft() + " " + thumbView.getTop()); set.play(ObjectAnimator.ofFloat(expandedImageView, "X", startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, "Y", startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); // expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); // expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:fr.julienvermet.bugdroid.ui.tablet.AbsBugsMultiPaneFragment.java
public void expandLeftPane(int speed) { int targetWidth = mMaxLeftWidth; ValueAnimator animator = ValueAnimator.ofObject(new WidthEvaluator(mLeftPane), mLeftPane.getWidth(), targetWidth);//from w ww . j a v a 2 s .com animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mIsLeftCollapsed = false; } }); animator.setInterpolator(new DecelerateInterpolator()); animator.setDuration(speed); animator.start(); }
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
private void init() { if (headerInterpolator == null) { headerInterpolator = new DecelerateInterpolator(); }/*from w ww. j a v a 2 s. c o m*/ if (footerInterpolator == null) { footerInterpolator = new DecelerateInterpolator(); } touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); if (headerView == null || footerView == null) { headerView = new DefaultSwipeView(getContext()); footerView = new DefaultSwipeView(getContext()); SwipeRefreshHelp.buildDrawerSwipeRefreshLayout(this); } addView(headerView); addView(footerView); headerView.setVisibility(INVISIBLE); footerView.setVisibility(INVISIBLE); setWillNotDraw(true); ViewCompat.setChildrenDrawingOrderEnabled(this, true); }
From source file:com.zzisoo.toylibrary.adapter.ToyListAdapter.java
@Override public void onBindViewHolder(ViewHolder viewHolder, final int position) { Log.e(TAG, "onBindViewHolder #" + position); // Get element from your dataset at this position and replace the contents of the view // with that element View v = viewHolder.getVh();//from w w w. ja v a2 s . com final ImageView ivToyImage = viewHolder.getIvToyImage(); final TextView textView = viewHolder.getTvTitle(); final FlipImageView flipImageView = viewHolder.getFlipImageView(); View.OnClickListener l = new View.OnClickListener() { @Override public void onClick(View v) { String strPid = mDataSet.get(position).getStrPid(); if (mPref.getStringArrayList(SharedPref.PREF_FAVORITE_LIST).contains(strPid)) { mPref.removeStringArrayListItem(SharedPref.PREF_FAVORITE_LIST, strPid); } else { mPref.addStringArrayListItem(SharedPref.PREF_FAVORITE_LIST, strPid); } flipImageView.toggleFlip(); } }; textView.setOnClickListener(l); flipImageView.setOnClickListener(l); viewHolder.getTvLoadingBackground().setBackgroundColor(getPastelRBG()); viewHolder.getTvLoading().setText("ToyToI"); if (-1 < position && position < mDataSet.size()) { setItemSize(v); mFavList = mPref.getStringArrayList(SharedPref.PREF_FAVORITE_LIST); if (mFavList.contains(mDataSet.get(position).getStrPid())) { flipImageView.setFlipped(true); } else { flipImageView.setFlipped(false); } final Toy toy = mDataSet.get(position); String bgImage = Config.HOST_SERVER_URL + toy.getImage().replace("..", ""); String strTitle = toy.getTitle(); textView.setText(strTitle);// ImageLoadingListener fadeImageLoadingListener = new ImageLoadingListener() { long ANIM_DURATION = 500; @Override public void onLoadingStarted(String s, View view) { view.clearAnimation(); ((ImageView) view).setImageResource(R.drawable.alpha_zero); } @Override public void onLoadingFailed(String s, View view, FailReason failReason) { Toast.makeText(view.getContext(), "Network Error : " + failReason.getType().toString(), Toast.LENGTH_LONG).show(); ((TextView) ((FrameLayout) view.getParent()).findViewById(R.id.tvLoading)).setText("Error"); Log.e(TAG, "onLoadingFailed :" + s); } @Override public void onLoadingComplete(String s, View view, Bitmap bitmap) { ((ImageView) view).setImageBitmap(bitmap); Animation fadeIn = new AlphaAnimation(0, 1); fadeIn.setInterpolator(new DecelerateInterpolator()); // add this fadeIn.setDuration(ANIM_DURATION); view.clearAnimation(); view.startAnimation(fadeIn); } @Override public void onLoadingCancelled(String s, View view) { if (view != null) { ((TextView) ((FrameLayout) view.getParent()).findViewById(R.id.tvLoading)).setText("Error"); Log.e(TAG, "onLoadingCancelled :" + s); } } }; App.getImageLoader(v.getContext()).displayImage(bgImage, ivToyImage, fadeImageLoadingListener); ivToyImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); asyncHttpClient.get(v.getContext(), Config.URL_DETAIL + mDataSet.get(position).getStrPid(), new AsyncHttpResponseHandler() { @Override public void onSuccess(int i, Header[] headers, byte[] bytes) { String responseStr = new String(bytes); Context context = v.getContext(); Bundle bundle = new Bundle(); Gson gson = new Gson(); Product[] products = gson.fromJson(responseStr, Product[].class); Intent intent = new Intent(context, FlexibleSpaceWithImageRecyclerViewActivity.class); intent.putExtra("Products", gson.toJson(products)); intent.putExtra("title", toy.getTitle()); intent.putExtra("image", toy.getImage()); intent.putExtra("favorite", mPref.getStringArrayList(SharedPref.PREF_FAVORITE_LIST) .contains(toy.getStrPid())); context.startActivity(intent); //changeFragment } private void changeFragment(Bundle bundle) { Fragment fragment = new ProductListViewFragment(); fragment.setArguments(bundle); FragmentTransaction transaction = ((FragmentActivity) v.getContext()) .getSupportFragmentManager().beginTransaction(); transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.popenter, R.anim.popexit); transaction.addToBackStack(getClass().getSimpleName()); transaction.replace(R.id.toyListViewWraper, fragment); transaction.commit(); } @Override public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { } }); Log.d(TAG, "Element " + position + " clicked."); mClickedPostion = position; // } }); } }
From source file:com.msn.support.gallery.ZoomActivity.java
/** * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" * image view and animating its bounds to fit the entire activity content area. More * specifically://from w w w . j a va2 s . c om * <ol> * <li>Assign the high-res image to the hidden "zoomed-in" (expanded) image view.</li> * <li>Calculate the starting and ending bounds for the expanded view.</li> * <li>Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) * simultaneously, from the starting bounds to the ending bounds.</li> * <li>Zoom back out by running the reverse animation on click.</li> * </ol> * ??ImageView? * Activity * <ol> * <li>???ImageView</li> * <li>?ImageView?</li> * <li>??ImageView?/?X, Y, SCALE_X, SCALE_Y * ??</li> * <li>???</li> * @param thumbView The thumbnail view to zoom in. * @param imageResId The high-resolution version of the image represented by the thumbnail. * */ @TargetApi(11) private void zoomImageFromThumb(final View thumbView, int imageResId) { // If there's an animation in progress, cancel it immediately and proceed with this one. // ? if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Load the high-resolution "zoomed-in" image.?ImageView final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. This step // involves lots of math. Yay, math. //?ImageView?? final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, and the // final bounds are the global visible rectangle of the container view. Also // set the container view's offset as the origin for the bounds, since that's // the origin for the positioning animation properties (X, Y). // ????? // ???? thumbView.getGlobalVisibleRect(startBounds); findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); Log.e("Test", "globalOffset.x=" + globalOffset.x + " globalOffset.y=" + globalOffset.y); Log.e("Test", "startBounds.top=" + startBounds.top + " startBounds.left=" + startBounds.left); startBounds.offset(-globalOffset.x, -globalOffset.y); Log.e("Test", "startBounds2.top=" + startBounds.top + " startBounds2.left=" + startBounds.left); finalBounds.offset(-globalOffset.x, -globalOffset.y); // Adjust the start bounds to be the same aspect ratio as the final bounds using the // "center crop" technique. This prevents undesirable stretching during the animation. // Also calculate the start scaling factor (the end scaling factor is always 1.0). // ??"center crop"??? // ????1.0 float startScale; if ((float) finalBounds.width() / finalBounds.height() > (float) startBounds.width() / startBounds.height()) { // Extend start bounds horizontally ? startScale = (float) startBounds.height() / finalBounds.height(); float startWidth = startScale * finalBounds.width(); float deltaWidth = (startWidth - startBounds.width()) / 2; startBounds.left -= deltaWidth; startBounds.right += deltaWidth; } else { // Extend start bounds vertically ? startScale = (float) startBounds.width() / finalBounds.width(); float startHeight = startScale * finalBounds.height(); float deltaHeight = (startHeight - startBounds.height()) / 2; startBounds.top -= deltaHeight; startBounds.bottom += deltaHeight; } // Hide the thumbnail and show the zoomed-in view. When the animation begins, // it will position the zoomed-in view in the place of the thumbnail. //thumbView.setAlpha(0f); expandedImageView.setVisibility(View.VISIBLE); // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of // the zoomed-in view (the default is the center of the view). expandedImageView.setPivotX(0f); expandedImageView.setPivotY(0f); // Construct and run the parallel animation of the four translation and scale properties // (X, Y, SCALE_X, and SCALE_Y). AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; // Upon clicking the zoomed-in image, it should zoom back down to the original bounds // and show the thumbnail instead of the expanded image. final float startScaleFinal = startScale; expandedImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } // Animate the four positioning/sizing properties in parallel, back to their // original values. AnimatorSet set = new AnimatorSet(); set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); set.setDuration(mShortAnimationDuration); set.setInterpolator(new DecelerateInterpolator()); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } @Override public void onAnimationCancel(Animator animation) { thumbView.setAlpha(1f); expandedImageView.setVisibility(View.GONE); mCurrentAnimator = null; } }); set.start(); mCurrentAnimator = set; } }); }
From source file:org.mozilla.focus.fragment.UrlInputFragment.java
/** * Play animation between home screen and the URL input. *///w w w . j av a 2s .co m private void playHomeScreenAnimation(final boolean reverse) { int[] screenLocation = new int[2]; urlInputContainerView.getLocationOnScreen(screenLocation); int leftDelta = getArguments().getInt(ARGUMENT_X) - screenLocation[0]; int topDelta = getArguments().getInt(ARGUMENT_Y) - screenLocation[1]; float widthScale = (float) getArguments().getInt(ARGUMENT_WIDTH) / urlInputContainerView.getWidth(); float heightScale = (float) getArguments().getInt(ARGUMENT_HEIGHT) / urlInputContainerView.getHeight(); if (!reverse) { // Move all views to the position of the fake URL bar on the home screen. Hide them until // the animation starts because we need to switch between fake URL bar and the actual URL // bar once the animation starts. urlInputContainerView.setAlpha(0); urlInputContainerView.setPivotX(0); urlInputContainerView.setPivotY(0); urlInputContainerView.setScaleX(widthScale); urlInputContainerView.setScaleY(heightScale); urlInputContainerView.setTranslationX(leftDelta); urlInputContainerView.setTranslationY(topDelta); urlInputContainerView.setAnimationOffset(1.0f); toolbarBackgroundView.setAlpha(0); dismissView.setAlpha(0); } // Move the URL bar from its position on the home screen to the actual position (and scale it). urlInputContainerView.animate().setDuration(ANIMATION_DURATION).scaleX(reverse ? widthScale : 1) .scaleY(reverse ? heightScale : 1).translationX(reverse ? leftDelta : 0) .translationY(reverse ? topDelta : 0).setInterpolator(new DecelerateInterpolator()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { ViewUtils.updateAlphaIfViewExists(getActivity(), R.id.fake_urlbar, 0f); urlInputContainerView.setAlpha(1); if (reverse) { urlView.setText(""); urlView.setCursorVisible(false); urlView.clearFocus(); } } @Override public void onAnimationEnd(Animator animation) { if (reverse) { urlInputContainerView.setAlpha(0f); ViewUtils.updateAlphaIfViewExists(getActivity(), R.id.fake_urlbar, 1f); dismiss(); } else { urlView.setCursorVisible(true); } } }); final ObjectAnimator hintAnimator = ObjectAnimator.ofFloat(urlInputContainerView, "animationOffset", reverse ? 0f : 1f, reverse ? 1f : 0f); hintAnimator.setDuration(ANIMATION_DURATION); hintAnimator.start(); // Let the toolbar background come int from the top toolbarBackgroundView.animate().alpha(reverse ? 0 : 1).setDuration(ANIMATION_DURATION) .setInterpolator(new DecelerateInterpolator()); // Use an alpha animation on the transparent black background dismissView.animate().alpha(reverse ? 0 : 1).setDuration(ANIMATION_DURATION); }