Updated on 2026-08-14
This commit is contained in:
parent
a943d462b7
commit
0500d454fb
7 changed files with 475 additions and 429 deletions
|
|
@ -13,7 +13,7 @@ import com.google.zxing.Result;
|
|||
|
||||
import me.dm7.barcodescanner.zxing.ZXingScannerView;
|
||||
|
||||
public class QRScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{
|
||||
public class QRScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
|
||||
|
||||
private ZXingScannerView mScannerView;
|
||||
|
||||
|
|
@ -22,15 +22,14 @@ public class QRScanActivity extends AppCompatActivity implements ZXingScannerVi
|
|||
super.onCreate(savedInstanceState);
|
||||
//setContentView(R.layout.activity_qrscan);
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.e("QRScanActivity","User hasn't granted permission to use camera");
|
||||
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA}, 1);
|
||||
}else {
|
||||
Log.e("QRScanActivity", "User hasn't granted permission to use camera");
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1);
|
||||
} else {
|
||||
runScanner();
|
||||
}
|
||||
}
|
||||
|
||||
void runScanner()
|
||||
{
|
||||
void runScanner() {
|
||||
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
|
||||
setContentView(mScannerView);
|
||||
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
|
||||
|
|
@ -38,21 +37,20 @@ public class QRScanActivity extends AppCompatActivity implements ZXingScannerVi
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
String permissions[], int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case 1: {
|
||||
// If request is cancelled, the result arrays are empty.
|
||||
if (grantResults.length > 0
|
||||
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
|
||||
Log.i("QRScanActivity","permission was granted");
|
||||
Log.i("QRScanActivity", "permission was granted");
|
||||
// permission was granted, yay! Do the
|
||||
// contacts-related task you need to do.
|
||||
runScanner();
|
||||
|
||||
} else {
|
||||
Log.e("QRScanActivity","permission denied");
|
||||
Log.e("QRScanActivity", "permission denied");
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
|
||||
|
|
@ -67,24 +65,24 @@ public class QRScanActivity extends AppCompatActivity implements ZXingScannerVi
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleResult(Result result) {
|
||||
Intent data=new Intent();
|
||||
Intent data = new Intent();
|
||||
data.putExtra("QRCode", result.getText());
|
||||
setResult(Activity.RESULT_OK, data);
|
||||
setResult(Activity.RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if( mScannerView!=null ) mScannerView.stopCamera(); // Stop camera on pause
|
||||
if (mScannerView != null) mScannerView.stopCamera(); // Stop camera on pause
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if( mScannerView!=null ) mScannerView.startCamera();
|
||||
if (mScannerView != null) mScannerView.startCamera();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -50,11 +50,8 @@ public class RequestPINActivity extends AppCompatActivity implements NfcAdapter.
|
|||
|
||||
Mode mode;
|
||||
boolean allowFingerprint = false;
|
||||
|
||||
private NfcManager mNfcManager;
|
||||
|
||||
private TextView tvPIN;
|
||||
|
||||
private StartFingerprintReaderTask mStartFingerprintReaderTask;
|
||||
|
||||
public static final String KEY_ALIAS = "pinKey";
|
||||
|
|
@ -102,23 +99,15 @@ public class RequestPINActivity extends AppCompatActivity implements NfcAdapter.
|
|||
Button btn9 = findViewById(R.id.btn9);
|
||||
btn9.setOnClickListener(onButtonNClick);
|
||||
Button btnBS = findViewById(R.id.btnBackspace);
|
||||
btnBS.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String S = tvPIN.getText().toString();
|
||||
if (S.length() > 0) {
|
||||
tvPIN.setText(S.substring(0, S.length() - 1));
|
||||
}
|
||||
btnBS.setOnClickListener(view -> {
|
||||
String S = tvPIN.getText().toString();
|
||||
if (S.length() > 0) {
|
||||
tvPIN.setText(S.substring(0, S.length() - 1));
|
||||
}
|
||||
});
|
||||
|
||||
Button btnContinue = findViewById(R.id.btnContinue);
|
||||
btnContinue.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
doContinue();
|
||||
}
|
||||
});
|
||||
btnContinue.setOnClickListener(view -> doContinue());
|
||||
|
||||
mode = Mode.valueOf(getIntent().getStringExtra("mode"));
|
||||
TextView tvPrompt = findViewById(R.id.pin_prompt);
|
||||
|
|
@ -530,6 +519,4 @@ public class RequestPINActivity extends AppCompatActivity implements NfcAdapter.
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue