Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.github.mikephil.charting.jobs

import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.view.View
import com.github.mikephil.charting.utils.ObjectPool
import com.github.mikephil.charting.utils.ObjectPool.Poolable
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.ViewPortHandler

@SuppressLint("NewApi")
class AnimatedMoveViewJob(
viewPortHandler: ViewPortHandler?,
xValue: Float,
yValue: Float,
trans: Transformer?,
v: View?,
xOrigin: Float,
yOrigin: Float,
duration: Long
) : AnimatedViewPortJob(viewPortHandler, xValue, yValue, trans, v, xOrigin, yOrigin, duration) {
override fun onAnimationUpdate(animation: ValueAnimator) {
pts[0] = xOrigin + (xValue - xOrigin) * phase
pts[1] = yOrigin + (yValue - yOrigin) * phase

transformer!!.pointValuesToPixel(pts)
viewPortHandler!!.centerViewPort(pts, view!!)
}

override fun recycleSelf() {
recycleInstance(this)
}

protected override fun instantiate(): Poolable {
return AnimatedMoveViewJob(null, 0f, 0f, null, null, 0f, 0f, 0)
}

companion object {
private val pool: ObjectPool<AnimatedMoveViewJob>

init {
pool = ObjectPool.create(4, AnimatedMoveViewJob(null, 0f, 0f, null, null, 0f, 0f, 0)) as ObjectPool<AnimatedMoveViewJob>
pool.setReplenishPercentage(0.5f)
}

@JvmStatic
fun getInstance(
viewPortHandler: ViewPortHandler?,
xValue: Float,
yValue: Float,
trans: Transformer?,
v: View?,
xOrigin: Float,
yOrigin: Float,
duration: Long
): AnimatedMoveViewJob {
val result: AnimatedMoveViewJob = pool.get()
result.viewPortHandler = viewPortHandler
result.xValue = xValue
result.yValue = yValue
result.transformer = trans
result.view = v
result.xOrigin = xOrigin
result.yOrigin = yOrigin
//result.resetAnimator();
result.animator.duration = duration
return result
}

fun recycleInstance(instance: AnimatedMoveViewJob) {
// Clear reference avoid memory leak
instance.xValue = 0f
instance.yValue = 0f
instance.xOrigin = 0f
instance.yOrigin = 0f
instance.animator.duration = 0
instance.recycle()
pool.recycle(instance)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.github.mikephil.charting.jobs

import android.animation.Animator
import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.animation.ValueAnimator.AnimatorUpdateListener
import android.annotation.SuppressLint
import android.view.View
import com.github.mikephil.charting.utils.Transformer
import com.github.mikephil.charting.utils.ViewPortHandler

@SuppressLint("NewApi")
abstract class AnimatedViewPortJob(
viewPortHandler: ViewPortHandler?,
xValue: Float,
yValue: Float,
trans: Transformer?,
v: View?,
var xOrigin: Float,
var yOrigin: Float,
duration: Long
) : ViewPortJob(viewPortHandler, xValue, yValue, trans, v), AnimatorUpdateListener, Animator.AnimatorListener {
protected var animator: ObjectAnimator = ObjectAnimator.ofFloat(this, "phase", 0f, 1f)

var phase: Float = 0f

init {
animator.duration = duration
animator.addUpdateListener(this)
animator.addListener(this)
}

@SuppressLint("NewApi")
override fun run() {
animator.start()
}

abstract fun recycleSelf()

protected fun resetAnimator() {
animator.removeAllListeners()
animator.removeAllUpdateListeners()
animator.reverse()
animator.addUpdateListener(this)
animator.addListener(this)
}

override fun onAnimationStart(animation: Animator) {
}

override fun onAnimationEnd(animation: Animator) {
try {
recycleSelf()
} catch (_: IllegalArgumentException) {
}
}

override fun onAnimationCancel(animation: Animator) {
try {
recycleSelf()
} catch (_: IllegalArgumentException) {
}
}

override fun onAnimationRepeat(animation: Animator) = Unit

override fun onAnimationUpdate(animation: ValueAnimator) = Unit
}
Loading
Loading