Merge "Fix Settings crashed on tapping on notification animation video"

This commit is contained in:
TreeHugger Robot
2019-11-06 04:50:52 +00:00
committed by Android (Google) Code Review
4 changed files with 81 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ import android.view.View;
class MediaAnimationController implements VideoPreference.AnimationController {
private MediaPlayer mMediaPlayer;
private boolean mVideoReady;
private Surface mSurface;
MediaAnimationController(Context context, int videoId) {
final Uri videoPath = new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
@@ -86,10 +87,7 @@ class MediaAnimationController implements VideoPreference.AnimationController {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width,
int height) {
if (mMediaPlayer != null) {
final Surface surface = new Surface(surfaceTexture);
mMediaPlayer.setSurface(surface);
}
setSurface(surfaceTexture);
}
@Override
@@ -105,6 +103,7 @@ class MediaAnimationController implements VideoPreference.AnimationController {
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
setSurface(surfaceTexture);
if (mVideoReady) {
if (preview.getVisibility() == View.VISIBLE) {
preview.setVisibility(View.GONE);
@@ -146,4 +145,11 @@ class MediaAnimationController implements VideoPreference.AnimationController {
mMediaPlayer.start();
}
}
private void setSurface(SurfaceTexture surfaceTexture) {
if (mMediaPlayer != null && mSurface == null) {
mSurface = new Surface(surfaceTexture);
mMediaPlayer.setSurface(mSurface);
}
}
}

View File

@@ -50,6 +50,9 @@ public class VideoPreference extends Preference {
private int mAnimationId;
private int mVectorAnimationId;
private int mHeight = LinearLayout.LayoutParams.MATCH_PARENT - 1; // video height in pixels
private TextureView mVideo;
private ImageView mPreviewImage;
private ImageView mPlayButton;
public VideoPreference(Context context) {
super(context);
@@ -108,19 +111,19 @@ public class VideoPreference extends Preference {
return;
}
final TextureView video = (TextureView) holder.findViewById(R.id.video_texture_view);
final ImageView previewImage = (ImageView) holder.findViewById(R.id.video_preview_image);
final ImageView playButton = (ImageView) holder.findViewById(R.id.video_play_button);
mVideo = (TextureView) holder.findViewById(R.id.video_texture_view);
mPreviewImage = (ImageView) holder.findViewById(R.id.video_preview_image);
mPlayButton = (ImageView) holder.findViewById(R.id.video_play_button);
final AspectRatioFrameLayout layout = (AspectRatioFrameLayout) holder.findViewById(
R.id.video_container);
previewImage.setImageResource(mPreviewId);
mPreviewImage.setImageResource(mPreviewId);
layout.setAspectRatio(mAspectRatio);
if (mHeight >= LinearLayout.LayoutParams.MATCH_PARENT) {
layout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, mHeight));
}
mAnimationController.attachView(video, previewImage, playButton);
mAnimationController.attachView(mVideo, mPreviewImage, mPlayButton);
}
@Override
@@ -164,6 +167,9 @@ public class VideoPreference extends Preference {
}
if (mAnimationId != 0) {
mAnimationController = new MediaAnimationController(mContext, mAnimationId);
if (mVideo != null) {
mAnimationController.attachView(mVideo, mPreviewImage, mPlayButton);
}
}
}