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);
}
});
}
}
}
}
});
}
}
});
}
});
}
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);
}
});
}
}
}
}
});
}
}
});
}
});
}
Aggregations