From e16850deab53bd1658e0f0cacb79c33131e37818 Mon Sep 17 00:00:00 2001 From: maning <154292322@qq.com> Date: Tue, 20 Nov 2018 17:18:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=AB=E6=8F=8F=E7=BA=BF=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zxing/client/android/ViewfinderView.java | 44 ++++++++++++++---- .../res/drawable-xhdpi/mn_icon_scan_close.png | Bin 3601 -> 628 bytes 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/libraryzxing/src/main/java/com/google/zxing/client/android/ViewfinderView.java b/libraryzxing/src/main/java/com/google/zxing/client/android/ViewfinderView.java index b1078a2..a9fc29c 100755 --- a/libraryzxing/src/main/java/com/google/zxing/client/android/ViewfinderView.java +++ b/libraryzxing/src/main/java/com/google/zxing/client/android/ViewfinderView.java @@ -16,6 +16,7 @@ package com.google.zxing.client.android; +import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Resources; @@ -24,6 +25,7 @@ import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; +import android.util.Log; import android.view.View; import com.google.zxing.client.android.camera.CameraManager; @@ -50,6 +52,10 @@ public final class ViewfinderView extends View { private Context context; + private Rect frame; + private int margin; + private int lineW; + // This constructor is used when the class is built from an XML resource. public ViewfinderView(Context context, AttributeSet attrs) { super(context, attrs); @@ -69,6 +75,9 @@ public ViewfinderView(Context context, AttributeSet attrs) { paintText.setTextAlign(Paint.Align.CENTER); //扫描线 + 四角 paintLine.setColor(laserColor); + + margin = CommonUtils.dip2px(context, 4); + lineW = CommonUtils.dip2px(context, 2); } //设置颜色 @@ -92,7 +101,7 @@ public void onDraw(Canvas canvas) { if (cameraManager == null) { return; // not ready yet, early draw before done configuring } - Rect frame = cameraManager.getFramingRect(); + frame = cameraManager.getFramingRect(); Rect previewFrame = cameraManager.getFramingRectInPreview(); if (frame == null || previewFrame == null) { return; @@ -128,16 +137,8 @@ public void onDraw(Canvas canvas) { canvas.drawRect(frame.right - rectH, frame.bottom - rectW, frame.right + 1, frame.bottom + 1, paintLine); //中间的线:动画 - int margin = CommonUtils.dip2px(context, 6); - int lineW = CommonUtils.dip2px(context, 2); if (linePosition == 0) { linePosition = frame.top + margin; - } else { - if (linePosition > frame.bottom - margin * 2) { - linePosition = frame.top + margin; - } else { - linePosition += 8; - } } canvas.drawRect(frame.left + margin, linePosition, frame.right - margin, linePosition + lineW, paintLine); @@ -148,10 +149,33 @@ public void onDraw(Canvas canvas) { frame.top, frame.right, frame.bottom); + + startAnimation(); + } + + + ValueAnimator anim; + + public void startAnimation() { + if (anim != null && anim.isRunning()) { + return; + } + anim = ValueAnimator.ofInt(frame.top + margin, frame.bottom - margin); + anim.setRepeatCount(ValueAnimator.INFINITE); + anim.setRepeatMode(ValueAnimator.RESTART); + anim.setDuration(2500); + anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator animation) { + linePosition = (int) animation.getAnimatedValue(); + postInvalidate(); + } + }); + anim.start(); } public void drawViewfinder() { - invalidate(); + postInvalidate(); } } diff --git a/libraryzxing/src/main/res/drawable-xhdpi/mn_icon_scan_close.png b/libraryzxing/src/main/res/drawable-xhdpi/mn_icon_scan_close.png index c9abd6c9cd05f554b4a8977b01bded26b4395ca5..0380c6f3ac38274d15f255c9ebef6b61ee8deb14 100644 GIT binary patch literal 628 zcmV-)0*n2LP)F3^|2#tWcd1jS2$nfFBW8NFhdc?V!eL`TV7MF7nF0bmax4f+rj zf|(xyJSPAEuSE1zLMQ?-^8vv7XrLbechL}r@NeV5L{!XId;>FI1NfRqhC=u+Jb-T^ zN^_q*iU8@;nJ)-|keS;rfPdRSc!xIy zSc=dhyg7grp;dSnfD*#cYCG%X01!XVr}1l!MUTTZUo_KHN&UO=;TGPl0#4~N2+hK~ z1I#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