正在查看: Clash Legends v0.0.1 应用的 OverlayView.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Clash Legends v0.0.1 应用的 OverlayView.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package io.card.payment;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import io.card.payment.i18n.LocalizedStrings;
import io.card.payment.i18n.StringKey;
import java.lang.ref.WeakReference;
class OverlayView extends View {
private int guideColor;
private boolean hideCardIOLogo;
private Bitmap mBitmap;
private Rect mCameraPreviewRect;
private DetectionInfo mDInfo;
private CreditCard mDetectedCard;
private GradientDrawable mGradientDrawable;
private Rect mGuide;
private final Paint mGuidePaint;
private final Paint mLockedBackgroundPaint;
private Path mLockedBackgroundPath;
private final Logo mLogo;
private Rect mLogoRect;
private int mRotation;
private int mRotationFlip;
private float mScale;
private final WeakReference<CardIOActivity> mScanActivityRef;
private final boolean mShowTorch;
private int mState;
private final Torch mTorch;
private Rect mTorchRect;
private String scanInstructions;
private static final String TAG = OverlayView.class.getSimpleName();
private static final GradientDrawable.Orientation[] GRADIENT_ORIENTATIONS = {GradientDrawable.Orientation.TOP_BOTTOM, GradientDrawable.Orientation.LEFT_RIGHT, GradientDrawable.Orientation.BOTTOM_TOP, GradientDrawable.Orientation.RIGHT_LEFT};
public OverlayView(CardIOActivity captureActivity, AttributeSet attributeSet, boolean showTorch) {
super(captureActivity, attributeSet);
this.mScale = 1.0f;
this.mShowTorch = showTorch;
this.mScanActivityRef = new WeakReference<>(captureActivity);
this.mRotationFlip = 1;
this.mScale = getResources().getDisplayMetrics().density / 1.5f;
float f = this.mScale;
this.mTorch = new Torch(70.0f * f, f * 50.0f);
this.mLogo = new Logo(captureActivity);
this.mGuidePaint = new Paint(1);
Paint paint = new Paint(1);
this.mLockedBackgroundPaint = paint;
paint.clearShadowLayer();
paint.setStyle(Paint.Style.FILL);
paint.setColor(-1157627904);
this.scanInstructions = LocalizedStrings.getString(StringKey.SCAN_GUIDE);
}
public void setGuideColor(int color) {
this.guideColor = color;
}
public void setHideCardIOLogo(boolean hide) {
this.hideCardIOLogo = hide;
}
public void setScanInstructions(String scanInstructions) {
this.scanInstructions = scanInstructions;
}
public void setGuideAndRotation(Rect rect, int rotation) {
Point topEdgeUIOffset;
this.mRotation = rotation;
this.mGuide = rect;
invalidate();
if (this.mRotation % 180 != 0) {
float f = this.mScale;
topEdgeUIOffset = new Point((int) (40.0f * f), (int) (f * 60.0f));
this.mRotationFlip = -1;
} else {
float f2 = this.mScale;
topEdgeUIOffset = new Point((int) (60.0f * f2), (int) (f2 * 40.0f));
this.mRotationFlip = 1;
}
if (this.mCameraPreviewRect != null) {
Point torchPoint = new Point(this.mCameraPreviewRect.left + topEdgeUIOffset.x, this.mCameraPreviewRect.top + topEdgeUIOffset.y);
float f3 = this.mScale;
this.mTorchRect = Util.rectGivenCenter(torchPoint, (int) (70.0f * f3), (int) (f3 * 50.0f));
Point logoPoint = new Point(this.mCameraPreviewRect.right - topEdgeUIOffset.x, this.mCameraPreviewRect.top + topEdgeUIOffset.y);
float f4 = this.mScale;
this.mLogoRect = Util.rectGivenCenter(logoPoint, (int) (100.0f * f4), (int) (f4 * 50.0f));
int[] gradientColors = {-1, -16777216};
GradientDrawable.Orientation gradientOrientation = GRADIENT_ORIENTATIONS[(this.mRotation / 90) % 4];
GradientDrawable gradientDrawable = new GradientDrawable(gradientOrientation, gradientColors);
this.mGradientDrawable = gradientDrawable;
gradientDrawable.setGradientType(0);
this.mGradientDrawable.setBounds(this.mGuide);
this.mGradientDrawable.setAlpha(50);
Path path = new Path();
this.mLockedBackgroundPath = path;
path.addRect(new RectF(this.mCameraPreviewRect), Path.Direction.CW);
this.mLockedBackgroundPath.addRect(new RectF(this.mGuide), Path.Direction.CCW);
}
}
public void setBitmap(Bitmap bitmap) {
Bitmap bitmap2 = this.mBitmap;
if (bitmap2 != null) {
bitmap2.recycle();
}
this.mBitmap = bitmap;
if (bitmap != null) {
decorateBitmap();
}
}
public Bitmap getBitmap() {
return this.mBitmap;
}
public void setDetectionInfo(DetectionInfo dinfo) {
DetectionInfo detectionInfo = this.mDInfo;
if (detectionInfo != null && !detectionInfo.sameEdgesAs(dinfo)) {
invalidate();
}
this.mDInfo = dinfo;
}
public Bitmap getCardImage() {
Bitmap bitmap = this.mBitmap;
if (bitmap != null && !bitmap.isRecycled()) {
Bitmap bitmap2 = this.mBitmap;
return Bitmap.createBitmap(bitmap2, 0, 0, bitmap2.getWidth(), this.mBitmap.getHeight());
}
return null;
}
private Rect guideStrokeRect(int x1, int y1, int x2, int y2) {
int t2 = (int) (this.mScale * 8.0f);
Rect r = new Rect();
r.left = Math.min(x1, x2) - t2;
r.right = Math.max(x1, x2) + t2;
r.top = Math.min(y1, y2) - t2;
r.bottom = Math.max(y1, y2) + t2;
return r;
}
@Override
public void onDraw(Canvas canvas) {
int tickLength;
if (this.mGuide == null || this.mCameraPreviewRect == null) {
return;
}
canvas.save();
this.mGradientDrawable.draw(canvas);
int i = this.mRotation;
if (i == 0 || i == 180) {
tickLength = (this.mGuide.bottom - this.mGuide.top) / 4;
} else {
tickLength = (this.mGuide.right - this.mGuide.left) / 4;
}
DetectionInfo detectionInfo = this.mDInfo;
if (detectionInfo != null && detectionInfo.numVisibleEdges() == 4) {
canvas.drawPath(this.mLockedBackgroundPath, this.mLockedBackgroundPaint);
}
this.mGuidePaint.clearShadowLayer();
this.mGuidePaint.setStyle(Paint.Style.FILL);
this.mGuidePaint.setColor(this.guideColor);
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.top, this.mGuide.left + tickLength, this.mGuide.top), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.top, this.mGuide.left, this.mGuide.top + tickLength), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.right, this.mGuide.top, this.mGuide.right - tickLength, this.mGuide.top), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.right, this.mGuide.top, this.mGuide.right, this.mGuide.top + tickLength), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.bottom, this.mGuide.left + tickLength, this.mGuide.bottom), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.bottom, this.mGuide.left, this.mGuide.bottom - tickLength), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.right, this.mGuide.bottom, this.mGuide.right - tickLength, this.mGuide.bottom), this.mGuidePaint);
canvas.drawRect(guideStrokeRect(this.mGuide.right, this.mGuide.bottom, this.mGuide.right, this.mGuide.bottom - tickLength), this.mGuidePaint);
DetectionInfo detectionInfo2 = this.mDInfo;
if (detectionInfo2 != null) {
if (detectionInfo2.topEdge) {
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.top, this.mGuide.right, this.mGuide.top), this.mGuidePaint);
}
if (this.mDInfo.bottomEdge) {
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.bottom, this.mGuide.right, this.mGuide.bottom), this.mGuidePaint);
}
if (this.mDInfo.leftEdge) {
canvas.drawRect(guideStrokeRect(this.mGuide.left, this.mGuide.top, this.mGuide.left, this.mGuide.bottom), this.mGuidePaint);
}
if (this.mDInfo.rightEdge) {
canvas.drawRect(guideStrokeRect(this.mGuide.right, this.mGuide.top, this.mGuide.right, this.mGuide.bottom), this.mGuidePaint);
}
if (this.mDInfo.numVisibleEdges() < 3) {
float f = this.mScale;
float guideHeight = 34.0f * f;
float guideFontSize = f * 26.0f;
Util.setupTextPaintStyle(this.mGuidePaint);
this.mGuidePaint.setTextAlign(Paint.Align.CENTER);
this.mGuidePaint.setTextSize(guideFontSize);
canvas.translate(this.mGuide.left + (this.mGuide.width() / 2), this.mGuide.top + (this.mGuide.height() / 2));
canvas.rotate(this.mRotationFlip * this.mRotation);
String str = this.scanInstructions;
if (str != null && str != "") {
String[] lines = str.split("\n");
float y = (-((((lines.length - 1) * guideHeight) - guideFontSize) / 2.0f)) - 3.0f;
for (String str2 : lines) {
canvas.drawText(str2, 0.0f, y, this.mGuidePaint);
y += guideHeight;
}
}
}
}
canvas.restore();
if (!this.hideCardIOLogo) {
canvas.save();
canvas.translate(this.mLogoRect.exactCenterX(), this.mLogoRect.exactCenterY());
canvas.rotate(this.mRotationFlip * this.mRotation);
Logo logo = this.mLogo;
float f2 = this.mScale;
logo.draw(canvas, 100.0f * f2, f2 * 50.0f);
canvas.restore();
}
if (this.mShowTorch) {
canvas.save();
canvas.translate(this.mTorchRect.exactCenterX(), this.mTorchRect.exactCenterY());
canvas.rotate(this.mRotationFlip * this.mRotation);
this.mTorch.draw(canvas);
canvas.restore();
}
}
public void setDetectedCard(CreditCard creditCard) {
this.mDetectedCard = creditCard;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Rect rect;
try {
int action = event.getAction() & 255;
if (action == 0) {
Point p = new Point((int) event.getX(), (int) event.getY());
Rect r = Util.rectGivenCenter(p, 20, 20);
if (this.mShowTorch && (rect = this.mTorchRect) != null && Rect.intersects(rect, r)) {
this.mScanActivityRef.get().toggleFlash();
} else {
this.mScanActivityRef.get().triggerAutoFocus();
}
}
return false;
} catch (NullPointerException e) {
Log.d(TAG, "NullPointerException caught in onTouchEvent method");
return false;
}
}
private void decorateBitmap() {
RectF roundedRect = new RectF(2.0f, 2.0f, this.mBitmap.getWidth() - 2, this.mBitmap.getHeight() - 2);
float cornerRadius = this.mBitmap.getHeight() * 0.06666667f;
Bitmap maskBitmap = Bitmap.createBitmap(this.mBitmap.getWidth(), this.mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas maskCanvas = new Canvas(maskBitmap);
maskCanvas.drawColor(0);
Paint maskPaint = new Paint(1);
maskPaint.setColor(-16777216);
maskPaint.setStyle(Paint.Style.FILL);
maskCanvas.drawRoundRect(roundedRect, cornerRadius, cornerRadius, maskPaint);
Paint paint = new Paint();
paint.setFilterBitmap(false);
Canvas canvas = new Canvas(this.mBitmap);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawBitmap(maskBitmap, 0.0f, 0.0f, paint);
paint.setXfermode(null);
maskBitmap.recycle();
}
public void markupCard() {
if (this.mBitmap == null) {
return;
}
if (this.mDetectedCard.flipped) {
Matrix m = new Matrix();
m.setRotate(180.0f, this.mBitmap.getWidth() / 2, this.mBitmap.getHeight() / 2);
Bitmap bitmap = this.mBitmap;
this.mBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), this.mBitmap.getHeight(), m, false);
}
Canvas bc = new Canvas(this.mBitmap);
Paint paint = new Paint();
Util.setupTextPaintStyle(paint);
paint.setTextSize(this.mScale * 28.0f);
int len = this.mDetectedCard.cardNumber.length();
float sf = this.mBitmap.getWidth() / 428.0f;
int yOffset = (int) ((this.mDetectedCard.yoff * sf) - 6.0f);
for (int i = 0; i < len; i++) {
int xOffset = (int) (this.mDetectedCard.xoff[i] * sf);
bc.drawText("" + this.mDetectedCard.cardNumber.charAt(i), xOffset, yOffset, paint);
}
}
public boolean isAnimating() {
return this.mState != 0;
}
public void setCameraPreviewRect(Rect rect) {
this.mCameraPreviewRect = rect;
}
public void setTorchOn(boolean b) {
this.mTorch.setOn(b);
invalidate();
}
public void setUseCardIOLogo(boolean useCardIOLogo) {
this.mLogo.loadLogo(useCardIOLogo);
}
public Rect getTorchRect() {
return this.mTorchRect;
}
}