Tire Plugin


Examples Source Code

The source code of all examples can be found in the Android SDK Bundle

Plugin Description

The Anyline Tire plugin is capable of scanning Tire Identification Numbers (TIN), Tire Size Specifications, and Commercial Tire Identification Numbers.

How to implement the Tire Plugin

This is a step by step guide on how to implement the Tire Plugin in Android.

Get the Tire Plugin in Android

First add the Scan View to your xml-layout.

Add the ScanView to the layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:id="@+id/main_layout"
    android:animateLayoutChanges="true">


    <io.anyline.view.ScanView
        android:id="@+id/scan_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

In the next step, go to your Java Activity code and get the view from the layout in onCreate() or onActivityCreated()

Get the Scan View
        String lic = getString(R.string.anyline_license_key);

Initialize and Configure Anyline

ScanView

Initialize ScanView

The behaviour of the Tire plugin can be fine-tuned to scan Tire Identification Numbers (TIN), Tire Size Specifications, and Commercial Tire Identification Numbers. To configure each of those, their respective configs are utilized: TINConfig, TireSizeConfig, and CommercialTireIdConfig. You can check the DEMOS AND SAMPLE CODE page for the Tire Examples.

Initialize the ScanView
        //init the scanView with the JSON config file
        scanView.init("tire_config.json");

The Result Listener

After a successful scan, you will be provided results via a ResultListener. The listener is called ScanResultListener.

This section describes the ScanResultListener callback in detail.

The result is an instance of TireScanResult, which holds the detected text, the confidence of the result, a cutout image and the full image.

See TireScanResult in the Javadocs

onResult
        //add the scan result listener
        scanView.getScanViewPlugin().addScanResultListener(new ScanResultListener<TireScanResult>() {
            @Override
            public void onResult(TireScanResult result) {

                if (!result.toString().isEmpty()) {
                    Toast.makeText(getApplicationContext(), result.getResult(), Toast.LENGTH_LONG).show();
                }
            }
        });
  • result
Type Description
TireScanResult The scanned result and supplementary scan information
Parameter Type Description
getResult() String The scan result
getCutoutImage() AnylineImage An image of the scan, cropped to the cutout
getFullImage() AnylineImage The full image the result was found on
getConfidence() Integer The confidence of the SDK in the detected result

Tire Size Scanning

Tire Size Scanning provides the possibility to get detailed results by casting the returned ScanResult into TireSizeScanResult. TireSizeScanResult.getResult() then returns a TireScanDetailedResult, which contains multiple recognized Tire Size Parameters and their respective confidences. Refer to Tire Size Scanning Specifications for details.

Usage of TireScanResult and TireSizeScanResult
scanViewPlugin.addScanResultListener((ScanResultListener<TireScanResult>) result -> {

    // Cast to TireScanResult in order to get a simple result string
    TireScanResult tireScanResult = (TireScanResult) result;

    // simpleResult contains simply the result as a string
    String simpleResult = tireScanResult.getResult();


    // Cast to TireSizeScanResult in order to get detailed results
    TireSizeScanResult tireSizeScanResult = (TireSizeScanResult) result;

    // tireScanDetailedResult contains many more properties, e.g. a prettified result, prettified result with meta data, etc.
    TireScanDetailedResult tireScanDetailedResult = tireSizeScanResult.getResult();

    // Example: get prettified result with meta data
    String prettifiedResultWithMetaData = tireScanDetailedResult.getPrettifiedStringWithMeta().getText();

    // Example: get simple string result from TireScanDetailedResult
    String alsoSimpleResult = tireScanDetailedResult.getText().getText();

    // Example: get confidence for simple string result
    int simpleResultConfidence = tireScanDetailedResult.getText().getConfidence();

});

The parameters available via TireScanDetailedResult are listed as follows.

Parameters provided via TireScanDetailedResult, whereas each ResultField contains a text String and a confidence Integer Field. ? denote nullable (== optional) parameters.
data class TireScanDetailedResult(
        val text: ResultField,
        val prettifiedString: ResultField?,
        val prettifiedStringWithMeta: ResultField?,
        val vehicleType: ResultField?,
        val width: ResultField,
        val ratio: ResultField,
        val construction: ResultField,
        val diameter: ResultField,
        val commercialTire: ResultField?,
        val loadIndex: ResultField?,
        val speedRating: ResultField?,
        val extraLoad: ResultField?,
  val winter: ResultField?
)

data class ResultField(
        val text: String,
        val confidence: Int
)

TireScanDetailedResult also provides the possibility to return the parameters as JSON by calling TireScanDetailedResult.toJson(), with the following result.

Data structure of the JSON returned from TireScanDetailedResult.toJson()
{
        "text": {
                "text": String,
                "confidence": Int
        },
        "prettifiedString": {
                "text": String,
                "confidence": Int
        },
        "prettifiedStringWithMeta": {
                "text": String,
                "confidence": Int
        },
        "vehicleType": {
                "text": String,
                "confidence": Int
        },
        "width": {
                "text": String,
                "confidence": Int
        },
        "ratio": {
                "text": String,
                "confidence": Int
        },
        "construction": {
                "text": String,
                "confidence": Int
        },
        "diameter": {
                "text": String,
                "confidence": Int
        },
        "commercialTire": {
                "text": String,
                "confidence": Int
        },
        "loadIndex": {
                "text": String,
                "confidence": Int
        },
        "speedRating": {
                "text": String,
                "confidence": Int
        },
        "extraLoad": {
                "text": String,
                "confidence": Int
        },
        "winter": {
                "text": String,
                "confidence": Int
        }
}

Start Scanning

After everything is initialised, you can start the scanning process, by calling start() on the scanView. It is advised to place this call in the onResume() lifecycle method of Android. The``start()`` method on the scanView will internally call the start method from the scan plugin. The Scan Plugin is the most important in order to start the scanning process.

start
    @Override
    protected void onResume() {
        super.onResume();
        //start the scanning
        //internally scanView is calling the scanPlugin which is starting the scanning part
        scanView.start();
    }

Stop Scanning

To stop the scanning process, call stop() on the scanView.

To make sure the SDK is properly stopped upon leaving the Activity, make sure to place stop() and releaseCamera()/releaseCameraInBackground() in the onPause() lifecycle method of Android. The stop() method is referencing internally the stop method from the scan plugin. The Scan Plugin is the most important in order to stop the scanning process.

stop
    @Override
    protected void onPause() {
        super.onPause();

        scanView.stop();
        scanView.releaseCameraInBackground();
    }

Full Example Activity

Anyline Tire Identification Number Scan Mode Example
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import io.anyline.plugin.ScanResultListener;
import io.anyline.plugin.tire.TINConfig;
import io.anyline.plugin.tire.TireScanResult;
import io.anyline.plugin.tire.TireScanViewPlugin;
import io.anyline.view.BaseScanViewConfig;
import io.anyline.view.ScanView;
import io.anyline.view.ScanViewPluginConfig;
import io.anyline.AnylineSDK;

import at.nineyards.anyline.core.LicenseException;

public class ScanTINActivity extends AppCompatActivity {
    private static final String TAG = ScanTINActivity.class.getSimpleName();
    private ScanView scanView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.activity_scan_tire);

        String lic = getString(R.string.anyline_license_key);
        scanView = (ScanView) findViewById(R.id.scan_view);

        // This must be called before doing anything Anyline-related! 
        // Try/Catch this to check whether or not your license key is valid! 
        try {
            AnylineSDK.init(getString(lic), this);
        } catch (LicenseException e) {
            // handle exception
        }

        //init the scanView with the JSON config file
        scanView.init("tire_config.json");
        //add the scan result listener
        scanView.getScanViewPlugin().addScanResultListener(new ScanResultListener<TireScanResult>() {
            @Override
            public void onResult(TireScanResult result) {

                if (!result.toString().isEmpty()) {
                    Toast.makeText(getApplicationContext(), result.getResult(), Toast.LENGTH_LONG).show();
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        //start the scanning
        //internally scanView is calling the scanPlugin which is starting the scanning part
        scanView.start();
    }

    @Override
    protected void onPause() {
        super.onPause();

        scanView.stop();
        scanView.releaseCameraInBackground();
    }
}