buildFragmentArguments
fun buildFragmentArguments(@DrawableRes scanInstructionsSearchingDrawableId: Int? = null, @DrawableRes scanInstructionsReadingDrawableId: Int? = null, @DrawableRes scanInstructionsSuccessDrawableId: Int? = null, @DrawableRes scanInstructionsFailureDrawableId: Int? = null, @StringRes scanInstructionsTextId: Int? = null, shouldShowFailoverPopup: Boolean? = null, skipVisibilityTimeout: Int? = null, handleOrientation: Boolean? = null): Bundle
Formats an arguments object for this fragment to use with Fragment.setArguments.
Return
Bundle with the relevant arguments set, pass it into Fragment.setArguments to apply the settings.
Parameters
scanInstructionsSearchingDrawableId
Formats the SCAN_INSTRUCTIONS_SEARCHING_DRAWABLE_ID.
scanInstructionsReadingDrawableId
Formats the SCAN_INSTRUCTIONS_READING_DRAWABLE_ID.
scanInstructionsSuccessDrawableId
Formats the SCAN_INSTRUCTIONS_SUCCESS_DRAWABLE_ID.
scanInstructionsFailureDrawableId
Formats the SCAN_INSTRUCTIONS_FAILURE_DRAWABLE_ID.
scanInstructionsTextId
Formats the SCAN_INSTRUCTIONS_TEXT_ID.
shouldShowFailoverPopup
Formats the SHOULD_SHOW_FAILOVER_POPUP.
skipVisibilityTimeout
Formats the SKIP_VISIBILITY_TIMEOUT.
handleOrientation
Formats the HANDLE_ORIENTATION.
Samples
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.ViewModelProvider
import com.miteksystems.misnap.apputil.LicenseFetcher
import com.miteksystems.misnap.core.MiSnapSettings
import com.miteksystems.misnap.databinding.ExampleFragmentTransactionBinding
import com.miteksystems.misnap.workflow.fragment.DocumentAnalysisFragment
import com.miteksystems.misnap.workflow.fragment.DocumentAnalysisFragment.ReviewCondition
import com.miteksystems.misnap.workflow.fragment.HelpFragment
import com.miteksystems.misnap.workflow.fragment.MiSnapWorkflowViewModel
import com.miteksystems.misnap.workflow.fragment.NavigationError
fun main() {
//sampleStart
/**
* This example demonstrates the customization of the MiSnap SDK UI and behavior through the use
* of a [Bundle] containing the fragment arguments. This type of customization is best suited for
* developers that will use the built-in fragments directly.
*
* Please refer to the "buildFragmentArguments" method of the fragment you want to customize for the
* full list of customization options.
*
* NOTE: Ensure that the provided license has all the necessary features enabled for the target
* MiSnap session.
*
* @see com.miteksystems.misnap.examples.settings.WorkflowSettings for an example on how to customize
* the UI and behavior using [MiSnapSettings] instead.
*/
class FragmentArguments : AppCompatActivity() {
/**
* Fetch the Misnap SDK license.
* Good practice: Handle the license in a way that it is remotely updatable.
*/
private val license by lazy {
LicenseFetcher.fetch()
}
private lateinit var binding: ExampleFragmentTransactionBinding
private val viewModel by lazy {
ViewModelProvider(this)[MiSnapWorkflowViewModel::class.java]
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ExampleFragmentTransactionBinding.inflate(layoutInflater)
setContentView(binding.root)
}
override fun onStart() {
super.onStart()
/**
* Use the method "buildFragmentArguments" from the workflow fragment you want to customize
* to create a [Bundle] that can be used in a standard [FragmentTransaction].
*/
val helpFragmentArguments =
HelpFragment.buildFragmentArguments(showSkipCheckBox = false)
val documentAnalysisFragmentArguments =
DocumentAnalysisFragment.buildFragmentArguments(
timeoutDuration = 15_000,
manualButtonDrawableId = android.R.drawable.ic_menu_camera,
guideViewShowVignette = true,
successViewShouldVibrate = true,
reviewCondition = ReviewCondition.ALWAYS
)
viewModel.applySettings(MiSnapSettings(MiSnapSettings.UseCase.ID_FRONT, license))
/**
* Handle the incoming [NavigationError]s to determine the next destination and drive the navigation
* using [FragmentTransaction]s. Apply the customized [Bundle] to the fragment before executing
* the transaction.
*/
viewModel.navigationErrors.observe(this) { navError ->
navError?.navigationErrorInfo?.let { errorInfo ->
when (errorInfo.fragmentClass) {
HelpFragment::class.java -> {
val analysisFragment = DocumentAnalysisFragment().apply {
arguments = documentAnalysisFragmentArguments
}
executeFragmentTransaction(analysisFragment)
}
}
}
}
/**
* Create the fragment, apply the arguments bundle and start a transaction to the first
* destination of the workflow, in this case the [HelpFragment].
*/
val helpFragment = HelpFragment().apply {
arguments = helpFragmentArguments
}
executeFragmentTransaction(helpFragment)
}
/**
* Create and execute [FragmentTransaction]s to drive the navigation manually.
*/
private fun executeFragmentTransaction(fragment: Fragment) {
supportFragmentManager
.beginTransaction()
.apply {
replace(binding.fragmentContainer.id, fragment)
}
.commit()
}
}
//sampleEnd
}