Transflo Mobile Scanning Framework: Android

Minimum Android SDK version supported: API 14
Supported architectures: release, 32-bit architecture: armeabi, armeabi-v7a, x86 Interface: Public interface
External dependencies: Maven dependency management
Maven Repositories
compile 'com.android.support:appcompat-v7:23.1.1’
compile 'com.google.code.gson:gson:2.5'
compile 'com.squareup.picasso:picasso:2.5.2’
compile 'io.reactivex:rxandroid:1.1.0’
compile 'io.reactivex:rxjava:1.1.0’
compile 'me.dm7.barcodescanner:zbar:1.5’

The Confirmation Screen method of the framework is called to get more data about any prior document scanning session, indicated by the confirmation number provided as the input parameter.

PTCClient client: singleton object PTCClient.getInstance(), used across the app
<String> Confirmation number

<Intent> intent

private void showConfirmationViewer(String confirmationNumber) {
PTCConfirmationViewer.Builder builder = new PTCConfirmationViewer.Builder(); builder.setClient(PTCClient.getInstance());
try {
Intent intent = builder.build().getConfirmationViewerIntent(MainActivity.this, confirmationNumber); startActivity(intent);
} catch (NotInitializatedException e) { e.printStackTrace();
} catch (NotRegisteredException e) { e.printStackTrace();
}
}

The Confirmation Viewer URL method of the framework is called to get the URL of the confirmation viewer web page for a given confirmation number. The web page allows the user to browse all the information of the uploaded documents.
Input parameters
PTCClient client: singleton object PTCClient.getInstance(), used across the app
<String> Confirmation number
Results
<String> URL of the web page
Usage
This is the signature of the method:
private void showConfirmationViewer(String confirmationNumber) {
PTCConfirmationViewer.Builder builder = new PTCConfirmationViewer.Builder(); builder.setClient(PTCClient.getInstance());
try {
String url = builder.build().getConfirmationViewerURL(confirmationNumber);
Toast.makeText(MainActivity.this, url, Toast.LENGTH_LONG).show();
} catch (NotInitializatedException e) { e.printStackTrace();
} catch (NotRegisteredException e) {
e.printStackTrace();
} }

This optional method is called to obtain the registration fields for a specific fleet. This method can be called at any time. Calling this method does not predetermine the next step or steps.
The purpose of this method is to provide to the host app the necessary information about the registration fields of a fleet. This information might be useful to build a customized UI that allows the user to enter the values for the registration fields.

PTCClient client: singleton object PTCClient.getInstance(), used across the app
String recipientId
Implement interface PTCRecipientDefinitionListener

Success: onRecipientDefinition(PTCRecipientDefinition recipientDefinition) RecipientDefinition
String recipientId
String name
List<PTCFieldDefinitionModel> fields
PTCFieldDefinitionModel
String id
String datatype
String prompt
Boolean required o int minLength
int maxLength
Failure: onError(Throwable throwable)

private void getRecipientDefinition(String recipientId) {
PTCRegistration.Builder builder = new PTCRegistration.Builder();
builder.setClient(PTCClient.getInstance())
.addRecipientDefinitionListener(this);
try {
builder.build().getRecipientDefinition(recipientId);
} catch (NotInitializatedException e) { e.printStackTrace();
} catch (NullCallBackException e) { e.printStackTrace();
}
}
//Listener Implementation
@Override
public void onRecipientDefinition(PTCRecipientDefinition recipientDefinition) {
Gson gson = new Gson();
String json = gson.toJson(recipientDefinition);
showMessageDialog("Recipient Definition", json);
}
@Override
public void onError(Throwable throwable) {
showMessageDialog("Error", PTCErrorFabric.getThrowableErrorMessage(MainActivity.this, throwable));
}

The initialization method is called before proceeding to other API calls. The purpose of this call is to make sure all dependencies are in place and that the required environment checks also take place.
This method must be called in the onCreate() method of the application object of the host app (your app). Failure to call this method will result in the framework not working.

Context context: app context
String license key: string app ID or source app
Example: com.werner.mobileapp

PTCClient instance: singleton object initialized
In case of failure, a NotInitializedException exception is launched.

The first step is to initialize the framework using the following method:
//Get instance of PTCClient and execute the init process.
PTCClient.getInstance().init(this, "license_key", "com.pegasustranstech.transflodocscan.demo");

The Scan method of the library is called to capture and send documents to the Pegasus TransTech cloud. The purpose of this call is to start and complete the document sending steps. This is the primary method for the framework and is expected to get the most use.
This method includes processes for capturing a document as an image and accepting images that were already taken. Like the TRANSFLO® Mobile+ app, this method will also handle cropping, processing, compressing, and enhancing those images prior to sending them to the Pegasus TransTech cloud. The user also has the option to review and retake each document image.
After each image is scanned and before scanning the next image, the user receives a selection prompt for a doc type populated with the provided doc type description list. The user must select a doc type for the current image and before proceeding to the next image. This is how a driver provides the suggested document type, even though Pegasus TransTech may later override this doc type as part of their system processes.

PTCClient client: singleton object PTCClient.getInstance(), used across the app
String recipientId
List<PTCFieldModel> fields: index fields for the scanning process
PTCFieldModel
String id
String value
List<String> docTypes: required documents for the scanning process

onActivityResult(int requestCode, int resultCode, Intent data)
Success: PTCScanResult
String confirmationNumber
String confirmationViewer
long size
double duration
int numberOfImages
long timestamp
List<PTCImageData> imageData
PTCImageData
String uniqueId
String encoding
long size
double quality

private PTCScan scanComponent;
private void buildScanComponent() {
if (scanComponent == null) {
PTCScan.Builder builder = new PTCScan.Builder(); builder.setClient(PTCClient.getInstance()); builder.hideConfirmationViewer(false);
try {
scanComponent = builder.build();
} catch (Exception e) {
Log.e(TAG, "startScan: " + e.getMessage());
}
}
}
private void startScan(String recipientId) {
buildScanComponent();
try {
// fields example
List<PTCFieldModel> fields = new ArrayList<>();
PTCFieldModel field = new PTCFieldModel();
field.setId("loadnumber");
field.setValue("259878");
fields.add(field);
//doctype
List<String> doc = new ArrayList<>(); doc.add("POD");
doc.add("PAD");
Intent intentToScan = scanComponent.getScanIntent(MainActivity.this, recipientId, null, doc); startActivityForResult(intentToScan, REQUEST_CODE); } catch (InvalidRecipientException e) { e.printStackTrace();
} }
//Listener Implementation
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode != REQUEST_CODE)
return;
if (resultCode == Activity.RESULT_OK && data != null) {
// Get the result from the intent
PTCScanResult result = scanComponent.getScanResult(data);
if (result != null) {
getConfirmationNumber.setText(result.getConfirmationNumber());
Toast.makeText(MainActivity.this, "Documents scanned", Toast.LENGTH_LONG).show();
}
} else
Toast.makeText(MainActivity.this, "Scanning canceled", Toast.LENGTH_LONG).show();
}

This method is called to obtain the Email or User ID of the registered user. If there is no user registered, the method returns null.

None

<String>Registered user email

//Get registered user e-mail.
String userEmail = PTCClient.getInstance().getUserEmail();

The registration method is called before proceeding to other API calls. This method can be called at any time and does not predetermine the next step. The purpose of this call is to make sure all dependencies are in place and that the required environment checks also take place. Based upon the response returned, the caller or host app will know if subsequent calls to other APIs are expected to complete successfully.

PTCClient client: singleton object PTCClient.getInstance(), used across the app
PTCConfiguration config: object holding the configuration parameters
String email: email address of the user / Alternatively, Unique ID for the user
String firstName: First name of the user (optional)
String lastName: Last name of the user (optional)
String phone: Phone number of the user (optional)
List<PTCRecipient> recipients: registration information for each recipient.
PTCRecipient
String recipientId: id code for the recipient (unique in PTC cloud)
List<PTCFieldModel> Registration fields for the recipient
PTCFieldModel
String ID: ID for the field
String value: value for the field
Implement interface PTCRegistrationListener

Success: onRegistered()
Failure: onError(Throwable throwable)

private void doRegistration() {
PTCRegistration.Builder builder = new PTCRegistration.Builder();
builder.setClient(PTCClient.getInstance())
.addRegistrationListener(this)
.setConfig(buildPTCtionFromJSON());
try {
//Build the PTC registration component to do the registration process.
PTCRegistration registrationComponent = builder.build();
registrationComponent.register(); showProgressDialog("Registering...");
} catch (Exception e) {
Log.e(TAG, "doRegistration: " + e.getMessage());
} }
//Listener Implementation
@Override
public void onRegistered() {
hideDialog();
Toast.makeText(MainActivity.this, "Registered Succesfully!!" , Toast.LENGTH_LONG).show(); tvClientState.setText("Registered");
controlerContainer.setVisibility(View.VISIBLE);
}
@Override
public void onError(Throwable throwable) {
showMessageDialog("Error", PTCErrorFabric.getThrowableErrorMessage(MainActivity.this, throwable));
}