Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onCompltion Listener added #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/java/com/masoudss/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.masoudss.R
import com.masoudss.databinding.ActivityMainBinding
import com.masoudss.lib.DrawCompletionListener
import com.masoudss.lib.SeekBarOnProgressChanged
import com.masoudss.lib.WaveformSeekBar
import com.masoudss.lib.utils.Utils
Expand Down Expand Up @@ -54,6 +55,11 @@ class MainActivity : AppCompatActivity() {
binding.waveProgress.progress = progress.toInt()
}
}
onCompletionListener = object : DrawCompletionListener {
override fun onDrawComplete() {
Toast.makeText(this@MainActivity, "onDrawComplete", Toast.LENGTH_SHORT).show()
}
}
}

binding.waveWidth.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/main/java/com/masoudss/lib/DrawCompletionListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.masoudss.lib

interface DrawCompletionListener {
fun onDrawComplete()
}
7 changes: 7 additions & 0 deletions lib/src/main/java/com/masoudss/lib/WaveformSeekBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ open class WaveformSeekBar @JvmOverloads constructor(
private var mAlreadyMoved = false
private lateinit var progressBitmap: Bitmap
private lateinit var progressShader: Shader
private var mOnCompleteCalled = false

var onProgressChanged: SeekBarOnProgressChanged? = null
var onCompletionListener: DrawCompletionListener? = null

var sample: IntArray? = null
set(value) {
Expand Down Expand Up @@ -367,6 +369,11 @@ open class WaveformSeekBar @JvmOverloads constructor(
canvas.drawText(it.value, markerTextDistance, markerTextXPosition, mMarkerPaint)
canvas.rotate(-90f)
}

if(!mOnCompleteCalled) {
mOnCompleteCalled = true
onCompletionListener?.onDrawComplete()
}
}
}

Expand Down