Example usage for android.animation ObjectAnimator start

List of usage examples for android.animation ObjectAnimator start

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

/**
 * Animate the bounce back of the given item.
 *///w w w. j a  va 2 s  .  c  om
private void animateRestore(final ConversationListItemView itemView, final float velocityX) {
    onSwipeAnimationStart(itemView);

    final float translationX = itemView.getSwipeTranslationX();
    final long duration;
    if (velocityX != 0 // Has velocity.
            && velocityX > 0 != translationX > 0) { // Right direction.
        duration = calculateTranslationDuration(translationX, velocityX);
    } else {
        duration = mDefaultRestoreAnimationDuration;
    }
    final ObjectAnimator animator = getSwipeTranslationXAnimator(itemView, 0f, duration,
            UiUtils.DEFAULT_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            onSwipeAnimationEnd(itemView);
        }
    });
    animator.start();
}

From source file:com.simas.vc.MainActivity.java

/**
 * Adds helper tooltips if they haven't yet been closed. Must be called after the toolbar is
 * set.//from   w w  w  .jav a 2 s .co  m
 */
private void addTooltips() {
    getToolbar().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop,
                int oldRight, int oldBottom) {
            View concat = mToolbar.findViewById(R.id.action_concat);
            View add = mToolbar.findViewById(R.id.action_add_item);
            if (concat != null && add != null) {
                add.setOnClickListener(new View.OnClickListener() {
                    private boolean mRotated;

                    @Override
                    public void onClick(View v) {
                        ObjectAnimator animator = ObjectAnimator.ofFloat(v, "rotation",
                                (mRotated = !mRotated) ? 360 : 0);
                        animator.setDuration(300);
                        animator.start();
                    }
                });
                new Tooltip(MainActivity.this, concat, Utils.getString(R.string.help_concatenate));
                new Tooltip(MainActivity.this, add, Utils.getString(R.string.help_add_item));
                mToolbar.removeOnLayoutChangeListener(this);
            }
        }
    });
    // Force re-draw
    getToolbar().requestLayout();
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

/**
 * Animate the dismissal of the given item.
 *//*from  w w  w .ja  v  a2  s. c o  m*/
private void animateDismiss(final ConversationListItemView itemView, final int swipeDirection,
        final float velocityX) {
    Assert.isTrue(swipeDirection != SWIPE_DIRECTION_NONE);

    onSwipeAnimationStart(itemView);

    final float animateTo = (swipeDirection == SWIPE_DIRECTION_RIGHT) ? mRecyclerView.getWidth()
            : -mRecyclerView.getWidth();
    final long duration;
    if (velocityX != 0) {
        final float deltaX = animateTo - itemView.getSwipeTranslationX();
        duration = calculateTranslationDuration(deltaX, velocityX);
    } else {
        duration = mDefaultDismissAnimationDuration;
    }

    final ObjectAnimator animator = getSwipeTranslationXAnimator(itemView, animateTo, duration,
            UiUtils.DEFAULT_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(final Animator animation) {
            onSwipeAnimationEnd(itemView);
        }
    });
    animator.start();
}

From source file:com.example.customview.DynamicListView.java

/**
 * This method determines whether the hover cell has been shifted far enough
 * to invoke a cell swap. If so, then the respective cell swap candidate is
 * determined and the data set is changed. Upon posting a notification of the
 * data set change, a layout is invoked to place the cells in the right place.
 * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
 * offset the cell being swapped to where it previously was and then animate it to
 * its new position.//from   www .ja va2  s.com
 */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;

    View belowView = getViewForID(mBelowItemId);
    View mobileView = getViewForID(mMobileItemId);
    View aboveView = getViewForID(mAboveItemId);

    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());

    if (isBelow || isAbove) {

        final long switchItemID = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView);

        if (switchView == null) {
            updateNeighborViewsForID(mMobileItemId);
            return;
        }

        if (getPositionForView(switchView) == mPanelList.size() - 1) {
            return;
        }
        swapElements(mPanelList, originalItem, getPositionForView(switchView));

        ((BaseAdapter) getAdapter()).notifyDataSetChanged();
        mDownY = mLastEventY;

        final int switchViewStartTop = switchView.getTop();

        mobileView.setVisibility(View.VISIBLE);
        switchView.setVisibility(View.INVISIBLE);

        updateNeighborViewsForID(mMobileItemId);

        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);

                View switchView = getViewForID(switchItemID);

                mTotalOffset += deltaY;

                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;

                switchView.setTranslationY(delta);

                ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, View.TRANSLATION_Y, 0);
                animator.setDuration(MOVE_DURATION);
                animator.start();

                return true;
            }
        });
    }
}

From source file:com.cuelogic.android.WheelIndicatorView.java

public void startItemsAnimation() {
    ObjectAnimator animation = ObjectAnimator.ofInt(WheelIndicatorView.this, "filledPercent", 0, filledPercent);
    animation.setDuration(ANIMATION_DURATION);
    animation.setInterpolator(PathInterpolatorCompat.create(0.4F, 0.0F, 0.2F, 1.0F));
    animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//  w  ww. jav  a  2s .co  m
        public void onAnimationUpdate(ValueAnimator animation) {
            recalculateItemsAngles();
            invalidate();
        }
    });
    animation.start();
}

From source file:android.improving.utils.views.PagerSlidingTabStrip.java

/**
 *  text animation/*from   w w w  .j  a  va 2  s  . c  om*/
 * @param view
 * @param color1
 * @param color2
 */
private void animTextColor(TextView view, int color1, int color2) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        view.setTextColor(color2);
    } else {
        if (color1 == color2) {
            view.setTextColor(color2);
        } else {
            ObjectAnimator backgroundColorAnimator = ObjectAnimator.ofObject(view, CHANGECOLORSTRING,
                    new ArgbEvaluator(), color1, color2);
            backgroundColorAnimator.setDuration(100);
            backgroundColorAnimator.start();
        }
    }

}

From source file:ucsc.hci.rankit.DynamicListView.java

/**
 * This method determines whether the hover cell has been shifted far enough
 * to invoke a cell swap. If so, then the respective cell swap candidate is
 * determined and the data set is changed. Upon posting a notification of the
 * data set change, a layout is invoked to place the cells in the right place.
 * Using a ViewTreeObserver and a corresponding OnPreDrawListener, we can
 * offset the cell being swapped to where it previously was and then animate it to
 * its new position.//from  w  w  w. j av a  2s.com
 */
private void handleCellSwitch() {
    final int deltaY = mLastEventY - mDownY;
    int deltaYTotal = mHoverCellOriginalBounds.top + mTotalOffset + deltaY;

    View belowView = getViewForID(mBelowItemId);
    View mobileView = getViewForID(mMobileItemId);
    View aboveView = getViewForID(mAboveItemId);

    boolean isBelow = (belowView != null) && (deltaYTotal > belowView.getTop());
    boolean isAbove = (aboveView != null) && (deltaYTotal < aboveView.getTop());

    if (isBelow || isAbove) {

        final long switchItemID = isBelow ? mBelowItemId : mAboveItemId;
        View switchView = isBelow ? belowView : aboveView;
        final int originalItem = getPositionForView(mobileView);

        if (switchView == null) {
            updateNeighborViewsForID(mMobileItemId);
            return;
        }

        swapElements(mObjectList, originalItem, getPositionForView(switchView));

        ((BaseAdapter) getAdapter()).notifyDataSetChanged();

        mDownY = mLastEventY;

        final int switchViewStartTop = switchView.getTop();

        //   if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.KITKAT) {
        mobileView.setVisibility(View.VISIBLE);
        switchView.setVisibility(View.INVISIBLE);
        //   }
        //   else {
        //       mobileView.setVisibility(View.INVISIBLE);
        //       switchView.setVisibility(View.VISIBLE);
        //   }

        updateNeighborViewsForID(mMobileItemId);

        final ViewTreeObserver observer = getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);

                View switchView = getViewForID(switchItemID);

                mTotalOffset += deltaY;

                int switchViewNewTop = switchView.getTop();
                int delta = switchViewStartTop - switchViewNewTop;

                switchView.setTranslationY(delta);

                ObjectAnimator animator = ObjectAnimator.ofFloat(switchView, View.TRANSLATION_Y, 0);
                animator.setDuration(MOVE_DURATION);
                animator.start();

                return true;
            }
        });
    }
}

From source file:com.evandroid.musica.fragment.LocalLyricsFragment.java

public void animateUndo(Lyrics[] lyricsArray) {
    final HashMap<Long, Integer> itemIdTopMap = new HashMap<>();
    int firstVisiblePosition = megaListView.getFirstVisiblePosition();
    for (int i = 0; i < megaListView.getChildCount(); ++i) {
        View child = megaListView.getChildAt(i);
        int position = firstVisiblePosition + i;
        long itemId = megaListView.getAdapter().getItemId(position);
        itemIdTopMap.put(itemId, child.getTop());
    }/*from   w  ww. j  ava2s . co m*/
    final boolean[] firstAnimation = { true };
    // Delete the item from the adapter
    final int groupPosition = ((LocalAdapter) getExpandableListAdapter()).add(lyricsArray[0]);
    megaListView.setAdapter(getExpandableListAdapter());
    megaListView.post(new Runnable() {
        @Override
        public void run() {
            megaListView.expandGroupWithAnimation(groupPosition);
        }
    });
    new WriteToDatabaseTask(LocalLyricsFragment.this).execute(LocalLyricsFragment.this, null, lyricsArray);

    final ViewTreeObserver[] observer = { megaListView.getViewTreeObserver() };
    observer[0].addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        public boolean onPreDraw() {
            observer[0].removeOnPreDrawListener(this);
            firstAnimation[0] = true;
            int firstVisiblePosition = megaListView.getFirstVisiblePosition();
            for (int i = 0; i < megaListView.getChildCount(); ++i) {
                final View child = megaListView.getChildAt(i);
                int position = firstVisiblePosition + i;
                long itemId = getListView().getAdapter().getItemId(position);
                Integer formerTop = itemIdTopMap.get(itemId);
                int newTop = child.getTop();
                if (formerTop != null) {
                    if (formerTop != newTop) {
                        int delta = formerTop - newTop;
                        child.setTranslationY(delta);
                        int MOVE_DURATION = 500;
                        child.animate().setDuration(MOVE_DURATION).translationY(0);
                        if (firstAnimation[0]) {
                            child.animate().setListener(new AnimatorActionListener(new Runnable() {
                                public void run() {
                                    mBackgroundContainer.hideBackground();
                                    mSwiping = false;
                                    getListView().setEnabled(true);
                                }
                            }, AnimatorActionListener.ActionType.END));
                            firstAnimation[0] = false;
                        }
                    }
                } else {
                    // Animate new views along with the others. The catch is that they did not
                    // exist in the start state, so we must calculate their starting position
                    // based on neighboring views.
                    int childHeight = child.getHeight() + megaListView.getDividerHeight();
                    formerTop = newTop - childHeight;
                    int delta = formerTop - newTop;
                    final float z = ((CardView) child).getCardElevation();
                    ((CardView) child).setCardElevation(0f);
                    child.setTranslationY(delta);
                    final int MOVE_DURATION = 500;
                    child.animate().setDuration(MOVE_DURATION).translationY(0);
                    child.animate().setListener(new AnimatorActionListener(new Runnable() {
                        public void run() {
                            mBackgroundContainer.hideBackground();
                            mSwiping = false;
                            getListView().setEnabled(true);
                            ObjectAnimator anim = ObjectAnimator.ofFloat(child, "cardElevation", 0f, z);
                            anim.setDuration(200);
                            anim.setInterpolator(new AccelerateInterpolator());
                            anim.start();
                        }
                    }, AnimatorActionListener.ActionType.END));
                    firstAnimation[0] = false;
                }
            }
            if (firstAnimation[0]) {
                mBackgroundContainer.hideBackground();
                mSwiping = false;
                getListView().setEnabled(true);
                firstAnimation[0] = false;
            }
            itemIdTopMap.clear();
            return true;
        }
    });
}

From source file:com.money.manager.ex.fragment.HomeFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    MainActivity mainActivity = null;//www. j  av a 2  s  . com
    if (getActivity() != null && getActivity() instanceof MainActivity)
        mainActivity = (MainActivity) getActivity();

    switch (loader.getId()) {
    case ID_LOADER_USER_NAME:
        if (data != null && data.moveToFirst()) {
            while (data.isAfterLast() == false) {
                String infoValue = data.getString(data.getColumnIndex(infoTable.INFONAME));
                // save into preferences username and basecurrency id
                if (Constants.INFOTABLE_USERNAME.equalsIgnoreCase(infoValue)) {
                    application.setUserName(data.getString(data.getColumnIndex(infoTable.INFOVALUE)));
                } else if (Constants.INFOTABLE_BASECURRENCYID.equalsIgnoreCase(infoValue)) {
                    //application.setBaseCurrencyId(data.getInt(data.getColumnIndex(infoTable.INFOVALUE)));
                }
                data.moveToNext();
            }
        }
        // show username
        if (!TextUtils.isEmpty(application.getUserName()))
            ((SherlockFragmentActivity) getActivity()).getSupportActionBar()
                    .setSubtitle(application.getUserName());
        // set user name on drawer
        if (mainActivity != null)
            mainActivity.setDrawableUserName(application.getUserName());

        break;

    case ID_LOADER_ACCOUNT_BILLS:
        double curTotal = 0, curReconciled = 0;
        AccountBillsAdapter adapter = null;

        linearHome.setVisibility(data != null && data.getCount() > 0 ? View.VISIBLE : View.GONE);
        linearWelcome.setVisibility(linearHome.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);

        // cycle cursor
        if (data != null && data.moveToFirst()) {
            while (data.isAfterLast() == false) {
                curTotal += data.getDouble(data.getColumnIndex(QueryAccountBills.TOTALBASECONVRATE));
                curReconciled += data.getDouble(data.getColumnIndex(QueryAccountBills.RECONCILEDBASECONVRATE));
                data.moveToNext();
            }
            // create adapter
            adapter = new AccountBillsAdapter(getActivity(), data);
        }
        // write accounts total
        txtTotalAccounts.setText(currencyUtils.getBaseCurrencyFormatted(curTotal));
        // manage footer listview
        if (linearFooter == null) {
            linearFooter = (LinearLayout) getActivity().getLayoutInflater().inflate(R.layout.item_account_bills,
                    null);
            // textview into layout
            txtFooterSummary = (TextView) linearFooter.findViewById(R.id.textVievItemAccountTotal);
            txtFooterSummaryReconciled = (TextView) linearFooter
                    .findViewById(R.id.textVievItemAccountTotalReconciled);
            // set text
            TextView txtTextSummary = (TextView) linearFooter.findViewById(R.id.textVievItemAccountName);
            txtTextSummary.setText(R.string.summary);
            // invisibile image
            ImageView imgSummary = (ImageView) linearFooter.findViewById(R.id.imageViewAccountType);
            imgSummary.setVisibility(View.INVISIBLE);
            // set color textview
            txtTextSummary.setTextColor(Color.GRAY);
            txtFooterSummary.setTextColor(Color.GRAY);
            txtFooterSummaryReconciled.setTextColor(Color.GRAY);
        }
        // remove footer
        lstAccountBills.removeFooterView(linearFooter);
        // set text
        txtFooterSummary.setText(txtTotalAccounts.getText());
        txtFooterSummaryReconciled.setText(currencyUtils.getBaseCurrencyFormatted(curReconciled));
        // add footer
        lstAccountBills.addFooterView(linearFooter, null, false);
        // set adapter and shown
        lstAccountBills.setAdapter(adapter);
        setListViewAccountBillsVisible(true);
        // set total accounts in drawer
        if (mainActivity != null) {
            mainActivity.setDrawableTotalAccounts(txtTotalAccounts.getText().toString());
        }
        break;

    case ID_LOADER_BILL_DEPOSITS:
        mainActivity.setDrawableRepeatingTransactions(data != null ? data.getCount() : 0);
        break;

    case ID_LOADER_INCOME_EXPENSES:
        double income = 0, expenses = 0;
        if (data != null && data.moveToFirst()) {
            while (!data.isAfterLast()) {
                expenses = data.getDouble(data.getColumnIndex(QueryReportIncomeVsExpenses.Expenses));
                income = data.getDouble(data.getColumnIndex(QueryReportIncomeVsExpenses.Income));
                //move to next record
                data.moveToNext();
            }
        }
        TextView txtIncome = (TextView) getActivity().findViewById(R.id.textViewIncome);
        TextView txtExpenses = (TextView) getActivity().findViewById(R.id.textViewExpenses);
        TextView txtDifference = (TextView) getActivity().findViewById(R.id.textViewDifference);
        // set value
        if (txtIncome != null)
            txtIncome.setText(currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(), income));
        if (txtExpenses != null)
            txtExpenses.setText(
                    currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(), Math.abs(expenses)));
        if (txtDifference != null)
            txtDifference.setText(currencyUtils.getCurrencyFormatted(currencyUtils.getBaseCurrencyId(),
                    income - Math.abs(expenses)));
        // manage progressbar
        final ProgressBar barIncome = (ProgressBar) getActivity().findViewById(R.id.progressBarIncome);
        final ProgressBar barExpenses = (ProgressBar) getActivity().findViewById(R.id.progressBarExpenses);

        if (barIncome != null && barExpenses != null) {
            barIncome.setMax((int) (Math.abs(income) + Math.abs(expenses)));
            barExpenses.setMax((int) (Math.abs(income) + Math.abs(expenses)));

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                ObjectAnimator animationIncome = ObjectAnimator.ofInt(barIncome, "progress",
                        (int) Math.abs(income));
                animationIncome.setDuration(1000); // 0.5 second
                animationIncome.setInterpolator(new DecelerateInterpolator());
                animationIncome.start();

                ObjectAnimator animationExpenses = ObjectAnimator.ofInt(barExpenses, "progress",
                        (int) Math.abs(expenses));
                animationExpenses.setDuration(1000); // 0.5 second
                animationExpenses.setInterpolator(new DecelerateInterpolator());
                animationExpenses.start();
            } else {
                barIncome.setProgress((int) Math.abs(income));
                barExpenses.setProgress((int) Math.abs(expenses));
            }
        }
    }
}

From source file:cn.hjl.newspush.mvp.ui.activities.NewsPhotoDetailActivity.java

private void startAnimation(final int endState, float startValue, float endValue) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(mPhotoDetailTitleTv, "alpha", startValue, endValue)
            .setDuration(200);//ww w  . j ava  2  s.  c om
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mPhotoDetailTitleTv.setVisibility(endState);
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animator.start();
}