Skip to content

Commit

Permalink
减肥
Browse files Browse the repository at this point in the history
  • Loading branch information
hupei committed Aug 25, 2016
1 parent b65d95c commit 81485b4
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 300 deletions.
Binary file added preview/zxingscanner-1.2.1.jar
Binary file not shown.
13 changes: 4 additions & 9 deletions zxingscanner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ install {
project {
packaging 'aar'
artifactId 'zxingscanner'
name 'android zxing style' //添加项目描述
name 'android zxing style'
url siteUrl
//设置开源证书信息
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
//填写开发者基本信息
developers {
developer {
id 'mylhyl'
Expand Down Expand Up @@ -80,22 +78,19 @@ artifacts {
archives javadocJar
archives sourcesJar
}
//配置上传bintray相关信息
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
//读取bintray帐号和密码。
//一般的为了保密和安全性,在项目的local.properties文件中添加两行句话即可:
user = properties.getProperty("BINTRAY_USER")
key = properties.getProperty("BINTRAY_KEY")
configurations = ['archives']
pkg {
repo = "maven" //上传的中央仓库名称
name = "zxingscanner" //上传的项目的名字
repo = "maven"
name = "zxingscanner"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true //是否发布
publish = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.zxing.BarcodeFormat;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.result.ParsedResult;
import com.mylhyl.zxing.scanner.camera.CameraManager;
import com.mylhyl.zxing.scanner.common.Scanner;

Expand Down Expand Up @@ -55,10 +54,12 @@ private void init(Context context, AttributeSet attrs, int defStyle) {
mBeepManager = new BeepManager(context);

mSurfaceView = new SurfaceView(context, attrs, defStyle);
addView(mSurfaceView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
addView(mSurfaceView, new LayoutParams(LayoutParams.MATCH_PARENT
, LayoutParams.MATCH_PARENT));

mViewfinderView = new ViewfinderView(context, attrs);
addView(mViewfinderView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
addView(mViewfinderView, new LayoutParams(LayoutParams.MATCH_PARENT
, LayoutParams.MATCH_PARENT));
}

public void onResume() {
Expand Down Expand Up @@ -132,8 +133,8 @@ public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
//扫描成功
if (mScannerCompletionListener != null) {
//转换结果
ParsedResult parsedResult = Scanner.parseResult(rawResult);
mScannerCompletionListener.OnScannerCompletion(rawResult, parsedResult, barcode);
mScannerCompletionListener.OnScannerCompletion(rawResult,
Scanner.parseResult(rawResult), barcode);
}
//设置扫描结果图片
if (barcode != null) {
Expand Down Expand Up @@ -291,7 +292,8 @@ public void setLaserFrameCornerWidth(int laserFrameCornerWidth) {
* @param isBottom 是否在扫描框下方
* @param textMargin 离扫描框间距 dp
*/
public void setDrawText(String text, int textSize, int textColor, boolean isBottom, int textMargin) {
public void setDrawText(String text, int textSize, int textColor
, boolean isBottom, int textMargin) {
mViewfinderView.setDrawText(text, textSize, textColor, isBottom, textMargin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.zxing.DecodeHintType;
import com.google.zxing.Result;
import com.mylhyl.zxing.scanner.camera.CameraManager;
import com.mylhyl.zxing.scanner.common.Intents;
import com.mylhyl.zxing.scanner.common.Scanner;
import com.mylhyl.zxing.scanner.decode.DecodeThread;

Expand Down Expand Up @@ -87,16 +88,13 @@ public void handleMessage(Message message) {
0, compressedBitmap.length, null);
barcode = barcode.copy(Bitmap.Config.ARGB_8888, true);
}
scaleFactor = bundle
.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
scaleFactor = bundle.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
}
scannerView
.handleDecode((Result) message.obj, barcode, scaleFactor);
scannerView.handleDecode((Result) message.obj, barcode, scaleFactor);
break;
case Scanner.DECODE_FAILED:
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(),
Scanner.DECODE);
cameraManager.requestPreviewFrame(decodeThread.getHandler(), Scanner.DECODE);
break;
case Scanner.RETURN_SCAN_RESULT:
break;
Expand All @@ -123,8 +121,7 @@ public void quitSynchronously() {
private void restartPreviewAndDecode() {
if (state == State.SUCCESS) {
state = State.PREVIEW;
cameraManager.requestPreviewFrame(decodeThread.getHandler(),
Scanner.DECODE);
cameraManager.requestPreviewFrame(decodeThread.getHandler(), Scanner.DECODE);
scannerView.drawViewfinder();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @author [email protected] (Daniel Switkin)
*/
final class ViewfinderView extends View {

private static final int CURRENT_POINT_OPACITY = 0xA0;
private static final int MAX_RESULT_POINTS = 20;
private static final int POINT_SIZE = 6;
Expand Down Expand Up @@ -182,8 +183,8 @@ private void drawFrameCorner(Canvas canvas, Rect frame) {
// 左上角
canvas.drawRect(frame.left - laserFrameCornerWidth, frame.top, frame.left, frame.top
+ laserFrameCornerLength, paint);
canvas.drawRect(frame.left - laserFrameCornerWidth, frame.top - laserFrameCornerWidth, frame.left
+ laserFrameCornerLength, frame.top, paint);
canvas.drawRect(frame.left - laserFrameCornerWidth, frame.top - laserFrameCornerWidth
, frame.left + laserFrameCornerLength, frame.top, paint);
// 右上角
canvas.drawRect(frame.right, frame.top, frame.right + laserFrameCornerWidth,
frame.top + laserFrameCornerLength, paint);
Expand Down Expand Up @@ -224,15 +225,17 @@ private void drawLaserLine(Canvas canvas, Rect frame) {
if (laserLineResId == 0) {
paint.setStyle(Paint.Style.FILL);
paint.setColor(laserColor);// 设置扫描线颜色
canvas.drawRect(frame.left, laserLineTop, frame.right, laserLineTop + laserLineHeight, paint);
canvas.drawRect(frame.left, laserLineTop, frame.right
, laserLineTop + laserLineHeight, paint);
} else {
if (laserLineBitmap == null)//图片资源文件转为 Bitmap
laserLineBitmap = BitmapFactory.decodeResource(getResources(), laserLineResId);
int height = laserLineBitmap.getHeight();//取原图高
//网格图片
if (isLaserGridLine) {
RectF dstRectF = new RectF(frame.left, frame.top, frame.right, laserLineTop);
Rect srcRect = new Rect(0, (int) (height - dstRectF.height()), laserLineBitmap.getWidth(), height);
Rect srcRect = new Rect(0, (int) (height - dstRectF.height())
, laserLineBitmap.getWidth(), height);
canvas.drawBitmap(laserLineBitmap, srcRect, dstRectF, paint);
}
//线条图片
Expand All @@ -241,7 +244,8 @@ private void drawLaserLine(Canvas canvas, Rect frame) {
if (laserLineHeight == Scanner.dp2px(getContext(), DEFAULT_LASER_LINE_HEIGHT)) {
laserLineHeight = laserLineBitmap.getHeight() / 2;
}
Rect laserRect = new Rect(frame.left, laserLineTop, frame.right, laserLineTop + laserLineHeight);
Rect laserRect = new Rect(frame.left, laserLineTop, frame.right
, laserLineTop + laserLineHeight);
canvas.drawBitmap(laserLineBitmap, null, laserRect, paint);
}
}
Expand Down Expand Up @@ -345,7 +349,8 @@ public void setLaserFrameCornerWidth(int laserFrameCornerWidth) {
this.laserFrameCornerWidth = Scanner.dp2px(getContext(), laserFrameCornerWidth);
}

public void setDrawText(String text, int textSize, int textColor, boolean isBottom, int textMargin) {
public void setDrawText(String text, int textSize, int textColor
, boolean isBottom, int textMargin) {
if (!TextUtils.isEmpty(text))
drawText = text;
if (textSize > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Context;
import android.graphics.Point;
import android.hardware.Camera;
import android.util.Log;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;
Expand All @@ -34,8 +35,9 @@
*/
final class CameraConfigurationManager {

// private static final String TAG = "CameraConfiguration";

private static final String TAG = "CameraConfiguration";
private static final int FRONT_LIGHT_MODE_ON = 0;
private static final int FRONT_LIGHT_MODE_OFF = 1;
private final Context context;
private int cwNeededRotation;
private int cwRotationFromDisplayToCamera;
Expand Down Expand Up @@ -82,63 +84,38 @@ void initFromCameraParameters(OpenCamera camera) {
+ displayRotation);
}
}
// Log.i(TAG, "Display at: " + cwRotationFromNaturalToDisplay);

int cwRotationFromNaturalToCamera = camera.getOrientation();
// Log.i(TAG, "Camera at: " + cwRotationFromNaturalToCamera);

// Still not 100% sure about this. But acts like we need to flip this:
if (camera.getFacing() == CameraFacing.FRONT) {
cwRotationFromNaturalToCamera = (360 - cwRotationFromNaturalToCamera) % 360;
// Log.i(TAG, "Front camera overriden to: " + cwRotationFromNaturalToCamera);
}

/*
* SharedPreferences prefs =
* PreferenceManager.getDefaultSharedPreferences(context); String
* overrideRotationString; if (camera.getFacing() == CameraFacing.FRONT)
* { overrideRotationString =
* prefs.getString(PreferencesActivity.KEY_FORCE_CAMERA_ORIENTATION_FRONT
* , null); } else { overrideRotationString =
* prefs.getString(PreferencesActivity.KEY_FORCE_CAMERA_ORIENTATION,
* null); } if (overrideRotationString != null &&
* !"-".equals(overrideRotationString)) { Log.i(TAG,
* "Overriding camera manually to " + overrideRotationString);
* cwRotationFromNaturalToCamera =
* Integer.parseInt(overrideRotationString); }
*/

cwRotationFromDisplayToCamera = (360 + cwRotationFromNaturalToCamera - cwRotationFromNaturalToDisplay) % 360;
// Log.i(TAG, "Final display orientation: " + cwRotationFromDisplayToCamera);
cwRotationFromDisplayToCamera = (360 +
cwRotationFromNaturalToCamera - cwRotationFromNaturalToDisplay) % 360;

if (camera.getFacing() == CameraFacing.FRONT) {
// Log.i(TAG, "Compensating rotation for front camera");
cwNeededRotation = (360 - cwRotationFromDisplayToCamera) % 360;
} else {
cwNeededRotation = cwRotationFromDisplayToCamera;
}
// Log.i(TAG, "Clockwise rotation from display to camera: " + cwNeededRotation);

Point theScreenResolution = new Point();
display.getSize(theScreenResolution);
screenResolution = theScreenResolution;
// Log.i(TAG, "Screen resolution in current orientation: " + screenResolution);
cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(
parameters, screenResolution);
// Log.i(TAG, "Camera resolution: " + cameraResolution);
bestPreviewSize = CameraConfigurationUtils.findBestPreviewSizeValue(
parameters, screenResolution);
// Log.i(TAG, "Best available preview size: " + bestPreviewSize);

boolean isScreenPortrait = screenResolution.x < screenResolution.y;
boolean isPreviewSizePortrait = bestPreviewSize.x < bestPreviewSize.y;

if (isScreenPortrait == isPreviewSizePortrait) {
previewSizeOnScreen = bestPreviewSize;
} else {
previewSizeOnScreen = new Point(bestPreviewSize.y,
bestPreviewSize.x);
previewSizeOnScreen = new Point(bestPreviewSize.y, bestPreviewSize.x);
}
// Log.i(TAG, "Preview size on screen: " + previewSizeOnScreen);
}

/**
Expand All @@ -153,18 +130,16 @@ void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {
Camera.Parameters parameters = theCamera.getParameters();

if (parameters == null) {
// Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
return;
}

// Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

// if (safeMode) {
// Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
// }
if (safeMode) {
Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
}

// 默认关闪光灯
initializeTorch(parameters, FrontLightMode.OFF, safeMode);
initializeTorch(parameters, FRONT_LIGHT_MODE_OFF, safeMode);
// 自动对焦
boolean autoFocus = true;
// 持续对焦
Expand Down Expand Up @@ -202,9 +177,8 @@ void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {
Camera.Parameters afterParameters = theCamera.getParameters();
Camera.Size afterSize = afterParameters.getPreviewSize();
if (afterSize != null
&& (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
// Log.w(TAG, "Camera said it supported preview size " + bestPreviewSize.x + 'x' + bestPreviewSize.y
// + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
&& (bestPreviewSize.x != afterSize.width
|| bestPreviewSize.y != afterSize.height)) {
bestPreviewSize.x = afterSize.width;
bestPreviewSize.y = afterSize.height;
}
Expand Down Expand Up @@ -236,7 +210,8 @@ boolean getTorchState(Camera camera) {
if (parameters != null) {
String flashMode = camera.getParameters().getFlashMode();
return flashMode != null
&& (Camera.Parameters.FLASH_MODE_ON.equals(flashMode) || Camera.Parameters.FLASH_MODE_TORCH
&& (Camera.Parameters.FLASH_MODE_ON.equals(flashMode)
|| Camera.Parameters.FLASH_MODE_TORCH
.equals(flashMode));
}
}
Expand All @@ -250,8 +225,8 @@ void setTorch(Camera camera, boolean newSetting) {
}

private void initializeTorch(Camera.Parameters parameters,
FrontLightMode frontLightMode, boolean safeMode) {
boolean currentSetting = frontLightMode == FrontLightMode.ON;
int frontLightMode, boolean safeMode) {
boolean currentSetting = frontLightMode == FRONT_LIGHT_MODE_ON;
doSetTorch(parameters, currentSetting, safeMode);
}

Expand Down

This file was deleted.

Loading

0 comments on commit 81485b4

Please sign in to comment.