Skip to content
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
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ plugins {

android {
namespace = "com.example.platform"
compileSdk = 35
compileSdk = 36

defaultConfig {
applicationId = "com.example.platform"
minSdk = 21
targetSdk = 35
targetSdk = 36
versionCode = 1
versionName = "1.0"

Expand Down Expand Up @@ -92,6 +92,7 @@ dependencies {
implementation(project(":samples:user-interface:constraintlayout"))
implementation(project(":samples:user-interface:draganddrop"))
implementation(project(":samples:user-interface:haptics"))
implementation(project(":samples:user-interface:live-updates"))
implementation(project(":samples:user-interface:picture-in-picture"))
implementation(project(":samples:user-interface:predictiveback"))
implementation(project(":samples:user-interface:quicksettings"))
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/example/platform/app/ApiSurface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ val UserInterfaceHapticsApiSurface = ApiSurface(
null,
)

val UserInterfaceLiveUpdatesApiSurface = ApiSurface(
"live-updates",
"User Interface - Live Updates",
null,
)

val UserInterfacePictureInPictureApiSurface = ApiSurface(
"user-interface-picture-in-picture",
"User Interface - Picture In Picture",
Expand Down Expand Up @@ -204,6 +210,7 @@ val API_SURFACES = listOf(
UserInterfaceConstraintLayoutApiSurface,
UserInterfaceDragAndDropApiSurface,
UserInterfaceHapticsApiSurface,
UserInterfaceLiveUpdatesApiSurface,
UserInterfacePictureInPictureApiSurface,
UserInterfacePredictiveBackApiSurface,
UserInterfaceQuickSettingsApiSurface,
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/example/platform/app/SampleDemo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import com.example.platform.ui.haptics.Resist
import com.example.platform.ui.haptics.Wobble
import com.example.platform.ui.insets.ImmersiveMode
import com.example.platform.ui.insets.WindowInsetsAnimationActivity
import com.example.platform.ui.live_updates.LiveUpdateSample
import com.example.platform.ui.predictiveback.PBHostingActivity
import com.example.platform.ui.quicksettings.QuickSettings
import com.example.platform.ui.share.receiver.ShareReceiverActivity
Expand Down Expand Up @@ -993,6 +994,20 @@ val SAMPLE_DEMOS by lazy {
tags = listOf("Haptics"),
content = { Wobble() }
),
ComposableSampleDemo(
id = "live-updates",
name = "Live Updates - ProgressStyle implementation",
description = "Usage of ProgressStyle with Live update treatment",
documentation = "https://developer.android.com/about/versions/16/features/progress-centric-notifications",
minSdk = Build.VERSION_CODES.BAKLAVA,
apiSurface = UserInterfaceLiveUpdatesApiSurface,
content = {
MinSdkBox(minSdk = Build.VERSION_CODES.BAKLAVA) {
//noinspection NewApi
LiveUpdateSample()
}
},
),
ActivitySampleDemo(
id = "picture-in-picture-video-playback",
name = "Picture in Picture (PiP) - Video playback",
Expand Down
5 changes: 4 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#
[versions]
agp = "8.8.1"
agp = "8.9.1"
fragmentCompose = "1.8.6"
kotlin = "2.1.10"
coreKtx = "1.15.0"
Expand Down Expand Up @@ -51,6 +51,7 @@ androidxTestExtTruth = "1.5.0"
androidxTestRules = "1.5.0"
androidxTestRunner = "1.5.2"
androidxUiAutomator = "2.2.0"
material3Android = "1.3.2"
media3 = "1.5.0"
constraintlayout = "2.1.4"
glide-compose = "1.0.0-beta01"
Expand Down Expand Up @@ -162,6 +163,7 @@ androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4"
androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "androidx-datastore" }
androidx-draganddrop = "androidx.draganddrop:draganddrop:1.0.0"
androidx-dynamicanimation = "androidx.dynamicanimation:dynamicanimation-ktx:1.0.0-alpha03"
androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" }
androidx-media3-common = { module = "androidx.media3:media3-common", version.ref = "media3" }
androidx-media3-effect = { module = "androidx.media3:media3-effect", version.ref = "media3" }
androidx-media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3" }
Expand All @@ -185,6 +187,7 @@ android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
android-library = { id = "com.android.library", version.ref = "agp" }
compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

affectedmoduledetector = { id = "com.dropbox.affectedmoduledetector", version = "0.2.0" }
versionCatalogUpdate = { id = "nl.littlerobots.version-catalog-update", version = "0.7.0" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Fri Feb 14 20:10:12 KST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
32 changes: 32 additions & 0 deletions samples/user-interface/live-updates/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.compose)
}

android {
namespace = "com.example.platform.ui.live_updates"
compileSdk = 36

defaultConfig {
minSdk = 21
targetSdk = 36
}
kotlinOptions {
jvmTarget = "1.8"
}

buildFeatures {
viewBinding = true
}
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.activity.compose)
implementation(libs.material)
implementation(libs.accompanist.permissions)
implementation(libs.androidx.constraintlayout)
implementation(libs.androidx.material3.android)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2025 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ https://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

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

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

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.platform.ui.live_updates
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs license header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


import android.annotation.SuppressLint
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
import com.google.accompanist.permissions.shouldShowRationale
import kotlinx.coroutines.launch

@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun LiveUpdateSample() {
val notificationManager =
LocalContext.current.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
SnackbarNotificationManager.initialize(LocalContext.current.applicationContext, notificationManager)
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
Scaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
},
) { contentPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(contentPadding),
) {
Text(stringResource( R.string.live_update_summary_text))
Spacer(modifier = Modifier.height(4.dp))
NotificationPermission()
Button(onClick = {
onCheckout()
scope.launch {
snackbarHostState.showSnackbar("Order placed")
}
}) {
Text("Checkout")
}
}
}
}

fun onCheckout() {
SnackbarNotificationManager.start()
}

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun NotificationPermission() {
@SuppressLint("InlinedApi") // Granted at install time on API <33.
val notificationPermissionState = rememberPermissionState(
android.Manifest.permission.POST_NOTIFICATIONS,
)
if (!notificationPermissionState.status.isGranted) {
NotificationPermissionCard(
shouldShowRationale = notificationPermissionState.status.shouldShowRationale,
onGrantClick = {
notificationPermissionState.launchPermissionRequest()
},
modifier = Modifier
.fillMaxWidth()
)
}
}

@Composable
private fun NotificationPermissionCard(
shouldShowRationale: Boolean,
onGrantClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Card(
modifier = modifier,
) {
Text(
text = stringResource(R.string.permission_message),
modifier = Modifier.padding(16.dp),
)
if (shouldShowRationale) {
Text(
text = stringResource(R.string.permission_rationale),
modifier = Modifier.padding(horizontal = 10.dp),
)
}
Box(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
contentAlignment = Alignment.BottomEnd,
) {
Button(onClick = onGrantClick) {
Text(text = stringResource(R.string.permission_grant))
}
}
}
}
Loading
Loading