Created
July 5, 2021 14:46
-
-
Save ziginsider/3c848d6b49059906116a8b94e0af9b55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 lateinit var binding: ActivityMainBinding | |
private var current = 0L | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
binding.customViewOne.setPeriod(PERIOD) | |
binding.customViewTwo.setPeriod(PERIOD) | |
// Never use GlobalScope for real projects !!! | |
GlobalScope.launch { | |
while (current < PERIOD * REPEAT) { | |
current += INTERVAL | |
binding.customViewOne.setCurrent(current) | |
binding.customViewTwo.setCurrent(current) | |
delay(INTERVAL) | |
} | |
} | |
} | |
private companion object { | |
private const val INTERVAL = 100L | |
private const val PERIOD = 1000L * 30 // 30 sec | |
private const val REPEAT = 10 // 10 times | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment