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 @@
  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 19 import android.view.View;
20 20 import android.widget.EditText;;
21 21 import android.widget.Toast;
  22 +import android.os.Handler;
22 23  
23 24 import org.json.JSONObject;
24 25  
... ... @@ -26,7 +27,6 @@ import java.net.URL;
26 27 import java.net.URLEncoder;
27 28 import java.util.HashMap;
28 29  
29   -
30 30 /**
31 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 41 public static final int STATE_ANNULER= 6;
42 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 46 private int mState;
47 47 private String mToken;
48 48 private int mDroit;
49 49 private long mTimeToken;
50 50 private String mUser;
  51 + private Handler mTimerHandler;
  52 + private Runnable mTimerRunnable;
51 53  
52 54 private NfcAdapter mNfcAdapter;
53 55  
... ... @@ -66,6 +68,19 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
66 68 getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary)));
67 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 84 if(savedInstanceState == null){
70 85 FragmentManager fragmentManager = getFragmentManager();
71 86 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
... ... @@ -398,6 +413,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr
398 413 mUser = output.get("login").toString();
399 414 Snackbar.make(findViewById(R.id.coordinator), "Bonjour " + mUser + " vous êtes connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Snackbar.LENGTH_SHORT).show();
400 415 getFragmentManager().beginTransaction().replace(R.id.fragment_container, new main_tab_frag()).commit();
  416 + mTimerRunnable.run();
401 417 break;
402 418 case STATE_CREATION_COMPTE:
403 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 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 }
... ...