Commit 6ebf3522 authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

Internet connection management

Manage internet connection
Popup if no internet is available
parent 5f2047e9
......@@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
......
......@@ -3,7 +3,9 @@ package fr.utc.simde.payutc;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.BaseAdapter;
......@@ -20,6 +22,7 @@ import fr.utc.simde.payutc.tools.CASConnexion;
import fr.utc.simde.payutc.tools.Config;
import fr.utc.simde.payutc.tools.Dialog;
import fr.utc.simde.payutc.tools.HTTPRequest;
import fr.utc.simde.payutc.tools.InternetBroadcast;
import fr.utc.simde.payutc.tools.NemopaySession;
/**
......@@ -28,15 +31,21 @@ import fr.utc.simde.payutc.tools.NemopaySession;
public abstract class BaseActivity extends NFCActivity {
private static final String LOG_TAG = "_BaseActivity";
protected static Dialog dialog;
protected static NemopaySession nemopaySession;
protected static CASConnexion casConnexion;
protected static InternetBroadcast internetBroadcast;
protected static Config config;
protected static Dialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.internetBroadcast = new InternetBroadcast();
registerReceiver(this.internetBroadcast, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
dialog = new Dialog(this);
}
......@@ -44,6 +53,7 @@ public abstract class BaseActivity extends NFCActivity {
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(this.internetBroadcast);
dialog.dismiss();
}
......
......@@ -3,10 +3,12 @@ package fr.utc.simde.payutc;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
......@@ -356,7 +358,7 @@ public class MainActivity extends BaseActivity {
.setTitle(R.string.badge_dialog)
.setView(pinView)
.setCancelable(false)
.setPositiveButton(R.string.connexion, new DialogInterface.OnClickListener() {
.setPositiveButton(R.string.connect, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (pinInput.getText().toString().equals("")) {
Toast.makeText(MainActivity.this, R.string.pin_required, Toast.LENGTH_SHORT).show();
......@@ -399,7 +401,7 @@ public class MainActivity extends BaseActivity {
.setTitle(R.string.username_dialog)
.setView(usernameView)
.setCancelable(false)
.setPositiveButton(R.string.connexion, new DialogInterface.OnClickListener() {
.setPositiveButton(R.string.connect, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int id) {
if (usernameInput.getText().toString().equals("") || passwordInput.getText().toString().equals("")) {
if (!usernameInput.getText().toString().equals(""))
......
......@@ -4,8 +4,11 @@ package fr.utc.simde.payutc.tools;
* Created by Samy on 24/10/2017.
*/
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode;
......
package fr.utc.simde.payutc.tools;
/**
* Created by Samy on 24/10/2017.
*/
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.Ndef;
import android.os.Bundle;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.Toast;
import fr.utc.simde.payutc.R;
public class InternetBroadcast extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
if (!checkInternet(context))
enableInternetDialog(context);
}
public boolean checkInternet(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
}
protected void enableInternetDialog(final Context context) {
Toast.makeText(context, R.string.internet_not_available, Toast.LENGTH_SHORT).show();
AlertDialog.Builder internetAlertDialog = new AlertDialog.Builder(context);
internetAlertDialog
.setTitle(R.string.connection)
.setMessage(R.string.internet_accessibility)
.setCancelable(true)
.setPositiveButton(R.string.pass, null)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
if (!checkInternet(context))
enableInternetDialog(context);
}
});
AlertDialog alertDialog = internetAlertDialog.create();
alertDialog.show();
}
}
\ No newline at end of file
package fr.utc.simde.payutc.tools;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -447,8 +450,9 @@ public class NemopaySession {
throw new Exception(this.serviceText + " " + service + " " + this.notFound);
else if (responseCode == 400)
throw new Exception(this.serviceText + " " + service + " " + this.badRequest);
else if (responseCode == 500 || responseCode == 503)
else if (responseCode == 500 || responseCode == 503) {
throw new Exception(this.serviceText + " " + service + " " + this.internalError);
}
else
throw new Exception(this.serviceText + " " + service + " " + this.errorRequest + " " + responseCode);
}
......
......@@ -52,7 +52,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:text="@string/connexion" />
android:text="@string/connect" />
</LinearLayout>
......
......@@ -3,7 +3,8 @@
<string name="payutc">PayUTC</string>
<string name="hello">Pour se connecter, clique sur\n le bouton ou scanne ton badge</string>
<string name="ok">Ok</string>
<string name="connexion">Se connecter</string>
<string name="connect">Se connecter</string>
<string name="connection">Connexion</string>
<string name="register">Enregistrer</string>
<string name="applicate">Appliquer</string>
<string name="reload">Recharger</string>
......@@ -42,8 +43,10 @@
<string name="nfc_not_available">NFC non disponible</string>
<string name="nfc_not_enabled">NFC non activé</string>
<string name="nfc_availability">L\'application nécessite que le NFC soit disponible sur le téléphone pour que celle-ci fonctionne correctement. Elle ne pourra donc être utilisée sur ce téléphone.</string>
<string name="nfc_accessibility">L\'application nécessite que le NFC soit activé pour fonctionner correctement.</string>
<string name="nfc_availability">L\'application nécessite que le NFC soit disponible sur le téléphone pour que celle-ci fonctionne correctement. Elle ne pourra donc être utilisée sur ce téléphone</string>
<string name="nfc_accessibility">L\'application nécessite que le NFC soit activé pour fonctionner correctement</string>
<string name="internet_not_available">L\'appareil n\'est pas connecté à internet</string>
<string name="internet_accessibility">L\'application nécessite d\'être connecté à internet pour fonctionner correctement.</string>
<string name="cas_connection">Connexion via CAS</string>
<string name="cas_in_url">Récupération du lien CAS</string>
<string name="cas_in_connection">Connexion au CAS</string>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment