1 package com.example.groom;
3 import android.app.AlertDialog;
4 import android.bluetooth.BluetoothAdapter;
5 import android.bluetooth.BluetoothDevice;
6 import android.content.DialogInterface;
7 import android.content.Intent;
8 import android.os.Bundle;
9 import android.util.Log;
10 import android.view.View;
11 import android.widget.AdapterView;
12 import android.widget.ArrayAdapter;
13 import android.widget.Button;
14 import android.widget.EditText;
15 import android.widget.Spinner;
16 import android.widget.Toast;
17 import java.io.Serializable;
18 import java.util.ArrayList;
19 import java.util.List;
22 import androidx.appcompat.app.AppCompatActivity;
34 public class IHMConnexion extends AppCompatActivity implements View.OnClickListener {
39 private static final String
TAG =
"IHMConnexion";
77 protected void onCreate(Bundle savedInstanceState)
79 super.onCreate(savedInstanceState);
80 setContentView(R.layout.activity_communication);
82 groom =
new Groom(
"Eyraud",
"Grégory",
"étudiant",
"Libre",
true,
false);
97 listeGroom.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener()
100 public void onItemSelected(AdapterView<?> parent, View view,
int position,
long id)
102 Log.v(TAG,
"onItemSelected()");
103 for (
int i = 0; i < listeAppareilsBluetooth.size(); i++)
105 if (listeAppareilsBluetooth.get(i).getName().equals(listeNomsAppareilsBluetooth.get(position)))
107 Log.v(TAG,
"onItemSelected() " + listeAppareilsBluetooth.get(i).getName());
108 groom.
setNomDevice(listeAppareilsBluetooth.get(i).getName());
115 public void onNothingSelected(AdapterView<?> parent)
126 listeOccupant.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
128 public void onItemSelected(AdapterView<?> parent, View view,
int position,
long id)
130 Log.v(TAG,
"onItemSelected()" +
"Occupant choisi : " + listeOccupants.get(position));
131 String identite[] = listeOccupants.get(position).split(
" ");
136 public void onNothingSelected(AdapterView<?> parent) {
147 bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
148 if (bluetoothAdapter == null)
150 Toast.makeText(getApplicationContext(),
"Bluetooth non activé !", Toast.LENGTH_SHORT).show();
154 if (!bluetoothAdapter.isEnabled())
156 Toast.makeText(getApplicationContext(),
"Bluetooth non activé !", Toast.LENGTH_SHORT).show();
157 bluetoothAdapter.enable();
161 Toast.makeText(getApplicationContext(),
"Bluetooth activé", Toast.LENGTH_SHORT).show();
174 devices = bluetoothAdapter.getBondedDevices();
183 for (BluetoothDevice bluetoothDevice : devices)
185 listeAppareilsBluetooth.add(bluetoothDevice);
186 listeNomsAppareilsBluetooth.add(bluetoothDevice.getName());
194 List<Occupant> liste = occupants.
getListe();
195 for(
int i = 0; i<liste.size(); i++)
197 listeOccupants.add(liste.get(i).getNom() +
" " + liste.get(i).getPrenom() +
" " + liste.get(i).getFonction());
208 Log.d(TAG,
"initialiserRessourcesIHM()");
210 boutonConnexion = findViewById(R.id.bouttonConnexion);
211 boutonAjoutOccupant = findViewById(R.id.bouttonAjoutOccupant);
212 boutonRetraitOccupant = findViewById(R.id.bouttonRetraitOccupant);
214 boutonConnexion.setOnClickListener(
this);
215 boutonAjoutOccupant.setOnClickListener(
this);
216 boutonRetraitOccupant.setOnClickListener(
this);
218 listeGroom = findViewById(R.id.listeGroom);
219 listeOccupant = findViewById(R.id.listeOccupant);
221 listeNomsAppareilsBluetooth =
new ArrayList<String>();
222 listeAppareilsBluetooth =
new ArrayList<BluetoothDevice>();
223 listeOccupants =
new ArrayList<String>();
236 adapterGroom.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
237 listeGroom.setAdapter(adapterGroom);
239 adapterOccupant =
new ArrayAdapter<String>(
this, R.layout.support_simple_spinner_dropdown_item,
listeOccupants);
240 adapterOccupant.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
241 listeOccupant.setAdapter(adapterOccupant);
254 if (requestCode == ACTION_GROOM && resultCode == RESULT_OK)
256 groom = (
Groom) intent.getSerializableExtra(
"Groom");
265 switch (element.getId())
267 case R.id.bouttonAjoutOccupant:
272 case R.id.bouttonRetraitOccupant:
277 case R.id.bouttonConnexion:
281 intent.putExtra(
"Groom", (Serializable) groom);
282 startActivityForResult(intent, ACTION_GROOM);
298 toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
310 ajoutOccupant.setMessage(
"Veuillez saisir vos informations : ");
312 ajoutOccupant.setPositiveButton(
"Ajouter",
new DialogInterface.OnClickListener()
315 public void onClick(DialogInterface dialog,
int which)
317 nomOccupant = (EditText) ((AlertDialog) dialog).findViewById(R.id.nomOccupant);
318 prenomOccupant = (EditText) ((AlertDialog) dialog).findViewById(R.id.prenomOccupant);
319 fonctionOccupant = (EditText) ((AlertDialog) dialog).findViewById(R.id.fonctionOccupant);
320 Log.v(TAG,
"Occupant ajouté :" +
"Nom = " + nomOccupant.getText().toString() +
" " 321 +
"Prenom = " + prenomOccupant.getText().toString() +
" " 322 +
"Fonction = " + fonctionOccupant.getText().toString());
324 adapterOccupant.add(nomOccupant.getText().toString() +
" " + prenomOccupant.getText().toString() +
" " + fonctionOccupant.getText().toString());
326 occupants.
inserer(nomOccupant.getText().toString(), prenomOccupant.getText().toString(), fonctionOccupant.getText().toString());
329 ajoutOccupant.setNegativeButton(
"Annuler",
new DialogInterface.OnClickListener()
332 public void onClick(DialogInterface dialog,
int which)
334 Log.v(TAG,
"Ajout annulé");
346 retraitOccupant.setMessage(
"Vous êtes sur le point de supprimer l'occupant choisit.\r\n\r\n" +
"Êtes-vous sûr de vouloir le supprimer ?");
347 retraitOccupant.setPositiveButton(
"Supprimer",
new DialogInterface.OnClickListener()
350 public void onClick(DialogInterface dialog,
int which)
352 Log.v(TAG,
"Supression Occupant");
355 listeOccupant.setAdapter(adapterOccupant);
358 retraitOccupant.setNegativeButton(
"Annuler",
new DialogInterface.OnClickListener()
361 public void onClick(DialogInterface dialog,
int which)
363 Log.v(TAG,
"Suppression annulée");
void selectionnerOccupant()
Méthode permet de sélectionner un occupant dans la liste.
void lancerRecherchePeripherique()
Méthode qui lance la recherche de périphérique.
List< String > listeOccupants
Conteneur qui liste les occupants.
ArrayAdapter< String > adapterOccupant
Adaptateur pour mettre la liste des occupants dnas la liste déroulante listeOccupant.
Occupant getOccupant(String nom)
Déclaration de la classe Groom.
Déclaration de la classe IHMConnexion.
List< Occupant > getListe()
EditText fonctionOccupant
Le champ de texte pour écrire la fonction de l'occupnt.
Button boutonAjoutOccupant
Le bouton pour ajouter un occupant.
void setOccupant(Occupant occupant)
void activerBluetooth()
Méthode qui active le Bluetooth de l'appareil.
void selectionnerGroom()
Méthode permet de sélectionner un portier Groom Bluetooth dans la liste.
List< BluetoothDevice > listeAppareilsBluetooth
Conteneur qui liste les appareils bluetooth disponibles.
void onCreate(Bundle savedInstanceState)
Méthode appelée à la création de l'activité IHMConnexion.
void onClick(View element)
static final int ACTION_GROOM
Code de requête lors du début et de la fin de l'activité IHMGroom.
Déclaration de la classe IHMGroom.
Spinner listeOccupant
Liste déroulante des occupants.
void afficherToast(String message)
Méthode appelée pour donner des informations supplémentaires à l'utilisateur.
AlertDialog.Builder ajoutOccupant
Le builder qui permet de créer une fenêtre de dialogue d'ajout d'occupant.
EditText nomOccupant
Le champ de texte pour écrire le nom de l'occupant.
Toast toast
Le toast qui permet d'afficher des informations à l'utilisateur.
BluetoothAdapter bluetoothAdapter
L'objet BluetoothAdapter.
Groom groom
L'objet groom.
Button boutonConnexion
Le bouton pour se connecter à l'appareil Groom.
void setNomDevice(String nomDevice)
Accesseur set du nomDevice.
void initialiserListeDeroulante()
Méthode qui initialise la liste déroulante d'appareils Bluetooth appairés.
Set< BluetoothDevice > devices
Conteneur qui liste les appareils bluetooth disponibles sans doublons.
String getDisponibilite()
Accesseur get de la disponibilité
EditText prenomOccupant
Le champ de texte pour écrire le prenom de l'occupant.
void onActivityResult(int requestCode, int resultCode, Intent intent)
Méthode appelée à la fin de l'activité lancée et récupère l'objet groom envoyé
AlertDialog.Builder retraitOccupant
Le builder qui permet de créer une fenêtre de dialogue de retrait d'occupant.
List< String > listeNomsAppareilsBluetooth
Conteneur qui liste les noms des appareils bluetooth disponibles.
ArrayAdapter< String > adapterGroom
Adaptateur pour mettre la liste de noms des appareils dans la liste déroulante listeGroom.
void initialiserRetraitOccupant()
Preference getPreference()
static final String TAG
TAG pour les logs.
long inserer(String nom, String prenom, String fonction)
Spinner listeGroom
Liste déroulante des appareils bluetooth.
void initialiserAjoutOccupant()
Méthode appelée pour initialiser la boite de dialogue personnalisé pour l'ajout d'un occupant...
Button boutonRetraitOccupant
Le bouton pour retirer un occupant.
boolean getModeSonnette()
Accesseur get du mode de la sonnette.
void initialiserRessourcesIHM()
Méthode qui initialise les ressources du layout de l'activité IHMConnexion.