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
fun animateItemsOut() = animate(R.anim.item_animation_out) | |
fun animateItemsIn() = animate(R.anim.item_animation_in) | |
private fun animate(@AnimRes animationId: Int) { | |
var startOffset = 0L | |
for (i in childCount - 1 downTo 0) { | |
val set = AnimationUtils.loadAnimation(context, animationId) | |
set.startOffset = startOffset | |
getChildAt(i)?.startAnimation(set) |
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
class AnimatedLayoutManager constructor(private val context: Context) : LinearLayoutManager(context) { | |
// other code | |
override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int { | |
if (childCount == 0) return 0 | |
val legal = super.scrollVerticallyBy(dy, recycler, state) | |
calculateDy(dy) | |
updateViews() | |
return legal |
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 fun onDraw(canvas: Canvas) { | |
canvas?.drawOval(defRect, backgroundPaint) | |
canvas?.drawOval(animatedRect, foregroundPaint) | |
} | |
fun startAnimation() { | |
// ... | |
val animateLeft = ObjectAnimator.ofFloat(animatedRect, "left", animatedRect.left, toRect.left) | |
val animateTop = ObjectAnimator.ofFloat(animatedRect, "top", animatedRect.top, toRect.top) | |
val animateRight = ObjectAnimator.ofFloat(animatedRect, "right", animatedRect.right, toRect.right) |
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
{ | |
"version": 1, | |
"layers": { | |
"vectorLayer": { | |
"id": "2258", | |
"name": "vector", | |
"type": "vector", | |
"width": 24, | |
"height": 24, | |
"children": [ |
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 var angle = 0f | |
set(value) { | |
field = value | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
postInvalidateOnAnimation() | |
} else { | |
invalidate() | |
} | |
} |
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
textPaint.apply { | |
// some other initialization | |
xfermode = PorterDuffXfermode(PorterDuff.Mode.DST_ATOP) | |
} |
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
val topY = textPaint.ascent() * -1 - textBounds.height() | |
lightPath.moveTo(lightPivotX - letterWidth / 2f, topY) | |
lightPath.moveTo(lightPivotX + letterWidth / 2f, topY) | |
lightPath.lineTo(lightPivotX + width / 2f, width.toFloat()) | |
lightPath.lineTo(lightPivotX - width / 2f, width.toFloat()) | |
lightPath.lineTo(lightPivotX - letterWidth / 2f, topY) | |
lightPath.close() |
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 var animator = ValueAnimator.ofFloat(0f, 1f).apply { | |
addUpdateListener { | |
val value = it.animatedValue as Float | |
angle = lerp(0f, FULL_CIRCLE, value) | |
} | |
interpolator = CustomSpringInterpolator(INTERPOLATOR_FACTOR) | |
repeatMode = ValueAnimator.RESTART | |
repeatCount = ValueAnimator.INFINITE | |
duration = ANIMATION_DURATION | |
} |
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 fun onDraw(canvas: Canvas ?) { | |
canvas?.withRotation(angle, lightPivotX, lightPivotY) { | |
drawPath(lightPath, lightPaint) | |
} | |
canvas?.drawBitmap(textBitmap, 0f, 0f, textPaint) | |
} |
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 fun onDraw(canvas: Canvas ?) { | |
// draw switcher (green rect) | |
canvas?.drawRoundRect(switcherRect, switcherCornerRadius, switcherCornerRadius, switcherPaint) | |
// draw icon (white rect) | |
canvas?.withTranslation(x = iconTranslateX) { | |
drawRoundRect(iconRect, switcherCornerRadius, switcherCornerRadius, iconPaint) | |
} | |
} |
NewerOlder