Skip to content

Commit

Permalink
Bug fix about calculating size
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 26, 2019
1 parent c054133 commit 7dc4f0e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/src/main/java/com/masoudss/lib/WaveformSeekBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import android.view.ViewConfiguration
import androidx.annotation.RequiresApi
import com.masoudss.lib.exception.SampleDataException
import java.io.File
import kotlin.math.abs

class WaveformSeekBar : View {

private var mCanvasWidth = 0
private var mCanvasHeight = 0

private val mWavePaint = Paint(Paint.ANTI_ALIAS_FLAG)
private val mWaveRect = RectF()
private val mProgressCanvas = Canvas()
Expand Down Expand Up @@ -54,6 +58,12 @@ class WaveformSeekBar : View {
ta.recycle()
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
mCanvasWidth = w
mCanvasHeight = h
}

@SuppressLint("DrawAllocation")
override fun onDraw(canvas: Canvas) {

Expand All @@ -76,7 +86,7 @@ class WaveformSeekBar : View {
val top : Float = when(waveGravity){
WaveGravity.TOP -> paddingTop.toFloat()
WaveGravity.CENTER -> paddingTop+getAvailableHeight()/2F - waveHeight/2F
WaveGravity.BOTTOM -> height - paddingBottom - waveHeight
WaveGravity.BOTTOM -> mCanvasHeight - paddingBottom - waveHeight
}

mWaveRect.set(lastWaveRight, top, lastWaveRight+waveWidth, top + waveHeight)
Expand Down Expand Up @@ -137,7 +147,7 @@ class WaveformSeekBar : View {
updateProgress(event)
}
MotionEvent.ACTION_UP ->{
if (Math.abs(event.x - mTouchDownX) > mScaledTouchSlop)
if (abs(event.x - mTouchDownX) > mScaledTouchSlop)
updateProgress(event)

performClick()
Expand Down Expand Up @@ -180,8 +190,8 @@ class WaveformSeekBar : View {
return true
}

private fun getAvailableWith() = width-paddingLeft-paddingRight
private fun getAvailableHeight() = height-paddingTop-paddingBottom
private fun getAvailableWith() = mCanvasWidth-paddingLeft-paddingRight
private fun getAvailableHeight() = mCanvasHeight-paddingTop-paddingBottom

var onProgressChanged : SeekBarOnProgressChanged? = null

Expand Down

0 comments on commit 7dc4f0e

Please sign in to comment.