Search in sources :

Example 1 with GenerateQrCodeClass

use of com.example.alphatour.qrcode.GenerateQrCodeClass in project AlphaTour by Frank99DG.

the class ImportPhotoObjectActivity method saveQrCode.

private void saveQrCode(String dataQr, Element element, int i, long id) {
    GenerateQrCodeClass generateQrCodeClass = new GenerateQrCodeClass(ImportPhotoObjectActivity.this);
    Bitmap qrCode = generateQrCodeClass.generateQrCode(dataQr);
    final StorageReference fileRef = storegeProfilePick.child("QrCodeObjects").child("QrCode_Objects" + "_" + id);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    qrCode.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] data = baos.toByteArray();
    UploadTask uploadTask = fileRef.putBytes(data);
    uploadTask.addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
        // Handle unsuccessful uploads
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
            uploadTask.continueWithTask(new Continuation() {

                @Override
                public Object then(@NonNull Task task) throws Exception {
                    if (!task.isSuccessful()) {
                        throw task.getException();
                    }
                    return fileRef.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(@NonNull Task task) {
                    if (task.isSuccessful()) {
                        // scarico il link di Storage dell'immagine
                        Uri downloadUrl = (Uri) task.getResult();
                        uriUploadQrCode.add(downloadUrl.toString());
                        db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                            @Override
                            public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                                if (!queryDocumentSnapshots.isEmpty()) {
                                    // lista zone
                                    List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                                    for (DocumentSnapshot d : listDocument) {
                                        ElementString elme = d.toObject(ElementString.class);
                                        if (elme.getTitle().matches(element.getTitle())) {
                                            HashMap<String, Object> userMap = new HashMap<>();
                                            userMap.put("qrCode", uriUploadQrCode.get(i));
                                            db.collection("Elements").document(d.getId()).update("qrCode", uriUploadQrCode.get(i)).addOnSuccessListener(new OnSuccessListener<Void>() {

                                                @Override
                                                public void onSuccess(Void unused) {
                                                    success = true;
                                                    Toast.makeText(ImportPhotoObjectActivity.this, "Zone e Oggetti creati con successo", Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            }).addOnFailureListener(new OnFailureListener() {

                                                @Override
                                                public void onFailure(@NonNull Exception e) {
                                                    success = false;
                                                    Toast.makeText(ImportPhotoObjectActivity.this, "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            });
        }
    });
}
Also used : GenerateQrCodeClass(com.example.alphatour.qrcode.GenerateQrCodeClass) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) StorageTask(com.google.firebase.storage.StorageTask) HashMap(java.util.HashMap) Uri(android.net.Uri) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) Bitmap(android.graphics.Bitmap) UploadTask(com.google.firebase.storage.UploadTask) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) NonNull(androidx.annotation.NonNull) List(java.util.List) ArrayList(java.util.ArrayList) ElementString(com.example.alphatour.oggetti.ElementString) Continuation(com.google.android.gms.tasks.Continuation) StorageReference(com.google.firebase.storage.StorageReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 2 with GenerateQrCodeClass

use of com.example.alphatour.qrcode.GenerateQrCodeClass in project AlphaTour by Frank99DG.

the class FileReceiverActivity method saveQrCode.

private void saveQrCode(String dataQr, Element element, int i, long id) {
    GenerateQrCodeClass generateQrCodeClass = new GenerateQrCodeClass(FileReceiverActivity.this);
    Bitmap qrCode = generateQrCodeClass.generateQrCode(dataQr);
    final StorageReference fileRef = storegeProfilePick.child("QrCodeObjects").child("QrCode_Objects" + "_" + id);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    qrCode.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] data = baos.toByteArray();
    UploadTask uploadTask = fileRef.putBytes(data);
    uploadTask.addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
        // Handle unsuccessful uploads
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
            uploadTask.continueWithTask(new Continuation() {

                @Override
                public Object then(@NonNull Task task) throws Exception {
                    if (!task.isSuccessful()) {
                        throw task.getException();
                    }
                    return fileRef.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(@NonNull Task task) {
                    if (task.isSuccessful()) {
                        // scarico il link di Storage dell'immagine
                        Uri downloadUrl = (Uri) task.getResult();
                        uriUploadQrCode.add(downloadUrl.toString());
                        db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                            @Override
                            public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                                if (!queryDocumentSnapshots.isEmpty()) {
                                    // lista zone
                                    List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                                    for (DocumentSnapshot d : listDocument) {
                                        ElementString elme = d.toObject(ElementString.class);
                                        if (elme.getTitle().matches(element.getTitle())) {
                                            HashMap<String, Object> userMap = new HashMap<>();
                                            userMap.put("qrCode", uriUploadQrCode.get(i));
                                            db.collection("Elements").document(d.getId()).update("qrCode", uriUploadQrCode.get(i)).addOnSuccessListener(new OnSuccessListener<Void>() {

                                                @Override
                                                public void onSuccess(Void unused) {
                                                    success = true;
                                                    Toast.makeText(FileReceiverActivity.this, "Zone e Oggetti creati con successo", Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            }).addOnFailureListener(new OnFailureListener() {

                                                @Override
                                                public void onFailure(@NonNull Exception e) {
                                                    success = false;
                                                    Toast.makeText(FileReceiverActivity.this, "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            });
        }
    });
}
Also used : GenerateQrCodeClass(com.example.alphatour.qrcode.GenerateQrCodeClass) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) StorageTask(com.google.firebase.storage.StorageTask) HashMap(java.util.HashMap) Uri(android.net.Uri) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) Bitmap(android.graphics.Bitmap) UploadTask(com.google.firebase.storage.UploadTask) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) NonNull(androidx.annotation.NonNull) List(java.util.List) ArrayList(java.util.ArrayList) ElementString(com.example.alphatour.oggetti.ElementString) Continuation(com.google.android.gms.tasks.Continuation) StorageReference(com.google.firebase.storage.StorageReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 NonNull (androidx.annotation.NonNull)2 ElementString (com.example.alphatour.oggetti.ElementString)2 GenerateQrCodeClass (com.example.alphatour.qrcode.GenerateQrCodeClass)2 Continuation (com.google.android.gms.tasks.Continuation)2 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)2 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)2 Task (com.google.android.gms.tasks.Task)2 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)2 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)2 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)2 StorageReference (com.google.firebase.storage.StorageReference)2 StorageTask (com.google.firebase.storage.StorageTask)2 UploadTask (com.google.firebase.storage.UploadTask)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2