diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 586bf68..91b8ecd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -49,6 +49,7 @@ dependencies { implementation(libs.androidx.lifecycle.viewmodel.ktx) implementation(libs.androidx.navigation.fragment.ktx) implementation(libs.androidx.navigation.ui.ktx) + implementation(libs.play.services.code.scanner) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/app/src/main/java/com/lhw/pdf/ui/NetworkFragment.kt b/app/src/main/java/com/lhw/pdf/ui/NetworkFragment.kt new file mode 100644 index 0000000..22183a7 --- /dev/null +++ b/app/src/main/java/com/lhw/pdf/ui/NetworkFragment.kt @@ -0,0 +1,42 @@ +package com.lhw.pdf.ui + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.mlkit.vision.barcode.common.Barcode +import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions +import com.google.mlkit.vision.codescanner.GmsBarcodeScanning +import com.lhw.pdf.R +import com.lhw.pdf.databinding.FragmentNetworkBinding +import com.lhw.pdf.databinding.FragmentSlideshowBinding + +class NetworkFragment : Fragment() { + private var _binding: FragmentNetworkBinding? = null + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + _binding = FragmentNetworkBinding.inflate(inflater, container, false) + val root: View = binding.root + + binding.btnScanQrCode.setOnClickListener { getQrCode() } + return root + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + + private fun getQrCode() { + val options = GmsBarcodeScannerOptions.Builder().setBarcodeFormats(Barcode.FORMAT_QR_CODE, Barcode.FORMAT_AZTEC).enableAutoZoom().build() + val scanner = GmsBarcodeScanning.getClient(requireContext(), options) + scanner.startScan() + .addOnSuccessListener { println("QR scan success: ${it.rawValue}") } + .addOnCanceledListener { println("QR scan canceled") } + .addOnFailureListener { println("QR scan failure: $it") } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt b/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt index 1128741..2c44217 100644 --- a/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt +++ b/app/src/main/java/com/lhw/pdf/ui/gallery/GalleryViewModel.kt @@ -1,7 +1,6 @@ package com.lhw.pdf.ui.gallery import android.graphics.Bitmap -import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel diff --git a/app/src/main/res/layout/fragment_network.xml b/app/src/main/res/layout/fragment_network.xml new file mode 100644 index 0000000..a7931fd --- /dev/null +++ b/app/src/main/res/layout/fragment_network.xml @@ -0,0 +1,21 @@ + + + + + + +