Fixes #34 : visual glitches when replaying a hand and exporting at the same time due to the static nature of the drawer

bs
Laurent 5 years ago
parent 2d1589babb
commit 7dafd0b87b
  1. 103
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayExportService.kt
  2. 15
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerAnimator.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerView.kt
  4. 112
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt

@ -18,13 +18,11 @@ import kotlinx.coroutines.launch
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.extensions.toByteArray
import net.pokeranalytics.android.util.FFMPEG_DESCRIPTOR_FILE import net.pokeranalytics.android.util.FFMPEG_DESCRIPTOR_FILE
import net.pokeranalytics.android.util.TriggerNotification import net.pokeranalytics.android.util.TriggerNotification
import net.pokeranalytics.android.util.extensions.dateTimeFileFormatted import net.pokeranalytics.android.util.extensions.dateTimeFileFormatted
import net.pokeranalytics.android.util.extensions.findById import net.pokeranalytics.android.util.extensions.findById
import net.pokeranalytics.android.util.video.AnimatedGIFWriter import net.pokeranalytics.android.util.video.AnimatedGIFWriter
import net.pokeranalytics.android.util.video.MMediaMuxer
import timber.log.Timber import timber.log.Timber
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
@ -79,7 +77,6 @@ class ReplayExportService : Service() {
val height = square val height = square
animator.setDimension(width.toFloat(), height.toFloat()) animator.setDimension(width.toFloat(), height.toFloat())
TableDrawer.configurePaints(context, animator)
val formattedDate = Date().dateTimeFileFormatted val formattedDate = Date().dateTimeFileFormatted
val path = File( val path = File(
@ -91,8 +88,11 @@ class ReplayExportService : Service() {
val os = FileOutputStream(path) val os = FileOutputStream(path)
writer.prepareForWrite(os, width, height) writer.prepareForWrite(os, width, height)
val drawer = TableDrawer()
drawer.configurePaints(context, animator)
var animationCount = 0 var animationCount = 0
animator.frames(context) { bitmap, count -> animator.frames(drawer, context) { bitmap, count ->
when { when {
count > 10 -> { count > 10 -> {
@ -137,11 +137,12 @@ class ReplayExportService : Service() {
val height = square val height = square
animator.setDimension(width.toFloat(), height.toFloat()) animator.setDimension(width.toFloat(), height.toFloat())
TableDrawer.configurePaints(context, animator) val drawer = TableDrawer()
drawer.configurePaints(context, animator)
// generates all images and file descriptor // generates all images and file descriptor
Timber.d("Generating images for video...") Timber.d("Generating images for video...")
val tmpDir = animator.generateVideoContent(this@ReplayExportService) val tmpDir = animator.generateVideoContent(drawer, this@ReplayExportService)
val dpath = "${tmpDir.path}/$FFMPEG_DESCRIPTOR_FILE" val dpath = "${tmpDir.path}/$FFMPEG_DESCRIPTOR_FILE"
val directory = context.getExternalFilesDir(null) ?: throw PAIllegalStateException("File is invalid") val directory = context.getExternalFilesDir(null) ?: throw PAIllegalStateException("File is invalid")
@ -170,51 +171,51 @@ class ReplayExportService : Service() {
} }
private fun startVideoExport() { // private fun startVideoExport() {
//
GlobalScope.launch(coroutineContext) { // GlobalScope.launch(coroutineContext) {
val c = GlobalScope.async { // val c = GlobalScope.async {
//
val realm = Realm.getDefaultInstance() // val realm = Realm.getDefaultInstance()
val handHistory = realm.findById<HandHistory>(handHistoryId) ?: throw PAIllegalStateException("HandHistory not found, id: $handHistoryId") // val handHistory = realm.findById<HandHistory>(handHistoryId) ?: throw PAIllegalStateException("HandHistory not found, id: $handHistoryId")
//
val context = this@ReplayExportService // val context = this@ReplayExportService
//
val animator = ReplayerAnimator(handHistory, true) // val animator = ReplayerAnimator(handHistory, true)
//
val square = 1024 // val square = 1024
//
val width = square // val width = square
val height = square // val height = square
//
animator.setDimension(width.toFloat(), height.toFloat()) // animator.setDimension(width.toFloat(), height.toFloat())
TableDrawer.configurePaints(context, animator) // TableDrawer.configurePaints(context, animator)
//
val muxer = MMediaMuxer() // val muxer = MMediaMuxer()
muxer.init(null, width, height, "hhVideo", "YES!") // muxer.init(null, width, height, "hhVideo", "YES!")
//
animator.frames(context) { bitmap, count -> // animator.frames(context) { bitmap, count ->
//
try { // try {
val byteArray = bitmap.toByteArray() // val byteArray = bitmap.toByteArray()
muxer.addFrame(byteArray, count, false) // muxer.addFrame(byteArray, count, false)
} catch (e: Exception) { // } catch (e: Exception) {
Timber.e("error = ${e.message}") // Timber.e("error = ${e.message}")
} // }
//
} // }
//
realm.close() // realm.close()
//
muxer.createVideo { path -> // muxer.createVideo { path ->
notifyUser(path) // notifyUser(path)
} // }
//
} // }
c.await() // c.await()
} // }
//
} // }
private fun notifyUser(path: String) { private fun notifyUser(path: String) {

@ -4,7 +4,6 @@ import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.RectF import android.graphics.RectF
import kotlinx.coroutines.delay
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.Action
@ -147,7 +146,6 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
init { init {
loadHandHistory(this.handHistory) loadHandHistory(this.handHistory)
TableDrawer.clearColors()
} }
private fun loadHandHistory(handHistory: HandHistory) { private fun loadHandHistory(handHistory: HandHistory) {
@ -479,7 +477,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
* Generates images and image descriptor to build the video using ffmpeg * Generates images and image descriptor to build the video using ffmpeg
* Command line: https://trac.ffmpeg.org/wiki/Slideshow * Command line: https://trac.ffmpeg.org/wiki/Slideshow
*/ */
suspend fun generateVideoContent(context: Context): File { fun generateVideoContent(tableDrawer: TableDrawer, context: Context): File {
var ffmpegImageDescriptor = "" var ffmpegImageDescriptor = ""
var count = 0 var count = 0
@ -500,21 +498,20 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
val canvas = Canvas(bitmap) val canvas = Canvas(bitmap)
val vo = this.visualOccurences / 90.0 // this is needed before the call to drawTable which pass to the next frame val vo = this.visualOccurences / 90.0 // this is needed before the call to drawTable which pass to the next frame
TableDrawer.drawTable(this, canvas, context) tableDrawer.drawTable(canvas, context)
imagePath = File(directory, "img_$count.png").path imagePath = File(directory, "img_$count.png").path
FileUtils.writeBitmapToPNG(bitmap, imagePath) FileUtils.writeBitmapToPNG(bitmap, imagePath)
bitmap.recycle() // bitmap.recycle()
ffmpegImageDescriptor = ffmpegImageDescriptor.plus("file '$imagePath'\n") ffmpegImageDescriptor = ffmpegImageDescriptor.plus("file '$imagePath'\n")
ffmpegImageDescriptor = ffmpegImageDescriptor.plus("duration $vo\n") ffmpegImageDescriptor = ffmpegImageDescriptor.plus("duration $vo\n")
count++ count++
Thread.sleep(100L) // awaitFrame()
// delay(100L)
} }
nextStep() nextStep()
@ -537,7 +534,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
* As soon as a bitmap has been created, the [frameHandler] is called with the created * As soon as a bitmap has been created, the [frameHandler] is called with the created
* bitmap, and a appropriate occurrences of the bitmap to be added is passed along * bitmap, and a appropriate occurrences of the bitmap to be added is passed along
*/ */
fun frames(context: Context, frameHandler: (Bitmap, Int) -> Unit) { fun frames(tableDrawer: TableDrawer, context: Context, frameHandler: (Bitmap, Int) -> Unit) {
Timber.d("Step count = ${this.steps.size}") Timber.d("Step count = ${this.steps.size}")
@ -553,7 +550,7 @@ class ReplayerAnimator(var handHistory: HandHistory, var export: Boolean) {
val canvas = Canvas(bitmap) val canvas = Canvas(bitmap)
val vo = this.visualOccurences // this is needed before the call to drawTable which pass to the next frame val vo = this.visualOccurences // this is needed before the call to drawTable which pass to the next frame
TableDrawer.drawTable(this, canvas, context) tableDrawer.drawTable(canvas, context)
frameHandler(bitmap, vo) frameHandler(bitmap, vo)

@ -9,6 +9,8 @@ import android.view.View
class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs) { class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private var drawer: TableDrawer = TableDrawer()
lateinit var animator: ReplayerAnimator lateinit var animator: ReplayerAnimator
private val animationHandler = Handler(Looper.getMainLooper()) private val animationHandler = Handler(Looper.getMainLooper())
@ -20,7 +22,7 @@ class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs)
init { init {
this.viewTreeObserver.addOnGlobalLayoutListener { this.viewTreeObserver.addOnGlobalLayoutListener {
this.animator.setDimension(width.toFloat(), height.toFloat()) this.animator.setDimension(width.toFloat(), height.toFloat())
TableDrawer.configurePaints(context, this.animator) this.drawer.configurePaints(context, this.animator)
} }
} }
@ -37,7 +39,7 @@ class ReplayerView(context: Context, attrs: AttributeSet) : View(context, attrs)
super.onDraw(canvas) super.onDraw(canvas)
canvas?.let { canvas?.let {
TableDrawer.drawTable(animator, canvas, context) this.drawer.drawTable(canvas, context)
} }
} }

@ -12,11 +12,11 @@ import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction
import net.pokeranalytics.android.util.RANDOM_PLAYER import net.pokeranalytics.android.util.RANDOM_PLAYER
import net.pokeranalytics.android.util.extensions.formatted import net.pokeranalytics.android.util.extensions.formatted
class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) { class TableDrawer {
companion object { lateinit var animator: ReplayerAnimator
private const val backgroundColor = R.color.green_darker private val backgroundColor = R.color.green_darker
private val backgroundPaint = Paint() private val backgroundPaint = Paint()
private val strokePaint = Paint() private val strokePaint = Paint()
private val fillPaint = Paint() private val fillPaint = Paint()
@ -30,12 +30,14 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
private val colorsByAmount = hashMapOf<Double, ChipColor>() private val colorsByAmount = hashMapOf<Double, ChipColor>()
fun clearColors() { // fun clearColors() {
this.colorsByAmount.clear() // this.colorsByAmount.clear()
} // }
fun configurePaints(context: Context, animator: ReplayerAnimator) { fun configurePaints(context: Context, animator: ReplayerAnimator) {
this.animator = animator
backgroundPaint.color = context.getColor(backgroundColor) backgroundPaint.color = context.getColor(backgroundColor)
tablePaint.isAntiAlias = true tablePaint.isAntiAlias = true
@ -72,15 +74,15 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
cardTextPaint.isAntiAlias = true cardTextPaint.isAntiAlias = true
} }
fun drawTable(animator: ReplayerAnimator, canvas: Canvas, context: Context) { fun drawTable(canvas: Canvas, context: Context) {
drawTableItems(animator, canvas, context) drawTableItems(canvas, context)
animator.frameDrawn() animator.frameDrawn()
} }
private fun drawTableItems(animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawTableItems(canvas: Canvas, context: Context) {
// base // base
initializeTable(animator, canvas, context) initializeTable(canvas, context)
val step = animator.currentStep val step = animator.currentStep
val street = step.street val street = step.street
@ -88,31 +90,31 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
val computedAction = step as? ComputedAction? val computedAction = step as? ComputedAction?
// draw board // draw board
drawBoardCards(street, animator, canvas, context) drawBoardCards(street, canvas, context)
// draw player shapes and chips // draw player shapes and chips
val hh = animator.handHistory val hh = animator.handHistory
for (i in 0 until hh.numberOfPlayers) { for (i in 0 until hh.numberOfPlayers) {
drawPlayerShapes(i, computedAction, animator, canvas, context) drawPlayerShapes(i, computedAction, canvas, context)
drawPlayerChips(i, animator, canvas, context) drawPlayerChips(i, canvas, context)
} }
// draw pot // draw pot
drawPot(street, computedAction, animator, canvas, context) drawPot(street, computedAction, canvas, context)
// draw player cards // draw player cards
animator.activePositions.forEach { animator.activePositions.forEach {
drawPlayerCards(it, animator, canvas, context) drawPlayerCards(it, canvas, context)
} }
} }
private fun drawPlayerShapes(i: Int, computedAction: ComputedAction?, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawPlayerShapes(i: Int, computedAction: ComputedAction?, canvas: Canvas, context: Context) {
// draw player rectangles with action or name + stack // draw player rectangles with action or name + stack
if (computedAction?.positionIndex == i) { if (computedAction?.positionIndex == i) {
drawPlayerRectangle(i, true, animator, canvas, context) drawPlayerRectangle(i, true, canvas, context)
drawAction(i, computedAction, animator, canvas, context) drawAction(i, computedAction, canvas, context)
} else { } else {
val info = if (animator.isPlayerAllin(i)) { val info = if (animator.isPlayerAllin(i)) {
context.getString(R.string.allin) context.getString(R.string.allin)
@ -120,8 +122,8 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
val remainingStack = animator.playerRemainingStack(i) val remainingStack = animator.playerRemainingStack(i)
remainingStack?.formatted remainingStack?.formatted
} }
drawPlayerRectangle(i, false, animator, canvas, context) drawPlayerRectangle(i, false, canvas, context)
drawPositionAndInfo(i, info, animator, canvas) drawPositionAndInfo(i, info, canvas)
} }
} }
@ -130,7 +132,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
* Draw chips * Draw chips
* A chip should appears when the player has put some money during the current street * A chip should appears when the player has put some money during the current street
*/ */
private fun drawPlayerChips(i: Int, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawPlayerChips(i: Int, canvas: Canvas, context: Context) {
when (animator.currentStep) { when (animator.currentStep) {
is Street -> { is Street -> {
@ -149,7 +151,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
} }
FrameType.GATHER_ANIMATION -> { FrameType.GATHER_ANIMATION -> {
lastCommittedAmount(i, animator)?.let { amount -> lastCommittedAmount(i)?.let { amount ->
val color = colorForAmount(amount) val color = colorForAmount(amount)
val circle = animator.animatedChipCircleToPot(i) val circle = animator.animatedChipCircleToPot(i)
drawChipCircle(circle, color, canvas, context) drawChipCircle(circle, color, canvas, context)
@ -167,19 +169,19 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
} }
is ComputedAction -> { is ComputedAction -> {
drawChipForAction(i, animator, canvas, context) drawChipForAction(i, canvas, context)
} }
} }
} }
private fun drawChipForAction(i: Int, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawChipForAction(i: Int, canvas: Canvas, context: Context) {
lastCommittedAmount(i, animator)?.let { amount -> lastCommittedAmount(i)?.let { amount ->
drawChip(amount, i, animator, canvas, context) drawChip(amount, i, canvas, context)
} }
} }
private fun lastCommittedAmount(i: Int, animator: ReplayerAnimator): Double? { private fun lastCommittedAmount(i: Int): Double? {
var committingAction = animator.lastChipCommittingActionOfPlayer(i) var committingAction = animator.lastChipCommittingActionOfPlayer(i)
if (committingAction?.action?.type?.isCall == true) { if (committingAction?.action?.type?.isCall == true) {
committingAction = committingAction.getStreetLastSignificantAction() committingAction = committingAction.getStreetLastSignificantAction()
@ -190,44 +192,22 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
/*** /***
* WARNING: Avoid instancing objects here, as it's called from onDraw method * WARNING: Avoid instancing objects here, as it's called from onDraw method
*/ */
private fun initializeTable(animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun initializeTable(canvas: Canvas, context: Context) {
canvas.drawColor(context.getColor(backgroundColor)) canvas.drawColor(context.getColor(backgroundColor))
// Felt rosace
// val xr = animator.tableCornerXRadius
// val yr = animator.tableCornerYRadius
// val r = animator.tableRect
// val r1 = RectF(r.left, r.top, r.left + 2 * xr, r.top + 2 * yr)
// canvas.drawRoundRect(r1, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r2 = RectF(r.right - 2 * xr, r.top, r.right, r.top + 2 * yr)
// canvas.drawRoundRect(r2, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r3 = RectF(r.right - 2 * xr, r.bottom - 2 * yr, r.right, r.bottom)
// canvas.drawRoundRect(r3, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r4 = RectF(r.left, r.bottom - 2 * yr, r.left + 2 * xr, r.bottom)
// canvas.drawRoundRect(r4, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r5 = RectF(r.right - 2 * xr, r.centerY() - yr, r.right, r.centerY() + yr)
// canvas.drawRoundRect(r5, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r6 = RectF(r.right - 2 * xr, r.top, r.right, r.top + 2 * yr)
// canvas.drawRoundRect(r6, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r7 = RectF(r.left, r.centerY() - yr, r.left + 2 * xr, r.centerY() + yr)
// canvas.drawRoundRect(r7, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
// val r8 = RectF(r.left, r.bottom - 2 * yr, r.left + 2 * xr, r.bottom)
// canvas.drawRoundRect(r8, animator.tableCornerXRadius, animator.tableCornerYRadius, this.feltPaint)
canvas.drawRoundRect(animator.tableRect, animator.tableCornerXRadius, animator.tableCornerYRadius, this.tablePaint) canvas.drawRoundRect(animator.tableRect, animator.tableCornerXRadius, animator.tableCornerYRadius, this.tablePaint)
this.cardTextPaint.textSize = animator.cardSpecs.height * .38f this.cardTextPaint.textSize = animator.cardSpecs.height * .38f
val hh = animator.handHistory val hh = animator.handHistory
for (i in 0 until hh.numberOfPlayers) { for (i in 0 until hh.numberOfPlayers) {
drawPlayerRectangle(i,false, animator, canvas, context) drawPlayerRectangle(i,false, canvas, context)
drawPlayerCircle(i, animator, canvas, context) drawPlayerCircle(i, canvas, context)
} }
} }
private fun drawChip(amount: Double, playerIndex: Int, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawChip(amount: Double, playerIndex: Int, canvas: Canvas, context: Context) {
val circle = animator.chipCircle(playerIndex) val circle = animator.chipCircle(playerIndex)
val text = animator.chipText(playerIndex) val text = animator.chipText(playerIndex)
drawChip(amount, text, circle, canvas, context) drawChip(amount, text, circle, canvas, context)
@ -268,7 +248,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun drawPlayerCards(playerIndex: Int, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawPlayerCards(playerIndex: Int, canvas: Canvas, context: Context) {
val playerSetup = animator.handHistory.playerSetupForPosition(playerIndex) val playerSetup = animator.handHistory.playerSetupForPosition(playerIndex)
val cardRects = animator.cardRects(playerIndex) val cardRects = animator.cardRects(playerIndex)
@ -278,7 +258,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
if (j < cards?.size ?: 0 && (animator.showVillainHands || isHero)) { // show card if (j < cards?.size ?: 0 && (animator.showVillainHands || isHero)) { // show card
val card = cards?.get(j)!! // tested line before val card = cards?.get(j)!! // tested line before
drawCard(card, cardRect, animator, canvas, context) drawCard(card, cardRect, canvas, context)
} else { // show hidden cards } else { // show hidden cards
fillPaint.color = context.getColor(R.color.card_fill) fillPaint.color = context.getColor(R.color.card_fill)
canvas.drawRoundRect(cardRect, animator.cardRadius, animator.cardRadius, fillPaint) canvas.drawRoundRect(cardRect, animator.cardRadius, animator.cardRadius, fillPaint)
@ -290,7 +270,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun drawCard(card: Card, cardRect: RectF, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawCard(card: Card, cardRect: RectF, canvas: Canvas, context: Context) {
fillPaint.color = context.getColor(R.color.white) fillPaint.color = context.getColor(R.color.white)
canvas.drawRoundRect(cardRect, animator.cardRadius, animator.cardRadius, fillPaint) canvas.drawRoundRect(cardRect, animator.cardRadius, animator.cardRadius, fillPaint)
@ -306,7 +286,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun drawPlayerCircle(i: Int, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawPlayerCircle(i: Int, canvas: Canvas, context: Context) {
val playerSetup = animator.handHistory.playerSetupForPosition(i) val playerSetup = animator.handHistory.playerSetupForPosition(i)
@ -337,7 +317,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
/*** /***
* [i] is the player position in the hand * [i] is the player position in the hand
*/ */
private fun drawPlayerRectangle(i: Int, highlighted: Boolean, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawPlayerRectangle(i: Int, highlighted: Boolean, canvas: Canvas, context: Context) {
val rect = animator.stackRectForPlayer(i) val rect = animator.stackRectForPlayer(i)
val rectRadius = (rect.bottom - rect.top) / 4 val rectRadius = (rect.bottom - rect.top) / 4
@ -359,11 +339,11 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
) )
if (i == animator.handHistory.numberOfPlayers - 1) { // refresh dealer button if (i == animator.handHistory.numberOfPlayers - 1) { // refresh dealer button
drawDealerButton(animator, canvas, context) drawDealerButton(canvas, context)
} }
} }
private fun drawDealerButton(animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawDealerButton(canvas: Canvas, context: Context) {
// Dealer button // Dealer button
val dealerCircle = animator.dealerCircle val dealerCircle = animator.dealerCircle
@ -376,7 +356,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun drawPositionAndInfo(i: Int, secondLine: String?, animator: ReplayerAnimator, canvas: Canvas) { private fun drawPositionAndInfo(i: Int, secondLine: String?, canvas: Canvas) {
val hh = animator.handHistory val hh = animator.handHistory
// Player position // Player position
@ -395,7 +375,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun drawAction(i: Int, action: ComputedAction, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawAction(i: Int, action: ComputedAction, canvas: Canvas, context: Context) {
action.action.type?.let { type -> action.action.type?.let { type ->
val actionName = context.getString(type.resId) val actionName = context.getString(type.resId)
@ -417,18 +397,18 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
private fun drawBoardCards(street: Street, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawBoardCards(street: Street, canvas: Canvas, context: Context) {
val cards = animator.handHistory.cardsForStreet(street) val cards = animator.handHistory.cardsForStreet(street)
animator.boardCardRects.take(street.totalBoardCards).forEachIndexed { index, rectF -> animator.boardCardRects.take(street.totalBoardCards).forEachIndexed { index, rectF ->
if (index < cards.size) { if (index < cards.size) {
drawCard(cards[index], rectF, animator, canvas, context) drawCard(cards[index], rectF, canvas, context)
} }
} }
} }
private fun drawPot(street: Street, computedAction: ComputedAction?, animator: ReplayerAnimator, canvas: Canvas, context: Context) { private fun drawPot(street: Street, computedAction: ComputedAction?, canvas: Canvas, context: Context) {
if (street == Street.SUMMARY && animator.frameType != FrameType.GATHER_ANIMATION) { if (street == Street.SUMMARY && animator.frameType != FrameType.GATHER_ANIMATION) {
return return
@ -452,8 +432,6 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
}
} }
private data class ChipColor(val fillColor: Int, val borderColor: Int) { private data class ChipColor(val fillColor: Int, val borderColor: Int) {

Loading…
Cancel
Save