diff --git a/Sources/app/src/main/java/Views/ClickDetector.java b/Sources/app/src/main/java/Views/ClickDetector.java index e88221ba6039a323b376fb35a4f431148d412e67..36933ed5711cac22f2b9e452371008df09bb3d27 100644 --- a/Sources/app/src/main/java/Views/ClickDetector.java +++ b/Sources/app/src/main/java/Views/ClickDetector.java @@ -2,16 +2,24 @@ package Views; 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 android.view.View; import android.widget.Toast; +import com.furwaz.roomview.R; + import Common.Callback; import Common.Coord; +import Structures.PathView; +import Structures.PhotoInfo; public class ClickDetector extends View { Callback cb = null; + PhotoInfo photo = null; // set the on touch callback function protected void init() { @@ -35,6 +43,11 @@ public class ClickDetector extends View { this.cb = c; } + public void setPhoto(PhotoInfo p) { + this.photo = p; + this.invalidate(); + } + // on touch, if the touch is valid (only one finger, and the action is up), call the callback function with the touch coordinates protected boolean touchListener(View v, MotionEvent ev) { if (ev.getPointerCount() != 1) return true; @@ -47,5 +60,36 @@ public class ClickDetector extends View { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); + + if (photo == null) return; + for (PathView p : photo.getPathViews()) { + drawDoorZone( + canvas, + p.getRect(), + p.getPath().getName() + ); + } + } + + // draw one pathview on the canvas + protected void drawDoorZone(Canvas c, RectF rect, String name) { + Paint p = new Paint(); + int width = getWidth(); + int height = getHeight(); + + RectF r = new RectF(rect.left * width, rect.top * height, rect.right * width, rect.bottom * height); + + p.setColor(Color.parseColor("#60f8fafc")); + c.drawRect( + r.left, + r.top, + r.right, + r.bottom, + p + ); + p.setColor(getResources().getColor(R.color.slate_50, getContext().getTheme())); + p.setTextSize(36); + p.setTextAlign(Paint.Align.CENTER); + c.drawText(name, (r.left + r.right) / 2, (r.top + r.bottom) / 2, p); } } diff --git a/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java b/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java index afa9b9b40bb5fd5ff58db37c6ba24c603bcd5582..c1c126f4f0a827fbf95b7864b33886461027c70d 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/ZoneView.java @@ -48,6 +48,7 @@ public class ZoneView extends AppCompatActivity { PhotoInfo photo = null; Orientation orient = Orientation.NORTH; + ClickDetector bitmap_zone = null; // return the string corresponding to the orientation protected String stringifyOrientation(Orientation orient) { @@ -135,7 +136,7 @@ public class ZoneView extends AppCompatActivity { }); // set the photo zone click listener (for pathviews click, to move) - ClickDetector bitmap_zone = findViewById(R.id.bitmap_zone); + if (bitmap_zone == null) bitmap_zone = findViewById(R.id.bitmap_zone); bitmap_zone.setOnClickCallback(param -> { Coord c = (Coord) param; this.onClickAt(c); @@ -155,6 +156,7 @@ public class ZoneView extends AppCompatActivity { TextView tv_orient = findViewById(R.id.orient_text); TextView tv_room = findViewById(R.id.room_name); TextView tv_zone = findViewById(R.id.zone_name); + if (bitmap_zone == null) bitmap_zone = findViewById(R.id.bitmap_zone); tv_orient.setText(getResources().getString(R.string.orientation)+": "+stringifyOrientation(this.orient)); tv_room.setText(room == null? "": room.getName()); @@ -182,6 +184,8 @@ public class ZoneView extends AppCompatActivity { return; } + bitmap_zone.setPhoto(photo); + // if the photo has not been taken yet, display an error message Bitmap bm = photo.getBitmap(); if (bm == null) {