Example usage for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

List of usage examples for android.animation AnimatorListenerAdapter AnimatorListenerAdapter

Introduction

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

Prototype

AnimatorListenerAdapter

Source Link

Usage

From source file:com.doctoror.fuckoffmusicplayer.presentation.queue.QueueActivity.java

private void prepareViewsAndExit(@NonNull final Runnable exitAction) {
    if (!TransitionUtils.supportsActivityTransitions()
            || (fab.getScaleX() == 0f && albumArtDim.getAlpha() == 0f)) {
        exitAction.run();/* w  ww  . ja v a 2 s. c o  m*/
    } else {
        final boolean isLandscape = getResources()
                .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
        // Landscape Now Playing has a dim, so dim the ImageView and send it
        if (isLandscape) {
            albumArtDim.setAlpha(0f);
            albumArt.setColorFilter(ContextCompat.getColor(this, R.color.translucentBackground),
                    PorterDuff.Mode.SRC_ATOP);
        } else {
            // Portrait NowPlaying does not have a dim. Fade out the dim before animating.
            albumArtDim.animate().alpha(0f).setDuration(mShortAnimTime).start();
        }
        fab.animate().scaleX(0f).scaleY(0f).setDuration(mShortAnimTime)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(final Animator animation) {
                        exitAction.run();
                    }
                }).start();
    }
}

From source file:android.support.transition.Visibility.java

/**
 * The default implementation of this method does nothing. Subclasses
 * should override if they need to create an Animator when targets disappear.
 * The method should only be called by the Visibility class; it is
 * not intended to be called from external classes.
 *
 * @param sceneRoot       The root of the transition hierarchy
 * @param startValues     The target values in the start scene
 * @param startVisibility The target visibility in the start scene
 * @param endValues       The target values in the end scene
 * @param endVisibility   The target visibility in the end scene
 * @return An Animator to be started at the appropriate time in the
 * overall transition for this scene change. A null value means no animation
 * should be run./*from www .  ja  va2  s .co m*/
 */
@SuppressWarnings("UnusedParameters")
public Animator onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility,
        TransitionValues endValues, int endVisibility) {
    if ((mMode & MODE_OUT) != MODE_OUT) {
        return null;
    }

    View startView = (startValues != null) ? startValues.view : null;
    View endView = (endValues != null) ? endValues.view : null;
    View overlayView = null;
    View viewToKeep = null;
    if (endView == null || endView.getParent() == null) {
        if (endView != null) {
            // endView was removed from its parent - add it to the overlay
            overlayView = endView;
        } else if (startView != null) {
            // endView does not exist. Use startView only under certain
            // conditions, because placing a view in an overlay necessitates
            // it being removed from its current parent
            if (startView.getParent() == null) {
                // no parent - safe to use
                overlayView = startView;
            } else if (startView.getParent() instanceof View) {
                View startParent = (View) startView.getParent();
                TransitionValues startParentValues = getTransitionValues(startParent, true);
                TransitionValues endParentValues = getMatchedTransitionValues(startParent, true);
                VisibilityInfo parentVisibilityInfo = getVisibilityChangeInfo(startParentValues,
                        endParentValues);
                if (!parentVisibilityInfo.mVisibilityChange) {
                    overlayView = TransitionUtils.copyViewImage(sceneRoot, startView, startParent);
                } else if (startParent.getParent() == null) {
                    int id = startParent.getId();
                    if (id != View.NO_ID && sceneRoot.findViewById(id) != null && mCanRemoveViews) {
                        // no parent, but its parent is unparented  but the parent
                        // hierarchy has been replaced by a new hierarchy with the same id
                        // and it is safe to un-parent startView
                        overlayView = startView;
                    }
                }
            }
        }
    } else {
        // visibility change
        if (endVisibility == View.INVISIBLE) {
            viewToKeep = endView;
        } else {
            // Becoming GONE
            if (startView == endView) {
                viewToKeep = endView;
            } else {
                overlayView = startView;
            }
        }
    }
    final int finalVisibility = endVisibility;

    if (overlayView != null && startValues != null) {
        // TODO: Need to do this for general case of adding to overlay
        int[] screenLoc = (int[]) startValues.values.get(PROPNAME_SCREEN_LOCATION);
        int screenX = screenLoc[0];
        int screenY = screenLoc[1];
        int[] loc = new int[2];
        sceneRoot.getLocationOnScreen(loc);
        overlayView.offsetLeftAndRight((screenX - loc[0]) - overlayView.getLeft());
        overlayView.offsetTopAndBottom((screenY - loc[1]) - overlayView.getTop());
        final ViewGroupOverlayImpl overlay = ViewGroupUtils.getOverlay(sceneRoot);
        overlay.add(overlayView);
        Animator animator = onDisappear(sceneRoot, overlayView, startValues, endValues);
        if (animator == null) {
            overlay.remove(overlayView);
        } else {
            final View finalOverlayView = overlayView;
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    overlay.remove(finalOverlayView);
                }
            });
        }
        return animator;
    }

    if (viewToKeep != null) {
        int originalVisibility = viewToKeep.getVisibility();
        ViewUtils.setTransitionVisibility(viewToKeep, View.VISIBLE);
        Animator animator = onDisappear(sceneRoot, viewToKeep, startValues, endValues);
        if (animator != null) {
            DisappearListener disappearListener = new DisappearListener(viewToKeep, finalVisibility, true);
            animator.addListener(disappearListener);
            AnimatorUtils.addPauseListener(animator, disappearListener);
            addListener(disappearListener);
        } else {
            ViewUtils.setTransitionVisibility(viewToKeep, originalVisibility);
        }
        return animator;
    }
    return null;
}

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

@Override
public void onResume() {
    Intent newIntent = null;//from  ww w.  j  a  va2 s  . c  om

    if (getActivity() instanceof DeskClock) {
        DeskClock activity = (DeskClock) getActivity();
        activity.registerPageChangedListener(this);
        newIntent = activity.getIntent();
    }
    super.onResume();
    mPrefs.registerOnSharedPreferenceChangeListener(this);

    mAdapter = createAdapter(getActivity());
    mAdapter.onRestoreInstanceState(null);

    LayoutParams params;
    float dividerHeight = getResources().getDimension(R.dimen.timer_divider_height);
    if (getActivity() instanceof DeskClock) {
        // If this is a DeskClock fragment (i.e. not a FullScreenTimerAlert), add a footer to
        // the bottom of the list so that it can scroll underneath the bottom button bar.
        // StaggeredGridView doesn't support a footer view, but GridAdapter does, so this
        // can't happen until the Adapter itself is instantiated.
        View footerView = getActivity().getLayoutInflater().inflate(R.layout.blank_footer_view, mTimersList,
                false);
        params = footerView.getLayoutParams();
        params.height -= dividerHeight;
        footerView.setLayoutParams(params);
        mAdapter.setFooterView(footerView);
    }

    if (mPrefs.getBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, false)) {
        // Clear the flag indicating the adapter is out of sync with the database.
        mPrefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, false).apply();
    }

    mTimersList.setAdapter(mAdapter);
    setTimerListPosition(mAdapter.getCount());

    mLastVisibleView = null; // Force a non animation setting of the view
    setPage();
    // View was hidden in onPause, make sure it is visible now.
    View v = getView();
    if (v != null) {
        getView().setVisibility(View.VISIBLE);
    }

    if (newIntent != null) {
        processIntent(newIntent);
    }

    mFab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            final Animator revealAnimator = getRevealAnimator(mFab, Color.WHITE);
            revealAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    updateAllTimesUpTimers();
                }
            });
            revealAnimator.start();
        }
    });
}

From source file:com.phonemetra.deskclock.timer.TimerFragment.java

@Override
public void onFabClick(View view) {
    if (mLastView != mTimerView) {
        // Timer is at Setup View, so fab is "play", rotate from setup view to timer view
        final AnimatorListenerAdapter adapter = new AnimatorListenerAdapter() {
            @Override// w  w w  .  j  a va  2 s.co  m
            public void onAnimationStart(Animator animation) {
                final int timerLength = mSetupView.getTime();
                final TimerObj timerObj = new TimerObj(timerLength * DateUtils.SECOND_IN_MILLIS);
                timerObj.mState = TimerObj.STATE_RUNNING;
                updateTimerState(timerObj, Timers.START_TIMER);

                // Go to the newly created timer view
                mAdapter.addTimer(timerObj);
                mViewPager.setCurrentItem(0);
                highlightPageIndicator(0);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mSetupView.reset(); // Make sure the setup is cleared for next time
                mSetupView.setScaleX(1.0f); // Reset the scale for setup view
                goToPagerView();
            }
        };
        createRotateAnimator(adapter, false).start();
    } else {
        // Timer is at view pager, so fab is "play" or "pause" or "square that means reset"
        final TimerObj t = getCurrentTimer();
        switch (t.mState) {
        case TimerObj.STATE_RUNNING:
            // Stop timer and save the remaining time of the timer
            t.mState = TimerObj.STATE_STOPPED;
            t.mView.pause();
            t.updateTimeLeft(true);
            updateTimerState(t, Timers.TIMER_STOP);
            break;
        case TimerObj.STATE_STOPPED:
        case TimerObj.STATE_RESTART:
            // Reset the remaining time and continue timer
            t.mState = TimerObj.STATE_RUNNING;
            t.mStartTime = Utils.getTimeNow() - (t.mOriginalLength - t.mTimeLeft);
            t.mView.start();
            updateTimerState(t, Timers.START_TIMER);
            break;
        case TimerObj.STATE_TIMESUP:
            if (t.mDeleteAfterUse) {
                cancelTimerNotification(t.mTimerId);
                // Tell receiver the timer was deleted.
                // It will stop all activity related to the
                // timer
                t.mState = TimerObj.STATE_DELETED;
                updateTimerState(t, Timers.DELETE_TIMER);
            } else {
                t.mState = TimerObj.STATE_RESTART;
                t.mOriginalLength = t.mSetupLength;
                t.mTimeLeft = t.mSetupLength;
                t.mView.stop();
                t.mView.setTime(t.mTimeLeft, false);
                t.mView.set(t.mOriginalLength, t.mTimeLeft, false);
                updateTimerState(t, Timers.TIMER_RESET);
                cancelTimerNotification(t.mTimerId);
            }
            break;
        }
        setTimerViewFabIcon(t);
    }
}

From source file:com.jinzht.pro.swipelistview.SwipeListViewTouchListener.java

/**
 * Create dismiss animation/*from  www.ja va 2  s.c  o m*/
 *
 * @param view      affected view
 * @param swap      If will change state. If is "false" returns to the original position
 * @param swapRight If swap is true, this parameter tells if move is to the right or left
 * @param position  Position of list
 */
private void generateDismissAnimate(final View view, final boolean swap, final boolean swapRight,
        final int position) {
    int moveTo = 0;
    if (opened.get(position)) {
        if (!swap) {
            moveTo = openedRight.get(position) ? (int) (viewWidth - rightOffset)
                    : (int) (-viewWidth + leftOffset);
        }
    } else {
        if (swap) {
            moveTo = swapRight ? (int) (viewWidth - rightOffset) : (int) (-viewWidth + leftOffset);
        }
    }

    int alpha = 1;
    if (swap) {
        ++dismissAnimationRefCount;
        alpha = 0;
    }

    view.animate().translationX(moveTo).alpha(alpha).setDuration(animationTime)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (swap) {
                        closeOpenedItems();
                        performDismiss(view, position, true);
                    }
                    resetCell();
                }
            });

}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();/*w ww.  j av a2  s  .c  o  m*/
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        inAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.itsronald.widget.ViewPagerIndicator.java

@Nullable
private Animator pageChangeAnimator(final int lastPageIndex, final int newPageIndex) {
    final IndicatorDotPathView dotPath = getDotPathForPageChange(lastPageIndex, newPageIndex);
    final IndicatorDotView lastDot = getDotForPage(lastPageIndex);

    if (dotPath == null || lastDot == null) {
        final String warning = dotPath == null ? "dotPath is null!" : "lastDot is null!";
        Log.w(TAG, warning);/* ww w .j  a v a 2  s  .com*/
        return null;
    }

    final Animator connectPathAnimator = dotPath.connectPathAnimator();
    connectPathAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            dotPath.setVisibility(VISIBLE);
            lastDot.setVisibility(INVISIBLE);
        }
    });

    final long dotSlideDuration = DOT_SLIDE_ANIM_DURATION;
    final Animator selectedDotSlideAnimator = selectedDotSlideAnimator(newPageIndex, dotSlideDuration, 0);

    final int pathDirection = getPathDirectionForPageChange(lastPageIndex, newPageIndex);
    final Animator retreatPathAnimator = dotPath.retreatConnectedPathAnimator(pathDirection);

    final Animator dotRevealAnimator = lastDot.revealAnimator();
    dotRevealAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            dotPath.setVisibility(INVISIBLE);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(connectPathAnimator).before(selectedDotSlideAnimator);
    animatorSet.play(retreatPathAnimator).after(selectedDotSlideAnimator);
    animatorSet.play(dotRevealAnimator).with(retreatPathAnimator);

    return animatorSet;
}

From source file:com.sinyuk.jianyimaterial.widgets.FloatingToolbar.java

@TargetApi(21)
private void showLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float endFabX;
    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        endFabX = rootWidth / 2f + (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 0.98f;
    } else {// www  .j ava 2s .c  o  m
        endFabX = rootWidth / 2f - (mFabOriginalX - rootWidth / 2f) / 4f;
        controlX = mFabOriginalX * 1.02f;
    }

    /**
     * Animate FAB movement
     */
    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, endFabX, getY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Fade FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration((long) (FAB_MORPH_DURATION / 3f));
        anim.start();
    }

    /**
     * Animate FAB elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, dpToPixels(2));
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_MORPH_DURATION);
    anim.start();

    /**
     * Create circular reveal
     */
    Animator toolbarReveal = ViewAnimationUtils.createCircularReveal(this, getWidth() / 2, getHeight() / 2,
            (float) mFab.getWidth() / 2f, (float) (Math.hypot(getWidth() / 2, getHeight() / 2)));

    toolbarReveal.setDuration(CIRCULAR_REVEAL_DURATION);
    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mFab.setVisibility(View.INVISIBLE);
            setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mMorphing = false;
        }
    });

    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_REVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar elevation to 8dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, dpToPixels(2));
    anim.setDuration(CIRCULAR_REVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_REVEAL_DELAY);
    anim.start();
}

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

@OnClick(R.id.results_scrim)
  protected void hideSaveConfimation() {
      if (confirmSaveContainer.getVisibility() == View.VISIBLE) {
          // contract the bubble & hide the scrim
          AnimatorSet hideConfirmation = new AnimatorSet();
          hideConfirmation.playTogether(
                  ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                          confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                          confirmSaveContainer.getWidth() / 2, fab.getWidth() / 2),
                  ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR, Color.TRANSPARENT));
          hideConfirmation.setDuration(150L);
          hideConfirmation.setInterpolator(
                  AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
          hideConfirmation.addListener(new AnimatorListenerAdapter() {
              @Override// w  w  w.j a  v  a 2  s  . co  m
              public void onAnimationEnd(Animator animation) {
                  confirmSaveContainer.setVisibility(View.GONE);
                  resultsScrim.setVisibility(View.GONE);
                  fab.setVisibility(results.getVisibility());
              }
          });
          hideConfirmation.start();
      }
  }

From source file:cc.flydev.launcher.Folder.java

public void animateClosed() {
    if (!(getParent() instanceof DragLayer))
        return;/*from   w w w.  j a va  2s .c  o  m*/
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
    final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            onCloseComplete();
            setLayerType(LAYER_TYPE_NONE, null);
            mState = STATE_SMALL;
        }

        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    getContext().getString(R.string.folder_closed));
            mState = STATE_ANIMATING;
        }
    });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    oa.start();
}