Commit 6360f887 authored by Sli's avatar Sli

Merge branch 'application' into 'master'

Application

Mise à jour de l'application utilisant le serveur pour validé l'unicité d'un billet

See merge request !2
parents ea51d5fe e320fbcc
Gala
\ No newline at end of file
Development
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="android" withSubpackages="true" static="false" />
<emptyLine />
<package name="com" withSubpackages="true" static="false" />
<emptyLine />
<package name="junit" withSubpackages="true" static="false" />
<emptyLine />
<package name="net" withSubpackages="true" static="false" />
<emptyLine />
<package name="org" withSubpackages="true" static="false" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="true" />
<emptyLine />
</value>
</option>
<option name="RIGHT_MARGIN" value="100" />
<AndroidXmlCodeStyleSettings>
<option name="USE_CUSTOM_SETTINGS" value="true" />
</AndroidXmlCodeStyleSettings>
<Objective-C-extensions>
<option name="GENERATE_INSTANCE_VARIABLES_FOR_PROPERTIES" value="ASK" />
<option name="RELEASE_STYLE" value="IVAR" />
<option name="TYPE_QUALIFIERS_PLACEMENT" value="BEFORE" />
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" />
<pair source="c" header="h" />
</extensions>
</Objective-C-extensions>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_NAMESPACE>Namespace:</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_NAMESPACE>Namespace:</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:layout_.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:width</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:height</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
</value>
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default (1)" />
</component>
</project>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="djamel" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
......@@ -3,16 +3,15 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" />
<option name="gradleJvm" value="1.7" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
......
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintDeprecated" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidLintRtlHardcoded" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
......@@ -37,25 +37,10 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" 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>
<component name="masterDetails">
<states>
<state key="ScopeChooserConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
......@@ -23,4 +23,6 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
}
......@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="djamelfel.gala" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/gala_logo"
......@@ -11,15 +13,15 @@
<activity
android:name=".Read_QR_Code"
android:label="@string/app_name">
</activity>
<activity
android:name=".Login"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Settings"
android:label="@string/settings">
</activity>
</application>
</manifest>
</manifest>
\ No newline at end of file
......@@ -3,21 +3,26 @@ package djamelfel.gala;
import android.os.Parcel;
import android.os.Parcelable;
import java.io.Serializable;
/**
* Created by djamel on 17/10/15.
*/
public class Key_List implements Parcelable {
int id;
String key;
public class Key_List implements Parcelable, Serializable {
private int id;
private String key;
private boolean is_child;
public Key_List(int id, String key) {
public Key_List(int id, String key, boolean is_child) {
this.id = id;
this.key = key;
this.is_child = is_child;
}
protected Key_List(Parcel in) {
this.id = in.readInt();
this.key = in.readString();
this.is_child = in.readByte() != 0;
}
public int getId() {
......@@ -28,6 +33,10 @@ public class Key_List implements Parcelable {
return this.key;
}
public boolean getIs_child() {
return this.is_child;
}
@Override
public int describeContents() {
return 0;
......@@ -37,6 +46,7 @@ public class Key_List implements Parcelable {
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.id);
dest.writeString(this.key);
dest.writeByte((byte) (this.is_child ? 1 : 0));
}
......
package djamelfel.gala;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import org.apache.http.conn.util.InetAddressUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import cz.msebera.android.httpclient.Header;
public class Login extends ActionBarActivity implements View.OnClickListener {
private EditText _ipAddress;
private EditText _portNumber;
private ArrayList<Key_List> key_list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
_ipAddress = (EditText)findViewById(R.id.text_ipAddress);
_portNumber = (EditText)findViewById(R.id.text_port);
Button validateIPAddress = (Button) findViewById(R.id.button_ipAddress);
validateIPAddress.setOnClickListener(this);
key_list = new ArrayList<Key_List>();
}
@Override
public void onClick(View vue) {
final Button button = (Button)findViewById(R.id.button_ipAddress);
button.setEnabled(false);
button.setText(getText(R.string.connecting));
String myIpString = _ipAddress.getText().toString();
String myPortString = _portNumber.getText().toString();
final String server = "http://" + myIpString + ":" + myPortString;
// check if ip address is right
if (!InetAddressUtils.isIPv4Address(myIpString)) {
display(getString(R.string.errorIP), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
else if (myPortString.isEmpty()) {
display(getString(R.string.errorPORT), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
else {
AsyncHttpClient client = new AsyncHttpClient();
client.setTimeout(5000);
client.get(server + "/keys", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
JSONObject element;
try {
for (int index = 0; index < response.length(); index++) {
element = response.getJSONObject(index);
Key_List key = new Key_List(element.getInt("id"), element.getString
("key"), element.getBoolean("is_child"));
key_list.add(key);
}
} catch (JSONException e) {
e.printStackTrace();
}
//Send key_list to next activity
Intent intent = new Intent(Login.this, Read_QR_Code.class);
intent.putParcelableArrayListExtra("key_list", key_list);
intent.putExtra("server", server);
startActivity(intent);
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
display(getString(R.string.serverError), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
display(getString(R.string.serverError), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
display(getString(R.string.serverError), false);
button.setEnabled(true);
button.setText(getText(R.string.connect));
}
});
}
}
/**
*
* @param msg
* @param success
* @info print on screen a message in red if success in false or green if it's true
*/
public void display(String msg, boolean success) {
LayoutInflater inflater = getLayoutInflater();
View layout;
if(success) {
layout = inflater.inflate(R.layout.toast_success,
(ViewGroup) findViewById(R.id.toast_success));
}
else {
layout = inflater.inflate(R.layout.toast_failure,
(ViewGroup) findViewById(R.id.toast_failure));
}
TextView text = (TextView)layout.findViewById(R.id.text);
text.setTextSize(20);
text.setText(msg.toUpperCase());
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
\ No newline at end of file
package djamelfel.gala;
import android.app.ActionBar;
import android.content.Intent;
import android.database.MatrixCursor;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Iterator;
public class Settings extends ActionBarActivity implements View.OnClickListener {
private ArrayList<Key_List> key_list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Intent intent = getIntent();
if (intent != null) {
Log.i("intent", "variable");
key_list = intent.getParcelableArrayListExtra("key_list");
}
if (key_list != null) {
updateView();
} else {
key_list = new ArrayList<Key_List>();
}
findViewById(R.id.new_key).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.new_key:
EditText id = (EditText)findViewById(R.id.id);
EditText key = (EditText)findViewById(R.id.key);
String idS = id.getText().toString();
String keyS = key.getText().toString();
if (idS.isEmpty() || keyS.isEmpty()) {
Toast.makeText(getApplicationContext(), R.string.empty_text_area, Toast
.LENGTH_LONG).show();
}
else {
key_list.add(new Key_List(Integer.parseInt(idS), keyS));
id.setText("");
key.setText("");
updateView();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(Settings.this, Read_QR_Code.class);
intent.putParcelableArrayListExtra("key_list", key_list);
startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void updateView() {
String[] columns = new String[]{"_id", "id", "key"};
MatrixCursor matrixCursor = new MatrixCursor(columns);
startManagingCursor(matrixCursor);
Iterator<Key_List> itr = key_list.iterator();
while(itr.hasNext()) {
Key_List kl = itr.next();
matrixCursor.addRow(new Object[]{
0, kl.getId(), kl.getKey()
});
}
String[] from = new String[]{"id", "key"};
int[] to = new int[]{R.id.textViewCol1, R.id.textViewCol2};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row_item,
matrixCursor, from, to, 0);
ListView lv = (ListView) findViewById(R.id.listView);
lv.setAdapter(adapter);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/label_ipAddress"
android:id="@+id/textView"
android:textSize="18dp"/>
<Space
android:layout_width="120px"
android:layout_height="20px"
android:layout_alignTop="@+id/textView"
android:layout_toRightOf="@+id/textView"
android:id="@+id/space1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_ipAddress"
android:hint="@string/label_ipAddress"
android:inputType="text"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_alignTop="@+id/textView"
android:textSize="18dp"
android:layout_toRightOf="@+id/space1"
android:visibility="visible"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"