Commit 9f0e5ffc7ca69b526b71965a3335cc421bc67972

Authored by JLo'w
1 parent 2596297c

Un petit popup de déconnexion

PremiereActivite/app/src/main/java/com/example/app_10p5/Dialogue.java 0 → 100644
@@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
  1 +package com.example.app_10p5;
  2 +
  3 +import android.app.AlertDialog;
  4 +import android.app.Dialog;
  5 +import android.app.DialogFragment;
  6 +import android.content.DialogInterface;
  7 +import android.os.Bundle;
  8 +
  9 +/**
  10 + * Created by Jean-loup Beaussart on 07/05/2016.
  11 + */
  12 +public class Dialogue extends DialogFragment {
  13 + @Override
  14 + public Dialog onCreateDialog(Bundle savedInstanceState) {
  15 + // Use the Builder class for convenient dialog construction
  16 + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  17 + builder.setMessage("Session expirée")
  18 + .setPositiveButton("ok", new DialogInterface.OnClickListener() {
  19 + public void onClick(DialogInterface dialog, int id) {
  20 + MainActivite parent = (MainActivite) getActivity();
  21 + parent.disconnect();
  22 + }
  23 + });
  24 + // Create the AlertDialog object and return it
  25 + return builder.create();
  26 + }
  27 +}
PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java
@@ -19,6 +19,7 @@ import android.view.MenuItem; @@ -19,6 +19,7 @@ import android.view.MenuItem;
19 import android.view.View; 19 import android.view.View;
20 import android.widget.EditText;; 20 import android.widget.EditText;;
21 import android.widget.Toast; 21 import android.widget.Toast;
  22 +import android.os.Handler;
22 23
23 import org.json.JSONObject; 24 import org.json.JSONObject;
24 25
@@ -26,7 +27,6 @@ import java.net.URL; @@ -26,7 +27,6 @@ import java.net.URL;
26 import java.net.URLEncoder; 27 import java.net.URLEncoder;
27 import java.util.HashMap; 28 import java.util.HashMap;
28 29
29 -  
30 /** 30 /**
31 * Created by Jean-loup Beaussart on 24/04/2016. 31 * Created by Jean-loup Beaussart on 24/04/2016.
32 */ 32 */
@@ -41,13 +41,15 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -41,13 +41,15 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
41 public static final int STATE_ANNULER= 6; 41 public static final int STATE_ANNULER= 6;
42 public static final int STATE_REFAIRE = 7; 42 public static final int STATE_REFAIRE = 7;
43 43
44 - public static final long EXPIRATION = 1000*60*10; 44 + public static final long EXPIRATION = 1000*10*1;
45 45
46 private int mState; 46 private int mState;
47 private String mToken; 47 private String mToken;
48 private int mDroit; 48 private int mDroit;
49 private long mTimeToken; 49 private long mTimeToken;
50 private String mUser; 50 private String mUser;
  51 + private Handler mTimerHandler;
  52 + private Runnable mTimerRunnable;
51 53
52 private NfcAdapter mNfcAdapter; 54 private NfcAdapter mNfcAdapter;
53 55
@@ -66,6 +68,19 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -66,6 +68,19 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
66 getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); 68 getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
67 mNfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext()); 69 mNfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
68 70
  71 + mTimerHandler = new Handler();
  72 + mTimerRunnable = new Runnable() {
  73 + @Override
  74 + public void run() {
  75 + if(System.currentTimeMillis() - mTimeToken >= EXPIRATION){
  76 + afficherPopup();
  77 + }
  78 + else{
  79 + mTimerHandler.postDelayed(this, 5000);
  80 + }
  81 + }
  82 + };
  83 +
69 if(savedInstanceState == null){ 84 if(savedInstanceState == null){
70 FragmentManager fragmentManager = getFragmentManager(); 85 FragmentManager fragmentManager = getFragmentManager();
71 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 86 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
@@ -398,6 +413,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -398,6 +413,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
398 mUser = output.get("login").toString(); 413 mUser = output.get("login").toString();
399 Snackbar.make(findViewById(R.id.coordinator), "Bonjour " + mUser + " vous êtes connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Snackbar.LENGTH_SHORT).show(); 414 Snackbar.make(findViewById(R.id.coordinator), "Bonjour " + mUser + " vous êtes connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Snackbar.LENGTH_SHORT).show();
400 getFragmentManager().beginTransaction().replace(R.id.fragment_container, new main_tab_frag()).commit(); 415 getFragmentManager().beginTransaction().replace(R.id.fragment_container, new main_tab_frag()).commit();
  416 + mTimerRunnable.run();
401 break; 417 break;
402 case STATE_CREATION_COMPTE: 418 case STATE_CREATION_COMPTE:
403 Snackbar.make(findViewById(R.id.coordinator), "Client créé avec un solde de " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show(); 419 Snackbar.make(findViewById(R.id.coordinator), "Client créé avec un solde de " + output.get("soldeNouveau") + "€", Snackbar.LENGTH_LONG).setAction("ANNULER", new viewListenerAnnulerRefaire(output.getInt("idTransaction"), this, true)).show();
@@ -482,4 +498,10 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr @@ -482,4 +498,10 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
482 System.out.println(t.toString()); 498 System.out.println(t.toString());
483 } 499 }
484 } 500 }
  501 +
  502 + public void afficherPopup(){
  503 + Dialogue d = new Dialogue();
  504 + d.show(getFragmentManager(), null);
  505 + }
  506 +
485 } 507 }