Commit 3fd9bdbe authored by Nastuzzi Samy's avatar Nastuzzi Samy
Browse files

BaseActivity

Creation of the BaseActivity
Move NFCActivity
Create activity hierarchy
parent 0cead7cd
......@@ -18,6 +18,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BaseActivity" />
</application>
</manifest>
\ No newline at end of file
package fr.utc.simde.payutc;
import android.os.Bundle;
import android.widget.TextView;
import fr.utc.simde.payutc.tools.CASConnexion;
import fr.utc.simde.payutc.tools.Dialog;
import fr.utc.simde.payutc.tools.NemopaySession;
/**
* Created by Samy on 26/10/2017.
*/
public abstract class BaseActivity extends NFCActivity {
private static final String LOG_TAG = "_LOG_TAG";
protected static Dialog dialog;
protected static NemopaySession nemopaySession;
protected static CASConnexion casConnexion;
protected void disconnect() {
nemopaySession.disconnect();
casConnexion.disconnect();
}
protected void unregister() {
nemopaySession.unregister();
disconnect();
dialog.errorDialog(getString(R.string.key_registration), getString(R.string.key_remove_temp));
}
}
......@@ -17,18 +17,14 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import fr.utc.simde.payutc.tools.NFCActivity;
import fr.utc.simde.payutc.tools.CASConnexion;
import fr.utc.simde.payutc.tools.Dialog;
import fr.utc.simde.payutc.tools.NemopaySession;
public class MainActivity extends NFCActivity {
public class MainActivity extends BaseActivity {
private static final String LOG_TAG = "_MainActivity";
private static final String service = "https://assos.utc.fr";
private static Dialog dialog;
private static NemopaySession nemopaySession;
private static CASConnexion casConnexion;
private static SharedPreferences sharedPreferences;
private static TextView AppConfigText;
......@@ -79,17 +75,10 @@ public class MainActivity extends NFCActivity {
badgeDialog(idBadge);
}
protected void disconnect() {
nemopaySession.disconnect();
casConnexion.disconnect();
}
@Override
protected void unregister() {
nemopaySession.unregister();
disconnect();
super.unregister();
((TextView) findViewById(R.id.text_app_registered)).setText(R.string.app_not_registred);
dialog.errorDialog(getString(R.string.key_registration), getString(R.string.key_remove_temp));
}
protected void delKey() {
......@@ -116,7 +105,7 @@ public class MainActivity extends NFCActivity {
nemopaySession.loginApp(key, casConnexion);
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
......@@ -157,7 +146,7 @@ public class MainActivity extends NFCActivity {
else
throw new Exception("Impossible to get CAS url");
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
......@@ -180,7 +169,7 @@ public class MainActivity extends NFCActivity {
casConnexion.connect(username, password);
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
......@@ -202,7 +191,7 @@ public class MainActivity extends NFCActivity {
casConnexion.addService(service);
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
......@@ -225,7 +214,7 @@ public class MainActivity extends NFCActivity {
nemopaySession.loginCas(casConnexion.getTicket(), service);
Thread.sleep(1000);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
......@@ -260,7 +249,7 @@ public class MainActivity extends NFCActivity {
nemopaySession.loginBadge(idBadge, pin);
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
......@@ -276,7 +265,7 @@ public class MainActivity extends NFCActivity {
else
dialog.errorDialog(getString(R.string.badge_dialog), getString(R.string.badge_error_no_rights) + ".\n" + nemopaySession.needRights(MainActivity.this));
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
});
......@@ -357,7 +346,7 @@ public class MainActivity extends NFCActivity {
try {
connectWithCAS(usernameInput.getText().toString(), passwordInput.getText().toString());
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
dialogInterface.cancel();
}
......@@ -404,7 +393,7 @@ public class MainActivity extends NFCActivity {
nemopaySession.registerApp(nameInput.getText().toString() + (nameInput.getText().toString().matches("^.* - ([0-9]{4})([/-])([0-9]{2})\\2([0-9]{2})$") ? "" : " - " + date), descriptionInput.getText().toString(), service);
Thread.sleep(100);
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
runOnUiThread(new Runnable() {
......
package fr.utc.simde.payutc.tools;
package fr.utc.simde.payutc;
/**
* Created by Samy on 24/10/2017.
......@@ -26,20 +26,20 @@ public abstract class NFCActivity extends Activity {
private static final String LOG_TAG = "_NFCActivity";
private static NfcAdapter NFCAdapter;
private static AlertDialog.Builder alertDialogBuilder;
private static AlertDialog.Builder NFCAlertDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NFCAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
alertDialogBuilder = new AlertDialog.Builder(this);
NFCAlertDialog = new AlertDialog.Builder(this);
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
this.registerReceiver(NFCReceiver, filter);
if (NFCAdapter == null) {
Toast.makeText(this, R.string.nfc_not_available, Toast.LENGTH_LONG).show();
alertDialogBuilder
NFCAlertDialog
.setTitle(R.string.nfc_not_available)
.setMessage(R.string.nfc_availability)
.setCancelable(false)
......@@ -50,7 +50,7 @@ public abstract class NFCActivity extends Activity {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
AlertDialog alertDialog = NFCAlertDialog.create();
alertDialog.show();
}
}
......@@ -124,7 +124,7 @@ public abstract class NFCActivity extends Activity {
protected void enableNFCDialog() {
Toast.makeText(this, R.string.nfc_not_enabled, Toast.LENGTH_SHORT).show();
alertDialogBuilder
NFCAlertDialog
.setTitle(R.string.nfc_not_enabled)
.setMessage(R.string.nfc_accessibility)
.setCancelable(true)
......@@ -153,7 +153,7 @@ public abstract class NFCActivity extends Activity {
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
AlertDialog alertDialog = NFCAlertDialog.create();
alertDialog.show();
}
}
\ No newline at end of file
......@@ -46,7 +46,7 @@ public class HTTPRequest {
get = args2String(this.getArgs, true);
}
catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
Log.d(LOG_TAG, "get: " + this.url + get);
......@@ -67,7 +67,7 @@ public class HTTPRequest {
Log.d(LOG_TAG, "code: " + Integer.toString(this.request.getResponseCode()) + ", error: " + e.getMessage());
}
catch (Exception e2) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
......@@ -83,7 +83,7 @@ public class HTTPRequest {
post = args2String(this.postArgs);
}
catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
Log.d(LOG_TAG, "post: " + this.url + get + ", data: " + post);
......@@ -109,7 +109,7 @@ public class HTTPRequest {
Log.d(LOG_TAG, "code: " + Integer.toString(this.request.getResponseCode()) + ", error: " + e.getMessage());
}
catch (Exception e2) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
}
......@@ -138,7 +138,7 @@ public class HTTPRequest {
return this.request.getResponseCode();
}
catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
return 500;
......@@ -152,7 +152,7 @@ public class HTTPRequest {
return this.request.getResponseMessage();
}
catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
Log.e(LOG_TAG, "error: " + e.getMessage());
}
return "";
......
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