Receive correct returnCode

This commit is contained in:
jacques 2022-02-19 12:19:27 +01:00
parent 2a7856179c
commit 066fee7334

View file

@ -32,6 +32,9 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.google.zxing.client.android.Intents;
import com.journeyapps.barcodescanner.ScanOptions;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -185,9 +188,17 @@ public class DrugListActivity extends AppCompatActivity {
});*/ });*/
mBarcodeScannerLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { mBarcodeScannerLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
Intent intent = result.getData(); Intent intent = result.getData();
BarcodeValues barcodeValues = Utils.parseSetBarcodeActivtyResult(Utils.BARCODE_SCAN, result.getResultCode(), intent, this); BarcodeValues barcodeValues = Utils.parseSetBarcodeActivityResult(Utils.BARCODE_SCAN, result.getResultCode(), intent, this);
if (!barcodeValues.isEmpty()) { int resultCode = result.getResultCode();
assert intent != null;
Bundle bundle = intent.getExtras();
String format = bundle.getString("Barcode Format name");
String content = bundle.getString("Barcode Content");
int requestCode = bundle.getInt("requestCode");
int returnCode = bundle.getInt("returnCode");
/*if (!barcodeValues.isEmpty()) {
Intent newIntent = new Intent(getApplicationContext(), DrugListActivity.class); Intent newIntent = new Intent(getApplicationContext(), DrugListActivity.class);
Bundle newBundle = new Bundle(); Bundle newBundle = new Bundle();
@ -196,9 +207,8 @@ public class DrugListActivity extends AppCompatActivity {
newIntent.putExtras(newBundle); newIntent.putExtras(newBundle);
startActivity(newIntent); startActivity(newIntent);
} }*/
}); });
constructDrugsList(); constructDrugsList();
} }
@ -265,7 +275,7 @@ public class DrugListActivity extends AppCompatActivity {
// Launch scan // Launch scan
public void onButtonClick(View view) { public void onButtonClick(View view) {
/*ScanOptions options = new ScanOptions(); ScanOptions options = new ScanOptions();
options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_39, options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_39,
ScanOptions.CODE_128, ScanOptions.CODE_128); ScanOptions.CODE_128, ScanOptions.CODE_128);
options.setCameraId(0); // Use a specific camera of the device options.setCameraId(0); // Use a specific camera of the device
@ -274,7 +284,7 @@ public class DrugListActivity extends AppCompatActivity {
//options.setTimeout(3600); //options.setTimeout(3600);
options.setCaptureActivity(CustomScannerActivity.class); options.setCaptureActivity(CustomScannerActivity.class);
options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN); options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.MIXED_SCAN);
options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN);*/ options.addExtra(Intents.Scan.SCAN_TYPE, Intents.Scan.INVERTED_SCAN);
//barcodeLauncher.launch(options); //barcodeLauncher.launch(options);
Intent intent = new Intent(getApplicationContext(), CustomScannerActivity.class); Intent intent = new Intent(getApplicationContext(), CustomScannerActivity.class);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -282,39 +292,53 @@ public class DrugListActivity extends AppCompatActivity {
mBarcodeScannerLauncher.launch(intent); mBarcodeScannerLauncher.launch(intent);
} }
/* @Override /* @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) { if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
// This is important, otherwise the result will not be passed to the fragment // This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
return; return;
} }
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
if (BuildConfig.DEBUG) {
Toast.makeText(this, "REQUEST_CODE = " + requestCode +
"RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
}
if (requestCode == CUSTOMIZED_REQUEST_CODE) { if (requestCode == CUSTOMIZED_REQUEST_CODE) {
if (BuildConfig.DEBUG) { Toast.makeText(this, "REQUEST_CODE = " + requestCode + if (BuildConfig.DEBUG) {
"RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show(); } Toast.makeText(this, "REQUEST_CODE = " + requestCode +
"RESULT_CODE = " + resultCode, Toast.LENGTH_LONG).show();
}
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode); Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
constructDrugsList(); constructDrugsList();
} else { } else {
IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data); IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
if (BuildConfig.DEBUG) { Toast.makeText(this, "REQUEST_CODE = " + requestCode, if (BuildConfig.DEBUG) {
Toast.LENGTH_LONG).show(); } Toast.makeText(this, "REQUEST_CODE = " + requestCode,
Toast.LENGTH_LONG).show();
}
Log.d(TAG, "REQUEST_CODE = " + requestCode + "resultCode = " + resultCode); Log.d(TAG, "REQUEST_CODE = " + requestCode + "resultCode = " + resultCode);
if (result.getContents() == null) { if (result.getContents() == null) {
Intent originalIntent = result.getOriginalIntent(); Intent originalIntent = result.getOriginalIntent();
if (originalIntent == null) { if (originalIntent == null) {
if (resultCode == 3) { if (resultCode == 3) {
if(BuildConfig.DEBUG) { Toast.makeText(this, "Keyboard input", if (BuildConfig.DEBUG) {
Toast.LENGTH_SHORT).show(); } Toast.makeText(this, "Keyboard input",
Toast.LENGTH_SHORT).show();
}
Log.d(TAG, "Keyboard Input"); Log.d(TAG, "Keyboard Input");
showInputDialog(); showInputDialog();
} else { } else {
Log.d(TAG, "Cancelled scan"); Log.d(TAG, "Cancelled scan");
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode); Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
} }
if(BuildConfig.DEBUG) { Toast.makeText(this, "Cancelled", if (BuildConfig.DEBUG) {
Toast.LENGTH_LONG).show(); } Toast.makeText(this, "Cancelled",
Toast.LENGTH_LONG).show();
}
} else if (originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) { } else if (originalIntent.hasExtra(Intents.Scan.MISSING_CAMERA_PERMISSION)) {
Log.d(TAG, "Cancelled scan due to missing camera permission"); Log.d(TAG, "Cancelled scan due to missing camera permission");
Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode); Log.d(TAG, "REQUEST_CODE = " + requestCode + " RESULT_CODE = " + resultCode);
@ -326,8 +350,10 @@ public class DrugListActivity extends AppCompatActivity {
Log.d(TAG, "result.getContents = " + result.getContents()); Log.d(TAG, "result.getContents = " + result.getContents());
Log.d(TAG, "format = " + result.getFormatName()); Log.d(TAG, "format = " + result.getFormatName());
if (BuildConfig.DEBUG) { Toast.makeText(this, "Scanned: " + if (BuildConfig.DEBUG) {
result.getContents(), Toast.LENGTH_LONG).show(); } Toast.makeText(this, "Scanned: " +
result.getContents(), Toast.LENGTH_LONG).show();
}
String cip13; String cip13;
@ -353,7 +379,7 @@ public class DrugListActivity extends AppCompatActivity {
// Get Drug from database // Get Drug from database
final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13); final Drug scannedDrug = dbDrug.getDrugByCIP13(cip13);
askToAddInDB(scannedDrug); askToAddInDB(scannedDrug);
} }
} }
}*/ }*/