For #2392 - Centers private browsing icon
parent
cfca683a14
commit
2dc76dda6a
|
@ -4,6 +4,8 @@
|
|||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
|
||||
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
import android.text.style.ImageSpan
|
||||
|
@ -12,10 +14,33 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import kotlinx.android.synthetic.main.onboarding_private_browsing.view.*
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
|
||||
|
||||
class OnboardingPrivateBrowsingViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
|
||||
init {
|
||||
val icon = ImageSpan(view.context, R.drawable.ic_private_browsing)
|
||||
val icon = object : ImageSpan(view.context, R.drawable.ic_private_browsing) {
|
||||
override fun draw(
|
||||
canvas: Canvas,
|
||||
text: CharSequence?,
|
||||
start: Int,
|
||||
end: Int,
|
||||
x: Float,
|
||||
top: Int,
|
||||
y: Int,
|
||||
bottom: Int,
|
||||
paint: Paint
|
||||
) {
|
||||
canvas.save()
|
||||
val fmPaint = paint.fontMetricsInt
|
||||
val fontHeight = fmPaint.descent - fmPaint.ascent
|
||||
val centerY = y + fmPaint.descent - fontHeight / 2
|
||||
val transY = (centerY - (drawable.bounds.bottom - drawable.bounds.top) / 2).toFloat()
|
||||
canvas.translate(x, transY)
|
||||
drawable.draw(canvas)
|
||||
canvas.restore()
|
||||
}
|
||||
}
|
||||
val text = SpannableString(view.context.getString(R.string.onboarding_private_browsing_description))
|
||||
|
||||
val spanStartIndex = text.indexOf(IMAGE_PLACEHOLDER)
|
||||
|
|
Loading…
Reference in New Issue