mirror of
https://github.com/jfoucry/Pilldroid.git
synced 2024-11-22 04:29:22 +01:00
back to almost working situation
This commit is contained in:
parent
1efac31e54
commit
9815482244
3 changed files with 18 additions and 150 deletions
|
@ -61,10 +61,17 @@ public class CustomScannerActivity extends Activity {
|
||||||
findViewById(R.id.switch_flashlight).setVisibility(View.GONE);
|
findViewById(R.id.switch_flashlight).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
capture = new CaptureManager(this, barcodeScannerView);
|
|
||||||
|
|
||||||
captureIntentBundle.putBoolean(Intents.Scan.BEEP_ENABLED, true);
|
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.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.initializeFromIntent(getIntent(), savedInstanceState);
|
||||||
capture.setShowMissingCameraPermissionDialog(false);
|
capture.setShowMissingCameraPermissionDialog(false);
|
||||||
//capture.decode();
|
//capture.decode();
|
||||||
|
|
|
@ -10,6 +10,7 @@ import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -33,7 +34,6 @@ import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.google.zxing.client.android.Intents;
|
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;
|
||||||
|
@ -275,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
|
||||||
|
@ -283,11 +283,16 @@ public class DrugListActivity extends AppCompatActivity {
|
||||||
options.setBarcodeImageEnabled(true);
|
options.setBarcodeImageEnabled(true);
|
||||||
//options.setTimeout(3600);
|
//options.setTimeout(3600);
|
||||||
options.setCaptureActivity(CustomScannerActivity.class);
|
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.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(), ScannerActivity.class);
|
Intent intent = new Intent(getApplicationContext(), CustomScannerActivity.class);
|
||||||
Bundle bundle = new Bundle();
|
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);
|
intent.putExtras(bundle);
|
||||||
mBarcodeScannerLauncher.launch(intent);
|
mBarcodeScannerLauncher.launch(intent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<ScanOptions, ScanIntentResult> {
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue