Created
April 10, 2022 11:59
-
-
Save andrewbel31/69fb6bcbfa67c520ac29b9005e190c6f to your computer and use it in GitHub Desktop.
Dispatching amplitude values to view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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