Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexL164 committed Mar 25, 2018
1 parent d3879cb commit b0eb55d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/zemfi/de/vertaktoid/CustomViewPager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/zemfi/de/vertaktoid/FacsimileView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/zemfi/de/vertaktoid/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -250,7 +253,7 @@ protected void onPause() {
}

/**
* onCreateIptionMenu events routine
* onCreateOptionsMenu events routine
* @param menu The menu.
* @return true value.
*/
Expand Down
37 changes: 27 additions & 10 deletions src/main/java/zemfi/de/vertaktoid/PageImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@
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;
private Facsimile facsimile;
private final Page page;
private Path boundingPath;
private Path verticesPath;
private ArrayList<Point2D> pointPath;
private ArrayList<Point2D> pointPath; //currentPath
private Paint selectionPaint;
private Paint cutLinePaint;
private Paint drawPaint;
Expand Down Expand Up @@ -138,6 +143,7 @@ public void onClick(View view) {
}
});

// show preview
setOnHoverListener(new View.OnHoverListener() {
@Override
public boolean onHover(View v, MotionEvent event) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<Point2D> vertices = measure.zone.getVertices();
final PointF fp = sourceToViewCoord(vertices.get(0).getPointF());
verticesPath.moveTo(fp.x, fp.y);
Expand All @@ -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(
Expand All @@ -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))));
Expand All @@ -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();
Expand All @@ -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 ||
Expand All @@ -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<Measure> measures, Point2D[] touchSegment) {
Point2D[] cutPreview = new Point2D[2];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/zemfi/de/vertaktoid/model/Facsimile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/zemfi/de/vertaktoid/model/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<>();
Expand Down Expand Up @@ -148,6 +150,10 @@ public void removeMeasures(ArrayList<Measure> 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;
Expand Down

0 comments on commit b0eb55d

Please sign in to comment.