List of usage examples for android.animation ValueAnimator getAnimatedValue
public Object getAnimatedValue()
ValueAnimator
when there is just one property being animated. From source file:com.cocoa.cocoautils.widget.navigationtabbar.ntb.NavigationTabBar.java
@SuppressWarnings("ResourceAsColor") public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB/*from ww w . ja v a 2 s .co m*/ // Always draw setWillNotDraw(false); // Speed and fix for pre 17 API ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); setLayerType(LAYER_TYPE_SOFTWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)); setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true)); setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true)); setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true)); setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, -2f)); setIsBadgeUseTypeface( typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)); setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX)); setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, -2f)); setBadgePosition( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX)); setBadgeGravity( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX)); setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR)); setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR)); setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR)); setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F)); setIconSizeFraction( typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE)); // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); // Set preview models if (isInEditMode()) { // Get preview colors String[] previewColors = null; try { final int previewColorsId = typedArray .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0); previewColors = previewColorsId == 0 ? null : typedArray.getResources().getStringArray(previewColorsId); } catch (Exception exception) { previewColors = null; exception.printStackTrace(); } finally { if (previewColors == null) previewColors = typedArray.getResources().getStringArray(R.array.default_preview); for (String previewColor : previewColors) mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build()); requestLayout(); } } } finally { typedArray.recycle(); } }
From source file:devlight.io.library.ntb.NavigationTabBar.java
@SuppressWarnings({ "ResourceAsColor", "ResourceType" }) public NavigationTabBar(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTB/*from www . ja v a 2 s . c o m*/ // Always draw setWillNotDraw(false); // Speed and fix for pre 17 API ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, null); setLayerType(LAYER_TYPE_SOFTWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabBar); try { setIsTitled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_titled, false)); setIsBadged(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badged, false)); setIsScaled(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_scaled, true)); setIsTinted(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_tinted, true)); setIsSwiped(typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_swiped, true)); setTitleSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_title_size, AUTO_SIZE)); setIsBadgeUseTypeface( typedArray.getBoolean(R.styleable.NavigationTabBar_ntb_badge_use_typeface, false)); setTitleMode(typedArray.getInt(R.styleable.NavigationTabBar_ntb_title_mode, TitleMode.ALL_INDEX)); setBadgeSize(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_badge_size, AUTO_SIZE)); setBadgePosition( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_position, BadgePosition.RIGHT_INDEX)); setBadgeGravity( typedArray.getInt(R.styleable.NavigationTabBar_ntb_badge_gravity, BadgeGravity.TOP_INDEX)); setBadgeBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_bg_color, AUTO_COLOR)); setBadgeTitleColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_badge_title_color, AUTO_COLOR)); setTypeface(typedArray.getString(R.styleable.NavigationTabBar_ntb_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabBar_ntb_active_color, DEFAULT_ACTIVE_COLOR)); setBgColor(typedArray.getColor(R.styleable.NavigationTabBar_ntb_bg_color, DEFAULT_BG_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabBar_ntb_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabBar_ntb_corners_radius, 0.0F)); setIconSizeFraction( typedArray.getFloat(R.styleable.NavigationTabBar_ntb_icon_size_fraction, AUTO_SCALE)); // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); // Set preview models if (isInEditMode()) { // Get preview colors String[] previewColors = null; try { final int previewColorsId = typedArray .getResourceId(R.styleable.NavigationTabBar_ntb_preview_colors, 0); previewColors = previewColorsId == 0 ? null : typedArray.getResources().getStringArray(previewColorsId); } catch (Exception exception) { previewColors = null; exception.printStackTrace(); } finally { if (previewColors == null) previewColors = typedArray.getResources().getStringArray(R.array.default_preview); for (String previewColor : previewColors) mModels.add(new Model.Builder(null, Color.parseColor(previewColor)).build()); requestLayout(); } } } finally { typedArray.recycle(); } }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void fadeOutBackground() { ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_FOCUSED, BACKGROUND_DRAWABLE_ALPHA_SEARCH_NOT_FOCUSED); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w w w . j av a2 s.c om*/ public void onAnimationUpdate(ValueAnimator animation) { int value = (Integer) animation.getAnimatedValue(); mBackgroundDrawable.setAlpha(value); } }); anim.setDuration(BACKGROUND_FADE_ANIM_DURATION); anim.start(); }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void fadeInBackground() { ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_NOT_FOCUSED, BACKGROUND_DRAWABLE_ALPHA_SEARCH_FOCUSED); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from www . j a v a 2 s . co m*/ public void onAnimationUpdate(ValueAnimator animation) { int value = (Integer) animation.getAnimatedValue(); mBackgroundDrawable.setAlpha(value); } }); anim.setDuration(BACKGROUND_FADE_ANIM_DURATION); anim.start(); }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void openMenuDrawable(final DrawerArrowDrawable drawerArrowDrawable, boolean withAnim) { if (withAnim) { ValueAnimator anim = ValueAnimator.ofFloat(0.0f, 1.0f); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . j a v a 2 s . c o m public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); drawerArrowDrawable.setProgress(value); } }); anim.setDuration(MENU_ICON_ANIM_DURATION); anim.start(); } else { drawerArrowDrawable.setProgress(1.0f); } }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void closeMenuDrawable(final DrawerArrowDrawable drawerArrowDrawable, boolean withAnim) { if (withAnim) { ValueAnimator anim = ValueAnimator.ofFloat(1.0f, 0.0f); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* w w w. java2 s . c o m*/ public void onAnimationUpdate(ValueAnimator animation) { float value = (Float) animation.getAnimatedValue(); drawerArrowDrawable.setProgress(value); } }); anim.setDuration(MENU_ICON_ANIM_DURATION); anim.start(); } else { drawerArrowDrawable.setProgress(0.0f); } }
From source file:chao.widget.tablayout.TabLayout.java
private void animateToTab(int newPosition) { if (newPosition == Tab.INVALID_POSITION) { return;//from ww w.j a va2s .co m } if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f, true); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); if (startScrollX != targetScrollX) { if (mScrollAnimator == null) { mScrollAnimator = createAnimator(); mScrollAnimator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); mScrollAnimator.setDuration(ANIMATION_DURATION); mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scrollTo((Integer) animation.getAnimatedValue(), 0); } }); } mScrollAnimator.setIntValues(startScrollX, targetScrollX); mScrollAnimator.start(); } // Now animate the indicator mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION); }
From source file:com.commonsware.cwac.crossport.design.widget.TabLayout.java
private void ensureScrollAnimator() { if (mScrollAnimator == null) { mScrollAnimator = new ValueAnimator(); mScrollAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); mScrollAnimator.setDuration(ANIMATION_DURATION); mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/* w ww .j av a2s . c om*/ public void onAnimationUpdate(ValueAnimator animator) { scrollTo((int) animator.getAnimatedValue(), 0); } }); } }
From source file:org.xjy.android.nova.widget.ColorTabLayout.java
private void animateToTab(int newPosition) { if (newPosition == Tab.INVALID_POSITION) { return;//from w ww . j a v a 2 s. c o m } if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f, true); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); if (startScrollX != targetScrollX) { if (mScrollAnimator == null) { mScrollAnimator = new ValueAnimator(); mScrollAnimator.setInterpolator(new FastOutSlowInInterpolator()); mScrollAnimator.setDuration(ANIMATION_DURATION); mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scrollTo((Integer) animation.getAnimatedValue(), 0); } }); } mScrollAnimator.setIntValues(startScrollX, targetScrollX); mScrollAnimator.start(); } // Now animate the indicator mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION); }
From source file:android.support.design.widget.RaeTabLayout.java
private void animateToTab(int newPosition) { if (newPosition == Tab.INVALID_POSITION) { return;/*from ww w.jav a 2s . c o m*/ } if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f, true); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); if (startScrollX != targetScrollX) { if (this.mScrollAnimator == null) { this.mScrollAnimator = new ValueAnimator(); this.mScrollAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); this.mScrollAnimator.setDuration(300L); this.mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator animator) { scrollTo(((Integer) animator.getAnimatedValue()).intValue(), 0); } }); } mScrollAnimator.setIntValues(startScrollX, targetScrollX); mScrollAnimator.start(); } // Now animate the indicator mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION); }