Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
feat: Add StaticLayout maxLines support.
Browse files Browse the repository at this point in the history
PonyCui committed Nov 26, 2019
1 parent d0da4d5 commit fd63642
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -5,11 +5,14 @@ import android.graphics.*
import android.os.Build
import android.text.BoringLayout
import android.text.StaticLayout
import android.text.TextUtils
import android.widget.FrameLayout
import android.widget.ImageView
import com.opensource.svgaplayer.SVGADynamicEntity
import com.opensource.svgaplayer.SVGAVideoEntity
import com.opensource.svgaplayer.entities.SVGAVideoShapeEntity
import java.lang.Exception
import java.lang.reflect.Field

/**
* Created by cuiminghui on 2017/3/29.
@@ -271,7 +274,21 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
textBitmap = it
} ?: kotlin.run {
it.paint.isAntiAlias = true
var layout = StaticLayout(it.text, 0, it.text.length, it.paint, drawingBitmap.width, it.alignment, it.spacingMultiplier, it.spacingAdd, false)
var layout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
var lineMax = try {
val field = StaticLayout::class.java.getDeclaredField("mMaximumVisibleLineCount")
field.isAccessible = true
field.getInt(it)
} catch (e: Exception) { Int.MAX_VALUE }
StaticLayout.Builder
.obtain(it.text, 0, it.text.length, it.paint, drawingBitmap.width)
.setAlignment(it.alignment)
.setMaxLines(lineMax)
.setEllipsize(TextUtils.TruncateAt.END)
.build()
} else {
StaticLayout(it.text, 0, it.text.length, it.paint, drawingBitmap.width, it.alignment, it.spacingMultiplier, it.spacingAdd, false)
}
textBitmap = Bitmap.createBitmap(drawingBitmap.width, drawingBitmap.height, Bitmap.Config.ARGB_8888)
val textCanvas = Canvas(textBitmap)
textCanvas.translate(0f, ((drawingBitmap.height - layout.height) / 2).toFloat())

0 comments on commit fd63642

Please sign in to comment.