List of usage examples for android.animation ArgbEvaluator ArgbEvaluator
ArgbEvaluator
From source file:com.musenkishi.atelier.Atelier.java
private static void applyColorToView(final CardView cardView, int color, boolean fromCache) { if (fromCache) { cardView.setCardBackgroundColor(color); } else {/*from w ww. j av a 2 s. c om*/ Integer colorFrom = Color.parseColor("#FFFAFAFA"); //Default light CardView color. Integer colorTo = color; ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { cardView.setCardBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.setDuration(300); colorAnimation.start(); } }
From source file:com.jerrellmardis.amphitheatre.util.Utils.java
public static void animateColorChange(final View view, int colorFrom, int colorTo) { ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override// w w w . j a v a 2 s .c om public void onAnimationUpdate(ValueAnimator animator) { view.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); valueAnimator.start(); }
From source file:com.taobao.weex.dom.action.AnimationAction.java
private @Nullable ObjectAnimator createAnimator(final View target, final int viewPortWidth) { if (target == null) { return null; }//ww w.j a va2 s . c o m WXAnimationBean.Style style = mAnimationBean.styles; if (style != null) { ObjectAnimator animator; List<PropertyValuesHolder> holders = style.getHolders(); if (!TextUtils.isEmpty(style.backgroundColor)) { BorderDrawable borderDrawable; if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor))); } else if (target.getBackground() instanceof ColorDrawable) { holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(), WXResourceUtils.getColor(style.backgroundColor))); } } if (style.getPivot() != null) { Pair<Float, Float> pair = style.getPivot(); target.setPivotX(pair.first); target.setPivotY(pair.second); } animator = ObjectAnimator.ofPropertyValuesHolder(target, holders.toArray(new PropertyValuesHolder[holders.size()])); animator.setStartDelay(mAnimationBean.delay); if (target.getLayoutParams() != null && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { DimensionUpdateListener listener = new DimensionUpdateListener(target); ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); if (!TextUtils.isEmpty(style.width)) { listener.setWidth(layoutParams.width, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)); } if (!TextUtils.isEmpty(style.height)) { listener.setHeight(layoutParams.height, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)); } animator.addUpdateListener(listener); } return animator; } else { return null; } }
From source file:com.taobao.weex.ui.action.GraphicActionAnimation.java
private @Nullable ObjectAnimator createAnimator(final View target, final int viewPortWidth) { if (target == null) { return null; }//from w w w .ja v a2 s. c om WXAnimationBean.Style style = mAnimationBean.styles; if (style != null) { ObjectAnimator animator; List<PropertyValuesHolder> holders = style.getHolders(); if (!TextUtils.isEmpty(style.backgroundColor)) { BorderDrawable borderDrawable; if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) { holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor))); } else if (target.getBackground() instanceof ColorDrawable) { holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(), WXResourceUtils.getColor(style.backgroundColor))); } } if (target.getLayoutParams() != null && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) { ViewGroup.LayoutParams layoutParams = target.getLayoutParams(); if (!TextUtils.isEmpty(style.width)) { holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth))); } if (!TextUtils.isEmpty(style.height)) { holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height, (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth))); } } if (style.getPivot() != null) { Pair<Float, Float> pair = style.getPivot(); target.setPivotX(pair.first); target.setPivotY(pair.second); } animator = ObjectAnimator.ofPropertyValuesHolder(target, holders.toArray(new PropertyValuesHolder[holders.size()])); animator.setStartDelay(mAnimationBean.delay); return animator; } else { return null; } }
From source file:com.musenkishi.wally.util.PaletteLoader.java
private static void applyColorToView(final PaletteTarget target, int color, boolean fromCache) { if (target.getView() instanceof TextView) { applyColorToView((TextView) target.getView(), color, fromCache); return;//w ww. j a va2s . com } if (fromCache) { if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) { ((ImageView) target.getView()).getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY); } else { target.getView().setBackgroundColor(color); } } else { if (target.getView() instanceof ImageView && target.shouldMaskDrawable()) { Integer colorFrom; ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { ((ImageView) target.getView()).getDrawable().mutate().setColorFilter( (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY); } }; ValueAnimator.AnimatorUpdateListener animatorUpdateListener; PaletteTag paletteTag = (PaletteTag) target.getView().getTag(); animatorUpdateListener = imageAnimatorUpdateListener; colorFrom = paletteTag.getColor(); target.getView().setTag(new PaletteTag(paletteTag.getId(), color)); Integer colorTo = color; ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.addUpdateListener(animatorUpdateListener); colorAnimation.setDuration(300); colorAnimation.start(); } else { Drawable preDrawable; if (target.getView().getBackground() == null) { preDrawable = new ColorDrawable(Color.TRANSPARENT); } else { preDrawable = target.getView().getBackground(); } TransitionDrawable transitionDrawable = new TransitionDrawable( new Drawable[] { preDrawable, new ColorDrawable(color) }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { target.getView().setBackground(transitionDrawable); } else { target.getView().setBackgroundDrawable(transitionDrawable); } transitionDrawable.startTransition(300); } } }
From source file:com.google.samples.apps.ourstreets.view.ViewUtils.java
/** * Create a color change animation over a foreground property of a {@link FrameLayout}. * * @param target The target view./*from w w w. j a v a 2s . com*/ * @param startColorRes The color to start from. * @param targetColorRes The color this animation will end with. * @param interpolator The interpolator to use. * @return The color change animation. */ @NonNull public static ObjectAnimator createColorChange(@NonNull FrameLayout target, @ColorRes int startColorRes, @ColorRes int targetColorRes, @NonNull Interpolator interpolator) { Context context = target.getContext(); final int startColor = ContextCompat.getColor(context, startColorRes); final int targetColor = ContextCompat.getColor(context, targetColorRes); ObjectAnimator colorChange = ObjectAnimator.ofInt(target, ViewUtils.FOREGROUND_COLOR, startColor, targetColor); colorChange.setEvaluator(new ArgbEvaluator()); colorChange.setInterpolator(interpolator); colorChange.setDuration(context.getResources().getInteger(android.R.integer.config_longAnimTime)); return colorChange; }
From source file:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java
/** * Background color animation builder./*from w w w. j a v a 2s . co m*/ * * @param colors the colors * @return the animation builder */ public AnimationBuilder backgroundColor(int... colors) { for (View view : views) { ObjectAnimator objectAnimator = ObjectAnimator.ofInt(view, "backgroundColor", colors); objectAnimator.setEvaluator(new ArgbEvaluator()); this.animatorList.add(objectAnimator); } return this; }
From source file:com.android.launcher3.Hotseat.java
public void updateColor(ExtractedColors extractedColors, boolean animate) { if (!mHasVerticalHotseat) { int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT); if (mBackgroundColorAnimator != null) { mBackgroundColorAnimator.cancel(); }// w w w. j a v a 2s .c o m if (!animate) { setBackgroundColor(color); } else { mBackgroundColorAnimator = ValueAnimator.ofInt(mBackgroundColor, color); mBackgroundColorAnimator.setEvaluator(new ArgbEvaluator()); mBackgroundColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mBackground.setColor((Integer) animation.getAnimatedValue()); } }); mBackgroundColorAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mBackgroundColorAnimator = null; } }); mBackgroundColorAnimator.start(); } mBackgroundColor = color; } }
From source file:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java
/** * Text color animation builder./*from ww w . j ava 2s .co m*/ * * @param colors the colors * @return the animation builder */ public AnimationBuilder textColor(int... colors) { for (View view : views) { if (view instanceof TextView) { ObjectAnimator objectAnimator = ObjectAnimator.ofInt(view, "textColor", colors); objectAnimator.setEvaluator(new ArgbEvaluator()); this.animatorList.add(objectAnimator); } } return this; }
From source file:io.github.trulyfree.easyaspi.MainActivity.java
@Override public boolean setup() { downloadHandler = new DownloadHandler(this); fileHandler = new FileHandler(this); moduleHandler = new ModuleHandler(this); executorService = Executors.newCachedThreadPool(); setContentView(R.layout.activity_main); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override// www.j a va2 s . co m public boolean onNavigationItemSelected(@NonNull MenuItem item) { ViewSwitcher viewGroup = (ViewSwitcher) findViewById(R.id.content); int id = item.getItemId(); if ((id == R.id.navigation_home || id == R.id.navigation_modules) && id != currentID) { currentID = item.getItemId(); viewGroup.showNext(); return true; } return false; } }); ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.content); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); viewSwitcher.setInAnimation(in); viewSwitcher.setOutAnimation(out); resetConfigReturned(); Button getNewModule = (Button) findViewById(R.id.new_module_config_confirm); getNewModule.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText editText = (EditText) findViewById(R.id.new_module_config_configurl); final String url = editText.getText().toString(); Toast.makeText(MainActivity.this, "Requested config from: " + url, Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { ModuleConfig config; try { config = moduleHandler.getModuleConfig(url); } catch (MalformedURLException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Invalid URL. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Failed to get module config. :(", Toast.LENGTH_LONG).show(); } }); return false; } catch (JsonParseException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MainActivity.this, "Config loaded was invalid. :(", Toast.LENGTH_LONG).show(); } }); return false; } final ModuleConfig finalConfig = config; final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config); EditText moduleName = (EditText) findViewById(R.id.module_returned_configname); EditText moduleVersion = (EditText) findViewById( R.id.module_returned_configversion); EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl); EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl); LinearLayout moduleDependencies = (LinearLayout) findViewById( R.id.module_returned_dependencies); moduleDependencies.removeAllViewsInLayout(); try { configResponseBlock.setVisibility(View.GONE); moduleName.setText(finalConfig.getName()); moduleVersion.setText(finalConfig.getVersion()); moduleConfigUrl.setText(finalConfig.getConfUrl()); moduleJarUrl.setText(finalConfig.getJarUrl()); Config[] dependencies = finalConfig.getDependencies(); for (Config dependency : dependencies) { LinearLayout dependencyLayout = new LinearLayout(MainActivity.this); dependencyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dependencyLayout.setOrientation(LinearLayout.HORIZONTAL); EditText name = new EditText(MainActivity.this); EditText jarUrl = new EditText(MainActivity.this); EditText[] loopThrough = { name, jarUrl }; LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f); for (EditText item : loopThrough) { item.setLayoutParams(params); item.setClickable(false); item.setInputType(InputType.TYPE_NULL); item.setCursorVisible(false); item.setFocusable(false); item.setFocusableInTouchMode(false); } name.setText(dependency.getName()); jarUrl.setText(dependency.getJarUrl()); dependencyLayout.addView(name); dependencyLayout.addView(jarUrl); moduleDependencies.addView(dependencyLayout); } layout.setClickable(true); Button validate = (Button) findViewById(R.id.module_returned_validate); Button cancel = (Button) findViewById(R.id.module_returned_cancel); validate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Requesting jars...", Toast.LENGTH_SHORT).show(); executorService.submit(new Callable<Boolean>() { @Override public Boolean call() { try { boolean success = true, refreshAllModification = true; Button refreshAll = null, getNewModule = (Button) findViewById( R.id.new_module_config_confirm); try { refreshAll = (Button) findViewById(R.id.refresh_all); refreshAll.setClickable(false); } catch (Throwable e) { refreshAllModification = false; } getNewModule.setClickable(false); final TextView stager = (TextView) findViewById( R.id.new_module_config_downloadstage); final ProgressBar progressBar = (ProgressBar) findViewById( R.id.new_module_config_downloadprogress); try { runOnUiThread(new Runnable() { @Override public void run() { resetConfigReturned(); } }); moduleHandler.getNewModule( makeModuleCallback(stager, progressBar), finalConfig, null, true); } catch (IOException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { stager.setText(""); progressBar.setProgress(0); } }); success = false; } getNewModule.setClickable(true); if (refreshAllModification) { refreshAll.setClickable(true); } return success; } catch (Throwable throwable) { throwable.printStackTrace(); return false; } } }); } }); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Cancelling request...", Toast.LENGTH_SHORT).show(); resetConfigReturned(); } }); } catch (Exception e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Module config invalid. :(", Toast.LENGTH_LONG).show(); layout.setClickable(false); final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorClear); final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(ANIMATION_DURATION); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { configResponseBlock .setBackgroundColor((Integer) animator.getAnimatedValue()); } }); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); runOnUiThread(new Runnable() { @Override public void run() { colorAnimation.start(); } }); return true; } }); } }); moduleHandler.setup(); refreshFilling(); return true; }