Example usage for android.animation ObjectAnimator setInterpolator

List of usage examples for android.animation ObjectAnimator setInterpolator

Introduction

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

Prototype

@Override
public void setInterpolator(TimeInterpolator value) 

Source Link

Document

The time interpolator used in calculating the elapsed fraction of this animation.

Usage

From source file:com.mina.breathitout.AnalyzeActivity.java

private void moveRight() {
    AnalyzeActivity.this.runOnUiThread(new Runnable() {
        @Override//from  w w  w.  j  a  va 2s  . c  o  m
        public void run() {
            mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_in));
            mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.left_out));
            // controlling animation
            mViewFlipper.getInAnimation().setAnimationListener(mAnimationListener);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                // will update the "progress" propriety of seekbar until it reaches progress
                ObjectAnimator progressAnimation = ObjectAnimator.ofInt(progressBar, "progress", lastMaxTime,
                        0);
                progressAnimation.setDuration(1000); // 0.5 second
                progressAnimation.setInterpolator(new DecelerateInterpolator());
                progressAnimation.start();
            } else
                progressBar.setProgress(0); // no animation on Gingerbread or lower
            mViewFlipper.showNext();
        }
    });
}

From source file:com.mina.breathitout.AnalyzeActivity.java

public void animateProgressBar() {
    AnalyzeActivity.this.runOnUiThread(new Runnable() {
        @Override//w  w  w .  j a v  a2 s  . c  o  m
        public void run() {
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                // will update the "progress" propriety of seekbar until it reaches progress
                ObjectAnimator progressAnimation = ObjectAnimator.ofInt(progressBar, "progress",
                        progressBar.getProgress(), lastMaxTime);
                progressAnimation.setDuration(1000); // 0.5 second
                progressAnimation.setInterpolator(new DecelerateInterpolator());
                progressAnimation.start();
            } else
                progressBar.setProgress(timerCounter); // no animation on Gingerbread or lower
        }
    });
}

From source file:com.waz.zclient.ui.cursor.CursorLayout.java

private ObjectAnimator getHideToolbarAnimator(final View view, float fromValue, float toValue) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.TRANSLATION_Y, fromValue, toValue);
    animator.setDuration(cursorToolbarAnimationDuration);
    animator.setInterpolator(new Expo.EaseIn());
    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*ww  w.j  ava2  s . co m*/
        public void onAnimationCancel(Animator animation) {
            if (view == null) {
                return;
            }
            view.setVisibility(GONE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (view == null) {
                return;
            }
            view.setVisibility(GONE);
        }
    });
    return animator;
}

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

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

    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        controlX = mFabOriginalX * 0.98f;
    } else {//  w ww .  j  a v a  2 s  . c  o  m
        controlX = mFabOriginalX * 1.02f;
    }

    final Path path = new Path();
    path.moveTo(mFab.getX(), mFab.getY());
    final float x2 = controlX;
    final float y2 = getY();
    path.quadTo(x2, y2, mFabOriginalX, mFabOriginalY + getTranslationY());
    ObjectAnimator anim = ObjectAnimator.ofFloat(mFab, View.X, View.Y, path);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Animate FAB elevation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(mFab, View.TRANSLATION_Z, 0);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.setDuration(FAB_UNMORPH_DURATION);
    anim.setStartDelay(FAB_UNMORPH_DELAY);
    anim.start();

    /**
     * Restore alpha of FAB drawable
     */
    Drawable drawable = mFab.getDrawable();
    if (drawable != null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.setDuration(FAB_UNMORPH_DURATION);
        anim.setStartDelay(FAB_UNMORPH_DELAY);
        anim.start();
    }

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

    toolbarReveal.setTarget(this);
    toolbarReveal.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            setVisibility(View.INVISIBLE);
            mFab.setVisibility(View.VISIBLE);
            mMorphing = false;
        }
    });
    toolbarReveal.setDuration(CIRCULAR_UNREVEAL_DURATION);
    toolbarReveal.setInterpolator(new AccelerateInterpolator());
    toolbarReveal.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    toolbarReveal.start();

    /**
     * Animate FloatingToolbar animation back to 6dp
     */
    anim = ObjectAnimator.ofFloat(this, View.TRANSLATION_Z, 0);
    anim.setDuration(CIRCULAR_UNREVEAL_DURATION);
    anim.setStartDelay(CIRCULAR_UNREVEAL_DELAY);
    anim.start();
}

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

@OnClick(R.id.fab)
  protected void save() {
      // show the save confirmation bubble
      fab.setVisibility(View.INVISIBLE);
      confirmSaveContainer.setVisibility(View.VISIBLE);
      resultsScrim.setVisibility(View.VISIBLE);

      // expand it once it's been measured and show a scrim over the search results
      confirmSaveContainer.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
          @Override//from w ww . j av  a 2  s.  com
          public boolean onPreDraw() {
              // expand the confirmation
              confirmSaveContainer.getViewTreeObserver().removeOnPreDrawListener(this);
              Animator reveal = ViewAnimationUtils.createCircularReveal(confirmSaveContainer,
                      confirmSaveContainer.getWidth() / 2, confirmSaveContainer.getHeight() / 2,
                      fab.getWidth() / 2, confirmSaveContainer.getWidth() / 2);
              reveal.setDuration(250L);
              reveal.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                      android.R.interpolator.fast_out_slow_in));
              reveal.start();

              // show the scrim
              int centerX = (fab.getLeft() + fab.getRight()) / 2;
              int centerY = (fab.getTop() + fab.getBottom()) / 2;
              Animator revealScrim = ViewAnimationUtils.createCircularReveal(resultsScrim, centerX, centerY, 0,
                      (float) Math.hypot(centerX, centerY));
              revealScrim.setDuration(400L);
              revealScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                      android.R.interpolator.linear_out_slow_in));
              revealScrim.start();
              ObjectAnimator fadeInScrim = ObjectAnimator.ofArgb(resultsScrim, ViewUtils.BACKGROUND_COLOR,
                      Color.TRANSPARENT, ContextCompat.getColor(SearchActivity.this, R.color.scrim));
              fadeInScrim.setDuration(800L);
              fadeInScrim.setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                      android.R.interpolator.linear_out_slow_in));
              fadeInScrim.start();

              // ease in the checkboxes
              saveDribbble.setAlpha(0.6f);
              saveDribbble.setTranslationY(saveDribbble.getHeight() * 0.4f);
              saveDribbble.animate().alpha(1f).translationY(0f).setDuration(200L).setInterpolator(AnimationUtils
                      .loadInterpolator(SearchActivity.this, android.R.interpolator.linear_out_slow_in));
              saveDesignerNews.setAlpha(0.6f);
              saveDesignerNews.setTranslationY(saveDesignerNews.getHeight() * 0.5f);
              saveDesignerNews.animate().alpha(1f).translationY(0f).setDuration(200L)
                      .setInterpolator(AnimationUtils.loadInterpolator(SearchActivity.this,
                              android.R.interpolator.linear_out_slow_in));
              return false;
          }
      });
  }

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.// w ww .j ava2  s .  c o  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.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 {//from w w  w  . ja va 2  s .  c  om
        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.justplay1.shoppist.features.search.widget.FloatingSearchView.java

private void fadeIn(boolean enter) {
    ValueAnimator backgroundAnim;/*from  w w  w  . j  ava 2  s .  co  m*/

    if (Build.VERSION.SDK_INT >= 19) {
        backgroundAnim = ObjectAnimator.ofInt(backgroundDrawable, "alpha", enter ? 255 : 0);
    } else {
        backgroundAnim = ValueAnimator.ofInt(enter ? 0 : 255, enter ? 255 : 0);
        backgroundAnim.addUpdateListener(animation -> {
            int value = (Integer) animation.getAnimatedValue();
            backgroundDrawable.setAlpha(value);
        });
    }

    backgroundAnim.setDuration(enter ? DEFAULT_DURATION_ENTER : DEFAULT_DURATION_EXIT);
    backgroundAnim.setInterpolator(enter ? DECELERATE : ACCELERATE);
    backgroundAnim.start();

    Drawable icon = unwrap(getIcon());

    if (icon != null) {
        ObjectAnimator iconAnim = ObjectAnimator.ofFloat(icon, "progress", enter ? 1 : 0);
        iconAnim.setDuration(backgroundAnim.getDuration());
        iconAnim.setInterpolator(backgroundAnim.getInterpolator());
        iconAnim.start();
    }
}

From source file:com.android.tv.menu.MenuLayoutManager.java

private ObjectAnimator createAlphaAnimator(View view, float from, float to, TimeInterpolator interpolator) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, from, to);
    animator.setDuration(mRowAnimationDuration);
    animator.setInterpolator(interpolator);
    return animator;
}

From source file:com.android.tv.menu.MenuLayoutManager.java

private ObjectAnimator createAlphaAnimator(View view, float from, float to, float end,
        TimeInterpolator interpolator) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, from, to);
    animator.setDuration(mRowAnimationDuration);
    animator.setInterpolator(interpolator);
    mPropertyValuesAfterAnimation.add(new ViewPropertyValueHolder(View.ALPHA, view, end));
    return animator;
}