diff --git a/android/app/build.gradle b/android/app/build.gradle index b43ad6e..019071f 100755 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,10 +1,11 @@ +//noinspection GradleDependency apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "projet.license" - minSdkVersion 21 + minSdkVersion 23 targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -12,9 +13,9 @@ android { } sourceSets { // ajout de la partie commune - main.java.srcDirs += '../../../javastd/commun/src/main/java' + main.java.srcDirs += '../../javastd/commun/src/main/java' // et quand il y aura des tests... - // test.java.srcDirs += '../../../javastd/commun/src/test/java' + test.java.srcDirs += '../../javastd/commun/src/test/java' } buildTypes { release { @@ -32,13 +33,26 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + + implementation 'androidx.appcompat:appcompat:1.0.2' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1' + implementation('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' // car cela est dans le java android } + testImplementation 'androidx.test:core:1.1.0' + + androidTestImplementation 'androidx.test:rules:1.1.1' + androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' + //noinspection GradleDynamicVersion + androidTestImplementation 'com.android.support:support-annotations:28+' + } diff --git a/android/app/src/androidTest/java/projet/license/MyViewAction.java b/android/app/src/androidTest/java/projet/license/MyViewAction.java new file mode 100644 index 0000000..6497d88 --- /dev/null +++ b/android/app/src/androidTest/java/projet/license/MyViewAction.java @@ -0,0 +1,56 @@ +package projet.license; + +import android.os.SystemClock; +import android.view.MotionEvent; +import android.view.View; + +import org.hamcrest.Matcher; + +import androidx.test.espresso.UiController; +import androidx.test.espresso.ViewAction; +import androidx.test.espresso.matcher.ViewMatchers; + +public class MyViewAction { + public static ViewAction singleTouchAt(final int x, final int y, final int action) { + return new ViewAction() { + @Override + public void perform(UiController uiController, View view) { + long date = SystemClock.uptimeMillis(); + MotionEvent me = MotionEvent.obtain(date, date, action, x, y, 0); + view.onTouchEvent(me); + } + + @Override + public String getDescription() { + return "touch "; + } + + @Override + public Matcher getConstraints() { + return ViewMatchers.isAssignableFrom(View.class); + } + }; + } + + + public static ViewAction pamatreziedSingleTouchAt(final float x, final float y, final int action, final long d1, final long d2, final int meta) { + return new ViewAction() { + @Override + public void perform(UiController uiController, View view) { + MotionEvent me = MotionEvent.obtain(d1, d2, action, x, y, meta); + view.onTouchEvent(me); + } + + @Override + public String getDescription() { + return "touch "; + } + + @Override + public Matcher getConstraints() { + return ViewMatchers.isAssignableFrom(View.class); + } + }; + } + +} diff --git a/android/app/src/androidTest/java/projet/license/RiddleGame.java b/android/app/src/androidTest/java/projet/license/RiddleGame.java new file mode 100644 index 0000000..d0f442b --- /dev/null +++ b/android/app/src/androidTest/java/projet/license/RiddleGame.java @@ -0,0 +1,84 @@ +package projet.license; + + +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import androidx.test.espresso.ViewInteraction; +import androidx.test.rule.ActivityTestRule; +import androidx.test.runner.AndroidJUnit4; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; +import static org.hamcrest.core.AllOf.allOf; + + +@RunWith(AndroidJUnit4.class) +public class RiddleGame { + + @Rule + public ActivityTestRule mActivityTestRule = new ActivityTestRule<>(LoginActivity.class); + + @Test + public void riddleGame() { + ViewInteraction button = onView( + allOf(withId(R.id.loginConfim), withText("confirm"), + childAtPosition( + childAtPosition( + withId(android.R.id.content), + 0), + 3), + isDisplayed())); + button.perform(click()); + + ViewInteraction button2 = onView( + allOf(withId(R.id.Riddle), withText("RIDDLES"), + childAtPosition( + childAtPosition( + withId(android.R.id.content), + 0), + 3), + isDisplayed())); + button2.perform(click()); + + ViewInteraction button3 = onView( + allOf(withId(R.id.start), withText("START"), + childAtPosition( + childAtPosition( + withId(android.R.id.content), + 0), + 2), + isDisplayed())); + button3.perform(click()); + } + + private static Matcher childAtPosition( + final Matcher parentMatcher, final int position) { + + return new TypeSafeMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Child at position " + position + " in parent "); + parentMatcher.describeTo(description); + } + + @Override + public boolean matchesSafely(View view) { + ViewParent parent = view.getParent(); + return parent instanceof ViewGroup && parentMatcher.matches(parent) + && view.equals(((ViewGroup) parent).getChildAt(position)); + } + }; + } +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 5039a11..c272c92 100755 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -3,18 +3,19 @@ xmlns:tools="http://schemas.android.com/tools" package="projet.license"> + - diff --git a/android/app/src/main/java/commun/Affichage.java b/android/app/src/main/java/commun/Affichage.java index 00dc007..dff20bf 100644 --- a/android/app/src/main/java/commun/Affichage.java +++ b/android/app/src/main/java/commun/Affichage.java @@ -1,7 +1,5 @@ package commun; -import java.util.List; - public interface Affichage { void majScor(boolean ok); @@ -14,4 +12,6 @@ public interface Affichage { void riddleGame(boolean rep); + + // void majGraphic(String message, Bundle parameters); } diff --git a/android/app/src/main/java/commun/Controleur.java b/android/app/src/main/java/commun/Controleur.java index d211daf..1bd75ff 100644 --- a/android/app/src/main/java/commun/Controleur.java +++ b/android/app/src/main/java/commun/Controleur.java @@ -1,10 +1,12 @@ package commun; -import java.util.List; - - +import android.os.Bundle; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; public class Controleur { Connexion connexion; @@ -35,7 +37,16 @@ public void majScor(boolean verif) { } public void timeGameScor(Integer scor,Integer tentative) { - getAffichage().timeGameScor(scor,tentative); } + getAffichage().timeGameScor(scor,tentative); + + /* + Bundle bundle = new Bundle(); + bundle.putInt("scor", scor); + bundle.putInt("tentative", tentative); + getAffichage().majGraphic("timeGameScor", bundle); + */ + + } public void listTimeGame(String listFormeDem,String listFormeRec) { getAffichage().listTimeGame(listFormeDem,listFormeRec); @@ -59,9 +70,33 @@ public Affichage getAffichage() { public void timeDetectorValider(String image) {connexion.timeImage(image);} - public void endTimeGame() {connexion.endTimeGame(); } + public void endTimeGame() {connexion.endTimeGame(); + + } public void listTimeGame2(){connexion.listResTimeGame();} public void rtoValider(String image) {connexion.rtoImage(image);} public void riddleValider(String image) {connexion.riddleImage(image);} + + + + //pour recuperer l'adressIp + public String getLocalIpAddress() { + try { + for (Enumeration en = NetworkInterface + .getNetworkInterfaces(); en.hasMoreElements();) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf + .getInetAddresses(); enumIpAddr.hasMoreElements();) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress()) { + return inetAddress.getHostAddress().toString(); + } + } + } + } catch (SocketException ex) { + } + return ""; + } + } \ No newline at end of file diff --git a/android/app/src/main/java/commun/Identification.java b/android/app/src/main/java/commun/Identification.java deleted file mode 100755 index 98a1d44..0000000 --- a/android/app/src/main/java/commun/Identification.java +++ /dev/null @@ -1,20 +0,0 @@ -package commun; - -public class Identification { - private String nom; - - public Identification(){} - - public Identification(String nom){ - this.nom = nom; - } - - public String getNom(){ - return nom ; - } - public void setNom(String nom){ - this.nom = nom; - } - - -} diff --git a/android/app/src/main/java/projet/license/DrawDetectorActivity.java b/android/app/src/main/java/projet/license/DrawDetectorActivity.java index 4107e4e..90166c9 100755 --- a/android/app/src/main/java/projet/license/DrawDetectorActivity.java +++ b/android/app/src/main/java/projet/license/DrawDetectorActivity.java @@ -33,10 +33,6 @@ public class DrawDetectorActivity extends Activity implements View.OnClickListe private String formeDemande = "Press start"; public PaintView myCanvas; final String[] formes = {"Point", "Segment", "Triangle", "Carre", "Rond"}; - private RelativeLayout mRelativeLayout; - private Context mContext; - private int textCol; - private boolean debut = true; @@ -48,9 +44,7 @@ protected void onCreate(Bundle savedInstanceState) { ctrl = new Controleur(this); - //tilefono - //Connexion connexion = new Connexion("http://192.168.0.101:10101",ctrl); - Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl); + Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl); connexion.seConnecter(); @@ -78,7 +72,6 @@ private void init() { - mContext = getApplicationContext(); myCanvas = findViewById(R.id.myCanvas); effacer.setOnClickListener(this); diff --git a/android/app/src/main/java/projet/license/HomeActivity.java b/android/app/src/main/java/projet/license/HomeActivity.java index fbf43b0..21edcb4 100644 --- a/android/app/src/main/java/projet/license/HomeActivity.java +++ b/android/app/src/main/java/projet/license/HomeActivity.java @@ -2,7 +2,6 @@ import android.app.Activity; import android.content.Intent; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; diff --git a/android/app/src/main/java/projet/license/LoginActivity.java b/android/app/src/main/java/projet/license/LoginActivity.java index 3f131b4..7bb4226 100644 --- a/android/app/src/main/java/projet/license/LoginActivity.java +++ b/android/app/src/main/java/projet/license/LoginActivity.java @@ -34,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState){ valider.setOnClickListener(this); ctrl = new Controleur(this); - Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl); + Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl); connexion.seConnecter(); } diff --git a/android/app/src/main/java/projet/license/RiddleActivity.java b/android/app/src/main/java/projet/license/RiddleActivity.java index 3e36740..750e653 100644 --- a/android/app/src/main/java/projet/license/RiddleActivity.java +++ b/android/app/src/main/java/projet/license/RiddleActivity.java @@ -41,9 +41,7 @@ protected void onCreate(Bundle savedInstanceState) { ctrl = new Controleur(this); - //tilefono - //Connexion connexion = new Connexion("http://192.168.0.101:10101",ctrl); - Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl); + Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl); connexion.seConnecter(); diff --git a/android/app/src/main/java/projet/license/RtoDetectorActivity.java b/android/app/src/main/java/projet/license/RtoDetectorActivity.java index f5a71ff..efcee1c 100644 --- a/android/app/src/main/java/projet/license/RtoDetectorActivity.java +++ b/android/app/src/main/java/projet/license/RtoDetectorActivity.java @@ -70,12 +70,7 @@ protected void onCreate(Bundle savedInstanceState) { ctrl = new Controleur((Affichage) this); - //fac - //Connexion connexion = new Connexion("http://10.1.124.22:10101",ctrl); - //spiti - //Connexion connexion = new Connexion("http://192.168.0.18:10101", ctrl); - //tilefono - Connexion connexion = new Connexion("http://172.20.10.2:10101",ctrl); + Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl); connexion.seConnecter(); diff --git a/android/app/src/main/java/projet/license/TimeDetectorActivity.java b/android/app/src/main/java/projet/license/TimeDetectorActivity.java index 26f0e57..5d63526 100755 --- a/android/app/src/main/java/projet/license/TimeDetectorActivity.java +++ b/android/app/src/main/java/projet/license/TimeDetectorActivity.java @@ -57,7 +57,8 @@ protected void onCreate(Bundle savedInstanceState) { mDessin = findViewById(R.id.dessin); ctrl = new Controleur(this); - Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl); + + Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl); connexion.seConnecter(); mButtonStartPause.setOnClickListener(new View.OnClickListener() { @Override diff --git a/javastd/commun/pom.xml b/javastd/commun/pom.xml index 9905a3f..7fc9607 100755 --- a/javastd/commun/pom.xml +++ b/javastd/commun/pom.xml @@ -17,32 +17,44 @@ 1.8 1.8 + + src/main/java + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + java + + + + + client.Client + + + + + + + + + + + + + - - junit - junit - 4.12 - test - - - org.openpnp - opencv - 3.4.2-1 - - - Detector - serveur - 1.0-SNAPSHOT - test - - - client-serveur - serveur - 1.0-SNAPSHOT - test - + \ No newline at end of file diff --git a/javastd/commun/src/main/java/commun/Identification.java b/javastd/commun/src/main/java/commun/Identification.java index b3ecbd4..8ba9e73 100755 --- a/javastd/commun/src/main/java/commun/Identification.java +++ b/javastd/commun/src/main/java/commun/Identification.java @@ -6,6 +6,11 @@ public class Identification { public Identification() {} + + public Identification(String nom){ + setNom(nom); + } + public Identification(String nom, int level) { this.nom = nom; } diff --git a/javastd/serveur/opencv_java342.dll b/javastd/serveur/opencv_java342.dll new file mode 100644 index 0000000..026345b Binary files /dev/null and b/javastd/serveur/opencv_java342.dll differ diff --git a/javastd/serveur/pom.xml b/javastd/serveur/pom.xml index 9851d62..272b49d 100755 --- a/javastd/serveur/pom.xml +++ b/javastd/serveur/pom.xml @@ -20,6 +20,15 @@ src/main/java + + src/test/java + + + + src/test/resources + + + org.codehaus.mojo @@ -70,6 +79,12 @@ slf4j-simple 1.7.25 + + junit + junit + 4.12 + test + org.openpnp opencv diff --git a/javastd/commun/src/main/java/commun/RtoDetector.java b/javastd/serveur/src/main/java/detector/RtoDetector.java old mode 100755 new mode 100644 similarity index 99% rename from javastd/commun/src/main/java/commun/RtoDetector.java rename to javastd/serveur/src/main/java/detector/RtoDetector.java index b2671c1..7b1198e --- a/javastd/commun/src/main/java/commun/RtoDetector.java +++ b/javastd/serveur/src/main/java/detector/RtoDetector.java @@ -1,4 +1,4 @@ -package commun; +package detector; import org.opencv.core.*; import org.opencv.core.Point; diff --git a/javastd/commun/src/main/java/commun/shapedetector.java b/javastd/serveur/src/main/java/detector/shapedetector.java old mode 100755 new mode 100644 similarity index 99% rename from javastd/commun/src/main/java/commun/shapedetector.java rename to javastd/serveur/src/main/java/detector/shapedetector.java index 4cd8ce2..94023bd --- a/javastd/commun/src/main/java/commun/shapedetector.java +++ b/javastd/serveur/src/main/java/detector/shapedetector.java @@ -1,4 +1,4 @@ -package commun; +package detector; import org.opencv.core.*; import org.opencv.core.Point; diff --git a/javastd/commun/src/main/java/commun/show.java b/javastd/serveur/src/main/java/detector/show.java old mode 100755 new mode 100644 similarity index 99% rename from javastd/commun/src/main/java/commun/show.java rename to javastd/serveur/src/main/java/detector/show.java index 3994b51..4f4507c --- a/javastd/commun/src/main/java/commun/show.java +++ b/javastd/serveur/src/main/java/detector/show.java @@ -1,4 +1,4 @@ -package commun; +package detector; import org.opencv.core.Mat; import org.opencv.core.Size; diff --git a/javastd/serveur/src/main/java/serveur/Serveur.java b/javastd/serveur/src/main/java/serveur/Serveur.java index df55720..f99514b 100755 --- a/javastd/serveur/src/main/java/serveur/Serveur.java +++ b/javastd/serveur/src/main/java/serveur/Serveur.java @@ -8,16 +8,18 @@ import com.corundumstudio.socketio.listener.DataListener; -import commun.Identification; -import commun.RtoDetector; -import commun.shapedetector; +import detector.RtoDetector; +import detector.shapedetector; import org.opencv.core.Core; import java.io.*; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Base64; -import java.util.List; +import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -303,6 +305,23 @@ else if (os.indexOf("mac") >= 0) { // chargement de la lib System.load(testLib.getAbsolutePath()); } + public static String getLocalIpAddress() { + try { + for (Enumeration en = NetworkInterface + .getNetworkInterfaces(); en.hasMoreElements();) { + NetworkInterface intf = en.nextElement(); + for (Enumeration enumIpAddr = intf + .getInetAddresses(); enumIpAddr.hasMoreElements();) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress()) { + return inetAddress.getHostAddress().toString(); + } + } + } + } catch (SocketException ex) { + } + return ""; + } public static final void main(String []args) throws IOException { try { @@ -323,7 +342,7 @@ public static final void main(String []args) throws IOException { Configuration config = new Configuration(); config.setMaxFramePayloadLength(200000); - config.setHostname("172.20.10.2"); + config.setHostname("192.168.0.100"); config.setPort(10101); diff --git a/javastd/commun/src/main/test/commun/RtoDetectorTest.java b/javastd/serveur/src/test/java/detector/RtoDetectorTest.java similarity index 85% rename from javastd/commun/src/main/test/commun/RtoDetectorTest.java rename to javastd/serveur/src/test/java/detector/RtoDetectorTest.java index f0c2381..aa6717a 100644 --- a/javastd/commun/src/main/test/commun/RtoDetectorTest.java +++ b/javastd/serveur/src/test/java/detector/RtoDetectorTest.java @@ -1,4 +1,4 @@ -package commun; +package detector; import org.junit.Test; import serveur.Serveur; @@ -8,7 +8,7 @@ import java.util.ArrayList; import java.util.Base64; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; public class RtoDetectorTest { @@ -28,7 +28,9 @@ public void detectRtoS() throws IOException { e.printStackTrace(); } - BufferedReader br = new BufferedReader(new FileReader("C:/Users/Kyriakos Petrou/Desktop/PLF/javastd/commun/src/main/test/commun/ressourcesRTO.txt")); + + InputStream resource = getClass().getClassLoader().getResourceAsStream("ressourcesRTO.txt"); + BufferedReader br = new BufferedReader(new InputStreamReader(resource)); String base64; Integer compter = 0; while ((base64 = br.readLine()) != null) { diff --git a/javastd/commun/src/main/test/commun/shapedetectorTest.java b/javastd/serveur/src/test/java/detector/shapedetectorTest.java similarity index 90% rename from javastd/commun/src/main/test/commun/shapedetectorTest.java rename to javastd/serveur/src/test/java/detector/shapedetectorTest.java index ac7e97e..25d4e24 100644 --- a/javastd/commun/src/main/test/commun/shapedetectorTest.java +++ b/javastd/serveur/src/test/java/detector/shapedetectorTest.java @@ -1,4 +1,4 @@ -package commun; +package detector; import org.junit.Test; import serveur.Serveur; @@ -32,7 +32,8 @@ public void detectShapes() throws IOException { } catch (URISyntaxException | IOException e) { e.printStackTrace(); } - BufferedReader br = new BufferedReader(new FileReader("C:/Users/Kyriakos Petrou/Desktop/Projet2/PLFGJ-master/javastd/commun/src/main/test/commun/ressources.txt")); + + BufferedReader br = new BufferedReader(new FileReader("src/test/resources/ressources.txt")); String base64; Integer compter = 0; while ((base64 = br.readLine()) != null) { diff --git a/javastd/commun/src/main/test/commun/ressources.txt b/javastd/serveur/src/test/resources/ressources.txt similarity index 100% rename from javastd/commun/src/main/test/commun/ressources.txt rename to javastd/serveur/src/test/resources/ressources.txt diff --git a/javastd/commun/src/main/test/commun/ressourcesRTO.txt b/javastd/serveur/src/test/resources/ressourcesRTO.txt similarity index 100% rename from javastd/commun/src/main/test/commun/ressourcesRTO.txt rename to javastd/serveur/src/test/resources/ressourcesRTO.txt diff --git a/javastd/serveur/test.png b/javastd/serveur/test.png new file mode 100644 index 0000000..272d65a Binary files /dev/null and b/javastd/serveur/test.png differ