Skip to content
Snippets Groups Projects
Commit 82118083 authored by @potel5u's avatar @potel5u
Browse files

début gestions des acces

parent f574d458
No related branches found
No related tags found
No related merge requests found
......@@ -62,9 +62,25 @@ public class AccesActivity extends AppCompatActivity {
TextView textView = findViewById(R.id.textView2);
textView.setText(getString(R.string.acces, this.modele.getNom(), this.piece.getNom(), direction));
ImageView imageView = findViewById(R.id.imageView);
DrawableImageView imageView = findViewById(R.id.imageView);
imageView.setImageURI(photo);
Button ajouter = findViewById(R.id.boutonAcces);
ajouter.setOnClickListener(v -> {
imageView.setDrawing();
});
imageView.setOnRectangleClickListener(new DrawableImageView.OnRectangleClickListener() {
@Override
public void onRectangleClick(int rectangleId) {
Toast.makeText(AccesActivity.this, "Rectangle " + rectangleId + " cliqué", Toast.LENGTH_SHORT).show();
}
});
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.acces), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
......
package fr.ul.projet;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.MotionEvent;
import androidx.appcompat.widget.AppCompatImageView;
import java.util.HashMap;
public class DrawableImageView extends AppCompatImageView {
private Paint paint;
private HashMap<Integer,RectF> rectangles = new HashMap<>();
private HashMap<Integer,RectF> rectanglesTemp = new HashMap<>();
private float startX, startY, endX, endY;
private boolean isDrawingFinished = false;
private boolean fixed = false;
private boolean drawing = false;
private OnRectangleClickListener listener;
public DrawableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public DrawableImageView(Context context) {
super(context);
init();
}
private void init() {
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
}
@Override
public boolean performClick() {
super.performClick(); // Appeler la méthode de la superclasse pour marquer le clic
return true;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for (RectF rect : rectangles.values()) {
canvas.drawRect(rect, paint);
}
for (RectF rect : rectanglesTemp.values()) {
canvas.drawRect(rect, paint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (isDrawingFinished){
// Vérifier si l'utilisateur a cliqué sur un rectangle existant
for (Integer key : rectangles.keySet()) {
RectF rect = rectangles.get(key);
if (rect.contains(event.getX(), event.getY())) {
performClick();
if (listener != null) {
listener.onRectangleClick(key); // Passer l'ID du rectangle cliqué
}
return true; // Clic détecté, on arrête l'événement
}
}
return false;
}
if (!drawing){
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getY();
isDrawingFinished = false;
return true;
case MotionEvent.ACTION_MOVE:
if (!fixed) {
endX = event.getX();
endY = event.getY();
// Mettre à jour un rectangle temporaire en cours de dessin
rectanglesTemp.put(-1, new RectF(
Math.min(startX, endX), Math.min(startY, endY),
Math.max(startX, endX), Math.max(startY, endY)
));
invalidate();
}
return true;
case MotionEvent.ACTION_UP:
if (!fixed) {
RectF rect = new RectF(
Math.min(startX, endX), Math.min(startY, endY),
Math.max(startX, endX), Math.max(startY, endY)
);
rectangles.put(rectangles.size(), rect);
rectanglesTemp.clear();
fixed = true;
drawing=false;
isDrawingFinished=true;
invalidate();
}
return true;
}
return false;
}
public void setDrawing(){
drawing = true;
}
public void setOnRectangleClickListener(OnRectangleClickListener listener) {
this.listener = listener;
}
public interface OnRectangleClickListener {
void onRectangleClick(int rectangleId);
}
}
......@@ -32,7 +32,7 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.951" />
<ImageView
<fr.ul.projet.DrawableImageView
android:id="@+id/imageView"
android:layout_width="399dp"
android:layout_height="248dp"
......@@ -40,7 +40,8 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
tools:srcCompat="@tools:sample/backgrounds/scenic"/>
<TextView
android:id="@+id/textView2"
......@@ -53,4 +54,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.254" />
<Button
android:id="@+id/boutonAcces"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/boutonAcces"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.745" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -15,4 +15,5 @@
<string name="ouest">Photo Ouest</string>
<string name="piece_nom">%1$s : %2$s</string>
<string name="acces">%1$s : %2$s (%3$s)</string>
<string name="boutonAcces">Ajouter un accés</string>
</resources>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment