Skip to content
Snippets Groups Projects
Commit 2906195c authored by FurWaz's avatar FurWaz
Browse files

Added pathviews preview when visiting

parent 4a37a4dc
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment