initial commit engine begining

This commit is contained in:
mmarc471@gmail.com
2020-09-06 13:50:01 +02:00
commit d095a3418f
38 changed files with 1075 additions and 0 deletions
@@ -0,0 +1,26 @@
package com.iutlaval.myapplication;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented 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() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.iutlaval.myapplication", appContext.getPackageName());
}
}
+21
View File
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iutlaval.myapplication">
<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>
@@ -0,0 +1,167 @@
package com.iutlaval.myapplication;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder holder;
private Paint p;
private DrawingThread drawingThread;
private List<Drawable> toDraw;
private Rect fullscreen;
public CanevasView(Context context) {
super(context);
holder = getHolder();
holder.addCallback(this);
drawingThread = new DrawingThread();
p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
p.setColor(Color.RED);
p.setStyle(Paint.Style.FILL_AND_STROKE);
toDraw = new ArrayList<>();
}
@Override
public void surfaceCreated(@NonNull SurfaceHolder holder) {
fullscreen = holder.getSurfaceFrame();
drawingThread.start();
}
@Override
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(@NonNull SurfaceHolder surfaceHolder) {
drawingThread.keepDrawing = false;
try {
drawingThread.join();
} catch (InterruptedException e) {}
}
@Override
protected void onDraw(Canvas canvas) {
for(Drawable d : toDraw)
{
d.drawOn(canvas,p);
}
}
private class DrawingThread extends Thread {
public boolean keepDrawing = true;
@SuppressLint("WrongCall")
@Override
public void run() {
while (keepDrawing) {
Canvas canvas = null;
try {
// On récupère le canvas pour dessiner dessus
canvas = holder.lockCanvas();
// On s'assure qu'aucun autre thread n'accède au holder
synchronized (holder) {
// Et on dessine
onDraw(canvas);
}
} finally {
// Notre dessin fini, on relâche le Canvas pour que le dessin s'affiche
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
//empecher d'aller plus vite que le taux de rafraichissement de l'ecran
//sauve de la betterie
try {
float fps = getDisplay().getRefreshRate();
Thread.sleep((long)(1.0/fps*1000));
} catch (InterruptedException e) {}
}
}
}
/**
* permet d'ajouter un element a afficher
* @return retourne faux si l'element existe deja
*/
public boolean addToDraw(Drawable newElement){
for(Drawable d : toDraw)
{
if(d.equals(newElement))
{
return false;
}
}
toDraw.add(newElement);
return true;
}
/**
* permet de changer les coordoné d'un objet a l'ecran
* @param x coordonné en x (-1.0 a 1.0)
* @param y coodonné en y (-1.0 a 1.0)
* @param name nom de l'element a modifier
*/
public void ChangeToDraw(float x,float y,String name) throws DrawableNotFoundException {
for(Drawable d : toDraw)
{
if(d.getName().equals(name))
{
d.setCoordinates(x,y);
return;
}
}
throw new DrawableNotFoundException();
}
/**
* remove the element from the draw list
* @param name the element name
*/
public void removeToDraw(String name){
Drawable toRemove = null;
for(Drawable d : toDraw)
{
if(d.getName().equals(name))
{
toRemove=d;
break;
}
}
if(toRemove != null)
{
toDraw.remove(toRemove);
}
}
/**
* remove the element from the draw list
* @param toRemove the element toRemove
*/
public void removeToDraw(Drawable toRemove){
toDraw.remove(toRemove);
}
public Rect getFullscreen() {
return fullscreen;
}
}
@@ -0,0 +1,135 @@
package com.iutlaval.myapplication;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import java.util.Objects;
public class Drawable {
private float x,y;
private String name;
private Bitmap bitmap;
/**
* cree un drawable a partir de coordonné est d'un nom
* @param x coordoné x compris entre 0 et 100
* @param y coordoné y comrpis entre 0 et 100
* @param name nom du drawable agit comme un identifiant mais doit être unique
*/
private Drawable(float x,float y,String name)
{
this.x=x;
this.y=y;
this.name=name;
}
/**
* cree un drawable depuis une bitmap est des coordonnés
* @param bitmap bitmap
* @param x coordoné x compris entre 0 et 100
* @param y coordoné y comrpis entre 0 et 100
* @param name nom du drawable agit comme un identifiant mais doit être unique
*
* deprecier car non adapter a la resolution de l'ecran
*/
@Deprecated
public Drawable(Bitmap bitmap,float x,float y,String name){
this(x,y,name);
this.bitmap=bitmap;
}
/**
* cree un drawable depuis une bitmap est des coordonnés
* @param bitmap bitmap
* @param x_pos coordoné x compris entre 0 et 100
* @param y_pos coordoné y comrpis entre 0 et 100
* @param name nom du drawable agit comme un identifiant mais doit être unique
* deprecier car non adapter a la resolution de l'ecran
*
* TODO : echelle dynamique avec l'ecran
*/
public Drawable(Bitmap bitmap,float x_pos,float y_pos,String name,float x_size,float y_size) throws InvalidDataException {
this(x_pos,y_pos,name);
float x_scaled_size = x_size*bitmap.getWidth()/100;
float y_scaled_size = y_size*bitmap.getHeight()/100;
if(x_scaled_size <=0 || y_scaled_size <=0)
{
throw new InvalidDataException(name,x_scaled_size,y_scaled_size);
}
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size,true);
this.bitmap=scaledBitmap;
}
/**
* ce constructeur n'est pas rapide essayer de l'utiliser le moin possible
* TODO : optimize it and remove the deprecated flag
*
* this contructor create a Drawable object from a rectangle and a color
* @param rectangle recange cooresspondant a la surface a dessiner
* @param name nom du drawable agit comme un identifiant mais doit être unique
* @param color couleur du rectangle
*/
@Deprecated
public Drawable(Rect rectangle, String name, int color) throws InvalidDataException {
if(rectangle.height() <= 0 || rectangle.width() <=0)throw new InvalidDataException(name,rectangle);
Bitmap bitmap = Bitmap.createBitmap(rectangle.width(),rectangle.height(), Bitmap.Config.ARGB_8888);
//on crée un canevas pour interagir avec la bitmap
Canvas c = new Canvas(bitmap);
Paint p = new Paint();
p.setColor(color);
p.setStyle(Paint.Style.FILL_AND_STROKE);
c.drawRect(rectangle,p);
this.bitmap=bitmap;
this.name=name;
this.x=rectangle.left;
this.y=rectangle.top;
}
public void drawOn(Canvas c, Paint p)
{
//drawings
c.drawBitmap(bitmap,x*MainActivity.screenWidth/100,y*MainActivity.screenHeight/100,p);
}
public Bitmap getBitmap() {
return bitmap;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if(o instanceof Drawable)
{
return ((Drawable)o).getName().equals(name);
}
return false;
}
public void setCoordinates(float x, float y) {
this.x=x;
this.y=y;
}
}
@@ -0,0 +1,4 @@
package com.iutlaval.myapplication;
public class DrawableNotFoundException extends Exception{
}
@@ -0,0 +1,25 @@
package com.iutlaval.myapplication;
import android.graphics.Rect;
public class InvalidDataException extends Throwable {
private String name;
private float x;
private float y;
public InvalidDataException(String name, Rect rectangle)
{
x = rectangle.width();
y = rectangle.height();
this.name=name;
}
public InvalidDataException(String name,float x,float y)
{
this.y=y;
this.x=x;
}
public String getDetail() {
return "name " + name + " x:" + x +" y:"+ y;
}
}
@@ -0,0 +1,56 @@
package com.iutlaval.myapplication;
//N'oubliez pas de déclarer le bon package dans lequel se trouve le fichier !
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Display;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
public class MainActivity extends Activity {
public static int screenWidth=0;
public static int screenHeight=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Display display = getWindowManager().getDefaultDisplay();
CanevasView v = new CanevasView(getBaseContext());
//return portrait mode resolution so we need to flip them
Point size = new Point();
display.getSize(size);
screenWidth = size.y;
screenHeight = size.x;
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.debug_card);
try {
//v.addToDraw(new Drawable(new Rect(0,0,screenHeight,screenWidth),"background",Color.BLUE));
v.addToDraw(new Drawable(bm,0.0F,00.0F,"Card1",50F,50F));
} catch (InvalidDataException e) {
//cette erreur est lance si un carre est invalid
System.err.println(e.getDetail());
e.printStackTrace();
}
setContentView(v);
}
}
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeWidth="0.8"
android:strokeColor="#33FFFFFF" />
</vector>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>
+3
View File
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">My Application</string>
</resources>
+10
View File
@@ -0,0 +1,10 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
@@ -0,0 +1,17 @@
package com.iutlaval.myapplication;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}