buildFragmentArguments
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
Formats the GUIDE_VIEW_DRAWABLE_ID
Formats the GUIDE_VIEW_ALIGNED_SCALE_PERCENTAGE
Formats the GUIDE_VIEW_UNALIGNED_SCALE_PERCENTAGE
Formats the GUIDE_VIEW_SHOW_VIGNETTE
Formats the MANUAL_BUTTON_DRAWABLE_ID
Formats the MANUAL_BUTTON_VISIBLE
Formats the TIMEOUT_DURATION
Formats the TORCH_VIEW_ON_DRAWABLE_ID
Formats the TORCH_VIEW_OFF_DRAWABLE_ID
Formats the HINT_DURATION
Formats the HINT_ANIMATION_ID
Formats the HINT_VIEW_SHOW_BACKGROUND
Formats the RECORDING_ICON_DRAWABLE_ID
Formats the RECORDING_ICON_ANIMATION_ID
Formats the HELP_BUTTON_DRAWABLE_ID
Formats the SUCCESS_VIEW_MESSAGE_DRAWABLE_ID
Formats the SUCCESS_VIEW_MESSAGE_ANIMATION_ID
Formats the SUCCESS_VIEW_BACKGROUND_DRAWABLE_ID
Formats the SUCCESS_VIEW_SHOULD_VIBRATE
Formats the SUCCESS_VIEW_SOUND_URI
Formats the MISNAP_VIEW_SHOW_BOUNDING_BOX
Formats the MISNAP_VIEW_SHOW_GLARE_BOX
Formats the REVIEW_CONDITION
Formats the HANDLE_ORIENTATION
Formats the SHOW_DOCUMENT_LABEL
Formats the DOCUMENT_LABEL_STRING_ID
Formats the SHOW_CANCEL_BUTTON
Formats the CANCEL_BUTTON_DRAWABLE_ID
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
}