Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Change the way you draw guide text. #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions card.io/src/main/java/io/card/payment/OverlayView.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class OverlayView extends View {
private GradientDrawable mGradientDrawable;
private final Paint mGuidePaint;
private final Paint mLockedBackgroundPaint;
private final TextPaint mGuideTextPaint;
private Path mLockedBackgroundPath;
private Rect mCameraPreviewRect;
private final Torch mTorch;
Expand Down Expand Up @@ -133,6 +134,11 @@ public OverlayView(CardIOActivity captureActivity, AttributeSet attributeSet, bo
mLockedBackgroundPaint.clearShadowLayer();
mLockedBackgroundPaint.setStyle(Paint.Style.FILL);
mLockedBackgroundPaint.setColor(0xbb000000); // 75% black

// Set up paint attributes
mGuideTextPaint = new TextPaint();
Util.setupTextPaintStyle(mGuideTextPaint);
mGuideTextPaint.setTextAlign(Align.CENTER);

scanInstructions = LocalizedStrings.getString(StringKey.SCAN_GUIDE);
}
Expand Down Expand Up @@ -338,26 +344,27 @@ public void onDraw(Canvas canvas) {

if (mDInfo.numVisibleEdges() < 3) {
// Draw guide text
// Set up paint attributes
float guideHeight = GUIDE_LINE_HEIGHT * mScale;
float guideFontSize = GUIDE_FONT_SIZE * mScale;

Util.setupTextPaintStyle(mGuidePaint);
mGuidePaint.setTextAlign(Align.CENTER);
mGuidePaint.setTextSize(guideFontSize);

// Translate and rotate text
canvas.translate(mGuide.left + mGuide.width() / 2, mGuide.top + mGuide.height() / 2);
canvas.rotate(mRotationFlip * mRotation);
mGuideTextPaint.setTextSize(guideFontSize);

int textWidth = mRotationFlip == 1 ? mGuide.width() : mGuide.height();
if (scanInstructions != null && scanInstructions != "") {
String[] lines = scanInstructions.split("\n");
float y = -(((guideHeight * (lines.length - 1)) - guideFontSize) / 2) - 3;
StaticLayout sl = new StaticLayout(scanInstructions, mGuideTextPaint, textWidth, Layout.Alignment.ALIGN_NORMAL, 1, 0, false);

int dx = mGuide.left + (mGuide.width() / 2);
int dy = mGuide.top + (mGuide.height() / 2);

for (int i = 0; i < lines.length; i++) {
canvas.drawText(lines[i], 0, y, mGuidePaint);
y += guideHeight;
int moveToCenter = mRotation / 90 > 1 ? 1 : -1;

if (mRotationFlip == 1) {
canvas.translate(dx, dy + (sl.getHeight() / 2) * moveToCenter);
}else {
canvas.translate(dx + (sl.getHeight() / 2) * moveToCenter, dy);
}

canvas.rotate(mRotationFlip * mRotation);
sl.draw(canvas);
}
}
}
Expand Down