Example usage for android.animation ObjectAnimator setDuration

List of usage examples for android.animation ObjectAnimator setDuration

Introduction

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

Prototype

@Override
@NonNull
public ObjectAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

From source file:de.baumann.thema.RequestActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.request_grid);
    switcherLoad = (ViewSwitcher) findViewById(R.id.viewSwitcherLoadingMain);
    context = this;

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }/*from  w w  w.  j  av a  2s. c o m*/

    if (savedInstanceState == null) {

        //Loading Logo Animation
        ImageView logo = (ImageView) findViewById(R.id.imageViewLogo);
        ObjectAnimator logoAni = (ObjectAnimator) AnimatorInflater.loadAnimator(context,
                R.animator.request_flip);
        logoAni.setRepeatCount(Animation.INFINITE);
        logoAni.setRepeatMode(Animation.RESTART);
        logoAni.setTarget(logo);
        logoAni.setDuration(2000);
        logoAni.start();

        taskList.execute();
    } else {
        populateView(list_activities_final);
        switcherLoad.showNext();
    }
}

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);//w ww  .j  a  va  2 s  . 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.gsoc.ijosa.liquidgalaxycontroller.PW.NearbyBeaconsFragment.java

private void showListView() {
    if (getListView() != null) {
        if (getListView().getVisibility() == View.VISIBLE) {
            return;
        }/*from  w  w  w . j av a 2 s .  c om*/

        mSwipeRefreshWidget.setRefreshing(false);
        getListView().setAlpha(0f);
        getListView().setVisibility(View.VISIBLE);
        safeNotifyChange();
        ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(getListView(), "alpha", 0f, 1f);
        alphaAnimation.setDuration(400);
        alphaAnimation.setInterpolator(new DecelerateInterpolator());
        alphaAnimation.addListener(new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mScanningAnimationTextView.setAlpha(0f);
                mScanningAnimationDrawable.stop();
                arrowDownLayout.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }
        });
        alphaAnimation.start();
    }
}

From source file:com.example.google.maps.flyover.MainActivity.java

public void animateRoute() {
    LinkedList<Animator> animators = new LinkedList<Animator>();

    // For each segment of the route, create one heading adjustment animator
    // and one segment fly-over animator.
    for (int i = 0; i < ROUTE.length - 1; i++) {
        // If it the first segment, ensure the camera is rotated properly.
        float h1;
        if (i == 0) {
            h1 = mMap.getCameraPosition().bearing;
        } else {//from  w  w  w.ja  v a  2s. c  o m
            h1 = (float) SphericalUtil.computeHeading(ROUTE[i - 1], ROUTE[i]);
        }

        float h2 = (float) SphericalUtil.computeHeading(ROUTE[i], ROUTE[i + 1]);

        ValueAnimator va = ValueAnimator.ofFloat(h1, h2);
        va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float bearing = (Float) animation.getAnimatedValue();
                CameraPosition pos = CameraPosition.builder(mMap.getCameraPosition()).bearing(bearing).build();
                mMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
            }
        });

        // Use the change in degrees of the heading for the animation
        // duration.
        long d = Math.round(Math.abs(h1 - h2));
        va.setDuration(d * CAMERA_HEADING_CHANGE_RATE);
        animators.add(va);

        ObjectAnimator oa = ObjectAnimator.ofObject(mMarker, "position",
                new LatLngEvaluator(ROUTE[i], ROUTE[i + 1]), ROUTE[i], ROUTE[i + 1]);

        oa.setInterpolator(new LinearInterpolator());
        oa.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                LatLng target = (LatLng) animation.getAnimatedValue();
                mMap.moveCamera(CameraUpdateFactory.newLatLng(target));
            }
        });

        // Use the distance of the route segment for the duration.
        double dist = SphericalUtil.computeDistanceBetween(ROUTE[i], ROUTE[i + 1]);
        oa.setDuration(Math.round(dist) * 10);

        animators.add(oa);
    }

    mAnimatorSet = new AnimatorSet();
    mAnimatorSet.playSequentially(animators);
    mAnimatorSet.start();

    mAnimatorSet.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationCancel(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_replay);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mMenu.findItem(R.id.action_animation).setIcon(R.drawable.ic_action_stop);
        }
    });
}

From source file:com.amaze.carbonfilemanager.utils.files.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 a2 s . c om*/
            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.android.deskclock.timer.TimerFullScreenFragment.java

private void gotoTimersView() {
    if (mLastVisibleView == null || mLastVisibleView.getId() == R.id.timers_list_page) {
        mTimerSetup.setVisibility(View.GONE);
        mTimersListPage.setVisibility(View.VISIBLE);
        mTimersListPage.setScaleX(1f);/*from  w ww  .  j  a  v a  2  s  . c o m*/
    } else {
        // Animate
        ObjectAnimator a = ObjectAnimator.ofFloat(mTimerSetup, View.SCALE_X, 1f, 0f);
        a.setInterpolator(new AccelerateInterpolator());
        a.setDuration(125);
        a.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mTimerSetup.setVisibility(View.GONE);
                mTimersListPage.setScaleX(0);
                mTimersListPage.setVisibility(View.VISIBLE);
                ObjectAnimator b = ObjectAnimator.ofFloat(mTimersListPage, View.SCALE_X, 0f, 1f);
                b.setInterpolator(new DecelerateInterpolator());
                b.setDuration(225);
                b.start();
            }
        });
        a.start();
    }
    startClockTicks();
    mLastVisibleView = mTimersListPage;
}

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

private void gotoSetupView() {
    if (mLastVisibleView == null || mLastVisibleView.getId() == R.id.timer_setup) {
        mTimerSetup.setVisibility(View.VISIBLE);
        mTimerSetup.setScaleX(1f);//from w  ww . jav a 2 s .  c o  m
        mTimersListPage.setVisibility(View.GONE);
    } else {
        // Animate
        ObjectAnimator a = ObjectAnimator.ofFloat(mTimersListPage, View.SCALE_X, 1f, 0f);
        a.setInterpolator(new AccelerateInterpolator());
        a.setDuration(125);
        a.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mTimersListPage.setVisibility(View.GONE);
                mTimerSetup.setScaleX(0);
                mTimerSetup.setVisibility(View.VISIBLE);
                ObjectAnimator b = ObjectAnimator.ofFloat(mTimerSetup, View.SCALE_X, 0f, 1f);
                b.setInterpolator(new DecelerateInterpolator());
                b.setDuration(225);
                b.start();
            }
        });
        a.start();

    }
    stopClockTicks();
    mTimerSetup.updateDeleteButtonAndDivider();
    mLastVisibleView = mTimerSetup;
}

From source file:io.plaidapp.core.ui.transitions.ReflowText.java

/**
 * Create Animators to transition each run of text from start to end position and size.
 *///from ww w  .j av a  2s  .  c o m
@NonNull
private List<Animator> createRunAnimators(View view, ReflowData startData, ReflowData endData, Bitmap startText,
        Bitmap endText, List<Run> runs) {
    List<Animator> animators = new ArrayList<>(runs.size());
    int dx = startData.bounds.left - endData.bounds.left;
    int dy = startData.bounds.top - endData.bounds.top;
    long startDelay = 0L;
    // move text closest to the destination first i.e. loop forward or backward over the runs
    boolean upward = startData.bounds.centerY() > endData.bounds.centerY();
    boolean first = true;
    boolean lastRightward = true;
    LinearInterpolator linearInterpolator = new LinearInterpolator();

    for (int i = upward ? 0 : runs.size() - 1; ((upward && i < runs.size())
            || (!upward && i >= 0)); i += (upward ? 1 : -1)) {
        Run run = runs.get(i);

        // skip text runs which aren't visible in either state
        if (!run.startVisible && !run.endVisible)
            continue;

        // create & position the drawable which displays the run; add it to the overlay.
        SwitchDrawable drawable = new SwitchDrawable(startText, run.start, startData.textSize, endText, run.end,
                endData.textSize);
        drawable.setBounds(run.start.left + dx, run.start.top + dy, run.start.right + dx,
                run.start.bottom + dy);
        view.getOverlay().add(drawable);

        PropertyValuesHolder topLeft = PropertyValuesHolder.ofObject(SwitchDrawable.TOP_LEFT, null,
                getPathMotion().getPath(run.start.left + dx, run.start.top + dy, run.end.left, run.end.top));
        PropertyValuesHolder width = PropertyValuesHolder.ofInt(SwitchDrawable.WIDTH, run.start.width(),
                run.end.width());
        PropertyValuesHolder height = PropertyValuesHolder.ofInt(SwitchDrawable.HEIGHT, run.start.height(),
                run.end.height());
        // the progress property drives the switching behaviour
        PropertyValuesHolder progress = PropertyValuesHolder.ofFloat(SwitchDrawable.PROGRESS, 0f, 1f);
        Animator runAnim = ObjectAnimator.ofPropertyValuesHolder(drawable, topLeft, width, height, progress);

        boolean rightward = run.start.centerX() + dx < run.end.centerX();
        if ((run.startVisible && run.endVisible) && !first && rightward != lastRightward) {
            // increase the start delay (by a decreasing amount) for the next run
            // (if it's visible throughout) to stagger the movement and try to minimize overlaps
            startDelay += staggerDelay;
            staggerDelay *= STAGGER_DECAY;
        }
        lastRightward = rightward;
        first = false;

        runAnim.setStartDelay(startDelay);
        long animDuration = Math.max(minDuration, duration - (startDelay / 2));
        runAnim.setDuration(animDuration);
        animators.add(runAnim);

        if (run.startVisible != run.endVisible) {
            // if run is appearing/disappearing then fade it in/out
            ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA,
                    run.startVisible ? OPAQUE : TRANSPARENT, run.endVisible ? OPAQUE : TRANSPARENT);
            fade.setDuration((duration + startDelay) / 2);
            if (!run.startVisible) {
                drawable.setAlpha(TRANSPARENT);
                fade.setStartDelay((duration + startDelay) / 2);
            } else {
                fade.setStartDelay(startDelay);
            }
            animators.add(fade);
        } else {
            // slightly fade during transition to minimize movement
            ObjectAnimator fade = ObjectAnimator.ofInt(drawable, SwitchDrawable.ALPHA, OPAQUE,
                    OPACITY_MID_TRANSITION, OPAQUE);
            fade.setStartDelay(startDelay);
            fade.setDuration(duration + startDelay);
            fade.setInterpolator(linearInterpolator);
            animators.add(fade);
        }
    }
    return animators;
}

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

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    switch (loader.getId()) {
    case LOADER_ACCOUNT_BILLS:
        try {/*from w  w w.j  a  v  a  2 s. c  o  m*/
            renderAccountsList(data);
        } catch (Exception e) {
            Timber.e(e, "rendering account list");
        }

        // set total for accounts in the main Drawer.
        EventBus.getDefault().post(new AccountsTotalLoadedEvent(txtTotalAccounts.getText().toString()));
        break;

    case LOADER_INCOME_EXPENSES:
        double income = 0, expenses = 0;
        if (data != null) {
            while (data.moveToNext()) {
                expenses = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses));
                income = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income));
            }
        }
        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(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(),
                    MoneyFactory.fromDouble(income)));
        if (txtExpenses != null)
            txtExpenses.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(),
                    MoneyFactory.fromDouble(Math.abs(expenses))));
        if (txtDifference != null)
            txtDifference.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(),
                    MoneyFactory.fromDouble(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));
            }
        }
        break;
    }

    // Close the cursor.
    MmxDatabaseUtils.closeCursor(data);
}

From source file:com.waz.zclient.pages.main.profile.camera.CameraFragment.java

@Override
public void onAccentColorHasChanged(Object sender, int color) {
    colorOverlay.setBackgroundColor(color);
    float accentColorOpacity = ResourceUtils.getResourceFloat(getResources(),
            R.dimen.background_color_overlay_opacity);
    float accentColorOpacityOverdriven = ResourceUtils.getResourceFloat(getResources(),
            R.dimen.background_color_overlay_opacity_overdriven);
    ObjectAnimator anim = ObjectAnimator.ofFloat(colorOverlay, View.ALPHA, 0, accentColorOpacityOverdriven,
            accentColorOpacityOverdriven, accentColorOpacityOverdriven / 2, accentColorOpacity);
    anim.setInterpolator(new AccentColorInterpolator());
    anim.setDuration(
            getResources().getInteger(R.integer.background_accent_color_transition_animation_duration));
    anim.start();/*from  w w w  . j  a  va 2 s  .c o m*/
    cameraBottomControl.setAccentColor(color);
}