# Get started

## Integration

The Common UI module is a core configuration module for all DriveKit UI modules.

To add Common UI module to your app, add the following line to your dependencies in your application build.gradle file:

{% tabs %}
{% tab title="build.gradle" %}

<pre class="language-gradle"><code class="lang-gradle">dependencies {
<strong>    implementation 'com.drivequant.drivekit:drivekit-common-ui:$drivekitui_version'
</strong>}
</code></pre>

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Replace `$drivekitui_version` with the DriveKit version you are using in your app
{% endhint %}

On a[ Github repository](https://github.com/DriveQuantPublic/drivekit-ui-android), you have a demo app and source code that you can use as an example.

## Initialization

If you have [disabled the SDK auto-initialization](https://docs.drivequant.com/get-started-drivekit/android/advanced-configurations#manually-initialize-the-sdk), an initialization phase is required to ensure that Common UI module works perfectly. To initialize Common UI module in your app, you must call the initialization method in `onCreate` method of your application class.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MyApplication: Application() {
    override fun onCreate() {
        super.onCreate()
        (…)
        DriveKitUI.initialize()
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MyApplication extends Application {
   @Override
   public void onCreate() {
       super.onCreate();
       (…)
       DriveKitUI.initialize();
}}

```

{% endtab %}
{% endtabs %}

This method will initialize the SDK with the default configuration set up by DriveQuant.&#x20;

## **Configurations**

### **Colors**

The colors that can be configured are listed in the table below:

<table data-header-hidden><thead><tr><th width="306.3333333333333">Name</th><th width="283">Description</th><th>Default value</th></tr></thead><tbody><tr><td>Name</td><td>Description</td><td>Default value</td></tr><tr><td><code>primaryColor</code></td><td>Main app color</td><td>#0B4D6E</td></tr><tr><td><code>secondaryColor</code></td><td>Call to action color</td><td>#77E2B0</td></tr><tr><td><code>mainFontColor</code></td><td>Main font color</td><td>#161616</td></tr><tr><td><code>complementaryFontColor</code></td><td>Secondary font color</td><td>#9E9E9E</td></tr><tr><td><code>fontColorOnPrimaryColor</code></td><td>Color of a text displayed on an element whose color is <code>primaryColor</code></td><td>#FFFFFF</td></tr><tr><td><code>fontColorOnSecondaryColor</code></td><td>Color of a text displayed on an element whose color is <code>secondaryColor</code></td><td>#FFFFFF</td></tr><tr><td><code>backgroundViewColor</code></td><td>Background color</td><td>#FAFAFA</td></tr><tr><td><code>neutralColor</code></td><td>Color of the separating lines</td><td>#F0F0F0</td></tr><tr><td><code>warningColor</code></td><td>Warning color (non-critical hint)</td><td>#F7A334</td></tr><tr><td><code>criticalColor</code></td><td>Alert color (critical hint)</td><td>#E52027</td></tr></tbody></table>

To override the default colors configuration, you just have to add the colors you want to change in the file `res/values/colors.xml` in your app:

```xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="primaryColor">#0B4D6E</color>
    <color name="secondaryColor">#77E2B0</color>
    <color name="mainFontColor">#161616</color>
    <color name="complementaryFontColor">#9E9E9E</color>
    <color name="fontColorOnPrimaryColor">@android:color/white</color>
    <color name="fontColorOnSecondaryColor">@android:color/white</color>
    <color name="backgroundViewColor">#FAFAFA</color>
    <color name="neutralColor">#F0F0F0</color>
    <color name="warningColor">#F7A334</color>
    <color name="criticalColor">#E52027</color>
</resources>
```

{% hint style="info" %}
The flavor "`colorsTest`" of the demo application is an example of colors customization.
{% endhint %}

### Fonts

The Common UI configuration module allows to set up two fonts:

1. `primaryFont`: this is the main font used in the application. The default value is Roboto.
2. `secondaryFont`: this font is used on the page titles or to emphasize a specific point. The default value is Roboto.

To override the primary font, define your font family in the file `res/font/dkprimary.xml` in your app:

```xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
    <font
        app:font="@font/sketchy"
        app:fontStyle="normal"
        app:fontWeight="400" /> <!-- Weight 400 = Normal (Regular) -->
    <font
        app:font="@font/deadknight"
        app:fontStyle="normal"
        app:fontWeight="700" /> <!-- Weight 700 = Bold -->
</font-family>

```

To override the secondary font, define your font family in the file `res/font/dksecondary.xml` in your app:

```xml
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto">
    <font app:font="@font/stocky" />
</font-family>

```

{% hint style="info" %}
The flavor "`fontsTest`" of the demo application customizes the fonts to test and see where the different fonts are used.
{% endhint %}

### Text Localization

Contents of each DriveKit UI module are translated into 7 languages: English, French, German, Spanish, Italian, Danish and Portuguese.

DriveKit simplifies the internationalization of your application and it is possible to add other languages.

DriveKit Common UI contains a number of basic text keys used in other DriveKit UI modules. You can override these keys to customize your application.

To help make the text keys in the code easier to read, a specific nomenclature has been set up: `dk_<module name>_<key description>`.

For the Common UI module, all localizable keys are prefixed with: `dk_common`.

There are several files containing text keys:

* A string.xml file in the common UI module containing generic keys to all modules.
* One file per UI module containing module-specific text keys.

### Text customization

You can override any texts to customize your application. To override a text key, simply define the keys to be modified in a string.xml file at the application level. The text keys can be directly retrieved on [Github](https://github.com/DriveQuantPublic/drivekit-ui-android), in the src/main/res/values folder of each module.

### **Add language**

The translation file can be retrieved from [GitHub ](https://github.com/DriveQuantPublic/drivekit-ui-android)in the various DriveKit UI modules and integrated into the values-\<Locale> folder of the app.

### **Get analytics**

You can retrieve some data and build analytics for any DriveKit UI component. To enable the feature, call the following method:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
DriveKitUI.configureAnalytics(object: DriveKitAnalyticsListener{
   override fun trackScreen(screen: String, className: String) {
       // TODO: manage screen tracking here
   }

   override fun trackEvent(event: DKAnalyticsEvent, parameters: Map<DKAnalyticsEventKey, String>) {
       // TODO: manage event tracking here
    }
})
```

{% endtab %}

{% tab title="Java" %}

```java
DriveKitUI.configureAnalytics(new DriveKitAnalyticsListener() {
   @Override
   public void trackScreen(@NotNull String screen, @NotNull String className) {
       // TODO: manage screen tracking here
   }

   @Override
   public void trackEvent(@NotNull DKAnalyticsEvent event, @NotNull Map<DKAnalyticsEventKey, String> parameters) {
       // TODO: manage event tracking here
   }
});

```

{% endtab %}
{% endtabs %}

`trackScreen()` method is called when a screen is displayed (i.e. trips list, trip detail, etc.).

When the method is called, you just have to call your analytics solution like Google Analytics for Firebase.\
The `screen` String received in the `trackScreen` method is the value associated with one of the keys [in this array](https://docs.drivequant.com/common-ui/references), corresponding to the visited screen.

In order to customize screens values, you have to override keys you can find in dk\_analytics.xml in each DriveKit UI component.

`trackEvent()` allows adding additional information that may be useful for analysis. For example, that method is triggered each time the user is opening the trip detail screen.
