Skip to content
Snippets Groups Projects
Commit 4bfc42e8 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

partie 5 conn

parent 80846eb7
Branches
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/Git/application-android-iut/app/src/main/res/layout-land/activity_main.xml" value="0.1" />
<entry key="..\:/Git/application-android-iut/app/src/main/res/layout-land/activity_main.xml" value="0.19635416666666666" />
<entry key="..\:/Git/application-android-iut/app/src/main/res/layout/activity_main.xml" value="0.176" />
<entry key="..\:/Git/application-android-iut/app/src/main/res/layout/activity_num_table.xml" value="0.264" />
<entry key="..\:/Z IUT Orsay/AndroidStudioProjects/Pizzeria/app/src/main/res/layout-land/activity_main.xml" value="0.1" />
......
......@@ -23,4 +23,9 @@
android:exported="true" />
</application>
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
\ No newline at end of file
package com.slprojects.pizzeria;
import static com.slprojects.pizzeria.NumTable.numTable;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
......@@ -18,6 +20,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private ArrayList<Integer> idIndexes;
private ArrayList<Integer> numCommands;
private ArrayList<String> nomBoutons;
private int numTable;
private backTasks tacheDeFond;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -27,7 +31,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Intent intent = getIntent();
// On récupère le num de la table
int numTable = intent.getIntExtra(NumTable.numTable, 1);
numTable = intent.getIntExtra(NumTable.numTable, 1);
TextView textView = findViewById(R.id.textNumTable);
String numTableText = textView.getText().toString() + numTable;
textView.setText(numTableText);
......@@ -67,6 +71,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// On réserve les espaces pour les commandes
boutons.forEach((btn) -> numCommands.add(idIndexes.indexOf(btn.getId()), 0));
}
tacheDeFond = new backTasks();
tacheDeFond.execute();
}
@Override
......@@ -80,6 +86,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Button bouton = boutons.get(idIndexes.indexOf(v.getId()));
numCommands.set(idIndexes.indexOf(v.getId()), numCommands.get(idIndexes.indexOf(v.getId()))+1);
setButtonText(bouton);
// Envoie de la commande
tacheDeFond.registerCommand(numTable+nomBoutons.get(idIndexes.indexOf(v.getId())));
}catch ( Exception e ){
Log.e("Erreur", e.getMessage());
}
......
package com.slprojects.pizzeria;
import android.os.AsyncTask;
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
public class backTasks extends AsyncTask {
private Socket socket;
private PrintWriter output;
private BufferedReader input;
@Override
protected Object doInBackground(Object[] objects) {
int serverPort = 9874;
String address = "chadok.info";
try {
InetAddress ipAddress = InetAddress.getByName(address);
Log.i("backTasks:", "Connecting to " + address + ":"+ serverPort + "...");
socket = new Socket(ipAddress, serverPort);
Log.i("backTasks:", "Connected");
output = new PrintWriter(socket.getOutputStream(), true);
input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while(true){
String message = input.readLine();
if (message != null){
Log.i("backTasks", "received message: " + message);
}
}
} catch (Exception x) {
x.printStackTrace();
}
return null;
}
public void registerCommand(String command){
if(output != null){
Log.i("backTasks", "registered command: "+command);
output.write(command);
}
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
}
task clean(type: Delete) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment