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
| view.doOnResume { | |
| startWelcomeAnimation(view) | |
| } | |
| view.doOnPause { | |
| stopWelcomeAnimation(view) | |
| } |
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
| val lifecycle = findViewById(R.id.frameLayout).lifecycle | |
| // Or | |
| val imageView = ImageView(context) | |
| imageView.lifecycleScope.launchWhenCreated { | |
| (imageView.parent as View).isVisible = true | |
| loadSlideShow(imageView.width, imageView.height) | |
| } |
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
| textView.lifecycleScope.launchWhenCreated { | |
| while (isActive) { | |
| view.text = "${System.currentTimeMillis()}" // Dispatchers.Main | |
| withContext(Dispatchers.IO) { // Dispatchers.IO for waiting in background | |
| delay(1000) // Wait 1 second | |
| } | |
| } | |
| } |
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
| texView.lifecycleScope.launchWhenCreated { // Launch on Dispatchers.Main | |
| val data = withContext(Dispatchers.IO) { // Dispatchers.IO for background task | |
| loadNetworkData() // Suspend function making http calls | |
| } | |
| texView.text = data // Dispatchers.Main for UI change | |
| } |
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
| view.lifecycle.addObserver(onResume = { | |
| refreshData() | |
| }) |
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
| dependencies { | |
| implementation "com.gorisse.thomas:android-view-lifecycle:1.0.1" | |
| } |
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
| val View.lifecycle get() = lifecycleOwner.lifecycle | |
| val View.lifecycleScope get() = lifecycleOwner.lifecycleScope |
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
| val View.lifecycleOwner: LifecycleOwner | |
| get() = getTag(R.id.view_lifecycle_owner) as? LifecycleOwner ?: object : LifecycleOwner, | |
| LifecycleEventObserver { | |
| private val lifecycle = LifecycleRegistry(this) | |
| init { | |
| doOnAttach { | |
| findViewTreeLifecycleOwner()?.lifecycle?.addObserver(this) | |
| } | |
| doOnDetach { |
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
| dependencies { | |
| implementation("com.gorisse.thomas.sceneform:sceneform:1.20.1") | |
| } |
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
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| // Load model.glb from assets folder or http url | |
| (supportFragmentManager.findFragmentById(R.id.arFragment) as ArFragment) | |
| .setOnTapPlaneGlbModel("model.glb") | |
| } |