-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1384 from DataDog/xgouchet/poc/wearos
Create a minimal WearOS sample to test compatibility
- Loading branch information
Showing
17 changed files
with
338 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
24 changes: 24 additions & 0 deletions
24
sample/wear/src/main/java/com/datadog/android/wear/sample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
@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) | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
sample/wear/src/main/java/com/datadog/android/wear/sample/WearApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="hello_world">Hello Round World!</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters