use of com.example.alphatour.oggetti.ElementString 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.oggetti.ElementString in project AlphaTour by Frank99DG.
the class ListElementsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_elements);
// istanza oggetti firebase
db = FirebaseFirestore.getInstance();
auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser();
idUser = user.getUid();
Intent intent = getIntent();
Place = intent.getStringExtra("Place");
idPlace = intent.getStringExtra("idPlace");
Zone = intent.getStringExtra("Zone");
idZone = intent.getStringExtra("idZone");
dashboardFlag = intent.getStringExtra("dashboardFlag");
zoneText = findViewById(R.id.specificZoneText);
zoneText.setText(Zone);
layout_list = findViewById(R.id.listElementsLayout);
db.collection("Elements").whereEqualTo("idZone", idZone).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
List<DocumentSnapshot> listDocuments = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : listDocuments) {
ElementString element = d.toObject(ElementString.class);
final View elementView = getLayoutInflater().inflate(R.layout.row_update, null, false);
TextView editableElement = (TextView) elementView.findViewById(R.id.itemUpdateText);
editableElement.setText(element.getTitle());
layout_list.addView(elementView);
editableElement.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View elementView) {
db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
// lista elementi
List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : listDocument) {
ElementString element = d.toObject(ElementString.class);
if (editableElement.getText().toString().equals(element.getTitle())) {
Intent intent = new Intent(ListElementsActivity.this, ModifyObjectActivity.class);
myQrData = element.getQrData();
intent.putExtra("data", myQrData);
intent.putExtra("Place", Place);
intent.putExtra("idPlace", idPlace);
intent.putExtra("Zone", Zone);
intent.putExtra("idZone", idZone);
intent.putExtra("Element", editableElement.getText().toString());
// per indicare a ModifyObject che fa parte del Modifica Luogo
String dashboardFlag = "0";
intent.putExtra("dashboardFlag", dashboardFlag);
startActivity(intent);
break;
}
}
}
}
});
}
});
}
}
}
});
}
use of com.example.alphatour.oggetti.ElementString in project AlphaTour by Frank99DG.
the class ModifyObjectActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify_object);
db = FirebaseFirestore.getInstance();
storegeProfilePick = FirebaseStorage.getInstance().getReference();
// riferimenti alle view
title = findViewById(R.id.titleQr);
description = findViewById(R.id.descriptionQr);
photo = findViewById(R.id.changePhotoObjectQr);
qrCode = findViewById(R.id.changeQr);
imagePhoto = findViewById(R.id.photoQr);
imageQrCode = findViewById(R.id.qr);
typology = findViewById(R.id.inputTypeZoneQr);
loadingBar = findViewById(R.id.modifyLoadingBar);
loadingBar.setVisibility(View.VISIBLE);
adapterItems = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, zoneList);
Intent intent = getIntent();
myQrData = intent.getStringExtra("data");
Place = intent.getStringExtra("Place");
idPlace = intent.getStringExtra("idPlace");
Zone = intent.getStringExtra("Zone");
idZone = intent.getStringExtra("idZone");
Element = intent.getStringExtra("Element");
dashboardFlag = intent.getStringExtra("dashboardFlag");
// settaggio idPlace,idZone se si arriva da dashboard
if (dashboardFlag.equals("1")) {
getIdPlaceAndIdZone(myQrData);
}
// settaggio dati elemento
db.collection("Elements").whereEqualTo("qrData", myQrData).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
if (task.getResult() != null) {
for (QueryDocumentSnapshot document : task.getResult()) {
ElementString element = document.toObject(ElementString.class);
idElement = document.getId();
db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
i++;
for (QueryDocumentSnapshot document : task.getResult()) {
Zone zone = document.toObject(Zone.class);
if (i == 1 && zone.getIdPlace().equals(idPlace)) {
zoneList.add(zone.getName());
zoneMap.put(document.getId(), zone.getName());
}
if (document.getId().matches(element.getIdZone())) {
zone = document.toObject(Zone.class);
title.setText(element.getTitle());
description.setText(element.getDescription());
idPhotoAndQrCode = element.getIdPhotoAndQrCode();
Qrdata = element.getQrData();
showPhoto();
showQrCode();
typology.setAdapter(adapterItems);
Zone = zone.getName();
typology.setHint(Zone);
typology.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
typology.setError(null);
item = parent.getItemAtPosition(position).toString();
}
});
}
}
} else {
Toast.makeText(ModifyObjectActivity.this, "Non è stato possibile caricare i dati dell'oggetto !!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
}
}
});
}
} else {
Toast.makeText(ModifyObjectActivity.this, "Oggetto non trovato !!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
Intent intent = new Intent(ModifyObjectActivity.this, DashboardActivity.class);
startActivity(intent);
}
} else {
Toast.makeText(ModifyObjectActivity.this, "Non è stato possibile caricare i dati dell'oggetto", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
Intent intent = new Intent(ModifyObjectActivity.this, DashboardActivity.class);
startActivity(intent);
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(ModifyObjectActivity.this, "Oggetto non trovato !!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
}
});
}
use of com.example.alphatour.oggetti.ElementString in project AlphaTour by Frank99DG.
the class DashboardActivity method inputSearchClick.
private void inputSearchClick() {
inputSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TourItem clickedItem = (TourItem) parent.getItemAtPosition(position);
String clickedTourText = clickedItem.getTourText();
db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
// lista elementi
List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : listDocument) {
ElementString element = d.toObject(ElementString.class);
if (clickedTourText.equals(element.getTitle())) {
Intent intent = new Intent(DashboardActivity.this, ModifyObjectActivity.class);
intent.putExtra("data", element.getQrData());
String dashboardFlag = "1";
intent.putExtra("dashboardFlag", dashboardFlag);
startActivity(intent);
inputSearch.setText(null);
break;
}
}
}
}
});
db.collection("Zones").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) {
Zone zone = d.toObject(Zone.class);
if (clickedTourText.equals(zone.getName())) {
Intent intent = new Intent(DashboardActivity.this, ModifyZoneActivity.class);
intent.putExtra("idPlace", zone.getIdPlace());
intent.putExtra("Zone", zone.getName());
String dashboardFlag = "1";
intent.putExtra("dashboardFlag", dashboardFlag);
startActivity(intent);
inputSearch.setText(null);
break;
}
}
}
}
});
db.collection("Places").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
// lista luoghi
List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : listDocument) {
Place place = d.toObject(Place.class);
if (clickedTourText.equals(place.getName())) {
Intent intent = new Intent(DashboardActivity.this, ModifyPlaceActivity.class);
intent.putExtra("Place", place.getName());
String dashboardFlag = "1";
intent.putExtra("dashboardFlag", dashboardFlag);
startActivity(intent);
inputSearch.setText(null);
break;
}
}
}
}
});
}
});
}
use of com.example.alphatour.oggetti.ElementString in project AlphaTour by Frank99DG.
the class CreateConstraintsWizard method saveQrCode.
private void saveQrCode(Bitmap qrCode, Element element, int i, long id) {
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(getContext(), "Zone e Oggetti creati con successo", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
success = false;
Toast.makeText(getContext(), "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
loadingBar.setVisibility(View.GONE);
}
});
}
}
}
}
});
}
}
});
}
});
}
Aggregations