Fix Settings crashed on tapping on notification animation video

- When preference goes back from pause state, it doesn't call through
onBindViewHolder, caused surface view doesn't attach to Mediaplayer.
Call attachView in initAnimationController and set SurfaceView to
MediaPlayer when onSurfaceTextureUpdated to fix the issue.

Fixes: 143905693
Test: manual, robolectric
Change-Id: I0eceead2e4c90ca176ef0f35937898f9b9be6232
This commit is contained in:
Raff Tsai
2019-11-05 13:24:08 +08:00
parent ee9f1be50a
commit 9547fa73cc
4 changed files with 81 additions and 9 deletions

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);
}
}
}