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.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

private void reveal(View sourceView, AnimatorListener listener) {
    final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay();

    final Rect displayRect = new Rect();
    mDisplayView.getGlobalVisibleRect(displayRect);

    // Make reveal cover the display and status bar.
    final View revealView = new View(this);
    revealView.setBottom(displayRect.bottom);
    revealView.setLeft(displayRect.left);
    revealView.setRight(displayRect.right);
    revealView.setBackgroundColor(themeClearAccent);
    groupOverlay.add(revealView);/*from   w  w w . j a v  a  2s .co m*/

    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));

    final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
            revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    alphaAnimator.addListener(listener);

    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);
            mCurrentAnimator = null;
        }
    });

    mCurrentAnimator = animatorSet;
    animatorSet.start();
}

From source file:com.gitstudy.rili.liarbry.CalendarLayout.java

/**
 * //from ww w  .ja  va 2s .c  om
 *
 * @return ?
 */
public boolean shrink() {
    if (isAnimating || mContentView == null) {
        return false;
    }
    ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
            mContentView.getTranslationY(), -mContentViewTranslateY);
    objectAnimator.setDuration(240);
    objectAnimator.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float currentValue = (Float) animation.getAnimatedValue();
            float percent = currentValue * 1.0f / mContentViewTranslateY;
            mMonthView.setTranslationY(mViewPagerTranslateY * percent);
            isAnimating = true;
        }
    });
    objectAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            isAnimating = false;
            showWeek();

        }
    });
    objectAnimator.start();
    return true;
}

From source file:com.appunite.appunitevideoplayer.PlayerActivity.java

private void showControls() {
    toolbar.animate().translationY(0).setDuration(ANIMATION_DURATION)
            .setListener(new AnimatorListenerAdapter() {
                @Override//  w  w  w.ja v  a 2 s . c  om
                public void onAnimationEnd(Animator animation) {
                    mElementsHidden = false;
                }
            }).start();
    controllerView.animate().translationY(0).setDuration(ANIMATION_DURATION).start();
}

From source file:com.projecttango.examples.java.greenscreen.GreenScreenActivity.java

/**
 * Here is where you would set up your rendering logic. We're replacing it with a minimalistic,
 * dummy example, using a standard GLSurfaceView and a basic renderer, for illustration purposes
 * only./*from w  ww. jav  a 2s. co m*/
 */
private void setupRenderer() {
    mSurfaceView.setEGLContextClientVersion(2);
    mRenderer = new GreenScreenRenderer(this, new GreenScreenRenderer.RenderCallback() {

        @Override
        public void preRender() {
            // This is the work that you would do on your main OpenGL render thread.

            // We need to be careful to not run any Tango-dependent code in the
            // OpenGL thread unless we know the Tango Service to be properly set up
            // and connected.
            if (!mIsConnected) {
                return;
            }

            // Synchronize against concurrently disconnecting the service triggered
            // from the UI thread.
            synchronized (GreenScreenActivity.this) {
                // Connect the Tango SDK to the OpenGL texture ID where we are
                // going to render the camera.
                // NOTE: This must be done after both the texture is generated
                // and the Tango Service is connected.
                if (mConnectedTextureIdGlThread != mRenderer.getTextureId()) {
                    mTango.connectTextureId(TangoCameraIntrinsics.TANGO_CAMERA_COLOR, mRenderer.getTextureId());
                    mConnectedTextureIdGlThread = mRenderer.getTextureId();
                    Log.d(TAG, "connected to texture id: " + mRenderer.getTextureId());
                    // Set up scene camera projection to match RGB camera intrinsics.
                    mRenderer.setProjectionMatrix(projectionMatrixFromCameraIntrinsics(mIntrinsics));
                    mRenderer.setCameraIntrinsics(mIntrinsics);
                }
                // If there is a new RGB camera frame available, update the texture and
                // scene camera pose.
                if (mIsFrameAvailableTangoThread.compareAndSet(true, false)) {
                    double depthTimestamp = 0;
                    TangoPointCloudData pointCloud = mPointCloudManager.getLatestPointCloud();
                    if (pointCloud != null) {
                        mRenderer.updatePointCloud(pointCloud);
                        depthTimestamp = pointCloud.timestamp;
                    }
                    try {
                        // {@code mRgbTimestampGlThread} contains the exact timestamp at
                        // which the rendered RGB frame was acquired.
                        mRgbTimestampGlThread = mTango.updateTexture(TangoCameraIntrinsics.TANGO_CAMERA_COLOR);

                        // In the following code, we define t0 as the depth timestamp
                        // and t1 as the color camera timestamp.

                        // Calculate the relative pose between color camera frame at
                        // timestamp color_timestamp t1 and depth.
                        TangoPoseData poseColort1Tdeptht0;
                        poseColort1Tdeptht0 = TangoSupport.calculateRelativePose(mRgbTimestampGlThread,
                                TangoPoseData.COORDINATE_FRAME_CAMERA_COLOR, depthTimestamp,
                                TangoPoseData.COORDINATE_FRAME_CAMERA_DEPTH);
                        if (poseColort1Tdeptht0.statusCode == TangoPoseData.POSE_VALID) {
                            float[] colort1Tdeptht0 = poseToMatrix(poseColort1Tdeptht0);
                            mRenderer.updateModelMatrix(colort1Tdeptht0);
                        } else {
                            Log.w(TAG, "Could not get relative pose from camera depth" + " " + "at "
                                    + depthTimestamp + " to camera color at " + mRgbTimestampGlThread);
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Exception on the OpenGL thread", e);
                    }
                }
            }
        }

        /**
         * This method is called by the renderer when the screenshot has been taken.
         */
        @Override
        public void onScreenshotTaken(final Bitmap screenshotBitmap) {
            // Give immediate feedback to the user.
            MediaActionSound sound = new MediaActionSound();
            sound.play(MediaActionSound.SHUTTER_CLICK);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mPanelFlash.setVisibility(View.VISIBLE);
                    // Run a fade in and out animation of a white screen.
                    ObjectAnimator fadeIn = ObjectAnimator.ofFloat(mPanelFlash, View.ALPHA, 0, 1);
                    fadeIn.setDuration(100);
                    fadeIn.setInterpolator(new DecelerateInterpolator());
                    ObjectAnimator fadeOut = ObjectAnimator.ofFloat(mPanelFlash, View.ALPHA, 1, 0);
                    fadeOut.setInterpolator(new AccelerateInterpolator());
                    fadeOut.setDuration(100);

                    AnimatorSet animation = new AnimatorSet();
                    animation.playSequentially(fadeIn, fadeOut);
                    animation.addListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            mPanelFlash.setVisibility(View.GONE);
                        }
                    });
                    animation.start();
                }
            });
            // Save bitmap to gallery in background.
            new BitmapSaverTask(screenshotBitmap).execute();
        }
    });

    mSurfaceView.setRenderer(mRenderer);
}

From source file:com.alburivan.slickform.tooltip.SimpleTooltip.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void startAnimation() {
    final String property = mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM ? "translationY"
            : "translationX";

    final ObjectAnimator anim1 = ObjectAnimator.ofFloat(mContentLayout, property, -mAnimationPadding,
            mAnimationPadding);//from   w  w  w .java2  s  . com
    anim1.setDuration(mAnimationDuration);
    anim1.setInterpolator(new AccelerateDecelerateInterpolator());

    final ObjectAnimator anim2 = ObjectAnimator.ofFloat(mContentLayout, property, mAnimationPadding,
            -mAnimationPadding);
    anim2.setDuration(mAnimationDuration);
    anim2.setInterpolator(new AccelerateDecelerateInterpolator());

    mAnimator = new AnimatorSet();
    mAnimator.playSequentially(anim1, anim2);
    mAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!dismissed && isShowing()) {
                animation.start();
            }
        }
    });
    mAnimator.start();
}

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

private Animator getRevealAnimator(View source, int revealColor) {
    final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);/*  w  w w  .  j  av a  2  s .com*/
    containerView.addView(revealView);

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f));

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS);
    animatorSet.playSequentially(revealAnimator, fadeAnimator);

    return revealAnimator;
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

private void onClear() {
    if (TextUtils.isEmpty(mInputEditText.getText())) { //TODO check if necessary or not
        return;/*from w ww . java2s .  c  o m*/
    }

    final View sourceView = mClearButton.getVisibility() == View.VISIBLE ? mClearButton : mDeleteButton;
    reveal(sourceView, new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            mInputEditText.getEditableText().clear();
        }
    });
}

From source file:com.phonemetra.turbo.launcher.Folder.java

public void animateOpen() {
    positionAndSizeAsIcon();/*from  w ww  . j  a v  a  2  s  .com*/

    if (!(getParent() instanceof DragLayer))
        return;
    centerAboutIcon();
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                    String.format(getContext().getString(R.string.folder_opened), mContent.getCountX(),
                            mContent.getCountY()));
            mState = STATE_ANIMATING;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            setLayerType(LAYER_TYPE_NONE, null);

            setFocusOnFirstChild();
        }
    });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    oa.start();

    // Make sure the folder picks up the last drag move even if the finger doesn't move.
    if (mDragController.isDragging()) {
        mDragController.forceTouchMove();
    }
}

From source file:com.google.android.apps.muzei.MuzeiActivity.java

private void updateUiMode() {
    // TODO: this should really just use fragment transactions and transitions

    int newUiMode = UI_MODE_INTRO;
    if (mWallpaperActive) {
        newUiMode = UI_MODE_TUTORIAL;/*from  w w w  .  j a  v  a2  s. co  m*/
        if (mSeenTutorial) {
            newUiMode = UI_MODE_ART_DETAIL;
        }
    }

    if (mUiMode == newUiMode) {
        return;
    }

    // Crossfade between main containers
    final View oldContainerView = getMainContainerForUiMode(mUiMode);
    final View newContainerView = getMainContainerForUiMode(newUiMode);

    if (oldContainerView != null) {
        oldContainerView.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {
            @Override
            public void run() {
                oldContainerView.setVisibility(View.GONE);
            }
        });
    }

    if (newContainerView != null) {
        if (newContainerView.getAlpha() == 1) {
            newContainerView.setAlpha(0);
        }
        newContainerView.setVisibility(View.VISIBLE);
        newContainerView.animate().alpha(1).setDuration(1000).withEndAction(null);
    }

    // Special work
    if (newUiMode == UI_MODE_INTRO) {
        final View activateButton = findViewById(R.id.activate_muzei_button);
        activateButton.setAlpha(0);
        final AnimatedMuzeiLogoFragment logoFragment = (AnimatedMuzeiLogoFragment) getFragmentManager()
                .findFragmentById(R.id.animated_logo_fragment);
        logoFragment.reset();
        logoFragment.setOnFillStartedCallback(new Runnable() {
            @Override
            public void run() {
                activateButton.animate().alpha(1f).setDuration(500);
            }
        });
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                logoFragment.start();
            }
        }, 1000);
    }

    if (mUiMode == UI_MODE_INTRO || newUiMode == UI_MODE_INTRO) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment demoFragment = fm.findFragmentById(R.id.demo_view_container);
        if (newUiMode == UI_MODE_INTRO && demoFragment == null) {
            fm.beginTransaction()
                    .add(R.id.demo_view_container, MuzeiRendererFragment.createInstance(true, true)).commit();
        } else if (newUiMode != UI_MODE_INTRO && demoFragment != null) {
            fm.beginTransaction().remove(demoFragment).commit();
        }
    }

    if (newUiMode == UI_MODE_TUTORIAL) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100,
                getResources().getDisplayMetrics());
        View mainTextView = findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);

        View subTextView = findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);

        final View affordanceView = findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);

        View iconTextView = findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);

        AnimatorSet set = new AnimatorSet();
        set.setStartDelay(500);
        set.setDuration(250);
        set.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        set.start();

        set = new AnimatorSet();
        set.setStartDelay(2000);

        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        set.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            set.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    ImageView emanateView = (ImageView) findViewById(R.id.tutorial_icon_emanate);
                    AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources()
                            .getDrawable(R.drawable.avd_tutorial_icon_emanate, getTheme());
                    emanateView.setImageDrawable(avd);
                    avd.start();
                }
            });
        }
        set.start();
    }

    mPanScaleProxyView.setVisibility(newUiMode == UI_MODE_ART_DETAIL ? View.VISIBLE : View.GONE);

    mUiMode = newUiMode;

    maybeUpdateArtDetailOpenedClosed();
}

From source file:com.hippo.vector.AnimatedVectorDrawable.java

@Override
public void registerAnimationCallback(@NonNull AnimationCallback callback) {
    if (callback == null) {
        return;//from w w w. j av  a  2 s. c o m
    }

    // Add listener accordingly.
    if (mAnimationCallbacks == null) {
        mAnimationCallbacks = new ArrayList<>();
    }

    mAnimationCallbacks.add(callback);

    if (mAnimatorListener == null) {
        // Create a animator listener and trigger the callback events when listener is
        // triggered.
        mAnimatorListener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                ArrayList<AnimationCallback> tmpCallbacks = new ArrayList<>(mAnimationCallbacks);
                int size = tmpCallbacks.size();
                for (int i = 0; i < size; i++) {
                    tmpCallbacks.get(i).onAnimationStart(AnimatedVectorDrawable.this);
                }
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                ArrayList<AnimationCallback> tmpCallbacks = new ArrayList<>(mAnimationCallbacks);
                int size = tmpCallbacks.size();
                for (int i = 0; i < size; i++) {
                    tmpCallbacks.get(i).onAnimationEnd(AnimatedVectorDrawable.this);
                }
            }
        };
    }
    mAnimatorSet.addListener(mAnimatorListener);
}