Skip to content

Commit cc8a4e9

Browse files
authored
[MOBILE-4503] Add a Jetpack Glance widget to the sample app (#1450)
* minor sample tidying, fix warning in DeviceTagSelector * Add glance widget to sample app * Launch app on widget tap * spots
1 parent 81e0ce3 commit cc8a4e9

File tree

10 files changed

+388
-39
lines changed

10 files changed

+388
-39
lines changed

gradle/libs.versions.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ktlint = '1.1.1'
1515
# Kotlin
1616
kotlin = '1.9.21'
1717
kotlinx-coroutines = '1.7.3'
18+
kotlinx-serialization = '1.6.3' # Only used in Sample app
1819

1920
# Compose
2021
compose-bom = '2024.02.02'
@@ -34,6 +35,9 @@ androidx-fragment = '1.6.2'
3435
androidx-lifecycle = '2.7.0'
3536
androidx-navigation = '2.7.7'
3637

38+
# Using the RC to test the new features from I/O 2024 (Scaffold, TitleBar, LazyColumn, etc.)
39+
androidx-glance = '1.1.0-rc01' # Only used in Sample app
40+
3741
androidx-activity-compose = '1.8.2'
3842

3943
androidx-paging = '2.1.2'
@@ -92,6 +96,7 @@ dokka = '1.9.20'
9296
android-application = { id = 'com.android.application', version.ref = "androidGradlePlugin" }
9397
android-library = { id = 'com.android.library', version.ref = "androidGradlePlugin" }
9498
kotlin-allopen = { id = 'org.jetbrains.kotlin.plugin.allopen', version.ref = "kotlin" }
99+
kotlinx-serialization = { id = 'org.jetbrains.kotlin.plugin.serialization', version.ref = "kotlin" }
95100
google-services = { id = 'com.google.gms.google-services', version.ref = "googleServicesPlugin" }
96101
spotless = { id = 'com.diffplug.spotless', version.ref = "spotlessPlugin" }
97102
benmanes-versions = { id = 'com.github.ben-manes.versions', version.ref = "gradle-versions" }
@@ -103,6 +108,7 @@ kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "
103108
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines"}
104109
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines"}
105110
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines"}
111+
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" }
106112

107113
# Compose
108114
compose-bom = { module = "androidx.compose:compose-bom", version.ref = "compose-bom" }
@@ -116,6 +122,11 @@ compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview"
116122
compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
117123
compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4" }
118124
compose-material3 = { module = "androidx.compose.material3:material3" }
125+
compose-material = { module = "androidx.compose.material:material" }
126+
127+
# Glance
128+
glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "androidx-glance" }
129+
glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "androidx-glance" }
119130

120131
# Androidx
121132
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }

sample/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'com.android.application'
33
id 'kotlin-android'
44
id 'kotlin-kapt'
5+
alias(libs.plugins.kotlinx.serialization)
56
}
67

78
android {
@@ -22,6 +23,11 @@ android {
2223
buildFeatures {
2324
dataBinding = true
2425
buildConfig = true
26+
compose = true
27+
}
28+
29+
composeOptions {
30+
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
2531
}
2632

2733
buildTypes {
@@ -47,6 +53,12 @@ android {
4753
}
4854

4955
dependencies {
56+
// Kotlin
57+
implementation(libs.kotlinx.coroutines.android)
58+
implementation(libs.kotlinx.coroutines.core)
59+
implementation(libs.kotlinx.serialization.json)
60+
61+
// Jetpack
5062
implementation(libs.androidx.appcompat)
5163
implementation(libs.google.material)
5264
implementation(libs.androidx.preference)
@@ -58,6 +70,9 @@ dependencies {
5870
implementation(libs.playservices.instantapps)
5971
implementation(libs.playservices.location)
6072

73+
// Jetpack Glance
74+
implementation(libs.glance.appwidget)
75+
6176
// Airship ADM
6277
implementation project(':urbanairship-adm')
6378

sample/src/main/AndroidManifest.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<dist:module dist:instant="true" />
66

77
<!-- Optional: Needed if using location in Airship. -->
8-
<!-- Use "android.permission.ACCESS_COARSE_LOCATION" instead if GPS access is not necessary -->
8+
<!-- Use only "android.permission.ACCESS_COARSE_LOCATION" if GPS access is not necessary -->
99
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
10+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1011

1112
<application
1213
android:name="com.urbanairship.sample.SampleApplication"
@@ -44,6 +45,16 @@
4445
</intent-filter>
4546
</activity>
4647

48+
<receiver android:name=".glance.SampleAppWidgetReceiver"
49+
android:exported="true">
50+
<intent-filter>
51+
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
52+
</intent-filter>
53+
<meta-data
54+
android:name="android.appwidget.provider"
55+
android:resource="@xml/sample_widget_info" />
56+
</receiver>
57+
4758
</application>
4859

4960
</manifest>

sample/src/main/java/com/urbanairship/sample/CustomLiveUpdate.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

sample/src/main/java/com/urbanairship/sample/SampleAutopilot.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.urbanairship.UAirship;
1313
import com.urbanairship.liveupdate.LiveUpdateManager;
1414
import com.urbanairship.messagecenter.MessageCenter;
15+
import com.urbanairship.sample.glance.SampleAppWidgetLiveUpdate;
1516

1617
import androidx.annotation.NonNull;
1718
import androidx.annotation.Nullable;
@@ -55,6 +56,7 @@ public void onAirshipReady(@NonNull UAirship airship) {
5556
// Register handlers for Live Updates.
5657
LiveUpdateManager.shared().register("sports", new SampleLiveUpdate());
5758
LiveUpdateManager.shared().register("sports-async", new SampleAsyncLiveUpdate());
59+
LiveUpdateManager.shared().register("medals-widget", new SampleAppWidgetLiveUpdate());
5860

5961
MessageCenter.shared().setOnShowMessageCenterListener(messageId -> {
6062
// Use an implicit navigation deep link for now as explicit deep links are broken

0 commit comments

Comments
 (0)