[Android] VideoPlayer: change SurfaceLayout via OnLayoutChangeListener

Thomas Guillem git at videolan.org
Tue Nov 25 17:34:19 CET 2014


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri Nov 21 16:12:47 2014 +0100| [a8cccc778c1bcd4e3b8f877312fca4b16e32ee5f] | committer: Thomas Guillem

VideoPlayer: change SurfaceLayout via OnLayoutChangeListener

After Honeycomb only.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=a8cccc778c1bcd4e3b8f877312fca4b16e32ee5f
---

 .../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;



More information about the Android mailing list