From 981548224419df4d24578dce8866f1e3e8bd9556 Mon Sep 17 00:00:00 2001 From: jacques Date: Mon, 21 Feb 2022 14:53:47 +0100 Subject: [PATCH] back to almost working situation --- .../pilldroid/CustomScannerActivity.java | 11 +- .../foucry/pilldroid/DrugListActivity.java | 13 +- .../net/foucry/pilldroid/ScanContract.java | 144 ------------------ 3 files changed, 18 insertions(+), 150 deletions(-) delete mode 100644 app/src/main/java/net/foucry/pilldroid/ScanContract.java diff --git a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java index 7bdae27..6687af3 100644 --- a/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/CustomScannerActivity.java @@ -61,10 +61,17 @@ public class CustomScannerActivity extends Activity { findViewById(R.id.switch_flashlight).setVisibility(View.GONE); } - capture = new CaptureManager(this, barcodeScannerView); - captureIntentBundle.putBoolean(Intents.Scan.BEEP_ENABLED, true); + captureIntentBundle.putInt("Intents.Scan.MIXED_SCAN", Intents.Scan.MIXED_SCAN); + captureIntentBundle.putInt("Intents.Scan.INVERTED_SCAN", Intents.Scan.INVERTED_SCAN); + captureIntent.putExtras(captureIntentBundle); + + /*captureIntent.putExtra("Intents.Scan.MIXED_SCAN", Intents.Scan.MIXED_SCAN); + captureIntent.putExtra("Intents.Scan.INVERTED_SCAN", Intents.Scan.INVERTED_SCAN); + captureIntent.putExtra("Intents.Scan.BEEP_ENABLED", Intents.Scan.BEEP_ENABLED);*/ + + capture = new CaptureManager(this, barcodeScannerView); capture.initializeFromIntent(getIntent(), savedInstanceState); capture.setShowMissingCameraPermissionDialog(false); //capture.decode(); diff --git a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java index 86bca3e..309cf61 100644 --- a/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java +++ b/app/src/main/java/net/foucry/pilldroid/DrugListActivity.java @@ -10,6 +10,7 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; + import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -33,7 +34,6 @@ import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.RecyclerView; import com.google.zxing.client.android.Intents; -import com.journeyapps.barcodescanner.ScanOptions; import java.text.SimpleDateFormat; import java.util.Date; @@ -275,7 +275,7 @@ public class DrugListActivity extends AppCompatActivity { // Launch scan public void onButtonClick(View view) { - ScanOptions options = new ScanOptions(); + /*ScanOptions options = new ScanOptions(); options.setDesiredBarcodeFormats(ScanOptions.DATA_MATRIX, ScanOptions.CODE_39, ScanOptions.CODE_128, ScanOptions.CODE_128); options.setCameraId(0); // Use a specific camera of the device @@ -283,11 +283,16 @@ public class DrugListActivity extends AppCompatActivity { options.setBarcodeImageEnabled(true); //options.setTimeout(3600); options.setCaptureActivity(CustomScannerActivity.class); + options.setBeepEnabled(true); 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); - Intent intent = new Intent(getApplicationContext(), ScannerActivity.class); + Intent intent = new Intent(getApplicationContext(), CustomScannerActivity.class); Bundle bundle = new Bundle(); + bundle.putBoolean(Intents.Scan.BEEP_ENABLED, true); + bundle.putInt("Intents.Scan.MIXED_SCAN", Intents.Scan.MIXED_SCAN); + bundle.putInt("Intents.Scan.INVERTED_SCAN", Intents.Scan.INVERTED_SCAN); + intent.putExtras(bundle); mBarcodeScannerLauncher.launch(intent); } diff --git a/app/src/main/java/net/foucry/pilldroid/ScanContract.java b/app/src/main/java/net/foucry/pilldroid/ScanContract.java deleted file mode 100644 index 824f743..0000000 --- a/app/src/main/java/net/foucry/pilldroid/ScanContract.java +++ /dev/null @@ -1,144 +0,0 @@ -package net.foucry.pilldroid; - -import android.content.Context; -import android.content.Intent; - -import androidx.activity.result.contract.ActivityResultContract; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public class ScanContract extends ActivityResultContract { - - private static final String TAG = ScanContract.class.getName(); - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - findViewById(R.id.keyboard_button).setOnClickListener(this::onkeyboard); - findViewById(R.id.cancel_button).setOnClickListener(this::onCancel); - findViewById(R.id.switch_flashlight).setOnClickListener(this::switchFlashLight); - viewfinderView = findViewById(R.id.zxing_viewfinder_view); - - barcodeScannerView = findViewById(R.id.zxing_barcode_scanner); - - capture = new CaptureManager(this, barcodeScannerView); - Intent captureIntent = createIntent(this, options); - Bundle captureIntentBundle = new Bundle(); - - captureIntentBundle.putBoolean(Intents.Scan.BEEP_ENABLED, true); - captureIntent.putExtras(captureIntentBundle); - capture.initializeFromIntent(captureIntent, savedInstanceState); - - changeMaskColor(null); - changeLaserVisibility(true); - - barcodeScannerView.decodeSingle(new BarcodeCallback() { - @Override - public void barcodeResult(BarcodeResult result) { - Intent scanResult = new Intent(); - scanResult.putExtra("Barcode Content", result.getText()); - scanResult.putExtra("Barcode Forma name", result.getBarcodeFormat().name()); - scanResult.putExtra("returnCode", capture.captureIntentBundle.getInt("returnCode")); - scanResult.putExtra("resultCode", 1); - ScannerContract.this.setResult(RESULT_OK, scanResult); - - Log.d(TAG, "scanResult ==" + scanResult.toString()); - finish(); - } - }); - } - - @NonNull - @Override - public Intent createIntent(@NonNull Context context, ScanOptions input) { - return input.createScanIntent(context); - } - - @Override - public ScanIntentResult parseResult(int resultCode, @Nullable Intent intent) { - return ScanIntentResult.parseActivityResult(resultCode, intent); - } - - @Override - protected void onResume() { - super.onResume(); - capture.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - capture.onPause(); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - capture.onSaveInstanceState(outState); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - return barcodeScannerView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); - } - - /** - * Check if the device's camera has a Flashlight. - * - * @return true if there is Flashlight, otherwise false. - */ - private boolean hasFlash() { - return getApplicationContext().getPackageManager() - .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); - } - - public void switchFlashlight(View view) { - Log.d(TAG, "Switch torch"); - if (switchFlashlightButton.isActivated()) { - barcodeScannerView.setTorchOff(); - } else { - barcodeScannerView.setTorchOn(); - } - } - - public void changeMaskColor(View view) { - Random rnd = new Random(); - int color = Color.argb(100, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); - viewfinderView.setMaskColor(color); - } - - public void changeLaserVisibility(boolean visible) { - viewfinderView.setLaserVisibility(visible); - } - - public void onTorchOn() { - Log.d(TAG, "TorchON"); - switchFlashlightButton.setActivated(true); - } - - public void onTorchOff() { - Log.d(TAG, "TorchOFF"); - switchFlashlightButton.setActivated(false); - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - capture.onRequestPermissionsResult(requestCode, permissions, grantResults); - } - - public void onKeyboard(View view) { - Log.d(TAG, "onkeyboard"); - Intent resultIntent = new Intent(); - resultIntent.putExtra("returnCode",3); - CustomScannerActivity.this.setResult(RESULT_OK, resultIntent); - finish(); - } - - public void onCancel(View view) { - Log.d(TAG, "onCancel"); - Intent resultIntent = new Intent(); - resultIntent.putExtra("returnCode", 2); - CustomScannerActivity.this.setResult(RESULT_OK, resultIntent); - finish(); - } -}