package com.mobilinkbank
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.embedding.android.FlutterFragmentActivity
import android.content.Intent
import android.graphics.Color
import androidx.annotation.NonNull
import com.google.gson.Gson
import com.unikrew.faceoff.fingerprint.Customization.CustomDialog
import com.unikrew.faceoff.fingerprint.Customization.CustomUI
import com.unikrew.faceoff.fingerprint.FingerprintConfig
import com.unikrew.faceoff.fingerprint.FingerprintScannerActivity
import com.unikrew.faceoff.fingerprint.ResultIPC


class MainActivity: FlutterFragmentActivity() {

    private val CHANNELFaceOff = "com.unikrew.faceooff/initiate"
    private var methodChannelResult: MethodChannel.Result? = null
    private val LIVENESS_CHECK_REQUEST = 2

    private val CHANNEL = "dost.app.Sdk.BVS"
    private val BIOMETRIC_CHECK_REQUEST = 111

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {

        GeneratedPluginRegistrant.registerWith(flutterEngine);
              MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
                  methodChannelResult = result
    if (call.method.equals("launchSDK")) {
                launchScanning()
            }
             if (call.method.equals("launchSDK")) {
                launchScanning()
            }
    }
}

private fun launchScanning() {

        if(CHANNELFaceOff == "com.unikrew.faceooff/initiate") {
            val config: LivenessConfig = LivenessConfig.Builder()
            .setChallengeMoveYourFaceToLeft()
            .setChallengeMoveYourFaceToRight()
            .setChallengeNodYourHead()
            .setFaceComparisonRequired(false)
            .setOcrRequired(false) //
            .setMaxChallenges(1) //This defines the max number of challenges to show randomly from the defined challenges.
            .setPassiveLiveness(true)
            .build()

        val intent = Intent(this@MainActivity, FaceoffLivenessInitializationActivity::class.java)
        intent.putExtra(FaceoffLivenessInitializationActivity.FACEOFF_LIVENESS_CONFIG, config)

        startActivityForResult(intent, LIVENESS_CHECK_REQUEST)

        } else {
            val customUI = CustomUI()
            .setAppBarTextColor(resources.getColor(R.color.colorWhite))
            .setAppBarColor(resources.getColor(R.color.colorPrimary))
            .setIconsColor(resources.getColor(R.color.colorWhite))
            .setGuidanceScreenBackgroundColor(resources.getColor(R.color.colorWhite))
            .setGuidanceScreenButtonColor(resources.getColor(R.color.colorPrimary))
            .setGuidanceScreenButtonTextColor(resources.getColor(R.color.colorWhite))
            .setGuidanceScreenFullWidthButton(true)
            .setGuidanceScreenButtonText("Continue")
            .setGuidanceScreenInstructionTextColor(Color.BLACK)
            .setAppBarBackgroundImage(0)
            .setGuidanceScreenInstructionText("Align your hand as demonstrated below\nKeep your fingers together\nThen stay still.")
            .setGuidanceScreenInstructionImage(0)
            .setGuidanceScreenAppBarTitle("Guidance")
            .setSplashScreenLoaderColor(resources.getColor(R.color.colorWhite))
            .setSplashScreenMessageColor(resources.getColor(R.color.colorWhite))
            .setSplashScreenMessage("")
            .setShowGuidanceScreen(true)

        val customDialog = CustomDialog()
            .setDialogBackgroundColor(Color.WHITE)
            .setDialogTitleColor(resources.getColor(R.color.colorPrimary))
            .setDialogMessageColor(Color.GRAY)
            .setDialogImageBackgroundColor(resources.getColor(R.color.colorPrimary))
            .setDialogImageForegroundColor(resources.getColor(R.color.colorPrimary))
            .setDialogButtonBackgroundColor(resources.getColor(R.color.colorPrimary))
            .setDialogButtonTextColor(resources.getColor(R.color.colorWhite))
            .setDialogSuccessImage(0)
            .setDialogSwitchHandImage(0)
            .setDialogErrorImage(0)
            .setSuccessDialogTitle("Almost done")
            .setSuccessDialogMessage("Proceed to verify")
            .setSuccessDialogButtonText("Next")
            .setSwitchHandDialogTitle("Thank You")
            .setSwitchHandDialogMessage("Your Right Hand Please")
            .setSwitchHandDialogButtonText("Proceed")
            .setErrorDialogTitle("Please try again")

        val config: FingerprintConfig = FingerprintConfig.Builder()
            .setFingers(FingerprintConfig.Fingers.EIGHT_FINGERS)
            .setMode(FingerprintConfig.Mode.EXPORT_WSQ)
            .setPackPng(false)
            .setLiveness(true)
            .setCustomUI(customUI)
            .setCustomDialog(customDialog)
            .build()

             val intent = Intent(this@MainActivity, FingerprintScannerActivity::class.java)
        intent.putExtra(FingerprintScannerActivity.FACEOFF_FINGERPRINT_CONFIG, config)
        startActivityForResult(intent, BIOMETRIC_CHECK_REQUEST)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(data != null){
            if(CHANNELFaceOff == "com.unikrew.faceooff/initiate"){
al responseCode =
            data!!.getIntExtra(FaceoffLivenessInitializationActivity.LIVENESS_RESPONSE_CODE, -1)
        if (responseCode > 0) {
            val livenessResponse = LivenessResponseIPC.getInstance().getLivenessResponse(responseCode)
            val  json = Gson().toJson(livenessResponse)
            val  jsonString = json.toString ()
            methodChannelResult?.success(jsonString)
        }
            }else{
val responseCode =
                data!!.getIntExtra(FingerprintScannerActivity.FINGERPRINT_RESPONSE_CODE, -1)
            if (responseCode > 0) {
                val fingerprintResponse = ResultIPC.getInstance().getFingerprintResponse(responseCode)
                val  json = Gson().toJson(fingerprintResponse)
                val  jsonString = json.toString ()
                methodChannelResult?.success(jsonString)
            }
            }
            
        }
    }
}
 

Kotlin online compiler

Write, Run & Share Kotlin code online using OneCompiler’s Kotlin online compiler for free. It’s a modern and fast online playground for Kotlin, supporting the latest version and ideal for learning, experimenting, and sharing code instantly.

About Kotlin

Kotlin is a statically typed, modern programming language developed by JetBrains. It runs on the JVM and is fully interoperable with Java. Kotlin is concise, expressive, and safe, and it’s officially supported by Google for Android app development.

Sample Code

The following is a simple Kotlin program that prints a greeting:

fun main() {
    println("Hello, OneCompiler!")
}

Taking inputs (stdin)

OneCompiler’s Kotlin editor supports stdin. You can provide input using the I/O tab. Here's a sample program that reads a line of input and prints a greeting:

fun main() {
    print("Enter your name: ")
    val name = readLine()
    println("Hello, $name")
}

Syntax Basics

Variables

val name: String = "OneCompiler"  // Immutable
var age: Int = 25                 // Mutable

Kotlin supports type inference, so explicit types are optional:

val city = "Hyderabad"
var count = 10

Conditionals

val score = 85
if (score >= 50) {
    println("Pass")
} else {
    println("Fail")
}

Loops

For loop

for (i in 1..5) {
    println(i)
}

While loop

var i = 1
while (i <= 5) {
    println(i)
    i++
}

Do-While loop

var j = 1
do {
    println(j)
    j++
} while (j <= 5)

Functions

fun add(a: Int, b: Int): Int {
    return a + b
}

fun greet(name: String) = "Hello, $name"

Collections

val items = listOf("apple", "banana", "cherry")
for (item in items) {
    println(item)
}

This guide provides a quick reference to Kotlin programming syntax and features. Start coding in Kotlin using OneCompiler’s Kotlin online compiler today!