TP07byMathieu + boutDeControleBlanc
This commit is contained in:
42
TP05/EX01_Reticule/app/build.gradle.kts
Normal file
42
TP05/EX01_Reticule/app/build.gradle.kts
Normal file
@@ -0,0 +1,42 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "fr.iutfbleau.dev45.wamster.tp05ex01_reticule"
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId = "fr.iutfbleau.dev45.wamster.tp05ex01_reticule"
|
||||
minSdk = 19
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation("androidx.appcompat:appcompat:1.6.1")
|
||||
implementation("com.google.android.material:material:1.11.0")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package fr.iutfbleau.dev45.wamster.tp05ex01_reticule;
|
||||
|
||||
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("fr.iutfbleau.dev45.wamster.tp05ex01_reticule", appContext.getPackageName());
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package fr.iutfbleau.dev45.wamster.tp05ex01_reticule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
public class Dessin extends View {
|
||||
private float rayon;
|
||||
private float x;
|
||||
private float y;
|
||||
private final Paint pinceau;
|
||||
public Dessin(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.pinceau = new Paint();
|
||||
this.pinceau.setStyle(Paint.Style.STROKE);
|
||||
this.pinceau.setStrokeWidth(20.0f);
|
||||
this.pinceau.setColor(0xfffc6600);
|
||||
this.rayon = 100f;
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
}
|
||||
|
||||
public void setCoordonnee(float x, float y){
|
||||
this.x = x;
|
||||
this.y =y;
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas){
|
||||
if (this.x < 0){
|
||||
this.x = getWidth()/2f;
|
||||
}
|
||||
if (this.y < 0){
|
||||
this.y = getHeight()/2f;
|
||||
}
|
||||
canvas.drawCircle(this.x, this.y, this.rayon, this.pinceau);
|
||||
Path trait1 = new Path();
|
||||
trait1.moveTo(this.x,this.y-(1.5f*this.rayon));
|
||||
trait1.lineTo(this.x, this.y+(1.5f*this.rayon));
|
||||
trait1.close();
|
||||
canvas.drawPath(trait1, this.pinceau);
|
||||
|
||||
Path trait2 = new Path();
|
||||
trait2.moveTo(this.x-(1.5f*this.rayon),this.y);
|
||||
trait2.lineTo(this.x+(1.5f*this.rayon), this.y);
|
||||
trait2.close();
|
||||
canvas.drawPath(trait2, this.pinceau);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package fr.iutfbleau.dev45.wamster.tp05ex01_reticule;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class Evenement implements View.OnTouchListener{
|
||||
|
||||
private Dessin dessin;
|
||||
private boolean mouvementEnCours;
|
||||
private float distance = 50f;
|
||||
|
||||
public Evenement(Dessin dessin){
|
||||
this.dessin = dessin;
|
||||
this.mouvementEnCours = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
int action = event.getActionMasked();
|
||||
int index = event.getActionIndex();
|
||||
int id = event.getPointerId(index);
|
||||
Log.v("test1", id+"");
|
||||
float x,y;
|
||||
|
||||
switch (action) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
this.mouvementEnCours = true;
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
this.mouvementEnCours = false;
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (this.mouvementEnCours){
|
||||
this.dessin.setCoordonnee(event.getX(), event.getY());
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
this.mouvementEnCours = false;
|
||||
break;
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
this.mouvementEnCours = false;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public float isDistancePetite(float x1, float y1){
|
||||
float x2 = this.dessin.getX();
|
||||
float y2 = this.dessin.getX();
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package fr.iutfbleau.dev45.wamster.tp05ex01_reticule;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Dessin dessin = findViewById(R.id.zoneDeDessin);
|
||||
Evenement ecouteurDoigt = new Evenement(dessin);
|
||||
dessin.setOnTouchListener(ecouteurDoigt);
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package fr.iutfbleau.dev45.wamster.tp05ex01_reticule;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user