Skip to content

Instantly share code, notes, and snippets.

// reset paint object and set color, style, alpha by step
private void resetPaint(int step) {
paint.reset();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL);
paint.setColor(color);
if (step < 3) {
paint.setAlpha((int) (255 - (step + frame) * (255 - ALPHA_FINAL) / 3));
// "positive" is increasing positively horizontally
private float[] getHorizontalCenter(int width, int height, boolean positive) {
float x = (width - 2 * radius) * (positive ? frame : 1 - frame) + radius;
float y = positive ? radius : height - radius;
return new float[] {x, y};
}
// "negative" is increasing negatively vertically
private float[] getVerticalCenter(int width, int height, boolean negative) {
float x = negative ? width - radius : radius;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
// o ㅡㅡ o
//
//
// o o
public void start() {
ValueAnimator animator = ValueAnimator.ofInt(0, 1);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
frame = animation.getAnimatedFraction();
postInvalidate();
}
});
animator.setDuration(durationRotate);
public void setRadius(int radius) {
this.radius = radius;
postInvalidate();
}
public void setColor(int color) {
this.color = color;
postInvalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
float size = (width > height ? height : width) - tileMargin * 2;
float tileSize = size / 3;
// 참고로 안돌려보고 여기에서 대충 만든거라 컴파일 에러날 확률이 매우 높습니다.
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
outRect.setEmpty()
val position = parent.getChildAdapterPosition(view).takeIf { it != RecyclerView.NO_POSITION } ?: run {
return
}
val space = 20.dp
// 참고로 안돌려보고 여기에서 대충 만든거라 컴파일 에러날 확률이 매우 높습니다.
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
outRect.setEmpty()
val position = parent.getChildAdapterPosition(view).takeIf { it != RecyclerView.NO_POSITION } ?: run {
return
}
val space = 20.dp