Java Code Examples for android.animation.ArgbEvaluator#evaluate()

The following examples show how to use android.animation.ArgbEvaluator#evaluate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpandIconView.java    From Android-ExpandIcon with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: WizardFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleColorTransitions(int position, float positionOffset, int positionOffsetPixels) {
  if (animatedColorView != null) {
    if (position < (viewPagerAdapter.getCount() - 1) && position < (transitionColors.length
        - 1)) {
      ArgbEvaluator argbEvaluator = new ArgbEvaluator();
      int argbEvaluation =
          (Integer) argbEvaluator.evaluate(positionOffset, transitionColors[position],
              transitionColors[position + 1]);
      animatedColorView.setBackgroundColor(argbEvaluation);
    } else {
      if (viewPagerAdapter.isLoggedIn()) {
        animatedColorView.setBackgroundColor(transitionColors[transitionColors.length - 2]);
      } else {
        animatedColorView.setBackgroundColor(transitionColors[transitionColors.length - 1]);
      }
    }
  }
}
 
Example 3
Source File: ExpandIconView.java    From Blackbulb with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: SimpleViewBehavior.java    From simple-view-behavior with MIT License 4 votes vote down vote up
@Override
void updateViewWithPercent(View child, float percent) {
    super.updateViewWithPercent(child, percent);

    float newX = targetX == UNSPECIFIED_INT ? 0 : (targetX - mStartX) * percent;
    float newY = targetY == UNSPECIFIED_INT ? 0 : (targetY - mStartY) * percent;

    // set scale
    if (targetWidth != UNSPECIFIED_INT || targetHeight != UNSPECIFIED_INT) {
        float newWidth = mStartWidth + ((targetWidth - mStartWidth) * percent);
        float newHeight = mStartHeight + ((targetHeight - mStartHeight) * percent);

        child.setScaleX(newWidth / mStartWidth);
        child.setScaleY(newHeight / mStartHeight);
        // make up position for scale change
        newX -= (mStartWidth - newWidth) / 2;
        newY -= (mStartHeight - newHeight) / 2;
    }

    // set new position
    child.setTranslationX(newX);
    child.setTranslationY(newY);

    // set alpha
    if (targetAlpha != UNSPECIFIED_FLOAT) {
        child.setAlpha(mStartAlpha + (targetAlpha - mStartAlpha) * percent);
    }

    // set background color
    if (targetBackgroundColor != UNSPECIFIED_INT && mStartBackgroundColor != 0) {
        ArgbEvaluator evaluator = new ArgbEvaluator();
        int color = (int) evaluator.evaluate(percent, mStartBackgroundColor, targetBackgroundColor);
        child.setBackgroundColor(color);
    }

    // set rotation
    if (targetRotateX != UNSPECIFIED_FLOAT) {
        child.setRotationX(mStartRotateX + (targetRotateX - mStartRotateX) * percent);
    }
    if (targetRotateY != UNSPECIFIED_FLOAT) {
        child.setRotationY(mStartRotateY + (targetRotateY - mStartRotateY) * percent);
    }

    child.requestLayout();
}
 
Example 5
Source File: SimpleViewBehavior.java    From simple-view-behavior with MIT License 4 votes vote down vote up
@Override
void updateViewWithPercent(View child, float percent) {
    super.updateViewWithPercent(child, percent);

    float newX = targetX == UNSPECIFIED_INT ? 0 : (targetX - mStartX) * percent;
    float newY = targetY == UNSPECIFIED_INT ? 0 : (targetY - mStartY) * percent;

    // set scale
    if (targetWidth != UNSPECIFIED_INT || targetHeight != UNSPECIFIED_INT) {
        float newWidth = mStartWidth + ((targetWidth - mStartWidth) * percent);
        float newHeight = mStartHeight + ((targetHeight - mStartHeight) * percent);

        child.setScaleX(newWidth / mStartWidth);
        child.setScaleY(newHeight / mStartHeight);
        // make up position for scale change
        newX -= (mStartWidth - newWidth) / 2;
        newY -= (mStartHeight - newHeight) / 2;
    }

    // set new position
    child.setTranslationX(newX);
    child.setTranslationY(newY);

    // set alpha
    if (targetAlpha != UNSPECIFIED_FLOAT) {
        child.setAlpha(mStartAlpha + (targetAlpha - mStartAlpha) * percent);
    }

    // set background color
    if (targetBackgroundColor != UNSPECIFIED_INT && mStartBackgroundColor != 0) {
        ArgbEvaluator evaluator = new ArgbEvaluator();
        int color = (int) evaluator.evaluate(percent, mStartBackgroundColor, targetBackgroundColor);
        child.setBackgroundColor(color);
    }

    // set rotation
    if (targetRotateX != UNSPECIFIED_FLOAT) {
        child.setRotationX(mStartRotateX + (targetRotateX - mStartRotateX) * percent);
    }
    if (targetRotateY != UNSPECIFIED_FLOAT) {
        child.setRotationY(mStartRotateY + (targetRotateY - mStartRotateY) * percent);
    }

    child.requestLayout();
}
 
Example 6
Source File: IntroScreenSlidePagerAdapter.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings({"deprecation", "ResourceAsColor"})
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    View tutorialLayout = mActivity.findViewById(R.id.tutorial_layout);
    ArgbEvaluator evaluator = new ArgbEvaluator();
    Object background = position < getCount() - 1 ?
            evaluator.evaluate(positionOffset, mActivity.getResources().getColor(colors[position]),
                    mActivity.getResources().getColor(colors[position + 1]))
            : mActivity.getResources().getColor(colors[position]);
    tutorialLayout.setBackgroundColor((int) background);
    MainActivity.setNavBarColor(mActivity.getWindow(), mActivity.getTheme(), (int)
            evaluator.evaluate(0.5f, mActivity.getResources().getColor(R.color.action_dark),
                    background));
    MainActivity.setStatusBarColor(mActivity.getWindow(), mActivity.getTheme(), (int)
            evaluator.evaluate(0.5f, mActivity.getResources().getColor(R.color.action_dark),
                    background));

    View gearA;
    View gearB;

    BubblePopImageView tableImageView = tutorialLayout.findViewById(R.id.table);
    position = rightToLeft ? getCount() - 1 - position : position;
    if (rightToLeft && positionOffset > 0.0) {
        position -= 1;
        positionOffset = 1f - positionOffset;
        positionOffsetPixels = (int) (positionOffset * mPager.getWidth());
    }

    switch (position) {
        case 0:
            if (tableImageView != null) {
                tableImageView.setProgress(positionOffset);
                tableImageView.setTranslationX((rightToLeft ? -1f : 1f) * (1f - positionOffset) *
                        (tableImageView.getMeasuredWidth() / 3f));
            }
            break;
        case 1:
            if (tableImageView != null) {
                tableImageView.setProgress(1f);
                tableImageView.setTranslationX((rightToLeft ? 0.15f : -0.4f) * positionOffsetPixels);
            }
            View bigFab = tutorialLayout.findViewById(R.id.big_fab);
            if (bigFab != null) {
                bigFab.setTranslationX((rightToLeft ? -1f : 1f) *
                        (1f - positionOffset) * (bigFab.getMeasuredWidth() / 3f));
                if (mCurrentPage == 1 ^ rightToLeft)
                    bigFab.setRotation(positionOffset * 360f);
                else
                    bigFab.setRotation((1f - positionOffset) * 360f);
            }
            break;
        /*case 2:
            View redKey = tutorialLayout.findViewById(R.id.intro_3_red_key);
            View yellowKey = tutorialLayout.findViewById(R.id.intro_3_yellow_key);
            if (redKey != null && yellowKey != null) {
                if (redKey.getMeasuredHeight() < redKey.getResources().getDimensionPixelSize(R.dimen.dp) * 15) {
                    redKey.setVisibility(View.INVISIBLE);
                    yellowKey.setVisibility(View.INVISIBLE);
                    break;
                } else {
                    redKey.setVisibility(View.VISIBLE);
                    yellowKey.setVisibility(View.VISIBLE);
                }
                redKey.setTranslationY(330f * (1 - positionOffset));
                yellowKey.setTranslationY(290f * Math.min(1.3f * (1 - positionOffset), 1.0f));
                yellowKey.setTranslationX(105f * Math.min(1.3f * (1 - positionOffset), 1.0f));
            }
            gearA = tutorialLayout.findViewById(R.id.redGear);
            gearB = tutorialLayout.findViewById(R.id.blueGear);
            if (3 == count - 2 && gearA != null && gearB != null) {
                gearA.setRotation(-180f * positionOffset);
                gearB.setRotation(180f * positionOffset);
            }
            break;*/
        case 2:
            gearA = tutorialLayout.findViewById(R.id.redGear);
            gearB = tutorialLayout.findViewById(R.id.blueGear);
            if (gearA != null && gearB != null) {
                gearA.setRotation(-180f * positionOffset);
                gearB.setRotation(180f * positionOffset);
            }
            break;
    }
}