From b0eb55d181680c6ba16dca044a5d5026616f2205 Mon Sep 17 00:00:00 2001 From: Alexander Leemhuis Date: Sun, 25 Mar 2018 13:05:40 +0200 Subject: [PATCH] comments --- .../zemfi/de/vertaktoid/CustomViewPager.java | 2 +- .../zemfi/de/vertaktoid/FacsimileView.java | 11 ++++-- .../zemfi/de/vertaktoid/MainActivity.java | 7 +++- .../zemfi/de/vertaktoid/PageImageView.java | 37 ++++++++++++++----- .../zemfi/de/vertaktoid/model/Facsimile.java | 9 ++++- .../java/zemfi/de/vertaktoid/model/Page.java | 6 +++ 6 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/main/java/zemfi/de/vertaktoid/CustomViewPager.java b/src/main/java/zemfi/de/vertaktoid/CustomViewPager.java index fe1a362..ba3739f 100644 --- a/src/main/java/zemfi/de/vertaktoid/CustomViewPager.java +++ b/src/main/java/zemfi/de/vertaktoid/CustomViewPager.java @@ -9,7 +9,7 @@ import java.io.Console; /** - * Created by eugen on 30.03.17. + * Layout manager that contains an adapter to show the pages. */ public class CustomViewPager extends ViewPager { diff --git a/src/main/java/zemfi/de/vertaktoid/FacsimileView.java b/src/main/java/zemfi/de/vertaktoid/FacsimileView.java index 1640123..c4457a8 100644 --- a/src/main/java/zemfi/de/vertaktoid/FacsimileView.java +++ b/src/main/java/zemfi/de/vertaktoid/FacsimileView.java @@ -26,7 +26,7 @@ import zemfi.de.vertaktoid.model.Facsimile; /** - * Contains the presentation and user interaction functions. Directs the UI layouts. + * Contains the presentation and user interaction functions (click on icon). Directs the UI layouts. * Extends the SubsamplingScaleImageView class. */ @@ -130,6 +130,9 @@ public void setPage(int page) { } } + /** + * Sets Icons after actions to show possible undo and redo actions. + */ public void adjustHistoryNavigation() { if(commandManager.getUndoStackSize() > 0) { menu.findItem(R.id.action_undo).setIcon(R.drawable.undo_on); @@ -196,9 +199,9 @@ public void onClick(View v) { gotoDialog.show(); } - /* - Shows the settings dialog and process the user input. - Currently obtains the horizontal overlapping parameter. + /** + * Shows the settings dialog and process the user input. + * Currently obtains the horizontal overlapping parameter. */ public void settingsClicked() { resetState(); diff --git a/src/main/java/zemfi/de/vertaktoid/MainActivity.java b/src/main/java/zemfi/de/vertaktoid/MainActivity.java index 389bffb..7f74bc2 100644 --- a/src/main/java/zemfi/de/vertaktoid/MainActivity.java +++ b/src/main/java/zemfi/de/vertaktoid/MainActivity.java @@ -39,6 +39,7 @@ public class MainActivity extends AppCompatActivity { final String TAG = "de.zemfi.vertaktoid"; + // bindable status for bar final Status status = new Status(); Menu mainMenu; String path = null; @@ -119,6 +120,7 @@ protected void onCreate(Bundle savedInstanceState) { loadFacsimile(path); } + // link activity ui to facsimileView binding.setFview(facsimileView); status.setStatus(StatusStrings.StatusId.SUCCESS); status.setAction(StatusStrings.ActionId.STARTED); @@ -128,10 +130,11 @@ protected void onCreate(Bundle savedInstanceState) { } private void loadFacsimile(String path) { + // facsimile contains pages, movements, breaks Facsimile facsimile = new Facsimile(); File dir = new File(path); - //create subfolder (for MEI) and dummy image file + // create subfolder (for MEI) and dummy image file prepareApplicationFiles(dir); facsimile.openDirectory(dir); @@ -250,7 +253,7 @@ protected void onPause() { } /** - * onCreateIptionMenu events routine + * onCreateOptionsMenu events routine * @param menu The menu. * @return true value. */ diff --git a/src/main/java/zemfi/de/vertaktoid/PageImageView.java b/src/main/java/zemfi/de/vertaktoid/PageImageView.java index acea6c0..4ba05c0 100644 --- a/src/main/java/zemfi/de/vertaktoid/PageImageView.java +++ b/src/main/java/zemfi/de/vertaktoid/PageImageView.java @@ -38,6 +38,11 @@ import zemfi.de.vertaktoid.model.Page; import zemfi.de.vertaktoid.model.Zone; +/** + * Includes rendering functions, dialogs, touch functions. + * Uses rotating calipers algorithm. + */ + public class PageImageView extends SubsamplingScaleImageView { private final FacsimileView facsimileView; @@ -45,7 +50,7 @@ public class PageImageView extends SubsamplingScaleImageView { private final Page page; private Path boundingPath; private Path verticesPath; - private ArrayList pointPath; + private ArrayList pointPath; //currentPath private Paint selectionPaint; private Paint cutLinePaint; private Paint drawPaint; @@ -138,6 +143,7 @@ public void onClick(View view) { } }); + // show preview setOnHoverListener(new View.OnHoverListener() { @Override public boolean onHover(View v, MotionEvent event) { @@ -318,6 +324,8 @@ ImageSource findImageForPage() { /** * Rendering function + * boundingPath is an oriented orthogonal box covering all points + * verticesPath is the Path connecting the corner marks * @param canvas canvas */ @Override @@ -337,6 +345,7 @@ protected void onDraw(Canvas canvas) { facsimileView.generateColors(); + // if image is missing draw Name if (!page.imageFile.exists()) { largeTextPaint.getTextBounds(page.imageFile.getName(), 0, page.imageFile.getName().length(), pageNameRect); @@ -346,6 +355,7 @@ protected void onDraw(Canvas canvas) { } for (int i = 0; i < page.measures.size(); i++) { + // foreach measure boundingPath.reset(); verticesPath.reset(); Measure measure = page.measures.get(i); @@ -366,9 +376,13 @@ protected void onDraw(Canvas canvas) { return; } + // calculated in zone by rotating calipers if(measure.zone.getAnnotationType() == Facsimile.AnnotationType.ORTHOGONAL_BOX) { boundingPath.addRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y, Path.Direction.CW); } + + // adds vertices (corner marks) of each measure (its zone) to verticesPath + // vertices were set in onTouchEvent (Action Up, draw mode) List vertices = measure.zone.getVertices(); final PointF fp = sourceToViewCoord(vertices.get(0).getPointF()); verticesPath.moveTo(fp.x, fp.y); @@ -377,6 +391,8 @@ protected void onDraw(Canvas canvas) { verticesPath.lineTo(cp.x, cp.y); } verticesPath.close(); + + // draw border of each measure drawPaint.setStyle(Paint.Style.FILL); fillColor.a = 0.1f; fillColor.h = facsimileView.movementColors.get( @@ -389,6 +405,7 @@ protected void onDraw(Canvas canvas) { } else { canvas.drawPath(verticesPath, drawPaint); } + drawPaint.setStyle(Paint.Style.STROKE); drawPaint.setColor(HSLColor.toRGB(facsimileView.movementColors.get( facsimile.movements.indexOf(measure.movement)))); @@ -403,32 +420,28 @@ protected void onDraw(Canvas canvas) { boundingPath.reset(); + // draw sequence number String measureLabel = measure.manualSequenceNumber != null ? "" + measure.manualSequenceNumber : "" + measure.sequenceNumber; - String movementLabel = measure.movement.getName() + " >>"; - largeTextPaint.getTextBounds(measureLabel, 0, measureLabel.length(), measureNameRect); smallTextPaint.getTextBounds(movementLabel, 0, movementLabel.length(), movementNameRect); - Point2D centroid = Geometry.centroid2D(measure.zone.getVertices()); PointF centroidF = sourceToViewCoord((float) centroid.x(), (float) centroid.y()); float leftTextBox = centroidF.x - measureNameRect.width() / 2 - 5; float topTextBox = centroidF.y - 20 - measureNameRect.height() /2 ; float rightTextBox = centroidF.x + measureNameRect.width() / 2 + 5; float bottomTextBox = centroidF.y - 15 + measureNameRect.height() / 2; - if(measure.manualSequenceNumber != null) { canvas.drawRect(leftTextBox, topTextBox, rightTextBox, bottomTextBox, drawPaint); } - canvas.drawText(measureLabel, centroidF.x - measureNameRect.centerX(), centroidF.y, largeTextPaint); if(measure.movement.measures.indexOf(measure) == 0) { canvas.drawText(movementLabel, centroidF.x - movementNameRect.centerX(),centroidF.y + 30, smallTextPaint); - } - } + } // end for (foreach measure) + // build current Path verticesPath.reset(); for (int i = 0; i < pointPath.size(); i++) { PointF bitmapCoord = pointPath.get(i).getPointF(); @@ -440,6 +453,8 @@ protected void onDraw(Canvas canvas) { verticesPath.lineTo(touchCoord.x, touchCoord.y); } } + + // execute current path drawing canvas.drawPath(verticesPath, drawPaint); canvas.drawPath(polygonHoverPath, drawPaint); if((facsimileView.nextAction == FacsimileView.Action.ORTHOGONAL_CUT || @@ -449,7 +464,7 @@ protected void onDraw(Canvas canvas) { PointF lcut = sourceToViewCoord(lastCutPoint.getPointF()); canvas.drawLine(fcut.x, fcut.y, lcut.x, lcut.y, cutLinePaint); } - } + } // end onDraw private Point2D[] preciseCutPreview(List measures, Point2D[] touchSegment) { Point2D[] cutPreview = new Point2D[2]; @@ -692,6 +707,7 @@ public boolean onTouchEvent(MotionEvent event) { break; case DRAW: if (facsimileView.isFirstPoint) { + // add to current Path pointPath = new ArrayList<>(); pointPath.add(touchBitmapPosition); firstDrawPoint = touchBitmapPosition; @@ -789,13 +805,14 @@ public boolean onTouchEvent(MotionEvent event) { if (distanceToFirstPoint < 20.0f && trackLength > 20f) { pointPath.remove(pointPath.size() - 1); Measure newMeasure = new Measure(); - newMeasure.zone.setVertices(pointPath); + newMeasure.zone.setVertices(pointPath); // sets Vertices to currentPath switch (facsimile.nextAnnotationsType) { case ORTHOGONAL_BOX: newMeasure.zone.convertToOrthogonalBox(); newMeasure.zone.setAnnotationType(Facsimile.AnnotationType.ORTHOGONAL_BOX); break; case ORIENTED_BOX: + // uses rotating calipers newMeasure.zone.convertToOrientedBox(); newMeasure.zone.setAnnotationType(Facsimile.AnnotationType.ORIENTED_BOX); break; diff --git a/src/main/java/zemfi/de/vertaktoid/model/Facsimile.java b/src/main/java/zemfi/de/vertaktoid/model/Facsimile.java index f2d7861..2e11b0e 100644 --- a/src/main/java/zemfi/de/vertaktoid/model/Facsimile.java +++ b/src/main/java/zemfi/de/vertaktoid/model/Facsimile.java @@ -76,7 +76,7 @@ public int measuresCount() { } /** - * Adds measure to giving movement and page objects. + * Adds measure to giving movement and page object. * Creates references to the parent movement\page in measure. * @param measure new measure * @param movement target movement @@ -89,6 +89,13 @@ public void addMeasure(Measure measure, Movement movement, Page page) { page.measures.add(measure); } + /** + * Adds measure to page object and calculated movement. + * Creates references to the parent movement\page in measure. + * The movement is calculated based on the position of the measure. + * @param measure new measure + * @param page target page + */ public void addMeasure(Measure measure, Page page) { measure.page = page; page.measures.add(measure); diff --git a/src/main/java/zemfi/de/vertaktoid/model/Page.java b/src/main/java/zemfi/de/vertaktoid/model/Page.java index 4b9d7cb..eef7414 100644 --- a/src/main/java/zemfi/de/vertaktoid/model/Page.java +++ b/src/main/java/zemfi/de/vertaktoid/model/Page.java @@ -42,6 +42,7 @@ public class Page implements Parcelable { * @param number The sequence number. */ public Page(File imageFile, int number) { + //Universally Unique Identifier surfaceUuid = Vertaktoid.MEI_SURFACE_ID_PREFIX + UUID.randomUUID().toString(); graphicUuid = Vertaktoid.MEI_GRAPHIC_ID_PREFIX + UUID.randomUUID().toString(); this.imageFile = imageFile; @@ -51,6 +52,7 @@ public Page(File imageFile, int number) { } public Page() { + //Universally Unique Identifier surfaceUuid = Vertaktoid.MEI_SURFACE_ID_PREFIX + UUID.randomUUID().toString(); graphicUuid = Vertaktoid.MEI_GRAPHIC_ID_PREFIX + UUID.randomUUID().toString(); measures = new ArrayList<>(); @@ -148,6 +150,10 @@ public void removeMeasures(ArrayList measures) { } } + /** + * Calculates factor to downscale the image + * Example: inSampleSize == 4 for 1/4 of the width/height of the original + */ private int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { int inSampleSize = 1; final int height = options.outHeight;