1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| public class recuperationJson extends AppCompatActivity implements getData.ReturnValue {
private getData data=null;
private JSONObject jObj = null;
private String json_url = "http://192.168.0.14/projet/php/fichier.php";//adresse ip du serveur + chemin
final private Handler handler = new Handler(); // Handler car une asynctask ne peut pas être eappelé par un autre thread que l'ui
private Timer timer = new Timer();
private TextView Mpx, Al, Ar, Rds, Pilots, Frequence, Rf,idsighfox;
private int mpxInt, arInt, alInt, rdsInt, pilotsInt, frequenceInt, rfInt,
mpxIntMin,mpxIntMax,arIntMin,arIntMax,alIntMin,alIntMax,rdsIntMin,rdsIntMax,pilotIntMin,pilotIntMax,frequenceIntMin,frequenceIntMax,rfInMin,rfIntMax;
private String longitude,altitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/******************************************************************************************/
//logo multisys
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.multi);
getSupportActionBar().setDisplayShowTitleEnabled(false);
/******************************************************************************************/
//Instancie getData et l'execute
data = new getData(json_url);
data.setReturnListener(this);
data.execute((Void) null);
/**********************************************************************************************/
//créer le timer
timer.schedule(MyTimerTask, 0, 5000/*ms*/);//commence a 0 seconde toutes les 5 seconds
/**********************************************************************************************/
//Associe les widgets aux variables de la vue main
idsighfox=(TextView)findViewById(R.id.nomAntenne);
Mpx = (TextView) findViewById(R.id.mpx);
Ar = (TextView) findViewById(R.id.ar);
Al = (TextView) findViewById(R.id.al);
Rds = (TextView) findViewById(R.id.rds);
Pilots = (TextView) findViewById(R.id.pilots);
Frequence = (TextView) findViewById(R.id.frequence);
Rf = (TextView) findViewById(R.id.rf);
/**********************************************************************************************/
}
//Méthode qui renvoie la valeur de getData
@Override
public void renvoyerValeurString(String valeurARenvoyer) {
data = null;
//Ici je récupère directement mon json contenu dans la variable valeurARenvoyer
try {
// Json Object {}
/**************************************************************************************/
//Insere les valeurs du json dans la classe valeur qui contient les get et set
String mpxMin,mpxMax,mpx,rdsMin,rdsMax, rds,alMax,alMin, al,arMax,arMin, ar,frequenceMax,frequenceMin, frequence,pilotMax,pilotMin, pilot, id, id_SIGFOX, timestamps,rfMax,rfMin, rf;
jObj = new JSONObject(valeurARenvoyer);
mpx = jObj.getString("mpx");//se place a l'endroit MPX du json et obtient le string apres les :
mpxMin=jObj.getString("mpxMin");
mpxMax=jObj.getString("mpxMax");
rds = jObj.getString("rds");
rdsMin = jObj.getString("rdsMin");
rdsMax = jObj.getString("rdsMax");
rf = jObj.getString("rf");
rfMin = jObj.getString("rfMin");
rfMax = jObj.getString("rfMax");
frequence = jObj.getString("frequence");
frequenceMin = jObj.getString("frequenceMin");
frequenceMax = jObj.getString("frequenceMax");
timestamps = jObj.getString("timestamp");
id = jObj.getString("id");
id_SIGFOX = jObj.getString("idsighfox");
pilot = jObj.getString("pilot");
pilotMin = jObj.getString("pilotMin");
pilotMax = jObj.getString("pilotMax");
al = jObj.getString("al");
alMin = jObj.getString("alMin");
alMax = jObj.getString("alMax");
ar = jObj.getString("ar");
arMin = jObj.getString("arMin");
arMax = jObj.getString("arMax");
longitude=jObj.getString("longitude");
altitude=jObj.getString("altitude");
/**************************************************************************************/
//Valeurs
Valeur valeurs = new Valeur (mpx, rds, al, ar, pilot, frequence, id, timestamps, id_SIGFOX, rf );
//Transforme les valeurs String en Int
mpxInt = Integer.parseInt(valeurs.getMpx());
arInt = Integer.parseInt(valeurs.getAr());
alInt = Integer.parseInt(valeurs.getAl());
rdsInt = Integer.parseInt(valeurs.getRds());
rfInt = Integer.parseInt(valeurs.getRf());
frequenceInt = Integer.parseInt(valeurs.getFrequence());
pilotsInt = Integer.parseInt(valeurs.getPilots());
/**************************************************************************************/
//Seuils
Seuil seuil=new Seuil(mpxMin,mpxMax,rdsMin,rdsMax,alMax,alMin,arMax,arMin,pilotMin,pilotMax,frequenceMin,frequenceMax,rfMin,rfMax);
//Transforme les valeurs String en Int
mpxIntMin=Integer.parseInt(seuil.getMpxMin());
mpxIntMax=Integer.parseInt(seuil.getMpxMax());
arIntMin=Integer.parseInt(seuil.getArMin());
arIntMax=Integer.parseInt(seuil.getArMax());
alIntMin=Integer.parseInt(seuil.getAlMin());
alIntMax=Integer.parseInt(seuil.getAlMax());
rdsIntMin=Integer.parseInt(seuil.getRdsMin());
rdsIntMax=Integer.parseInt(seuil.getRdsMax());
rfInMin=Integer.parseInt(seuil.getRfMin());
rfIntMax=Integer.parseInt(seuil.getRfMax());
frequenceIntMin=Integer.parseInt(seuil.getFrequenceMin());
frequenceIntMax=Integer.parseInt(seuil.getFrequenceMax());
pilotIntMin=Integer.parseInt(seuil.getPilotMin());
pilotIntMax=Integer.parseInt(seuil.getPilotMax());
/**************************************************************************************/
idsighfox.setText(valeurs.getId_SIGFOX());
if (mpxInt <mpxIntMin || mpxInt > mpxIntMax ){
Mpx.setText(valeurs.getMpx());//affiche la valeur mpx dans le textView
Mpx.setTextColor(Color.parseColor("#DF0101"));//red
} else {
Mpx.setText(valeurs.getMpx());
} |
Partager