Skip to content

Commit 2a4fe7b

Browse files
Made the changes to Remove the PiP implementation and also Removed the Unused Code.
1 parent b0c5ef5 commit 2a4fe7b

File tree

2 files changed

+1
-225
lines changed

2 files changed

+1
-225
lines changed

samples/user-interface/picture-in-picture/src/main/java/com/example/android/pip/PiPMovieActivity.kt

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616

1717
package com.example.android.pip
1818

19-
import android.app.PictureInPictureParams
20-
import android.app.PictureInPictureUiState
2119
import android.content.res.Configuration
22-
import android.graphics.Rect
2320
import android.os.Build
2421
import android.os.Bundle
2522
import android.support.v4.media.MediaMetadataCompat
@@ -28,14 +25,12 @@ import android.support.v4.media.session.MediaSessionCompat
2825
import android.support.v4.media.session.PlaybackStateCompat
2926
import android.text.util.Linkify
3027
import android.util.Log
31-
import android.util.Rational
3228
import android.view.View
3329
import androidx.activity.ComponentActivity
3430
import androidx.annotation.RequiresApi
3531
import androidx.core.view.WindowCompat
3632
import androidx.core.view.WindowInsetsCompat
3733
import androidx.core.view.WindowInsetsControllerCompat
38-
import androidx.core.view.doOnLayout
3934
import com.example.android.pip.databinding.PipMovieActivityBinding
4035
import com.example.android.pip.widget.MovieView
4136

@@ -109,10 +104,6 @@ class PiPMovieActivity : ComponentActivity() {
109104
}
110105
binding.pip.setOnClickListener { minimize() }
111106

112-
// Configure parameters for the picture-in-picture mode. We do this at the first layout of
113-
// the MovieView because we use its layout position and size.
114-
// binding.movie.doOnLayout { updatePictureInPictureParams() }
115-
116107
// Set up the video; it automatically starts.
117108
binding.movie.setMovieListener(movieListener)
118109
}
@@ -175,57 +166,11 @@ class PiPMovieActivity : ComponentActivity() {
175166
}
176167
}
177168

178-
/*override fun onPictureInPictureModeChanged(
179-
isInPictureInPictureMode: Boolean, newConfig: Configuration,
180-
) {
181-
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
182-
if (isInPictureInPictureMode) {
183-
// Hide the controls in picture-in-picture mode.
184-
binding.movie.hideControls()
185-
} else {
186-
// Show the video controls if the video is not playing
187-
if (!binding.movie.isPlaying) {
188-
binding.movie.showControls()
189-
}
190-
}
191-
}*/
192-
193-
/*@RequiresApi(35)
194-
override fun onPictureInPictureUiStateChanged(pipState: PictureInPictureUiState) {
195-
super.onPictureInPictureUiStateChanged(pipState)
196-
if (pipState.isTransitioningToPip) {
197-
binding.movie.hideControls()
198-
}
199-
}*/
200-
201-
202-
/*private fun updatePictureInPictureParams(): PictureInPictureParams {
203-
// Calculate the aspect ratio of the PiP screen.
204-
val aspectRatio = Rational(binding.movie.width, binding.movie.height)
205-
// The movie view turns into the picture-in-picture mode.
206-
val visibleRect = Rect()
207-
binding.movie.getGlobalVisibleRect(visibleRect)
208-
val params = PictureInPictureParams.Builder()
209-
.setAspectRatio(aspectRatio)
210-
// Specify the portion of the screen that turns into the picture-in-picture mode.
211-
// This makes the transition animation smoother.
212-
.setSourceRectHint(visibleRect)
213-
214-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
215-
// The screen automatically turns into the picture-in-picture mode when it is hidden
216-
// by the "Home" button.
217-
params.setAutoEnterEnabled(true)
218-
}
219-
return params.build().also {
220-
setPictureInPictureParams(it)
221-
}
222-
}*/
223-
224169
/**
225170
* Enters Picture-in-Picture mode.
226171
*/
227172
private fun minimize() {
228-
// enterPictureInPictureMode(updatePictureInPictureParams())
173+
// Used for Entering to Picture-in-Picture mode.
229174
}
230175

231176
/**

samples/user-interface/picture-in-picture/src/main/java/com/example/android/pip/PiPSampleActivity.kt

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,11 @@
1616

1717
package com.example.android.pip
1818

19-
import android.app.PendingIntent
20-
import android.app.PictureInPictureParams
21-
import android.app.PictureInPictureUiState
22-
import android.app.RemoteAction
23-
import android.content.BroadcastReceiver
24-
import android.content.Context
25-
import android.content.Intent
26-
import android.content.IntentFilter
27-
import android.content.res.Configuration
28-
import android.graphics.drawable.Icon
29-
import android.os.Build
3019
import android.os.Bundle
31-
import android.util.Rational
32-
import android.view.View
3320
import androidx.activity.ComponentActivity
34-
import androidx.activity.trackPipAnimationHintView
3521
import androidx.activity.viewModels
36-
import androidx.annotation.DrawableRes
3722
import androidx.annotation.RequiresApi
38-
import androidx.annotation.StringRes
39-
import androidx.core.app.ActivityCompat
40-
import androidx.core.content.ContextCompat
41-
import androidx.lifecycle.Lifecycle
42-
import androidx.lifecycle.lifecycleScope
43-
import androidx.lifecycle.repeatOnLifecycle
4423
import com.example.android.pip.databinding.PipActivityBinding
45-
import kotlinx.coroutines.launch
46-
47-
/** Intent action for stopwatch controls from Picture-in-Picture mode. */
48-
private const val ACTION_STOPWATCH_CONTROL = "stopwatch_control"
49-
50-
/** Intent extra for stopwatch controls from Picture-in-Picture mode. */
51-
private const val EXTRA_CONTROL_TYPE = "control_type"
52-
private const val CONTROL_TYPE_CLEAR = 1
53-
private const val CONTROL_TYPE_START_OR_PAUSE = 2
54-
55-
private const val REQUEST_CLEAR = 3
56-
private const val REQUEST_START_OR_PAUSE = 4
5724

5825
/**
5926
* Demonstrates usage of Picture-in-Picture mode on phones and tablets.
@@ -64,23 +31,6 @@ class PiPSampleActivity : ComponentActivity() {
6431
private val viewModel: PiPViewModel by viewModels()
6532
private lateinit var binding: PipActivityBinding
6633

67-
/**
68-
* A [BroadcastReceiver] for handling action items on the picture-in-picture mode.
69-
*/
70-
private val broadcastReceiver = object : BroadcastReceiver() {
71-
72-
// Called when an item is clicked.
73-
override fun onReceive(context: Context?, intent: Intent?) {
74-
if (intent == null || intent.action != ACTION_STOPWATCH_CONTROL) {
75-
return
76-
}
77-
when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {
78-
CONTROL_TYPE_START_OR_PAUSE -> viewModel.startOrPause()
79-
CONTROL_TYPE_CLEAR -> viewModel.clear()
80-
}
81-
}
82-
}
83-
8434
override fun onCreate(savedInstanceState: Bundle?) {
8535
super.onCreate(savedInstanceState)
8636
binding = PipActivityBinding.inflate(layoutInflater)
@@ -89,132 +39,13 @@ class PiPSampleActivity : ComponentActivity() {
8939
binding.clear.setOnClickListener { viewModel.clear() }
9040
binding.startOrPause.setOnClickListener { viewModel.startOrPause() }
9141
binding.pip.setOnClickListener {
92-
// enterPictureInPictureMode(updatePictureInPictureParams(viewModel.started.value == true))
9342
}
9443
// Observe data from the viewModel.
9544
viewModel.time.observe(this) { time -> binding.time.text = time }
9645
viewModel.started.observe(this) { started ->
9746
binding.startOrPause.setImageResource(
9847
if (started) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp,
9948
)
100-
// updatePictureInPictureParams(started)
101-
}
102-
103-
// Use trackPipAnimationHint view to make a smooth enter/exit pip transition.
104-
// See https://android.devsite.corp.google.com/develop/ui/views/picture-in-picture#smoother-transition
105-
/* lifecycleScope.launch {
106-
repeatOnLifecycle(Lifecycle.State.STARTED) {
107-
trackPipAnimationHintView(binding.stopwatchBackground)
108-
}
109-
}*/
110-
111-
// Handle events from the action icons on the picture-in-picture mode.
112-
/*ActivityCompat.registerReceiver(
113-
this,
114-
broadcastReceiver,
115-
IntentFilter(ACTION_STOPWATCH_CONTROL),
116-
ContextCompat.RECEIVER_NOT_EXPORTED
117-
)*/
118-
}
119-
120-
// This is called when the activity gets into or out of the picture-in-picture mode.
121-
/*override fun onPictureInPictureModeChanged(
122-
isInPictureInPictureMode: Boolean,
123-
newConfig: Configuration,
124-
) {
125-
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
126-
// Toggle visibility of in-app buttons. They cannot be interacted in the picture-in-picture
127-
// mode, and their features are provided as the action icons.
128-
toggleControls(if (isInPictureInPictureMode) View.GONE else View.VISIBLE)
129-
}*/
130-
131-
private fun toggleControls(view: Int) {
132-
binding.clear.visibility = view
133-
binding.startOrPause.visibility = view
134-
}
135-
136-
/* @RequiresApi(35)
137-
override fun onPictureInPictureUiStateChanged(pipState: PictureInPictureUiState) {
138-
super.onPictureInPictureUiStateChanged(pipState)
139-
if (pipState.isTransitioningToPip) {
140-
toggleControls(View.GONE)
141-
}
142-
}*/
143-
144-
/**
145-
* Updates the parameters of the picture-in-picture mode for this activity based on the current
146-
* [started] state of the stopwatch.
147-
*/
148-
/*
149-
private fun updatePictureInPictureParams(started: Boolean): PictureInPictureParams {
150-
val params = PictureInPictureParams.Builder()
151-
// Set action items for the picture-in-picture mode. These are the only custom controls
152-
// available during the picture-in-picture mode.
153-
.setActions(
154-
listOf(
155-
// "Clear" action.
156-
createRemoteAction(
157-
R.drawable.ic_refresh_24dp,
158-
R.string.clear,
159-
REQUEST_CLEAR,
160-
CONTROL_TYPE_CLEAR,
161-
),
162-
if (started) {
163-
// "Pause" action when the stopwatch is already started.
164-
createRemoteAction(
165-
R.drawable.ic_pause_24dp,
166-
R.string.pause,
167-
REQUEST_START_OR_PAUSE,
168-
CONTROL_TYPE_START_OR_PAUSE,
169-
)
170-
} else {
171-
// "Start" action when the stopwatch is not started.
172-
createRemoteAction(
173-
R.drawable.ic_play_arrow_24dp,
174-
R.string.start,
175-
REQUEST_START_OR_PAUSE,
176-
CONTROL_TYPE_START_OR_PAUSE,
177-
)
178-
},
179-
),
180-
)
181-
// Set the aspect ratio of the picture-in-picture mode.
182-
.setAspectRatio(Rational(16, 9))
183-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
184-
// Turn the screen into the picture-in-picture mode if it's hidden by the "Home" button.
185-
params.setAutoEnterEnabled(true)
186-
// Disables the seamless resize. The seamless resize works great for videos where the
187-
// content can be arbitrarily scaled, but you can disable this for non-video content so
188-
// that the picture-in-picture mode is resized with a cross fade animation.
189-
.setSeamlessResizeEnabled(false)
190-
}
191-
return params.build().also {
192-
setPictureInPictureParams(it)
19349
}
19450
}
195-
*/
196-
197-
/**
198-
* Creates a [RemoteAction]. It is used as an action icon on the overlay of the
199-
* picture-in-picture mode.
200-
*/
201-
private fun createRemoteAction(
202-
@DrawableRes iconResId: Int,
203-
@StringRes titleResId: Int,
204-
requestCode: Int,
205-
controlType: Int,
206-
): RemoteAction {
207-
return RemoteAction(
208-
Icon.createWithResource(this, iconResId),
209-
getString(titleResId),
210-
getString(titleResId),
211-
PendingIntent.getBroadcast(
212-
this,
213-
requestCode,
214-
Intent(ACTION_STOPWATCH_CONTROL)
215-
.putExtra(EXTRA_CONTROL_TYPE, controlType),
216-
PendingIntent.FLAG_IMMUTABLE,
217-
),
218-
)
219-
}
22051
}

0 commit comments

Comments
 (0)