Plugin Configuration

A Plugin is a component of the Anyline SDK that implements a scanning use case. We support a wide variety of scanning possibilities covering use cases such as ID, License Plate, Barcode, Meter and so on, to name a few examples.

It is possible to configure the scanning behavior either through code or JSON. We’ll cover both in this section.

The Configuration object and JSON

A config determines how a ScanPlugin, ScanViewPlugin, or ScanView appears or operates. Each of these takes a config object, or a JSON dictionary representation thereof, as a parameter in its initializer.

Some configs, such as ScanViewConfig, can also have children config objects.

To give an example, ScanPluginConfig is an class that looks like the following (this is simplified):

val scanPluginConfig: ScanPluginConfig

It holds an PluginConfig which contains the aggregate representations of all supported use cases.

To construct an Anyline config object it is often more convenient to prepare a JSON Object that holds the config for your use case, and then create the Anyline plugin components with initializer methods that take this object:

// either hardcoded, or taken from a file included in the app bundle
 val jsonString = "{\"pluginConfig\":...}"

// convert to a json object
val jsonObject = JSONObject(jsonString)

Alternative methods to initialize these components are also available, for when you want additional run-time control over the configuration, or if you want to forego error handling. However, provided that you structure your config JSON correctly, the above example remains the simplest way to set up your Anyline scan components.

Configs

ScanPluginConfig

A ScanPluginConfig determines, among other things, the scanning use case and essential characteristics of the plugin’s scan behavior. Its key use is to help initialize the ScanPlugin, which takes it as a parameter to its constructor.

Inside it, it holds an PluginConfig object which offer further customization possibilities for specific uses cases.

It is perhaps easier to see this config object through its JSON representation. Here we give an example based on a meter plugin config:

"pluginConfig": {
    "meterConfig": {
        "scanMode": "auto_analog_digital_meter",
        "id": "METER",
        "cancelOnResult": true
    },
}

A short note: the ScanPluginConfig consists of a PluginConfig property named meterConfig, which further specifies within it that it is going to be run with the auto_analog_digital_meter scan mode.

ScanViewPluginConfig

A ScanViewPluginConfig basically combines in it a ScanPluginConfig, a CutoutConfig, and a ScanFeedbackConfig.

  • The ScanPluginConfig is the same as the one discussed in the previous section.

  • A CutoutConfig includes details about the camera cutout to be shown on the scan view including where and how large the region of interest lies within the scan view.

  • A ScanFeedbackConfig holds properties to help you configure how the objects of interest within the scan frame are visually treated, and what happens when a scan result is found.

An example for meter is shown below:

"viewPluginConfig": {
    "pluginConfig": {
        "id": "METER",
        "meterConfig": {
            "scanMode": "auto_analog_digital_meter"
        },
        "cancelOnResult": true
    },
    "cutoutConfig": {
        "maxWidthPercent": "75%",
        "maxHeightPercent": "90%",
        "ratioFromSize": { "width": 7, "height": 3 },
        "cornerRadius": 8,
        "strokeColor": "#8be9fd",
        "strokeWidth": 3
    },
    "scanFeedbackConfig": {
        "style": "rect",
        "strokeWidth": 2,
        "strokeColor": "#0099FF",
        "fillColor": "#220099FF",
        "beepOnResult": true,
        "vibrateOnResult": true,
        "blinkAnimationOnResult": true
    }
}

To create a Scan Plugin Config, prepare a JSON Object just as you would with the ScanPluginConfig and then pass it as a parameter to its initializer:

val scanViewPluginConfig = ScanViewPluginConfig(jsonObject)
val scanViewPlugin = ScanViewPlugin(context, scanViewPluginConfig)

CameraConfig and FlashConfig

The FlashConfig allows you to configure the torch module, which includes the visibility and location of the flash toggle button within the scan view.

The CameraConfig defines a few properties determining the camera module used. At the moment, the main property is zoomGesture, which, when true, allows pinch-to-zoom behavior for the running scan view.

For the time being, only "1080" is supported for the Camera Config property captureResolution.

Best Practices

Use a single JSON file per use case

In most scenarios, you should find it most convenient to keep a single JSON file holding together the configs for your scaning use case, with all component configs listed together, in your application bundle.

An example is shown in this JSON sample config (sample_id_config.json):

sample_id_config.json
{
  "cameraConfig": {
    "captureResolution": "1080p"
  },
  "flashConfig": {
    "mode": "manual",
    "alignment": "top_right",
    "offset": { "x": 0, "y": 0 }
  },
  "viewPluginConfig": {
    "pluginConfig": {
      "id": "com.anyline.configs.plugin.id_mrz_dl",
      "universalIdConfig": {
        "allowedLayouts": {
          "mrz": [],
          "drivingLicense": [],
          "idFront": []
        },
        "alphabet": "latin",
        "drivingLicense": {
          "surname": {"scanOption": 0, "minConfidence": 40},
          "givenNames": {"scanOption": 0, "minConfidence": 40},
          "dateOfBirth": {"scanOption": 0, "minConfidence": 50},
          "placeOfBirth": {"scanOption": 1, "minConfidence": 50},
          "dateOfIssue": {"scanOption": 0, "minConfidence": 50},
          "dateOfExpiry": {"scanOption": 1, "minConfidence": 50},
          "authority": {"scanOption": 1, "minConfidence": 30},
          "documentNumber": {"scanOption": 0, "minConfidence": 40},
          "categories": {"scanOption": 1, "minConfidence": 30},
          "address": {"scanOption": 1}
        },
        "idFront": {
          "surname": {"scanOption": 0, "minConfidence": 60},
          "givenNames": {"scanOption": 0, "minConfidence": 60},
          "dateOfBirth": {"scanOption": 0, "minConfidence": 60},
          "placeOfBirth": {"scanOption": 1, "minConfidence": 60},
          "dateOfExpiry": {"scanOption": 1, "minConfidence": 60},
          "cardAccessNumber": {"scanOption": 1, "minConfidence": 60},
          "documentNumber": {"scanOption": 0, "minConfidence": 60},
          "nationality": {"scanOption": 1, "minConfidence": 60}
        }
      },
      "cancelOnResult": true
    },
    "cutoutConfig": {
      "animation": "fade",
      "maxWidthPercent": "90%",
      "maxHeightPercent": "90%",
      "width": 0,
      "alignment": "center",
      "ratioFromSize": { "width": 86, "height": 54 },
      "offset": { "x": 0, "y": 60 },
      "cropOffset": { "x": 0, "y": 0 },
      "cropPadding": { "x": 0, "y": 0 },
      "cornerRadius": 8,
      "strokeColor": "#8BE9FD",
      "strokeWidth": 2,
      "feedbackStrokeColor": "#0099FF",
      "outerColor": "#000000",
      "outerAlpha": 0.3
    },
    "scanFeedbackConfig": {
      "style": "animated_rect",
      "strokeWidth": 0,
      "strokeColor": "#8be9fd",
      "fillColor": "#908be9fd",
      "cornerRadius": 2,
      "beepOnResult": true,
      "vibrateOnResult": false,
      "blinkAnimationOnResult": false
    }
  }
}

Changing the config in real time

Your work flow may require you to update the scan config without leaving the view controller. To take an example, for instance, you may have a UI switch over the scan view to toggle the cutout width-height ratio (eg 3:1, 2:1, and so on), and it was tapped by the user.

In such a case, it is important to remember that once a component has been created, it can no longer be modified. The only option that remains is to recreate the components: the ScanView, ScanViewPlugin, and ScanPlugin with an updated configuration, and reinstall the scan view into the view hierarchy.


Questions or need further assistance? Please reach out to the Anyline Support Helpdesk.