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.mahhaus.scanloto.ScannerActivity.java

private void showErrorMessageUiAnimated(String message) {
    if (lastErrorRecieved == 0) {
        // the cleanup takes care of removing the message after some time if the error did not show up again
        handler.post(errorMessageCleanup);
    }//  w ww .  j ava  2s .  com
    lastErrorRecieved = System.currentTimeMillis();
    if (errorMessageAnimator != null
            && (errorMessageAnimator.isRunning() || errorMessage.getText().equals(message))) {
        return;
    }

    errorMessageLayout.setVisibility(View.VISIBLE);
    errorMessage.setBackgroundColor(ContextCompat.getColor(this, R.color.anyline_blue_darker));
    errorMessage.setAlpha(0f);
    errorMessage.setText(message);
    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(getResources().getInteger(R.integer.error_message_delay));
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.start();
}

From source file:com.bar.foldinglayout.sample.FoldingLayoutActivity.java

/**
 * Animates the folding view inwards (to a completely folded state) from its
 * current state and then back out to its original state.
 *//*  w ww. j  a  v  a2 s. c  o m*/
public void animateFold() {
    float foldFactor = mFoldLayout.getFoldFactor();

    ObjectAnimator animator = ObjectAnimator.ofFloat(mFoldLayout, "foldFactor", foldFactor, 1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(1);
    animator.setDuration(FOLD_ANIMATION_DURATION);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.start();
}

From source file:com.igniva.filemanager.utils.Futils.java

public void revealShow(final View view, boolean reveal) {

    if (reveal) {
        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 0f, 1f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override//from   ww w .  j  av  a 2  s. c o m
            public void onAnimationStart(Animator animation) {
                view.setVisibility(View.VISIBLE);
            }
        });
        animator.start();
    } else {

        ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, 1f, 0f);
        animator.setDuration(300); //ms
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }
        });
        animator.start();

    }

}

From source file:com.grepsound.activities.MainActivity.java

/**
 * This method animates the image fragment into the background by both
 * scaling and rotating the fragment's view, as well as adding a
 * translucent dark hover view to inform the user that it is inactive.
 *//* w w  w  . j  av a 2s  .  c om*/
public void slideBack(Animator.AnimatorListener listener) {

    // Make sure Toolbar is visible
    mToolbar.setTranslationY(0);

    View movingFragmentView = mMainFrag.getView();

    PropertyValuesHolder rotateX = PropertyValuesHolder.ofFloat("rotationX", 40f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.8f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.8f);
    ObjectAnimator movingFragmentAnimator = ObjectAnimator.ofPropertyValuesHolder(movingFragmentView, rotateX,
            scaleX, scaleY);

    ObjectAnimator darkHoverViewAnimator = ObjectAnimator.ofFloat(mDarkHoverView, "alpha", 0.0f, 0.5f);

    ObjectAnimator movingFragmentRotator = ObjectAnimator.ofFloat(movingFragmentView, "rotationX", 0);
    movingFragmentRotator.setStartDelay(getResources().getInteger(R.integer.half_slide_up_down_duration));

    AnimatorSet s = new AnimatorSet();
    s.playTogether(movingFragmentAnimator, darkHoverViewAnimator, movingFragmentRotator);
    s.addListener(listener);
    s.start();
}

From source file:com.hannesdorfmann.FeedAdapter.java

private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) {
    final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView;
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override/*w w  w.  ja v a2 s. c  o  m*/
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target,
                boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                iv.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f,
                        1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        if (iv.getDrawable() != null) {
                            iv.getDrawable().setColorFilter(new ColorMatrixColorFilter(cm));
                        }
                    }
                });
                saturation.setDuration(2000);
                saturation.setInterpolator(
                        AnimationUtils.loadInterpolator(host, android.R.interpolator.fast_out_slow_in));
                saturation.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        iv.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length])
            .diskCacheStrategy(DiskCacheStrategy.ALL).into(new DribbbleTarget(iv, false));

    iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            iv.setTransitionName(iv.getResources().getString(R.string.transition_shot));
            iv.setBackgroundColor(ContextCompat.getColor(host, R.color.background_light));
            Intent intent = new Intent();
            intent.setClass(host, DribbbleShot.class);
            intent.putExtra(DribbbleShot.EXTRA_SHOT, shot);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host,
                    Pair.create(view, host.getString(R.string.transition_shot)),
                    Pair.create(view, host.getString(R.string.transition_shot_background)));
            host.startActivity(intent, options.toBundle());
        }
    });
}

From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java

public void drawSuccess() {
    mTarget = 100;// w w w  .  ja  va2  s .  c  o m

    final ObjectAnimator successAnim = ObjectAnimator.ofFloat(this, "flip", 1, -1);
    successAnim.setInterpolator(new OvershootInterpolator());
    successAnim.setDuration(ANIMATION_DURATION_BASE);

    ObjectAnimator anim = ObjectAnimator.ofFloat(this, "progress", getProgress(), mTarget);
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration((long) (ANIMATION_DURATION_BASE + Math.abs(mTarget * 10 - getProgress() * 10) / 2));
    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mState = State.STATE_SUCCESS;
            successAnim.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    anim.start();
}

From source file:com.mahhaus.scanloto.ScannerActivity.java

private void showHighlightErrorMessageUiAnimated(String message) {
    lastErrorRecieved = System.currentTimeMillis();
    errorMessageLayout.setVisibility(View.VISIBLE);
    errorMessage.setBackgroundColor(ContextCompat.getColor(this, R.color.anyline_red));
    errorMessage.setAlpha(0f);//from  w ww .ja  v a 2 s.  co  m
    errorMessage.setText(message);

    if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) {
        errorMessageAnimator.cancel();
    }

    errorMessageAnimator = ObjectAnimator.ofFloat(errorMessage, "alpha", 0f, 1f);
    errorMessageAnimator.setDuration(getResources().getInteger(R.integer.error_message_delay));
    errorMessageAnimator.setInterpolator(new DecelerateInterpolator());
    errorMessageAnimator.setRepeatMode(ValueAnimator.REVERSE);
    errorMessageAnimator.setRepeatCount(1);
    errorMessageAnimator.start();
}

From source file:com.berniesanders.fieldthebern.MainActivity.java

void animateShading(boolean show) {
    shading.setVisibility(View.VISIBLE);
    float toAlpha = show ? 1 : 0;
    ObjectAnimator.ofFloat(shading, "alpha", shading.getAlpha(), toAlpha).setDuration(100).start();
}

From source file:com.example.mike.birdalarm.ExpandingListView.java

/**
 * This method expands the view that was clicked and animates all the views
 * around it to make room for the expanding view. There are several steps
 * required to do this which are outlined below.
 * <p/>// w w w. j a va2  s  .c  om
 * 1. Store the current top and bottom bounds of each visible item in the
 * listview. 2. Update the layout parameters of the selected view. In the
 * context of this method, the view should be originally collapsed and set
 * to some custom height. The layout parameters are updated so as to wrap
 * the content of the additional text that is to be displayed.
 * <p/>
 * After invoking a layout to take place, the listview will order all the
 * items such that there is space for each view. This layout will be
 * independent of what the bounds of the items were prior to the layout so
 * two pre-draw passes will be made. This is necessary because after the
 * layout takes place, some views that were visible before the layout may
 * now be off bounds but a reference to these views is required so the
 * animation completes as intended.
 * <p/>
 * 3. The first predraw pass will set the bounds of all the visible items to
 * their original location before the layout took place and then force
 * another layout. Since the bounds of the cells cannot be set directly, the
 * method setSelectionFromTop can be used to achieve a very similar effect.
 * 4. The expanding view's bounds are animated to what the final values
 * should be from the original bounds. 5. The bounds above the expanding
 * view are animated upwards while the bounds below the expanding view are
 * animated downwards. 6. The extra text is faded in as its contents become
 * visible throughout the animation process.
 * <p/>
 * It is important to note that the listview is disabled during the
 * animation because the scrolling behaviour is unpredictable if the bounds
 * of the items within the listview are not constant during the scroll.
 */

public void expandView(final View view) {

    final Alarm viewObject = (Alarm) getItemAtPosition(getPositionForView(view));

    //        final CardListItem viewObject = (CardListItem) getItemAtPosition(getPositionForView(view));

    /* Store the original top and bottom bounds of all the cells. */
    final int oldTop = view.getTop();
    final int oldBottom = view.getBottom();

    final HashMap<View, int[]> oldCoordinates = new HashMap<>();

    int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        View v = getChildAt(i);
        ViewCompat.setHasTransientState(v, true);
        oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() });
    }

    /* Update the layout so the extra content becomes visible. */
    final View expandingLayout = view.findViewById(R.id.options_layout);
    expandingLayout.setVisibility(View.VISIBLE);

    /*
       * Add an onPreDraw Listener to the listview. onPreDraw will get invoked
     * after onLayout and onMeasure have run but before anything has been
     * drawn. This means that the final post layout properties for all the
     * items have already been determined, but still have not been rendered
     * onto the screen.
     */
    final ViewTreeObserver observer = getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            /* Determine if this is the first or second pass. */
            if (!mShouldRemoveObserver) {
                mShouldRemoveObserver = true;

                /*
                 * Calculate what the parameters should be for
                 * setSelectionFromTop. The ListView must be offset in a
                 * way, such that after the animation takes place, all the
                 * cells that remain visible are rendered completely by the
                 * ListView.
                 */
                int newTop = view.getTop();
                int newBottom = view.getBottom();

                int newHeight = newBottom - newTop;
                int oldHeight = oldBottom - oldTop;
                int delta = newHeight - oldHeight;

                mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, delta, true);

                int currentTop = view.getTop();
                int futureTop = oldTop - mTranslate[0];

                int firstChildStartTop = getChildAt(0).getTop();
                int firstVisiblePosition = getFirstVisiblePosition();
                int deltaTop = currentTop - futureTop;

                int i;
                int childCount = getChildCount();
                for (i = 0; i < childCount; i++) {
                    View v = getChildAt(i);
                    int height = v.getBottom() - Math.max(0, v.getTop());
                    if (deltaTop - height > 0) {
                        firstVisiblePosition++;
                        deltaTop -= height;
                    } else {
                        break;
                    }
                }

                if (i > 0) {
                    firstChildStartTop = 0;
                }

                setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop);

                /*
                 * Request another layout to update the layout parameters of
                 * the cells.
                 */
                requestLayout();

                /*
                 * Return false such that the ListView does not redraw its
                 * contents on this layout but only updates all the
                 * parameters associated with its children.
                 */
                return false;
            }

            /*
             * Remove the predraw listener so this method does not keep
             * getting called.
             */
            mShouldRemoveObserver = false;
            observer.removeOnPreDrawListener(this);

            int yTranslateTop = mTranslate[0];
            int yTranslateBottom = mTranslate[1];

            ArrayList<Animator> animations = new ArrayList<>();

            int index = indexOfChild(view);

            /*
             * Loop through all the views that were on the screen before the
             * cell was expanded. Some cells will still be children of the
             * ListView while others will not. The cells that remain
             * children of the ListView simply have their bounds animated
             * appropriately. The cells that are no longer children of the
             * ListView also have their bounds animated, but must also be
             * added to a list of views which will be drawn in dispatchDraw.
             */
            for (View v : oldCoordinates.keySet()) {
                int[] old = oldCoordinates.get(v);
                v.setTop(old[0]);
                v.setBottom(old[1]);
                if (v.getParent() == null) {
                    mViewsToDraw.add(v);
                    int delta = old[0] < oldTop ? -yTranslateTop : yTranslateBottom;
                    animations.add(getAnimation(v, delta, delta));
                } else {
                    int i = indexOfChild(v);
                    if (v != view) {
                        int delta = i > index ? yTranslateBottom : -yTranslateTop;
                        animations.add(getAnimation(v, delta, delta));
                    }
                    ViewCompat.setHasTransientState(v, false);
                }
            }

            /* Adds animation for expanding the cell that was clicked. */
            animations.add(getAnimation(view, -yTranslateTop, yTranslateBottom));

            /* Adds an animation for fading in the extra content. */
            animations.add(ObjectAnimator.ofFloat(view.findViewById(R.id.options_layout), View.ALPHA, 0, 1));

            /* Disabled the ListView for the duration of the animation. */
            setEnabled(false);
            setClickable(false);

            /*
             * Play all the animations created above together at the same
             * time.
             */
            AnimatorSet s = new AnimatorSet();
            s.playTogether(animations);
            s.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    viewObject.setExpandedState(true);
                    setEnabled(true);
                    setClickable(true);
                    if (mViewsToDraw.size() > 0) {
                        for (View v : mViewsToDraw) {
                            ViewCompat.setHasTransientState(v, false);
                        }
                    }
                    mViewsToDraw.clear();
                }
            });
            s.start();
            return true;
        }
    });
}

From source file:com.example.volunteerhandbook.MainActivity.java

void loop_what_I_thought() {
    thoughts = getResources().getStringArray(R.array.what_I_thought);
    int lines = thoughts.length / 4;
    container = (FrameLayout) findViewById(R.id.main_content_frame);
    LinearLayout[] textBox = new LinearLayout[3];
    endY = container.getHeight() - 100f;
    h = (float) container.getHeight();
    hBox = 0;// w ww . j av  a  2  s  . c o m
    /*
    for (int k=0; k<3; k++){
       textBox[k]=new LinearLayout(this);
       textBox[k].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    textBox[k].setOrientation(1);
    }
    */
    //LinearLayout tmp=(LinearLayout) getLayoutInflater().inflate(R.layout.one_line, null);
    //TextView  tmpTxt=(TextView)tmp.findViewById(R.id.oneLine);
    //tmp.removeView(tmpTxt);
    int[] color = new int[4];
    color[3] = Color.parseColor("#66FF66");
    color[1] = Color.parseColor("#FF9900");
    color[2] = Color.parseColor("#0099FF");
    color[0] = Color.parseColor("#00FF00");
    toMove = new TextView[thoughts.length];
    int textSize = 24;
    for (int i = 0; i < thoughts.length; i++) {
        toMove[i] = new TextView(this);
        toMove[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        toMove[i].setText(thoughts[i]);
        toMove[i].setTextSize(textSize);
        toMove[i].getPaint().setFakeBoldText(true);
        toMove[i].setTextColor(color[1] - 0x20202 * i);
        //textBox.addView(toMove);
    }
    int boxHeight = (lines + 1) * (int) (textSize * 1.5);
    for (int k = 0; k < 3; k++) {
        textBox[k].removeAllViews();
        for (int i = 0; i < thoughts.length / 4; i++) {
            TextView v = toMove[iTh++ % thoughts.length];
            v.setTextColor(color[k]);
            textBox[k].addView(v);
        }
        //toMove.setTranslationY(600);
        //container.addView(textBox);
        container.addView(textBox[k]);
        textBox[k].setX(20);
        textBox[k].setY(2 * boxHeight + hBox);
        hBox += boxHeight; //textBox[k].getHeight();
        float startY = textBox[k].getY();
        endY = (-1) * boxHeight;
        int duration = (int) (((startY - endY) / (3 * boxHeight)) * 20000);
        ValueAnimator bounceAnim = ObjectAnimator.ofFloat(textBox[k], "y", startY, endY);
        bounceAnim.setDuration(duration);
        bounceAnim.setInterpolator(new LinearInterpolator());
        final LinearLayout iBox = textBox[k];
        bounceAnim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                loopNewBox(iBox);
            }
        });
        bounceAnim.start();
    }

}