Skip to content

Commit

Permalink
#22 Echange des Information entre Joueur et Serveur
Browse files Browse the repository at this point in the history
  • Loading branch information
aekathens03 committed Mar 15, 2019
1 parent dd577dc commit 83d33bd
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 313 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/java/projet/license/Connexion.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,5 @@ public void envoyerValider(String list) {
public void envoyerTutoriel(){connexion.emit("Bien recu5");}


public void sendImage(String image) {connexion.emit("imageB64",image);}
}
2 changes: 2 additions & 0 deletions android/app/src/main/java/projet/license/Controleur.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ public void setAffichage(Affichage affichage) {
public Affichage getAffichage() {
return affichage;
}

public void sendImage(String image) {connexion.sendImage(image);}
}
22 changes: 6 additions & 16 deletions android/app/src/main/java/projet/license/DrawDetectorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {


ctrl = new Controleur(this);
Connexion connexion = new Connexion("http://10.1.124.22:10101", ctrl);
Connexion connexion = new Connexion("http://192.168.0.18:10101", ctrl);
connexion.seConnecter();


Expand Down Expand Up @@ -210,7 +210,7 @@ public void onClick(View v){
Button press = (Button)findViewById(v.getId());
switch (v.getId()){
case R.id.effacer:
myCanvas.reset(kyriakos);
myCanvas.clear();
ctrl.msgReset();
myCanvas.countTicks = 0;
listDemande.setTicks(0);
Expand All @@ -228,15 +228,9 @@ public void onClick(View v){
afficherTick();
break;
case R.id.color:

Integer newColor = getColor();

if(newColor == Color.BLACK){
myCanvas.setPenColor(Color.WHITE);
kyriakos = Color.WHITE;}
else{
myCanvas.setPenColor(newColor);
kyriakos = newColor;}
mRelativeLayout.setBackgroundColor(getColor());
myCanvas.setBackgroundColor(Color.BLACK);
myCanvas.mPaint.setColor(Color.WHITE);



Expand All @@ -245,7 +239,7 @@ public void onClick(View v){
break;
case R.id.valider:
ctrl.msgValider(formeDemande +"," + myCanvas.getTicks());
// startShare();
ctrl.sendImage(myCanvas.encodeBitMap());
Log.d("Button Pressed : ",press.getText() + "");
afficherTick();
myCanvas.countTicks = 0;
Expand Down Expand Up @@ -299,10 +293,6 @@ public void run() {
}


public void drawlines(){
myCanvas.getCanvas().drawLines(myCanvas.getCoord(),myCanvas.getmPaint());
}


public void startShare(){
Bitmap bitmap = viewToBitmap(myCanvas,myCanvas.getWidth(),myCanvas.getHeight());
Expand Down
199 changes: 92 additions & 107 deletions android/app/src/main/java/projet/license/PaintView.java
Original file line number Diff line number Diff line change
@@ -1,161 +1,146 @@
package projet.license;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Base64;
import android.view.MotionEvent;
import android.view.View;

import java.util.ArrayList;
import java.util.Arrays;
import java.io.ByteArrayOutputStream;


public class PaintView extends View implements View.OnTouchListener {
private final int defaultDot = 10;
private final int defaultColor = Color.GRAY;
private int mPenColor;
private int mDotSize;
private float mX,mY,mOldX,mOldY;
public int countTicks = 0;
private ArrayList<Path> mPaths;
private ArrayList<Paint> mPaints;
public class PaintView extends View {
public Bitmap mBitmap;
public Canvas mCanvas;
private Path mPath;
private Paint mPaint;
private float[] coord;
private Canvas canvas;

private Paint mBitmapPaint;
public Paint mPaint;
public int countTicks = 0;


public PaintView(Context c, AttributeSet attrs) {
super(c, attrs);

public PaintView(Context context) {
super(context);
this.init();
}
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);

private void init() {
this.mDotSize = defaultDot;
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setDither(true);
mPaint.setColor(0xFF000000);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(9);
mPaint.setColor(Color.WHITE);
this.setBackgroundColor(Color.BLACK);
this.mPenColor = defaultColor;
this.mPaths = new ArrayList<Path>();
this.mPaints = new ArrayList<Paint>();
this.mPath = new Path();
this.addPath(false);
this.mX = this.mY = this.mOldY = this.mOldX = (float) 0.0;
this.countTicks = 0;
this.setOnTouchListener(this);
this.coord = new float[]{};
}


}
public int getTicks(){
return this.countTicks;
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}

public void addPath(boolean fill){
mPath = new Path();
mPaths.add(mPath);
mPaint = new Paint();
mPaints.add(mPaint);
mPaint.setColor(mPenColor);
if (!fill)
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(mDotSize);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
for (int i = 0; i<mPaths.size();i++)
canvas.drawPath(mPaths.get(i),mPaints.get(i));
canvas.drawPath(mPath,mPaint);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

canvas.drawPath(mPath, mPaint);


public void setPenColor(int penColor){
this.mPenColor = penColor;
this.mPaint.setColor(mPenColor);
}

private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;

public PaintView(Context context, AttributeSet attrs){
super(context,attrs);
this.init();
private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;
}

public PaintView(Context context,AttributeSet attrs,int defSystelAttr){
super(context,attrs,defSystelAttr);
this.init();
}

public void reset(int PenColor) {
this.init();
this.invalidate();
setPenColor(PenColor);
this.countTicks = 0;
private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
mX = x;
mY = y;
}
}
public void addTick(){
this.countTicks = this.countTicks + 1;
private void touch_up() {
mPath.lineTo(mX, mY);
// commit the path to our offscreen
mCanvas.drawPath(mPath, mPaint);
// kill this so we don't double draw
mPath.reset();
}

@Override
public boolean onTouch(View v, MotionEvent event) {
mX = event.getX();
mY = event.getY();
Log.d("Touched : "," ("+mX + "," + mY + ")");
switch (event.getAction()){
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
this.addPath(true);
this.mPath.addCircle(mX,mY,mDotSize/2,Path.Direction.CW);
this.addPath(false);
this.mPath.moveTo(mX,mY);
this.addTick();
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
this.mPath.lineTo(mX,mY);

touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
this.addPath(true);
if (mOldX == mX && mOldY == mY)
this.mPath.addCircle(mX,mY,mDotSize/2,Path.Direction.CW);

touch_up();
invalidate();
break;
}
this.addElement(coord, mX);
this.addElement(coord, mY);
this.invalidate();
mOldX = mX;
mOldY = mY;
return true;

}

public float[] getCoord(){
return this.coord;
public Bitmap getBitmap()
{
//this.measure(100, 100);
//this.layout(0, 0, 100, 100);
this.setDrawingCacheEnabled(true);
this.buildDrawingCache();
Bitmap bmp = Bitmap.createBitmap(this.getDrawingCache());
this.setDrawingCacheEnabled(false);


return bmp;
}

private float[] addElement(float[] a, float e) {
a = Arrays.copyOf(a, a.length + 1);
a[a.length - 1] = e;
return a;
public void addTick(){
this.countTicks = this.countTicks + 1;
}

public void drawline(Canvas canvas){
for(int i = 0; i < coord.length - 4; i ++){

canvas.drawLine(coord[i],coord[i+1],coord[i+2],coord[i+3],this.mPaint);
}
public void clear(){
mBitmap.eraseColor(Color.BLACK);
invalidate();
System.gc();

}
public Canvas getCanvas(){
return this.canvas;
public String encodeBitMap(){
Bitmap bmp = this.mBitmap;
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG,100,stream);
byte[] byteArray = stream.toByteArray();
String encoded = Base64.encodeToString(byteArray,Base64.DEFAULT);
return encoded;
}

public Paint getmPaint(){
return this.mPaint;
public Integer getTicks(){
return this.countTicks;
}


}
}
6 changes: 5 additions & 1 deletion javastd/commun/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
</build>

<dependencies>

<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 83d33bd

Please sign in to comment.