diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml index b248a5f47493bcc06e6683bc3da32514c966b9c0..0c0c3383890637b4721df1f49d0b229e55c0f361 100644 --- a/.idea/deploymentTargetDropDown.xml +++ b/.idea/deploymentTargetDropDown.xml @@ -3,20 +3,7 @@ <component name="deploymentTargetDropDown"> <value> <entry key="app"> - <State> - <runningDeviceTargetSelectedWithDropDown> - <Target> - <type value="RUNNING_DEVICE_TARGET" /> - <deviceKey> - <Key> - <type value="VIRTUAL_DEVICE_PATH" /> - <value value="C:\Users\Shidq\.android\avd\Medium_Phone_API_33.avd" /> - </Key> - </deviceKey> - </Target> - </runningDeviceTargetSelectedWithDropDown> - <timeTargetWasSelectedWithDropDown value="2024-03-30T06:44:39.973184600Z" /> - </State> + <State /> </entry> </value> </component> diff --git a/.idea/misc.xml b/.idea/misc.xml index 8978d23db569daa721cb26dde7923f4c673d1fc9..f1044879e31aa73a3e757a2f81a68e7c26bd222a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ExternalStorageConfigurationManager" enabled="true" /> - <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/build/classes" /> </component> <component name="ProjectType"> diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 04056f64ca88cadbf3a5f930e66e19ab323d9bf5..7e447f7285ac75ffb47735eb62bed5feb7f63d8d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -62,6 +62,9 @@ dependencies { implementation("org.apache.poi:poi:5.2.2") implementation("org.apache.poi:poi-ooxml:5.2.2") + //QR COde + implementation ("com.github.yuriy-budiyev:code-scanner:2.3.0") + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 75284d44246151ac6010e659b77048b11d32f2e6..c26a7a5bd9cf623643f135c7910e14511b0cf123 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,11 @@ <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> + <uses-permission android:name="android.permission.CAMERA"/> + + <uses-feature + android:name="android.hardware.camera" + android:required="false"/> <application diff --git a/app/src/main/java/com/atm/bondowowo/ui/scan/ScanFragment.kt b/app/src/main/java/com/atm/bondowowo/ui/scan/ScanFragment.kt index 6dab1a1b91d5d7d714d164a033826cdff2b3a136..13d2dbb861c9d51b5a496376f8c0f56cb6277be3 100644 --- a/app/src/main/java/com/atm/bondowowo/ui/scan/ScanFragment.kt +++ b/app/src/main/java/com/atm/bondowowo/ui/scan/ScanFragment.kt @@ -1,6 +1,61 @@ package com.atm.bondowowo.ui.scan +import android.Manifest +import android.content.pm.PackageManager +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment +import com.atm.bondowowo.R +import com.budiyev.android.codescanner.CodeScanner +import com.budiyev.android.codescanner.CodeScannerView +import com.budiyev.android.codescanner.DecodeCallback +class ScanFragment : Fragment() { + private val CAMERA_PERMISSION_REQUEST_CODE = 100 + private lateinit var codeScanner: CodeScanner -class ScanFragment : Fragment() + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_scan, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val scannerView = view.findViewById<CodeScannerView>(R.id.scanner) + + // Check camera permission + if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(requireActivity(), arrayOf(Manifest.permission.CAMERA), CAMERA_PERMISSION_REQUEST_CODE) + } else { + initializeCodeScanner(scannerView) + } + } + + private fun initializeCodeScanner(scannerView: CodeScannerView) { + codeScanner = CodeScanner(requireActivity(), scannerView) + codeScanner.decodeCallback = DecodeCallback { + requireActivity().runOnUiThread { + Toast.makeText(requireContext(), "Scanned: ${it.text}", Toast.LENGTH_LONG).show() + } + } + scannerView.setOnClickListener { + codeScanner.startPreview() + } + } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) { + if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + val scannerView = requireView().findViewById<CodeScannerView>(R.id.scanner) + initializeCodeScanner(scannerView) + } else { + Toast.makeText(requireContext(), "Camera permission denied", Toast.LENGTH_SHORT).show() + } + } + } +} diff --git a/app/src/main/res/layout/fragment_scan.xml b/app/src/main/res/layout/fragment_scan.xml index 94e66ceffcca01ce964fcb6cbee53c0819c792cc..36b25531628c364f13e92516cd573573bdeaba13 100644 --- a/app/src/main/res/layout/fragment_scan.xml +++ b/app/src/main/res/layout/fragment_scan.xml @@ -24,28 +24,34 @@ android:textStyle="bold" /> </com.google.android.material.appbar.AppBarLayout> - <TextureView - android:id="@+id/camera_preview" - android:layout_width="300dp" - android:layout_height="400dp" - android:background="@color/black" - app:layout_constraintBottom_toTopOf="@id/capture_button" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.495" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/header" - app:layout_constraintVertical_bias="0.508" /> - - <Button - android:id="@+id/capture_button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginBottom="124dp" - android:text="@string/capture" - app:cornerRadius="999dp" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.498" - app:layout_constraintStart_toStartOf="parent" /> + <LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_marginTop="40dp" + android:layout_height="match_parent" + android:orientation="vertical" + tools:contex="com.atm.bondowowo.ui.scan.ScanFragment"> + + <com.budiyev.android.codescanner.CodeScannerView + android:id="@+id/scanner" + android:layout_width="match_parent" + android:layout_height="600dp" + app:autoFocusButtonVisible="true"/> + + <TextView + android:id="@+id/tv_output" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="20dp" + android:text="The result is here" + android:textAlignment="center" + android:textSize="20sp" + android:textColor="#A92B"/> + + </LinearLayout> + + </androidx.constraintlayout.widget.ConstraintLayout> diff --git a/settings.gradle.kts b/settings.gradle.kts index a166835a10904b5765bb52544763026579db581d..3fd94ef69f37af6fea3947a69af56df295f834c8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,6 +10,9 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { + url = uri("https://jitpack.io") + } } }