List of usage examples for android.animation ValueAnimator addListener
public void addListener(AnimatorListener listener)
From source file:com.dean.phonesafe.ui.SlideSwitch.java
public void moveToDest(final boolean toRight) { ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left); toDestAnim.setDuration(500);//from w ww.j a v a 2 s . c o m toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator()); toDestAnim.start(); toDestAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { frontRect_left = (Integer) animation.getAnimatedValue(); alpha = (int) (255 * (float) frontRect_left / (float) max_left); invalidateView(); } }); toDestAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (toRight) { isOpen = true; if (listener != null) listener.open(); frontRect_left_begin = max_left; } else { isOpen = false; if (listener != null) listener.close(); frontRect_left_begin = min_left; } } }); }
From source file:com.audionote.widget.SlideSwitch.java
public void moveToDest(final boolean toRight) { ValueAnimator toDestAnim = ValueAnimator.ofInt(frontRect_left, toRight ? max_left : min_left); toDestAnim.setDuration(200);/* w w w . ja v a 2 s . c o m*/ toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator()); toDestAnim.start(); toDestAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { frontRect_left = (Integer) animation.getAnimatedValue(); alpha = (int) (255 * (float) frontRect_left / (float) max_left); invalidateView(); } }); toDestAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (toRight) { isOpen = true; if (listener != null) listener.open(); frontRect_left_begin = max_left; } else { isOpen = false; if (listener != null) listener.close(); frontRect_left_begin = min_left; } } }); }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
public void fadeInSignal(final int colorTo, final ValueAnimator.AnimatorUpdateListener updateListener) { final int colorFrom = DEFAULT_BACKGROUND_COLOR; final ValueAnimator colorAnimation = getValueAnimator(colorTo, colorFrom); colorAnimation.setDuration(DEFAULT_DURATION_ENTER); // milliseconds colorAnimation.addUpdateListener(updateListener); colorAnimation.addListener(new Animator.AnimatorListener() { @Override/*from w w w .j a v a2 s. c om*/ public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { final ValueAnimator colorAnimation = getValueAnimator(colorFrom, colorTo); colorAnimation.setDuration(DEFAULT_DURATION_EXIT); // milliseconds colorAnimation.addUpdateListener(updateListener); colorAnimation.start(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); colorAnimation.start(); }
From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java
/** * Animate the dismissed list item to zero-height and fire the dismiss callback when * all dismissed list item animations have completed. * * @param dismissView The view that has been slided out. * @param listItemView The list item view. This is the whole view of the list item, and not just * the part, that the user swiped. * @param dismissPosition The position of the view inside the list. *//*from w ww.j a v a 2 s . c om*/ private void performDismiss(final View dismissView, final View listItemView, final int dismissPosition) { final ViewGroup.LayoutParams lp = listItemView.getLayoutParams(); final int originalLayoutHeight = lp.height; if (android.os.Build.VERSION.SDK_INT < 12) { mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView, listItemView)); finishDismiss(dismissView, originalLayoutHeight); } else { int originalHeight = listItemView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { finishDismiss(dismissView, originalLayoutHeight); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); listItemView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView, listItemView)); animator.start(); } }
From source file:orbin.deskclock.DeskClock.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.desk_clock); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Don't show the volume muted snackbar on rotations. mShowSilencedAlarmsSnackbar = savedInstanceState == null; mSnackbarAnchor = findViewById(R.id.coordinator); // Configure the toolbar. final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from ww w .jav a 2 s . c o m*/ getSupportActionBar().setDisplayShowTitleEnabled(false); // Configure the menu item controllers add behavior to the toolbar. mOptionsMenuManager.addMenuItemController(new NightModeMenuItemController(this)) .addMenuItemController(new SettingsMenuItemController(this)) .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this)); // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu // inflation occurs *after* the initial draw and a second layout pass adds in the menu. onCreateOptionsMenu(toolbar.getMenu()); // Create the tabs that make up the user interface. mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs); for (int i = 0; i < UiDataModel.getUiDataModel().getTabCount(); i++) { final Tab tab = UiDataModel.getUiDataModel().getTab(i); mTabLayout.addTab(mTabLayout.newTab().setIcon(tab.getIconId()) .setContentDescription(tab.getContentDescriptionId())); } // Configure the buttons shared by the tabs. mFab = (ImageView) findViewById(R.id.fab); mLeftButton = (ImageButton) findViewById(R.id.left_button); mRightButton = (ImageButton) findViewById(R.id.right_button); mFab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onFabClick(mFab); } }); mLeftButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onLeftButtonClick(mLeftButton); } }); mRightButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onRightButtonClick(mRightButton); } }); // Build the reusable animations that hide and show the fab and left/right buttons. // These may be used independently or be chained together. final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); mHideAnimation.setDuration(duration).play(getScaleAnimator(mFab, 1f, 0f)) .with(getAlphaAnimator(mLeftButton, 1f, 0f)).with(getAlphaAnimator(mRightButton, 1f, 0f)); mShowAnimation.setDuration(duration).play(getScaleAnimator(mFab, 0f, 1f)) .with(getAlphaAnimator(mLeftButton, 0f, 1f)).with(getAlphaAnimator(mRightButton, 0f, 1f)); // Build the reusable animation that hides and shows only the fab. final ValueAnimator hideFabAnimation = getScaleAnimator(mFab, 1f, 0f); hideFabAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { getSelectedDeskClockFragment().onUpdateFab(mFab); } }); final ValueAnimator showFabAnimation = getScaleAnimator(mFab, 0f, 1f); mUpdateFabOnlyAnimation.setDuration(duration).play(showFabAnimation).after(hideFabAnimation); // Customize the view pager. mFragmentTabPagerAdapter = new TabFragmentAdapter(this); mFragmentTabPager = (RtlViewPager) findViewById(R.id.desk_clock_pager); // Keep all four tabs to minimize jank. mFragmentTabPager.setOffscreenPageLimit(3); // Set Accessibility Delegate to null so view pager doesn't intercept movements and // prevent the fab from being selected. mFragmentTabPager.setAccessibilityDelegate(null); // Mirror changes made to the selected page of the view pager into UiDataModel. mFragmentTabPager.setOnRTLPageChangeListener(new PageChangeWatcher()); mFragmentTabPager.setAdapter(mFragmentTabPagerAdapter); // Selecting a tab implicitly selects a page in the view pager. mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mFragmentTabPager)); // Honor changes to the selected tab from outside entities. UiDataModel.getUiDataModel().addTabListener(mTabChangeWatcher); // Update the next alarm time on app startup because the user might have altered the data. AlarmStateManager.updateNextAlarm(this); if (savedInstanceState == null) { // Set the background color to initially match the theme value so that we can // smoothly transition to the dynamic color. final int backgroundColor = ContextCompat.getColor(this, R.color.default_background); adjustAppColor(backgroundColor, false /* animate */); } UiDataModel.getUiDataModel().setSelectedTab(ALARMS); }
From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java
void animateViewIn() { if (Build.VERSION.SDK_INT >= 12) { final int viewHeight = mView.getHeight(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, viewHeight); } else {//from w ww . j a v a 2s . co m mView.setTranslationY(viewHeight); } final ValueAnimator animator = new ValueAnimator(); animator.setIntValues(viewHeight, 0); animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); animator.setDuration(ANIMATION_DURATION); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animator) { mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION, ANIMATION_FADE_DURATION); } @Override public void onAnimationEnd(Animator animator) { onViewShown(); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { private int mPreviousAnimatedIntValue = viewHeight; @Override public void onAnimationUpdate(ValueAnimator animator) { int currentAnimatedIntValue = (int) animator.getAnimatedValue(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue); } else { mView.setTranslationY(currentAnimatedIntValue); } mPreviousAnimatedIntValue = currentAnimatedIntValue; } }); animator.start(); } else { final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in); anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setDuration(ANIMATION_DURATION); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationEnd(Animation animation) { onViewShown(); } @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mView.startAnimation(anim); } }
From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java
private void animateViewOut(final int event) { if (Build.VERSION.SDK_INT >= 12) { final ValueAnimator animator = new ValueAnimator(); animator.setIntValues(0, mView.getHeight()); animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); animator.setDuration(ANIMATION_DURATION); animator.addListener(new AnimatorListenerAdapter() { @Override/* w ww .j a va 2s .c o m*/ public void onAnimationStart(Animator animator) { mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION); } @Override public void onAnimationEnd(Animator animator) { onViewHidden(event); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { private int mPreviousAnimatedIntValue = 0; @Override public void onAnimationUpdate(ValueAnimator animator) { int currentAnimatedIntValue = (int) animator.getAnimatedValue(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue); } else { mView.setTranslationY(currentAnimatedIntValue); } mPreviousAnimatedIntValue = currentAnimatedIntValue; } }); animator.start(); } else { final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_out); anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setDuration(ANIMATION_DURATION); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationEnd(Animation animation) { onViewHidden(event); } @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mView.startAnimation(anim); } }
From source file:com.wizardsofm.deskclock.DeskClock.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(com.wizardsofm.deskclock.R.layout.desk_clock); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Don't show the volume muted snackbar on rotations. mShowSilencedAlarmsSnackbar = savedInstanceState == null; mSnackbarAnchor = findViewById(com.wizardsofm.deskclock.R.id.coordinator); // Configure the toolbar. final Toolbar toolbar = (Toolbar) findViewById(com.wizardsofm.deskclock.R.id.toolbar); setSupportActionBar(toolbar);/* w w w. j a v a 2s. com*/ getSupportActionBar().setDisplayShowTitleEnabled(false); // Configure the menu item controllers add behavior to the toolbar. mOptionsMenuManager.addMenuItemController(new NightModeMenuItemController(this)) .addMenuItemController(new SettingsMenuItemController(this)) .addMenuItemController(MenuItemControllerFactory.getInstance().buildMenuItemControllers(this)); // Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu // inflation occurs *after* the initial draw and a second layout pass adds in the menu. onCreateOptionsMenu(toolbar.getMenu()); // Create the tabs that make up the user interface. mTabLayout = (TabLayout) findViewById(com.wizardsofm.deskclock.R.id.sliding_tabs); for (int i = 0; i < UiDataModel.getUiDataModel().getTabCount(); i++) { final UiDataModel.Tab tab = UiDataModel.getUiDataModel().getTab(i); mTabLayout.addTab(mTabLayout.newTab().setIcon(tab.getIconId()) .setContentDescription(tab.getContentDescriptionId())); } // Configure the buttons shared by the tabs. mFab = (ImageView) findViewById(com.wizardsofm.deskclock.R.id.fab); mLeftButton = (ImageButton) findViewById(com.wizardsofm.deskclock.R.id.left_button); mRightButton = (ImageButton) findViewById(com.wizardsofm.deskclock.R.id.right_button); mFab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onFabClick(mFab); } }); mLeftButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onLeftButtonClick(mLeftButton); } }); mRightButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { getSelectedDeskClockFragment().onRightButtonClick(mRightButton); } }); // Build the reusable animations that hide and show the fab and left/right buttons. // These may be used independently or be chained together. final long duration = UiDataModel.getUiDataModel().getShortAnimationDuration(); mHideAnimation.setDuration(duration).play(getScaleAnimator(mFab, 1f, 0f)) .with(getAlphaAnimator(mLeftButton, 1f, 0f)).with(getAlphaAnimator(mRightButton, 1f, 0f)); mShowAnimation.setDuration(duration).play(getScaleAnimator(mFab, 0f, 1f)) .with(getAlphaAnimator(mLeftButton, 0f, 1f)).with(getAlphaAnimator(mRightButton, 0f, 1f)); // Build the reusable animation that hides and shows only the fab. final ValueAnimator hideFabAnimation = getScaleAnimator(mFab, 1f, 0f); hideFabAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { getSelectedDeskClockFragment().onUpdateFab(mFab); } }); final ValueAnimator showFabAnimation = getScaleAnimator(mFab, 0f, 1f); mUpdateFabOnlyAnimation.setDuration(duration).play(showFabAnimation).after(hideFabAnimation); // Customize the view pager. mFragmentTabPagerAdapter = new TabFragmentAdapter(this); mFragmentTabPager = (RtlViewPager) findViewById(com.wizardsofm.deskclock.R.id.desk_clock_pager); // Keep all four tabs to minimize jank. mFragmentTabPager.setOffscreenPageLimit(3); // Set Accessibility Delegate to null so view pager doesn't intercept movements and // prevent the fab from being selected. mFragmentTabPager.setAccessibilityDelegate(null); // Mirror changes made to the selected page of the view pager into UiDataModel. mFragmentTabPager.setOnRTLPageChangeListener(new PageChangeWatcher()); mFragmentTabPager.setAdapter(mFragmentTabPagerAdapter); // Selecting a tab implicitly selects a page in the view pager. mTabLayout.setOnTabSelectedListener(new ViewPagerOnTabSelectedListener(mFragmentTabPager)); // Honor changes to the selected tab from outside entities. UiDataModel.getUiDataModel().addTabListener(mTabChangeWatcher); // Update the next alarm time on app startup because the user might have altered the data. AlarmStateManager.updateNextAlarm(this); if (savedInstanceState == null) { // Set the background color to initially match the theme value so that we can // smoothly transition to the dynamic color. final int backgroundColor = ContextCompat.getColor(this, com.wizardsofm.deskclock.R.color.default_background); adjustAppColor(backgroundColor, false /* animate */); } // request permission to use microphone ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.RECORD_AUDIO }, 1); }
From source file:com.example.volunteerhandbook.MainActivity.java
void loopNewBox(LinearLayout iBox) { if (lastone <= 1) { show_what_I_thought();/*w w w . j a va2s . c om*/ 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:com.ruesga.rview.wizard.WizardActivity.java
private Animator createHeaderAnimation(int from, int to) { final ValueAnimator animator = ValueAnimator.ofInt(from, to); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.setDuration(250L);/*from w w w. ja v a 2 s. c om*/ animator.addUpdateListener(animation -> { final View v = mBinding.pageHeader; v.getLayoutParams().height = (Integer) animation.getAnimatedValue(); v.requestLayout(); }); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mWorkflow.isBackEnabled = false; mWorkflow.isForwardEnabled = false; mBinding.setWorkflow(mWorkflow); mIsHeaderAnimatorRunning = true; } @Override public void onAnimationEnd(Animator animator) { if (mCurrentPageFragment != null) { onValidationChanged(mCurrentPageFragment); } mBinding.setWorkflow(mWorkflow); mIsHeaderAnimatorRunning = false; } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); return animator; }