Example usage for android.animation AnimatorSet AnimatorSet

List of usage examples for android.animation AnimatorSet AnimatorSet

Introduction

In this page you can find the example usage for android.animation AnimatorSet AnimatorSet.

Prototype

public AnimatorSet() 

Source Link

Usage

From source file:com.google.samples.apps.ourstreets.fragment.GalleryFragment.java

/**
 * Perform the animation from loading progress to the actual fragment's content.
 */// w w w  .jav  a 2s  .c o m
private void animateProgressToContent() {
    AnimatorSet animatorSet = new AnimatorSet();
    FrameLayout targetView = ((FrameLayout) getView());
    //noinspection ConstantConditions
    animatorSet.play(createCircularReveal(targetView)).with(createColorChange(targetView));
    animatorSet.start();
}

From source file:com.hannesdorfmann.search.SearchActivity.java

@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_search);
      setRetainInstance(true);//from ww  w.  j a v  a2s  . c o m

      ButterKnife.bind(this);
      setupSearchView();

      auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);
      adapter = new FeedAdapter(this, columns, PocketUtils.isPocketInstalled(this));

      results.setAdapter(adapter);
      GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
      layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
              return adapter.getItemColumnSpan(position);
          }
      });
      results.setLayoutManager(layoutManager);
      results.addOnScrollListener(new InfiniteScrollListener(layoutManager) {
          @Override
          public void onLoadMore() {
              if (!adapter.isLoadingMore()) {
                  presenter.searchMore(searchView.getQuery().toString());
              }
          }
      });
      results.setHasFixedSize(true);
      results.addOnScrollListener(gridScroll);

      // extract the search icon's location passed from the launching activity, minus 4dp to
      // compensate for different paddings in the views
      searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
              .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
      searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

      // translate icon to match the launching screen then animate back into position
      searchBackContainer.setTranslationX(searchBackDistanceX);
      searchBackContainer.animate().translationX(0f).setDuration(650L)
              .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
      // transform from search icon to back icon
      AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
              R.drawable.avd_search_to_back);
      searchBack.setImageDrawable(searchToBack);
      searchToBack.start();
      // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
      // the animation set a static drawable. Also animation callbacks weren't added until API23
      // so using post delayed :(
      // TODO fix properly!!
      searchBack.postDelayed(new Runnable() {
          @Override
          public void run() {
              searchBack.setImageDrawable(
                      ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
          }
      }, 600);

      // fade in the other search chrome
      searchBackground.animate().alpha(1f).setDuration(300L)
              .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
      searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
              .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
              .setListener(new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                      searchView.requestFocus();
                      ImeUtils.showIme(searchView);
                  }
              });

      // animate in a scrim over the content behind
      scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
          @Override
          public boolean onPreDraw() {
              scrim.getViewTreeObserver().removeOnPreDrawListener(this);
              AnimatorSet showScrim = new AnimatorSet();
              showScrim.playTogether(
                      ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                              searchBackground.getBottom(), 0,
                              (float) Math.hypot(searchBackDistanceX,
                                      scrim.getHeight() - searchBackground.getBottom())),
                      ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                              ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
              showScrim.setDuration(400L);
              showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                      android.R.interpolator.linear_out_slow_in));
              showScrim.start();
              return false;
          }
      });
      onNewIntent(getIntent());
  }

From source file:com.ibm.mil.readyapps.physio.fragments.LandingFragment.java

private void animateMetricsIn(boolean isInitial) {
    int delay = 0;
    if (isInitial) {
        delay = INIT_DELAY;/*from w w  w.ja va  2s  . c o m*/
    }

    ObjectAnimator heartRateSlideInAnimator = ObjectAnimator.ofFloat(heartRateTab, "translationX", 1f);
    ObjectAnimator weightSlideInAnimator = ObjectAnimator.ofFloat(weightTab, "translationX", 1f);
    ObjectAnimator stepsSlideInAnimator = ObjectAnimator.ofFloat(stepsTab, "translationX", 1f);

    heartRateSlideInAnimator.setDuration(ANIM_SPEED * 2);
    heartRateSlideInAnimator.setStartDelay(delay);

    weightSlideInAnimator.setDuration(ANIM_SPEED * 2);
    weightSlideInAnimator.setStartDelay(delay + (ANIM_SPEED * 2));

    stepsSlideInAnimator.setDuration(ANIM_SPEED * 2);
    stepsSlideInAnimator.setStartDelay(delay + ANIM_SPEED);

    AnimatorSet slideIn = new AnimatorSet();
    slideIn.play(heartRateSlideInAnimator).with(stepsSlideInAnimator).with(weightSlideInAnimator);
    slideIn.start();
}

From source file:com.ayuget.redface.ui.activity.BaseDrawerActivity.java

private void setupAccountBoxToggle() {
    expandAccountBoxIndicator.setImageResource(
            accountBoxExpanded ? R.drawable.ic_action_arrow_drop_up : R.drawable.ic_arrow_drop_down_white_24dp);

    int hideTranslateY = -accountListContainer.getHeight() / 4; // last 25% of animation
    if (accountBoxExpanded && accountListContainer.getTranslationY() == 0) {
        // initial setup
        accountListContainer.setAlpha(0);
        accountListContainer.setTranslationY(hideTranslateY);
    }//w  ww .  j a  va 2s .c o m

    AnimatorSet set = new AnimatorSet();
    set.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            drawerItemsListContainer.setVisibility(accountBoxExpanded ? View.INVISIBLE : View.VISIBLE);
            accountListContainer.setVisibility(accountBoxExpanded ? View.VISIBLE : View.INVISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            onAnimationEnd(animation);
        }
    });

    if (accountBoxExpanded) {
        accountListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(accountListContainer, View.ALPHA, 1)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(accountListContainer, View.TRANSLATION_Y, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(ObjectAnimator.ofFloat(drawerItemsListContainer, View.ALPHA, 0)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet);
        set.start();
    } else {
        drawerItemsListContainer.setVisibility(View.VISIBLE);
        AnimatorSet subSet = new AnimatorSet();
        subSet.playTogether(
                ObjectAnimator.ofFloat(accountListContainer, View.ALPHA, 0)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION),
                ObjectAnimator.ofFloat(accountListContainer, View.TRANSLATION_Y, hideTranslateY)
                        .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.playSequentially(subSet, ObjectAnimator.ofFloat(drawerItemsListContainer, View.ALPHA, 1)
                .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION));
        set.start();
    }

    set.start();
}

From source file:eu.davidea.flexibleadapter.FlexibleAnimatorAdapter.java

/**
 * Animates the view based on the custom animator list built with {@link #getAnimators(View, int, boolean)}.
 *///w  w w . j a va2 s.c  o  m
public final void animateView(final View itemView, int position, boolean isSelected) {
    //FIXME: first completed visible item on rotation gets high delay

    //      if (DEBUG)
    //         Log.v(TAG, "shouldAnimate=" + shouldAnimate
    //               + " isFastScroll=" + isFastScroll
    //               + " isNotified=" + mAnimatorNotifierObserver.isPositionNotified()
    //               + " isReverseEnabled=" + isReverseEnabled
    //               + (!isReverseEnabled ? " Pos>AniPos=" + (position > mLastAnimatedPosition) : "")
    //         );

    if (shouldAnimate && !isFastScroll && !mAnimatorNotifierObserver.isPositionNotified()
            && (isReverseEnabled || (!isReverseEnabled && position > mLastAnimatedPosition))) {

        //Cancel animation is necessary when fling
        cancelExistingAnimation(itemView);

        //Retrieve user animators
        List<Animator> animators = getAnimators(itemView, position, isSelected);

        //Add Alpha animator if not yet
        ViewCompat.setAlpha(itemView, 0);
        if (!animatorsUsed.contains(AnimatorEnum.ALPHA))
            addAlphaAnimator(animators, itemView, 0f);
        //Clear animators since the new item might have different animations
        animatorsUsed.clear();

        //Execute the animations all together
        AnimatorSet set = new AnimatorSet();
        set.playTogether(animators);
        //TODO: Animate with Solution 1 or 2?
        //set.setStartDelay(calculateAnimationDelay1(position));
        set.setStartDelay(calculateAnimationDelay2(position));
        set.setInterpolator(mInterpolator);
        set.setDuration(mDuration);
        set.addListener(new HelperAnimatorListener(itemView.hashCode()));
        set.start();
        if (DEBUG)
            Log.v(TAG, "Started Animation on position " + position + " animatorsUsed=" + animatorsUsed);
        mAnimators.put(itemView.hashCode(), set);
    }

    if (mAnimatorNotifierObserver.isPositionNotified())
        mAnimatorNotifierObserver.clearNotified();

    mLastAnimatedPosition = position;
}

From source file:com.example.google.maps.flyover.MainActivity.java

public void animateRoute() {
    LinkedList<Animator> animators = new LinkedList<Animator>();

    // For each segment of the route, create one heading adjustment animator
    // and one segment fly-over animator.
    for (int i = 0; i < ROUTE.length - 1; i++) {
        // If it the first segment, ensure the camera is rotated properly.
        float h1;
        if (i == 0) {
            h1 = mMap.getCameraPosition().bearing;
        } else {/*w ww.java  2s.c  o m*/
            h1 = (float) SphericalUtil.computeHeading(ROUTE[i - 1], ROUTE[i]);
        }

        float h2 = (float) SphericalUtil.computeHeading(ROUTE[i], ROUTE[i + 1]);

        ValueAnimator va = ValueAnimator.ofFloat(h1, h2);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float bearing = (Float) animation.getAnimatedValue();
                CameraPosition pos = CameraPosition.builder(mMap.getCameraPosition()).bearing(bearing).build();
                mMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
            }
        });

        // Use the change in degrees of the heading for the animation
        // duration.
        long d = Math.round(Math.abs(h1 - h2));
        va.setDuration(d * CAMERA_HEADING_CHANGE_RATE);
        animators.add(va);

        ObjectAnimator oa = ObjectAnimator.ofObject(mMarker, "position",
                new LatLngEvaluator(ROUTE[i], ROUTE[i + 1]), ROUTE[i], ROUTE[i + 1]);

        oa.setInterpolator(new LinearInterpolator());
        oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                LatLng target = (LatLng) animation.getAnimatedValue();
                mMap.moveCamera(CameraUpdateFactory.newLatLng(target));
            }
        });

        // Use the distance of the route segment for the duration.
        double dist = SphericalUtil.computeDistanceBetween(ROUTE[i], ROUTE[i + 1]);
        oa.setDuration(Math.round(dist) * 10);

        animators.add(oa);
    }

    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playSequentially(animators);
    mAnimatorSet.start();

    mAnimatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_stop);
        }
    });
}

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 ww 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:io.plaidapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();/*from  w ww .ja  v  a 2s  . c  om*/
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L)
                            .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                                    android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600L);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}

From source file:io.plaidapp.ui.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);
    ButterKnife.bind(this);
    setupSearchView();//from   w  ww  .  j  a v a  2  s.c  om
    auto = TransitionInflater.from(this).inflateTransition(R.transition.auto);

    dataManager = new SearchDataManager(this) {
        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            if (data != null && data.size() > 0) {
                if (results.getVisibility() != View.VISIBLE) {
                    TransitionManager.beginDelayedTransition(container, auto);
                    progress.setVisibility(View.GONE);
                    results.setVisibility(View.VISIBLE);
                    fab.setVisibility(View.VISIBLE);
                    fab.setAlpha(0.6f);
                    fab.setScaleX(0f);
                    fab.setScaleY(0f);
                    fab.animate().alpha(1f).scaleX(1f).scaleY(1f).setStartDelay(800L).setDuration(300L)
                            .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                                    android.R.interpolator.linear_out_slow_in));
                }
                adapter.addAndResort(data);
            } else {
                TransitionManager.beginDelayedTransition(container, auto);
                progress.setVisibility(View.GONE);
                setNoResultsVisibility(View.VISIBLE);
            }
        }
    };
    adapter = new FeedAdapter(this, dataManager, PocketUtils.isPocketInstalled(this));
    results.setAdapter(adapter);
    GridLayoutManager layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            return position == adapter.getDataItemCount() ? columns : 1;
        }
    });
    results.setLayoutManager(layoutManager);
    results.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
        @Override
        public void onLoadMore() {
            dataManager.loadMore();
        }
    });
    results.setHasFixedSize(true);
    results.addOnScrollListener(gridScroll);

    // extract the search icon's location passed from the launching activity, minus 4dp to
    // compensate for different paddings in the views
    searchBackDistanceX = getIntent().getIntExtra(EXTRA_MENU_LEFT, 0) - (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, getResources().getDisplayMetrics());
    searchIconCenterX = getIntent().getIntExtra(EXTRA_MENU_CENTER_X, 0);

    // translate icon to match the launching screen then animate back into position
    searchBackContainer.setTranslationX(searchBackDistanceX);
    searchBackContainer.animate().translationX(0f).setDuration(650L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in));
    // transform from search icon to back icon
    AnimatedVectorDrawable searchToBack = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_search_to_back);
    searchBack.setImageDrawable(searchToBack);
    searchToBack.start();
    // for some reason the animation doesn't always finish (leaving a part arrow!?) so after
    // the animation set a static drawable. Also animation callbacks weren't added until API23
    // so using post delayed :(
    // TODO fix properly!!
    searchBack.postDelayed(new Runnable() {
        @Override
        public void run() {
            searchBack.setImageDrawable(
                    ContextCompat.getDrawable(SearchActivity.this, R.drawable.ic_arrow_back_padded));
        }
    }, 600);

    // fade in the other search chrome
    searchBackground.animate().alpha(1f).setDuration(300L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    searchView.animate().alpha(1f).setStartDelay(400L).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });

    // animate in a scrim over the content behind
    scrim.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            scrim.getViewTreeObserver().removeOnPreDrawListener(this);
            AnimatorSet showScrim = new AnimatorSet();
            showScrim.playTogether(
                    ViewAnimationUtils.createCircularReveal(scrim, searchIconCenterX,
                            searchBackground.getBottom(), 0,
                            (float) Math.hypot(searchBackDistanceX,
                                    scrim.getHeight() - searchBackground.getBottom())),
                    ObjectAnimator.ofArgb(scrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT,
                            ContextCompat.getColor(SearchActivity.this, R.color.scrim)));
            showScrim.setDuration(400L);
            showScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                    android.R.interpolator.linear_out_slow_in));
            showScrim.start();
            return false;
        }
    });
    onNewIntent(getIntent());
}

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDesignerNewsStory(final Story story, final DesignerNewsStoryHolder holder) {
    holder.title.setText(story.title);/*w w w .  ja v a  2s . c  om*/
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CustomTabActivityHelper.openCustomTab(host,
                    DesignerNewsStory.getCustomTabIntent(host, story, null).build(), Uri.parse(story.url));
        }
    });
    holder.comments.setText(String.valueOf(story.comment_count));
    holder.comments.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View commentsView) {
            final Intent intent = new Intent();
            intent.setClass(host, DesignerNewsStory.class);
            intent.putExtra(DesignerNewsStory.EXTRA_STORY, story);
            final ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_title_background)),
                    Pair.create(holder.itemView, host.getString(R.string.transition_story_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
    if (pocketIsInstalled) {
        holder.pocket.setImageAlpha(178); // grumble... no xml setter, grumble...
        holder.pocket.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                final ImageButton pocketButton = (ImageButton) view;
                // actually add to pocket
                PocketUtils.addToPocket(host, story.url);

                // setup for anim
                holder.itemView.setHasTransientState(true);
                ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(false);
                final int initialLeft = pocketButton.getLeft();
                final int initialTop = pocketButton.getTop();
                final int translatedLeft = (holder.itemView.getWidth() - pocketButton.getWidth()) / 2;
                final int translatedTop = initialTop
                        - ((holder.itemView.getHeight() - pocketButton.getHeight()) / 2);
                final ArcMotion arc = new ArcMotion();

                // animate the title & pocket icon up, scale the pocket icon up
                PropertyValuesHolder pvhTitleUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y,
                        -(holder.itemView.getHeight() / 5));
                PropertyValuesHolder pvhTitleFade = PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f);
                Animator titleMoveFadeOut = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleUp,
                        pvhTitleFade);

                Animator pocketMoveUp = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X,
                        View.TRANSLATION_Y,
                        arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop));
                PropertyValuesHolder pvhPocketScaleUpX = PropertyValuesHolder.ofFloat(View.SCALE_X, 3f);
                PropertyValuesHolder pvhPocketScaleUpY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f);
                Animator pocketScaleUp = ObjectAnimator.ofPropertyValuesHolder(pocketButton, pvhPocketScaleUpX,
                        pvhPocketScaleUpY);
                ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 255);

                AnimatorSet up = new AnimatorSet();
                up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp);
                up.setDuration(300);
                up.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));

                // animate everything back into place
                PropertyValuesHolder pvhTitleMoveUp = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f);
                PropertyValuesHolder pvhTitleFadeUp = PropertyValuesHolder.ofFloat(View.ALPHA, 1f);
                Animator titleMoveFadeIn = ObjectAnimator.ofPropertyValuesHolder(holder.title, pvhTitleMoveUp,
                        pvhTitleFadeUp);
                Animator pocketMoveDown = ObjectAnimator.ofFloat(pocketButton, View.TRANSLATION_X,
                        View.TRANSLATION_Y, arc.getPath(translatedLeft, translatedTop, 0, 0));
                PropertyValuesHolder pvhPocketScaleDownX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1f);
                PropertyValuesHolder pvhPocketScaleDownY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f);
                Animator pvhPocketScaleDown = ObjectAnimator.ofPropertyValuesHolder(pocketButton,
                        pvhPocketScaleDownX, pvhPocketScaleDownY);
                ObjectAnimator pocketFadeDown = ObjectAnimator.ofInt(pocketButton, ViewUtils.IMAGE_ALPHA, 138);

                AnimatorSet down = new AnimatorSet();
                down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown);
                down.setDuration(300);
                down.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                down.setStartDelay(500);

                // play it
                AnimatorSet upDown = new AnimatorSet();
                upDown.playSequentially(up, down);

                // clean up
                upDown.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        ((ViewGroup) pocketButton.getParent().getParent()).setClipChildren(true);
                        holder.itemView.setHasTransientState(false);
                    }
                });
                upDown.start();
            }
        });
    }
}