VisTracks Library Integration Guide

Introduction

VisTracks provides a powerful and comprehensive solution for managing the movements and activities of mobile workers in general, and drivers subject to federal “hours of service” regulations in particular.

The full solution comprises a front-end app typically running on a tablet form-factor device, an administrative portal providing access to information about a fleet of vehicles, and a “back-end” cloud-resident platform that monitors and manages the real-time information transmitted from the tablets and other telematics devices.

This document focuses specifically on adding our front-end application to an existing application. This is provided by incorporating four android libraries into the application. An android library is a way of bundling code fragments into an easily accessible format.1

Prerequisites

Download VistracksApplicationIntegration.zip

How to Integrate Our Application

Step 1. In your project build.gradle file, add these dependencies

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    classpath 'com.google.gms:google-services:3.1.0'
    classpath 'me.tatarka:gradle-retrolambda:3.6.1'
    classpath 'com.google.firebase:firebase-plugins:1.1.0'
    // Your other dependencies here
}

Step 2. In your app module build.gradle file, add

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId [your application id]
        minSdkVersion [at least 19]
        targetSdkVersion [at least 25]
        versionCode 145
        // Have your other configuration code here
    }
}

Step 3. Add these values to your app module between your android {…} tag and dependencies {…} tag as follows. This ensures that the application is receiving the correct versions of it’s dependencies

android {[...]}
// ext.v to your code here
ext.v = [
    minSdkVersion      : 18,
    targetSdkVersion   : 25,
    compiledSdkVersion : 25,
    buildToolsVersion  : '26.0.0',
    commonsIoVersion     : '2.4',
    commonsLangVersion   : '3.4',
    daggerVersion        : '2.11',
    espressoVersion      : '2.2.2',
    eventBusVersion      : '3.0.0',
    gsonVersion          : '2.4',
    httpmimeVersion      : '4.2.2',
    jobDispatcherVersion : '0.7.0',
    jtsVersion           : '1.13',
    junitVersion         : '4.12',
    mockitoVersion       : '2.8.47',
    nordicsemiScannerVersion : '1.0.0',
    obdJavaApiVersion        : '1.0',
    okHttpVersion            : '3.8.1',
    playServicesVersion      : '11.0.2',
    roboElectricVersion      : '3.3.2',
    rulesVersion             : '0.5',
    runnerVersion            : '0.5',
    rxAndroidVersion         : '2.0.1',
    rxJavaVersion            : '2.1.1',
    squareOkHttpVersion      : '2.0.0',
    streamSupportVersion     : '1.5.5',
    supportLibraryVersion    : '25.3.1',
    flexBoxVersion           : '0.2.6'
]
dependencies{[...]}

Step 4. Add these dependencies in your application module

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile "com.squareup.okhttp:okhttp:${v.squareOkHttpVersion}"
    compile "no.nordicsemi.android.support.v18:scanner:${v.nordicsemiScannerVersion}"
    compile "io.reactivex.rxjava2:rxandroid:${v.rxAndroidVersion}"
    compile "io.reactivex.rxjava2:rxjava:${v.rxJava}"
    compile "net.sourceforge.streamsupport:streamsupport:${v.streamSupportVersion}"
    annotationProcessor "com.google.dagger:dagger-compiler:${v.daggerVersion}"
    compile "com.google.dagger:dagger:${v.daggerVersion}"
    provided 'javax.annotation:jsr250-api:1.0'
    compile "com.squareup.okhttp3:okhttp:${v.okHttpVersion}"
    compile "com.squareup.okhttp3:logging-interceptor:${v.okHttpVersion}"
    compile "org.greenrobot:eventbus:${v.eventBusVersion}"
    compile "com.android.support:appcompat-v7:${v.supportLibraryVersion}"
    compile "com.android.support:cardview-v7:${v.supportLibraryVersion}"
    compile "com.android.support:gridlayout-v7:${v.supportLibraryVersion}"
    compile "com.android.support:recyclerview-v7:${v.supportLibraryVersion}"
    compile "com.android.support:support-v4:${v.supportLibraryVersion}"
    compile "com.android.support:design:${v.supportLibraryVersion}"
    compile "com.google.android.gms:play-services-maps:${v.playServicesVersion}"
    compile "com.google.firebase:firebase-messaging:${v.playServicesVersion}"
    compile "com.google.firebase:firebase-core:${v.playServicesVersion}"
    compile "com.google.firebase:firebase-crash:${v.playServicesVersion}"
    compile "com.google.firebase:firebase-storage:${v.playServicesVersion}"
    compile "com.firebase:firebase-jobdispatcher:${v.jobDispatcherVersion}"
    compile "com.google.code.gson:gson:${v.gsonVersion}";
    compile "commons-io:commons-io:${v.commonsIoVersion}"
    compile "org.apache.httpcomponents:httpmime:${v.httpmimeVersion}"
    compile "org.apache.commons:commons-lang3:${v.commonsLangVersion}"
    compile "com.vividsolutions:jts:${v.jtsVersion}"
    compile "com.github.pires:obd-java-api:${v.obdJavaApiVersion}"
    compile "com.google.android:flexbox:${v.flexBoxVersion}"
    testCompile "junit:junit:${v.junitVersion}"
    testCompile "org.mockito:mockito-core:${v.mockitoVersion}"
    testCompile "com.squareup.okhttp3:mockwebserver:${v.okHttpVersion}"
    compile "com.google.firebase:firebase-core:${v.playServicesVersion}"
    // Used to provide an implementation of the android logger for now
    testCompile "org.robolectric:robolectric:${v.roboElectricVersion}"
    compile "org.greenrobot:eventbus:3.0.0"
    compile fileTree(include: '*.jar', dir: 'libs')
    compile 'joda-time:joda-time:2.9'
    compile 'com.vividsolutions:jts:1.13'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
}

Step 5. Import hoslib, pt-lib, wva-lib, and vtlib as new modules from an AAR.

Then add them as dependencies in your app module build.gradle

dependencies {
    // Previous dependencies here

    compile project(':hoslib')
    compile project(':pt-sdk-release')
    compile project(':vtlib-release')
    compile project(':wvalib-release')
}

Step 6. Have your application class extend VtApplication.

import com.vistracks.vtlib.app.VtApplication;

    public class TestApplication extends VtApplication {
    // Insert your application code here
}

Step 6.5 Add tools:replace=“android:name” in your application tag in your manifest

Step 7. Add this code snippet which adds AppTheme to your styles.xml (Typically found at [Root]/src/main/res/values/styles.xml). App theme must not extend *.NoActionBar or some activities will fail to launch.

<!-- Customized theme for branding -->
<style name="AppTheme" parent="AppBaseTheme">
    <item name="colorAccent">@color/default_colorAccent</item>
    <item name="colorLight">@color/grey50</item>
    <item name="dayNightAcceptRequest">@drawable/ic_accept_grey600_24dp</item>
    <item name="dayNightRejectRequest">@drawable/ic_reject_grey600_24dp</item>
    <item name="dayNightRequestDetailItemBackground">@color/colorSelected</item>
    <item name="dayNightTextColorPrimary">@color/listRowtextColorPrimary</item>
    <item name="dayNightTextColorSecondary">#61000000</item>
    <item name="dayNightErrorTextColor">@color/Red</item>

    <!-- Default font style sizes -->
    <item name="font_small">@dimen/appbase_text_size_small_material</item>
    <item name="font_medium">@dimen/appbase_text_size_medium_material</item>
    <item name="font_large">@dimen/appbase_text_size_large_material</item>
    <item name="font_xlarge">@dimen/appbase_text_size_headline_material</item>
    <item name="font_display3">@dimen/appbase_text_size_display_1_material</item>
</style>

Step 8. If you are using an app theme, or want to integrate your theme with our’s or want to customize the default theme, have that theme extend AppTheme.

Step 9. Add this code snippet on your AndroidManifest.xml to replace the launcher activity of HOS app.

<!-- Replace launcher from library -->
<activity android:name="com.vistracks.vtlib.authentication.StartMainActivity" tools:node="replace" />

Step 10. Make sure to add this DeveloperAPI.setHosAsLibrary(true) on your application to prevent exiting appliction when logging out from HOS screen.

Step 11. Use the DeveloperAPI.getVtApplication(Context c) to get the context for our application. Start it from an activity to launch our application.

 

Activity Classes

Job Sites JobSiteListActivity.class Intent i = new Intent(context, JobSiteListActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Work Orders WorkOrderListActivity.class Intent i = new Intent(context, WorkOrderListActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Roadside Inspection RoadsideInspectionStartActivity.class Intent i = new Intent(context, RoadsideInspectionStartActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Documents DriverDocumentListActivity.class Intent i = new Intent(context, DriverDocumentListActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Fuel Receipts DriverDocumentListActivity.class Intent i = new Intent(context, DriverDocumentListActivity.class);
i.putExtra(DriverDocumentListFragment.ARG_IS_FUEL_RECEIPT, true);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Settings AppPreferencesActivity.class Intent i = new Intent(context, AppPreferencesActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Help & Support UserHelpActivity.class Intent i = new Intent(context, UserHelpActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);