Add Gift badging bow.
This commit is contained in:
parent
bc44704f54
commit
1f8f1d433b
2 changed files with 33 additions and 9 deletions
|
@ -6,9 +6,12 @@ import android.graphics.Canvas
|
|||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.RectF
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.provider.Settings
|
||||
import android.view.animation.AccelerateDecelerateInterpolator
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.toRect
|
||||
import androidx.core.graphics.withSave
|
||||
import androidx.core.graphics.withTranslation
|
||||
import androidx.core.view.children
|
||||
|
@ -33,18 +36,22 @@ class OpenableGiftItemDecoration(context: Context) : RecyclerView.ItemDecoration
|
|||
private val animationState = mutableMapOf<Long, GiftAnimationState>()
|
||||
|
||||
private val rect = RectF()
|
||||
private val lineWidth = DimensionUnit.DP.toPixels(24f).toInt()
|
||||
private val lineWidth = DimensionUnit.DP.toPixels(16f).toInt()
|
||||
|
||||
private val boxPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = ContextCompat.getColor(context, R.color.core_ultramarine)
|
||||
}
|
||||
|
||||
private val ribbonPaint = Paint().apply {
|
||||
private val bowPaint = Paint().apply {
|
||||
isAntiAlias = true
|
||||
color = Color.WHITE
|
||||
}
|
||||
|
||||
private val bowWidth = DimensionUnit.DP.toPixels(80f)
|
||||
private val bowHeight = DimensionUnit.DP.toPixels(60f)
|
||||
private val bowDrawable: Drawable = AppCompatResources.getDrawable(context, R.drawable.ic_gift_bow)!!
|
||||
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
super.onDestroy(owner)
|
||||
animationState.clear()
|
||||
|
@ -124,7 +131,7 @@ class OpenableGiftItemDecoration(context: Context) : RecyclerView.ItemDecoration
|
|||
projection.y + projection.height
|
||||
)
|
||||
|
||||
canvas.drawRect(rect, ribbonPaint)
|
||||
canvas.drawRect(rect, bowPaint)
|
||||
|
||||
rect.set(
|
||||
projection.x,
|
||||
|
@ -133,18 +140,23 @@ class OpenableGiftItemDecoration(context: Context) : RecyclerView.ItemDecoration
|
|||
projection.y + (projection.height / 2) + lineWidth / 2
|
||||
)
|
||||
|
||||
canvas.drawRect(rect, ribbonPaint)
|
||||
canvas.drawRect(rect, bowPaint)
|
||||
}
|
||||
|
||||
private fun drawGiftBow(canvas: Canvas, projection: Projection) {
|
||||
rect.set(
|
||||
projection.x + (projection.width / 2) - lineWidth,
|
||||
projection.y + (projection.height / 2) - lineWidth,
|
||||
projection.x + (projection.width / 2) + lineWidth,
|
||||
projection.y + (projection.height / 2) + lineWidth
|
||||
projection.x + (projection.width / 2) - (bowWidth / 2),
|
||||
projection.y,
|
||||
projection.x + (projection.width / 2) + (bowWidth / 2),
|
||||
projection.y + bowHeight
|
||||
)
|
||||
|
||||
canvas.drawRect(rect, ribbonPaint)
|
||||
val padTop = (projection.height - rect.height()) * (48f / 89f)
|
||||
|
||||
bowDrawable.bounds = rect.toRect()
|
||||
canvas.withTranslation(y = padTop) {
|
||||
bowDrawable.draw(canvas)
|
||||
}
|
||||
}
|
||||
|
||||
private fun startShakeAnimation(child: OpenableGift) {
|
||||
|
|
12
app/src/main/res/drawable/ic_gift_bow.xml
Normal file
12
app/src/main/res/drawable/ic_gift_bow.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="80dp"
|
||||
android:height="60dp"
|
||||
android:viewportWidth="80"
|
||||
android:viewportHeight="60">
|
||||
<path
|
||||
android:pathData="M78.738,36.229l-6.797,-4.513c2.831,-0.994 5.188,-2.288 6.311,-3.947 0.864,-1.277 1.032,-2.749 0.473,-4.147 -3.227,-8.067 -7.676,-15.12 -13.223,-20.963l-0.889,-0.936 -1.219,0.424c-9.233,3.215 -17.112,12.09 -20.719,16.685 -0.825,-0.229 -1.757,-0.292 -2.677,-0.292s-1.852,0.063 -2.678,0.291c-3.607,-4.595 -11.485,-13.469 -20.717,-16.683l-1.219,-0.424 -0.889,0.936C8.95,8.502 4.501,15.555 1.274,23.622c-0.559,1.398 -0.391,2.871 0.473,4.147 1.123,1.659 3.48,2.953 6.311,3.947l-6.797,4.513 -1.052,0.698 0.178,1.25 2.573,18.069 0.485,3.406 2.72,-2.107c0.786,-0.609 19.3,-14.953 22.677,-17.79 0.925,-0.777 4.435,-3.789 7.171,-6.997 0.981,0.326 2.269,0.482 3.986,0.482s3.005,-0.156 3.986,-0.482c2.736,3.208 6.246,6.22 7.171,6.997 3.377,2.837 21.89,17.18 22.677,17.79l2.72,2.107 0.485,-3.406 2.573,-18.069 0.178,-1.25 -1.052,-0.698Z"
|
||||
android:fillColor="#2c6bed"/>
|
||||
<path
|
||||
android:pathData="M54.872,34.542c2.815,0 9.139,-0.572 14.602,-2.063l8.158,5.417 -2.573,18.069s-19.23,-14.896 -22.615,-17.74c-1.637,-1.375 -3.599,-3.174 -5.349,-5.013 1.802,0.578 3.962,1.099 6.284,1.28 0.433,0.034 0.935,0.051 1.493,0.051ZM4.941,55.964s19.23,-14.896 22.615,-17.74c1.637,-1.375 3.599,-3.174 5.349,-5.013 -1.802,0.578 -3.962,1.099 -6.284,1.28 -0.433,0.034 -0.935,0.051 -1.493,0.051 -2.815,0 -9.139,-0.572 -14.602,-2.063l-8.158,5.417 2.573,18.069ZM43.241,21.846c-0.097,-0.513 -0.154,-1.306 -3.241,-1.306s-3.144,0.793 -3.241,1.306l-1.227,7.615c-0.123,0.649 -0.002,1.779 4.468,1.779s4.591,-1.13 4.468,-1.779l-1.227,-7.615ZM76.869,24.365c-2.298,-5.745 -6.187,-13.346 -12.816,-20.329 -8.561,2.981 -16.064,11.33 -19.62,15.81 0.369,0.409 0.646,0.933 0.774,1.629l0.005,0.026 0.004,0.027 1.223,7.594c0.123,0.685 0.025,1.246 -0.156,1.693 1.893,0.709 4.464,1.464 7.252,1.682 0.384,0.03 0.833,0.045 1.337,0.045 6.927,0 24.139,-2.821 21.997,-8.176ZM33.561,29.121l1.223,-7.594 0.012,-0.065 0.004,-0.022c0.125,-0.683 0.398,-1.199 0.762,-1.601 -3.558,-4.481 -11.058,-12.824 -19.615,-15.803C9.318,11.019 5.429,18.62 3.131,24.365c-2.142,5.355 15.07,8.176 21.997,8.176 0.504,0 0.953,-0.015 1.337,-0.045 2.788,-0.218 5.359,-0.972 7.252,-1.682 -0.181,-0.447 -0.28,-1.008 -0.156,-1.693Z"
|
||||
android:fillColor="#fff"/>
|
||||
</vector>
|
Loading…
Add table
Reference in a new issue