In the initial version of * Android *, there was no concept of fragment, and it seems that it was difficult to control fat activity and terminal rotation. In this application, the fragment configuration for each screen is replaced from the main activity, and the control is omitted by prohibiting the terminal rotation in the setting of * AndroidManifest.xml *. The possibility that * UX * will be impaired by prohibiting terminal rotation has been addressed by incorporating a process to rotate the image. (I'm addicted to it later ...)
In this application, in order to seamlessly combine two images, select the original image to be combined (** want to ) on the first image, and combine ( want to **) the destination image on the second image. Choose. (The state of two images is managed by * FragmentA * and * FragmentB *) Therefore, after touching the image selection button to take a picture of the gallery or the camera, the image is pasted after the screen transition.
After touching the image selection button to take a picture of the gallery or the camera, the image is not displayed in * ImageView * on the screen transition destination layout and an exception occurs.
In order to display the image in * ImageView * on the screen transition destination layout, the fragment loaded in the transaction queue is executed immediately, so * FragmentManager * fragment transaction processing (* commit () *) immediately after * By calling executePendingTransactions () *, * onCreateView () * will be called and the layout will be generated.
Fragment transaction processing and executePendingTransactions()
// .....Abbreviation
FragmentA.newInstance().let { fragment ->
fragmentManager?.beginTransaction().let { trans ->
val fragments = fragmentManager?.fragments ?: return
for (rFragment in fragments) {
trans?.remove(rFragment)
}
trans?.replace(R.id.topContainer, fragment, FragmentA.TAG)
trans?.commit()
fragmentManager?.executePendingTransactions()
fragment.setImageView(intent) //Call after executing all transaction queues
}
}
// .....Abbreviation
In this application, two image images (combined (** want ) original image and composite ( want **) destination image) are selected, and the image images are seamlessly composited after the screen transition. Since there is a difference in the composition time depending on the image size, adjust the time in the animation image display.
After blocking until the seamless composition of the image image is completed on * launch * (separate thread) of Kotlin * coroutine while displaying the animation image, it is not possible to transition to the seamless composition result screen by fragment transaction processing.
There was an error in the blocking timing for the main (* UI *) thread in the control until the transition to the seamless composition result screen, and the transition to the seamless composition result screen could not be performed by fragment transaction processing.
While displaying the animation image, it will be blocked until the seamless composition of the image image is completed on * launch * (separate thread) of * Kotlin * coroutine, and then the transition to the seamless composition result screen will be performed in * Activity # runOnUiThread *.
Coroutine launch block processing
// .....Abbreviation
GlobalScope.launch { // Kotlin1.3 correspondence
launch { //GlobalScope optional
asyncFunc(argument).join()
}.join()
activity?.runOnUiThread {
//Fragment transaction processing
}
}
// .....Abbreviation
Suspend function
// .....Abbreviation
private fun asyncFunc(argument): Job {
return GlobalScope.launch { // Kotlin1.3 correspondence
seamlesscollage(argument)
}
}
// .....Abbreviation
In this application, touch the [Home] button on the seamless composition result screen to move to the home (top) screen.
After touching the [Home] button on the seamless composition result screen and back stacking, the image selection is not initialized.
Since * addToBackStack () * was called in the fragment transaction processing for the back stack, if you touch the [Home] button (call * popBackStack () *) on the seamless composition result screen, the number of times the fragment transaction was used and the back stack The status such as the screen transition status was not initialized because the number of entries in is not the same.
onViewCreated()When[home]Button processing
// .....Abbreviation
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// .....Abbreviation
homeButton.setOnClickListener {
backHome()
}
}
private fun backHome() {
// .....Abbreviation
replaceTopFragment()
}
// .....Abbreviation
Fragment transaction processing (replace)())
// .....Abbreviation
private fun replaceTopFragment() {
TopFragment.newInstance().let { fragment ->
fragment.arguments?.putInt(TopFragment.FLG_VIEW, 0)
fragmentManager?.beginTransaction().let { trans ->
trans?.replace(R.id.topContainer, fragment, TopFragment.TAG)
trans?.commit()
}
}
}
// .....Abbreviation
Technical causes and countermeasures for the first Android app & Kotlin addiction 2. Processing related to Android camera function 3. Processing related to Android images
Recommended Posts