Search in sources :

Example 1 with DecodeCallback

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();
        }
    });
}
Also used : CodeScanner(com.budiyev.android.codescanner.CodeScanner) CodeScannerView(com.budiyev.android.codescanner.CodeScannerView) Intent(android.content.Intent) DecodeCallback(com.budiyev.android.codescanner.DecodeCallback) CodeScannerView(com.budiyev.android.codescanner.CodeScannerView) View(android.view.View) Result(com.google.zxing.Result)

Example 2 with DecodeCallback

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();
        }
    });
}
Also used : Intent(android.content.Intent) DecodeCallback(com.budiyev.android.codescanner.DecodeCallback) CodeScannerView(com.budiyev.android.codescanner.CodeScannerView) View(android.view.View) TextView(android.widget.TextView) CollectionReference(com.google.firebase.firestore.CollectionReference) FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException) Result(com.google.zxing.Result) CodeScanner(com.budiyev.android.codescanner.CodeScanner) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

Intent (android.content.Intent)2 View (android.view.View)2 CodeScanner (com.budiyev.android.codescanner.CodeScanner)2 CodeScannerView (com.budiyev.android.codescanner.CodeScannerView)2 DecodeCallback (com.budiyev.android.codescanner.DecodeCallback)2 Result (com.google.zxing.Result)2 TextView (android.widget.TextView)1 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 CollectionReference (com.google.firebase.firestore.CollectionReference)1 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)1