"ui";
runtime.loadDex("core.dex");
importClass(com.google.zxing.PlanarYUVLuminanceSource);
importClass(com.google.zxing.common.HybridBinarizer)
importClass(com.google.zxing.BinaryBitmap)
importClass(com.google.zxing.MultiFormatReader)
importClass(com.google.zxing.NotFoundException)
importClass(com.google.zxing.DecodeHintType)
importClass(com.google.zxing.BarcodeFormat)
var scanBinder = null;
var scanBindService = function () {
var intent = new android.content.Intent();
intent.setComponent(new android.content.ComponentName("com.ten.weixinpay", "com.ten.weixinpay.MyService"));
let listener = new JavaAdapter(android.content.ServiceConnection, {
onServiceConnected(componentName, iBinder) {
print("链接成功");
scanBinder = iBinder;
},
onServiceDisconnected(componentName) {
print("链接断开")
scanBinder = null;
scanBindService()
}
});
activity.bindService(intent, listener, 1)
}
//scanBindService();
var scan = function () {
if (!scanBinder) {
scanBindService();
};
if (!scanBinder) {
toast("初始化中")
return;
}
var data = android.os.Parcel.obtain();
var result = android.os.Parcel.obtain();
scanBinder.transact(1, data, result, 0);
print("返回");
result.readException();
return result.readString();
}
var show = function (callback) {
ui.layout(
<vertical>
<button id="back">返回</button>
<android.view.SurfaceView id="surfaceView" />
</vertical>
);
ui.back.click(function () {
callback("取消");
})
var mCamera;
var surfaceHolder = ui.surfaceView.getHolder();
//90度
var rotateCW = function (data2, imageWidth, imageHeight) {
var yuv = util.java.array('byte', imageWidth * imageHeight);
var i = 0;
for (var x = 0; x < imageWidth; x++) {
for (var y = imageHeight - 1; y >= 0; y--) {
yuv[i] = data2[(y * imageWidth) + x];
i++;
}
}
return yuv;
}
var size = null;
var stateHandler = new android.os.Handler(new JavaAdapter(android.os.Handler.Callback,{
handleMessage(message) {
print(message);
if(message.what == 1){
print(message.obj);
}
return true;
}
}))
var setCallback = function () {
mCamera.setOneShotPreviewCallback(new JavaAdapter(android.hardware.Camera.PreviewCallback, {
onPreviewFrame(data, camera) {
// stateHandler.obtainMessage(1,data).sendToTarget();
try {
var source = new com.google.zxing.PlanarYUVLuminanceSource(data, size.width, size.height, 0, 0, size.width, size.height, false);
if (!source) {
return;
}
var bitmap = new com.google.zxing.BinaryBitmap(new com.google.zxing.common.HybridBinarizer(source));
if (!bitmap) {
return;
}
var reader = new com.google.zxing.MultiFormatReader();
var m = new java.util.HashMap()
m.put(com.google.zxing.DecodeHintType.CHARACTER_SET, "utf-8")
var rawResult = reader.decode(bitmap, m);
if (rawResult) {
ui.post(function () {
callback(rawResult.getText());
})
}
} catch (error) {
//print(error);
}
setCallback()
}
}))
}
var focusing = false;
var autoFocusCallback = new android.hardware.Camera.AutoFocusCallback({
onAutoFocus(success, theCamera) {
focusing = false;
setAutoFocus()
//setCallback();
}
})
var setAutoFocus = function(){
if(!focusing){
focusing = true;
mCamera.autoFocus(autoFocusCallback);
}
}
surfaceHolder.addCallback(new JavaAdapter(android.view.SurfaceHolder.Callback, {
surfaceCreated: function (surfaceDestroyed) {
mCamera = android.hardware.Camera.open(0); // 0 或者 1
if (!mCamera) {
toast("摄像头打开失败");
return
}
try {
var parameters = mCamera.getParameters();
size = parameters.getPreviewSize();
decodeFormats = parameters.getPreviewFormat();
var focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO)) {
parameters.setFocusMode(android.hardware.Camera.Parameters.FOCUS_MODE_AUTO);
}
mCamera.setParameters(parameters)
mCamera.setDisplayOrientation(90);
mCamera.setPreviewDisplay(surfaceHolder);
} catch (error) {
print(error);
}
},
surfaceChanged: function (surfaceDestroyed, arg1, arg2, arg3) {
mCamera.startPreview();
setAutoFocus();
setCallback();
},
surfaceDestroyed: function (surfaceDestroyed) {
focusing = false;
if (mCamera) {
try {
mCamera.release();
} catch (error) {}
}
}
}))
}
var def = function (code) {
$ui.layout(
<vertical>
<input id="name" text="" />
<button id="ok" w="120" h="120" text="扫一扫" />
</vertical>
);
ui.post(function () {
ui.name.attr("text", code || "");
})
ui.ok.click(function () {
show(function (result) {
def(result)
})
});
}
def("")
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Autojs调用zxing实现条形码与二维码.zip (3个子文件)
Autojs调用zxing实现条形码与二维码
.DS_Store 6KB
main.js 5KB
core.dex 481KB
共 3 条
- 1
资源评论
小锋学长生活大爆炸
- 粉丝: 8w+
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功