use of com.example.alphatour.oggetti.Constraint 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.Constraint in project AlphaTour by Frank99DG.
the class CreateConstraintsWizard method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_create_constraints_wizard, container, false);
layout_list = view.findViewById(R.id.listConstraintLayout);
zone_list = CreateZoneWizard.getZone_list();
db = FirebaseFirestore.getInstance();
storegeProfilePick = FirebaseStorage.getInstance().getReference();
auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser();
dialog = new Dialog(getContext());
dialog.setContentView(R.layout.dialog_delete);
dialog.getWindow().setBackgroundDrawable(getResources().getDrawable(R.drawable.backgroun_dialog));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.setCancelable(false);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
yesFinal = dialog.findViewById(R.id.btn_okay);
cancelFinal = dialog.findViewById(R.id.btn_cancel);
titleDialog = dialog.findViewById(R.id.titleDialog);
textDialog = dialog.findViewById(R.id.textDialog);
loadingBar = view.findViewById(R.id.objectLoadingBar);
imgDialog = dialog.findViewById(R.id.imageDialog);
DocumentReference docRef = db.collection("LastIdPhotoAndQrCode").document("1");
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
Map<String, Object> data = new HashMap<>();
data = document.getData();
Iterator it = data.entrySet().iterator();
while (it.hasNext()) {
Map.Entry val = (Map.Entry) it.next();
Object g = val.getValue();
idPhotoAndQrCode = (long) g;
}
} else {
idPhotoAndQrCode = 0;
}
} else {
// Log.d(TAG, "get failed with ", task.getException());
}
}
});
for (String nameZone : zone_list) {
final View zoneView = getLayoutInflater().inflate(R.layout.row_from_zone, null, false);
TextView from_zone = (TextView) zoneView.findViewById(R.id.displayZone);
LinearLayout sub_layout_list = (LinearLayout) zoneView.findViewById(R.id.listConstraintLayout);
AutoCompleteTextView menu_zones = (AutoCompleteTextView) zoneView.findViewById(R.id.inputLinkZone);
List<String> link_list = new ArrayList<String>();
from_zone.setText(nameZone);
adapterItems = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_dropdown_item, zone_list);
menu_zones.setAdapter(adapterItems);
menu_zones.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
item = parent.getItemAtPosition(position).toString();
if (link_list.contains(item)) {
Toast.makeText(getContext(), "La zona è gia stata collegata", Toast.LENGTH_LONG).show();
menu_zones.setText(null);
} else if (item.equals(nameZone)) {
Toast.makeText(getContext(), "Una zona non è collegabile con se stessa", Toast.LENGTH_LONG).show();
menu_zones.setText(null);
} else {
final View destinationView = getLayoutInflater().inflate(R.layout.row_in_zone, null, false);
TextView in_zone = (TextView) destinationView.findViewById(R.id.displayZone);
ImageView removeZone = (ImageView) destinationView.findViewById(R.id.deleteZone);
in_zone.setText(item);
Constraint constraint = new Constraint(nameZone, item);
listConstranints.add(constraint);
link_list.add(item);
sub_layout_list.addView(destinationView);
menu_zones.setText(null);
if (!(all_link_lists.contains(link_list))) {
all_link_lists.add(link_list);
}
removeZone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(), "Vincolo eliminato", Toast.LENGTH_LONG).show();
sub_layout_list.removeView(destinationView);
name = ((TextView) destinationView.findViewById(R.id.displayZone)).getText();
link_list.remove(name);
}
});
}
}
});
layout_list.addView(zoneView);
}
return view;
}
use of com.example.alphatour.oggetti.Constraint in project AlphaTour by Frank99DG.
the class FileReceiverActivity method readCsv.
private void readCsv(Intent data) {
if (data == null) {
return;
} else {
Uri uri = data.getParcelableExtra(Intent.EXTRA_STREAM);
Toast.makeText(FileReceiverActivity.this, uri.getPath(), Toast.LENGTH_SHORT).show();
String path = uri.getPath();
String filename = URLUtil.guessFileName(path, null, null);
String downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
path = path.substring(path.lastIndexOf('/') + 1);
File file = new File(downloadPath, filename);
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(FileReceiverActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
line = null;
}
}
if (isEmpty) {
Toast.makeText(FileReceiverActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
} else {
savePlace();
saveConstraints();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (success) {
Intent intent = new Intent(FileReceiverActivity.this, DashboardActivity.class);
startActivity(intent);
progressBar.setVisibility(View.GONE);
} else {
Toast.makeText(FileReceiverActivity.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.Constraint in project AlphaTour by Frank99DG.
the class CreateConstraintsWizard method saveConstraintsLocal.
private long saveConstraintsLocal() {
AlphaTourDbHelper dbAlpha = new AlphaTourDbHelper(getContext());
SQLiteDatabase db = dbAlpha.getWritableDatabase();
ContentValues values = new ContentValues();
long newRowId = -1;
for (j = 0; j < listConstranints.size(); j++) {
Constraint constraint = listConstranints.get(j);
values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_CONSTRAINTS_FROM_ZONE, constraint.getFromZone());
values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_CONSTRAINTS_IN_ZONE, constraint.getInZone());
values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_CONSTRAINTS_LOAD, load);
newRowId = db.insert(AlphaTourContract.AlphaTourEntry.NAME_TABLE_CONSTRAINTS, AlphaTourContract.AlphaTourEntry.COLUMN_NAME_NULLABLE, values);
}
return newRowId;
}
use of com.example.alphatour.oggetti.Constraint in project AlphaTour by Frank99DG.
the class Step2 method getZones.
public void getZones() {
loadingbar.setVisibility(View.VISIBLE);
if (!receiver.isConnected()) {
}
db.collection("Zones").whereEqualTo("idUser", user.getUid()).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()) {
// lista zone
List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
if (!DashboardActivity.isFirstZoneChosen()) {
for (DocumentSnapshot d : listDocument) {
Zone zone = d.toObject(Zone.class);
if (idPlace.matches(zone.getIdPlace())) {
View zoneView = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
CheckableTextView textZone1 = (CheckableTextView) zoneView.findViewById(R.id.textObjectss);
textZone1.setText(zone.getName());
array_database.add(zone.getName());
arrayZone.add(textZone1);
list_zone.addView(zoneView);
deleteView.add(zoneView);
}
}
for (i = 0; i < arrayZone.size(); i++) {
arrayZone.get(i).setOnCheckChangeListener(new CheckedListener() {
@Override
public void onCheckChange(@NonNull View view, boolean b) {
// contatore per capire quando ne seleziona 2
int c = 0;
for (int a = 0; a < arrayZone.size(); a++) {
// ciclo per contare quanti sono checkati
if (arrayZone.get(a).isChecked()) {
c++;
}
}
for (int j = 0; j < arrayZone.size(); j++) {
// se è checkato più di uno, il precedente che è checkato viene impostato a false
if (c > 1) {
if (n == j) {
arrayZone.get(j).setChecked(false, false);
}
}
}
for (int k = 0; k < arrayZone.size(); k++) {
// serve per tenere la posizione dell'ultimo checkato
if (arrayZone.get(k).isChecked()) {
n = k;
continue;
}
}
}
});
}
} else {
db.collection("Constraints").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
List<DocumentSnapshot> listConstraint = queryDocumentSnapshots.getDocuments();
for (DocumentSnapshot d : listConstraint) {
Constraint constraint = d.toObject(Constraint.class);
String zona;
if (PercorsoWizard.isZonePassFromReview()) {
zona = PercorsoWizard.getZone();
DashboardActivity.setZona_vecchia(zona);
DashboardActivity.setZona_scelta(zona);
} else {
zona = DashboardActivity.getZona_scelta();
DashboardActivity.setZona_vecchia(zona);
}
if (constraint.getFromZone().matches(zona)) {
View zone = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
CheckableTextView textZone1 = (CheckableTextView) zone.findViewById(R.id.textObjectss);
textZone1.setText(constraint.getInZone());
array_database.add(constraint.getInZone());
arrayZone.add(textZone1);
list_zone.addView(zone);
deleteView.add(zone);
}
}
PercorsoWizard.setZonePassFromReview(false);
for (i = 0; i < arrayZone.size(); i++) {
arrayZone.get(i).setOnCheckChangeListener(new CheckedListener() {
@Override
public void onCheckChange(@NonNull View view, boolean b) {
// contatore per capire quando ne seleziona 2
int c = 0;
for (int a = 0; a < arrayZone.size(); a++) {
// ciclo per contare quanti sono checkati
if (arrayZone.get(a).isChecked()) {
c++;
}
}
for (int j = 0; j < arrayZone.size(); j++) {
// se è checkato più di uno, il precedente che è checkato viene impostato a false
if (c > 1) {
if (n == j) {
arrayZone.get(j).setChecked(false, false);
}
}
}
for (int k = 0; k < arrayZone.size(); k++) {
// serve per tenere la posizione dell'ultimo checkato
if (arrayZone.get(k).isChecked()) {
n = k;
continue;
}
}
}
});
}
}
});
}
loadingbar.setVisibility(View.GONE);
}
}
});
}
Aggregations