use of com.budiyev.android.codescanner.DecodeCallback in project EasyPlayer-RTMP-Android by EasyDSS.
the class ScanQRActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan_qr);
CodeScannerView scannerView = findViewById(R.id.scanner_view);
mCodeScanner = new CodeScanner(this, scannerView);
mCodeScanner.setScanMode(ScanMode.SINGLE);
mCodeScanner.setAutoFocusEnabled(true);
mCodeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull final Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!TextUtils.isEmpty(result.getText())) {
final String text = result.getText().trim();
if (text.toLowerCase().startsWith("rtmp://")) {
Intent intent = new Intent();
intent.putExtra("text", text);
setResult(RESULT_OK, intent);
finish();
}
}
}
});
}
});
scannerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCodeScanner.startPreview();
}
});
}
use of com.budiyev.android.codescanner.DecodeCallback in project QR-Game by CMPUT301W22T15.
the class ScannerView method onCreate.
/**
* This method creates the inital interface and obtains the necessary permissions.
* @param savedInstanceState
* Expects object of type Bundle.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scanner_view);
// Access a Cloud FireStore instance from Activity
db = FirebaseFirestore.getInstance();
final CollectionReference collectionReference = db.collection("Players");
// Set variable data
scannerView = findViewById(R.id.scanner_view);
codeScanner = new CodeScanner(this, scannerView);
// resultData = findViewById(R.id.code_result);
// Decode data from QR code
codeScanner.setDecodeCallback(new DecodeCallback() {
@Override
public void onDecoded(@NonNull Result result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// resultData.setText(result.getText());
Toast.makeText(ScannerView.this, "Scanned Successfully", Toast.LENGTH_SHORT).show();
// TODO create the location string
QRCode qrcode = new QRCode(result.getText(), "");
qrcode.setKey("classified information");
if (isUnique(qrcode.getId())) {
singletonPlayer.player.addQrcode(qrcode);
String TAG = "working";
collectionReference.document(singletonPlayer.player.getUsername()).set(singletonPlayer.player).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
Log.d(TAG, "message");
Intent intent = new Intent(ScannerView.this, QRCodeEditor.class);
intent.putExtra("QRCodeValue", (Parcelable) qrcode);
startActivity(intent);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("MYAPP", "exception: " + e.getMessage());
Log.e("MYAPP", "exception: " + e.toString());
}
});
} else {
// not unique. close activity
Toast.makeText(ScannerView.this, "you already scanned this one", Toast.LENGTH_SHORT).show();
finish();
}
}
});
}
});
// Restart scan if UI is clicked
scannerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
codeScanner.startPreview();
}
});
}
Aggregations