# Android

## **Get the module**

To add the Driver Achievement UI module to your app, add the following lines to your dependencies in your application build.gradle file:

```gradle
dependencies {
    implementation 'com.drivequant.drivekit:drivekit-driver-achievement-ui:$drivekitui_version'
}
```

{% 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 also have a demo app and source code of Driver Achievement UI that you can use as an example.

## **Initialize**

If you have [disabled the SDK auto-initialization](https://docs.drivequant.com/get-started-drivekit/android/advanced-configurations#manually-initialize-the-sdk), the Driver Achievement UI module must also be manually initialized.

Then, to initialize the module in your app, you must call the initialization method in `onCreate` method of your Application class:

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

```kotlin
fun initialize()
```

{% endtab %}
{% endtabs %}

## **Override colors and texts**

To override colors and texts in the Driver Achievement UI SDK, see [Common UI configuration](https://docs.drivequant.com/common-ui/android/get-started).&#x20;

## **Select Streak themes**

You can choose which streak theme you want to display in which order, by calling the following method:

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

```kotlin
fun configureStreakThemes(streakThemes: List<StreakTheme>)
```

{% endtab %}
{% endtabs %}

Accepted values:

* `PHONE_DISTRACTION`
* `SAFETY`
* `ACCELERATION`
* `BRAKE`
* `ADHERENCE`
* `SPEEDING`
* `CALL`

Default value:

&#x20;`listOf(PHONE_DISTRACTION, SAFETY, ACCELERATION, BRAKE, ADHERENCE, CALL)`

{% hint style="danger" %}
For SPEEDING streaks, make sure that the service is activated on your DriveQuant account.
{% endhint %}

## Display streak list interface

To display the streak list UI, you can call the following methods:

### By creating a `Fragment`

{% code fullWidth="false" %}

```kotlin
val fragment = DriverAchievementUI.createStreakListFragment()
```

{% endcode %}

### By launching an `Activity`

```kotlin
DriverAchievementUI.startRankingActivity(context)
```

## **Select Badges categories**

You can choose which badge category you want to display in which order, by calling the following method:

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

```kotlin
fun configureBadgeCategories(badgeCategories: MutableList<BadgeCategory>)
```

{% endtab %}
{% endtabs %}

Accepted values:

* `GENERIC`
* `SAFETY`
* `ECO_DRIVING`
* `PHONE_DISTRACTION`

Default value:

`listOf(GENERIC, PHONE_DISTRACTION, SAFETY, ECO_DRIVING)`<br>

## Display Badge list interface

To show the badge UI you can use these following methods:

### By creating a `Fragment`

```kotlin
supportFragmentManager
    .beginTransaction()
    .replace(R.id.yourContainer, BadgesListFragment())
    .commit()
```

### By launching an `Activity`

```kotlin
val intent = Intent(context, BadgeListActivity::class.java)
context.startActivity(intent)
```

## **Select ranking themes**

By calling the following method, you can choose which rank type you want to display:

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

```kotlin
fun configureRankingTypes(rankingTypes: List<RankingType>)
```

{% endtab %}
{% endtabs %}

Accepted values:&#x20;

* `RankingType.SAFETY`
* `RankingType.ECO_DRIVING`
* `RankingType.DISTRACTION`
* `RankingType.SPEEDING`

Default values \[`RankingType.SAFETY`, `RankingType.ECO_DRIVING`, `RankingType.DISTRACTION`]

## **Set ranking selectors**

You can have many periods displayed on the ranking screen. This way, the user can see his ranking on many periods. The following method allows you to selected the order of the displayed periods:

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

```kotlin
fun configureRankingSelector(rankingSelector: RankingSelectorType)
```

{% endtab %}
{% endtabs %}

Accepted values :&#x20;

* `RankingPeriod.WEEKLY`,
* `RankingPeriod.MONTHLY`,
* `RankingPeriod.ALL_TIME`

Default value: \[`RankingPeriod.WEEKLY`, `RankingPeriod.MONTHLY`,  `RankingPeriod.ALL_TIME`]

If you don’t need any kind of selectors you can use the following code:

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

```kotlin
 val rankingSelectorType = RankingSelectorType.NONE
 DriverAchievementUI.configureRankingSelector(rankingSelectorType)
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
In this case, the period of the ranking is weekly
{% endhint %}

## **Configure ranking depth**

This method allows you to choose the ranking depth you want to display:

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

```kotlin
fun configureRankingDepth(rankingDepth: Int)
```

{% endtab %}

{% tab title="Java" %}

```
int rankingDepthValue = 20;
DriverAchievementUI.INSTANCE.configureRankingDepth(rankingDepthValue);
```

{% endtab %}
{% endtabs %}

Accepted values: from `5` to `20`

Default value: `5`

## Display Ranking interface

To display the ranking interface, you can call the following methods:

### By creating a `Fragment`

```kotlin
RankingFragment.newInstance()
```

### By launching an `Activity`

```kotlin
RankingActivity.launchActivity(context)
```
