本文整理汇总了Java中android.animation.ArgbEvaluator类的典型用法代码示例。如果您正苦于以下问题:Java ArgbEvaluator类的具体用法?Java ArgbEvaluator怎么用?Java ArgbEvaluator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArgbEvaluator类属于android.animation包,在下文中一共展示了ArgbEvaluator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.animation.ArgbEvaluator; //导入依赖的package包/类
@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);
}
示例2: setColor
import android.animation.ArgbEvaluator; //导入依赖的package包/类
/**
* 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();
}
示例3: onDrawState
import android.animation.ArgbEvaluator; //导入依赖的package包/类
@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();
}
}
示例4: onDrawState
import android.animation.ArgbEvaluator; //导入依赖的package包/类
@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();
}
}
}
示例5: startAnim
import android.animation.ArgbEvaluator; //导入依赖的package包/类
/**
* 给背景设置一个动画
*
* @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();
}
示例6: animateColorChange
import android.animation.ArgbEvaluator; //导入依赖的package包/类
/**
* 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();
}
示例7: setBackgroundColor
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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);
}
}
示例8: setDialogBackgroundColor
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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);
}
}
示例9: recolorBackground
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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();
}
示例10: changeBackGroundColor
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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();
}
示例11: sunsetAnimator
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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();
}
示例12: sunriseAnimator
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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();
}
示例13: startIncertitudeAnimator
import android.animation.ArgbEvaluator; //导入依赖的package包/类
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();
}
示例14: onPageScrolled
import android.animation.ArgbEvaluator; //导入依赖的package包/类
@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);
}
}
示例15: run
import android.animation.ArgbEvaluator; //导入依赖的package包/类
@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;
}