Skip to content

Instantly share code, notes, and snippets.

@andreymusth
Created April 10, 2022 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreymusth/69fb6bcbfa67c520ac29b9005e190c6f to your computer and use it in GitHub Desktop.
Save andreymusth/69fb6bcbfa67c520ac29b9005e190c6f to your computer and use it in GitHub Desktop.
Dispatching amplitude values to view
class MainActivity : AppCompatActivity() {
private val handler = Handler(Looper.getMainLooper())
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val dynamic = findViewById<DynamicView>(R.id.dynamic1)
val button = findViewById<Button>(R.id.button)
button.setOnClickListener {
button.isEnabled = false
for (i in 0 until 100) {
handler.postDelayed({
val ampl = Random.nextFloat() * 1200
dynamic.setAmplitude(ampl)
if (i == 99) {
button.isEnabled = true
dynamic.setAmplitude(500f)
}
}, i * 100L)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment