LeanbackDemo: Support Picture-in-picture
Bug: 26696836 Change-Id: I9809470b1fdc7bfbb049da3d40ab209578c4b656
This commit is contained in:
@@ -52,6 +52,7 @@ abstract class PlaybackControlHelper extends PlaybackControlGlue {
|
||||
private PlaybackControlsRow.RepeatAction mRepeatAction;
|
||||
private PlaybackControlsRow.ThumbsUpAction mThumbsUpAction;
|
||||
private PlaybackControlsRow.ThumbsDownAction mThumbsDownAction;
|
||||
private PlaybackControlsRow.PictureInPictureAction mPipAction;
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
private final Runnable mUpdateProgressRunnable = new Runnable() {
|
||||
@@ -69,6 +70,7 @@ abstract class PlaybackControlHelper extends PlaybackControlGlue {
|
||||
mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(context);
|
||||
mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsDownAction.OUTLINE);
|
||||
mRepeatAction = new PlaybackControlsRow.RepeatAction(context);
|
||||
mPipAction = new PlaybackControlsRow.PictureInPictureAction(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,6 +82,9 @@ abstract class PlaybackControlHelper extends PlaybackControlGlue {
|
||||
if (!THUMBS_PRIMARY) {
|
||||
adapter.add(mThumbsDownAction);
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT > 23) {
|
||||
adapter.add(mPipAction);
|
||||
}
|
||||
adapter.add(mRepeatAction);
|
||||
if (!THUMBS_PRIMARY) {
|
||||
adapter.add(mThumbsUpAction);
|
||||
@@ -275,4 +280,4 @@ abstract class PlaybackControlHelper extends PlaybackControlGlue {
|
||||
mUpdateProgressRunnable.run();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -54,6 +54,7 @@ abstract class PlaybackControlSupportHelper extends PlaybackControlSupportGlue {
|
||||
private PlaybackControlsRow.RepeatAction mRepeatAction;
|
||||
private PlaybackControlsRow.ThumbsUpAction mThumbsUpAction;
|
||||
private PlaybackControlsRow.ThumbsDownAction mThumbsDownAction;
|
||||
private PlaybackControlsRow.PictureInPictureAction mPipAction;
|
||||
|
||||
private Handler mHandler = new Handler();
|
||||
private final Runnable mUpdateProgressRunnable = new Runnable() {
|
||||
@@ -71,6 +72,7 @@ abstract class PlaybackControlSupportHelper extends PlaybackControlSupportGlue {
|
||||
mThumbsDownAction = new PlaybackControlsRow.ThumbsDownAction(context);
|
||||
mThumbsDownAction.setIndex(PlaybackControlsRow.ThumbsDownAction.OUTLINE);
|
||||
mRepeatAction = new PlaybackControlsRow.RepeatAction(context);
|
||||
mPipAction = new PlaybackControlsRow.PictureInPictureAction(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,6 +84,9 @@ abstract class PlaybackControlSupportHelper extends PlaybackControlSupportGlue {
|
||||
if (!THUMBS_PRIMARY) {
|
||||
adapter.add(mThumbsDownAction);
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT > 23) {
|
||||
adapter.add(mPipAction);
|
||||
}
|
||||
adapter.add(mRepeatAction);
|
||||
if (!THUMBS_PRIMARY) {
|
||||
adapter.add(mThumbsUpAction);
|
||||
@@ -277,4 +282,4 @@ abstract class PlaybackControlSupportHelper extends PlaybackControlSupportGlue {
|
||||
mUpdateProgressRunnable.run();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -16,8 +16,12 @@ package com.example.android.leanback;
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class PlaybackOverlayActivity extends Activity
|
||||
{
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaybackOverlayActivity extends Activity {
|
||||
private List<PictureInPictureModeListener> mListeners = new ArrayList<>();
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
@@ -25,4 +29,23 @@ public class PlaybackOverlayActivity extends Activity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.playback_controls);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean pictureInPictureMode) {
|
||||
for (PictureInPictureModeListener listener : mListeners) {
|
||||
listener.onPictureInPictureModeChanged(pictureInPictureMode);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPictureInPictureModeListener(PictureInPictureModeListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void unregisterPictureInPictureModeListener(PictureInPictureModeListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
public interface PictureInPictureModeListener {
|
||||
void onPictureInPictureModeChanged(boolean pictureInPictureMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,9 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class PlaybackOverlayFragment extends android.support.v17.leanback.app.PlaybackOverlayFragment {
|
||||
public class PlaybackOverlayFragment
|
||||
extends android.support.v17.leanback.app.PlaybackOverlayFragment
|
||||
implements PlaybackOverlayActivity.PictureInPictureModeListener {
|
||||
private static final String TAG = "leanback.PlaybackControlsFragment";
|
||||
|
||||
/**
|
||||
@@ -121,6 +123,15 @@ public class PlaybackOverlayFragment extends android.support.v17.leanback.app.Pl
|
||||
getAdapter().notifyArrayItemRangeChanged(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClicked(Action action) {
|
||||
if (action.getId() == R.id.lb_control_picture_in_picture) {
|
||||
getActivity().enterPictureInPictureMode();
|
||||
return;
|
||||
}
|
||||
super.onActionClicked(action);
|
||||
}
|
||||
};
|
||||
|
||||
mGlue.setOnItemViewClickedListener(mOnItemViewClickedListener);
|
||||
@@ -160,11 +171,24 @@ public class PlaybackOverlayFragment extends android.support.v17.leanback.app.Pl
|
||||
super.onStart();
|
||||
mGlue.setFadingEnabled(true);
|
||||
mGlue.enableProgressUpdating(mGlue.hasValidMedia() && mGlue.isMediaPlaying());
|
||||
((PlaybackOverlayActivity) getActivity()).registerPictureInPictureModeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mGlue.enableProgressUpdating(false);
|
||||
((PlaybackOverlayActivity) getActivity()).unregisterPictureInPictureModeListener(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean pictureInPictureMode) {
|
||||
if (pictureInPictureMode) {
|
||||
// Hide the controls in picture-in-picture mode.
|
||||
setFadingEnabled(true);
|
||||
fadeOut();
|
||||
} else {
|
||||
setFadingEnabled(mGlue.isMediaPlaying());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,12 @@ package com.example.android.leanback;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class PlaybackOverlaySupportActivity extends FragmentActivity
|
||||
{
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PlaybackOverlaySupportActivity extends FragmentActivity {
|
||||
private List<PictureInPictureModeListener> mListeners = new ArrayList<>();
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
@@ -27,4 +31,23 @@ public class PlaybackOverlaySupportActivity extends FragmentActivity
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.playback_controls_support);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean pictureInPictureMode) {
|
||||
for (PictureInPictureModeListener listener : mListeners) {
|
||||
listener.onPictureInPictureModeChanged(pictureInPictureMode);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPictureInPictureModeListener(PictureInPictureModeListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void unregisterPictureInPictureModeListener(PictureInPictureModeListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
public interface PictureInPictureModeListener {
|
||||
void onPictureInPictureModeChanged(boolean pictureInPictureMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class PlaybackOverlaySupportFragment extends android.support.v17.leanback.app.PlaybackOverlaySupportFragment {
|
||||
public class PlaybackOverlaySupportFragment
|
||||
extends android.support.v17.leanback.app.PlaybackOverlaySupportFragment
|
||||
implements PlaybackOverlaySupportActivity.PictureInPictureModeListener {
|
||||
private static final String TAG = "leanback.PlaybackControlsFragment";
|
||||
|
||||
/**
|
||||
@@ -123,6 +125,15 @@ public class PlaybackOverlaySupportFragment extends android.support.v17.leanback
|
||||
getAdapter().notifyArrayItemRangeChanged(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClicked(Action action) {
|
||||
if (action.getId() == R.id.lb_control_picture_in_picture) {
|
||||
getActivity().enterPictureInPictureMode();
|
||||
return;
|
||||
}
|
||||
super.onActionClicked(action);
|
||||
}
|
||||
};
|
||||
|
||||
mGlue.setOnItemViewClickedListener(mOnItemViewClickedListener);
|
||||
@@ -162,11 +173,25 @@ public class PlaybackOverlaySupportFragment extends android.support.v17.leanback
|
||||
super.onStart();
|
||||
mGlue.setFadingEnabled(true);
|
||||
mGlue.enableProgressUpdating(mGlue.hasValidMedia() && mGlue.isMediaPlaying());
|
||||
((PlaybackOverlaySupportActivity) getActivity()).registerPictureInPictureModeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mGlue.enableProgressUpdating(false);
|
||||
((PlaybackOverlaySupportActivity) getActivity()).unregisterPictureInPictureModeListener(
|
||||
this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPictureInPictureModeChanged(boolean pictureInPictureMode) {
|
||||
if (pictureInPictureMode) {
|
||||
// Hide the controls in picture-in-picture mode.
|
||||
setFadingEnabled(true);
|
||||
fadeOut();
|
||||
} else {
|
||||
setFadingEnabled(mGlue.isMediaPlaying());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user