Meeting  1.1
BTS SNIR LaSalle Avignon 2021
EspaceDeTravail.java
Aller à la documentation de ce fichier.
1 package com.lasalle.meeting;
2 
3 import android.os.Bundle;
4 import android.os.Handler;
5 import android.os.Message;
6 import android.util.Log;
7 
8 import org.json.JSONException;
9 import org.json.JSONObject;
10 
11 import java.io.Serializable;
12 import java.util.Arrays;
13 import java.util.List;
14 
27 public class EspaceDeTravail implements Serializable
28 {
32  private static final String TAG = "_EspaceDeTravail";
33  public static final int INDICE_CHAUD = 3;
34  public static final int INDICE_TIEDE = 2;
35  public static final int INDICE_LEGEREMENT_TIEDE = 1;
36  public static final int INDICE_NEUTRE = 0;
37  public static final int INDICE_LEGEREMENT_FRAIS = -1;
38  public static final int INDICE_FRAIS = -2;
39  public static final int INDICE_FROID = -3;
40 
44  private String adresseIP;
45  private String nom;
46  private String lieu;
47  private String description;
48  private int superficie;
49  private double temperature;
50  private int indiceDeConfort;
51  private boolean estReserve;
52  private String code;
53  private boolean estFavori;
54  private Communication communication = null;
55 
59  public EspaceDeTravail(String adresseIP)
60  {
61  this.adresseIP = adresseIP;
62  this.nom = "";
63  this.lieu = "";
64  this.description = "";
65  this.superficie = 0;
66  this.temperature = 0.;
67  this.indiceDeConfort = 0;
68  this.estReserve = false;
69  this.code = "";
70  this.estFavori = false;
71 
73  }
74 
79  public String getAdresseIP()
80  {
81  return adresseIP;
82  }
83 
88  public String getNom()
89  {
90  return nom;
91  }
92 
97  public String getLieu()
98  {
99  return lieu;
100  }
101 
106  public String getDescription()
107  {
108  return description;
109  }
110 
115  public int getSuperficie()
116  {
117  return superficie;
118  }
119 
124  public double getTemperature()
125  {
126  return temperature;
127  }
128 
133  public int getIndiceDeConfort()
134  {
135  return indiceDeConfort;
136  }
137 
142  public boolean getEstReserve()
143  {
144  return estReserve;
145  }
146 
151  public String getCode()
152  {
153  return code;
154  }
155 
160  public boolean getEstFavori()
161  {
162  return estFavori;
163  }
164 
169  public void setEstReserve(boolean estReserve)
170  {
171  this.estReserve = estReserve;
172  }
173 
178  public void setCode(String code)
179  {
180  this.code = code;
181  //IHMMeeting.sauvegarderDonneesEspaceDeTravail(this);
182 
183  Log.d(TAG, "setCode() " + code);
184  }
185 
190  public void setEstFavori(boolean estFavori)
191  {
192  this.estFavori = estFavori;
194 
195  Log.d(TAG, "setEstFavori() " + estFavori);
196  }
197 
201  public void reserver()
202  {
203  if(communication == null)
204  return;
205  Log.d(TAG, "reserver()");
206 
207  String trame = "\0";
208  List<String> parametres = Arrays.asList("0");
209  trame = communication.fabriquerTrameModification(Communication.MODIFICATION_DISPONIBILITE, parametres);
210  communication.envoyer(trame, adresseIP);
211 
212  setEstReserve(true);
213  }
214 
218  public void liberer(String code)
219  {
220  if(communication == null)
221  return;
222  Log.d(TAG, "liberer()");
223 
224  String trame = "\0";
225  List<String> parametres = Arrays.asList("1", code);
226  trame = communication.fabriquerTrameModification(Communication.MODIFICATION_DISPONIBILITE, parametres);
227  communication.envoyer(trame, adresseIP);
228 
229  setEstReserve(false);
230  }
231 
236  public void modifierInformations(List<String> parametres)
237  {
238  if(communication == null)
239  return;
240  Log.d(TAG, "modifierInformations()");
241 
242  String trame = "\0";
243  trame = communication.fabriquerTrameModification(Communication.MODIFICATION_INFORMATIONS, parametres);
244  communication.envoyer(trame, adresseIP);
245  }
246 
251  public boolean extraireInformations(String trame)
252  {
258  trame = trame.replace("$", "");
259  trame = trame.replace("\r\n", "");
260  String[] champs = trame.split(";");
261 
262  if(champs.length == Communication.NB_CHAMPS_DEMANDE_INFORMATIONS)
263  {
264  this.nom = champs[Communication.CHAMP_NOM];
265  this.description = champs[Communication.CHAMP_DESCRIPTION];
266  this.lieu = champs[Communication.CHAMP_LIEU];
267  if (!champs[Communication.CHAMP_SUPERFICIE].isEmpty())
268  {
269  this.superficie = Integer.parseInt(champs[Communication.CHAMP_SUPERFICIE]);
270  }
271  if (!champs[Communication.CHAMP_DISPONIBILITE].isEmpty())
272  {
273  if (Integer.parseInt(champs[Communication.CHAMP_DISPONIBILITE]) == 1)
274  {
275  this.estReserve = false;
276  }
277  else
278  {
279  this.estReserve = true;
280  }
281  }
282  if (!champs[Communication.CHAMP_TEMPERATURE].isEmpty())
283  {
284  this.temperature = Double.parseDouble(champs[Communication.CHAMP_TEMPERATURE]);
285  }
286  if(!champs[Communication.CHAMP_INDICE_DE_CONFORT].isEmpty())
287  {
288  this.indiceDeConfort = Integer.parseInt(champs[Communication.CHAMP_INDICE_DE_CONFORT]);
289  }
290 
291  Log.d(TAG, "extraireInformations() nom : " + nom + " - description : " + description + " - lieu : " + lieu + " - superficie : " + superficie + " - estReserve : " + estReserve + " - temperature : " + temperature + " - indiceDeConfort : " + indiceDeConfort);
292 
293  return true;
294  }
295 
296  return false;
297  }
298 
303  public boolean extraireCode(String trame)
304  {
310  trame = trame.replace("$", "");
311  trame = trame.replace("\r\n", "");
312  String[] champs = trame.split(";");
313 
315  {
316  this.nom = champs[Communication.CHAMP_NOM];
317 
318  if (!champs[1].isEmpty())
319  {
320  this.code = champs[Communication.CHAMP_CODE];
321  }
322 
323  Log.d(TAG, "extraireCode() nom : " + nom + " - code : " + code);
324 
325  return true;
326  }
327 
328  return false;
329  }
330 
335  public void initialiserCommunication(Handler handler)
336  {
337  Log.d(TAG, "initialiserCommunication()");
338  if(communication == null)
339  {
340  communication = new Communication();
341  communication.setHandler(handler);
342 
343  // Démarre la réception des trames des portiers
344  Thread tCommunicationUDP = new Thread(communication, getAdresseIP());
345  tCommunicationUDP.start(); // execute la méthode run()
346  }
347  else
348  {
349  communication.arreter();
350  communication.setHandler(null);
351  communication = null;
352  }
353  }
354 
358  public void demanderInformations()
359  {
361  }
362 
367  public String toJSON()
368  {
369  JSONObject objet = new JSONObject();
370  try
371  {
372  objet.put("code", this.code);
373  objet.put("estFavori", this.estFavori);
374  }
375  catch (JSONException e)
376  {
377  e.printStackTrace();
378  Log.i(TAG, "toJSON() Erreur !");
379  }
380 
381  //Log.i(TAG, "toJSON() JSON = " + objet.toString());
382  return objet.toString();
383  }
384 
389  public void fromJSON(String strJSON)
390  {
391  try
392  {
393  //Log.i(TAG, "fromJSON() JSON = " + strJSON);
394  JSONObject json = new JSONObject(strJSON);
395 
396  this.code = json.getString("code");
397  this.estFavori = json.getBoolean("estFavori");
398  }
399  catch (JSONException e)
400  {
401  e.printStackTrace();
402  Log.i(TAG, "fromJSON() Erreur !");
403  }
404  }
405 }
void setCode(String code)
Mutateur de l&#39;attribut code.
boolean getEstReserve()
Accesseur de l&#39;attribut estReserve.
double temperature
Température de l&#39;espace de travail.
int superficie
Superficie de l&#39;espace de travail.
Communication entre l&#39;application et le portier.
String getDescription()
Accesseur de l&#39;attribut description.
String fabriquerTrameDemande(int typeTrame)
Fabrique la trame de demande.
static void sauvegarderDonneesEspaceDeTravail(EspaceDeTravail espaceDeTravail)
Enregistre les données d&#39;un espace de travail.
String getLieu()
Accesseur de l&#39;attribut lieu.
static final int MODIFICATION_INFORMATIONS
void setEstReserve(boolean estReserve)
Mutateur de l&#39;attribut estReserve.
String code
Code pour libérer l&#39;espace de travail.
void modifierInformations(List< String > parametres)
Modifie les informations de l&#39;espace de travail.
static String recupererDonneesEspaceDeTravail(EspaceDeTravail espaceDeTravail)
Récupère les données stockées d&#39;un espace de travail.
String getCode()
Accesseur de l&#39;attribut code.
void fromJSON(String strJSON)
Récupération de données JSON.
boolean extraireCode(String trame)
Extrait le code.
static final int NB_CHAMPS_DEMANDE_INFORMATIONS
String getAdresseIP()
Accesseur de l&#39;attribut adresseIP.
static final int MODIFICATION_DISPONIBILITE
int indiceDeConfort
Indice de confort de l&#39;espace de travail.
boolean estReserve
Disponibilité de l&#39;espace de travail.
void arreter()
Arrête la socket, donc la communication avec les portiers.
void liberer(String code)
Libère l&#39;espace de travail.
L&#39;activité principale de l&#39;application Meeting.
Definition: IHMMeeting.java:44
String fabriquerTrameModification(int typeTrame, List< String > parametres)
Fabrique la trame de modification.
static final int NB_CHAMPS_MODIFICATION_DISPONIBILITE
boolean estFavori
Si l&#39;espace de travail est en favori.
String nom
Nom de l&#39;espace de travail.
int getIndiceDeConfort()
Accesseur de l&#39;attribut indiceDeConfort.
int getSuperficie()
Accesseur de l&#39;attribut superficie.
String adresseIP
Adresse IP du portier.
void envoyer(String trame, String adressePortier)
Envoyer la trame.
void setHandler(Handler handler)
double getTemperature()
Accesseur de l&#39;attribut temperature.
boolean getEstFavori()
Accesseur de l&#39;attribut estFavori.
Communication communication
Attribut permettant d&#39;envoyer des requêtes.
String toJSON()
Création de données JSON.
void setEstFavori(boolean estFavori)
Mutateur de l&#39;attribut estFavori.
String lieu
Lieu de l&#39;espace de travail.
String description
Description de l&#39;espace de travail.
static final String TAG
TAG pour les logs.
EspaceDeTravail(String adresseIP)
Constructeur par défaut de la classe EspaceDeTravail.
void initialiserCommunication(Handler handler)
Initialise une communication.
static final int CHAMP_INDICE_DE_CONFORT
void demanderInformations()
Envoie une trame de demande d&#39;informations au portier si clic sur bouton rafraîchir.
String getNom()
Accesseur de l&#39;attribut nom.
void reserver()
Réserve l&#39;espace de travail.
boolean extraireInformations(String trame)
Extrait les informations d&#39;une trame DEMANDE_INFORMATIONS.