List of usage examples for android.animation ValueAnimator setDuration
@Override public ValueAnimator setDuration(long duration)
From source file:com.android.deskclock.alarms.AlarmActivity.java
private ValueAnimator getAlarmBounceAnimator(float translationX, final int hintResId) { final ValueAnimator bounceAnimator = ObjectAnimator.ofFloat(mAlarmButton, View.TRANSLATION_X, mAlarmButton.getTranslationX(), translationX, 0.0f); bounceAnimator.setInterpolator(AnimatorUtils.DECELERATE_ACCELERATE_INTERPOLATOR); bounceAnimator.setDuration(ALARM_BOUNCE_DURATION_MILLIS); bounceAnimator.addListener(new AnimatorListenerAdapter() { @Override// w ww.j a v a 2 s . c o m public void onAnimationStart(Animator animator) { mHintView.setText(hintResId); if (mHintView.getVisibility() != View.VISIBLE) { mHintView.setVisibility(View.VISIBLE); ObjectAnimator.ofFloat(mHintView, View.ALPHA, 0.0f, 1.0f).start(); } } }); return bounceAnimator; }
From source file:com.example.volunteerhandbook.MainActivity.java
void loopNewBox(LinearLayout iBox) { if (lastone <= 1) { show_what_I_thought();//w w w . j a va 2s .c o m return; } if (iTh > 3 * thoughts.length + 2) { lastone--; return; } float bH = (int) (1.2 * iBox.getHeight()); iBox.removeAllViews(); for (int i = 0; i < thoughts.length / 4; i++) { iBox.addView(toMove[iTh++ % thoughts.length]); } //toMove.setTranslationY(600); //container.addView(textBox); iBox.setX(20); iBox.setY(2 * bH); //hBox += iBox.getHeight(); float startY = iBox.getY(); endY = (-1) * bH; int duration = 20000; ValueAnimator bounceAnim = ObjectAnimator.ofFloat(iBox, "y", startY, endY); bounceAnim.setDuration(duration); bounceAnim.setInterpolator(new LinearInterpolator()); final LinearLayout fBox = iBox; bounceAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { loopNewBox(fBox); } }); bounceAnim.start(); }
From source file:org.digitalcampus.oppia.activity.CourseIndexActivity.java
private void initializeCourseIndex(boolean animate) { final ListView listView = (ListView) findViewById(R.id.section_list); if (listView == null) return;/*ww w . j a va 2 s . c o m*/ ViewCompat.setNestedScrollingEnabled(listView, true); sla = new SectionListAdapter(CourseIndexActivity.this, course, sections, new SectionListAdapter.CourseClickListener() { @Override public void onActivityClicked(String activityDigest) { startCourseActivityByDigest(activityDigest); } }); if (animate) { AlphaAnimation fadeOutAnimation = new AlphaAnimation(1f, 0f); fadeOutAnimation.setDuration(700); fadeOutAnimation.setFillAfter(true); listView.setAlpha(0f); ValueAnimator animator = ValueAnimator.ofFloat(1f, 0f); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator valueAnimator) { listView.setTranslationX((Float) valueAnimator.getAnimatedValue() * 80); listView.setAlpha(1f - (Float) valueAnimator.getAnimatedValue()); } }); animator.setDuration(700); animator.start(); loadingCourseView.startAnimation(fadeOutAnimation); } else { loadingCourseView.setVisibility(View.GONE); listView.setVisibility(View.VISIBLE); } listView.setAdapter(sla); }
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;//from w ww .ja va 2 s . co 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(); } }
From source file:com.shalzz.attendance.activity.MainActivity.java
public void setDrawerAsUp(boolean enabled) { if (mDrawerLayout == null) return;/*from w ww . ja va2s . c om*/ float start = enabled ? 0f : 1f; float end = enabled ? 1f : 0f; mDrawerLayout.setDrawerLockMode( enabled ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED); ValueAnimator anim = ValueAnimator.ofFloat(start, end); anim.addUpdateListener(valueAnimator -> { float slideOffset = (Float) valueAnimator.getAnimatedValue(); mDrawerToggle.onDrawerSlide(mDrawerLayout, slideOffset); }); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration(300); anim.start(); }
From source file:com.rks.musicx.ui.fragments.PlayingViews.Playing1Fragment.java
@Override protected void playingView() { if (getMusicXService() != null) { String title = getMusicXService().getsongTitle(); String artist = getMusicXService().getsongArtistName(); SongTitle.setText(title);/*from w w w. j a v a 2 s.com*/ SongTitle.setSelected(true); SongTitle.setEllipsize(TextUtils.TruncateAt.MARQUEE); SongArtist.setText(artist); Helper.rotationAnim(playpausebutton); Helper.rotationAnim(mAlbumCoverView); mSeekBar.setOnSeekBarChangeListener(new CircularSeekBar.OnCircularSeekBarChangeListener() { @Override public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser) { if (fromUser && getMusicXService() != null && (getMusicXService().isPlaying() || getMusicXService().isPaused())) { getMusicXService().seekto(circularSeekBar.getProgress()); } } @Override public void onStopTrackingTouch(CircularSeekBar seekBar) { } @Override public void onStartTrackingTouch(CircularSeekBar seekBar) { } }); int duration = getMusicXService().getDuration(); if (duration != -1) { mSeekBar.setMax(duration); TotalDur.setText(Helper.durationCalculator(duration)); } LyricsHelper.LoadLyrics(getContext(), title, artist, getMusicXService().getsongAlbumName(), getMusicXService().getsongData(), lrcView); // NetworkHelper.absolutesLyrics(getContext(),artist, title, getMusicXService().getsongAlbumName(), getMusicXService().getsongData(), lrcView); updateQueuePos(getMusicXService().returnpos()); bitmap = new bitmap() { @Override public void bitmapwork(Bitmap bitmap) { ArtworkUtils.blurPreferances(getContext(), bitmap, blur_artowrk); mAlbumCoverView.setImageBitmap(bitmap); } @Override public void bitmapfailed(Bitmap bitmap) { ArtworkUtils.blurPreferances(getContext(), bitmap, blur_artowrk); mAlbumCoverView.setImageBitmap(bitmap); } }; palette = new palette() { @Override public void palettework(Palette palette) { final int[] colors = Helper.getAvailableColor(getContext(), palette); if (getActivity() == null || getActivity().getWindow() == null) { return; } getActivity().getWindow().setStatusBarColor(colors[0]); getActivity().getWindow().setNavigationBarColor(colors[0]); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ((ColorDrawable) Playing3view.getBackground()).getColor(), colors[0]); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener( animator -> Playing3view.setBackgroundColor((int) animator.getAnimatedValue())); colorAnimation.start(); if (Extras.getInstance().artworkColor()) { colorMode(colors[0]); } else { colorMode(accentColor); } } }; } }
From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java
private void fadeIn() { int colorFrom = Color.parseColor("#00000000"); int colorTo = Color.parseColor("#40000000"); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from ww w . jav a2 s. c o m public void onAnimationUpdate(ValueAnimator animator) { setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java
public void fadeOut() { int colorFrom = Color.parseColor("#40000000"); int colorTo = Color.parseColor("#00000000"); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override// www . ja v a 2s . com public void onAnimationUpdate(ValueAnimator animator) { setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
From source file:com.sociablue.nanodegree_p1.MovieListFragment.java
private void initializeFab(View rootView) { final RelativeLayout buttonContainer = (RelativeLayout) rootView.findViewById(R.id.menu_button_container); final FloatingActionButton Fab = (FloatingActionButton) rootView.findViewById(R.id.fab); final ImageView bottomBar = (ImageView) rootView.findViewById(R.id.menu_bottom_bar); final ImageView topBar = (ImageView) rootView.findViewById(R.id.menu_top_bar); Fab.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override// ww w. j a v a 2s. c om public void onClick(View v) { //Menu Button Icon Animation //Setting up necessary variables long animationDuration = 500; float containerHeight = buttonContainer.getHeight(); float containerCenterY = containerHeight / 2; float containerCenterX = buttonContainer.getWidth() / 2; float topBarCenter = topBar.getTop() + topBar.getHeight() / 2; float widthOfBar = topBar.getWidth(); float heightOfBar = topBar.getHeight(); final float distanceBetweenBars = (containerCenterY - topBarCenter); /** *TODO: Refactor block of code to use Value Property Animator. Should be more efficient to animate multiple properties *and objects at the same time. Also, will try to break intialization into smaller functions. */ //Setting up animations of hamburger bars and rotation /** * Animation For Top Menu Button Icon Bar. Sliding from the top to rest on top of the middle bar. * Y Translation is 1/2 the height of the hamburger bar minus the distance. * Subtracting the distance from the height because the distance between bars is * calculated of the exact center of the button. * With out the subtraction the bar would translate slightly below the middle bar. */ float yTranslation = heightOfBar / 2 - distanceBetweenBars; float xTranslation = widthOfBar / 2 + heightOfBar / 2; TranslateAnimation topBarTranslationAnim = new TranslateAnimation(Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, 0F, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, distanceBetweenBars); topBarTranslationAnim.setDuration((long) (animationDuration * 0.8)); topBarTranslationAnim.setFillAfter(true); //Animation for bottom hamburger bar. Translates and Rotates to create 'X' AnimationSet bottomBarAnimation = new AnimationSet(true); bottomBarAnimation.setFillAfter(true); //Rotate to create cross. (The cross becomes the X after the button rotation completes" RotateAnimation bottomBarRotationAnimation = new RotateAnimation(0f, 90f, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 1f); bottomBarRotationAnimation.setDuration(animationDuration); bottomBarAnimation.addAnimation(bottomBarRotationAnimation); //Translate to correct X alignment TranslateAnimation bottomBarTranslationAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, -xTranslation, Animation.ABSOLUTE, 0f, Animation.ABSOLUTE, -yTranslation); bottomBarTranslationAnimation.setDuration(animationDuration); bottomBarAnimation.addAnimation(bottomBarTranslationAnimation); //Button Specific Animations //Rotate Button Container RotateAnimation containerRotationAnimation = new RotateAnimation(0, 135f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); containerRotationAnimation.setDuration(animationDuration); containerRotationAnimation.setFillAfter(true); //Animate change of button color between Active and Disabled colors that have been //defined in color.xml int activeColor = getResources().getColor(R.color.active_button); int disabledColor = getResources().getColor(R.color.disabled_button); //Need to use ValueAnimator because property animator does not support BackgroundTint ValueAnimator buttonColorAnimation = ValueAnimator.ofArgb(activeColor, disabledColor); buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Fab.setBackgroundTintList(ColorStateList.valueOf((int) animation.getAnimatedValue())); } }); buttonColorAnimation.setDuration(animationDuration); //Start all the animations topBar.startAnimation(topBarTranslationAnim); bottomBar.startAnimation(bottomBarAnimation); buttonContainer.startAnimation(containerRotationAnimation); buttonColorAnimation.start(); //Toogle mMenu open and closed if (mMenu.isOpen()) { //If mMenu is open, do the reverse of the animation containerRotationAnimation .setInterpolator(new ReverseInterpolator(new AccelerateInterpolator())); topBarTranslationAnim.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator())); bottomBarAnimation.setInterpolator(new ReverseInterpolator(new AccelerateInterpolator())); buttonColorAnimation.setInterpolator(new ReverseInterpolator(new LinearInterpolator())); mMenu.close(); } else { bottomBarAnimation.setInterpolator(new AccelerateInterpolator()); mMenu.open(); } } }); }
From source file:com.lovejjfg.powerrefresh.PowerRefreshLayout.java
private void performAnim(int start, int end, final AnimListener listener) { ValueAnimator animator = ValueAnimator.ofInt(start, end); animator.setDuration(ANIMATION_DURATION).start(); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from ww w. j av a 2 s . c o m public void onAnimationUpdate(ValueAnimator animation) { int value = (int) animation.getAnimatedValue(); scrollTo(0, value); postInvalidate(); listener.onGoing(); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); listener.onEnd(); } }); }