Code Scanner


Source link: https://github.com/yuriy-budiyev/code-scanner

Code Scanner

Code scanner library for Android, based on ZXing

Features

  • Auto focus and flash light control
  • Portrait and landscape screen orientations
  • Back and front facing cameras
  • Customizable viewfinder

Supported formats

1D product 1D industrial 2D
UPC-A Code 39 QR Code
UPC-E Code 93 Data Matrix
EAN-8 Code 128 Aztec
EAN-13 Codabar PDF 417
ITF MaxiCode
RSS-14
RSS-Expanded

Usage

Add dependency:

dependencies {

  implementation 'com.budiyev.android:code-scanner:1.6.1' 
}

Add camera permission to AndroidManifest.xml (Don't forget about dynamic permissions on API >= 23):

<uses-permission android:name="android.permission.CAMERA"/>

Define a view in your layout file:

<?xml version="1.0" encoding="utf-8"?> <FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<com.budiyev.android.codescanner.CodeScannerView

android:id="@+id/scanner_view"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:frameColor="@android:color/white"

app:frameCornersSize="50dp"

app:frameWidth="2dp"

app:maskColor="#77000000"

app:squareFrame="true"

app:autoFocusButtonColor="@android:color/white"

app:flashButtonColor="@android:color/white"

app:autoFocusButtonVisible="true"

app:flashButtonVisible="true"/> </FrameLayout>

And add following code to your activity:

public class MainActivity extends AppCompatActivity {

  private CodeScanner mCodeScanner;

@Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

CodeScannerView scannerView = findViewById(R.id.scanner_view);

// Use builder

mCodeScanner = CodeScanner.builder()

  /*camera can be specified by calling .camera(cameraId), 

 first back-facing camera on the device by default*/

  /*code formats*/

  .formats(CodeScanner.ALL_FORMATS)/*List<BarcodeFormat>*/

  /*or .formats(BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX, ...)*/

  /*or .format(BarcodeFormat.QR_CODE) - only one format*/

  /*auto focus*/

  .autoFocus(true).autoFocusMode(AutoFocusMode.SAFE).autoFocusInterval(2000L)

  /*flash*/

  .flash(false)

  /*decode callback*/

  .onDecoded(new DecodeCallback() {

@Override

public void onDecoded(@NonNull final Result result) {

 runOnUiThread(new Runnable() {

  @Override

  public void run() {

Toast.makeText(MainActivity.this, result.getText(),

  Toast.LENGTH_LONG).show();

  
}

 
}
);

}

  
}
)

  /*error callback*/

  .onError(new ErrorCallback() {

@Override

public void onError(@NonNull final Exception error) {

 runOnUiThread(new Runnable() {

  @Override

  public void run() {

Toast.makeText(MainActivity.this, error.getMessage(),

  Toast.LENGTH_LONG).show();

  
}

 
}
);

}

  
}
).build(this, scannerView);

// Or use constructor to create scanner with default parameters

// All parameters can be changed after scanner created

// mCodeScanner = new CodeScanner(this, scannerView);

 

// mCodeScanner.setDecodeCallback(...);

 

scannerView.setOnClickListener(new View.OnClickListener() {

 @Override

 public void onClick(View view) {

  mCodeScanner.startPreview();

 
}

}
);

  
}

@Override
  protected void onResume() {

super.onResume();

mCodeScanner.startPreview();

  
}

@Override
  protected void onPause() {

mCodeScanner.releaseResources();

super.onPause();

  
}
 
}

Preview

Resources

A simple library that allows you to easily delineate sections of a list or grid list.

BatteryStatsLibrary is an Android library for implementing basic battery informations and to calculate remaining time for charge and discharge.

This library provides a background service to track the battery usage and reports almost accurate time to charge and discharge.

Running instrumentation tests on Android using Espresso requires disabling animations. DeviceAnimationTestRule is a JUnit rule which disables device animations prior to running any test, and enable them after every test has been executed.

More than one type of object field list type.

Build text Layouts easily on Android.

Random Beans is a library that generates random Java beans.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes