kit scan qr code scanning is added, some issues are still resolving only
This commit is contained in:
@@ -129,7 +129,7 @@ dependencies {
|
||||
|
||||
// Barcode scanner
|
||||
implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
|
||||
|
||||
implementation 'com.github.yuriy-budiyev:code-scanner:2.3.0'
|
||||
// Google ML Kit using play services
|
||||
implementation 'com.google.android.gms:play-services-code-scanner:16.1.0'
|
||||
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.BATTERY_STATS"
|
||||
tools:ignore="ProtectedPermissions" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.camera"
|
||||
android:required="false" />
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
@@ -25,16 +26,19 @@
|
||||
|
||||
<application
|
||||
android:name="com.example.hpostesting.HPOSTestingApplication"
|
||||
android:largeHeap="true"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/hpos_icon"
|
||||
android:label="@string/app_name"
|
||||
android:largeHeap="true"
|
||||
android:roundIcon="@mipmap/hpos_icon_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.HPOSTesting"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.ScannerKitActvity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.deviceinfo.DeviceActivity"
|
||||
android:exported="false" />
|
||||
@@ -60,23 +64,20 @@
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.calibration.CalibrationActivity"
|
||||
android:exported="false"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"/>
|
||||
|
||||
android:theme="@style/Theme.HPOS.NoActionBar" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.assurance.AssuranceControlsActivity"
|
||||
android:exported="false"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"/>
|
||||
|
||||
android:theme="@style/Theme.HPOS.NoActionBar" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.hemocube.HemocubeActivity"
|
||||
android:exported="false"
|
||||
android:noHistory="true"
|
||||
android:screenOrientation="portrait"
|
||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.trueheme.TrueHemeActivity"
|
||||
android:exported="false"
|
||||
@@ -84,7 +85,6 @@
|
||||
android:parentActivityName="com.example.hpostesting.presentation.MainActivity"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.buffercheck.HemocubeBufferCheckActivity"
|
||||
android:exported="false"
|
||||
@@ -94,27 +94,29 @@
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.KitScanActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||
android:exported="false"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar" />
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
android:windowSoftInputMode="stateHidden" />
|
||||
<activity
|
||||
android:name="com.example.hpostesting.presentation.dashboard.DashboardActivity"
|
||||
android:exported="false"
|
||||
android:label="@string/title_activity_dashboard"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/Theme.HPOS.NoActionBar"
|
||||
tools:ignore="AppLinkUrlError,MissingClass">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:scheme="content" />
|
||||
<data android:scheme="file" />
|
||||
<data android:mimeType="application/vnd.android.package-archive" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
||||
<service
|
||||
android:name="com.example.hpostesting.util.UsbService"
|
||||
android:enabled="true"
|
||||
@@ -126,8 +128,9 @@
|
||||
android:noHistory="true"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
@@ -164,8 +167,7 @@
|
||||
android:name="com.journeyapps.barcodescanner.CaptureActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:stateNotNeeded="true"
|
||||
tools:replace="android:screenOrientation" />
|
||||
<!-- ${applicationId}-->
|
||||
tools:replace="android:screenOrientation" /> <!-- ${applicationId} -->
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
@@ -175,7 +177,6 @@
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.hpostesting.presentation
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
@@ -9,6 +10,7 @@ import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.hpostesting.data.constant.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
@@ -42,23 +44,36 @@ class KitScanActivity : AppCompatActivity() {
|
||||
var sdkHandler: SDKHandler? = null
|
||||
var editBarcode: EditText? = null
|
||||
var mScannerInfoList = ArrayList<DCSScannerInfo>()
|
||||
companion object {
|
||||
const val QR_REQUEST_CODE = 1
|
||||
}
|
||||
// private val barcodeLauncher = registerForActivityResult(
|
||||
// ScanContract()
|
||||
// ) { result: ScanIntentResult ->
|
||||
// Log.d(TAG, result.contents)
|
||||
// if (result.contents.isNullOrEmpty()) {
|
||||
// Toast.makeText(this, R.string.cancelled_unable_scan, Toast.LENGTH_LONG).show()
|
||||
// } else {
|
||||
// Log.d(TAG, result.contents)
|
||||
// processScannedData(result.contents)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private fun processScannedData(contents: String) {
|
||||
// binding.nameEditText.setText(contents)
|
||||
// }
|
||||
|
||||
private val barcodeLauncher = registerForActivityResult(
|
||||
ScanContract()
|
||||
) { result: ScanIntentResult ->
|
||||
Log.d(TAG, result.contents)
|
||||
if (result.contents.isNullOrEmpty()) {
|
||||
Toast.makeText(this, R.string.cancelled_unable_scan, Toast.LENGTH_LONG).show()
|
||||
} else {
|
||||
Log.d(TAG, result.contents)
|
||||
processScannedData(result.contents)
|
||||
// In your calling activity
|
||||
var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) { // Handle the result
|
||||
val qrCode = result.data?.getStringExtra("QRCode")
|
||||
Toast.makeText(this, "scanned kit text:$qrCode",
|
||||
Toast.LENGTH_LONG).show()
|
||||
// val editText = findViewById<com.google.android.material.textfield.TextInputEditText>(R.id.name_edit_text)
|
||||
binding.nameEditText.setText(qrCode)
|
||||
// Use data to retrieve extra
|
||||
}
|
||||
}
|
||||
|
||||
private fun processScannedData(contents: String) {
|
||||
binding.nameEditText.setText(contents)
|
||||
}
|
||||
|
||||
override fun attachBaseContext(newBase: Context?) {
|
||||
val languageCode = LanguageManager.getSavedLanguage(newBase!!)
|
||||
LanguageManager.setLocale(newBase, languageCode)
|
||||
@@ -152,8 +167,9 @@ class KitScanActivity : AppCompatActivity() {
|
||||
setSupportActionBar(binding.toolbar)
|
||||
|
||||
binding.btnScanNow.setOnClickListener {
|
||||
startScanningNow()
|
||||
// pullTrigger()
|
||||
// startForResult.launch(Intent(this, ScannerKitActvity::class.java))
|
||||
val intent = Intent(this, ScannerKitActvity::class.java)
|
||||
resultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
binding.btnGo.setOnClickListener {
|
||||
@@ -304,21 +320,21 @@ class KitScanActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun startScanningNow() {
|
||||
val options = ScanOptions()
|
||||
options.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
||||
options.setPrompt("Scan a barcode")
|
||||
options.setCameraId(0) // Use a specific camera of the device
|
||||
|
||||
options.setBeepEnabled(true)
|
||||
options.setBarcodeImageEnabled(true)
|
||||
|
||||
options.setPrompt("Start Scanning")
|
||||
options.setOrientationLocked(false)
|
||||
// options.setTimeout(10000) // in ms
|
||||
|
||||
barcodeLauncher.launch(options)
|
||||
}
|
||||
// private fun startScanningNow() {
|
||||
// val options = ScanOptions()
|
||||
// options.setDesiredBarcodeFormats(ScanOptions.QR_CODE)
|
||||
// options.setPrompt("Scan a barcode")
|
||||
// options.setCameraId(0) // Use a specific camera of the device
|
||||
//
|
||||
// options.setBeepEnabled(true)
|
||||
// options.setBarcodeImageEnabled(true)
|
||||
//
|
||||
// options.setPrompt("Start Scanning")
|
||||
// options.setOrientationLocked(false)
|
||||
//// options.setTimeout(10000) // in ms
|
||||
//
|
||||
// barcodeLauncher.launch(options)
|
||||
// }
|
||||
|
||||
private fun checkDataNotNull(): Boolean {
|
||||
return if (DataHolder.selectedTest?._id == null) {
|
||||
@@ -334,4 +350,13 @@ class KitScanActivity : AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
// super.onActivityResult(requestCode, resultCode, data)
|
||||
// if (requestCode == QR_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||
// val qrCode = data?.getStringExtra("QRCode")
|
||||
//// val editText = findViewById<com.google.android.material.textfield.TextInputEditText>(R.id.name_edit_text)
|
||||
// binding.nameEditText.setText(qrCode)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.example.hpostesting.presentation
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import com.budiyev.android.codescanner.AutoFocusMode
|
||||
import com.budiyev.android.codescanner.CodeScanner
|
||||
import com.budiyev.android.codescanner.CodeScannerView
|
||||
import com.budiyev.android.codescanner.DecodeCallback
|
||||
import com.budiyev.android.codescanner.ErrorCallback
|
||||
import com.budiyev.android.codescanner.ScanMode
|
||||
import `in`.sminnovations.hpostesting.R
|
||||
|
||||
class ScannerKitActvity : AppCompatActivity() {
|
||||
private lateinit var codeScanner: CodeScanner
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_scanner_kit_actvity)
|
||||
val scannerView = findViewById<CodeScannerView>(R.id.scanner_view)
|
||||
|
||||
codeScanner = CodeScanner(this, scannerView)
|
||||
|
||||
// Parameters (default values)
|
||||
codeScanner.camera = CodeScanner.CAMERA_BACK // or CAMERA_FRONT or specific camera id
|
||||
codeScanner.formats = CodeScanner.ALL_FORMATS // list of type BarcodeFormat,
|
||||
// ex. listOf(BarcodeFormat.QR_CODE)
|
||||
codeScanner.autoFocusMode = AutoFocusMode.SAFE // or CONTINUOUS
|
||||
codeScanner.scanMode = ScanMode.SINGLE // or CONTINUOUS or PREVIEW
|
||||
codeScanner.isAutoFocusEnabled = true // Whether to enable auto focus or not
|
||||
codeScanner.isFlashEnabled = false // Whether to enable flash or not
|
||||
|
||||
// Callbacks
|
||||
codeScanner.decodeCallback = DecodeCallback {
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, "scanned text: ${it.text}",
|
||||
Toast.LENGTH_LONG).show()
|
||||
}
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra("QRCode", it.text)
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
|
||||
|
||||
}
|
||||
codeScanner.errorCallback = ErrorCallback { // or ErrorCallback.SUPPRESS
|
||||
runOnUiThread {
|
||||
Toast.makeText(this, "Camera initialization error: ${it.message}",
|
||||
Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
scannerView.setOnClickListener {
|
||||
codeScanner.startPreview()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
codeScanner.startPreview()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
codeScanner.releaseResources()
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
// You can do additional work here before calling super
|
||||
super.onBackPressed() // This calls finish() behind the scenes for you
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".presentation.KitScanActivity">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/app_bar_layout"
|
||||
|
||||
25
app/src/main/res/layout/activity_scanner_kit_actvity.xml
Normal file
25
app/src/main/res/layout/activity_scanner_kit_actvity.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.budiyev.android.codescanner.CodeScannerView
|
||||
android:id="@+id/scanner_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:autoFocusButtonColor="@android:color/white"
|
||||
app:autoFocusButtonVisible="true"
|
||||
app:flashButtonColor="@android:color/white"
|
||||
app:flashButtonVisible="true"
|
||||
app:frameColor="@android:color/white"
|
||||
app:frameCornersSize="50dp"
|
||||
app:frameCornersRadius="0dp"
|
||||
app:frameAspectRatioWidth="1"
|
||||
app:frameAspectRatioHeight="1"
|
||||
app:frameSize="0.75"
|
||||
app:frameThickness="2dp"
|
||||
app:frameVerticalBias="0.5"
|
||||
app:maskColor="#77000000"/>
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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_height="match_parent"
|
||||
tools:context="com.example.hpostesting.presentation.ScannerKitActvity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
25
app/src/main/res/layout/qrscanner.xml
Normal file
25
app/src/main/res/layout/qrscanner.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.budiyev.android.codescanner.CodeScannerView
|
||||
android:id="@+id/scanner_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:autoFocusButtonColor="@android:color/white"
|
||||
app:autoFocusButtonVisible="true"
|
||||
app:flashButtonColor="@android:color/white"
|
||||
app:flashButtonVisible="true"
|
||||
app:frameColor="@android:color/white"
|
||||
app:frameCornersSize="50dp"
|
||||
app:frameCornersRadius="0dp"
|
||||
app:frameAspectRatioWidth="1"
|
||||
app:frameAspectRatioHeight="1"
|
||||
app:frameSize="0.75"
|
||||
app:frameThickness="2dp"
|
||||
app:frameVerticalBias="0.5"
|
||||
app:maskColor="#77000000"/>
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user