@@ -18,6 +18,7 @@ package com.example.android.pip
18
18
19
19
import android.app.PendingIntent
20
20
import android.app.PictureInPictureParams
21
+ import android.app.PictureInPictureUiState
21
22
import android.app.RemoteAction
22
23
import android.content.BroadcastReceiver
23
24
import android.content.Context
@@ -63,7 +64,7 @@ private const val REQUEST_START_OR_PAUSE = 4
63
64
description = " Basic usage of Picture-in-Picture mode showcasing a stopwatch" ,
64
65
documentation = " https://developer.android.com/develop/ui/views/picture-in-picture" ,
65
66
)
66
- @RequiresApi(Build . VERSION_CODES . O )
67
+ @RequiresApi(26 )
67
68
class PiPSampleActivity : AppCompatActivity () {
68
69
69
70
private val viewModel: PiPViewModel by viewModels()
@@ -128,14 +129,21 @@ class PiPSampleActivity : AppCompatActivity() {
128
129
newConfig : Configuration ,
129
130
) {
130
131
super .onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
131
- if (isInPictureInPictureMode) {
132
- // Hide in-app buttons. They cannot be interacted in the picture-in-picture mode, and
133
- // their features are provided as the action icons.
134
- binding.clear.visibility = View .GONE
135
- binding.startOrPause.visibility = View .GONE
136
- } else {
137
- binding.clear.visibility = View .VISIBLE
138
- binding.startOrPause.visibility = View .VISIBLE
132
+ // Toggle visibility of in-app buttons. They cannot be interacted in the picture-in-picture
133
+ // mode, and their features are provided as the action icons.
134
+ toggleControls(if (isInPictureInPictureMode) View .GONE else View .VISIBLE )
135
+ }
136
+
137
+ private fun toggleControls (view : Int ) {
138
+ binding.clear.visibility = view
139
+ binding.startOrPause.visibility = view
140
+ }
141
+
142
+ @RequiresApi(35 )
143
+ override fun onPictureInPictureUiStateChanged (pipState : PictureInPictureUiState ) {
144
+ super .onPictureInPictureUiStateChanged(pipState)
145
+ if (pipState.isTransitioningToPip) {
146
+ toggleControls(View .GONE )
139
147
}
140
148
}
141
149
0 commit comments