Skip to content

Commit

Permalink
Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriy-budiyev committed Aug 16, 2017
1 parent d677883 commit 262e2fa
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/main/java/com/budiyev/android/codescanner/CodeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.budiyev.android.codescanner;

import android.Manifest;
import android.content.Context;
import android.graphics.Point;
import android.hardware.Camera;
Expand All @@ -41,6 +42,12 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
* Scanner of different codes
*
* @see CodeScannerView
* @see BarcodeFormat
*/
public final class CodeScanner {
public static final List<BarcodeFormat> ALL_FORMATS =
Arrays.asList(BarcodeFormat.AZTEC, BarcodeFormat.CODABAR, BarcodeFormat.CODE_39,
Expand Down Expand Up @@ -84,11 +91,27 @@ public final class CodeScanner {
private boolean mSurfaceAvailable;
private boolean mFocusing;

/**
* CodeScanner, associated with the first back-facing camera on the device
*
* @param context Context
* @param view A view to display the preview
* @see CodeScannerView
*/
@MainThread
public CodeScanner(@NonNull Context context, @NonNull CodeScannerView view) {
this(context, view, UNSPECIFIED);
}

/**
* CodeScanner, associated with particular hardware camera
*
* @param context Context
* @param view A view to display the preview
* @param cameraId Camera id (between {@code 0} and
* {@link Camera#getNumberOfCameras()} - {@code 1})
* @see CodeScannerView
*/
@MainThread
public CodeScanner(@NonNull Context context, @NonNull CodeScannerView view, int cameraId) {
mContext = context;
Expand All @@ -103,6 +126,15 @@ public CodeScanner(@NonNull Context context, @NonNull CodeScannerView view, int
mCameraId = cameraId;
}

/**
* Set formats, decoder to react to ({@link #ALL_FORMATS} bu default)
*
* @param formats Formats
* @see BarcodeFormat
* @see #ALL_FORMATS
* @see #ONE_DIMENSIONAL_FORMATS
* @see #TWO_DIMENSIONAL_FORMATS
*/
public void setFormats(@NonNull List<BarcodeFormat> formats) {
mInitializeLock.lock();
try {
Expand All @@ -116,18 +148,38 @@ public void setFormats(@NonNull List<BarcodeFormat> formats) {
}
}

/**
* Set format, decoder to react to
*
* @param format Format
* @see BarcodeFormat
*/
public void setFormat(@NonNull BarcodeFormat format) {
setFormats(Collections.singletonList(format));
}

/**
* Set callback of the decoding process
*
* @param decodeCallback Callback
* @see DecodeCallback
*/
public void setDecodeCallback(@Nullable DecodeCallback decodeCallback) {
mDecodeCallback = decodeCallback;
}

/**
* Whether if preview is active
*/
public boolean isPreviewActive() {
return mPreviewActive;
}

/**
* Start camera preview
* <br>
* Requires {@link Manifest.permission#CAMERA} permission
*/
@MainThread
public void startPreview() {
mInitializeLock.lock();
Expand All @@ -146,6 +198,9 @@ public void startPreview() {
}
}

/**
* Stop camera preview
*/
@MainThread
public void stopPreview() {
if (mInitialized && mPreviewActive) {
Expand All @@ -154,6 +209,9 @@ public void stopPreview() {
}
}

/**
* Release resources
*/
@MainThread
public void releaseResources() {
mPreviewActive = false;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/budiyev/android/codescanner/CodeScannerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
import android.view.SurfaceView;
import android.view.ViewGroup;

/**
* A view to display code scanner preview
*
* @see CodeScanner
*/
public final class CodeScannerView extends ViewGroup {
private static final boolean DEFAULT_SQUARE_FRAME = false;
private static final int DEFAULT_MASK_COLOR = 0x77000000;
Expand All @@ -47,16 +52,31 @@ public final class CodeScannerView extends ViewGroup {
private Point mFrameSize;
private LayoutListener mLayoutListener;

/**
* A view to display code scanner preview
*
* @see CodeScanner
*/
public CodeScannerView(@NonNull Context context) {
super(context);
initialize(context, null);
}

/**
* A view to display code scanner preview
*
* @see CodeScanner
*/
public CodeScannerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize(context, attrs);
}

/**
* A view to display code scanner preview
*
* @see CodeScanner
*/
public CodeScannerView(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
Expand Down Expand Up @@ -137,22 +157,47 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
}

/**
* Set whether frame is square or a rectangle
*
* @param squareFrame is {@code true}, the frame will be square, rectangle otherwise
*/
public void setSquareFrame(boolean squareFrame) {
mViewFinderView.setSquareFrame(squareFrame);
}

/**
* Set color of the space outside of the framing rect
*
* @param color Mask color
*/
public void setMaskColor(@ColorInt int color) {
mViewFinderView.setMaskColor(color);
}

/**
* Set color of the frame
*
* @param color Frame color
*/
public void setFrameColor(@ColorInt int color) {
mViewFinderView.setFrameColor(color);
}

/**
* Set frame width
*
* @param width Frame width in pixels
*/
public void setFrameWidth(@Px int width) {
mViewFinderView.setFrameWidth(width);
}

/**
* Set length on the frame corners
*
* @param size Length in pixels
*/
public void setFrameCornersSize(@Px int size) {
mViewFinderView.setFrameCornersSize(size);
}
Expand Down

0 comments on commit 262e2fa

Please sign in to comment.