· 6 years ago · Jan 24, 2020, 10:16 AM
1package com.example.myapplication;
2
3import android.annotation.SuppressLint;
4import android.app.AlertDialog;
5import android.content.DialogInterface;
6import android.content.Intent;
7import android.graphics.Color;
8import android.os.Bundle;
9import android.os.Handler;
10import android.view.GestureDetector;
11import android.view.MotionEvent;
12import android.view.View;
13import android.widget.AdapterView;
14import android.widget.ArrayAdapter;
15import android.widget.Button;
16import android.widget.CalendarView;
17import android.widget.ImageButton;
18import android.widget.LinearLayout;
19import android.widget.ScrollView;
20import android.widget.Spinner;
21import android.widget.Toast;
22
23import androidx.appcompat.app.ActionBar;
24import androidx.appcompat.app.AppCompatActivity;
25
26import java.text.DateFormat;
27import java.text.SimpleDateFormat;
28import java.util.Calendar;
29import java.util.Date;
30import java.util.GregorianCalendar;
31
32public class Calendario extends AppCompatActivity {
33
34 private final Handler mHideHandler = new Handler();
35 private View mContentView;
36 private String data; //Data presa da calendario nel suo listener
37 private Spinner dropdown; //Dropdown delle ore
38 private GestureDetector mDetector;
39 private final Runnable mHidePart2Runnable = new Runnable() {
40 @SuppressLint("InlinedApi")
41 @Override
42 public void run() {
43
44 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
45 | View.SYSTEM_UI_FLAG_FULLSCREEN
46 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
47 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
48 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
49 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
50 }
51 };
52
53 @SuppressLint({"Range", "WrongConstant"})
54 @Override
55 protected void onCreate(Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);
57 setContentView(R.layout.activity_calendario);
58 hide_all();
59
60 CalendarView simpleCalendarView = (CalendarView) findViewById(R.id.simpleCalendarView); // get the reference of CalendarView
61 simpleCalendarView.setDate(System.currentTimeMillis());
62 simpleCalendarView.setMinDate(System.currentTimeMillis() - 1000);
63
64 dropdown = findViewById(R.id.spinner1);
65 String[] items = new String[]{"15-16","16-17","17-18"};
66 //create an adapter to describe how the items are displayed, adapters are used in several places in android.
67 //There are multiple variations of this, but this is the basic variant.
68 ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items);
69 //set the spinners adapter to the previously created one.
70 dropdown.setAdapter(adapter);
71
72 dropdown.setSelection(0);
73
74 data = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())+" ";
75 //Toast.makeText(getApplicationContext(),data,1000).show();
76
77 dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
78 @Override
79 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
80 hide_all();
81 }
82
83 @Override
84 public void onNothingSelected(AdapterView<?> parent) {
85 hide_all();
86 }
87 });
88
89 simpleCalendarView.setOnDateChangeListener( new CalendarView.OnDateChangeListener() {
90 @SuppressLint("WrongConstant")
91 public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
92 //this.calendar = new GregorianCalendar(year, month, dayOfMonth );
93 month++;
94 data = year+ "-"+month+"-"+dayOfMonth+" ";
95 //Toast.makeText(getApplicationContext(),year + ","+month+1+","+dayOfMonth,1000).show();
96 }//met
97 });
98
99 findViewById(R.id.btnSalvaData).setOnClickListener(new View.OnClickListener() {
100 @SuppressLint("WrongConstant")
101 @Override
102 public void onClick(View v) {
103 data += dropdown.getSelectedItem();
104 //Toast.makeText(getApplicationContext(),data,1000).show();
105 Intent in = new Intent(Calendario.this, MainActivity.class);
106 in.putExtra("Data", data);
107 startActivity(in);
108 data = "";
109 finish(); //evita che la app si ripeschi i dati
110 }
111 });
112
113 SimpleGestureListener simpleGestureListener = new SimpleGestureListener();
114 simpleGestureListener.setListener(new SimpleGestureListener.Listener() {
115 @SuppressLint("WrongConstant")
116 @Override
117 //swipe x
118 public void onScrollHorizontal(float dx) {
119 if(dx<0){
120 Intent myin=new Intent(Calendario.this, MainActivity.class);
121 startActivity(myin);
122 finish(); //evita che la app si ripeschi i dati
123 }
124
125 }
126
127 @SuppressLint("WrongConstant")
128 @Override
129 //swipe y
130 public void onScrollVertical(float dy) {
131
132 }
133 });
134
135
136 mDetector = new GestureDetector(this, simpleGestureListener);
137
138 }
139
140 /*@Override
141 public void onBackPressed() {
142 startActivity(new Intent(Calendario.this,MainActivity.class));
143 }*/
144 @Override
145 public void onBackPressed() {
146 startActivity(new Intent(Calendario.this,MainActivity.class));
147 }
148
149 @SuppressLint("WrongConstant")
150 @Override
151 public boolean onTouchEvent(MotionEvent event) {
152 mDetector.onTouchEvent(event);
153 return super.onTouchEvent(event);
154 }
155
156 public void hide_all(){
157 mContentView = findViewById(R.id.sta);
158 ActionBar actionBar = getSupportActionBar();
159 if (actionBar != null) {
160 actionBar.hide();
161 }
162 mHideHandler.postDelayed(mHidePart2Runnable, 0);
163 }
164}
165package com.example.myapplication;
166
167public class Contact {
168
169 //private variables
170 int _id;
171 String _name;
172 String _phone_number;
173
174 // Empty constructor
175 public Contact(){
176
177 }
178 // constructor
179 public Contact(int id, String name, String _phone_number){
180 this._id = id;
181 this._name = name;
182 this._phone_number = _phone_number;
183 }
184
185 // constructor
186 public Contact(String name, String _phone_number){
187 this._name = name;
188 this._phone_number = _phone_number;
189 }
190 // getting ID
191 public int getID(){
192 return this._id;
193 }
194
195 // setting id
196 public void setID(int id){
197 this._id = id;
198 }
199
200 // getting name
201 public String getName(){
202 return this._name;
203 }
204
205 // setting name
206 public void setName(String name){
207 this._name = name;
208 }
209
210 // getting phone number
211 public String getPhoneNumber(){
212 return this._phone_number;
213 }
214
215 // setting phone number
216 public void setPhoneNumber(String phone_number){
217 this._phone_number = phone_number;
218 }
219}package com.example.myapplication;
220
221import androidx.appcompat.app.ActionBar;
222import androidx.appcompat.app.AppCompatActivity;
223
224import android.animation.AnimatorInflater;
225import android.animation.AnimatorSet;
226import android.annotation.SuppressLint;
227import android.content.Intent;
228import android.os.AsyncTask;
229import android.os.Bundle;
230import android.os.Handler;
231import android.text.method.PasswordTransformationMethod;
232import android.view.MotionEvent;
233import android.view.View;
234import android.view.ViewGroup;
235import android.view.animation.Animation;
236import android.view.animation.AnimationUtils;
237import android.widget.Button;
238import android.widget.EditText;
239import android.widget.LinearLayout;
240import android.widget.Toast;
241
242import java.io.Serializable;
243import java.math.BigInteger;
244import java.nio.charset.StandardCharsets;
245import java.security.MessageDigest;
246import java.security.NoSuchAlgorithmException;
247
248public class Login extends AppCompatActivity {
249
250
251 private final Handler mHideHandler = new Handler();
252 private View mContentView;
253 private database db;
254 private final Runnable mHidePart2Runnable = new Runnable() {
255 @SuppressLint("InlinedApi")
256 @Override
257 public void run() {
258
259 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
260 | View.SYSTEM_UI_FLAG_FULLSCREEN
261 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
262 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
263 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
264 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
265 }
266 };
267
268 /**
269 * Touch listener to use for in-layout UI controls to delay hiding the
270 * system UI. This is to prevent the jarring behavior of controls going away
271 * while interacting with activity UI.
272 */
273
274
275 @Override
276 protected void onCreate(Bundle savedInstanceState) {
277 super.onCreate(savedInstanceState);
278 setContentView(R.layout.log);
279 hide_all();
280 animate(mContentView);
281
282 db = new database(this);
283 db.fillTable();
284
285 final EditText editText_usr = (EditText) findViewById(R.id.editText2);
286 final EditText editText_pwd = (EditText) findViewById(R.id.editText3);
287 final LinearLayout lin = (LinearLayout) findViewById(R.id.lay);
288 final Button bu = findViewById(R.id.button);
289
290 editText_pwd.setOnFocusChangeListener(new View.OnFocusChangeListener() {
291 @Override
292 public void onFocusChange(View view, boolean hasFocus) {
293 if (hasFocus) {
294 editText_pwd.setText("");
295 editText_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
296 }
297 }
298 });
299
300 editText_usr.setOnTouchListener(new View.OnTouchListener() {
301 @Override
302 public boolean onTouch(View v, MotionEvent event) {
303 if (editText_usr.getText().toString().equals("Username"))
304 editText_usr.getText().clear();
305 if (editText_pwd.getText().toString().isEmpty()) {
306 editText_pwd.setTransformationMethod(null);
307 editText_pwd.setText("Password");
308 }
309 return false;
310 }
311 });
312
313
314 editText_pwd.setOnTouchListener(new View.OnTouchListener() {
315 @Override
316 public boolean onTouch(View v, MotionEvent event) {
317 if (editText_pwd.getText().toString().equals("Password")) {
318 editText_pwd.getText().clear();
319 editText_pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
320 }
321 if (editText_usr.getText().toString().isEmpty())
322 editText_usr.setText("Username");
323 return false;
324 }
325 });
326
327 bu.setOnClickListener(new View.OnClickListener() {
328 @SuppressLint("WrongConstant")
329 @Override
330 public void onClick(View v) {
331 Utente usr = db.getUtente(editText_usr.getText().toString());
332 try {
333 if(usr != null && toHexString(getSHA(editText_pwd.getText().toString())).compareTo(usr.getPasswd()) == 0){
334 Intent in = new Intent(Login.this, MainActivity.class);
335 db.close();
336 in.putExtra("Email", usr.getEmail());
337 startActivity(in);
338 finish(); //evita che la app si ripeschi i dati
339 }else{
340 Toast.makeText(getApplicationContext(),"Credenziali errate!", Toast.LENGTH_SHORT).show();
341 }
342 } catch (NoSuchAlgorithmException e) {
343 e.printStackTrace();
344 }
345 }
346 });
347 }
348
349 public static byte[] getSHA(String input) throws NoSuchAlgorithmException
350 {
351 // Static getInstance method is called with hashing SHA
352 MessageDigest md = MessageDigest.getInstance("SHA-256");
353
354 // digest() method called
355 // to calculate message digest of an input
356 // and return array of byte
357 return md.digest(input.getBytes(StandardCharsets.UTF_8));
358 }
359
360 public static String toHexString(byte[] hash)
361 {
362 // Convert byte array into signum representation
363 BigInteger number = new BigInteger(1, hash);
364
365 // Convert message digest into hex value
366 StringBuilder hexString = new StringBuilder(number.toString(16));
367
368 // Pad with leading zeros
369 while (hexString.length() < 32)
370 {
371 hexString.insert(0, '0');
372 }
373
374 return hexString.toString();
375 }
376
377 public void animate(View view){
378 Animation animation= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.anim);
379 findViewById(R.id.lay).startAnimation(animation);
380 }
381
382 @Override
383 protected void onPostCreate(Bundle savedInstanceState) {
384 super.onPostCreate(savedInstanceState);
385 //hide();
386 }
387
388 @Override
389 protected void onRestart() {
390 super.onRestart();
391 hide_all();
392 }
393
394 public void hide_all(){
395 mContentView = findViewById(R.id.sta);
396 ActionBar actionBar = getSupportActionBar();
397 if (actionBar != null) {
398 actionBar.hide();
399 }
400 mHideHandler.postDelayed(mHidePart2Runnable, 0);
401 }
402
403
404
405}
406package com.example.myapplication;
407
408import androidx.appcompat.app.ActionBar;
409import androidx.appcompat.app.AppCompatActivity;
410
411import android.annotation.SuppressLint;
412import android.app.AlertDialog;
413import android.content.DialogInterface;
414import android.content.Intent;
415import android.graphics.Color;
416import android.graphics.drawable.Drawable;
417import android.graphics.drawable.GradientDrawable;
418import android.os.AsyncTask;
419import android.os.Bundle;
420import android.os.Handler;
421import android.view.GestureDetector;
422import android.view.Gravity;
423import android.view.MotionEvent;
424import android.view.View;
425import android.view.ViewGroup;
426import android.widget.Button;
427import android.widget.ImageButton;
428import android.widget.TextView;
429import android.widget.Toast;
430
431import java.io.DataInput;
432import java.io.Serializable;
433import java.sql.DatabaseMetaData;
434
435import static java.lang.Thread.sleep;
436//Mando a settings: email
437public class MainActivity extends AppCompatActivity {
438
439 //handler per le gesture
440 private final Handler mHideHandler = new Handler();
441 private GestureDetector mDetector;
442 //usato per il fullscren ottengo il costraint layout (il "div" piu' grande)
443 private View mContentView;
444 //boolean per uscire dal while del blink del testo dopo il touch
445 private boolean leftButtonDown=false;
446 TextView text1;
447 private boolean terminate=true;
448
449 //Static messo per mantenere in memoria statica i valori passati tra Activity altrimenti
450 //"cancellati" --> sovrascritti con null al ritorni nella Main (cioè ad ogni intent)
451 private static String nomeUtente;
452 private static String emailUtente;
453 private static String dataPrenotazione = null;
454 private static String nomeMateria = null;
455 private static String professore = null;
456 private static Button save;
457 private AlertDialog.Builder alertDialogBuilder;
458 private int cntIstructions = 0; //Conta a che numero di istruzione siamo arrivati (1),(2),(3)
459
460 private database db;
461 //sett fullscreen
462 private final Runnable mHidePart2Runnable = new Runnable() {
463 @SuppressLint("InlinedApi")
464 @Override
465 public void run() {
466
467 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
468 | View.SYSTEM_UI_FLAG_FULLSCREEN
469 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
470 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
471 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
472 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
473 }
474 };
475
476 /**
477 * Touch listener to use for in-layout UI controls to delay hiding the
478 * system UI. This is to prevent the jarring behavior of controls going away
479 * while interacting with activity UI.
480 */
481
482 @Override
483 protected void onCreate(Bundle savedInstanceState) {
484 super.onCreate(savedInstanceState);
485 setContentView(R.layout.activity_main);
486 hide_all(); //fullscreen
487 db = new database(this);
488 //db.fillTable();
489 Bundle exr = getIntent().getExtras();
490 final Button clickButtonSett = (Button) findViewById(R.id.bsett);
491 final Button clickButtonMat = (Button) findViewById(R.id.bm);
492 final Button clickButtonProf = (Button) findViewById(R.id.bprof);
493 final Button save = (Button) findViewById(R.id.Save);
494
495 final TextView textSett = (TextView) findViewById(R.id.textView);
496 final TextView textMat = (TextView) findViewById(R.id.textView2);
497 final TextView textProf = (TextView) findViewById(R.id.textView3);
498
499 final ImageButton setting = (ImageButton) findViewById(R.id.sett);
500 final TextView lblSettimana = (TextView)findViewById(R.id.txtSettimana);
501 final TextView lblMateria = (TextView)findViewById(R.id.txtMateria);
502 final TextView lblProfessore = (TextView)findViewById(R.id.txtProfessore);
503
504 //modificata con la login
505 if (exr != null) {
506 switch ((String) exr.keySet().toArray()[0]){
507 case "Email":
508 emailUtente = exr.getString("Email");
509 nomeUtente=db.getUtente(emailUtente).getNome();
510 break;
511 case "Data":
512 dataPrenotazione = exr.getString("Data");
513 break;
514 case "Materia":
515 nomeMateria = exr.getString("Materia");
516 break;
517 case "Prof":
518 professore = exr.getString("Prof");
519 break;
520 default:
521 Toast.makeText(getApplicationContext(),((String) exr.keySet().toArray()[0]), Toast.LENGTH_SHORT).show();
522 }
523 }
524
525 //Ogni oncreate prova a settare i campi, se non trova nulla lo mette vuoto
526 lblMateria.setText(nomeMateria);
527 lblSettimana.setText(dataPrenotazione);
528 lblProfessore.setText(professore);
529
530
531 //Controllo se è il primo accesso
532 if(db.getAccessFromUtente(emailUtente).compareTo("0") == 0) {
533 printIstruction();
534 db.updateAccesses(emailUtente);
535 }
536
537
538 /*Intent intent = getIntent();
539 finish();
540 startActivity(intent);*/
541
542
543 //bottone per prenotazione fatte
544 (findViewById(R.id.buttonp)).setOnClickListener(new View.OnClickListener() {
545 @Override
546 public void onClick(View v) {
547 Intent in= new Intent(MainActivity.this, Prob.class);
548 in.putExtra("NomeUtente", emailUtente);
549 db.close();
550 startActivity(in);
551 finish(); //evita che la app si ripeschi i dati
552 }
553 });
554
555
556 save.setOnClickListener(new View.OnClickListener() {
557 @SuppressLint("WrongConstant")
558 @Override
559 public void onClick(View v) {
560 //Se ha gia una prenotazione in quella data viene bloccato
561 if(db.getPrenotazioniFromUtenteAndData(emailUtente,dataPrenotazione) == null) {
562 db.addPrenotazione(dataPrenotazione, professore.split(" ")[1], professore.split(" ")[0], nomeMateria, emailUtente, "n");
563 dataPrenotazione = null;
564 nomeMateria = null;
565 professore = null;
566 lblMateria.setText("");
567 lblProfessore.setText("");
568 lblSettimana.setText("");
569 Toast.makeText(getApplicationContext(), "prentazione avvenuta", 100).show();
570 save.setVisibility(View.INVISIBLE );
571 }else
572 Toast.makeText(getApplicationContext(), "Prenotazione gia presente in quella data", 100).show();
573 }
574 });
575
576 //Mostra btn salva solo se inserita Data,Materia e Professore
577 if(dataPrenotazione!=null && dataPrenotazione!=null && professore!=null)
578 save.setVisibility(View.VISIBLE);
579 else
580 save.setVisibility(View.INVISIBLE);
581
582 View.OnTouchListener c1 = null;
583 //btn circolare del piu' (settimama)
584
585 //di default il listener e' un lambda expression perche mette una new nelle parentesi
586 //allora ho separato le cose mettendo il codice che avevo inserito
587 // nella new in una View a parte
588 c1= new View.OnTouchListener() {
589 @SuppressLint({"WrongConstant", "ResourceType"})
590 public boolean onTouch(View v, MotionEvent event) {
591 switch (event.getAction()) {
592 case MotionEvent.ACTION_DOWN: //pres
593 leftButtonDown = true;
594 if(v.getResources().getResourceEntryName(v.getId()).compareTo("bsett")==0)
595 text1=textSett; //chiamo in modo asincrono per il blink
596 else if(v.getResources().getResourceEntryName(v.getId()).compareTo("bm")==0)
597 text1=textMat; //chiamo in modo asincrono per il blink
598 else
599 text1=textProf; //chiamo in modo asincrono per il blink
600 startTask();
601 leftButtonDown = true;
602
603 break;
604 case MotionEvent.ACTION_UP: //relese
605 leftButtonDown = false;
606 if(v.getResources().getResourceEntryName(v.getId()).compareTo("bsett")==0)
607 textSett.setTextColor(textSett.getTextColors().withAlpha(250)); //opacity massima
608 else if(v.getResources().getResourceEntryName(v.getId()).compareTo("bm")==0)
609 textMat.setTextColor(textMat.getTextColors().withAlpha(250)); //opacity massima
610 else
611 textProf.setTextColor(textProf.getTextColors().withAlpha(250)); //opacity massima
612 break;
613
614 default:
615 break;
616 }
617 return false;
618 }
619
620
621 //fa blinkare il testo
622 public void startTask() {
623 try {
624 AsyncTask asyncTask = new AsyncTask<Void, Void, Void>() {
625
626 @SuppressLint("WrongThread")
627 @Override
628 protected Void doInBackground(Void... params) {
629 int i = 254;
630 while (leftButtonDown) {
631 if (i >= 254 && leftButtonDown)
632 while (i > 60 && leftButtonDown) {
633 text1.setTextColor(text1.getTextColors().withAlpha(i--));
634 try {
635 Thread.sleep(2);
636 } catch (InterruptedException e) {
637 e.printStackTrace();
638 }
639 }
640 else
641 while (i < 254 && leftButtonDown) {
642 text1.setTextColor(text1.getTextColors().withAlpha(i++));
643 try {
644 Thread.sleep(8);
645 } catch (InterruptedException e) {
646 e.printStackTrace();
647 }
648 }
649 }
650 return null;
651 }
652
653 }.execute();
654 }catch (Exception e) {}
655 }
656
657 };
658
659 clickButtonSett.setOnTouchListener(c1);
660 clickButtonMat.setOnTouchListener(c1);
661 clickButtonProf.setOnTouchListener(c1);
662
663
664 //quando premo btn setting una volte
665 setting.setOnClickListener(new View.OnClickListener() {
666 @SuppressLint("WrongConstant")
667 @Override
668 public void onClick(View v) {
669 Intent in= new Intent(MainActivity.this, Setting.class);
670 in.putExtra("Email", emailUtente);
671 db.close();
672 startActivity(in);
673 finish(); //evita che la app si ripeschi i dati
674 }
675 });
676
677 //quando premo btn setting tanto
678 setting.setOnLongClickListener(new View.OnLongClickListener() {
679 @SuppressLint("WrongConstant")
680 @Override
681 public boolean onLongClick(View v) {
682 Integer p=Integer.parseInt(db.getUtente(emailUtente).getPref());
683 if(p==0){
684 finishAffinity(); //se non lo messo non torna al log
685 android.os.Process.killProcess(android.os.Process.myPid());
686 System.exit(1);
687 }
688 else if(p==1){
689 startActivity(new Intent(MainActivity.this, Login.class));
690 }
691 return true;
692 }
693 });
694
695 //quando premo il piu" (settimana)
696 clickButtonSett.setOnClickListener( new View.OnClickListener() {
697
698 @Override
699 public void onClick(View v) {
700 Intent in= new Intent(MainActivity.this, Calendario.class);
701 startActivity(in);
702 }
703 });
704
705 clickButtonMat.setOnClickListener( new View.OnClickListener() {
706
707 @Override
708 public void onClick(View v) {
709 db.close();
710 Intent it= new Intent(MainActivity.this, Select.class);
711 startActivity(it);
712 }
713 });
714
715 clickButtonProf.setOnClickListener( new View.OnClickListener() {
716 @Override
717 public void onClick(View v) {
718 db.close();
719 Intent it= new Intent(MainActivity.this, ProfActivity.class);
720 it.putExtra("Data", dataPrenotazione);
721 it.putExtra("Materia", nomeMateria);
722 startActivity(it);
723 }
724 });
725
726 //per le gesture (vedi SimpleGetsureListener)
727 SimpleGestureListener simpleGestureListener = new SimpleGestureListener();
728 simpleGestureListener.setListener(new SimpleGestureListener.Listener() {
729 @SuppressLint("WrongConstant")
730 @Override
731 //swipe x
732 public void onScrollHorizontal(float dx) {
733 if(dx>0){
734 Intent in= new Intent(MainActivity.this, Prob.class);
735 in.putExtra("NomeUtente", emailUtente);
736 db.close();
737 startActivity(in);
738 finish(); //evita che la app si ripeschi i dati
739 }
740 }
741
742 @SuppressLint("WrongConstant")
743 @Override
744 //swipe y
745 public void onScrollVertical(float dy) {
746 if(terminate==true)
747 //uscita
748 onBackPressed();
749 }
750 });
751
752 mDetector = new GestureDetector(this, simpleGestureListener);
753 }
754
755 public void printIstruction(){
756 alertDialogBuilder = new AlertDialog.Builder(this, R.style.CustomDialogTheme);
757 TextView title = new TextView(this);
758 TextView myMsg = new TextView(this);
759 if(cntIstructions==0) {
760 myMsg.setText("\nMagister e' la nuova ed innovativa applicazione per dispositivi Android " +
761 "che ti consente di gestire al meglio le prenotazioni dei recuperi di tutte le tue materie.\n\n(1) 2 3");
762 title.setText("Benvenuto in Magister");
763
764 }else if(cntIstructions==1) {
765 myMsg.setText("\nMagister offre la possibilita' di effettuare e gestire prenotazioni in base alla data, alla materia ed al professore. E' inoltre possibile modificare le impostazioni a piacere.\n\n1 (2) 3");
766 title.setText("Come posso usare Magister?");
767 }
768 else if(cntIstructions==2) {
769 myMsg.setText("\nMagister offre l'oppurtunita' di muoversi tra le pagine mediante il " +
770 "bottone indietro oppure con gli swipe verso sinistra e destra applicabili nella parte bassa dello schermo.\n\n1 2 (3)");
771 title.setText("Come posso muovermi in Magister?");
772 }
773
774
775 title.setBackgroundColor(Color.DKGRAY);
776 title.setPadding(10, 10, 10, 10);
777 title.setGravity(Gravity.CENTER);
778 title.setTextColor(Color.parseColor("#ff8b00"));
779 title.setTextSize(20);
780 myMsg.setGravity(Gravity.CENTER);
781 myMsg.setPadding(20, 10, 20, 10);
782 myMsg.setTextSize(18);
783 alertDialogBuilder.setView(myMsg);
784 alertDialogBuilder.setCustomTitle(title);
785
786 alertDialogBuilder
787 .setCancelable(false)
788 .setPositiveButton("avanti",
789 new DialogInterface.OnClickListener() {
790 public void onClick(DialogInterface dialog, int id) {
791 if(cntIstructions++!=2)
792 printIstruction();
793 //else
794 //pj();
795 /*finishAffinity(); //se non lo messo non torna al log
796 android.os.Process.killProcess(android.os.Process.myPid());
797 System.exit(1);*/
798
799 }
800 });
801
802
803
804 AlertDialog dialog = alertDialogBuilder.create();
805 dialog.getWindow().getAttributes().windowAnimations = R.style.DialogTheme;
806 dialog.show();
807 }
808
809 /*public void pj(){
810 final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.CustomDialogTheme);
811 TextView title = new TextView(this);
812 title.setText("Benvenuto in Magister");
813 title.setBackgroundColor(Color.DKGRAY);
814 title.setPadding(10, 10, 10, 10);
815 title.setGravity(Gravity.CENTER);
816 title.setTextColor(Color.parseColor("#FF6a00"));
817 alertDialogBuilder.setCancelable(false);
818 title.setTextSize(20);
819 alertDialogBuilder.setCustomTitle(title);
820 final AlertDialog alert= alertDialogBuilder.create();
821 alert.show();
822 final Handler handler = new Handler();
823 final Runnable runnable = new Runnable() {
824 @Override
825 public void run() {
826 if (alert.isShowing()) {
827 alert.dismiss();
828 }
829 }
830 };
831
832 alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
833 @Override
834 public void onDismiss(DialogInterface dialog) {
835 handler.removeCallbacks(runnable);
836 }
837 });
838
839 handler.postDelayed(runnable, 2000);
840 }*/
841
842 //finestra alert conferma uscita
843 @Override
844 public void onBackPressed() {
845 terminate=false; //per evitare molte finestre sovrapposte
846 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.CustomDialogTheme);
847 alertDialogBuilder.setTitle("Sei sicuro di voler uscire?");
848 alertDialogBuilder
849 .setMessage("Premi si per uscire!")
850 .setCancelable(false)
851 .setPositiveButton("Si",
852 new DialogInterface.OnClickListener() {
853 public void onClick(DialogInterface dialog, int id) {
854 finishAffinity(); //se non lo messo non torna al log
855 android.os.Process.killProcess(android.os.Process.myPid());
856 System.exit(1);
857
858 }
859 })
860
861 .setNegativeButton("No", new DialogInterface.OnClickListener() {
862 public void onClick(DialogInterface dialog, int id) {
863 terminate=true;
864 dialog.cancel();
865 }
866 });
867
868 AlertDialog alertDialog = alertDialogBuilder.create();
869 alertDialog.show();
870 }
871
872 @Override
873 protected void onPostCreate(Bundle savedInstanceState) {
874 super.onPostCreate(savedInstanceState);
875 //hide();
876 }
877
878 //gesture
879 @Override
880 public boolean onTouchEvent(MotionEvent event) {
881 mDetector.onTouchEvent(event);
882 return super.onTouchEvent(event);
883 }
884 @Override
885 protected void onRestart() {
886 super.onRestart();
887 hide_all();
888 }
889
890 //fullscreen
891 public void hide_all(){
892 mContentView = findViewById(R.id.sta);
893 ActionBar actionBar = getSupportActionBar();
894 if (actionBar != null) {
895 actionBar.hide();
896 }
897 mHideHandler.postDelayed(mHidePart2Runnable, 0);
898 }
899}
900package com.example.myapplication;
901
902public class Materia {
903 private String nome;
904
905 public Materia(String n){
906 this.nome = n;
907 }
908
909 public String getNome(){return this.nome;}
910 public void setNome(String n){this.nome = n;}
911}
912
913package com.example.myapplication;
914
915public class Prenotazione {
916 private String nomeUtente;
917 private String nomeProfessore;
918 private String cognomeProfessore;
919 private String nomeMateria;
920 private String data;
921 private String disdetta;
922
923 public Prenotazione(String data,String nomeProfessore,String cognomeProfessore, String nomeMateria, String nomeUtente,String disdetta){
924 this.nomeUtente = nomeUtente;
925 this.nomeProfessore = nomeProfessore;
926 this.cognomeProfessore = cognomeProfessore;
927 this.nomeMateria = nomeMateria;
928 this.data = data;
929 this.disdetta = disdetta;
930 }
931
932 public String getnomeUtente(){
933 return this.nomeUtente;
934 }
935
936 public void setnomeUtente(String nomeutente){
937 this.nomeUtente=nomeutente;
938 }
939
940 public String getnomeProfessore(){
941 return this.nomeProfessore;
942 }
943 public String getDisdetta(){
944 return this.disdetta;
945 }
946
947 public void setnomeProfessore(String nomeprofessore){
948 this.nomeProfessore=nomeprofessore;
949 }
950
951 public String getcognomeProfessore(){
952 return this.cognomeProfessore;
953 }
954
955 public void setcognomeProfessore(String cognomeprofessore){
956 this.cognomeProfessore=cognomeprofessore;
957 }
958
959 public String getnomeMateria(){
960 return this.nomeMateria;
961 }
962
963 public void setnomeMateria(String nomemateria){
964 this.nomeMateria=nomemateria;
965 }
966
967 public String getdata(){
968 return this.data;
969 }
970
971 public void setdata(String data){
972 this.data=data;
973 }
974 public void setDisdetta(String risp){
975 this.disdetta=risp;
976 }
977}
978package com.example.myapplication;
979
980import androidx.activity.OnBackPressedDispatcherOwner;
981import androidx.appcompat.app.ActionBar;
982import androidx.appcompat.app.AppCompatActivity;
983
984import android.annotation.SuppressLint;
985import android.content.Intent;
986import android.graphics.Color;
987import android.graphics.drawable.ColorDrawable;
988import android.graphics.drawable.Drawable;
989import android.graphics.drawable.GradientDrawable;
990import android.os.Bundle;
991import android.os.Handler;
992import android.util.Log;
993import android.view.GestureDetector;
994import android.view.MotionEvent;
995import android.view.View;
996import android.view.ViewTreeObserver;
997import android.view.animation.Animation;
998import android.view.animation.AnimationUtils;
999import android.widget.Button;
1000import android.widget.ImageButton;
1001import android.widget.LinearLayout;
1002import android.widget.ScrollView;
1003import android.widget.TextView;
1004import android.widget.Toast;
1005
1006import java.sql.DatabaseMetaData;
1007import java.text.SimpleDateFormat;
1008import java.util.ArrayList;
1009import java.util.Calendar;
1010
1011/*
1012* Prendere tutte le prenotazioni dell'utente
1013* Per tutti quelli con disdetta = s --> Disabilito e scrivo Disdetta
1014* Per tutti quelli che disdetta = n DataOdierna > data --> Disabilito e scrivo Effettuata
1015* Per tutti quelli che disdetta = n DAtaOdierna < data --> Lascio abilitato e scrivo Attiva
1016* */
1017public class Prob extends AppCompatActivity {
1018
1019 private final Handler mHideHandler = new Handler();
1020 private GestureDetector mDetector;
1021 private View mContentView;
1022 private Button current;
1023 private String text="";
1024 private boolean isSpeakButtonLongPressed=false;
1025 private String nomeUtente;
1026 private database db;
1027
1028 private final Runnable mHidePart2Runnable = new Runnable() {
1029 @SuppressLint("InlinedApi")
1030 @Override
1031 public void run() {
1032
1033 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
1034 | View.SYSTEM_UI_FLAG_FULLSCREEN
1035 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1036 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
1037 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1038 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
1039 }
1040 };
1041
1042 private static int count=0;
1043 private Button [] bu;
1044
1045 @SuppressLint("Range")
1046 @Override
1047 protected void onCreate(Bundle savedInstanceState) {
1048 super.onCreate(savedInstanceState);
1049 setContentView(R.layout.activity_prob);
1050 hide_all();
1051
1052 Bundle exr = getIntent().getExtras();
1053 if (exr != null) {
1054 nomeUtente = exr.getString("NomeUtente");
1055 //Toast.makeText(getApplicationContext(),"Nome " + nomeUtente, Toast.LENGTH_SHORT).show();
1056 }
1057
1058 SimpleGestureListener simpleGestureListener = new SimpleGestureListener();
1059 simpleGestureListener.setListener(new SimpleGestureListener.Listener() {
1060 @SuppressLint("WrongConstant")
1061 @Override
1062 public void onScrollHorizontal(float dx) {
1063 if (dx < 0) {
1064 Intent ie = new Intent(Prob.this, MainActivity.class);
1065 startActivity(ie);
1066 }
1067 }
1068
1069 @Override
1070 public void onScrollVertical(float dy) {
1071
1072 }
1073 });
1074
1075 (findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() {
1076 @Override
1077 public void onClick(View v) {
1078 Intent in = new Intent(Prob.this, MainActivity.class);
1079 startActivity(in);
1080 }
1081 });
1082
1083 LinearLayout rl=(LinearLayout) findViewById(R.id.rl);
1084 final ImageButton tr= findViewById(R.id.sett);
1085
1086 ScrollView sv = new ScrollView(this);
1087 sv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
1088 final LinearLayout ll = new LinearLayout(this);
1089 ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
1090 ll.setOrientation(LinearLayout.VERTICAL);
1091 sv.addView(ll);
1092
1093 db = new database(this);
1094 ArrayList<Prenotazione> listPrenotazioni = db.getPrenotazioniFromUtente(nomeUtente);
1095 if(listPrenotazioni != null) {
1096 bu= new Button[listPrenotazioni.size()]; //Setto n bottoni dinamici in base al numero di prenotazioni
1097 //Toast.makeText(getApplicationContext(), String.valueOf(listPrenotazioni.size()), Toast.LENGTH_SHORT).show();
1098 String dataNow = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
1099 //Toast.makeText(getApplicationContext(),listPrenotazioni.get(0).getdata() + " -- " + dataNow , Toast.LENGTH_SHORT).show();
1100
1101 for(int i = 0; i < listPrenotazioni.size(); i++) {
1102 final Button b = new Button(this);
1103 bu[i] = b;
1104 String txtBtn = listPrenotazioni.get(i).getdata()+"\n"+
1105 listPrenotazioni.get(i).getnomeMateria()+"\n"+
1106 listPrenotazioni.get(i).getnomeProfessore()+" "+
1107 listPrenotazioni.get(i).getcognomeProfessore();
1108 if(listPrenotazioni.get(i).getDisdetta().compareTo("n") == 0){
1109 //Non c'è stat disdetta
1110 if(dataNow.compareTo(listPrenotazioni.get(i).getdata().split(" ")[0]) > 0) {
1111 txtBtn += "\nTerminata";
1112 b.setEnabled(false);
1113 }else
1114 txtBtn += "\nAttiva";
1115
1116 }else{
1117 txtBtn += "\nDisdetta";
1118 b.setEnabled(false);
1119 }
1120 b.setText(txtBtn);
1121 b.setAlpha(254);
1122 b.setShadowLayer(4, -10, 10, Color.LTGRAY);
1123 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
1124 LinearLayout.LayoutParams.MATCH_PARENT,
1125 LinearLayout.LayoutParams.WRAP_CONTENT
1126 );
1127
1128 if (i == 0) {
1129 params.setMargins(30, 120, 30, 0);
1130 b.setLayoutParams(params);
1131 } else {
1132 params.setMargins(30, 40, 30, 0);
1133 b.setLayoutParams(params);
1134 }
1135
1136 b.setBackgroundResource(R.drawable.btn);
1137 //b.setEnabled(false);
1138
1139 b.setOnClickListener(new View.OnClickListener() {
1140 @SuppressLint({"WrongConstant", "Range"})
1141 @Override
1142 public void onClick(View v) {
1143 if (!isSpeakButtonLongPressed) {
1144 if (b.getAlpha() == 254) {
1145 count++;
1146 b.setBackgroundResource(R.drawable.btn_sel);
1147 b.setAlpha(252);
1148 tr.setVisibility(1);
1149 //Toast.makeText(getApplicationContext(), b.getText(), Toast.LENGTH_SHORT).show();
1150 } else {
1151 count--;
1152 b.setBackgroundResource(R.drawable.btn);
1153 b.setAlpha(254);
1154 if (count == 0) {
1155 tr.setVisibility(tr.INVISIBLE);
1156 }
1157 }
1158 } else {
1159 b.setText(text);
1160 isSpeakButtonLongPressed = false;
1161 }
1162 }
1163 });
1164 ll.addView(b);
1165 }
1166
1167 //lo uso per far tornare il testo normale sul long press perche se premo sposto
1168 //e levo il dito il testo rimane invece se sposto allora si muovo rl e cambio
1169 //non funziona
1170 /*rl.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
1171 @Override
1172 public void onScrollChanged() {
1173 if(isSpeakButtonLongPressed)
1174 current.setText(text);
1175 }
1176 });*/
1177
1178 /*b.setOnLongClickListener(new View.OnLongClickListener() {
1179 @Override
1180 public boolean onLongClick(View v) {
1181 text= (String) b.getText();
1182 b.setText("rfngrigrgn");
1183 isSpeakButtonLongPressed = true;
1184 current=b;
1185 return false;
1186 }
1187 });*/
1188
1189 }else{
1190 //Capita quando non ci sono prenotazione dell'utente immesso
1191 TextView txtNoPrenotazioni = (TextView)findViewById(R.id.noPrenotazioni);
1192 txtNoPrenotazioni.setText("Non ci sono prenotazioni");
1193 }
1194
1195 mDetector = new GestureDetector(this, simpleGestureListener);
1196
1197 rl.addView(sv);
1198
1199
1200 tr.setOnClickListener(new View.OnClickListener() {
1201 @SuppressLint("WrongConstant")
1202 @Override
1203 public void onClick(View v) {
1204 for(Button p : bu){
1205 if(p.getAlpha()==252) {
1206 deletePrenotazione(p);
1207 //Setto btn a disabled
1208 //ll.removeView(p);
1209 p.setEnabled(false);
1210 }
1211 }
1212 count=0;
1213 tr.setVisibility(tr.INVISIBLE);
1214 //Toast.makeText(getApplicationContext(),"prenotazioni eliminate", 100).show();
1215 }
1216 });
1217 }
1218
1219 @Override
1220 public void onBackPressed() {
1221 startActivity(new Intent(Prob.this,MainActivity.class));
1222 }
1223
1224 @SuppressLint("WrongConstant")
1225 @Override
1226 public boolean onTouchEvent(MotionEvent event) {
1227 mDetector.onTouchEvent(event);
1228 return super.onTouchEvent(event);
1229 }
1230
1231 public void hide_all(){
1232 mContentView = findViewById(R.id.sta);
1233 ActionBar actionBar = getSupportActionBar();
1234 if (actionBar != null) {
1235 actionBar.hide();
1236 }
1237 mHideHandler.postDelayed(mHidePart2Runnable, 0);
1238 }
1239
1240 //Non devo eliminare ma mettere a Disdetta = "s"
1241 @SuppressLint("WrongConstant")
1242 public void deletePrenotazione(Button btn){
1243 String arr[] = btn.getText().toString().split("\n");
1244 //Log.d("sss",arr[0]+" "+arr[2].split(" ")[0]);
1245 db.updatePrenotazione(arr[0],nomeUtente,arr[2].split(" ")[0],arr[2].split(" ")[1]);
1246 btn.setText(arr[0]+"\n"+arr[1]+"\n"+arr[2]+"\nDISDETTA");
1247 }
1248}
1249package com.example.myapplication;
1250
1251import android.annotation.SuppressLint;
1252import android.content.Intent;
1253import android.graphics.Color;
1254import android.os.Bundle;
1255import android.os.Handler;
1256import android.view.GestureDetector;
1257import android.view.MotionEvent;
1258import android.view.View;
1259import android.widget.Button;
1260import android.widget.ImageButton;
1261import android.widget.LinearLayout;
1262import android.widget.ScrollView;
1263import android.widget.TextView;
1264import android.widget.Toast;
1265
1266import androidx.appcompat.app.ActionBar;
1267import androidx.appcompat.app.AppCompatActivity;
1268
1269import java.util.ArrayList;
1270
1271public class ProfActivity extends AppCompatActivity {
1272
1273 private final Handler mHideHandler = new Handler();
1274 private GestureDetector mDetector;
1275 private View mContentView;
1276 private database db;
1277 private String data;
1278 private String materia;
1279 private final Runnable mHidePart2Runnable = new Runnable() {
1280 @SuppressLint("InlinedApi")
1281 @Override
1282 public void run() {
1283
1284 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
1285 | View.SYSTEM_UI_FLAG_FULLSCREEN
1286 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1287 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
1288 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1289 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
1290 }
1291 };
1292
1293 @SuppressLint({"Range", "WrongConstant"})
1294 @Override
1295 protected void onCreate(Bundle savedInstanceState) {
1296 super.onCreate(savedInstanceState);
1297 setContentView(R.layout.activity_select);
1298 hide_all();
1299 db = new database(this);
1300
1301 Bundle exr = getIntent().getExtras();
1302 if (exr != null) {
1303 data = exr.getString("Data");
1304 //Toast.makeText(getApplicationContext(),data,100).show();
1305 materia = exr.getString("Materia");
1306 }
1307
1308 SimpleGestureListener simpleGestureListener = new SimpleGestureListener();
1309 simpleGestureListener.setListener(new SimpleGestureListener.Listener() {
1310 @SuppressLint("WrongConstant")
1311 @Override
1312 public void onScrollHorizontal(float dx) {
1313 if (dx < 0) {
1314 Intent ie = new Intent(ProfActivity.this, MainActivity.class);
1315 startActivity(ie);
1316 }
1317
1318 }
1319
1320 @Override
1321 public void onScrollVertical(float dy) {
1322
1323 }
1324 });
1325
1326
1327 LinearLayout rl=(LinearLayout) findViewById(R.id.rl);
1328 final ImageButton tr= findViewById(R.id.sett);
1329
1330 TextView lblTitle = (TextView)findViewById(R.id.titleActivity);
1331 lblTitle.setText("Elenco professori");
1332
1333
1334 ScrollView sv = new ScrollView(this);
1335 sv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
1336 final LinearLayout ll = new LinearLayout(this);
1337 ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
1338 ll.setOrientation(LinearLayout.VERTICAL);
1339 sv.addView(ll);
1340 ArrayList<Professore> prof= db.getProfessoriDisponibili(materia,data);
1341 //Toast.makeText(getApplicationContext(),db.ok(materia,data),100).show();
1342 mDetector = new GestureDetector(this, simpleGestureListener);
1343 rl.addView(sv);
1344 TextView lblNoProf = (TextView)findViewById(R.id.noProfLbl);
1345 lblNoProf.setVisibility(View.INVISIBLE);
1346 if (prof==null) {
1347 lblNoProf.setText("Nessun professore disponibile");
1348 lblNoProf.setVisibility(View.VISIBLE);
1349 return;
1350 }
1351 lblNoProf.setVisibility(View.INVISIBLE);
1352 for(int i = 0; i < prof.size(); i++){
1353 final Button b = new Button(this);
1354 b.setText(prof.get(i).getCognome()+" "+prof.get(i).getNome());
1355 b.setTextColor(Color.BLACK);
1356 b.setAlpha(254);
1357 b.setShadowLayer(4, -10, 10, Color.LTGRAY);
1358 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
1359 LinearLayout.LayoutParams.MATCH_PARENT,
1360 LinearLayout.LayoutParams.WRAP_CONTENT
1361 );
1362 if(i == 0){
1363 params.setMargins(30, 120, 30, 0);
1364 b.setLayoutParams(params);
1365 }else{
1366 params.setMargins(30, 40, 30, 0);
1367 b.setLayoutParams(params);
1368 }
1369
1370 b.setBackgroundResource(R.drawable.btn);
1371
1372 b.setOnClickListener(new View.OnClickListener() {
1373 @SuppressLint({"WrongConstant", "Range"})
1374 @Override
1375 public void onClick(View v) {
1376 Intent it= new Intent(ProfActivity.this, MainActivity.class);
1377 it.putExtra("Prof", b.getText());
1378 startActivity(it);
1379 }
1380 });
1381
1382 //lo uso per far tornare il testo normale sul long press perche se premo sposto
1383 //e levo il dito il testo rimane invece se sposto allora si muovo rl e cambio
1384 //non funziona
1385 /*rl.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
1386 @Override
1387 public void onScrollChanged() {
1388 if(isSpeakButtonLongPressed)
1389 current.setText(text);
1390 }
1391 });*/
1392
1393 /*b.setOnLongClickListener(new View.OnLongClickListener() {
1394 @Override
1395 public boolean onLongClick(View v) {
1396 text= (String) b.getText();
1397 b.setText("rfngrigrgn");
1398 isSpeakButtonLongPressed = true;
1399 current=b;
1400 return false;
1401 }
1402 });*/
1403
1404 ll.addView(b);
1405 }
1406
1407 }
1408
1409 @Override
1410 public void onBackPressed() {
1411 startActivity(new Intent(ProfActivity.this,MainActivity.class));
1412 }
1413
1414 @SuppressLint("WrongConstant")
1415 @Override
1416 public boolean onTouchEvent(MotionEvent event) {
1417 mDetector.onTouchEvent(event);
1418 return super.onTouchEvent(event);
1419 }
1420
1421 public void hide_all(){
1422 mContentView = findViewById(R.id.sta);
1423 ActionBar actionBar = getSupportActionBar();
1424 if (actionBar != null) {
1425 actionBar.hide();
1426 }
1427 mHideHandler.postDelayed(mHidePart2Runnable, 0);
1428 }
1429}package com.example.myapplication;
1430
1431public class Professore {
1432 private String nome;
1433 private String cognome;
1434
1435 public Professore(String n, String c){
1436 this.nome = n;
1437 this.cognome = c;
1438 }
1439
1440 public String getNome(){return this.nome;}
1441 public String getCognome(){return this.cognome;}
1442
1443 public void setNome(String n){this.nome = n;}
1444 public void setCognome(String c){this.cognome = c;}
1445
1446}
1447package com.example.myapplication;
1448
1449import android.annotation.SuppressLint;
1450import android.content.Intent;
1451import android.graphics.Color;
1452import android.os.Bundle;
1453import android.os.Handler;
1454import android.view.GestureDetector;
1455import android.view.MotionEvent;
1456import android.view.View;
1457import android.widget.Button;
1458import android.widget.ImageButton;
1459import android.widget.LinearLayout;
1460import android.widget.ScrollView;
1461import android.widget.TextView;
1462import android.widget.Toast;
1463
1464import androidx.appcompat.app.ActionBar;
1465import androidx.appcompat.app.AppCompatActivity;
1466
1467import java.util.ArrayList;
1468
1469public class Select extends AppCompatActivity {
1470
1471 private final Handler mHideHandler = new Handler();
1472 private GestureDetector mDetector;
1473 private View mContentView;
1474 private database db;
1475 private final Runnable mHidePart2Runnable = new Runnable() {
1476 @SuppressLint("InlinedApi")
1477 @Override
1478 public void run() {
1479
1480 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
1481 | View.SYSTEM_UI_FLAG_FULLSCREEN
1482 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1483 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
1484 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1485 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
1486 }
1487 };
1488
1489 @SuppressLint("Range")
1490 @Override
1491 protected void onCreate(Bundle savedInstanceState) {
1492 super.onCreate(savedInstanceState);
1493 setContentView(R.layout.activity_select);
1494 hide_all();
1495
1496 TextView lblTitle = (TextView)findViewById(R.id.titleActivity);
1497 lblTitle.setText("Elenco materie");
1498
1499 SimpleGestureListener simpleGestureListener = new SimpleGestureListener();
1500 simpleGestureListener.setListener(new SimpleGestureListener.Listener() {
1501 @SuppressLint("WrongConstant")
1502 @Override
1503 public void onScrollHorizontal(float dx) {
1504 if (dx < 0) {
1505 Intent ie = new Intent(Select.this, MainActivity.class);
1506 startActivity(ie);
1507 }
1508 }
1509
1510 @Override
1511 public void onScrollVertical(float dy) {
1512
1513 }
1514 });
1515
1516
1517 LinearLayout rl=(LinearLayout) findViewById(R.id.rl);
1518 final ImageButton tr= findViewById(R.id.sett);
1519
1520 ScrollView sv = new ScrollView(this);
1521 sv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
1522 final LinearLayout ll = new LinearLayout(this);
1523 ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
1524 ll.setOrientation(LinearLayout.VERTICAL);
1525 sv.addView(ll);
1526
1527 db = new database(this);
1528 ArrayList<Materia>listMaterie = db.getMaterie();
1529 for(int i = 0; i < listMaterie.size(); i++){
1530 final Button b = new Button(this);
1531 b.setText(listMaterie.get(i).getNome());
1532 b.setTextColor(Color.BLACK);
1533 b.setAlpha(254);
1534 b.setShadowLayer(4, -10, 10, Color.LTGRAY);
1535 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
1536 LinearLayout.LayoutParams.MATCH_PARENT,
1537 LinearLayout.LayoutParams.WRAP_CONTENT
1538 );
1539 if(i == 0){
1540 params.setMargins(30, 120, 30, 0);
1541 b.setLayoutParams(params);
1542 }else{
1543 params.setMargins(30, 40, 30, 0);
1544 b.setLayoutParams(params);
1545 }
1546
1547 b.setBackgroundResource(R.drawable.btn);
1548
1549 b.setOnClickListener(new View.OnClickListener() {
1550 @SuppressLint({"WrongConstant", "Range"})
1551 @Override
1552 public void onClick(View v) {
1553 Intent in = new Intent(Select.this, MainActivity.class);
1554 in.putExtra("Materia", b.getText());
1555 startActivity(in);
1556 db.close();
1557 finish(); //evita che la app si ripeschi i dati
1558 }
1559 });
1560
1561 //lo uso per far tornare il testo normale sul long press perche se premo sposto
1562 //e levo il dito il testo rimane invece se sposto allora si muovo rl e cambio
1563 //non funziona
1564 /*rl.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
1565 @Override
1566 public void onScrollChanged() {
1567 if(isSpeakButtonLongPressed)
1568 current.setText(text);
1569 }
1570 });*/
1571
1572 /*b.setOnLongClickListener(new View.OnLongClickListener() {
1573 @Override
1574 public boolean onLongClick(View v) {
1575 text= (String) b.getText();
1576 b.setText("rfngrigrgn");
1577 isSpeakButtonLongPressed = true;
1578 current=b;
1579 return false;
1580 }
1581 });*/
1582
1583 ll.addView(b);
1584 }
1585
1586 mDetector = new GestureDetector(this, simpleGestureListener);
1587
1588 rl.addView(sv);
1589
1590 }
1591
1592 @Override
1593 public void onBackPressed() {
1594 startActivity(new Intent(Select.this,MainActivity.class));
1595 }
1596
1597 @SuppressLint("WrongConstant")
1598 @Override
1599 public boolean onTouchEvent(MotionEvent event) {
1600 mDetector.onTouchEvent(event);
1601 return super.onTouchEvent(event);
1602 }
1603
1604 public void hide_all(){
1605 mContentView = findViewById(R.id.sta);
1606 ActionBar actionBar = getSupportActionBar();
1607 if (actionBar != null) {
1608 actionBar.hide();
1609 }
1610 mHideHandler.postDelayed(mHidePart2Runnable, 0);
1611 }
1612}
1613package com.example.myapplication;
1614
1615import androidx.appcompat.app.ActionBar;
1616import androidx.appcompat.app.AppCompatActivity;
1617
1618import android.annotation.SuppressLint;
1619import android.app.AlertDialog;
1620import android.content.Context;
1621import android.content.DialogInterface;
1622import android.content.Intent;
1623import android.database.Cursor;
1624import android.net.Uri;
1625import android.os.Bundle;
1626import android.os.Handler;
1627import android.provider.MediaStore;
1628import android.view.GestureDetector;
1629import android.view.MotionEvent;
1630import android.view.View;
1631import android.widget.Button;
1632import android.widget.EditText;
1633import android.widget.ImageView;
1634import android.widget.RadioButton;
1635import android.widget.RadioGroup;
1636import android.widget.TextView;
1637import android.widget.Toast;
1638
1639import java.math.BigInteger;
1640import java.nio.charset.StandardCharsets;
1641import java.security.MessageDigest;
1642import java.security.NoSuchAlgorithmException;
1643import java.text.SimpleDateFormat;
1644import java.util.Base64;
1645import java.util.Calendar;
1646import java.util.Date;
1647import java.util.GregorianCalendar;
1648
1649public class Setting extends AppCompatActivity {
1650 //handler per le gesture
1651 private final Handler mHideHandler = new Handler();
1652 private GestureDetector mDetector;
1653 //usato per il fullscren ottengo il costraint layout (il "div" piu' grande)
1654 private View mContentView;
1655 //boolean per uscire dal while del blink del testo dopo il touch
1656 private boolean leftButtonDown=false;
1657 private Button butt_s;
1658 TextView imgmod;
1659 private ImageView p;
1660 private boolean terminate=true;
1661 private database db;
1662 private EditText emailUsrLabel;
1663 private EditText passwdUsrLabel;
1664 private int radioButtonID;
1665 private View radioButton;
1666 private RadioButton rdbtnChiusura;
1667 private RadioButton rdbtnLogout;
1668 private RadioButton rdbtnNoop;
1669 private RadioGroup radioGroup;
1670 private String oldEmail;
1671 private byte[] hash;
1672 private String encoded;
1673 private String emailUtente;
1674 private Utente usr;
1675 private MessageDigest digest;
1676 private Button btnSave;
1677 private String uri;
1678
1679 //sett fullscreen
1680 private final Runnable mHidePart2Runnable = new Runnable() {
1681 @SuppressLint("InlinedApi")
1682 @Override
1683 public void run() {
1684
1685 mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
1686 | View.SYSTEM_UI_FLAG_FULLSCREEN
1687 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1688 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
1689 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
1690 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
1691 }
1692 };
1693
1694
1695 @Override
1696 protected void onCreate(Bundle savedInstanceState) {
1697 super.onCreate(savedInstanceState);
1698 setContentView(R.layout.activity_setting);
1699
1700 hide_all();
1701
1702 btnSave=findViewById(R.id.save);
1703
1704 butt_s=findViewById(R.id.button2);
1705 p=findViewById(R.id.imageView6);
1706 imgmod=findViewById(R.id.textView9);
1707
1708 emailUsrLabel=findViewById(R.id.editText);
1709 passwdUsrLabel=findViewById(R.id.editText5);
1710 radioGroup = findViewById(R.id.group);
1711 rdbtnChiusura = findViewById(R.id.radioButton3);
1712 rdbtnLogout = findViewById(R.id.radioButton2);
1713 rdbtnNoop = findViewById(R.id.radioButton4);
1714
1715 Bundle exr = getIntent().getExtras();
1716 if (exr != null) {
1717 db = new database(this);
1718 emailUtente = exr.getString("Email");
1719 oldEmail=emailUtente;
1720 usr = db.getUtente(emailUtente);
1721
1722 //seleziono email e passwd
1723 emailUsrLabel.setText(usr.getEmail());
1724 passwdUsrLabel.setHint("nuova password");
1725 passwdUsrLabel.setText("");
1726
1727 //seleziono pref dalla query
1728 if(usr.getPref().compareTo("0") == 0) rdbtnChiusura.setChecked(true);
1729 else if(usr.getPref().compareTo("1") == 0) rdbtnLogout.setChecked(true);
1730 else rdbtnNoop.setChecked(true);
1731
1732 //seleziono immagine dalla query
1733 uri = usr.getImgpath();
1734 if(uri.compareTo("") == 0) {
1735 p.setImageResource(R.drawable.trashn1);
1736 }else {
1737 p.setImageURI(null);
1738 p.setImageURI(Uri.parse(uri));
1739 p.setMinimumHeight(100);
1740 }
1741
1742 //Toast.makeText(getApplicationContext(), usr.getImgpath() + " "+ usr.getPasswd()+ " "+usr.getPref(), 60).show();
1743 }
1744
1745 butt_s.setOnClickListener(new View.OnClickListener() {
1746 @Override
1747 public void onClick(View v) {
1748 Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
1749 intent.setType("image/*");
1750 startActivityForResult(intent, 10);
1751 }
1752 });
1753
1754 //click
1755 btnSave.setOnClickListener(new View.OnClickListener() {
1756 @SuppressLint("WrongConstant")
1757 @Override
1758 public void onClick(View v) {
1759 if(!emailUsrLabel.getText().toString().matches(".*@[a-z]+\\..*"))
1760 Toast.makeText(getApplicationContext(), "Email non corretta", 600).show();
1761 else if (passwdUsrLabel.getText().toString().isEmpty())
1762 Toast.makeText(getApplicationContext(), "Password non corretta", 600).show();
1763 else {
1764 radioButtonID = radioGroup.getCheckedRadioButtonId();
1765 radioButton = radioGroup.findViewById(radioButtonID);
1766 emailUtente = emailUsrLabel.getText().toString();
1767 try {
1768 db.settingUpdate(oldEmail, emailUtente, toHexString(getSHA(passwdUsrLabel.getText().toString())), uri, String.valueOf(radioGroup.indexOfChild(radioButton)));
1769 } catch (NoSuchAlgorithmException e) {
1770 e.printStackTrace();
1771 }
1772 oldEmail = emailUtente; //mi servere per il mail per sapere quale valore tornare
1773 Toast.makeText(getApplicationContext(), "Dati salvati", 600).show();
1774 //startActivity(new Intent(Setting.this, MainActivity.class));
1775 }
1776 }
1777 });
1778
1779 SimpleGestureListener simpleGestureListener = new SimpleGestureListener();
1780 simpleGestureListener.setListener(new SimpleGestureListener.Listener() {
1781 @SuppressLint("WrongConstant")
1782 @Override
1783 //swipe x
1784 public void onScrollHorizontal(float dx) {
1785 if(dx<0){
1786 Intent myin=new Intent(Setting.this, MainActivity.class);
1787 myin.putExtra("Email",emailUtente);
1788 startActivity(myin);
1789 }
1790
1791 }
1792
1793 @SuppressLint("WrongConstant")
1794 @Override
1795 //swipe y
1796 public void onScrollVertical(float dy) {
1797
1798 }
1799 });
1800
1801 mDetector = new GestureDetector(this, simpleGestureListener);
1802 }
1803
1804 public static byte[] getSHA(String input) throws NoSuchAlgorithmException
1805 {
1806 // Static getInstance method is called with hashing SHA
1807 MessageDigest md = MessageDigest.getInstance("SHA-256");
1808
1809 // digest() method called
1810 // to calculate message digest of an input
1811 // and return array of byte
1812 return md.digest(input.getBytes(StandardCharsets.UTF_8));
1813 }
1814
1815 public static String toHexString(byte[] hash)
1816 {
1817 // Convert byte array into signum representation
1818 BigInteger number = new BigInteger(1, hash);
1819
1820 // Convert message digest into hex value
1821 StringBuilder hexString = new StringBuilder(number.toString(16));
1822
1823 // Pad with leading zeros
1824 while (hexString.length() < 32)
1825 {
1826 hexString.insert(0, '0');
1827 }
1828
1829 return hexString.toString();
1830 }
1831
1832 @Override
1833 public boolean onTouchEvent(MotionEvent event) {
1834 mDetector.onTouchEvent(event);
1835 return super.onTouchEvent(event);
1836 }
1837
1838 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
1839 super.onActivityResult(requestCode, resultCode, data);
1840 switch (requestCode) {
1841 case 10:
1842 if (resultCode == RESULT_OK) {
1843 Uri selectedImage = data.getData();
1844 uri = selectedImage.toString();
1845 db.updateImg(emailUtente,uri);
1846 p.setImageURI(selectedImage);
1847 p.setMinimumHeight(100);
1848 Date c = Calendar.getInstance().getTime();
1849 SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
1850 String formattedDate = df.format(c);
1851 SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
1852 Date d = new Date();
1853 String dayOfTheWeek = sdf.format(d);
1854 imgmod.setText(dayOfTheWeek + "," + formattedDate);
1855 }
1856 break;
1857 }
1858 hide_all();
1859 }
1860
1861 @Override
1862 public void onBackPressed() {
1863 terminate=false; //per evitare molte finestre sovrapposte
1864 Intent myin=new Intent(Setting.this, MainActivity.class);
1865 startActivity(myin);
1866 /*AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this, R.style.CustomDialogTheme);
1867 alertDialogBuilder.setTitle("Sei sicuro di voler uscire?");
1868 alertDialogBuilder
1869 .setMessage("Premi si per uscire!")
1870 .setCancelable(false)
1871 .setPositiveButton("Si",
1872 new DialogInterface.OnClickListener() {
1873 public void onClick(DialogInterface dialog, int id) {
1874 finishAffinity(); //se non lo messo non torna al log
1875 android.os.Process.killProcess(android.os.Process.myPid());
1876 System.exit(1);
1877 }
1878 })
1879
1880 .setNegativeButton("No", new DialogInterface.OnClickListener() {
1881 public void onClick(DialogInterface dialog, int id) {
1882 terminate=true;
1883 dialog.cancel();
1884 }
1885 });
1886
1887 AlertDialog alertDialog = alertDialogBuilder.create();
1888 alertDialog.show();*/
1889
1890 }
1891
1892 //fullscreen
1893 public void hide_all(){
1894 mContentView = findViewById(R.id.sta);
1895 ActionBar actionBar = getSupportActionBar();
1896 if (actionBar != null) {
1897 actionBar.hide();
1898 }
1899 mHideHandler.postDelayed(mHidePart2Runnable, 0);
1900 }
1901
1902
1903}
1904package com.example.myapplication;
1905
1906import android.nfc.Tag;
1907import android.util.Log;
1908import android.view.GestureDetector;
1909import android.view.MotionEvent;
1910
1911/**
1912 * Created by CoXier on 17-2-21.
1913 */
1914
1915public class SimpleGestureListener extends GestureDetector.SimpleOnGestureListener {
1916 private static final String TAG = "SimpleGestureListener";
1917 private Listener mListener;
1918
1919 @Override
1920 public boolean onDown(MotionEvent e) {
1921 return true;
1922 }
1923
1924 @Override
1925 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
1926 Log.d(TAG,"distanceX = "+distanceX+",distanceY = "+distanceY);
1927 Log.d(TAG,"bdistanceX = "+Math.abs(distanceX)+",bdistanceY = "+Math.abs(distanceY));
1928 Log.d(TAG, "distancex------------------------");
1929
1930 if (mListener == null)
1931 return true;
1932
1933 //meno di 6 di distanza su y e uno scorrimento di almeno 30 verso sotto
1934 if ((Math.abs(distanceX) < 6) && (distanceY < -30) ){ //sotto
1935 mListener.onScrollVertical(distanceY);
1936 }
1937
1938 if (Math.abs(distanceY) < 6 && Math.abs(distanceX) > 20){
1939 Log.d(TAG,"distance_or = "+distanceX);
1940 mListener.onScrollHorizontal(distanceX);
1941 }
1942 return true;
1943 }
1944
1945 @Override
1946 public void onLongPress(MotionEvent event) {
1947 Log.d(TAG, "onLongPress: " + event.toString());
1948 }
1949
1950 @Override
1951 public boolean onDoubleTap(MotionEvent event) {
1952 Log.d(TAG, "onDoubleTap: " + event.toString());
1953 return true;
1954 }
1955
1956 public void setListener(Listener mListener) {
1957 this.mListener = mListener;
1958 }
1959
1960 interface Listener{
1961 /**
1962 * left scroll dx >0
1963 * right scroll dx <0
1964 * @param dx
1965 */
1966 void onScrollHorizontal(float dx);
1967
1968 /**
1969 * upward scroll dy > 0
1970 * downward scroll dy < 0
1971 * @param dy
1972 */
1973 void onScrollVertical(float dy);
1974 }
1975}package com.example.myapplication;
1976
1977public class Utente {
1978
1979 //private variables
1980 String email;
1981 String nome;
1982 String pref;
1983 String cognome;
1984 String passwd;
1985 String imgpath;
1986
1987 // constructor
1988 public Utente(String email, String nome, String cognome, String passwd, String pref, String imgpath){
1989 this.email = email;
1990 this.nome = nome;
1991 this.cognome = cognome;
1992 this.passwd = passwd;
1993 this.pref = pref;
1994 this.imgpath = imgpath;
1995 }
1996
1997 public String getEmail(){
1998 return this.email;
1999 }
2000
2001 public void setEmail(String Email){
2002 this.email=Email;
2003 }
2004
2005 public String getNome(){
2006 return this.nome;
2007 }
2008
2009 public void setNome(String Nome){
2010 this.nome=Nome;
2011 }
2012
2013 public String getCognome(){
2014 return this.cognome;
2015 }
2016
2017 public void setCognome(String Cognome){
2018 this.cognome=Cognome;
2019 }
2020
2021 public String getPasswd(){
2022 return this.passwd;
2023 }
2024
2025 public void setPasswd(String Passwd){
2026 this.passwd=Passwd;
2027 }
2028
2029 public String getPref(){
2030 return this.pref;
2031 }
2032
2033 public void setPref(String Pref){
2034 this.pref=Pref;
2035 }
2036
2037 public String getImgpath(){
2038 return this.imgpath;
2039 }
2040
2041 public void setImgpath(String Imgpath){
2042 this.imgpath=Imgpath;
2043 }
2044
2045}
2046package com.example.myapplication;
2047
2048import android.content.ContentValues;
2049import android.content.Context;
2050import android.database.Cursor;
2051import android.database.sqlite.SQLiteDatabase;
2052import android.database.sqlite.SQLiteOpenHelper;
2053import android.util.Log;
2054import android.view.View;
2055import android.widget.Toast;
2056
2057import org.apache.http.conn.ConnectTimeoutException;
2058
2059import java.time.LocalDateTime;
2060import java.time.format.DateTimeFormatter;
2061import java.util.ArrayList;
2062import java.util.List;
2063
2064public class database extends SQLiteOpenHelper {
2065
2066 // All Static variables
2067// Database Version
2068 private static final int DATABASE_VERSION = 1;
2069
2070 // Database Name
2071 private static final String DATABASE_NAME = "dbMagister";
2072
2073 // Contacts table name
2074 private static final String TABLE_CONTACTS = "Materia";
2075
2076
2077 // Contacts Table Columns names
2078 private static final String KEY_ID = "nome";
2079 private static final String KEY_NAME = "nome";
2080 private static final String KEY_PH_NO = "phone_number";
2081
2082 public database(Context context) {
2083 super(context, DATABASE_NAME, null, DATABASE_VERSION);
2084 }
2085
2086 // Creating Tables
2087 @Override
2088 public void onCreate(SQLiteDatabase db) {
2089 createTable(db);
2090 }
2091
2092 public void createTable(SQLiteDatabase db){
2093 String CREATE_UTENTE_TABLE = "CREATE TABLE Utente(" +
2094 "email VARCHAR(100) PRIMARY KEY," +
2095 "nome VARCHAR(100) NOT NULL," +
2096 "cognome VARCHAR(100) NOT NULL," +
2097 "passwd VARCHAR(100) NOT NULL," +
2098 "pref VARCHAR(1) NOT NULL,"+
2099 "imgpath VARCHAR(100) NOT NULL,"+
2100 "access VARCHAR(1) DEFAULT 0);";
2101
2102 String CREATE_PROFESSORE_TABLE = "CREATE TABLE Professore(" +
2103 "nome VARCHAR(100) NOT NULL," +
2104 "cognome VARCHAR(100) NOT NULL," +
2105 "PRIMARY KEY (nome, cognome))";
2106
2107 String CREATE_MATERIA_TABLE = "CREATE TABLE Materia(" +
2108 "nome varchar(100) PRIMARY KEY)";
2109
2110
2111 String CREATE_INSEGNA_TABLE = "CREATE TABLE Insegna(" +
2112 "nomeprof VARCHAR(100) NOT NULL," +
2113 "cognomeprof VARCHAR(100) NOT NULL," +
2114 "nomemateria VARCHAR(100) NOT NULL," +
2115 "PRIMARY KEY (nomeprof,cognomeprof,nomemateria),"+
2116 "FOREIGN KEY(nomeprof,cognomeprof) REFERENCES Professore(nome,cognome)," +
2117 "FOREIGN KEY(nomemateria) REFERENCES Materia(nome))";
2118
2119 String CREATE_PRENOTAZIONE_TABLE = "CREATE TABLE Prenotazione(" +
2120 "data VARCHAR(100) NOT NULL," +
2121 "nomeprof VARCHAR(100) NOT NULL," +
2122 "cognomeprof VARCHAR(100) NOT NULL," +
2123 "nomemateria VARCHAR(100) NOT NULL," +
2124 "emailutente VARCHAR(100) NOT NULL," +
2125 "disdetta VARCHAR(1) NOT NULL," +
2126 "PRIMARY KEY (data,nomeprof,cognomeprof,nomemateria,emailUtente,disdetta),"+
2127 "FOREIGN KEY(nomeprof,cognomeprof) REFERENCES Professore(nome,cognome)," +
2128 "FOREIGN KEY(nomemateria) REFERENCES Materia(nome)," +
2129 "FOREIGN KEY(emailutente) REFERENCES Utente(email))";
2130
2131 db.execSQL(CREATE_UTENTE_TABLE);
2132 db.execSQL(CREATE_PROFESSORE_TABLE);
2133 db.execSQL(CREATE_MATERIA_TABLE);
2134 db.execSQL(CREATE_INSEGNA_TABLE);
2135 db.execSQL(CREATE_PRENOTAZIONE_TABLE);
2136 }
2137
2138 public void fillTable(){
2139 String[] materie = {
2140 "IUM",
2141 "Matematica",
2142 "Informatica",
2143 "Scienze",
2144 "Motoria",
2145 "Fisica",
2146 "Chimica",
2147 "Inglese",
2148 "Geografia",
2149 "Arte",
2150 "Storia",
2151 "Arabo"
2152 };
2153 for(String s: materie){
2154 addMateria(s);
2155 }
2156
2157 addUtente("mario.rossi@gmail.com", "Mario", "Rossi", "936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af", "0", "");
2158 addUtente("a", "Jacopo", "Rentoni", "ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb", "0", "");
2159 addUtente("luca.verdi@gmail.com", "Luca", "Verdi", "passwdLuca", "0", "");
2160 addUtente("andrea.bianchi@gmail.com", "Andrea", "Bianchi", "passwdAndrea", "0", "");
2161 addUtente("luca.gialli@gmail.com", "Luca", "Gialli", "passwdLuca", "0", "");
2162 addUtente("matteo.neri@gmail.com", "Matteo", "Neri", "passwdMatteo", "0", "");
2163 addUtente("simone.azzurri@gmail.com", "Simone", "Azzurri", "passwdSimone", "0", "");
2164 addUtente("gabriele.arancioni@gmail.com", "Gabriele", "Arancioni", "passwdGabriele", "0", "");
2165 addUtente("lucia.blu@gmail.com", "Lucia", "Blu", "passwdLucia", "0", "");
2166 addUtente("martina.verdi@gmail.com", "Martina", "Verdi", "passwdMartina", "0", "");
2167 addUtente("lorenzo.grigi@gmail.com", "Lorenzo", "Grigi", "passwdLorenzo", "0", "");
2168 addUtente("filippo.marroni@gmail.com", "Filippo", "Marroni", "passwdFilippo", "0", "");
2169
2170
2171 addProfessore("Matteo","Viale");
2172 addProfessore("Marino","Segnan");
2173 addProfessore("Felice","Cardone");
2174 addProfessore("Daniele","Gunetti");
2175 addProfessore("Mario","Rossi");
2176 addProfessore("Luca","Verdi");
2177 addProfessore("Andrea","Bianchi");
2178 addProfessore("Gabriele","Cortese");
2179 addProfessore("Simone","Giovinazzo");
2180 addProfessore("Viviana","Patti");
2181
2182
2183 addInsegna("Matteo","Viale","Matematica");
2184 addInsegna("Felice","Cardone","Storia");
2185 addInsegna("Felice","Cardone","Italiano");
2186 addInsegna("Daniele","Gunetti","Matematica");
2187 addInsegna("Daniele","Gunetti","Arte");
2188 addInsegna("Marino","Segnan","IUM");
2189 addInsegna("Gabriele","Cortese","Inglese");
2190 addInsegna("Simone","Giovinazzo","Scienze");
2191 addInsegna("Mario","Rossi","Storia");
2192 addInsegna("Marino","Segnan","Matematica");
2193 addInsegna("Daniele","Gunetti","Arabo");
2194 addInsegna("Mario","Rossi","Chimica");
2195 addInsegna("Marino","Segnan","Fisica");
2196 addInsegna("Daniele","Gunetti","Italiano");
2197 addInsegna("Marino","Segnan","Storia");
2198 addInsegna("Marino","Segnan","Inglese");
2199
2200 addPrenotazione("2020-01-06 15-16","Matteo","Viale","Matematica","mario.rossi@gmail.com","n");
2201 addPrenotazione("2020-12-20 17-18", "Felice","Cardone","Italiano","luca.rossi@gmail.com","s");
2202 addPrenotazione("2020-11-24 18-19", "Daniele","Gunetti","Arabo","mario.rossi@gmail.com","n");
2203 addPrenotazione("2020-12-20 17-18", "Marino","Segnan","Inglese","mario.rossi@gmail.com","s");
2204
2205 }
2206
2207 // Upgrading database
2208 //Da tenere vuota, usata solo in caso di eliminazione DB
2209 @Override
2210 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
2211 // Drop older table if existed
2212 db.execSQL("DROP TABLE IF EXISTS Utente");
2213 db.execSQL("DROP TABLE IF EXISTS Materia");
2214 db.execSQL("DROP TABLE IF EXISTS Professore");
2215 db.execSQL("DROP TABLE IF EXISTS Insegna");
2216 db.execSQL("DROP TABLE IF EXISTS Prenotazione");
2217 // Create tables again
2218 onCreate(db);
2219 }
2220
2221 /**
2222 * All CRUD(Create, Read, Update, Delete) Operations
2223 */
2224//------ metodi opzionali con nostre query -------
2225// Adding new contact
2226 void addContact(Contact contact) {
2227 SQLiteDatabase db = this.getWritableDatabase();
2228
2229 ContentValues values = new ContentValues();
2230 values.put(KEY_NAME, contact.getName()); // Contact Name
2231 values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone
2232
2233 // Inserting Row
2234 db.insert(TABLE_CONTACTS, null, values);
2235 db.close(); // Closing database connection
2236 }
2237
2238 void addProfessore(String nomeProf, String cognomeProf){
2239 SQLiteDatabase db = this.getWritableDatabase();
2240 db.execSQL("INSERT OR IGNORE INTO Professore(nome,cognome) VALUES("+addSyntax(nomeProf)+","+addSyntax(cognomeProf)+");");
2241
2242
2243 /*ContentValues values = new ContentValues();
2244 values.put("nome", nomeProf);
2245 values.put("cognome", cognomeProf);
2246
2247
2248 db.insert("Professore", null, values);*/
2249 db.close(); // Closing database connection
2250 }
2251
2252 void addUtente(String email, String nome, String cognome, String passwd, String pref, String imgpath) {
2253 SQLiteDatabase db = this.getWritableDatabase();
2254 db.execSQL("INSERT OR IGNORE INTO Utente(email,nome,cognome,passwd,pref,imgpath) VALUES("+addSyntax(email)+","+addSyntax(nome)+","+addSyntax(cognome)+","+addSyntax(passwd)+","+addSyntax(pref)+","+addSyntax(imgpath)+");");
2255
2256 /*ContentValues values = new ContentValues();
2257 values.put("email", email);
2258 values.put("nome", nome);
2259 values.put("cognome", cognome);
2260 values.put("passwd", passwd);
2261 values.put("pref", pref);
2262 values.put("imgpath", imgpath);
2263
2264 db.insert("Utente", null, values);*/
2265 db.close(); // Closing database connection
2266 }
2267
2268 void addPrenotazione(String data,String nomeProf, String cognomeProf, String nomeMateria, String emailUtente, String disdetta){
2269 SQLiteDatabase db = this.getWritableDatabase();
2270 SQLiteDatabase db2 = this.getReadableDatabase();
2271
2272 String ctrlOraGiaEsistente = "SELECT * FROM Prenotazione WHERE emailutente = "+addSyntax(emailUtente)+" AND data = "+addSyntax(data)+" AND disdetta = 'n';";
2273 Cursor cursor = db2.rawQuery(ctrlOraGiaEsistente, null);
2274 //se il cursore non restitusce nulla
2275 if (cursor.getCount() == 0){
2276 //Non viene usata la dataNow perchè prende l'ora in cui è stata fatta la prenotazione
2277 // e non quando davvero l'utunte vuole fare ripetizione
2278 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
2279 LocalDateTime now = LocalDateTime.now();
2280 String dataNow = String.valueOf(now);
2281
2282 db.execSQL("INSERT OR IGNORE INTO Prenotazione(data,nomeprof,cognomeprof,nomemateria,emailutente,disdetta) VALUES("+addSyntax(data)+","+addSyntax(nomeProf)+","+addSyntax(cognomeProf)+","+addSyntax(nomeMateria)+","+addSyntax(emailUtente)+","+addSyntax(disdetta)+");");
2283
2284
2285 /*ContentValues values = new ContentValues();
2286 values.put("data", data); // Contact Name
2287 values.put("nomeprof", nomeProf); // Contact Name
2288 values.put("cognomeprof", cognomeProf); // Contact Name
2289 values.put("nomemateria", nomeMateria); // Contact Name
2290 values.put("emailutente", emailUtente); // Contact Name
2291
2292 // Inserting Row
2293 db.insert("Prenotazione", null, values);*/
2294 db.close(); // Closing database connection
2295 }
2296 }
2297
2298 void addMateria(String nomeMateria) {
2299 SQLiteDatabase db = this.getWritableDatabase();
2300 db.execSQL("INSERT OR IGNORE INTO Materia(nome) VALUES("+addSyntax(nomeMateria)+");");
2301
2302 /*ContentValues values = new ContentValues();
2303 values.put("nome", nomeMateria);
2304
2305 db.insert("Materia", null, values);*/
2306 db.close(); // Closing database connection
2307 }
2308
2309 void addInsegna(String nomeProf, String cognomeProf, String nomeMateria){
2310 SQLiteDatabase db = this.getWritableDatabase();
2311 db.execSQL("INSERT OR IGNORE INTO Insegna(nomeprof,cognomeprof,nomemateria) VALUES("+addSyntax(nomeProf)+","+addSyntax(cognomeProf)+","+addSyntax(nomeMateria)+");");
2312
2313 /*ContentValues values = new ContentValues();
2314 values.put("nomeprof",nomeProf);
2315 values.put("cognomeprof",cognomeProf);
2316 values.put("nomemateria",nomeMateria); // Contact Name
2317
2318 // Inserting Row
2319 db.insert("Insegna", null, values);*/
2320 db.close(); // Closing database connection
2321 }
2322
2323 // Getting single contact
2324 Contact getContact(int id) {
2325 SQLiteDatabase db = this.getReadableDatabase();
2326
2327 //fuuuuuck
2328 //https://stackoverflow.com/questions/10600670/sqlitedatabase-query-method
2329 //il cursore e' un iteratore
2330 Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID,
2331 KEY_NAME, KEY_PH_NO }, KEY_ID + "=?",
2332 new String[] { String.valueOf(id) }, null, null, null, null);
2333 if (cursor != null)
2334 cursor.moveToFirst();
2335
2336 Contact contact = new Contact(Integer.parseInt(cursor.getString(0)),
2337 cursor.getString(1), cursor.getString(2));
2338 // return contact
2339 return contact;
2340 }
2341
2342 Utente getUtente(String email){
2343 SQLiteDatabase db = this.getReadableDatabase();
2344
2345 String countQuery = "SELECT * FROM Utente WHERE email = "+addSyntax(email)+";";
2346 Cursor cursor = db.rawQuery(countQuery, null);
2347
2348 //se il cursore non restitusce nulla
2349 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2350 return null;
2351
2352 return new Utente(
2353 cursor.getString(0),
2354 cursor.getString(1),
2355 cursor.getString(2),
2356 cursor.getString(3),
2357 cursor.getString(4),
2358 cursor.getString(5)
2359 );
2360 }
2361
2362 ArrayList<Prenotazione> getPrenotazioniFromUtenteAndData(String emailUtente, String data){
2363 SQLiteDatabase db = this.getReadableDatabase();
2364 ArrayList<Prenotazione> pre = new ArrayList<>();
2365 String selectQuery = "SELECT * FROM Prenotazione WHERE emailutente = " + addSyntax(emailUtente) +" AND data = "+addSyntax(data)+" AND Disdetta = 'n';";
2366 Cursor cursor = db.rawQuery(selectQuery, null);
2367
2368 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2369 return null;
2370
2371 cursor.moveToPrevious();
2372 while(cursor.moveToNext()) {
2373 pre.add(new Prenotazione(cursor.getString(0),
2374 cursor.getString(1),
2375 cursor.getString(2),
2376 cursor.getString(3),
2377 cursor.getString(4),
2378 cursor.getString(5)
2379 ));
2380 }
2381 return pre;
2382 }
2383
2384 // Getting single contact
2385 Materia getMateria(String nomeMateria) {
2386 SQLiteDatabase db = this.getReadableDatabase();
2387 String countQuery = "SELECT * FROM Materia WHERE nome = "+addSyntax(nomeMateria)+";";
2388 Cursor cursor = db.rawQuery(countQuery, null);
2389
2390 //se il cursore non restitusce nulla
2391 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2392 return null;
2393
2394 return new Materia(cursor.getString(0));
2395 }
2396
2397 // Getting single contact
2398 ArrayList<Materia> getMaterie() {
2399 SQLiteDatabase db = this.getReadableDatabase();
2400 ArrayList<Materia> matAr = new ArrayList<Materia>();
2401
2402 String countQuery = "SELECT * FROM Materia;";
2403 Cursor cursor = db.rawQuery(countQuery, null);
2404
2405 //se il cursore non restitusce nulla NB: ne mangia uno
2406 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2407 return null;
2408
2409 cursor.moveToPrevious(); //Fatto perche cursor.moveToFirst si mangia una posizione
2410 while (cursor.moveToNext())
2411 matAr.add(new Materia(cursor.getString(0)));
2412
2413 return matAr;
2414 }
2415
2416 ArrayList<Professore> getProfessori() {
2417 SQLiteDatabase db = this.getReadableDatabase();
2418 ArrayList<Professore> profAr = new ArrayList<Professore>();
2419
2420 String countQuery = "SELECT * FROM Professore";
2421 Cursor cursor = db.rawQuery(countQuery, null);
2422 //se il cursore non restitusce nulla
2423 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2424 return null;
2425
2426 cursor.moveToPrevious();
2427 while (cursor.moveToNext())
2428 profAr.add(new Professore(
2429 cursor.getString(0),
2430 cursor.getString(1))
2431 );
2432
2433 return profAr;
2434 }
2435
2436 //Prendo tutti i professori che insegnano una determinata materia in una data precisa
2437 ArrayList<Professore> getProfessoriFromMateriaAndData(String nomeMateria, String data) {
2438 SQLiteDatabase db = this.getReadableDatabase();
2439 ArrayList<Professore> profAr = new ArrayList<Professore>();
2440
2441 String countQuery = "SELECT nomeprof,cognomeprof FROM Prenotazione WHERE nomemateria = "+addSyntax(nomeMateria)+" AND data = "+addSyntax(data)+";";
2442 Cursor cursor = db.rawQuery(countQuery, null);
2443 //se il cursore non restitusce nulla
2444 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2445 return null;
2446
2447 cursor.moveToPrevious();
2448 while (cursor.moveToNext())
2449 profAr.add(new Professore(
2450 cursor.getString(0),
2451 cursor.getString(1))
2452 );
2453
2454 return profAr;
2455 }
2456
2457 ArrayList<Professore> getProfessoriDisponibili(String nomeMateria, String data) {
2458 SQLiteDatabase db = this.getReadableDatabase();
2459 ArrayList<Professore> profAr = new ArrayList<Professore>();
2460
2461 String countQuery = "SELECT nomeprof,cognomeprof FROM Insegna WHERE nomemateria = "+addSyntax(nomeMateria)+" AND (nomeprof,cognomeprof) " +
2462 "NOT IN (SELECT nomeprof,cognomeprof FROM Prenotazione WHERE data = "+addSyntax(data)+" AND disdetta = 'n');";
2463 Cursor cursor = null;
2464 try {
2465 cursor = db.rawQuery(countQuery, null);
2466 }catch (Exception e){
2467 Log.d("pippo",e.getMessage());
2468 }
2469 //se il cursore non restitusce nulla
2470 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2471 return null;
2472
2473 cursor.moveToPrevious();
2474 while (cursor.moveToNext())
2475 profAr.add(new Professore(
2476 cursor.getString(0),
2477 cursor.getString(1))
2478 );
2479
2480 return profAr;
2481 }
2482
2483 /*ArrayList<String> getInsegnaAll() {
2484 SQLiteDatabase db = this.getReadableDatabase();
2485 ArrayList<String> matAr = new ArrayList<String>();
2486
2487 String countQuery = "SELECT * FROM Insegna";
2488 Cursor cursor = db.rawQuery(countQuery, null);
2489
2490 String m;
2491 while (cursor.moveToNext()) {
2492 m = cursor.getString(0) +","+cursor.getString(1)+","+cursor.getString(2);
2493 matAr.add(m);
2494 }
2495 cursor.close();
2496
2497 return matAr;
2498 }*/
2499
2500 ArrayList<Prenotazione> getPrenotazioni() {
2501 SQLiteDatabase db = this.getReadableDatabase();
2502 ArrayList<Prenotazione> prenotazioneAr = new ArrayList<Prenotazione>();
2503
2504 String countQuery = "SELECT * FROM Prenotazione";
2505 Cursor cursor = db.rawQuery(countQuery, null);
2506
2507 Prenotazione p;
2508 while (cursor.moveToNext()) {
2509 prenotazioneAr.add(new Prenotazione(
2510 cursor.getString(0),
2511 cursor.getString(1),
2512 cursor.getString(2),
2513 cursor.getString(3),
2514 cursor.getString(4),
2515 cursor.getString(5)
2516 ));
2517 }
2518 return prenotazioneAr;
2519 }
2520
2521 ArrayList<Materia> getMateriaAll2() {
2522 SQLiteDatabase db = this.getReadableDatabase();
2523 ArrayList<Materia> matAr = new ArrayList<Materia>();
2524
2525 String countQuery = "SELECT * FROM Materia";
2526 Cursor cursor = db.rawQuery(countQuery, null);
2527
2528 //fuuuuuck
2529 //https://stackoverflow.com/questions/10600670/sqlitedatabase-query-method
2530 //il cursore e' un iteratore
2531 /*Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID}, KEY_ID + "=?",
2532 new String[] { String.valueOf(nome) }, null, null, null, null);
2533 Cursor cursor = db.query("Materia",null,null,null,null,null,null,null);
2534 */Materia m;
2535 while (cursor.moveToNext()) {
2536 m = new Materia(cursor.getString(0));
2537 matAr.add(m);
2538 }
2539 cursor.close();
2540
2541 return matAr;
2542 //return cursor.getString(0);
2543 /* Materia m = new Materia(cursor.getString(0));
2544 return m;*/
2545 }
2546
2547 void deletePrenotazione(String data, String emailUtente, String nomeProf, String cognomeProf){
2548 SQLiteDatabase db = this.getWritableDatabase();
2549 String query = "DELETE FROM Prenotazione" +
2550 " WHERE data = " +addSyntax(data)+
2551 " AND emailutente = " +addSyntax(emailUtente)+
2552 " AND nomeprof = " + addSyntax(nomeProf) +
2553 " AND cognomeprof = "+addSyntax(cognomeProf)+";";
2554 db.execSQL(query);
2555 db.close();
2556 }
2557
2558 ArrayList<Prenotazione> getPrenotazioniFromUtente(String emailUtente){
2559 SQLiteDatabase db = this.getReadableDatabase();
2560 ArrayList<Prenotazione> pre = new ArrayList<>();
2561 String selectQuery = "SELECT * FROM Prenotazione WHERE emailutente = " + addSyntax(emailUtente);
2562 Cursor cursor = db.rawQuery(selectQuery, null);
2563
2564 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2565 return null;
2566
2567 cursor.moveToPrevious();
2568 while(cursor.moveToNext()) {
2569 pre.add(new Prenotazione(cursor.getString(0),
2570 cursor.getString(1),
2571 cursor.getString(2),
2572 cursor.getString(3),
2573 cursor.getString(4),
2574 cursor.getString(5)
2575 ));
2576 }
2577 return pre;
2578 }
2579
2580 void updatePref(String emailUtente, String pref){
2581 SQLiteDatabase db = this.getWritableDatabase();
2582 String query = "UPDATE Utente SET pref = " + addSyntax(pref) + " WHERE email = " + addSyntax(emailUtente)+";";
2583 db.execSQL(query);
2584 db.close();
2585 }
2586
2587 void updateImg(String emailUtente, String img){
2588 SQLiteDatabase db = this.getWritableDatabase();
2589 db.execSQL("UPDATE Utente" +
2590 " SET imgpath = " + addSyntax(img) +
2591 " WHERE email =" + addSyntax(emailUtente));
2592 db.close();
2593 }
2594
2595 // Getting All Contacts
2596 public List<Contact> getAllContacts() {
2597 List<Contact> contactList = new ArrayList<Contact>();
2598 // Select All Query
2599 String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
2600
2601 SQLiteDatabase db = this.getWritableDatabase();
2602 Cursor cursor = db.rawQuery(selectQuery, null);
2603
2604 // looping through all rows and adding to list
2605 if (cursor.moveToFirst()) {
2606 do {
2607 Contact contact = new Contact();
2608 contact.setID(Integer.parseInt(cursor.getString(0)));
2609 contact.setName(cursor.getString(1));
2610 contact.setPhoneNumber(cursor.getString(2));
2611 // Adding contact to list
2612 contactList.add(contact);
2613 } while (cursor.moveToNext());
2614 }
2615
2616 // return contact list
2617 return contactList;
2618 }
2619
2620 public void settingUpdate(String oldEmail, String newEmail, String passwd, String path, String pref){
2621 SQLiteDatabase db = this.getWritableDatabase();
2622 db.execSQL("UPDATE Utente "+
2623 "SET email = " + addSyntax(newEmail) +
2624 ", passwd = "+ addSyntax(passwd) +
2625 ", imgpath = "+addSyntax(path) +
2626 ", pref = "+addSyntax(pref)+
2627 "WHERE email = "+addSyntax(oldEmail)
2628 );
2629 db.close();
2630 }
2631
2632 // Updating single contact
2633 public int updateContact(Contact contact) {
2634 SQLiteDatabase db = this.getWritableDatabase();
2635
2636 ContentValues values = new ContentValues();
2637 values.put(KEY_NAME, contact.getName());
2638 values.put(KEY_PH_NO, contact.getPhoneNumber());
2639
2640 // updating row
2641 return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
2642 new String[] { String.valueOf(contact.getID()) });
2643 }
2644
2645 // Deleting single contact
2646 public void deleteContact(Contact contact) {
2647 SQLiteDatabase db = this.getWritableDatabase();
2648 db.delete(TABLE_CONTACTS, KEY_ID + " = ?",
2649 new String[] { String.valueOf(contact.getID()) });
2650 db.close();
2651 }
2652
2653 //Non elimino ma setto disdetta = s
2654 //Se esiste gia una mia prenotazione stesso giorno, materia professore allora decido di eliminare la tupla meno recente
2655 //evitando due tuple uguali(duplicata chiave primaria) e quindi errore.
2656 //Esempio: prenoto, disdico, prenoto, disdico --> ERRORE perche ho due tuple uguali con disdetta = s.
2657 //Soluzoine: Elimino la tupla con disdetta = n lasciando quella vecchia a s
2658 void updatePrenotazione(String data, String emailUtente, String nomeProf, String cognomeProf){
2659 SQLiteDatabase db = this.getWritableDatabase();
2660 String query = "SELECT * FROM Prenotazione" +
2661 " WHERE data = " +addSyntax(data)+
2662 " AND emailutente = " +addSyntax(emailUtente)+
2663 " AND nomeprof = " + addSyntax(nomeProf) +
2664 " AND cognomeprof = "+addSyntax(cognomeProf)+" AND disdetta = 's';";
2665 /*String query = "DELETE FROM Prenotazione" +
2666 " WHERE data = " +addSyntax(data)+
2667 " AND emailutente = " +addSyntax(emailUtente)+
2668 " AND nomeprof = " + addSyntax(nomeProf) +
2669 " AND cognomeprof = "+addSyntax(cognomeProf)+";";*/
2670 Cursor cursor = db.rawQuery(query, null);
2671 if (!(cursor.moveToFirst()) || cursor.getCount() == 0) {
2672 String queryUpdate = "UPDATE Prenotazione SET disdetta = 's'" +
2673 " WHERE data = " +addSyntax(data)+
2674 " AND emailutente = " +addSyntax(emailUtente)+
2675 " AND nomeprof = " + addSyntax(nomeProf) +
2676 " AND cognomeprof = "+addSyntax(cognomeProf)+";";
2677 db.execSQL(queryUpdate);
2678 }else{
2679 String queryDel = "DELETE FROM Prenotazione" +
2680 " WHERE data = " +addSyntax(data)+
2681 " AND emailutente = " +addSyntax(emailUtente)+
2682 " AND nomeprof = " + addSyntax(nomeProf) +
2683 " AND cognomeprof = "+addSyntax(cognomeProf)+" AND disdetta = 'n';";
2684 db.execSQL(queryDel);
2685 }
2686
2687
2688
2689 db.close();
2690 }
2691
2692
2693 // Getting contacts Count
2694 public int getContactsCount() {
2695 String countQuery = "SELECT * FROM " + TABLE_CONTACTS;
2696 SQLiteDatabase db = this.getReadableDatabase();
2697 Cursor cursor = db.rawQuery(countQuery, null);
2698 cursor.close();
2699
2700 // return count
2701 return cursor.getCount();
2702 }
2703
2704 public String getAccessFromUtente(String emailUtente){
2705 SQLiteDatabase db = this.getWritableDatabase();
2706 String selectQuery = "SELECT * FROM Utente WHERE email = "+addSyntax(emailUtente);
2707 Cursor cursor = db.rawQuery(selectQuery, null);
2708
2709 if (!(cursor.moveToFirst()) || cursor.getCount() ==0)
2710 return null;
2711
2712 return cursor.getString(6);
2713 }
2714
2715 public void updateAccesses(String emailUtente){
2716 SQLiteDatabase db = this.getWritableDatabase();
2717 db.execSQL("UPDATE Utente" +
2718 " SET access = '1'" +
2719 " WHERE email =" + addSyntax(emailUtente));
2720 db.close();
2721 }
2722
2723 String addSyntax(String stringToAdd){
2724 return "'" + stringToAdd + "'";
2725 }
2726
2727MacBook-Air-di-Gabriele:myapplication gabrielecortese$