From 9f0e5ffc7ca69b526b71965a3335cc421bc67972 Mon Sep 17 00:00:00 2001 From: JLo'w Date: Sat, 7 May 2016 15:17:08 +0200 Subject: [PATCH] Un petit popup de déconnexion --- PremiereActivite/app/src/main/java/com/example/app_10p5/Dialogue.java | 27 +++++++++++++++++++++++++++ PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java | 26 ++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 PremiereActivite/app/src/main/java/com/example/app_10p5/Dialogue.java diff --git a/PremiereActivite/app/src/main/java/com/example/app_10p5/Dialogue.java b/PremiereActivite/app/src/main/java/com/example/app_10p5/Dialogue.java new file mode 100644 index 0000000..c8b9621 --- /dev/null +++ b/PremiereActivite/app/src/main/java/com/example/app_10p5/Dialogue.java @@ -0,0 +1,27 @@ +package com.example.app_10p5; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.DialogFragment; +import android.content.DialogInterface; +import android.os.Bundle; + +/** + * Created by Jean-loup Beaussart on 07/05/2016. + */ +public class Dialogue extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("Session expirée") + .setPositiveButton("ok", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + MainActivite parent = (MainActivite) getActivity(); + parent.disconnect(); + } + }); + // Create the AlertDialog object and return it + return builder.create(); + } +} diff --git a/PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java b/PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java index cbee03b..21063d2 100644 --- a/PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java +++ b/PremiereActivite/app/src/main/java/com/example/app_10p5/MainActivite.java @@ -19,6 +19,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.EditText;; import android.widget.Toast; +import android.os.Handler; import org.json.JSONObject; @@ -26,7 +27,6 @@ import java.net.URL; import java.net.URLEncoder; import java.util.HashMap; - /** * Created by Jean-loup Beaussart on 24/04/2016. */ @@ -41,13 +41,15 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr public static final int STATE_ANNULER= 6; public static final int STATE_REFAIRE = 7; - public static final long EXPIRATION = 1000*60*10; + public static final long EXPIRATION = 1000*10*1; private int mState; private String mToken; private int mDroit; private long mTimeToken; private String mUser; + private Handler mTimerHandler; + private Runnable mTimerRunnable; private NfcAdapter mNfcAdapter; @@ -66,6 +68,19 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr getActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary))); mNfcAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext()); + mTimerHandler = new Handler(); + mTimerRunnable = new Runnable() { + @Override + public void run() { + if(System.currentTimeMillis() - mTimeToken >= EXPIRATION){ + afficherPopup(); + } + else{ + mTimerHandler.postDelayed(this, 5000); + } + } + }; + if(savedInstanceState == null){ FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); @@ -398,6 +413,7 @@ public class MainActivite extends Activity implements ASyncResponse, main_tab_fr mUser = output.get("login").toString(); Snackbar.make(findViewById(R.id.coordinator), "Bonjour " + mUser + " vous êtes connecté pour " + EXPIRATION / (1000 * 60) + " minutes.", Snackbar.LENGTH_SHORT).show(); getFragmentManager().beginTransaction().replace(R.id.fragment_container, new main_tab_frag()).commit(); + mTimerRunnable.run(); break; case STATE_CREATION_COMPTE: 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 System.out.println(t.toString()); } } + + public void afficherPopup(){ + Dialogue d = new Dialogue(); + d.show(getFragmentManager(), null); + } + } -- libgit2 0.21.2