package com.king.zxing;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
/**
* 取景视图:主要用于渲染扫描效果
*
* @author <a href="mailto:jenly1314@gmail.com">Jenly</a>
*/
public class ViewfinderView extends View {
/**
* 默认范围比例,之所以默认为 1.2 是因为内切圆半径和外切圆半径之和的二分之一(即:(1 + √2) / 2 ≈ 1.2)
*/
private final float DEFAULT_RANGE_RATIO = 1.2F;
private final float MAX_ZOOM_RATIO = 1.2F;
/**
* 画笔
*/
private Paint paint;
/**
* 文本画笔
*/
private TextPaint textPaint;
/**
* 扫码框外面遮罩颜色
*/
private int maskColor;
/**
* 扫描区域边框颜色
*/
private int frameColor;
/**
* 扫描线颜色
*/
private int laserColor;
/**
* 扫码框四角颜色
*/
private int cornerColor;
/**
* 提示文本与扫码框的边距
*/
private float labelTextPadding;
/**
* 提示文本的宽度
*/
private int labelTextWidth;
/**
* 提示文本的位置
*/
private TextLocation labelTextLocation;
/**
* 扫描区域提示文本
*/
private String labelText;
/**
* 扫描区域提示文本颜色
*/
private int labelTextColor;
/**
* 提示文本字体大小
*/
private float labelTextSize;
/**
* 扫描线开始位置
*/
public int scannerStart = 0;
/**
* 扫描线结束位置
*/
public int scannerEnd = 0;
/**
* 扫码框宽
*/
private int frameWidth;
/**
* 扫码框高
*/
private int frameHeight;
/**
* 扫描激光线风格
*/
private LaserStyle laserStyle;
/**
* 网格列数
*/
private int gridColumn;
/**
* 网格高度
*/
private int gridHeight;
/**
* 扫码框
*/
private Rect frame;
/**
* 扫描区边角的宽
*/
private int cornerRectWidth;
/**
* 扫描区边角的高
*/
private int cornerRectHeight;
/**
* 扫描线每次移动距离
*/
private int scannerLineMoveDistance;
/**
* 扫描线高度
*/
private int scannerLineHeight;
/**
* 边框线宽度
*/
private int frameLineWidth;
/**
* 扫描动画延迟间隔时间 默认20毫秒
*/
private int scannerAnimationDelay;
/**
* 扫码框占比
*/
private float frameRatio;
/**
* 扫码框内间距
*/
private float framePaddingLeft;
private float framePaddingTop;
private float framePaddingRight;
private float framePaddingBottom;
/**
* 扫码框对齐方式
*/
private FrameGravity frameGravity;
private int pointColor;
private int pointStrokeColor;
private Bitmap pointBitmap;
private boolean isShowPointAnim = true;
private float pointRadius;
private float pointStrokeRatio;
private float pointStrokeRadius;
/**
* 当前缩放比例
*/
private float currentZoomRatio = 1.0f;
/**
* 最后一次缩放比例(即上一次缩放比例)
*/
private float lastZoomRatio;
/**
* 缩放速度
*/
private float zoomSpeed = 0.02f;
private int zoomCount;
/**
* 结果点有效点击范围半径
*/
private float pointRangeRadius;
private Bitmap laserBitmap;
private float laserBitmapRatio;
private float laserBitmapWidth;
private int viewfinderStyle = ViewfinderStyle.CLASSIC;
private List<Point> pointList;
private boolean isShowPoints = false;
private OnItemClickListener onItemClickListener;
private GestureDetector gestureDetector;
/**
* 取景框样式
*/
@IntDef({ViewfinderStyle.CLASSIC, ViewfinderStyle.POPULAR})
@Retention(RetentionPolicy.SOURCE)
public @interface ViewfinderStyle {
/**
* 经典样式:经典的扫码风格(带扫码框)
*/
int CLASSIC = 0;
/**
* 流行样式:类似于新版的微信全屏扫码(不带扫码框)
*/
int POPULAR = 1;
}
/**
* 扫描线样式
*/
public enum LaserStyle {
NONE(0), LINE(1), GRID(2), IMAGE(3);
private final int mValue;
LaserStyle(int value) {
mValue = value;
}
private static LaserStyle getFromInt(int value) {
for (LaserStyle style : LaserStyle.values()) {
if (style.mValue == value) {
return style;
}
}
return LaserStyle.LINE;
}
}
/**
* 文字位置
*/
public enum TextLocation {
TOP(0), BOTTOM(1);
private final int mValue;
TextLocation(int value) {
mValue = value;
}
private static TextLocation getFromInt(int value) {
for (TextLocation location : TextLocation.values()) {
if (location.mValue == value) {
return location;
}
}
return TextLocation.TOP;
}
}
/**
* 扫码框对齐方式
*/
public enum FrameGravity {
CENTER(0), LEFT(1), TOP(2), RIGHT(3), BOTTOM(4);
private final int mValue;
FrameGravity(int value) {
mValue = value;
}
private static FrameGravity getFromInt(int value) {
for (FrameGravity gravity : values()) {
if (gravity.mValue == value) {
return gravity;
}
}
return CENTER;
}
}
public ViewfinderView(Context context) {
this(context, null);
}
public ViewfinderView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public ViewfinderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
/**
* 初始化
*
* @param context
* @param attrs
*/
private void init(Context context, AttributeSet attrs) {
// 初始化自定义属性信息
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView);
maskColor = array.getColor(R.styleable.ViewfinderView_maskColor, ContextCompat.getColor(context, R.color.viewfinder_mask));
frameColor = array.getColor(R.styleable.ViewfinderView_frameColor, ContextCompat.getColor(context, R.color.viewfinder_frame));
cornerColor = array.getColor(R.styleable.ViewfinderView_cornerColor, ContextCompat.getColor(context, R.color.vie
没有合适的资源?快使用搜索试试~ 我知道了~
基于ZXing库优化扫码和生成二维码/条形码功能,扫码界面完全支持自定义,也可一行代码使用默认实现的扫码功能
共117个文件
java:37个
xml:32个
png:21个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 187 浏览量
2023-06-17
10:05:57
上传
评论
收藏 11.27MB ZIP 举报
温馨提示
ZXingLite for Android 是ZXing的精简极速版,基于ZXing库优化扫码和生成二维码/条形码功能,扫码界面完全支持自定义,也可一行代码使用默认实现的扫码功能,优化扫码和生成二维码/条形码功能,扫描风格支持:微信的线条样式,支付宝的网格样式。几句代码轻松拥有扫码功能 ,ZXingLite让集成更简单。(扫码识别速度快如微信)。
资源推荐
资源详情
资源评论
收起资源包目录
基于ZXing库优化扫码和生成二维码/条形码功能,扫码界面完全支持自定义,也可一行代码使用默认实现的扫码功能 (117个子文件)
app-release.apk 3.73MB
gradlew.bat 2KB
GIF.gif 7.81MB
.gitignore 95B
.gitignore 8B
.gitignore 7B
versions.gradle 2KB
build.gradle 1KB
build.gradle 1KB
build.gradle 479B
bintray.gradle 367B
settings.gradle 367B
gradlew 5KB
gradle-wrapper.jar 53KB
ViewfinderView.java 30KB
CodeUtils.java 23KB
DefaultCameraScan.java 20KB
DecodeConfig.java 16KB
BitmapUtils.java 11KB
MainActivity.java 9KB
CaptureFragment.java 8KB
LogUtils.java 8KB
CameraScan.java 8KB
CaptureActivity.java 7KB
CustomCaptureActivity.java 7KB
DecodeFormatManager.java 6KB
AmbientLightManager.java 4KB
QRCodeActivity.java 4KB
PermissionUtils.java 4KB
CustomFullScanActivity.java 4KB
ResolutionCameraConfig.java 4KB
MultiFormatAnalyzer.java 3KB
BarcodeFormatAnalyzer.java 3KB
StatusBarUtils.java 3KB
CodeActivity.java 3KB
BeepManager.java 3KB
CameraConfig.java 3KB
UriUtils.java 3KB
AreaRectAnalyzer.java 2KB
AspectRatioCameraConfig.java 2KB
EasyCaptureActivity.java 2KB
ImageAnalyzer.java 2KB
CaptureFragmentActivity.java 1KB
ICameraControl.java 1KB
QRCodeAnalyzer.java 785B
ExampleInstrumentedTest.java 745B
ExampleInstrumentedTest.java 704B
Analyzer.java 660B
ICamera.java 519B
ExampleUnitTest.java 395B
ExampleUnitTest.java 375B
output-metadata.json 375B
LICENSE 11KB
change_log.md 3KB
zxl_beep.mp3 1KB
ic_launcher-web.png 14KB
ic_launcher_round.png 11KB
ic_launcher_round.png 7KB
ic_launcher_round.png 5KB
ic_launcher_foreground.png 5KB
ic_launcher.png 4KB
ic_laser_line.png 3KB
ic_launcher_foreground.png 3KB
ic_launcher_round.png 3KB
ic_launcher.png 3KB
ic_launcher_foreground.png 2KB
ic_launcher_round.png 2KB
logo.png 2KB
ic_launcher.png 2KB
ic_launcher_foreground.png 2KB
ic_launcher.png 1KB
ic_launcher_foreground.png 1KB
ic_launcher.png 1022B
btn_none.png 1008B
btn_back_pressed.png 804B
btn_back_normal.png 726B
proguard-rules.pro 1KB
proguard-rules.pro 772B
consumer-rules.pro 0B
gradle.properties 2KB
gradle-wrapper.properties 236B
gradle.properties 63B
activity_main.xml 6KB
ic_launcher_background.xml 6KB
attrs.xml 3KB
AndroidManifest.xml 2KB
zxl_flashlight_on.xml 2KB
custom_capture_activity.xml 1KB
qr_code_activity.xml 1KB
top_title_back_bar.xml 1KB
custom_activity.xml 1KB
zxl_flashlight_off.xml 1KB
zxl_capture.xml 899B
code_activity.xml 795B
styles.xml 696B
styles.xml 640B
colors.xml 523B
toolbar.xml 511B
fragment_activity.xml 507B
toolbar_capture.xml 465B
共 117 条
- 1
- 2
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6650
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功