Advertisement
Guest User

x

a guest
Jan 21st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. val current = sm.amplitude
  2. sm.start()
  3. if (current > maxLaugh) {
  4. maxLaugh = current
  5. }
  6. if (current > 300) {
  7. // change the responses
  8. when {
  9. current > 6 * maxLaugh / 7 -> {
  10. //Only the original thread that created a view hierarchy can touch its views.
  11. runOnUiThread {
  12. im.setBackgroundColor(Color.RED)
  13. }
  14. startService(intentFor<TorchService>().setAction("on"))
  15. startService(intentFor<TorchService>().setAction("off"))
  16. }
  17. current > 5 * maxLaugh / 7 -> {
  18. runOnUiThread {
  19. im.setBackgroundColor(Color.BLUE)
  20. }
  21. startService(intentFor<TorchService>().setAction("on"))
  22. startService(intentFor<TorchService>().setAction("off"))
  23. }
  24. current > 4 * maxLaugh / 7 -> {
  25. runOnUiThread {
  26. im.setBackgroundColor(Color.GREEN)
  27. }
  28. }
  29. current > 3 * maxLaugh / 7 -> {
  30. runOnUiThread {
  31. im.setBackgroundColor(Color.YELLOW)
  32. }}
  33. current > 2 * maxLaugh / 7 -> {
  34. runOnUiThread {
  35. im.setBackgroundColor(Color.WHITE)
  36. }
  37. }
  38. else -> {
  39. runOnUiThread {
  40. im.setBackgroundResource(R.drawable.asd)
  41. }
  42. }
  43. }
  44. }
  45. count++
  46. if (count == 20) {
  47. count = 0
  48. maxLaugh = 5 * maxLaugh / 6
  49. }
  50. h.postDelayed(this, delay.toLong())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement