Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation("com.ts.sdk:identityverification:1.0.+")
implementation("com.ts.sdk:identityverification:1.1.+")
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.transmitsecurity.idvsdkdemoapp
class Constants {

companion object {
const val CLIENT_ID = "client_id"
const val CLIENT_SECRET = "client_secret"
const val CLIENT_ID = "CLIENT_ID"
const val CLIENT_SECRET = "CLIENT_SECRET"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,131 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.transmit.identityverification.TSIdentityVerification
import com.transmit.identityverification.ITSIdentityVerificationStatus
import com.transmit.identityverification.TSIdentityVerificationError
import com.transmit.identityverification.TSRecaptureReason


import com.transmit.identityverification.*
import com.transmitsecurity.idvsdkdemoapp.fragments.*
import com.transmitsecurity.idvsdkdemoapp.viewmodel.IdvViewModel



class MainActivity : AppCompatActivity(), ITSIdentityVerificationStatus,
class MainActivity : AppCompatActivity(), ITSIdentityVerificationStatus,ITSFaceAuthenticationStatus,
PreparationFragmentActions {
companion object {
private const val BASE_URL = "https://api.transmitsecurity.io/"
private const val START_SDK = 101
private const val START_FACE_AUTH_SDK = 102
}

private var accessToken :String?= null
private lateinit var startToken :String
private var sessionIdVerification :String = ""
private var accessTokenFaceAuthentication :String?= null
private var startTokenFaceAuthentication :String = ""
private var sessionIdFaceAuthentication :String = ""
private var deviceSessionIdFaceAuthentication: String = ""
private var deviceSessionIdFaceAuthenticationResult: String = ""

private val viewModel: IdvViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
savedInstanceState?.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE")
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)



setContentView(R.layout.activity_main)
manageFragments(PreparationFragment())



viewModel.accessToken.observe(this
) { newAccessToken ->
accessToken=newAccessToken
viewModel.createSessionId("https://api.transmitsecurity.io/")
viewModel.createSessionId(BASE_URL)

}

viewModel.startToken.observe(this
) { newStartToken ->
startToken=newStartToken
isCameraPermissionsGranted()
isCameraPermissionsGranted(START_SDK)

}

viewModel.sessionIdVerification.observe(
this
) { newSessionId ->
sessionIdVerification = newSessionId

}

viewModel.accessTokenFaceAuthentication.observe(
this
) { newAccessToken ->
accessTokenFaceAuthentication = newAccessToken
viewModel.createSessionIdForFaceAuth(BASE_URL)

}
viewModel.startTokenFaceAuthentication.observe(
this
) { newStartToken ->
startTokenFaceAuthentication = newStartToken
}
viewModel.sessionIdFaceAuthentication.observe(
this
) { newSessionIdFaceAuth ->
sessionIdFaceAuthentication = newSessionIdFaceAuth
viewModel.createDeviceSessionIdForFaceAuth(
BASE_URL,
"verification-session-reference",sessionIdVerification)
}



viewModel.deviceSessionIdFaceAuthentication.observe(
this
) { newDeviceSessionId ->
deviceSessionIdFaceAuthentication = newDeviceSessionId
isCameraPermissionsGranted(START_FACE_AUTH_SDK)
}

viewModel.sessionIdFaceAuthenticationSessionResult.observe(
this
) { newDeviceSessionId ->
deviceSessionIdFaceAuthenticationResult = newDeviceSessionId
}


}

override fun onStart() {
super.onStart()
TSIdentityVerification.registerForStatus(this)
TSIdentityVerification.registerForFaceAuthStatus(this)

}


private fun isCameraPermissionsGranted() {
private fun isCameraPermissionsGranted(requestCode: Int) {
// Check if the camera permission is granted
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
// Camera permission granted, start Identity Verification here
TSIdentityVerification.start(this, startToken)
} else {
// Request camera permission
ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.CAMERA), 101)
if (ContextCompat.checkSelfPermission(
this,
android.Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED
) {
if (requestCode == START_SDK) {
// Camera permission granted, start Identity Verification here
TSIdentityVerification.start(this, startToken)
} else if (requestCode == START_FACE_AUTH_SDK) {
TSIdentityVerification.startFaceAuth(this, deviceSessionIdFaceAuthentication)
}
}else {
// Request camera permission
ActivityCompat.requestPermissions(
this,
arrayOf(android.Manifest.permission.CAMERA),
requestCode
)
}
}
}


// Handle the result of the permission request
override fun onRequestPermissionsResult(
Expand All @@ -76,15 +144,18 @@ class MainActivity : AppCompatActivity(), ITSIdentityVerificationStatus,
grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 101) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Camera permission granted, start Identity Verification here
TSIdentityVerification.start(this, startToken)
} else {
}
else if (requestCode == 102) {
// Camera permission granted, start Face Authentication here
TSIdentityVerification.startFaceAuth(this,deviceSessionIdFaceAuthentication)
}else {
// Camera permission denied, handle unauthorized state
Log.d("Camera permissions","Camera permissions denied")
}
}
}


override fun verificationStartCapturing() {
Log.d("verificationDidReceiveStatus", "verificationCapturing")
Expand Down Expand Up @@ -138,17 +209,62 @@ class MainActivity : AppCompatActivity(), ITSIdentityVerificationStatus,
}



override fun start() {
viewModel.getAccessToken("https://api.transmitsecurity.io","client_credentials",Constants.CLIENT_ID, Constants.CLIENT_SECRET)
viewModel.getAccessToken(BASE_URL,"client_credentials",Constants.CLIENT_ID, Constants.CLIENT_SECRET)

}


override fun startFaceAuth() {
viewModel.getAccessTokenForFaceAuth(
BASE_URL,
"client_credentials",
Constants.CLIENT_ID, Constants.CLIENT_SECRET)
}


private fun manageFragments(fragment: Fragment){
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
val fragment = fragment
fragmentTransaction.replace(R.id.fragmentContainer, fragment)
fragmentTransaction.commit()
fragmentTransaction.commitAllowingStateLoss()
}

override fun faceAuthenticationStartCapturing() {
Log.d("faceAuthDidReceiveStatus", "faceAuthCapturing")

}
}

override fun faceAuthenticationStartProcessing() {
Log.d("faceAuthDidReceiveStatus", "faceAuthProcessing")
manageFragments(FaceAuthProcessingFragment())

}

override fun faceAuthenticationCompleted() {
Log.d("faceAuthDidReceiveStatus", "faceAuthProcessingCompleted")
manageFragments(CompleteFaceAuthFragment())
}

override fun faceAuthenticationCanceled() {
Log.d("faceAuthDidReceiveStatus", "faceAuthCanceled")
Toast.makeText(this,"Previous face authentication was canceled", LENGTH_SHORT).show()

}

override fun faceAuthenticationFail(error: TSIdentityVerificationError) {
Log.d("faceAuthDidFail", error.name)
when(error.name){
"CameraPermissionRequired" ->manageFragments(RequiredCameraPermissionsFragment())
"SdkDisabled" ->manageFragments(ErrorFragment())
"SessionNotValid" ->manageFragments(ErrorFragment())
"VerificationStatusError" ->manageFragments(ErrorFragment())

}


}
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ open class MyApplication : Application(){
override fun onCreate() {
super.onCreate()
TSIdentityVerification.initialize(this,Constants.CLIENT_ID)


//initialize SDK using parameters from strings.xml
//TSIdentityVerification.initializeSDK(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.transmitsecurity.idvsdkdemoapp.fragments

import android.graphics.Typeface
import com.transmitsecurity.idvsdkdemoapp.R

class CompleteFaceAuthFragment:FirstFragment() {
override val title: String
get() = getString(R.string.face_auth_completion_title)
override val visibleBtn: Boolean
get() = true
override val visibleDrawing: Boolean
get() = true
override val subtitle: String
get() = ""
override val btnTxt: String
get() = getString(R.string.new_btn)
override val titleWeight: Typeface
get() = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
override val subTitleWeight: Typeface
get() = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
override val drawing: Int
get() = R.drawable.proccess_competion
override val visibleProgressBar: Boolean
get() = false

override fun myClickListener() {
val newVerification = PreparationFragment()
val transaction = requireActivity().supportFragmentManager.beginTransaction()
transaction.replace(R.id.fragmentContainer, newVerification)
transaction.addToBackStack(null)
transaction.commit()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.transmitsecurity.idvsdkdemoapp.fragments

import android.graphics.Typeface
import com.transmitsecurity.idvsdkdemoapp.R

class FaceAuthProcessingFragment() : FirstFragment() {
override val title: String
get() = getString(R.string.face_auth_processing_title)
override val visibleBtn: Boolean
get() = false
override val subtitle: String
get() = getString(R.string.processing_sub_title)
override val btnTxt: String
get() =""
override val titleWeight: Typeface
get() = Typeface.create(Typeface.DEFAULT,Typeface.BOLD)
override val subTitleWeight: Typeface
get() = Typeface.create(Typeface.DEFAULT, Typeface.BOLD)
override val visibleDrawing: Boolean
get() = false
override val drawing: Int
get() = R.drawable.proccess_competion
override val visibleProgressBar: Boolean
get() = true

override fun myClickListener() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.transmit.identityverification.ui.InitializedActions.StartFaceAuth
import com.transmitsecurity.idvsdkdemoapp.R
import com.transmitsecurity.idvsdkdemoapp.databinding.PreparationLayoutBinding


interface PreparationFragmentActions{
fun start()
fun startFaceAuth()

}

Expand All @@ -36,15 +38,24 @@ class PreparationFragment:Fragment() {
(requireActivity() as? PreparationFragmentActions)?.start()
}

binding.StartFaceAuthSDK.setOnClickListener {
(requireActivity() as? PreparationFragmentActions)?.startFaceAuth()
}

binding.StartSDK.isEnabled=false
binding.StartFaceAuthSDK.isEnabled=false

binding.checkBox.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
binding.StartSDK.isEnabled = true
binding.StartSDK.alpha= 1.0f
binding.StartFaceAuthSDK.isEnabled = true
binding.StartFaceAuthSDK.alpha= 1.0f
} else {
binding.StartSDK.isEnabled = false
binding.StartSDK.alpha= 0.5f
binding.StartFaceAuthSDK.isEnabled = true
binding.StartFaceAuthSDK.alpha= 1.0f
}
}

Expand Down
Loading