Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a minimal WearOS sample to test compatibility #1384

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions sample/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ android {
unitTests.isReturnDefaultValues = true
}

flavorDimensions += listOf("version")
flavorDimensions += listOf("site")
productFlavors {
val regions = arrayOf("us1", "us3", "us5", "us1_fed", "eu1", "ap1", "staging")

regions.forEachIndexed { index, region ->
register(region) {
isDefault = index == 0
dimension = "version"
dimension = "site"
configureFlavorForSampleApp(this, project.rootDir)
}
}
Expand Down Expand Up @@ -111,16 +111,16 @@ android {

dependencies {

api(project(":dd-sdk-android"))
api(project(":dd-sdk-android-ktx"))
api(project(":dd-sdk-android-ndk"))
api(project(":dd-sdk-android-rx"))
api(project(":dd-sdk-android-timber"))
api(project(":dd-sdk-android-coil"))
api(project(":dd-sdk-android-glide"))
api(project(":dd-sdk-android-fresco"))
api(project(":dd-sdk-android-sqldelight"))
api(project(":dd-sdk-android-compose"))
implementation(project(":dd-sdk-android"))
implementation(project(":dd-sdk-android-ktx"))
implementation(project(":dd-sdk-android-ndk"))
implementation(project(":dd-sdk-android-rx"))
implementation(project(":dd-sdk-android-timber"))
implementation(project(":dd-sdk-android-coil"))
implementation(project(":dd-sdk-android-glide"))
implementation(project(":dd-sdk-android-fresco"))
implementation(project(":dd-sdk-android-sqldelight"))
implementation(project(":dd-sdk-android-compose"))

implementation(libs.kotlin)

Expand Down
1 change: 1 addition & 0 deletions sample/wear/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
64 changes: 64 additions & 0 deletions sample/wear/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

import com.datadog.gradle.config.AndroidConfig
import com.datadog.gradle.config.configureFlavorForSampleApp

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
}

android {
compileSdk = AndroidConfig.TARGET_SDK
buildToolsVersion = AndroidConfig.BUILD_TOOLS_VERSION

defaultConfig {
applicationId = "com.datadog.android.wear.sample"
minSdk = AndroidConfig.MIN_SDK_FOR_COMPOSE
targetSdk = AndroidConfig.TARGET_SDK
versionCode = AndroidConfig.VERSION.code
versionName = AndroidConfig.VERSION.name
}

namespace = "com.datadog.android.wear.sample"

flavorDimensions += listOf("site")
productFlavors {
val regions = arrayOf("us1", "us3", "us5", "us1_fed", "eu1", "ap1", "staging")

regions.forEachIndexed { index, region ->
register(region) {
isDefault = index == 0
dimension = "site"
configureFlavorForSampleApp(this, project.rootDir)
}
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
buildFeatures {
viewBinding = true
}
}

dependencies {

implementation(project(":dd-sdk-android"))
implementation("androidx.core:core-ktx:1.7.0")
implementation("com.google.android.gms:play-services-wearable:17.1.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.recyclerview:recyclerview:1.3.0")
implementation("androidx.wear:wear:1.2.0")
}
21 changes: 21 additions & 0 deletions sample/wear/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
xgouchet marked this conversation as resolved.
Show resolved Hide resolved
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
46 changes: 46 additions & 0 deletions sample/wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
~ This product includes software developed at Datadog (https://www.datadoghq.com/).
~ Copyright 2016-Present Datadog, Inc.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />

<uses-feature android:name="android.hardware.type.watch" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault"
android:name=".WearApplication">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />

<!--
Set to true if your app is Standalone, that is, it does not require the handheld
app to run.
-->
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />

<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.wear.sample

import android.app.Activity
import android.os.Bundle
import com.datadog.android.wear.sample.databinding.ActivityMainBinding
xgouchet marked this conversation as resolved.
Show resolved Hide resolved

@Suppress("UndocumentedPublicProperty", "UndocumentedPublicClass")
class MainActivity : Activity() {

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.android.wear.sample

import android.app.Application
import android.util.Log
import com.datadog.android.Datadog
import com.datadog.android.DatadogSite
import com.datadog.android.core.configuration.Configuration
import com.datadog.android.core.configuration.Credentials
import com.datadog.android.privacy.TrackingConsent
import com.datadog.android.rum.GlobalRum
import com.datadog.android.rum.RumMonitor
import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
import com.datadog.android.tracing.AndroidTracer
import io.opentracing.util.GlobalTracer

/**
* The main [Application] for the sample WearOs project.
*/
class WearApplication : Application() {

override fun onCreate() {
super.onCreate()
initializeDatadog()
}

private fun initializeDatadog() {
Datadog.initialize(
this,
createDatadogCredentials(),
createDatadogConfiguration(),
TrackingConsent.GRANTED
)
Datadog.setVerbosity(Log.VERBOSE)
Datadog.enableRumDebugging(true)
Datadog.setUserInfo(
"wear 42",
null,
null
)

GlobalTracer.registerIfAbsent(
AndroidTracer.Builder()
.setServiceName(BuildConfig.APPLICATION_ID)
.build()
)
GlobalRum.registerIfAbsent(RumMonitor.Builder().build())
}

private fun createDatadogCredentials(): Credentials {
return Credentials(
clientToken = BuildConfig.DD_CLIENT_TOKEN,
envName = BuildConfig.BUILD_TYPE,
variant = BuildConfig.FLAVOR,
rumApplicationId = BuildConfig.DD_RUM_APPLICATION_ID
)
}

@Suppress("MagicNumber")
private fun createDatadogConfiguration(): Configuration {
val configBuilder = Configuration.Builder(
logsEnabled = true,
tracesEnabled = true,
crashReportsEnabled = true,
rumEnabled = true
)
.sampleTelemetry(100f)
.useViewTrackingStrategy(ActivityViewTrackingStrategy(true))
.trackInteractions()
.trackLongTasks(250L)

try {
configBuilder.useSite(DatadogSite.valueOf(BuildConfig.DD_SITE_NAME))
} catch (e: IllegalArgumentException) {
Log.e("WearApplication", "Error setting site to ${BuildConfig.DD_SITE_NAME}")
}

if (BuildConfig.DD_OVERRIDE_LOGS_URL.isNotBlank()) {
configBuilder.useCustomLogsEndpoint(BuildConfig.DD_OVERRIDE_LOGS_URL)
configBuilder.useCustomCrashReportsEndpoint(BuildConfig.DD_OVERRIDE_LOGS_URL)
}
if (BuildConfig.DD_OVERRIDE_TRACES_URL.isNotBlank()) {
configBuilder.useCustomTracesEndpoint(BuildConfig.DD_OVERRIDE_TRACES_URL)
}
if (BuildConfig.DD_OVERRIDE_RUM_URL.isNotBlank()) {
configBuilder.useCustomRumEndpoint(BuildConfig.DD_OVERRIDE_RUM_URL)
}

return configBuilder.build()
}
}
41 changes: 41 additions & 0 deletions sample/wear/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
~ This product includes software developed at Datadog (https://www.datadoghq.com/).
~ Copyright 2016-Present Datadog, Inc.
-->

<androidx.wear.widget.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".MainActivity"
tools:deviceIds="wear">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/inner_frame_layout_padding"
app:layout_boxedEdges="all">

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="8dp"
android:text="@string/hello_world" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@android:string/ok"
android:padding="8dp"
/>

</LinearLayout>
</androidx.wear.widget.BoxInsetLayout>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions sample/wear/src/main/res/values-round/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="hello_world">Hello Round World!</string>
</resources>
15 changes: 15 additions & 0 deletions sample/wear/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Because the window insets on round devices are larger than 15dp, this padding only applies
to square screens.
-->
<dimen name="box_inset_layout_padding">0dp</dimen>

<!--
This padding applies to both square and round screens. The total padding between the buttons
and the window insets is box_inset_layout_padding (above variable) on square screens and
inner_frame_layout_padding (below variable) on round screens.
-->
<dimen name="inner_frame_layout_padding">5dp</dimen>
</resources>
14 changes: 14 additions & 0 deletions sample/wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
~ Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
~ This product includes software developed at Datadog (https://www.datadoghq.com/).
~ Copyright 2016-Present Datadog, Inc.
-->

<resources>
<string name="app_name">Wear</string>
<!--
This string is used for square devices and overridden by hello_world in
values-round/strings.xml for round devices.
-->
<string name="hello_world">Hello Square World!</string>
</resources>
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(":instrumented:nightly-tests")
include(":library:dd-sdk-android-session-replay")

include(":sample:kotlin")
include(":sample:wear")

include(":tools:detekt")
include(":tools:unit")
Expand Down