@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gallery); evaluator = new ArgbEvaluator(); currentOverlayColor = ContextCompat.getColor(this, R.color.galleryCurrentItemOverlay); overlayColor = ContextCompat.getColor(this, R.color.galleryItemOverlay); Gallery gallery = Gallery.get(); List<Image> data = gallery.getData(); DiscreteScrollView itemPicker = (DiscreteScrollView) findViewById(R.id.item_picker); itemPicker.setAdapter(new GalleryAdapter(data)); itemPicker.addScrollListener(this); itemPicker.addOnItemChangedListener(this); itemPicker.scrollToPosition(1); findViewById(R.id.home).setOnClickListener(this); findViewById(R.id.fab_share).setOnClickListener(this); }
/** * Change the color of the statusbackground, toolbar, toolbarlayout and pagertitlestrip * With a color transition animation * * @param color the final color * @param duration the transition color animation duration */ void setColor(int color, int duration) { final ValueAnimator colorAnim = ObjectAnimator.ofInt(mHeader.headerBackground, "backgroundColor", settings.color, color); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.setDuration(duration); colorAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { final int animatedValue = (Integer) animation.getAnimatedValue(); int colorAlpha = colorWithAlpha(animatedValue, lastPercent); mHeader.headerBackground.setBackgroundColor(colorAlpha); mHeader.statusBackground.setBackgroundColor(colorAlpha); mHeader.toolbar.setBackgroundColor(colorAlpha); mHeader.toolbarLayoutBackground.setBackgroundColor(colorAlpha); mHeader.mPagerSlidingTabStrip.setBackgroundColor(colorAlpha); //set the new color as MaterialViewPager's color settings.color = animatedValue; } }); colorAnim.start(); }
@Override public void onDrawState(final EmptyStateRecyclerView rv, Canvas canvas) { canvas.drawText(title, (rv.getMeasuredWidth() >> 1), (rv.getMeasuredHeight() >> 1), textPaint); // Setup animator, if necessary if (anim == null) { this.anim = ObjectAnimator.ofObject(textPaint, "color", new ArgbEvaluator(), Color.parseColor("#E0E0E0"), Color.parseColor("#BDBDBD"), Color.parseColor("#9E9E9E")); this.anim.setDuration(900); this.anim.setRepeatMode(ValueAnimator.REVERSE); this.anim.setRepeatCount(ValueAnimator.INFINITE); this.anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { rv.invalidate(); } }); this.anim.start(); } }
@Override public final void onDrawState(final EmptyStateRecyclerView rv, Canvas canvas) { final int width = rv.getMeasuredWidth(); final int height = rv.getMeasuredHeight(); // Draw all of our content items renderContent(numberOfContentItems, width, height, canvas, contentPaint); // Setup and start animation, if possible if (animateContentItems) { if (anim == null) { this.anim = ObjectAnimator.ofObject(contentPaint, "color", new ArgbEvaluator(), Color.parseColor("#E0E0E0"), Color.parseColor("#BDBDBD"), Color.parseColor("#9E9E9E")); onInterceptAnimatorCreation(anim); this.anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { rv.invalidate(); } }); this.anim.start(); } } }
/** * 给背景设置一个动画 * * @param endProgress 动画的结束进度 * @param endCallback 动画结束时触发 */ private void startAnim(float endProgress, final Runnable endCallback) { // 获取一个最终的颜色 int finalColor = Resource.Color.WHITE; // UiCompat.getColor(getResources(), R.color.white); // 运算当前进度的颜色 ArgbEvaluator evaluator = new ArgbEvaluator(); int endColor = (int) evaluator.evaluate(endProgress, mBgDrawable.getColor(), finalColor); // 构建一个属性动画 ValueAnimator valueAnimator = ObjectAnimator.ofObject(this, property, evaluator, endColor); valueAnimator.setDuration(1500); // 时间 valueAnimator.setIntValues(mBgDrawable.getColor(), endColor); // 开始结束值 valueAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); // 结束时触发 endCallback.run(); } }); valueAnimator.start(); }
/** * Change card color. This method wraps the Property Animation API mentioned here * https://stackoverflow.com/a/14467625/7009268 */ public void animateColorChange(int colorFromId, int colorToId) { int colorFrom = ContextCompat.getColor(getContext(), colorFromId); int colorTo = ContextCompat.getColor(getContext(), colorToId); final SetGameCardView card = this; int duration = getContext().getResources().getInteger(R.integer.card_animation_duration); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(duration); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { card.setCardBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
public void setBackgroundColor(int color, boolean animated){ if (animated) { int colorFrom = ((ColorDrawable)cfDialogBackground.getBackground()).getColor(); int colorTo = color; ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(getContext().getResources().getInteger(R.integer.cfdialog_animation_duration)); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { cfDialogBackground.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); } else { cfDialogBackground.setBackgroundColor(color); } }
public void setDialogBackgroundColor(int color, boolean animated) { if (animated) { int colorFrom = ((ColorDrawable)dialogCardView.getBackground()).getColor(); int colorTo = color; ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(getContext().getResources().getInteger(R.integer.cfdialog_animation_duration)); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { dialogCardView.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); } else { dialogCardView.setBackgroundColor(color); } }
public static void recolorBackground(final View view, final int startColor, final int endColor, final int duration) { ValueAnimator anim = new ValueAnimator(); anim.setIntValues(startColor, endColor); anim.setEvaluator(new ArgbEvaluator()); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { view.setBackgroundColor((Integer) animation.getAnimatedValue()); } }); anim.setDuration(duration); anim.start(); }
private void changeBackGroundColor() { int colorTo; int colorFrom; if (fullScreenMode) { colorFrom = getResources().getColor(R.color.bg); colorTo = (ContextCompat.getColor(this, R.color.bg1)); } else { colorFrom = (ContextCompat.getColor(this, R.color.bg1)); colorTo = getResources().getColor(R.color.bg); } ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(240); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ActivityBackground.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.start(); }
private void sunsetAnimator() { float sunYStart = mSunView.getTop(); float sunYEnd = mSkyView.getHeight(); ObjectAnimator heightAnimator = ObjectAnimator.ofFloat(mSunView, "y", sunYStart, sunYEnd) .setDuration(3000); ObjectAnimator sunsetSkyAnimator = ObjectAnimator.ofInt(mSkyView, "backgroundColor", mBlueSkyColor, mSunsetSkyColor) .setDuration(3000); ObjectAnimator nightSkyAnimator = ObjectAnimator.ofInt(mSkyView, "backgroundColor", mSunsetSkyColor, mNightSkyColor) .setDuration(1500); heightAnimator.setInterpolator(new AccelerateInterpolator()); sunsetSkyAnimator.setEvaluator(new ArgbEvaluator()); nightSkyAnimator.setEvaluator(new ArgbEvaluator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(heightAnimator).with(sunsetSkyAnimator).before(nightSkyAnimator); animatorSet.start(); }
private void sunriseAnimator() { float sunriseYStart = mSkyView.getHeight(); float sunriseYEnd = mSunView.getTop(); ObjectAnimator heightAnimator = ObjectAnimator.ofFloat(mSunView, "y", sunriseYStart, sunriseYEnd) .setDuration(3000); ObjectAnimator sunriseSkyAnimator = ObjectAnimator.ofInt(mSkyView, "backgroundColor", mSunsetSkyColor, mBlueSkyColor) .setDuration(3000); ObjectAnimator daySkyAnimator = ObjectAnimator.ofInt(mSkyView, "backgroundColor", mNightSkyColor, mSunsetSkyColor) .setDuration(3000); heightAnimator.setInterpolator(new AccelerateInterpolator()); sunriseSkyAnimator.setEvaluator(new ArgbEvaluator()); daySkyAnimator.setEvaluator(new ArgbEvaluator()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(daySkyAnimator).before(sunriseSkyAnimator).before(heightAnimator) ; animatorSet.start(); }
private void startIncertitudeAnimator() { if (mColorAnimator == null) { mColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), mProgressColor, SkinHelper.getTranColor(mProgressColor, 0x10)); mColorAnimator.setInterpolator(new LinearInterpolator()); mColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { drawColor = (int) animation.getAnimatedValue();//之后就可以得到动画的颜色了. postInvalidate(); } }); mColorAnimator.setDuration(1000); mColorAnimator.setRepeatCount(ValueAnimator.INFINITE); mColorAnimator.setRepeatMode(ValueAnimator.REVERSE); } mColorAnimator.start(); }
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { this.position = position; ArgbEvaluator evaluator = new ArgbEvaluator(); // ARGB求值器 int evaluate = colors[0]; // 初始默认颜色(透明白) int startColor = colors[this.position <= 0 ? 0 : position]; int endColor; if (position == 0){ endColor = colors[position +1]; }else { endColor = colors[position +1 >=colors.length ? colors.length -1 : position +1]; } evaluate = (Integer) evaluator.evaluate(positionOffset, startColor, endColor); // 根据positionOffset和第0页~第1页的颜色转换范围取颜色值 mViewRoot.setBackgroundColor(evaluate); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(evaluate); } }
@Override public void run() { long currentTime = SystemClock.uptimeMillis(); long delta = currentTime - lastTime; totalDelta += delta; float totalPercentage = totalDelta / ((float) speed); totalPercentage = totalPercentage > 1 ? 1 : totalPercentage; for (int colorIndex = 0; colorIndex < currentColors.length; colorIndex++) { currentColors[colorIndex] = (int) (new ArgbEvaluator().evaluate(totalPercentage, colors[(currentGradient + colorIndex) % colors.length], colors[(currentGradient + (colorIndex + 1)) % colors.length])); } if (totalPercentage == 1) { totalDelta = 0; currentGradient = (currentGradient + 1) % colors.length; } Shader shader = new LinearGradient(gradientsPositions[0].x, gradientsPositions[0].y, gradientsPositions[1].x, gradientsPositions[1].y, currentColors, null, Shader.TileMode.CLAMP); textView.getPaint().setShader(shader); textView.postInvalidate(); lastTime = currentTime; }
private static void applyColorToView(final TextView textView, int color, boolean fromCache) { if (fromCache) { textView.setTextColor(color); } else { Integer colorFrom = textView.getCurrentTextColor(); Integer colorTo = color; ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { textView.setTextColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.start(); } }
private void m4a(Animator animator) { if (animator instanceof AnimatorSet) { List childAnimations = ((AnimatorSet) animator).getChildAnimations(); if (childAnimations != null) { for (int i = 0; i < childAnimations.size(); i++) { m4a((Animator) childAnimations.get(i)); } } } if (animator instanceof ObjectAnimator) { ObjectAnimator objectAnimator = (ObjectAnimator) animator; String propertyName = objectAnimator.getPropertyName(); if ("fillColor".equals(propertyName) || "strokeColor".equals(propertyName)) { if (this.f9d == null) { this.f9d = new ArgbEvaluator(); } objectAnimator.setEvaluator(this.f9d); } } }
public void load(boolean anim) { if (contentView == null) return; int duration = anim ? getResources().getInteger(R.integer.anim_speed) : 1; progressWheel.setVisibility(VISIBLE); if (contentView.getMeasuredHeight() == 0) { AnimUtils.mesureView(contentView); } int buttonHeight = contentView.getMeasuredHeight() - contentView.getPaddingTop() - contentView.getPaddingBottom(); progressWheel.setCircleRadius(buttonHeight / 2); progressWheel.animate().setDuration(duration).alpha(1); progressWheel.spin(); if (contentView instanceof TextView) { int color = ((TextView) contentView).getTextColors().getDefaultColor(); ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), color, Color.argb(0, Color.red(color), Color.green(color), Color.blue(color))); textColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ((TextView) contentView).setTextColor((Integer) animator.getAnimatedValue()); } }); textColorAnimator.setDuration(duration); textColorAnimator.start(); } animateToRadius(buttonHeight / 2, duration, new SimpleAnimatorListener()); }
private void onPresenceType(PresenceType presenceType) { if (currentChatroom != null) { currentChatroom.getOtherUser().setPresenceType(presenceType); } if (presenceAnimator != null) { presenceAnimator.cancel(); } Integer colorFrom = presenceColour; Integer colorTo = presenceType.getColor(context); presenceAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); presenceAnimator.addUpdateListener(this::onPresenceColor); presenceAnimator.setDuration(250); presenceAnimator.start(); }
private void updateColor(@NonNull ArgbEvaluator colorEvaluator) { float fraction; int colorFrom; int colorTo; if (colorIntermediate != -1) { colorFrom = alpha <= 0f ? colorMore : colorIntermediate; colorTo = alpha <= 0f ? colorIntermediate : colorLess; fraction = alpha <= 0 ? (1 + alpha / 45f) : alpha / 45f; } else { colorFrom = colorMore; colorTo = colorLess; fraction = (alpha + 45f) / 90f; } color = (int) colorEvaluator.evaluate(fraction, colorFrom, colorTo); paint.setColor(color); }
private void on(AnimatorSet animatorSet) { // 按钮移动 ObjectAnimator ballTransAnim1 = ofFloat(IOSSwitch.this, "mBallStartX", width - frameStrokeWidth - height + frameStrokeWidth + ballStrokeWidth); ballTransAnim1.setDuration(250); ballTransAnim1.setInterpolator(new DecelerateInterpolator()); ObjectAnimator ballTransAnim2 = ofFloat(IOSSwitch.this, "mBallStartX", width - frameStrokeWidth - height); ballTransAnim2.setDuration(80); ballTransAnim2.setInterpolator(new DecelerateInterpolator()); animatorSet.playSequentially(ballTransAnim1, ballTransAnim2); animatorSet.start(); // 背景改变 ObjectAnimator bgColorAnim = ObjectAnimator.ofInt(this, "frameColor", frameColor, bgColor); bgColorAnim.setEvaluator(new ArgbEvaluator()); bgColorAnim.setDuration(200); bgColorAnim.start(); }
private void off(AnimatorSet animatorSet) { // 按钮移动 ObjectAnimator ballTransAnim1 = ofFloat(IOSSwitch.this, "mBallStartX", -frameStrokeWidth - ballStrokeWidth); ballTransAnim1.setDuration(250); ballTransAnim1.setInterpolator(new DecelerateInterpolator()); ObjectAnimator ballTransAnim2 = ofFloat(IOSSwitch.this, "mBallStartX", 0); ballTransAnim2.setDuration(80); ballTransAnim2.setInterpolator(new DecelerateInterpolator()); animatorSet.playSequentially(ballTransAnim1, ballTransAnim2); animatorSet.start(); // 背景恢复 ObjectAnimator bgColorAnim = ObjectAnimator.ofInt(this, "frameColor", frameColor, Colors.IOS_GRAY); bgColorAnim.setEvaluator(new ArgbEvaluator()); bgColorAnim.setDuration(200); bgColorAnim.start(); // 背景遮罩恢复 ObjectAnimator backgroundScaleAnim = ofFloat(IOSSwitch.this, "mBackgroundStrokeWidth", frameStrokeWidth); backgroundScaleAnim.setDuration(300); backgroundScaleAnim.setInterpolator(new DecelerateInterpolator()); backgroundScaleAnim.start(); }
/** * Update image view color with animation */ public static void updateDrawableColor(final Context context, final Drawable drawable, final ImageView imageView, @ColorInt int fromColor, @ColorInt int toColor, final boolean forceTint) { ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), fromColor, toColor); colorAnimation.setDuration(150); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { imageView.setImageDrawable(Helper.getTintDrawable(drawable, (Integer) animator.getAnimatedValue(), forceTint)); imageView.requestLayout(); } }); colorAnimation.start(); }
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void changeUIColor(Integer color) { ValueAnimator anim = ValueAnimator.ofArgb(previsionThemeColor, color); anim.setEvaluator(new ArgbEvaluator()); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { progressBar.getProgressDrawable().setColorFilter(new LightingColorFilter(0xFF000000, (Integer) valueAnimator.getAnimatedValue())); setSystemBarColor((Integer) valueAnimator.getAnimatedValue()); navigation.setActiveTabColor((Integer) valueAnimator.getAnimatedValue()); fabSearch.setBackgroundTintList(ColorStateList.valueOf((Integer) valueAnimator.getAnimatedValue())); } }); anim.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime)); anim.start(); refreshLayout.setColorSchemeColors(color, color, color); }
public void blink() { ObjectAnimator animate= ObjectAnimator.ofObject(failedStripe,"backgroundColor",new ArgbEvaluator(), Color.RED,failedStripe.stripeColor); animate.setInterpolator(new LinearInterpolator()); animate.setRepeatMode(ValueAnimator.RESTART); animate.setRepeatCount(4); animate.setDuration(300); animate.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); p.setColor(failedStripe.stripeColor); startAnimation(); game.gameOverScreen(); } }); animate.start(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void prepareCircularReveal(View startView, FrameLayout targetView) { int centerX = (startView.getLeft() + startView.getRight()) / 2; // Subtract the start view's height to adjust for relative coordinates on screen. int centerY = (startView.getTop() + startView.getBottom()) / 2 - startView.getHeight(); float endRadius = (float) Math.hypot(centerX, centerY); mCircularReveal = ViewAnimationUtils.createCircularReveal( targetView, centerX, centerY, startView.getWidth(), endRadius); mCircularReveal.setInterpolator(new FastOutLinearInInterpolator()); mCircularReveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mIcon.setVisibility(View.GONE); mCircularReveal.removeListener(this); } }); // Adding a color animation from the FAB's color to transparent creates a dissolve like // effect to the circular reveal. int accentColor = ContextCompat.getColor(this, mCategory.getTheme().getAccentColor()); mColorChange = ObjectAnimator.ofInt(targetView, ViewUtils.FOREGROUND_COLOR, accentColor, Color.TRANSPARENT); mColorChange.setEvaluator(new ArgbEvaluator()); mColorChange.setInterpolator(mInterpolator); }
private void updateHeaderColor(int newBackgroundColor, int newTextColor) { if (mCurrentColor != newBackgroundColor) { if (colorAnimation != null && colorAnimation.isRunning()) { colorAnimation.cancel(); } if (headerLayout != null) { final int DURATION = 200; colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), mCurrentColor, newBackgroundColor).setDuration(DURATION); mCurrentColor = newBackgroundColor; colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { headerLayout.setBackgroundColor((int) valueAnimator.getAnimatedValue()); } }); colorAnimation.start(); for (int i = 0, size = headerTextViews.size(); i < size; i++) { animateTextColorChange(newTextColor, DURATION, headerTextViews.get(i)); } } } }
private void animateNextStation() { int colorFrom = 0xFFFFFFFF; int colorTo = getResources().getColor(R.color.colorAccent); final ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); final GradientDrawable background = (GradientDrawable) nextStationIcon.getBackground(); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animator) { background.setColor((Integer) animator.getAnimatedValue()); } }); valueAnimator.setDuration(1600); valueAnimator.setRepeatMode(ValueAnimator.REVERSE); valueAnimator.setRepeatCount(ValueAnimator.INFINITE); valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); valueAnimator.start(); }
/** * Calculates color for specific position on time picker * @param scrollX * @return */ private int getColor(int scrollX, int position) { int itemWithPadding = (int) (itemWidth + dividerSize); float proportion = Math.abs(((1f * scrollX % itemWithPadding) / 2) / (itemWithPadding / 2f)); if(proportion > .5) { proportion = (proportion - .5f); } else { proportion = .5f - proportion; } proportion *= 2; int defaultColor; int selectedColor; if(pressedItem == position) { defaultColor = textColor.getColorForState(new int[] { android.R.attr.state_pressed }, textColor.getDefaultColor()); selectedColor = textColor.getColorForState(new int[] { android.R.attr.state_pressed, android.R.attr.state_selected }, defaultColor); } else { defaultColor = textColor.getDefaultColor(); selectedColor = textColor.getColorForState(new int[] { android.R.attr.state_selected }, defaultColor); } return (Integer) new ArgbEvaluator().evaluate(proportion, selectedColor, defaultColor); }
private void updateColor(ArgbEvaluator colorEvaluator) { float fraction; int colorFrom; int colorTo; if (colorIntermediate != -1) { colorFrom = alpha <= 0f ? colorMore : colorIntermediate; colorTo = alpha <= 0f ? colorIntermediate : colorLess; fraction = alpha <= 0 ? (1 + alpha / 45f) : alpha / 45f; } else { colorFrom = colorMore; colorTo = colorLess; fraction = (alpha + 45f) / 90f; } color = (int) colorEvaluator.evaluate(fraction, colorFrom, colorTo); paint.setColor(color); }
private void init(Context context, AttributeSet attrs) { mPaint = new Paint(); //setFilterBitmap() and setAntiAlias used together to make drawing bitmap anti-aliased. mPaint.setFilterBitmap(true); mPaint.setAntiAlias(true); mMatrix = new Matrix(); bitmapDisappearDust = BitmapFactory.decodeResource(getResources(), R.drawable.icon_red_dust); bitmapDisappearDustHalfWidth = bitmapDisappearDust.getWidth() / 2; bitmapDisappearDustHalfHeight = bitmapDisappearDust.getHeight() / 2; random = new Random(bitmapDisappearDust.getByteCount()); mCenterBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_un_praised); centerBitmapHalfWidth = mCenterBitmap.getWidth() / 2; centerBitmapHalfHeight = mCenterBitmap.getHeight() / 2; this.setOnTouchListener(this); isPraised = false; //Follow circle outerCirclePaint = new Paint(); innerCirclePaint = new Paint(); outerCirclePaint.setStyle(Paint.Style.FILL); outerCirclePaint.setAntiAlias(true); innerCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); innerCirclePaint.setAntiAlias(true); argbEvaluator = new ArgbEvaluator(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void updateStatusBarColor() { if (mShotFragment == null || true) { return; } final int desiredStatusBarColor; // Only use a custom status bar color if QuickContacts touches the top of the viewport. if (/*mScroller.getScrollNeededToBeFullScreen() <= 0*/ true) { desiredStatusBarColor = mStatusBarColor; } else { desiredStatusBarColor = Color.TRANSPARENT; } // Animate to the new color. if (UiUtils.hasLollipop()) { final ObjectAnimator animation = ObjectAnimator.ofInt(getWindow(), "statusBarColor", getWindow().getStatusBarColor(), desiredStatusBarColor); animation.setDuration(ANIMATION_STATUS_BAR_COLOR_CHANGE_DURATION); animation.setEvaluator(new ArgbEvaluator()); animation.start(); } }
public AllAppsTransitionController(Launcher l) { mLauncher = l; mDetector = new VerticalPullDetector(l); mDetector.setListener(this); mShiftRange = DEFAULT_SHIFT_RANGE; mProgress = 1f; mEvaluator = new ArgbEvaluator(); mAllAppsBackgroundColor = PreferencesState.isDarkThemeEnabled(l) ? ContextCompat.getColor(l, R.color.material_dark) : ContextCompat.getColor(l, R.color.material_light_o); }
private void backgroundAnimator(int background) { int colorFrom = context.getResources().getColor(R.color.background); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, background); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { view.onBackgroundColorUpdate((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
private void titleTextAnimator(int titleText) { int colorFrom = context.getResources().getColor(R.color.colorAccent); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, titleText); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { view.onTitleTextColorUpdate((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
private void bodyTextAnimator(int bodyText) { int colorFrom = context.getResources().getColor(R.color.default_text_color); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, bodyText); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { view.onBodyTextColorUpdate((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }