Example usage for android.view View animate

List of usage examples for android.view View animate

Introduction

In this page you can find the example usage for android.view View animate.

Prototype

public ViewPropertyAnimator animate() 

Source Link

Document

This method returns a ViewPropertyAnimator object, which can be used to animate specific properties on this View.

Usage

From source file:org.starfishrespect.myconsumption.android.ui.BaseActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    setupNavDrawer();/*w ww  . ja v  a 2s .  c om*/

    View mainContent = findViewById(R.id.main_content);
    if (mainContent != null) {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    } else {
        LOGW(TAG, "No view with ID main_content to fade in.");
    }
}

From source file:android.example.com.animationdemos.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 *//*from  w  w w  . j  a v  a2s . c o m*/
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;
    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);
    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
    // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility
    // to GONE as an optimization step (it won't participate in layout passes, etc.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        view.animate().translationX(0);
    }//from   ww  w.jav  a  2  s.  c  o m
    if (deltaY != 0) {
        view.animate().translationY(0);
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    mMoveAnimations.add(holder);
    final ViewPropertyAnimator animation = view.animate();
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animator) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            View mView = view;
            if (animator instanceof ObjectAnimator) {
                mView = (View) ((ObjectAnimator) animator).getTarget();
            }
            if (deltaX != 0) {
                mView.setTranslationX(0);
            }
            if (deltaY != 0) {
                mView.setTranslationY(0);
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}

From source file:com.sorin.medisync.map.InfoMapActivity.java

/**
 * Invoked by the "Get Address" button. Get the address of the current
 * location, using reverse geocoding. This only works if a geocoding service
 * is available.//from w w  w  .  ja v  a  2s  . c om
 * 
 * @param v
 *            The view object associated with this method, in this case a
 *            Button.
 */
// For Eclipse with ADT, suppress warnings about Geocoder.isPresent()
@SuppressLint("NewApi")
public void getAddress(View v) {
    boolean on = ((ToggleButton) v).isChecked();
    if (on) {
        v.animate().translationX(TX_END).translationY(TY_END);
        // In Gingerbread and later, use Geocoder.isPresent() to see if a
        // geocoder is available.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && !Geocoder.isPresent()) {
            // No geocoder is present. Issue an error message
            Toast.makeText(this, R.string.no_geocoder_available, Toast.LENGTH_LONG).show();
            return;
        }

        // Get the current location
        Location currentLocation = mLocationClient.getLastLocation();

        // Turn the indefinite activity indicator on
        mActivityIndicator.setVisibility(View.VISIBLE);

        // Start the background task
        (new InfoMapActivity.GetAddressTask(this)).execute(currentLocation);
    } else {
        v.animate().translationX(TX_START).translationY(TY_START);
        // Turn the indefinite activity indicator on
        mActivityIndicator.setVisibility(View.INVISIBLE);

        // Start the background task
        mAddress.setText("No address updates");
    }
}

From source file:cn.androidy.materialdesignsample.animations.CrossfadeActivity.java

/**
 * Cross-fades between {@link #mContentView} and {@link #mLoadingView}.
 *//*from   w ww.  j  ava  2s  .  c  o  m*/
private void showContentOrLoadingIndicator(boolean contentLoaded) {
    // Decide which view to hide and which to show.
    final View showView = contentLoaded ? mContentView : mLoadingView;
    final View hideView = contentLoaded ? mLoadingView : mContentView;

    // Set the "show" view to 0% opacity but visible, so that it is visible
    // (but fully transparent) during the animation.
    showView.setAlpha(0f);
    showView.setVisibility(View.VISIBLE);

    // Animate the "show" view to 100% opacity, and clear any animation listener set on
    // the view. Remember that listeners are not limited to the specific animation
    // describes in the chained method calls. Listeners are set on the
    // ViewPropertyAnimator object for the view, which persists across several
    // animations.
    showView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);

    // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility
    // to GONE as an optimization step (it won't participate in layout passes, etc.)
    hideView.animate().alpha(0f).setDuration(mShortAnimationDuration)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    hideView.setVisibility(View.GONE);
                }
            });
}

From source file:com.waz.zclient.pages.main.conversation.SingleImageFragment.java

private void fadeView(final View view, final boolean fadeIn) {
    isFading = true;/*  ww w.j av  a  2s.  c  om*/
    float toAlpha = fadeIn ? 1f : 0f;

    view.setClickable(fadeIn);
    view.animate().alpha(toAlpha).setInterpolator(new Quart.EaseOut())
            .setDuration(getResources().getInteger(R.integer.single_image_message__overlay__fade_duration))
            .withStartAction(new Runnable() {
                @Override
                public void run() {
                    if (fadeIn) {
                        view.setVisibility(View.VISIBLE);
                    }
                }
            }).withEndAction(new Runnable() {
                @Override
                public void run() {
                    if (!fadeIn) {
                        view.setVisibility(View.GONE);
                    }
                    isFading = false;
                }
            }).start();
}

From source file:edward.com.recyclerview.BaseItemAnimator.java

@Override
public void endAnimation(ViewHolder item) {
    final View view = item.itemView;
    // this will trigger end callback which should set properties to their target values.
    view.animate().cancel();
    // TODO if some other animations are chained to end, how do we cancel them as well?
    for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
        MoveInfo moveInfo = mPendingMoves.get(i);
        if (moveInfo.holder == item) {
            view.setTranslationY(0);/* ww  w  . ja v  a  2 s .  c  om*/
            view.setTranslationX(0);
            dispatchMoveFinished(item);
            mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(mPendingChanges, item);
    if (mPendingRemovals.remove(item)) {
        reset(item.itemView);
        dispatchRemoveFinished(item);
    }
    if (mPendingAdditions.remove(item)) {
        reset(item.itemView);
        dispatchAddFinished(item);
    }

    for (int i = mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            mChangesList.remove(i);
        }
    }
    for (int i = mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = mMovesList.get(i);
        for (int j = moves.size() - 1; j >= 0; j--) {
            MoveInfo moveInfo = moves.get(j);
            if (moveInfo.holder == item) {
                view.setTranslationY(0);
                view.setTranslationX(0);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    mMovesList.remove(i);
                }
                break;
            }
        }
    }
    for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = mAdditionsList.get(i);
        if (additions.remove(item)) {
            reset(item.itemView);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                mAdditionsList.remove(i);
            }
        }
    }

    // animations should be ended by the cancel above.
    if (mRemoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mRemoveAnimations list");
    }

    if (mAddAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mAddAnimations list");
    }

    if (mChangeAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mChangeAnimations list");
    }

    if (mMoveAnimations.remove(item) && DEBUG) {
        throw new IllegalStateException(
                "after animation is cancelled, item should not be in " + "mMoveAnimations list");
    }
    dispatchFinishedWhenDone();
}

From source file:com.mobimvp.cliques.ui.BaseActivity.java

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    setupNavDrawer();/*from   ww  w  . j  a  v  a2s. c o  m*/
    trySetupSwipeRefresh();
    updateSwipeRefreshProgressBarTop();
    View mainContent = findViewById(R.id.main_content);
    if (mainContent != null) {
        mainContent.setAlpha(0);
        mainContent.animate().alpha(1).setDuration(MAIN_CONTENT_FADEIN_DURATION);
    } else {
        LOGW(TAG, "No view with ID main_content to fade in.");
    }
}

From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int top;/*  w  ww .  ja va 2s .c o m*/
    int left;
    int offsetTop;

    Line lastSelectedLine = findLastSelectedLine();
    Line firstSelectedLine = findFirstSelectedLine();

    for (int i = 0; i < mLines.size(); i++) {
        Line line = mLines.get(i);
        List<Item> items = line.getItems();
        left = getPaddingLeft() + mActionBar.getContentPadding();

        if (firstSelectedLine != null && firstSelectedLine.index > line.index) {
            offsetTop = -mActionBarTopHeight;
        } else if (lastSelectedLine != null && lastSelectedLine.index < line.index) {
            offsetTop = mActionBarBottomHeight;
        } else {
            offsetTop = 0;
        }

        for (int j = 0; j < items.size(); j++) {
            Item item = items.get(j);
            top = getPaddingTop() + i * (item.height + mLineSpace) + offsetTop + mActionBarTopHeight;
            View child = item.view;
            int oldTop = child.getTop();
            child.layout(left, top, left + child.getMeasuredWidth(), top + child.getMeasuredHeight());
            if (oldTop != top) {
                int translationY = oldTop - top;
                child.setTranslationY(translationY);
                child.animate().translationYBy(-translationY).setDuration(200).start();
            }
            left += child.getMeasuredWidth() + mItemSpace;
        }
    }

    if (firstSelectedLine != null && lastSelectedLine != null) {
        mActionBar.setVisibility(View.VISIBLE);
        mActionBar.setAlpha(1);
        int oldTop = mActionBar.getTop();
        int actionBarTop = firstSelectedLine.index * (firstSelectedLine.getHeight() + mLineSpace)
                + getPaddingTop();
        mActionBar.layout(getPaddingLeft(), actionBarTop, getPaddingLeft() + mActionBar.getMeasuredWidth(),
                actionBarTop + mActionBar.getMeasuredHeight());
        if (oldTop != actionBarTop) {
            int translationY = oldTop - actionBarTop;
            mActionBar.setTranslationY(translationY);
            mActionBar.animate().translationYBy(-translationY).setDuration(200).start();
        }
    } else {
        if (mActionBar.getVisibility() == View.VISIBLE) {
            mActionBar.animate().alpha(0).setDuration(200).setListener(mActionBarAnimationListener).start();
        }
    }
}

From source file:com.malmstein.materialanimations.elevation.ElevationDragFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_ztranslation, container, false);

    /* Find the {@link View} to apply z-translation to. */
    final View floatingShape = rootView.findViewById(R.id.circle);

    /* Define the shape of the {@link View}'s shadow by setting one of the {@link Outline}s. */
    floatingShape.setOutlineProvider(mOutlineProviderCircle);

    /* Clip the {@link View} with its outline. */
    floatingShape.setClipToOutline(true);

    DragFrameLayout dragLayout = ((DragFrameLayout) rootView.findViewById(R.id.main_layout));

    dragLayout.setDragFrameController(new DragFrameLayout.DragFrameLayoutController() {

        @Override/*from w  w w. ja  v a 2  s .  c  o m*/
        public void onDragDrop(boolean captured) {
            /* Animate the translation of the {@link View}. Note that the translation
             is being modified, not the elevation. */
            floatingShape.animate().translationZ(captured ? 50 : 0).scaleX(1.2f).scaleY(1.3f).setDuration(100);
            Log.d(TAG, captured ? "Drag" : "Drop");
        }
    });

    dragLayout.addDragView(floatingShape);

    /* Raise the circle in z when the "z+" button is clicked. */
    rootView.findViewById(R.id.raise_bt).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mElevation += mElevationStep;
            Log.d(TAG, String.format("Elevation: %.1f", mElevation));
            floatingShape.setElevation(mElevation);
        }
    });

    /* Lower the circle in z when the "z-" button is clicked. */
    rootView.findViewById(R.id.lower_bt).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mElevation -= mElevationStep;
            // Don't allow for negative values of Z.
            if (mElevation < 0) {
                mElevation = 0;
            }
            Log.d(TAG, String.format("Elevation: %.1f", mElevation));
        }
    });

    return rootView;
}