Commit a595b56e authored by Thomas Krex's avatar Thomas Krex
Browse files

more code cleaning

parent 7a504f44
......@@ -118,7 +118,7 @@ public class MainActivity extends Activity {
colorDialog = new MyColorPickerDialog(this);
annotationView.setOnTouchListener(new AnnotationCanvasTouchListener(
annotationView, im, imgV));
annotationView, im));
tttRec.setInteractionManager(im);
gestureDetector = new GestureDetector(this, im);
......
package tttrec.interaction;
import tttrec.customviews.AnnotationView;
import tttrec.customviews.ScaleAwareImageView;
import tttrec.messages.FreehandAnnotation;
import tttrec.messages.HighlightAnnotation;
import android.graphics.Rect;
......@@ -13,7 +12,6 @@ import android.view.View.OnTouchListener;
public class AnnotationCanvasTouchListener implements OnTouchListener {
private final InteractionManager im;
private final ScaleAwareImageView vncImageView;
private final AnnotationView annotationView;
public static final byte FREEHAND_MODE = 0;
......@@ -22,8 +20,7 @@ public class AnnotationCanvasTouchListener implements OnTouchListener {
public static byte annotationMode = FREEHAND_MODE;
public AnnotationCanvasTouchListener(AnnotationView annotationView,
InteractionManager im, ScaleAwareImageView vncImageView) {
this.vncImageView = vncImageView;
InteractionManager im) {
this.annotationView = annotationView;
this.im = im;
}
......@@ -49,13 +46,11 @@ public class AnnotationCanvasTouchListener implements OnTouchListener {
Math.min(event.getX(), annotationView.getWidth()));
y = Math.max(0,
Math.min(event.getY(), annotationView.getHeight()));
// TODO handle Stylus-Pen
// Stylus touch event is taken care of, can return true
switch (event.getAction()) {
// Note: There are 3 main possibilities: ACTION_UP,ACTION_DOWN,
// ACTION_MOVE
......@@ -65,24 +60,16 @@ public class AnnotationCanvasTouchListener implements OnTouchListener {
im.annotationReceived(highlightAnno);
annotationView.addAnnotation(highlightAnno);
highlightAnno = null;
}
// TODO: Submit annotation
if (freehandAnno != null) {
im.annotationReceived(freehandAnno);
annotationView.addAnnotation(freehandAnno);
freehandAnno = null;
}
break;
case MotionEvent.ACTION_DOWN:
//
// annotationView
// .setLayoutParams(new FrameLayout.LayoutParams(
// vncImageView.getScaledWidth(), vncImageView
// .getScaledHeight(), Gravity.CENTER));
if (freehandAnno != null) {
im.annotationReceived(freehandAnno);
......@@ -97,13 +84,9 @@ public class AnnotationCanvasTouchListener implements OnTouchListener {
switch (annotationMode) {
case FREEHAND_MODE:
// freehandAnno = new FreehandAnnotation(0,
// im.currentAnnotationcolor,
// vncImageView.getScaleX(),
// vncImageView.getScaleY());
freehandAnno = new FreehandAnnotation(0,
im.currentAnnotationcolor,
annotationView.getScaleRatio(),
annotationView.getScaleRatio());
annotationView.temporaryAnnotation = freehandAnno;
break;
......@@ -117,41 +100,27 @@ public class AnnotationCanvasTouchListener implements OnTouchListener {
annotationView.getScaleRatio());
annotationView.temporaryAnnotation = highlightAnno;
break;
}
// fall through
default:
switch (annotationMode) {
case FREEHAND_MODE:
freehandAnno.addPoint((int) x, (int) y);
Log.d("AnnotationCanvasTouchListener: ",
"Annotation at x: " + x + " ,y: " + y);
break;
case HIGHLIGHT_MODE:
// TODO handle Highlight anno
highlightAnno.setEndPoint((int) x, (int) y);
// annotationCanvas.drawColor(Color.TRANSPARENT,
// PorterDuff.Mode.CLEAR);
break;
}
v.invalidate();
break;
}
return true;
}
}
return false;
}
}
......@@ -41,28 +41,26 @@ public class FreehandAnnotation extends Annotation {
private final iterablePath path = new iterablePath();
private PathShape pathShape;
private int count;
private final float scalingX, scalingY;
private final float scale;
private final Point deletePoint = new Point(0, 0);
// private double scale;
// empty freehand annotation
public FreehandAnnotation(int timestamp, int color, float scalingX,
float scalingY) {
this.scalingX = scalingX;
this.scalingY = scalingY;
public FreehandAnnotation(int timestamp, int color, float scale) {
this.scale = scale;
this.timestamp = timestamp;
this.color = color;
this.count = 0;
}
// add point to freehand annotation
public void addPoint(int x, int y) {
if (count++ == 0) {
if (count == 0) {
path.moveTo(x, y);
deletePoint.set((int) (x / scalingX), (int) (y / scalingY));
deletePoint.set((int) (x / scale), (int) (y / scale));
} else
path.lineTo(x, y);
count++;
// update shape and bounds
pathShape = new PathShape(path, 1, 1);
}
......@@ -118,13 +116,12 @@ public class FreehandAnnotation extends Annotation {
for (iterator = path.iterator(), i = 0; i < count; i++) {
if (iterator.hasNext()) {
point = iterator.next();
// x
out.writeShort((int) (point[0] / scale));
// y
out.writeShort((int) (point[1] / scale));
}
// x
out.writeShort((int) (point[0] / scalingX));
// y
out.writeShort((int) (point[1] / scalingY));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment