Commit 69eb9e25 authored by Dean's avatar Dean

Add FingerPrintFragment.kt

parent c0001036
...@@ -43,6 +43,7 @@ dependencies { ...@@ -43,6 +43,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+' testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
......
package com.mdd.mddsimulatorcallerapp
import android.app.AlertDialog
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.mdd.mddsimulatorcallerapp.databinding.FragmentFingerPrintBinding
import com.mdd.mddsimulatorcallerapp.databinding.FragmentSecondBinding
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"
/**
* A simple [Fragment] subclass.
* Use the [FingerPrintFragment.newInstance] factory method to
* create an instance of this fragment.
*/
class FingerPrintFragment : Fragment() {
// TODO: Rename and change types of parameters
private var param1: String? = null
private var param2: String? = null
private var _binding: FragmentFingerPrintBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
param1 = it.getString(ARG_PARAM1)
param2 = it.getString(ARG_PARAM2)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
MyBroadcastReceiver.typeReceiver = "ISIINAJA"
_binding = FragmentFingerPrintBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.enrollBtn.setOnClickListener {
context?.let{act->
// WAJIB -> compileSdkVersion 29, minSdkVersion 22, targetSdkVersion 29
val br: MyBroadcastReceiver = MyBroadcastReceiver()
MyBroadcastReceiver.typeReceiver = "ISIINAJA"
val receiverPath = "com.mdd.mddsimulatorcallerapp.ON_RESULT"
val filter = IntentFilter(receiverPath)
act.registerReceiver(br, filter)
val intent = Intent(Intent.ACTION_SEND)
intent.`package` = "co.id.mdd.fingerprintscanner"
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.let { intent->
intent.putExtra("BroadcastReceiver", receiverPath)
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
showErrorMessage(e)
}
}
}
}
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun showErrorMessage(e: Exception) {
AlertDialog.Builder(context)
.setMessage(e.message)
.show()
}
companion object {
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment FingerPrintFragment.
*/
// TODO: Rename and change types and number of parameters
@JvmStatic
fun newInstance(param1: String, param2: String) =
FingerPrintFragment().apply {
arguments = Bundle().apply {
putString(ARG_PARAM1, param1)
putString(ARG_PARAM2, param2)
}
}
}
}
\ No newline at end of file
...@@ -64,6 +64,10 @@ class MainActivity : AppCompatActivity() { ...@@ -64,6 +64,10 @@ class MainActivity : AppCompatActivity() {
findNavController(R.id.nav_host_fragment_content_main).navigate(R.id.action_FirstFragment_to_SecondFragment) findNavController(R.id.nav_host_fragment_content_main).navigate(R.id.action_FirstFragment_to_SecondFragment)
true true
} }
R.id.action_To_FingerPrint -> {
findNavController(R.id.nav_host_fragment_content_main).navigate(R.id.action_To_FingerPrint)
true
}
else -> super.onOptionsItemSelected(item) else -> super.onOptionsItemSelected(item)
} }
} }
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FingerPrintFragment">
<Button
android:id="@+id/enrollBtn"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:text="Enroll FingerPrint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
\ No newline at end of file
...@@ -17,4 +17,9 @@ ...@@ -17,4 +17,9 @@
android:orderInCategory="100" android:orderInCategory="100"
android:title="ALPR CAMERA" android:title="ALPR CAMERA"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/action_To_FingerPrint"
android:orderInCategory="100"
android:title="Finger Print Scanner"
app:showAsAction="never" />
</menu> </menu>
\ No newline at end of file
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
app:popUpTo="@+id/FirstFragment" app:popUpTo="@+id/FirstFragment"
app:popUpToInclusive="true" app:popUpToInclusive="true"
/> />
<action
android:id="@+id/action_To_FingerPrint"
app:destination="@id/FingerPrintFragment"
app:popUpTo="@+id/FingerPrintFragment"
app:popUpToInclusive="true"
/>
<fragment <fragment
android:id="@+id/FirstFragment" android:id="@+id/FirstFragment"
android:name="com.mdd.mddsimulatorcallerapp.FirstFragment" android:name="com.mdd.mddsimulatorcallerapp.FirstFragment"
...@@ -28,4 +34,11 @@ ...@@ -28,4 +34,11 @@
android:label="ALPR CAMERA" android:label="ALPR CAMERA"
tools:layout="@layout/fragment_second"> tools:layout="@layout/fragment_second">
</fragment> </fragment>
<fragment
android:id="@+id/FingerPrintFragment"
android:name="com.mdd.mddsimulatorcallerapp.FingerPrintFragment"
android:label="FingerPrint"
tools:layout="@layout/fragment_finger_print">
</fragment>
</navigation> </navigation>
\ No newline at end of file
...@@ -9,4 +9,6 @@ ...@@ -9,4 +9,6 @@
<string name="hello_first_fragment">Hello first fragment</string> <string name="hello_first_fragment">Hello first fragment</string>
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string> <string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment