Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

Latest commit

 

History

History
105 lines (85 loc) · 4.94 KB

README.md

File metadata and controls

105 lines (85 loc) · 4.94 KB

DroidXing Build Status

Simple Android wrapper for ZXing.

Summary

DroidXing is a fork of the ZXing Android app intended for anyone, who only wants to allow users to input data in their app via a barcode (1D or 2D, including QR codes).

The flow revolves around the capture activity that gets started, provides the viewfinder UI to allow the user to scan the code and closes, handing the control back to your app.

Usage

The easiest way to import the library into your project is by grabbing the AAR from Maven Central. Alternatively, you can check out the the source and manually import it into your IDE.

depedencies {
  compile 'net.gouline.droidxing:droidxing:0.1.1@aar'
}

Next, declare the CaptureActivity in your AndroidManifest.xml.

<activity android:name="net.gouline.droidxing.CaptureActivity" />

Now you can just start CaptureActivity for result and let it handle the scanning.

activity.startActivityForResult(new Intent(activity, CaptureActivity.class), 0);

Once the code has been scanned, you can retrieve the data from the result by overriding onActivityResult() in the activity that started the CaptureActivity.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);
  if (resultCode == RESULT_OK && data != null) {
    Serializable codeResult = data.getSerializableExtra(CaptureActivity.EXTRA_CODE_RESULT);
    if (codeResult != null && codeResult instanceof CaptureResult) {
      CaptureResult codeResultBlock = (CaptureResult) codeResult;
      Result rawResult = codeResultBlock.getRawResult(); // Raw scan data
      ParsedResult parsedResult = codeResultBlock.getParsedResult(); // Parsed data
    }
  }
}

Once you have the ParsedResult object, you can test for the subtype you are expecting (look at the classes in the com.google.zxing.client.result package that extend ParsedResult) and retrieve the data. Below is a URI code example.

public String getCodeURI(ParsedResult parsedResult) {
  if (parsedResult != null && parsedResult instanceof URIParsedResult) {
    return ((URIParsedResult) parsedResult).getURI();
  }
  return null;
}

Configuration

Default configuration will suffice for most users but the following advanced features can be provided:

Key Description Default Type
KEY_DECODE_1D_PRODUCT enable 1D product barcodes true boolean
KEY_DECODE_1D_INDUSTRIAL enable 1D industrial barcodes true boolean
KEY_DECODE_QR enable QR codes true boolean
KEY_DECODE_DATA_MATRIX enable decoding of data matrices true boolean
KEY_DECODE_AZTEC enable Aztec codes false boolean
KEY_DECODE_PDF417 enable decoding PDF417 codes false boolean
KEY_FRONT_LIGHT_MODE front light mode: ON, OFF or AUTO OFF FrontLightMode
KEY_AUTO_FOCUS enable auto-focus true boolean
KEY_INVERT_SCAN enable inversion of the scan false boolean
KEY_DISABLE_CONTINUOUS_FOCUS disable continuous focus true boolean
KEY_DISABLE_EXPOSURE disable exposure true boolean
KEY_DISABLE_METERING disable metering true boolean
KEY_DISABLE_BARCODE_SCENE_MODE disable barcode scene mode true boolean

To override defaults, you can set a custom properties provider.

CapturePreferences.setProvider(new Provider() {
  @Override
  public Object getValue(String key) {
    if (CapturePreferences.KEY_DECODE_QR.equals(key)) {
      return false;
    } else if (CapturePreferences.KEY_DECODE_AZTEC.equals(key)) {
      return true;
    }
    return null;
  }
});

This is a simplistic example, in the real world you can either plug in a hash map with your values or implement any other retrieval flow.

If your custom provider is not set or does not return a value for any key, configuration will fall back to the defaults. As a result, only values differing to the defaults should be supplied by the custom provider.