Java Examples for android.animation.AnimatorListenerAdapter

The following java examples will help you to understand the usage of android.animation.AnimatorListenerAdapter. These source code samples are taken from different open source projects.

Example 1
Project: Mortar-architect-master  File: NavigatorView.java View source code
private void markReady() {
    readyCount++;
    Preconditions.checkArgument(readyCount <= presentations.size(), "Ready count cannot exceed presentations size");
    if (readyCount == presentations.size()) {
        if (!animators.isEmpty()) {
            AnimatorSet set = new AnimatorSet();
            set.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    end(callback);
                }
            });
            set.playTogether(animators);
            set.start();
        } else {
            end(callback);
        }
    }
}
Example 2
Project: MHacksAndroid-Public-master  File: PongHeaderTransformer.java View source code
@Override
public boolean hideHeaderView() {
    final boolean changeVis = mHeaderView.getVisibility() == View.VISIBLE;
    if (changeVis) {
        Animator animator = ObjectAnimator.ofFloat(mHeaderView, "alpha", 1f, 0f);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                mHeaderView.setVisibility(View.GONE);
                mPongPlayer.stopPlaying();
            }
        });
        animator.setDuration(FADE_IN_OUT_DURATION).start();
    }
    Log.d("PongHeaderTransformer", "hideHeaderView: " + changeVis);
    return changeVis;
}
Example 3
Project: sdk-support-master  File: ViewPropertyAnimatorCompatICS.java View source code
public static void setListener(final View view, final ViewPropertyAnimatorListener listener) {
    if (listener != null) {
        view.animate().setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationCancel(Animator animation) {
                listener.onAnimationCancel(view);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                listener.onAnimationEnd(view);
            }

            @Override
            public void onAnimationStart(Animator animation) {
                listener.onAnimationStart(view);
            }
        });
    } else {
        view.animate().setListener(null);
    }
}
Example 4
Project: Yhb-2.0-master  File: SwipeDismissTouchListener.java View source code
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    // offset because the view is translated during swipe
    motionEvent.offsetLocation(mTranslationX, 0);
    if (mViewWidth < 2) {
        mViewWidth = mView.getWidth();
    }
    switch(motionEvent.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            {
                // TODO: ensure this is a finger, and set a flag
                mDownX = motionEvent.getRawX();
                mDownY = motionEvent.getRawY();
                if (mCallbacks.canDismiss(mToken)) {
                    mVelocityTracker = VelocityTracker.obtain();
                    mVelocityTracker.addMovement(motionEvent);
                }
                return false;
            }
        case MotionEvent.ACTION_UP:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                float deltaX = motionEvent.getRawX() - mDownX;
                mVelocityTracker.addMovement(motionEvent);
                mVelocityTracker.computeCurrentVelocity(1000);
                float velocityX = mVelocityTracker.getXVelocity();
                float absVelocityX = Math.abs(velocityX);
                float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
                boolean dismiss = false;
                boolean dismissRight = false;
                if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) {
                    dismiss = true;
                    dismissRight = deltaX > 0;
                } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX && absVelocityY < absVelocityX && mSwiping) {
                    // dismiss only if flinging in the same direction as dragging
                    dismiss = (velocityX < 0) == (deltaX < 0);
                    dismissRight = mVelocityTracker.getXVelocity() > 0;
                }
                if (dismiss) {
                    // dismiss
                    mView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            performDismiss();
                        }
                    });
                } else if (mSwiping) {
                    // cancel
                    mView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
                }
                mVelocityTracker.recycle();
                mVelocityTracker = null;
                mTranslationX = 0;
                mDownX = 0;
                mDownY = 0;
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_CANCEL:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                mView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
                mVelocityTracker.recycle();
                mVelocityTracker = null;
                mTranslationX = 0;
                mDownX = 0;
                mDownY = 0;
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_MOVE:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                mVelocityTracker.addMovement(motionEvent);
                float deltaX = motionEvent.getRawX() - mDownX;
                float deltaY = motionEvent.getRawY() - mDownY;
                if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
                    mSwiping = true;
                    mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
                    mView.getParent().requestDisallowInterceptTouchEvent(true);
                    // Cancel listview's touch
                    MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
                    cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                    mView.onTouchEvent(cancelEvent);
                    cancelEvent.recycle();
                }
                if (mSwiping) {
                    mTranslationX = deltaX;
                    mView.setTranslationX(deltaX - mSwipingSlop);
                    // TODO: use an ease-out interpolator or such
                    mView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
                    return true;
                }
                break;
            }
    }
    return false;
}
Example 5
Project: android-sdk-sources-for-api-level-23-master  File: TaskStackViewScroller.java View source code
/** Animates the stack scroll */
void animateScroll(float curScroll, float newScroll, final Runnable postRunnable) {
    // Finish any current scrolling animations
    if (mScrollAnimator != null && mScrollAnimator.isRunning()) {
        setStackScroll(mFinalAnimatedScroll);
        mScroller.startScroll(0, progressToScrollRange(mFinalAnimatedScroll), 0, 0, 0);
    }
    stopScroller();
    stopBoundScrollAnimation();
    mFinalAnimatedScroll = newScroll;
    mScrollAnimator = ObjectAnimator.ofFloat(this, "stackScroll", curScroll, newScroll);
    mScrollAnimator.setDuration(mConfig.taskStackScrollDuration);
    mScrollAnimator.setInterpolator(mConfig.linearOutSlowInInterpolator);
    mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            setStackScroll((Float) animation.getAnimatedValue());
        }
    });
    mScrollAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (postRunnable != null) {
                postRunnable.run();
            }
            mScrollAnimator.removeAllListeners();
        }
    });
    mScrollAnimator.start();
}
Example 6
Project: jdroid-master  File: AnimationUtils.java View source code
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void hideWithReveal(final View view) {
    // get the center for the clipping circle
    int cx = (view.getLeft() + view.getRight()) / 2;
    int cy = (view.getTop() + view.getBottom()) / 2;
    // get the initial radius for the clipping circle
    int initialRadius = view.getWidth();
    // create the animation (the final radius is zero)
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);
    // make the view invisible when the animation is done
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            view.setVisibility(View.INVISIBLE);
        }
    });
    anim.setDuration(1000);
    // start the animation
    anim.start();
}
Example 7
Project: property-db-master  File: KeyguardMultiUserAvatar.java View source code
void updateVisualsForActive(boolean active, boolean animate, int duration, final Runnable onComplete) {
    final float finalAlpha = active ? mActiveAlpha : mInactiveAlpha;
    final float initAlpha = active ? mInactiveAlpha : mActiveAlpha;
    final float finalScale = active ? 1f : 1f / mActiveScale;
    final float initScale = mFramed.getScale();
    final int finalTextAlpha = active ? (int) (mActiveTextAlpha * 255) : (int) (mInactiveTextAlpha * 255);
    final int initTextAlpha = active ? (int) (mInactiveTextAlpha * 255) : (int) (mActiveTextAlpha * 255);
    int textColor = mTextColor;
    mUserName.setTextColor(textColor);
    if (animate && mTouched) {
        ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
        va.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float r = animation.getAnimatedFraction();
                float scale = (1 - r) * initScale + r * finalScale;
                float alpha = (1 - r) * initAlpha + r * finalAlpha;
                int textAlpha = (int) ((1 - r) * initTextAlpha + r * finalTextAlpha);
                mFramed.setScale(scale);
                mUserImage.setAlpha(alpha);
                mUserName.setTextColor(Color.argb(textAlpha, 255, 255, 255));
                mUserImage.invalidate();
            }
        });
        va.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                if (onComplete != null) {
                    onComplete.run();
                }
            }
        });
        va.setDuration(duration);
        va.start();
    } else {
        mFramed.setScale(finalScale);
        mUserImage.setAlpha(finalAlpha);
        mUserName.setTextColor(Color.argb(finalTextAlpha, 255, 255, 255));
        if (onComplete != null) {
            post(onComplete);
        }
    }
    mTouched = true;
}
Example 8
Project: AppCompat-Extension-Library-master  File: LabelView.java View source code
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void hideIceCreamSandwich() {
    animate().cancel();
    animate().translationX(mAnimationOffset).alpha(0f).setDuration(SHOW_HIDE_ANIM_DURATION).setInterpolator(AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR).setListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationStart(Animator animation) {
            mIsHiding = true;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mIsHiding = false;
            mCancelled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mIsHiding = false;
            // cancelled animations don't change visibility
            if (!mCancelled) {
                setVisibility(GONE);
            }
        }
    });
}
Example 9
Project: android-xkcd-master  File: AnimationUtils.java View source code
/** Fade out the given view. */
public static void fadeOut(final View view, float opacity, int duration) {
    // Animate the loading view to the given opacity.
    AnimatorListenerAdapter animatorListenerAdapter = null;
    if (opacity == 0f) {
        // After the animation ends, set its visibility to GONE as an optimization step
        // (it won't participate in layout passes, etc.)
        animatorListenerAdapter = new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        };
    }
    view.animate().withLayer().alpha(opacity).setDuration(duration).setListener(animatorListenerAdapter);
}
Example 10
Project: WordPress-Android-master  File: PlansActivity.java View source code
@Override
public void onGlobalLayout() {
    mViewPager.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    Point pt = DisplayUtils.getDisplayPixelSize(PlansActivity.this);
    float startRadius = 0f;
    float endRadius = (float) Math.hypot(pt.x, pt.y);
    int centerX = pt.x / 2;
    int centerY = pt.y / 2;
    Animator anim = ViewAnimationUtils.createCircularReveal(mViewPager, centerX, centerY, startRadius, endRadius);
    anim.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    anim.setInterpolator(new AccelerateInterpolator());
    anim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            showManageBar();
        }
    });
    mViewPager.setVisibility(View.VISIBLE);
    mTabLayout.setVisibility(View.VISIBLE);
    anim.start();
}
Example 11
Project: andevcon-2014-jl-master  File: LayoutAnimationsHideShow.java View source code
private void setupCustomAnimations() {
    // Changing while Adding
    PropertyValuesHolder pvhLeft = PropertyValuesHolder.ofInt("left", 0, 1);
    PropertyValuesHolder pvhTop = PropertyValuesHolder.ofInt("top", 0, 1);
    PropertyValuesHolder pvhRight = PropertyValuesHolder.ofInt("right", 0, 1);
    PropertyValuesHolder pvhBottom = PropertyValuesHolder.ofInt("bottom", 0, 1);
    PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
    PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
    final ObjectAnimator changeIn = ObjectAnimator.ofPropertyValuesHolder(this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY).setDuration(mTransitioner.getDuration(LayoutTransition.CHANGE_APPEARING));
    mTransitioner.setAnimator(LayoutTransition.CHANGE_APPEARING, changeIn);
    changeIn.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setScaleX(1f);
            view.setScaleY(1f);
        }
    });
    // Changing while Removing
    Keyframe kf0 = Keyframe.ofFloat(0f, 0f);
    Keyframe kf1 = Keyframe.ofFloat(.9999f, 360f);
    Keyframe kf2 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
    final ObjectAnimator changeOut = ObjectAnimator.ofPropertyValuesHolder(this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation).setDuration(mTransitioner.getDuration(LayoutTransition.CHANGE_DISAPPEARING));
    mTransitioner.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, changeOut);
    changeOut.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setRotation(0f);
        }
    });
    // Adding
    ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f).setDuration(mTransitioner.getDuration(LayoutTransition.APPEARING));
    mTransitioner.setAnimator(LayoutTransition.APPEARING, animIn);
    animIn.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setRotationY(0f);
        }
    });
    // Removing
    ObjectAnimator animOut = ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f).setDuration(mTransitioner.getDuration(LayoutTransition.DISAPPEARING));
    mTransitioner.setAnimator(LayoutTransition.DISAPPEARING, animOut);
    animOut.addListener(new AnimatorListenerAdapter() {

        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setRotationX(0f);
        }
    });
}
Example 12
Project: XieDaDeng-master  File: NavigationBarTransitions.java View source code
private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) {
    if (!force && lightsOut == mLightsOut)
        return;
    mLightsOut = lightsOut;
    final View navButtons = mView.getCurrentView().findViewById(R.id.nav_buttons);
    final View lowLights = mView.getCurrentView().findViewById(R.id.lights_out);
    // ok, everyone, stop it right there
    navButtons.animate().cancel();
    lowLights.animate().cancel();
    final float navButtonsAlpha = lightsOut ? 0f : 1f;
    final float lowLightsAlpha = lightsOut ? 1f : 0f;
    if (!animate) {
        navButtons.setAlpha(navButtonsAlpha);
        lowLights.setAlpha(lowLightsAlpha);
        lowLights.setVisibility(lightsOut ? View.VISIBLE : View.GONE);
    } else {
        final int duration = lightsOut ? LIGHTS_OUT_DURATION : LIGHTS_IN_DURATION;
        navButtons.animate().alpha(navButtonsAlpha).setDuration(duration).start();
        lowLights.setOnTouchListener(mLightsOutListener);
        if (lowLights.getVisibility() == View.GONE) {
            lowLights.setAlpha(0f);
            lowLights.setVisibility(View.VISIBLE);
        }
        lowLights.animate().alpha(lowLightsAlpha).setDuration(duration).setInterpolator(new AccelerateInterpolator(2.0f)).setListener(lightsOut ? null : new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator _a) {
                lowLights.setVisibility(View.GONE);
            }
        }).start();
    }
}
Example 13
Project: androidtv-Leanback-master  File: OnboardingFragment.java View source code
@Override
protected void onPageChanged(final int newPage, int previousPage) {
    if (mContentAnimator != null) {
        mContentAnimator.end();
    }
    ArrayList<Animator> animators = new ArrayList<>();
    Animator fadeOut = createFadeOutAnimator(mContentView);
    fadeOut.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mContentView.setImageDrawable(getResources().getDrawable(pageImages[newPage]));
            ((AnimationDrawable) mContentView.getDrawable()).start();
        }
    });
    animators.add(fadeOut);
    animators.add(createFadeInAnimator(mContentView));
    AnimatorSet set = new AnimatorSet();
    set.playSequentially(animators);
    set.start();
    mContentAnimator = set;
}
Example 14
Project: SyncthingAndroid-master  File: ExpandCollapseHelper.java View source code
/**
     * This method expandes the view that was clicked.
     *
     * @param expandingLayout  layout to expand
     * @param cardView         cardView
     * @param recyclerView     recyclerView
     */
public static void animateCollapsing(final View expandingLayout, final ExpandableView cardView, final RecyclerView recyclerView, boolean wobble) {
    final int origHeight = expandingLayout.getHeight();
    ValueAnimator animator = createHeightAnimator(expandingLayout, origHeight, 0);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animator) {
            expandingLayout.setVisibility(View.GONE);
            //reset height else recycled views never show
            ViewGroup.LayoutParams layoutParams = expandingLayout.getLayoutParams();
            layoutParams.height = origHeight;
            expandingLayout.setLayoutParams(layoutParams);
            cardView.getExpandable().setExpanded(false);
        //notifyAdapter(recyclerView, recyclerView.getLayoutManager().getPosition((View)cardView));
        //                Card card = cardView.getCard();
        //                if (card.getOnCollapseAnimatorEndListener()!=null)
        //                    card.getOnCollapseAnimatorEndListener().onCollapseEnd(card);
        }
    });
    if (wobble) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animator, createWobbleAnimator(cardView.getView()));
        animatorSet.start();
    } else {
        animator.start();
    }
}
Example 15
Project: WhatsThat-master  File: SwipeDismissListener.java View source code
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    motionEvent.offsetLocation(mTranslationX, 0);
    int mViewWidth = mView.getWidth();
    switch(motionEvent.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mActionDownXCoordinate = motionEvent.getRawX();
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
            view.onTouchEvent(motionEvent);
            return true;
        case MotionEvent.ACTION_UP:
            if (mVelocityTracker == null) {
                break;
            }
            float deltaXActionUp = motionEvent.getRawX() - mActionDownXCoordinate;
            mVelocityTracker.addMovement(motionEvent);
            mVelocityTracker.computeCurrentVelocity(1000);
            float velocityX = Math.abs(mVelocityTracker.getXVelocity());
            float velocityY = Math.abs(mVelocityTracker.getYVelocity());
            boolean dismiss = false;
            boolean dismissRight = false;
            if (Math.abs(deltaXActionUp) > mViewWidth / 2) {
                dismiss = true;
                dismissRight = deltaXActionUp > 0;
            } else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX) {
                dismiss = true;
                dismissRight = mVelocityTracker.getXVelocity() > 0;
            }
            if (dismiss) {
                mView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        performDismiss();
                    }
                });
            } else {
                // User has cancelled action
                mView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
            }
            mVelocityTracker.recycle();
            mTranslationX = 0;
            mActionDownXCoordinate = 0;
            isSwiping = false;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mVelocityTracker == null) {
                break;
            }
            mVelocityTracker.addMovement(motionEvent);
            float deltaXActionMove = motionEvent.getRawX() - mActionDownXCoordinate;
            if (Math.abs(deltaXActionMove) > mScaledTouchSlop) {
                isSwiping = true;
                mView.getParent().requestDisallowInterceptTouchEvent(true);
                // Cancel listview's touch
                MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
                cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                mView.onTouchEvent(cancelEvent);
                cancelEvent.recycle();
            }
            if (isSwiping) {
                mTranslationX = deltaXActionMove;
                mView.setTranslationX(deltaXActionMove);
                mView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaXActionMove) / mViewWidth)));
                return true;
            }
            break;
    }
    return false;
}
Example 16
Project: platform_packages_apps_settings-master  File: ConditionAdapterUtils.java View source code
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
    final int afterBottom = content.getBottom();
    v.removeOnLayoutChangeListener(this);
    final ObjectAnimator animator = ObjectAnimator.ofInt(content, "bottom", beforeBottom, afterBottom);
    animator.setDuration(DURATION);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!visible) {
                detailGroup.setVisibility(View.GONE);
            }
        }
    });
    animator.start();
}
Example 17
Project: iosched4eclipse-master  File: LPreviewUtilsBase.java View source code
public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck, boolean allowAnimate) {
    final int imageResId = isCheck ? R.drawable.add_schedule_button_icon_checked : R.drawable.add_schedule_button_icon_unchecked;
    if (imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();
            imageView.setAlpha(1f);
        }
    }
    if (allowAnimate && isCheck) {
        int duration = mActivity.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();
        outAnimator.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);
            }
        });
    }
}
Example 18
Project: kinballwc2015-master  File: RefereesFragment.java View source code
private void zoomImageFromThumb(final View thumbView, String url) {
    if (thumbView == null) {
        // || TextUtils.isEmpty(url)){
        return;
    }
    lastThumbImage = thumbView;
    progressBar.setVisibility(View.VISIBLE);
    // immediately and proceed with this one.
    if (mCurrentAnimator != null) {
        mCurrentAnimator.cancel();
    }
    // Load the high-resolution "zoomed-in" image.
    Glide.with(this).load(url).placeholder(R.drawable.placeholder).diskCacheStrategy(DiskCacheStrategy.ALL).error(R.drawable.ic_error).fitCenter().listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            progressBar.setVisibility(View.GONE);
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            progressBar.setVisibility(View.GONE);
            expandedImageView.setImageDrawable(resource);
            return false;
        }
    }).into(expandedImageView);
    // Calculate the starting and ending bounds for the zoomed-in image.
    // This step involves lots of math. Yay, math.
    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);
    rootLayout.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;
        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(SHORT_ANIMATION_DURATION);
    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.
    startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            zoomOutImage(thumbView);
        }
    });
}
Example 19
Project: android_packages_apps-master  File: SearchDropTargetBar.java View source code
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    // Get the individual components
    mQSBSearchBar = findViewById(R.id.qsb_search_bar);
    mDropTargetBar = findViewById(R.id.drag_target_bar);
    mInfoDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.info_target_text);
    mDeleteDropTarget = (ButtonDropTarget) mDropTargetBar.findViewById(R.id.delete_target_text);
    mBarHeight = getResources().getDimensionPixelSize(R.dimen.qsb_bar_height);
    mInfoDropTarget.setSearchDropTargetBar(this);
    mDeleteDropTarget.setSearchDropTargetBar(this);
    boolean enableDropDownDropTargets = getResources().getBoolean(R.bool.config_useDropTargetDownTransition);
    // Create the various fade animations
    mDropTargetBar.setAlpha(0f);
    ObjectAnimator fadeInAlphaAnim = ObjectAnimator.ofFloat(mDropTargetBar, "alpha", 1f);
    fadeInAlphaAnim.setInterpolator(new DecelerateInterpolator());
    mDropTargetBarFadeInAnim = new AnimatorSet();
    AnimatorSet.Builder fadeInAnimators = mDropTargetBarFadeInAnim.play(fadeInAlphaAnim);
    if (enableDropDownDropTargets) {
        mDropTargetBar.setTranslationY(-mBarHeight);
        fadeInAnimators.with(ObjectAnimator.ofFloat(mDropTargetBar, "translationY", 0f));
    }
    mDropTargetBarFadeInAnim.setDuration(sTransitionInDuration);
    mDropTargetBarFadeInAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mDropTargetBar.setVisibility(View.VISIBLE);
        }
    });
    ObjectAnimator fadeOutAlphaAnim = ObjectAnimator.ofFloat(mDropTargetBar, "alpha", 0f);
    fadeOutAlphaAnim.setInterpolator(new AccelerateInterpolator());
    mDropTargetBarFadeOutAnim = new AnimatorSet();
    AnimatorSet.Builder fadeOutAnimators = mDropTargetBarFadeOutAnim.play(fadeOutAlphaAnim);
    if (enableDropDownDropTargets) {
        fadeOutAnimators.with(ObjectAnimator.ofFloat(mDropTargetBar, "translationY", -mBarHeight));
    }
    mDropTargetBarFadeOutAnim.setDuration(sTransitionOutDuration);
    mDropTargetBarFadeOutAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mDropTargetBar.setVisibility(View.INVISIBLE);
            mDropTargetBar.setLayerType(View.LAYER_TYPE_NONE, null);
        }
    });
    mQSBSearchBarFadeInAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "alpha", 1f);
    mQSBSearchBarFadeInAnim.setDuration(sTransitionInDuration);
    mQSBSearchBarFadeInAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mQSBSearchBar.setVisibility(View.VISIBLE);
        }
    });
    mQSBSearchBarFadeOutAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "alpha", 0f);
    mQSBSearchBarFadeOutAnim.setDuration(sTransitionOutDuration);
    mQSBSearchBarFadeOutAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mQSBSearchBar.setVisibility(View.INVISIBLE);
        }
    });
}
Example 20
Project: Subsonic-master  File: FastScroller.java View source code
private void hideBubble() {
    if (currentAnimator != null)
        currentAnimator.cancel();
    currentAnimator = ObjectAnimator.ofFloat(bubble, "alpha", 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION);
    currentAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            bubble.setVisibility(INVISIBLE);
            currentAnimator = null;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            bubble.setVisibility(INVISIBLE);
            currentAnimator = null;
        }
    });
    currentAnimator.start();
}
Example 21
Project: android-platform-tools-base-master  File: NotificationStudioActivity.java View source code
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
    // animate preview height changes
    if (oldBottom != bottom) {
        final View e = findViewById(R.id.editors);
        final int y = bottom + margin;
        e.animate().translationY(y - oldBottom).setListener(new AnimatorListenerAdapter() {

            public void onAnimationEnd(Animator animation) {
                FrameLayout.LayoutParams lp = (LayoutParams) e.getLayoutParams();
                lp.topMargin = y;
                e.setTranslationY(0);
                e.setLayoutParams(lp);
            }
        });
    }
}
Example 22
Project: Fontster-master  File: ViewUtils.java View source code
public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView().getOverlay();
        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);
        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);
        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;
        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();
        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));
        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX, revealCenterY, 0.0f, revealRadius);
            revealAnimator.setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));
            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator.setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });
            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });
            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}
Example 23
Project: TasksProject-master  File: SwipeDismissTouchListener.java View source code
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    // offset because the view is translated during swipe
    motionEvent.offsetLocation(mTranslationX, 0);
    if (mViewWidth < 2) {
        mViewWidth = mView.getWidth();
    }
    switch(motionEvent.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            {
                // TODO: ensure this is a finger, and set a flag
                mDownX = motionEvent.getRawX();
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
                view.onTouchEvent(motionEvent);
                pos = (mView.getX() + mView.getWidth()) / 2;
                return false;
            }
        case MotionEvent.ACTION_UP:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                float deltaX = motionEvent.getRawX() - mDownX;
                mVelocityTracker.addMovement(motionEvent);
                mVelocityTracker.computeCurrentVelocity(1000);
                float velocityX = Math.abs(mVelocityTracker.getXVelocity());
                float velocityY = Math.abs(mVelocityTracker.getYVelocity());
                boolean dismiss = false;
                boolean dismissRight = false;
                if (Math.abs(deltaX) > mViewWidth / 2) {
                    dismiss = true;
                    dismissRight = deltaX > 0;
                } else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX) {
                    dismiss = true;
                    dismissRight = mVelocityTracker.getXVelocity() > 0;
                }
                if (dismiss) {
                    // dismiss
                    mView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            performDismiss();
                        }
                    });
                } else {
                    // cancel
                    mView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
                }
                mVelocityTracker = null;
                mTranslationX = 0;
                mDownX = 0;
                mSwiping = false;
                break;
            }
        case MotionEvent.ACTION_MOVE:
            {
                if (mVelocityTracker == null) {
                    break;
                }
                mVelocityTracker.addMovement(motionEvent);
                float deltaX = motionEvent.getRawX() - mDownX;
                if (Math.abs(deltaX) > mSlop) {
                    mSwiping = true;
                    mView.getParent().requestDisallowInterceptTouchEvent(true);
                    // Cancel listview's touch
                    MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
                    cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
                    mView.onTouchEvent(cancelEvent);
                }
                if (mSwiping) {
                    mTranslationX = deltaX;
                    mView.setTranslationX(deltaX);
                    // TODO: use an ease-out interpolator or such
                    mView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
                    //                }
                    return true;
                }
                break;
            }
    }
    return false;
}
Example 24
Project: cardslib-master  File: CardRecyclerView.java View source code
/**
         * This method expandes the view that was clicked.
         *
         * @param expandingLayout  layout to expand
         * @param cardView         cardView
         * @param recyclerView     recyclerView
         */
public static void animateCollapsing(final View expandingLayout, final CardViewWrapper cardView, final RecyclerView recyclerView) {
    int origHeight = expandingLayout.getHeight();
    ValueAnimator animator = createHeightAnimator(expandingLayout, origHeight, 0);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animator) {
            expandingLayout.setVisibility(View.GONE);
            //card.setExpanded(true);
            cardView.setExpanded(false);
            notifyAdapter(recyclerView, recyclerView.getLayoutManager().getPosition((View) cardView));
            Card card = cardView.getCard();
            if (card.getOnCollapseAnimatorEndListener() != null)
                card.getOnCollapseAnimatorEndListener().onCollapseEnd(card);
        }
    });
    animator.start();
}
Example 25
Project: Protocoder-master  File: PLiveCodingFeedback.java View source code
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public View add() {
    // live execution layout
    liveRLayout = new LinearLayout(a);
    RelativeLayout.LayoutParams liveLayoutParams = new RelativeLayout.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT);
    liveLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    liveLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    liveRLayout.setLayoutParams(liveLayoutParams);
    liveRLayout.setGravity(Gravity.BOTTOM);
    liveRLayout.setBackgroundColor(bgColor);
    liveRLayout.setPadding(10, 10, 10, 10);
    liveRLayout.setVisibility(View.GONE);
    // liveRLayout.setLayoutTransition(transition)
    // Animation spinin = AnimationUtils.loadAnimation(this,
    // R.anim.slide_in_left);
    // liveRLayout.setLayoutAnimation(new
    // LayoutAnimationController(spinin));
    Animator appearingAnimation = ObjectAnimator.ofFloat(null, "translationY", 20, 0);
    appearingAnimation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator anim) {
            View view = (View) ((ObjectAnimator) anim).getTarget();
            view.setTranslationX(0f);
        }
    });
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        LayoutTransition l = new LayoutTransition();
        l.enableTransitionType(LayoutTransition.CHANGING);
        AnimatorSet as = (AnimatorSet) AnimatorInflater.loadAnimator(a, R.animator.live_code);
        // as.se
        l.setAnimator(LayoutTransition.APPEARING, as);
        l.setDuration(LayoutTransition.APPEARING, 300);
        l.setStartDelay(LayoutTransition.APPEARING, 0);
        liveRLayout.setLayoutTransition(l);
    }
    return liveRLayout;
}