use of com.example.alphatour.oggetti.Element in project AlphaTour by Frank99DG.
the class AddElementActivity method saveObject.
public void saveObject(View v) {
element = new Element();
String Title = nameElement.getText().toString();
String Description = description.getText().toString();
if (Title.isEmpty()) {
nameElement.setError(getString(R.string.required_field));
nameElement.requestFocus();
errorFlag = true;
} else {
element.setTitle(Title);
errorFlag = false;
}
if (Description.isEmpty()) {
description.setError(getString(R.string.required_field));
description.requestFocus();
errorFlag = true;
} else {
element.setDescription(Description);
errorFlag = false;
}
if (flagPhoto == false) {
if (permission) {
photo.setError(getString(R.string.required_field));
photo.requestFocus();
errorFlag = true;
} else {
uri = Uri.parse("");
setPhoto(uri);
element.setPhoto(uri);
}
} else {
if (uri != null) {
element.setPhoto(uri);
setPhoto(uri);
errorFlag = false;
}
}
if (GenerateQrCodeActivity.getQrFlag() == false) {
generateQrCode.setError(getString(R.string.required_field));
generateQrCode.requestFocus();
errorFlag = true;
} else {
element.setQrCode(GenerateQrCodeActivity.getBitmap());
setQr(GenerateQrCodeActivity.getBitmap());
errorFlag = false;
}
if (errorFlag) {
return;
} else {
if (!duplicateControl(Title)) {
Intent intent = new Intent();
intent.putExtra("title", element.getTitle());
intent.putExtra("description", element.getDescription());
intent.putExtra("data", GenerateQrCodeActivity.getData());
Bundle bundle;
intent.putExtra("zone", item);
setResult(Activity.RESULT_OK, intent);
finish();
} else {
Toast.makeText(AddElementActivity.this, R.string.object_already_exists, Toast.LENGTH_LONG).show();
}
}
}
use of com.example.alphatour.oggetti.Element in project AlphaTour by Frank99DG.
the class ElementDetailsActivity method saveElement.
public void saveElement(View view) {
save = true;
String Title = title.getText().toString();
String Description = description.getText().toString();
// String Activity = activity.getText().toString();
Element elementModified = new Element();
if (Title.isEmpty()) {
title.setError(getString(R.string.required_field));
title.requestFocus();
errorFlag = true;
} else {
elementModified.setTitle(Title);
}
if (Description.isEmpty()) {
description.setError(getString(R.string.required_field));
description.requestFocus();
errorFlag = true;
} else {
elementModified.setDescription(Description);
}
if (errorFlag) {
return;
} else {
Intent intent = new Intent();
intent.putExtra("title", elementModified.getTitle());
intent.putExtra("description", elementModified.getDescription());
if (selected) {
intent.putExtra("zone", item);
} else {
intent.putExtra("zone", zone);
}
setResult(Activity.RESULT_OK, intent);
View v = list.get(0);
LinearLayout layout = CreateObjectWizard.getLayout_list();
for (int i = 0; i < elementList.size(); i++) {
if (elementList.get(i).equals(element)) {
elementList.remove(i);
CreateObjectWizard.setElementList(elementList);
}
}
layout.removeView(v);
list.remove(0);
finish();
}
}
use of com.example.alphatour.oggetti.Element in project AlphaTour by Frank99DG.
the class ImportPhotoObjectActivity method saveObjects.
private void saveObjects(List<Element> elmlist) {
db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (int i = 0; i < elmlist.size(); i++) {
for (QueryDocumentSnapshot document : task.getResult()) {
Element newElement = elmlist.get(i);
Zone zon = document.toObject(Zone.class);
if (zon.getName().matches(newElement.getZoneRif())) {
newElement.setIdZone(document.getId());
id = generateidPhotoAndQrCode();
elm.put("idZone", newElement.getIdZone());
elm.put("title", newElement.getTitle());
elm.put("description", newElement.getDescription());
elm.put("photo", newElement.getPhoto().toString());
elm.put("qrCode", null);
elm.put("idPhotoAndQrCode", Long.parseLong(newElement.getIdPhotoAndQrCodeString()));
elm.put("idUser", user.getUid());
elm.put("qrData", newElement.getQrData());
db.collection("Elements").add(elm).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
success = true;
// String id=documentReference.getId();
}
});
saveQrCode(newElement.getQrData(), newElement, i, id);
}
}
}
}
}
}).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();
}
});
}
use of com.example.alphatour.oggetti.Element in project AlphaTour by Frank99DG.
the class ImportPhotoObjectActivity method readCsv.
private void readCsv(Intent data) {
progressBar.setVisibility(View.VISIBLE);
if (data == null) {
return;
} else {
Uri uri = data.getData();
Toast.makeText(ImportPhotoObjectActivity.this, uri.getPath(), Toast.LENGTH_SHORT).show();
String path = uri.getPath();
path = path.substring(path.indexOf(":") + 1);
File file = new File(path);
try {
BufferedReader read = new BufferedReader(new FileReader(file));
String line = "";
Boolean isEmpty = true;
while ((line = read.readLine()) != null) {
isEmpty = false;
String[] token = line.split(",");
ReadCsv readCsv = new ReadCsv();
boolean flag = false;
for (int i = 0; i < token.length; i++) {
if (token[i] == null) {
flag = true;
}
}
if (!flag) {
if (!token[0].matches("namePlace")) {
Element elm = new Element();
Place place = new Place();
Zone zone = new Zone();
Constraint constraint = new Constraint();
if (listLineCsv.size() > 0) {
setDataToken(token, readCsv);
if (!token[0].isEmpty()) {
for (int i = 0; i < listPlace.size(); i++) {
if (!listPlace.get(i).getName().matches(token[0]) && !listPlace.get(i).getCity().matches(token[1]) && !listPlace.get(i).getTypology().matches(token[2])) {
idP++;
place.setIdPlace(idP);
place.setName(token[0]);
place.setCity(token[1]);
place.setTypology(token[2]);
listPlace.add(place);
}
}
for (int j = 0; j < listPlace.size(); j++) {
if (!listZone.get(i).getName().matches(token[3])) {
zone.setIdPl(idP);
zone.setName(token[3]);
idZ++;
listZone.add(zone);
}
}
elm.setIdZon(idZ);
elm.setTitle(readCsv.getTitleObject());
elm.setDescription(readCsv.getDescriptionObject());
elm.setQrData(readCsv.getQrDataObject());
elm.setPhoto(Uri.parse(readCsv.getLinkImageObject()));
String[] str = readCsv.getLinkImageObject().split("Objects_");
String[] st = str[1].split("\\?");
String idPh = st[0];
elm.setIdPhotoAndQrCodeString(idPh);
elm.setZoneRif(token[3]);
if (!token[8].isEmpty() && !!token[9].isEmpty()) {
constraint.setFromZone(token[8]);
constraint.setInZone(token[9]);
}
listElement.add(elm);
if (!token[8].isEmpty() && !token[9].isEmpty()) {
constraint.setFromZone(token[8]);
constraint.setInZone(token[9]);
listConstranints.add(constraint);
}
}
} else {
setDataToken(token, readCsv);
if (!token[0].isEmpty()) {
elm.setTitle(readCsv.getTitleObject());
elm.setDescription(readCsv.getDescriptionObject());
elm.setQrData(readCsv.getQrDataObject());
elm.setPhoto(Uri.parse(readCsv.getLinkImageObject()));
String[] str = readCsv.getLinkImageObject().split("Objects_");
String[] st = str[1].split("\\?");
String idPh = st[0];
elm.setIdPhotoAndQrCodeString(idPh);
elm.setZoneRif(token[3]);
place.setName(token[0]);
place.setCity(token[1]);
place.setTypology(token[2]);
place.setIdPlace(idP);
zone.setIdPl(idP);
zone.setName(token[3]);
elm.setIdZon(idZ);
listPlace.add(place);
listZone.add(zone);
listElement.add(elm);
}
if (!token[8].isEmpty() && !token[9].isEmpty()) {
constraint.setFromZone(token[8]);
constraint.setInZone(token[9]);
listConstranints.add(constraint);
}
}
}
} else {
Toast.makeText(ImportPhotoObjectActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
line = null;
progressBar.setVisibility(View.GONE);
}
}
if (isEmpty) {
Toast.makeText(ImportPhotoObjectActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
} else {
savePlace();
saveConstraints();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (success) {
Intent intent = new Intent(ImportPhotoObjectActivity.this, DashboardActivity.class);
startActivity(intent);
progressBar.setVisibility(View.GONE);
} else {
Toast.makeText(ImportPhotoObjectActivity.this, "Salvataggio Luogo non riuscito", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
}, 2000L);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.example.alphatour.oggetti.Element in project AlphaTour by Frank99DG.
the class CreateObjectWizard method LoadPreferences.
private void LoadPreferences() {
SharedPreferences sharedPreferences = getActivity().getPreferences(Context.MODE_PRIVATE);
int size = sharedPreferences.getInt("elementListSize", 0);
elementList.clear();
for (int i = 0; i < size; i++) {
created = true;
Element element = new Element();
element.setSaved(sharedPreferences.getBoolean("Saved" + i, true));
element.setZoneRif(sharedPreferences.getString("Zone" + i, ""));
element.setTitle(sharedPreferences.getString("Title" + i, ""));
element.setDescription(sharedPreferences.getString("Description" + i, ""));
element.setPhoto(Uri.parse(sharedPreferences.getString("Photo" + i, "")));
element.setQrData(sharedPreferences.getString("QrData" + i, ""));
Bitmap bitmap = convertStringToBitmap(sharedPreferences.getString("QrCode" + i, ""));
element.setQrCode(bitmap);
createdObject(element);
}
}
Aggregations