Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

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

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

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

/**
 * @param timerToRemove the timer to be removed during the animation
 *///  w  w  w  .  ja v  a  2 s  .  c  o  m
private void animateTimerRemove(final Timer timerToRemove) {
    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(duration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            DataModel.getDataModel().removeTimer(timerToRemove);
            Events.sendTimerEvent(com.wizardsofm.deskclock.R.string.action_delete,
                    com.wizardsofm.deskclock.R.string.label_deskclock);
        }
    });

    final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1);
    fadeIn.setDuration(duration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(fadeOut).before(fadeIn);
    animatorSet.start();
}

From source file:com.zhangyp.higo.drawingboard.fragment.SketchFragment.java

private void init(Bitmap bitmap) {

    float scaleRatio = 1;

    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    float screenRatio = 1.0f;
    float imgRatio = (float) height / (float) width;
    if (imgRatio >= screenRatio) {
        //?// w  ww .  j  a va  2  s  . c o m

        scaleRatio = (float) mScreenWidth / (float) height;

    }

    if (imgRatio < screenRatio) {
        scaleRatio = (float) mScreenWidth / (float) width;

    }

    Matrix matrix = new Matrix();
    matrix.postScale(scaleRatio, scaleRatio);
    Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

    GPUImage gpuImage = new GPUImage(getActivity());
    gpuImage.setFilter(new GPUImageSketchFilter());
    final Bitmap grayBmp = gpuImage.getBitmapWithFilterApplied(dstbmp);

    ivBg.setImageBitmap(grayBmp);
    mSketchView.getBackground().setAlpha(150);

    ivBgColor.setImageBitmap(dstbmp);
    ObjectAnimator alpha = ObjectAnimator.ofFloat(ivBgColor, "alpha", 1.0f, 0.0f);
    alpha.setDuration(2000).start();

    btShowBg.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ObjectAnimator alpha = ObjectAnimator.ofFloat(ivBgColor, "alpha", 0.0f, 1.0f);
            alpha.setDuration(1000).start();

        }
    });
    btShowBgGray.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ObjectAnimator alpha = ObjectAnimator.ofFloat(ivBgColor, "alpha", 1.0f, 0.0f);
            alpha.setDuration(1000).start();

        }
    });

}

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  . j a v  a2s. c o  m*/
    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.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  w  w  .  j  a  v  a2  s  .com
 */
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 hideLollipopImpl() {
    int rootWidth = mRoot.getWidth();

    float controlX;

    if (mFabOriginalX > rootWidth / 2f) {
        controlX = mFabOriginalX * 0.98f;
    } else {//from   www .  ja  v  a2  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.stasbar.knowyourself.timer.TimerFragment.java

/**
 * @param timerToRemove the timer to be removed during the animation
 *///from   w w  w.j av  a2 s  .co  m
private void animateTimerRemove(final Timer timerToRemove) {
    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();

    final Animator fadeOut = ObjectAnimator.ofFloat(mViewPager, ALPHA, 1, 0);
    fadeOut.setDuration(duration);
    fadeOut.setInterpolator(new DecelerateInterpolator());
    fadeOut.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            LogUtils.d("animateTimerRemove");
            DataModel.getDataModel().removeTimer(timerToRemove);

        }
    });

    final Animator fadeIn = ObjectAnimator.ofFloat(mViewPager, ALPHA, 0, 1);
    fadeIn.setDuration(duration);
    fadeIn.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(fadeOut).before(fadeIn);
    animatorSet.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);//ww w  .  j  a  v  a 2s.  c om
    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.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

private void performNavigation(final PageHolder.Content content, final String chanName, final String boardName,
        final String threadNumber, final String postNumber, final String threadTitle, final String searchQuery,
        final boolean fromCache, boolean animated, final boolean returnable) {
    PageHolder pageHolder = pageManager.getCurrentPage();
    if (pageHolder != null && pageHolder.is(chanName, boardName, threadNumber, content)
            && searchQuery == null) {
        // Page could be deleted from stack during clearStack (when home button pressed, for example)
        pageHolder.returnable &= returnable;
        pageManager.moveCurrentPageTop();
        page.updatePageConfiguration(postNumber, threadTitle);
        drawerForm.invalidateItems(true, false);
        invalidateHomeUpState();//  www.j a v a 2s .  co  m
        return;
    }
    switchView(ListPage.ViewType.LIST, null);
    listView.getWrapper().cancelBusyState();
    listView.getWrapper().setPullSides(PullableWrapper.Side.NONE);
    ClickableToast.cancel(this);
    requestStoreExtraAndPosition();
    cleanupPage();
    handler.removeCallbacks(queuedHandler);
    setActionBarLocked(LOCKER_HANDLE, true);
    if (animated) {
        queuedHandler = () -> {
            queuedHandler = null;
            if (listView.getAnimation() != null) {
                listView.getAnimation().cancel();
            }
            listView.setAlpha(1f);
            handleDataAfterAnimation(content, chanName, boardName, threadNumber, postNumber, threadTitle,
                    searchQuery, fromCache, true, returnable);
        };
        handler.postDelayed(queuedHandler, 300);
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(listView, View.ALPHA, 1f, 0f);
        alphaAnimator.setupStartValues();
        alphaAnimator.setStartDelay(150);
        alphaAnimator.setDuration(150);
        startListAnimator(alphaAnimator);
    } else {
        handleDataAfterAnimation(content, chanName, boardName, threadNumber, postNumber, threadTitle,
                searchQuery, fromCache, false, returnable);
    }
}

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

/**
 * ??//from w  w  w . j av a  2s  . c o m
 */
final void initStatus() {
    if (mContentView == null) {
        return;
    }
    if ((mDefaultStatus == STATUS_SHRINK || mCalendarShowMode == CALENDAR_SHOW_MODE_ONLY_WEEK_VIEW)
            && mCalendarShowMode != CALENDAR_SHOW_MODE_ONLY_MONTH_VIEW) {
        post(new Runnable() {
            @Override
            public void run() {
                ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(mContentView, "translationY",
                        mContentView.getTranslationY(), -mContentViewTranslateY);
                objectAnimator.setDuration(0);
                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();
            }
        });
    } else {
        if (mDelegate.mViewChangeListener == null) {
            return;
        }
        post(new Runnable() {
            @Override
            public void run() {
                mDelegate.mViewChangeListener.onViewChange(true);
            }
        });
    }
}

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

/**
 * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView}
 * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer
 *      should be removed/*from   ww w  .  j a v  a  2  s .c  o m*/
 */
private void animateToView(View toView, final Timer timerToRemove) {
    if (mCurrentView == toView) {
        throw new IllegalStateException("toView is already the current view");
    }

    final boolean toTimers = toView == mTimersView;

    // Avoid double-taps by enabling/disabling the set of buttons active on the new view.
    updateFab(UpdateType.DISABLE_BUTTONS);

    final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration();
    final Animator rotateFrom = ObjectAnimator.ofFloat(mCurrentView, SCALE_X, 1, 0);
    rotateFrom.setDuration(duration);
    rotateFrom.setInterpolator(new DecelerateInterpolator());
    rotateFrom.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (timerToRemove != null) {
                DataModel.getDataModel().removeTimer(timerToRemove);
                Events.sendTimerEvent(com.wizardsofm.deskclock.R.string.action_delete,
                        com.wizardsofm.deskclock.R.string.label_deskclock);
            }

            mCurrentView.setScaleX(1);
            if (toTimers) {
                showTimersView(UpdateType.FAB_AND_BUTTONS_SHRINK_AND_EXPAND);
            } else {
                showCreateTimerView(UpdateType.FAB_AND_BUTTONS_SHRINK_AND_EXPAND);
            }
        }
    });

    final Animator rotateTo = ObjectAnimator.ofFloat(toView, SCALE_X, 0, 1);
    rotateTo.setDuration(duration);
    rotateTo.setInterpolator(new AccelerateInterpolator());

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(rotateFrom).before(rotateTo);
    animatorSet.start();
}