diff options
author | Yorke Lee <yorkelee@google.com> | 2015-04-01 14:08:42 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2015-04-01 14:08:42 -0700 |
commit | 568f5d0395721643cda6c68cb30a05d9002faf23 (patch) | |
tree | 4a1bddca8ff8bc95eff4b2916306d12745e46c2c | |
parent | 98c3b09822844ce61685f794da36c74490a7046c (diff) |
Fix crash when rotating video fragment
Due to a recent framework change,
https://googleplex-android-review.git.corp.google.com/#/c/659363/
TextureView will now crash if setSurfaceTexture is called before
the TextureView is attached to the window. Use an
OnAttachStateListener to call setSurfaceTexture only after the view
is attached to the window.
Change-Id: Ic61302fb81461a00ae9e61352a1798d6c8b61318
-rw-r--r-- | InCallUI/src/com/android/incallui/VideoCallFragment.java | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/InCallUI/src/com/android/incallui/VideoCallFragment.java b/InCallUI/src/com/android/incallui/VideoCallFragment.java index 2b0ddd534..143ee2451 100644 --- a/InCallUI/src/com/android/incallui/VideoCallFragment.java +++ b/InCallUI/src/com/android/incallui/VideoCallFragment.java @@ -101,7 +101,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter, * changes. */ private class VideoCallSurface implements TextureView.SurfaceTextureListener, - View.OnClickListener { + View.OnClickListener, View.OnAttachStateChangeListener { private int mSurfaceId; private TextureView mTextureView; private SurfaceTexture mSavedSurfaceTexture; @@ -151,10 +151,7 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter, mTextureView = view; mTextureView.setSurfaceTextureListener(this); mTextureView.setOnClickListener(this); - - if (mSavedSurfaceTexture != null) { - mTextureView.setSurfaceTexture(mSavedSurfaceTexture); - } + mTextureView.addOnAttachStateChangeListener(this); } /** @@ -235,6 +232,19 @@ public class VideoCallFragment extends BaseFragment<VideoCallPresenter, // Not Handled } + @Override + public void onViewAttachedToWindow(View v) { + if (DEBUG) { + Log.i(TAG, "OnViewAttachedToWindow"); + } + if (mSavedSurfaceTexture != null) { + mTextureView.setSurfaceTexture(mSavedSurfaceTexture); + } + } + + @Override + public void onViewDetachedFromWindow(View v) {} + /** * Retrieves the current {@link TextureView}. * |