Last active
July 28, 2019 16:52
-
-
Save frogermcs/f900415dbbee650ef811 to your computer and use it in GitHub Desktop.
LikeAnimation source files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int cX = (int) (centerX + currentRadius1 * Math.cos(i * OUTER_DOTS_POSITION_ANGLE * Math.PI / 180)); | |
int cY = (int) (centerY + currentRadius1 * Math.sin(i * OUTER_DOTS_POSITION_ANGLE * Math.PI / 180)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onClick(View v) { | |
//... | |
animatorSet = new AnimatorSet(); | |
ObjectAnimator outerCircleAnimator = ObjectAnimator.ofFloat(vCircle, CircleView.OUTER_CIRCLE_RADIUS_PROGRESS, 0.1f, 1f); | |
outerCircleAnimator.setDuration(250); | |
outerCircleAnimator.setInterpolator(DECCELERATE_INTERPOLATOR); | |
ObjectAnimator innerCircleAnimator = ObjectAnimator.ofFloat(vCircle, CircleView.INNER_CIRCLE_RADIUS_PROGRESS, 0.1f, 1f); | |
innerCircleAnimator.setDuration(200); | |
innerCircleAnimator.setStartDelay(200); | |
innerCircleAnimator.setInterpolator(DECCELERATE_INTERPOLATOR); | |
ObjectAnimator starScaleYAnimator = ObjectAnimator.ofFloat(ivStar, ImageView.SCALE_Y, 0.2f, 1f); | |
starScaleYAnimator.setDuration(350); | |
starScaleYAnimator.setStartDelay(250); | |
starScaleYAnimator.setInterpolator(OVERSHOOT_INTERPOLATOR); | |
ObjectAnimator starScaleXAnimator = ObjectAnimator.ofFloat(ivStar, ImageView.SCALE_X, 0.2f, 1f); | |
starScaleXAnimator.setDuration(350); | |
starScaleXAnimator.setStartDelay(250); | |
starScaleXAnimator.setInterpolator(OVERSHOOT_INTERPOLATOR); | |
ObjectAnimator dotsAnimator = ObjectAnimator.ofFloat(vDotsView, DotsView.DOTS_PROGRESS, 0, 1f); | |
dotsAnimator.setDuration(900); | |
dotsAnimator.setStartDelay(50); | |
dotsAnimator.setInterpolator(ACCELERATE_DECELERATE_INTERPOLATOR); | |
animatorSet.playTogether( | |
outerCircleAnimator, | |
innerCircleAnimator, | |
starScaleYAnimator, | |
starScaleXAnimator, | |
dotsAnimator | |
); | |
//... | |
animatorSet.start(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Override | |
protected void onDraw(Canvas canvas) { | |
super.onDraw(canvas); | |
tempCanvas.drawColor(0xffffff, PorterDuff.Mode.CLEAR); | |
tempCanvas.drawCircle(getWidth() / 2, getHeight() / 2, outerCircleRadiusProgress * maxCircleSize, circlePaint); | |
tempCanvas.drawCircle(getWidth() / 2, getHeight() / 2, innerCircleRadiusProgress * maxCircleSize, maskPaint); | |
canvas.drawBitmap(tempBitmap, 0, 0, null); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onDraw(Canvas canvas) { | |
drawOuterDotsFrame(canvas); | |
drawInnerDotsFrame(canvas); | |
} | |
private void drawOuterDotsFrame(Canvas canvas) { | |
for (int i = 0; i < DOTS_COUNT; i++) { | |
int cX = (int) (centerX + currentRadius1 * Math.cos(i * OUTER_DOTS_POSITION_ANGLE * Math.PI / 180)); | |
int cY = (int) (centerY + currentRadius1 * Math.sin(i * OUTER_DOTS_POSITION_ANGLE * Math.PI / 180)); | |
canvas.drawCircle(cX, cY, currentDotSize1, circlePaints[i % circlePaints.length]); | |
} | |
} | |
private void drawInnerDotsFrame(Canvas canvas) { | |
for (int i = 0; i < DOTS_COUNT; i++) { | |
int cX = (int) (centerX + currentRadius2 * Math.cos((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)); | |
int cY = (int) (centerY + currentRadius2 * Math.sin((i * OUTER_DOTS_POSITION_ANGLE - 10) * Math.PI / 180)); | |
canvas.drawCircle(cX, cY, currentDotSize2, circlePaints[(i + 1) % circlePaints.length]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Override | |
protected void onSizeChanged(int w, int h, int oldw, int oldh) { | |
super.onSizeChanged(w, h, oldw, oldh); | |
maxCircleSize = w / 2; | |
tempBitmap = Bitmap.createBitmap(getWidth(), getWidth(), Bitmap.Config.ARGB_8888); | |
tempCanvas = new Canvas(tempBitmap); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
switch (event.getAction()) { | |
case MotionEvent.ACTION_DOWN: | |
ivStar.animate().scaleX(0.7f).scaleY(0.7f).setDuration(150).setInterpolator(DECCELERATE_INTERPOLATOR); | |
setPressed(true); | |
break; | |
case MotionEvent.ACTION_MOVE: | |
float x = event.getX(); | |
float y = event.getY(); | |
boolean isInside = (x > 0 && x < getWidth() && y > 0 && y < getHeight()); | |
if (isPressed() != isInside) { | |
setPressed(isInside); | |
} | |
break; | |
case MotionEvent.ACTION_UP: | |
ivStar.animate().scaleX(1).scaleY(1).setInterpolator(DECCELERATE_INTERPOLATOR); | |
if (isPressed()) { | |
performClick(); | |
setPressed(false); | |
} | |
break; | |
} | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void updateCircleColor() { | |
float colorProgress = (float) Utils.clamp(outerCircleRadiusProgress, 0.5, 1); | |
colorProgress = (float) Utils.mapValueFromRangeToRange(colorProgress, 0.5f, 1f, 0f, 1f); | |
this.circlePaint.setColor((Integer) argbEvaluator.evaluate(colorProgress, START_COLOR, END_COLOR)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void updateDotsPaints() { | |
if (currentProgress < 0.5f) { | |
float progress = (float) Utils.mapValueFromRangeToRange(currentProgress, 0f, 0.5f, 0, 1f); | |
circlePaints[0].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_1, COLOR_2)); | |
circlePaints[1].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_2, COLOR_3)); | |
circlePaints[2].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_3, COLOR_4)); | |
circlePaints[3].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_4, COLOR_1)); | |
} else { | |
float progress = (float) Utils.mapValueFromRangeToRange(currentProgress, 0.5f, 1f, 0, 1f); | |
circlePaints[0].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_2, COLOR_3)); | |
circlePaints[1].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_3, COLOR_4)); | |
circlePaints[2].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_4, COLOR_1)); | |
circlePaints[3].setColor((Integer) argbEvaluator.evaluate(progress, COLOR_1, COLOR_2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment