-
Notifications
You must be signed in to change notification settings - Fork 469
Add ProgressStyle notification sample #296
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8933a6d
Add ProgressStyle notification sample
alabiaga a486d03
Gate ProgressStyle sample on SDK 36+
alabiaga ad90c92
revert gradle update
alabiaga 9b392c9
remove generated launchers
alabiaga 186e424
update gradle version and wrapper and other fixes
alabiaga ac33db2
fix lint error
alabiaga 1a51da5
fix content padding lint check
alabiaga 9d9e352
change min sdk back to 21 for ic launcher
alabiaga 894a7e7
add license headers
alabiaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
This file contains hidden or 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 |
|---|---|---|
| @@ -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 |
This file contains hidden or 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,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) | ||
| } |
22 changes: 22 additions & 0 deletions
22
samples/user-interface/live-updates/src/main/AndroidManifest.xml
This file contains hidden or 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,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> |
137 changes: 137 additions & 0 deletions
137
...rface/live-updates/src/main/java/com/example/platform/ui/live_updates/LiveUpdateSample.kt
This file contains hidden or 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,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 | ||
|
|
||
| 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)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs license header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done