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
1 change: 1 addition & 0 deletions compose/snippets/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ dependencies {
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.core.pip)

implementation(libs.androidx.lifecycle.runtime)
implementation(libs.androidx.lifecycle.viewModelCompose)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026 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.compose.snippets.notifications

import android.content.Context
import android.content.Intent
import android.app.PendingIntent;
import androidx.compose.runtime.Composable
import androidx.core.app.NotificationCompat
import androidx.core.app.PendingIntentCompat

@Composable
fun NotificationSnippets(context: Context) {
// [START android_notification_authenticated_action]
val intent = Intent(
context, null
/** Replace with a valid target activity */
)
val moreSecureNotification = NotificationCompat.Action.Builder(
0, "Reply",
PendingIntentCompat.getActivity(context, 0, intent, PendingIntent.FLAG_NO_CREATE, false)
Comment thread
alabiaga marked this conversation as resolved.
)
// This notification always requests authentication when invoked
// from a lock screen.
.setAuthenticationRequired(true)
.build()
// [END android_notification_authenticated_action]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2026 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.compose.snippets.pictureinpicture

import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.content.ContextCompat
import androidx.core.pip.BasicPictureInPicture
import androidx.core.pip.PictureInPictureDelegate

// [START android_jpip_basic_impl]
class NavOrVideoCallJpipActivity : ComponentActivity(), PictureInPictureDelegate.OnPictureInPictureEventListener {
private lateinit var pictureInPictureImpl: BasicPictureInPicture
Comment thread
alabiaga marked this conversation as resolved.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pictureInPictureImpl = BasicPictureInPicture(this)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need to clean up pictureInPictureImpl in this file too?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i did clean it up in both files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hm can you tell me which line number it is in this file? maybe I'm not seeing it..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i instantiate pictureInPictureImpl in line 32 vs inline on line 29 as suggested by the assistant

// BasicPictureInPicture is ideal for Navigation and Video call use cases.
pictureInPictureImpl.addOnPictureInPictureEventListener(
ContextCompat.getMainExecutor(this),
this
)
setContent {
}
}
override fun onPictureInPictureEvent(
event: PictureInPictureDelegate.Event,
config: Configuration?
) {
when (event) {
PictureInPictureDelegate.Event.ENTERED -> { /* Toggle to PiP layout */ }
PictureInPictureDelegate.Event.EXITED -> { /* Toggle to Full-screen layout */ }
PictureInPictureDelegate.Event.STASHED -> { /* Optional: PiP is stashed */ }
PictureInPictureDelegate.Event.UNSTASHED -> { /* Optional: PiP is unstashed */ }
}
}
}
// [END android_jpip_basic_impl]
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,4 @@ fun EnterPiPPre12(shouldEnterPipMode: Boolean) {
}
// [END android_compose_pip_pre12_should_enter_pip]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2026 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.compose.snippets.pictureinpicture

import android.content.res.Configuration
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.core.content.ContextCompat
import androidx.core.pip.PictureInPictureDelegate
import androidx.core.pip.VideoPlaybackPictureInPicture

// [START android_jpip_video_playback_impl]
class VideoPlaybackJpipActivity : ComponentActivity(), PictureInPictureDelegate.OnPictureInPictureEventListener {
private lateinit var pictureInPictureImpl: VideoPlaybackPictureInPicture
Comment thread
alabiaga marked this conversation as resolved.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
pictureInPictureImpl = VideoPlaybackPictureInPicture(this)
pictureInPictureImpl.addOnPictureInPictureEventListener(
ContextCompat.getMainExecutor(this),
this
)
setContent {
ContentScreen(pictureInPictureImpl)
}
}
override fun onPictureInPictureEvent(
event: PictureInPictureDelegate.Event,
config: Configuration?
) {
when (event) {
PictureInPictureDelegate.Event.ENTER_ANIMATION_START -> { /* Hide overlays */ }
PictureInPictureDelegate.Event.ENTER_ANIMATION_END -> { /* Animation finished */ }
PictureInPictureDelegate.Event.ENTERED -> { /* Switch to PiP layout */ }
PictureInPictureDelegate.Event.STASHED -> { /* PiP stashed */ }
PictureInPictureDelegate.Event.UNSTASHED -> { /* PiP unstashed */ }
PictureInPictureDelegate.Event.EXITED -> { /* Return to full-screen */ }
}
}

@Composable
fun ContentScreen(pipController: VideoPlaybackPictureInPicture) {
DisposableEffect(pipController) {
onDispose {
pipController.close()
}
}
}
}
// [END android_jpip_video_playback_impl]
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
accompanist = "0.36.0"
activityKtx = "1.13.0"
android-googleid = "1.2.0"
androidGradlePlugin = "9.1.0"
androidGradlePlugin = "9.1.1"
androidx-activity-compose = "1.13.0"
androidx-appcompat = "1.7.1"
androidx-appfunctions = "1.0.0-alpha08"
Expand All @@ -15,6 +15,7 @@ androidx-constraintlayout = "2.2.1"
androidx-constraintlayout-compose = "1.1.1"
androidx-coordinator-layout = "1.3.0"
androidx-corektx = "1.18.0"
androidx-corepip = "1.0.0-alpha02"
androidx-credentials = "1.6.0-rc02"
androidx-credentials-play-services-auth = "1.6.0-rc02"
androidx-emoji2-views = "1.6.0"
Expand Down Expand Up @@ -167,6 +168,7 @@ androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayo
androidx-constraintlayout-compose = { module = "androidx.constraintlayout:constraintlayout-compose", version.ref = "androidx-constraintlayout-compose" }
androidx-coordinator-layout = { module = "androidx.coordinatorlayout:coordinatorlayout", version.ref = "androidx-coordinator-layout" }
androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-corektx" }
androidx-core-pip = { module = "androidx.core:core-pip", version.ref = "androidx-corepip"}
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "coreSplashscreen" }
androidx-credentials = { module = "androidx.credentials:credentials", version.ref = "androidx-credentials" }
androidx-credentials-play-services-auth = { module = "androidx.credentials:credentials-play-services-auth", version.ref = "androidx-credentials-play-services-auth" }
Expand Down
Loading