[Android] [PATCH 3/4] VideoPlayer: change SurfaceLayout via OnLayoutChangeListener
Thomas Guillem
thomas at gllm.fr
Tue Nov 25 16:20:26 CET 2014
After Honeycomb only.
---
.../vlc/gui/video/VideoPlayerActivity.java | 38 ++++++++++++++++++----
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index faf4d10..cf11ef6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -103,6 +103,7 @@ import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.View.OnLayoutChangeListener;
import android.view.View.OnSystemUiVisibilityChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
@@ -264,6 +265,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
private boolean mHasMenu = false;
private boolean mIsNavMenu = false;
+ private OnLayoutChangeListener mOnLayoutChangeListener;
+
@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void onCreate(Bundle savedInstanceState) {
@@ -302,7 +305,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == mUiVisibility)
return;
- setSurfaceLayout(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing && !isFinishing()) {
showOverlay();
}
@@ -528,6 +530,32 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
AudioServiceController.getInstance().unbindAudioService(this);
}
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ if (!LibVlcUtil.isHoneycombOrLater())
+ setSurfaceLayout(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
+ super.onConfigurationChanged(newConfig);
+ }
+
+ @Override
+ protected void onStart() {
+ if (LibVlcUtil.isHoneycombOrLater()) {
+ if (mOnLayoutChangeListener == null) {
+ mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right,
+ int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
+ if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom)
+ setSurfaceLayout(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
+ }
+ };
+ }
+ mSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
+ }
+ setSurfaceLayout(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
+ super.onStart();
+ }
+
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
protected void onStop() {
@@ -540,6 +568,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
mPresentation = null;
}
restoreBrightness();
+ if (LibVlcUtil.isHoneycombOrLater() && mOnLayoutChangeListener != null)
+ mSurfaceFrame.removeOnLayoutChangeListener(mOnLayoutChangeListener);
}
@TargetApi(android.os.Build.VERSION_CODES.FROYO)
@@ -853,12 +883,6 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
}
@Override
- public void onConfigurationChanged(Configuration newConfig) {
- setSurfaceLayout(mVideoWidth, mVideoHeight, mVideoVisibleWidth, mVideoVisibleHeight, mSarNum, mSarDen);
- super.onConfigurationChanged(newConfig);
- }
-
- @Override
public void setSurfaceLayout(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den) {
if (width * height == 0)
return;
--
2.1.1
More information about the Android
mailing list