11package com.example.autodoorctrl.autodoorctrlandroid
22
3- import android.Manifest
4- import android.annotation.TargetApi
5- import android.app.KeyguardManager
6- import android.content.Context
7- import android.content.DialogInterface
83import android.content.Intent
9- import android.content.pm.PackageManager
10- import android.hardware.biometrics.BiometricPrompt
11- import android.os.Build
124import android.os.Bundle
135import android.view.View
146import android.view.animation.AlphaAnimation
157import android.widget.ImageView
168import android.widget.Toast
179import androidx.appcompat.app.AppCompatActivity
1810import org.json.JSONException
19- import androidx.core.app.ActivityCompat
20- import androidx.core.hardware.fingerprint.FingerprintManagerCompat
21- import android.os.CancellationSignal
2211import android.widget.Button
2312import java.io.*
24- import com.google.android.material.textfield.TextInputEditText
2513import okhttp3.OkHttpClient
2614import okhttp3.Callback
2715import okhttp3.Response
@@ -32,7 +20,6 @@ import org.json.JSONObject
3220
3321class MainLogin : AppCompatActivity () {
3422 private val opacityClick: AlphaAnimation = AlphaAnimation (0.8f , 0.4f )
35- private val cancellationSignal: CancellationSignal = CancellationSignal ()
3623 private var client = OkHttpClient ()
3724 private var request = OkHttpRequest (client)
3825 private val url = " http://69.55.54.25:80/api/login"
@@ -56,15 +43,15 @@ class MainLogin : AppCompatActivity() {
5643 }
5744
5845 private fun loginUser (map : HashMap <String ,String >) {
59- request.POST (url,map,object : Callback {
46+ request.post (url,map,object : Callback {
6047 override fun onResponse (call : Call , response : Response )
6148 {
6249 try
6350 {
64- var jsonArray = JSONObject (response.body?.string())
51+ val jsonArray = JSONObject (response.body?.string())
6552 println (jsonArray)
6653 if (jsonArray.getString(" SESSIONID" ).compareTo(" " ) != 0 )
67- sendToMap(map.get( " RCSid" ) )
54+ sendToMap(map[ " RCSid" ] )
6855 else {
6956 runOnUiThread{
7057 Toast .makeText(applicationContext, " User does not exist" , Toast .LENGTH_SHORT )
@@ -86,77 +73,23 @@ class MainLogin : AppCompatActivity() {
8673 }
8774 })
8875 }
89- fun hideNavBar () {
76+ private fun hideNavBar () {
9077 this .window.decorView.systemUiVisibility = View .SYSTEM_UI_FLAG_FULLSCREEN or
9178 View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY or
9279 View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
9380 View .SYSTEM_UI_FLAG_LAYOUT_STABLE
9481 }
95- private fun sendCredentials ( RCS : String ,password : String ){
9682
97- }
83+
9884 private fun goToSettings () {
9985 val intent = Intent (this @MainLogin, Settings ::class .java)
10086 startActivity(intent)
10187 }
10288
103- fun notifyUser (message : String ) {
104- Toast .makeText(
105- this ,
106- message,
107- Toast .LENGTH_LONG
108- ).show()
109- }
110- private fun sendToMap (RCSid : String? ) {
111- var Maps = Intent (this , MapsActivity ::class .java)
112- Maps .putExtra(" RCSid" ,RCSid )
113- startActivity(Maps )
114- }
115-
116- @TargetApi(Build .VERSION_CODES .P )
117- fun getAuthenticationCallback (): BiometricPrompt .AuthenticationCallback {
118-
119- return object : BiometricPrompt .AuthenticationCallback () {
120- override fun onAuthenticationError (
121- errorCode : Int ,
122- errString : CharSequence
123- ) {
124- notifyUser(" Authentication error: $errString " )
125- super .onAuthenticationError(errorCode, errString)
126- }
127-
128- override fun onAuthenticationFailed () {
129- super .onAuthenticationFailed()
130- }
131-
132- override fun onAuthenticationSucceeded (
133- result : BiometricPrompt .AuthenticationResult
134- ) {
135- notifyUser(" Authentication Succeeded" )
136- super .onAuthenticationSucceeded(result)
137- val intent = Intent (this @MainLogin , MapsActivity ::class .java)
138- startActivity(intent)
139- }
140- }
141- }
142-
143- private fun getCancellationSignal (): CancellationSignal {
144-
145- cancellationSignal.setOnCancelListener(CancellationSignal .OnCancelListener { notifyUser(" Cancelled via signal" ) })
146- return cancellationSignal
147- }
148- @TargetApi(Build .VERSION_CODES .P )
149- private fun authenticateUser () {
150- val biometricPrompt = BiometricPrompt .Builder (this )
151- .setTitle(" Biometric Login" )
152- .setSubtitle(" Authentication is required to continue" )
153- .setDescription(" Use Fingerprint to login to Automatic Door Control." )
154- .setNegativeButton(" Cancel" , this .mainExecutor,
155- DialogInterface .OnClickListener { dialogInterface, i -> notifyUser(" Authentication cancelled" ) })
156- .build()
157-
158- biometricPrompt.authenticate(getCancellationSignal(), getMainExecutor(),
159- getAuthenticationCallback());
89+ private fun sendToMap (RCSid : String? ) {
90+ val maps = Intent (this , MapsActivity ::class .java)
91+ maps.putExtra(" RCSid" , RCSid )
92+ startActivity(maps)
16093 }
16194}
16295
0 commit comments