Commit 008c2ed0 authored by Nastuzzi Samy's avatar Nastuzzi Samy

Initialisation

Creation of the repository
Creation of the Android Studio project
Creation of the first structure
parent bb98155e
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/PayUTC.iml" filepath="$PROJECT_DIR$/PayUTC.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "fr.utc.simde.payutc"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Samy\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package fr.utc.simde.payutc;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("fr.utc.simde.payutc", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.utc.simde.payutc">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package fr.utc.simde.payutc;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import fr.utc.simde.payutc.tools.HTTPRequest;
import fr.utc.simde.payutc.tools.NFCActivity;
public class MainActivity extends NFCActivity {
private static final String LOG_TAG = "MainActivity";
private static Boolean registered = false;
private static String login = "";
private static String password = "";
private static AlertDialog alertDialog;
private static TextView AppConfigText;
private static TextView AppRegisteredText;
private static Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppConfigText = (TextView) findViewById(R.id.text_app_config);
AppRegisteredText = (TextView) findViewById(R.id.text_app_registered);
loginButton = (Button) findViewById(R.id.button_login);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Thread thread = new Thread(new Runnable(){
@Override
public void run() {
try {
HTTPRequest test = new HTTPRequest("https://nastuzzi.fr");
test.addArg("coucou", "test");
Log.d(LOG_TAG, Integer.toString(test.get()));
Log.d(LOG_TAG, test.getResponse());
} catch (Exception e) {
Log.e(LOG_TAG, e.getMessage());
}
}
});
thread.start();
if (registered) {
Log.d(LOG_TAG, "Enregistré");
connectDialog();
} else {
Log.d(LOG_TAG, "Non enregistré");
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setTitle("Application non enregistrée")
.setMessage("Application non enregistrée")
.setCancelable(true)
.setPositiveButton("Continuer", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
setRegistered(true);
dialog.cancel();
}
})
.setNegativeButton("Quitter",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
MainActivity.this.finish();
}
});
createDialog(alertDialogBuilder);
}
}
});
}
@Override
protected void onIdentification(String id) {
Log.d(LOG_TAG, id);
badgeDialog(id);
}
protected void setRegistered(boolean p_registered) {
registered = p_registered;
AppRegisteredText.setText(registered ? R.string.app_registred : R.string.app_not_registred);
}
protected Boolean connectWithBadge(String idBadge, String pin) {
Log.d(LOG_TAG, "ID: " + idBadge);
Log.d(LOG_TAG, "PIN: " + pin);
final ProgressDialog ringProgressDialog = ProgressDialog.show(MainActivity.this, "Please wait ...", "Downloading Image ...", true);
ringProgressDialog.setCancelable(false);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(10000);
} catch (Exception e) {
}
ringProgressDialog.dismiss();
}
}).start();
return false;
}
protected void createDialog(AlertDialog.Builder alertDialogBuilder) {
if (alertDialog != null)
alertDialog.dismiss();
alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
protected void badgeDialog(String idBadge) {
final View pinView = getLayoutInflater().inflate(R.layout.dialog_badge, null);
final EditText pinInput = (EditText) pinView.findViewById(R.id.input_pin);
final String uid = idBadge;
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setTitle(R.string.badge_dialog)
.setView(pinView)
.setCancelable(true)
.setPositiveButton(R.string.connexion, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (pinInput.getText().toString().equals("")) {
Toast.makeText(MainActivity.this, R.string.pin_required, Toast.LENGTH_SHORT).show();
dialog.cancel();
badgeDialog(uid);
}
else {
connectWithBadge(uid, pinInput.getText().toString());
dialog.cancel();
}
}
})
.setNeutralButton(R.string.no_pin, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
connectWithBadge(uid, "0000");
dialog.cancel();
}
});
createDialog(alertDialogBuilder);
}
protected void connectDialog() {
final View loginView = getLayoutInflater().inflate(R.layout.dialog_login, null);
final EditText loginInput = (EditText) loginView.findViewById(R.id.input_login);
final EditText passwordInput = (EditText) loginView.findViewById(R.id.input_password);
loginInput.setText(login);
passwordInput.setText(password);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this);
alertDialogBuilder
.setTitle(R.string.login_dialog)
.setView(loginView)
.setCancelable(true)
.setPositiveButton(R.string.connexion, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (loginInput.getText().toString().equals("") || passwordInput.getText().toString().equals("")) {
Toast.makeText(MainActivity.this, R.string.login_and_password_required, Toast.LENGTH_SHORT).show();
dialog.cancel();
connectDialog();
}
else {
Log.d(LOG_TAG, "Login: " + loginInput.getText().toString());
Log.d(LOG_TAG, "Mdp: " + passwordInput.getText().toString());
passwordInput.setText("");
dialog.cancel();
}
}
})
.setNeutralButton(R.string.erase, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
loginInput.setText("");
passwordInput.setText("");
dialog.cancel();
connectDialog();
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(final DialogInterface dialog) {
login = loginInput.getText().toString();
password = passwordInput.getText().toString();
}
});
createDialog(alertDialogBuilder);
}
}
package fr.utc.simde.payutc.tools;
/**
* Created by Samy on 24/10/2017.
*/
public class CASConnexion {
private String url;
private String username;
private String password;
private String ticket;
public void CASConnexion(String url) {
this.url = url;
}
public void setConnexion(String username, String password) {
this.username = username;
this.password = password;
}
public Boolean connect() {
if (url.isEmpty() || username.isEmpty() || password.isEmpty())
return false;
return false;
}
}
package fr.utc.simde.payutc.tools;
/**
* Created by Samy on 24/10/2017.
*/
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class HTTPRequest {
public static final String LOG_TAG = "JsonApiClient";
public String url;
public HttpURLConnection request;
static Map<String, String> args = new HashMap<String, String>();
static Map<String, String> cookies = new HashMap<String, String>();
public HTTPRequest(String url) {
this.url = url;
}
public int get() throws IOException {
String data = "?" + args2String(this.args);
Log.d(LOG_TAG, "get: " + this.url + data);
this.request = (HttpURLConnection) (new URL(this.url + data)).openConnection();
this.request.setRequestMethod("GET");
this.request.setRequestProperty("Cookie", getCookiesHeader());
this.request.setUseCaches(false);
this.request.setDoOutput(true);
updateCookies(this.request.getHeaderFields().get("Set-Cookie"));
return this.request.getResponseCode();
}
public int post() throws IOException {
String data = args2String(this.args);
Log.d(LOG_TAG, "post: " + this.url + ", data: " + data);
this.request = (HttpURLConnection) (new URL(this.url)).openConnection();
this.request.setRequestMethod("POST");
this.request.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
this.request.setRequestProperty("Content-Length", Integer.toString(data.getBytes().length));
this.request.setRequestProperty("Cookie", getCookiesHeader());
this.request.setUseCaches(false);
this.request.setDoInput(true);
this.request.setDoOutput(true);
this.request.getOutputStream().write(data.getBytes());
updateCookies(this.request.getHeaderFields().get("Set-Cookie"));
return this.request.getResponseCode();
}
public Map<String, List<String>> getHeaders() {
if (this.request == null)
return null;
return this.request.getHeaderFields();
}
public String getHeader(String name) {
if (this.request == null)
return null;
return this.request.getHeaderField(name);
}
public String getResponseMessage(String name) throws IOException {
if (this.request == null)
return null;
return this.request.getResponseMessage();
}
public String getResponse() throws IOException {
if (this.request == null)
return null;
BufferedReader in = new BufferedReader(new InputStreamReader(this.request.getInputStream(), "UTF-8"));
StringBuilder builder = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null)
builder.append(inputLine);
in.close();
return builder.toString();
}
protected String args2String(Map<String, String> args) throws UnsupportedEncodingException {
String data = "";
for (String arg : args.keySet())
data += (URLEncoder.encode(arg, "UTF-8") + "=" + URLEncoder.encode(args.get(arg), "UTF-8") + "&");
return data.substring(0, data.equals("") ? 0 : data.length() - 1);
}
public Boolean addArg(String key, String value) {
if (this.args.containsKey(key))
return false;
else
this.args.put(key, value);
return true;
}
public void setArg(String key, String value) {
this.args.put(key, value);
}
public Boolean delArg(String key) {
if (this.args.containsKey(key))
this.args.remove(key);
else
return false;
return true;
}
synchronized String getCookiesHeader() {
String data = "";
for (String cookie : cookies.keySet())
data += cookie + "=" + cookies.get(cookie) + "; ";
return data;
}
synchronized void updateCookies(List<String> cookiesHeader) {
if (cookiesHeader != null) {
Log.d(LOG_TAG, "cookies : " + cookiesHeader);
for (String cookie : cookiesHeader) {
try {
cookie = cookie.substring(0, cookie.indexOf(";"));
String cookieName = cookie.substring(0, cookie.indexOf("="));
String cookieValue = cookie.substring(cookie.indexOf("=") + 1);
this.cookies.put(cookieName, cookieValue);
Log.d(LOG_TAG, cookieName + " = " + cookieValue);
}
catch (Exception ex) {
Log.w(LOG_TAG, "error parsing cookie : '" + cookie + "'", ex);
}
}
}
}
}
\ No newline at end of file
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.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 abstract class NFCActivity extends Activity {
private static final String LOG_TAG = "NFCActivity";
private NfcAdapter NFCAdapter;
private static AlertDialog.Builder alertDialogBuilder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NFCAdapter = NfcAdapter.getDefaultAdapter(getApplicationContext());
alertDialogBuilder = 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
.setTitle(R.string.nfc_not_available)