[Android] ViewStub for video player info overlay

Geoffrey Métais git at videolan.org
Mon Jan 9 16:38:51 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  9 16:20:27 2017 +0100| [eea10f3ae9ccfeb9cb338e23a6052e96ff7d92f4] | committer: Geoffrey Métais

ViewStub for video player info overlay

> https://code.videolan.org/videolan/vlc-android/commit/eea10f3ae9ccfeb9cb338e23a6052e96ff7d92f4
---

 vlc-android/res/layout/player.xml                  | 37 ++--------------------
 vlc-android/res/layout/player_overlay_info.xml     | 36 +++++++++++++++++++++
 .../vlc/gui/video/VideoPlayerActivity.java         | 28 ++++++++++------
 3 files changed, 57 insertions(+), 44 deletions(-)

diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index 64823d5..1452289 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -57,45 +57,14 @@
             android:visibility="invisible"
             android:src="@drawable/ic_cone_o" />
 
-        <LinearLayout
-            android:id="@+id/player_overlay_info"
+        <android.support.v7.widget.ViewStubCompat
+            android:id="@+id/player_info_stub"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:orientation="horizontal"
             android:layout_above="@+id/progress_overlay"
             android:layout_centerHorizontal="true"
-            android:background="@drawable/video_list_length_bg"
             android:layout_marginBottom="@dimen/default_margin"
-            android:visibility="invisible">
-            <FrameLayout
-                android:id="@+id/verticalbar"
-                android:layout_width="20dp"
-                android:layout_height="100dp">
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:padding="4dp"
-                    android:orientation="vertical"
-                    android:weightSum="100"
-                    android:gravity="bottom">
-
-                    <View android:id="@+id/verticalbar_progress"
-                        android:layout_width="match_parent"
-                        android:layout_height="0dp"
-                        android:background="@color/orange500transparent" />
-                </LinearLayout>
-            </FrameLayout>
-            <TextView
-                android:id="@+id/player_overlay_textinfo"
-                android:layout_width="wrap_content"
-                android:layout_height="match_parent"
-                android:paddingLeft="10dp"
-                android:paddingRight="10dp"
-                android:gravity="center"
-                android:textColor="@color/white"
-                android:textSize="36sp" />
-        </LinearLayout>
+            android:layout="@layout/player_overlay_info"/>
 
         <ImageView
             android:id="@+id/player_delay_minus"
diff --git a/vlc-android/res/layout/player_overlay_info.xml b/vlc-android/res/layout/player_overlay_info.xml
new file mode 100644
index 0000000..d6bdbfd
--- /dev/null
+++ b/vlc-android/res/layout/player_overlay_info.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/player_overlay_info"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:orientation="horizontal"
+    android:background="@drawable/video_list_length_bg"
+    android:visibility="invisible">
+    <FrameLayout
+        android:id="@+id/verticalbar"
+        android:layout_width="20dp"
+        android:layout_height="100dp">
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:padding="4dp"
+            android:orientation="vertical"
+            android:weightSum="100"
+            android:gravity="bottom">
+
+            <View android:id="@+id/verticalbar_progress"
+                android:layout_width="match_parent"
+                android:layout_height="0dp"
+                android:background="@color/orange500transparent" />
+        </LinearLayout>
+    </FrameLayout>
+    <TextView
+        android:id="@+id/player_overlay_textinfo"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:paddingLeft="10dp"
+        android:paddingRight="10dp"
+        android:gravity="center"
+        android:textColor="@color/white"
+        android:textSize="36sp" />
+</LinearLayout>
\ No newline at end of file
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 3ede784..9c5b889 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -423,12 +423,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         mTime = (TextView) findViewById(R.id.player_overlay_time);
         mLength = (TextView) findViewById(R.id.player_overlay_length);
 
-        // the info textView is not on the overlay
-        mInfo = (TextView) findViewById(R.id.player_overlay_textinfo);
-        mOverlayInfo = findViewById(R.id.player_overlay_info);
-        mVerticalBar = findViewById(R.id.verticalbar);
-        mVerticalBarProgress = findViewById(R.id.verticalbar_progress);
-
         mScreenOrientation = Integer.valueOf(
                 mSettings.getString("screen_orientation", "99" /*SCREEN ORIENTATION SENSOR*/));
 
@@ -523,7 +517,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         getWindowManager().getDefaultDisplay().getMetrics(mScreen);
         mSurfaceYDisplayRange = Math.min(mScreen.widthPixels, mScreen.heightPixels);
         mSurfaceXDisplayRange = Math.max(mScreen.widthPixels, mScreen.heightPixels);
-
     }
 
     @Override
@@ -1350,11 +1343,12 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     }
 
     private void initPlaybackSettingInfo() {
+        initInfoOverlay();
         if (mPresentation == null) {
             UiTools.setViewVisibility(mVerticalBar, View.GONE);
             UiTools.setViewVisibility(mOverlayInfo, View.VISIBLE);
         } else
-            mInfo.setVisibility(View.VISIBLE);
+            UiTools.setViewVisibility(mInfo, View.VISIBLE);
         String text = "";
         if (mPlaybackSetting == DelayState.AUDIO) {
             text += getString(R.string.audio_delay)+"\n";
@@ -1393,7 +1387,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         if (mPresentation == null)
             UiTools.setViewVisibility(mOverlayInfo, View.INVISIBLE);
         else
-            mInfo.setVisibility(View.INVISIBLE);
+            UiTools.setViewVisibility(mInfo, View.INVISIBLE);
         mInfo.setText("");
         mPlayPause.requestFocus();
     }
@@ -1502,6 +1496,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
      * @param duration
      */
     private void showInfo(String text, int duration) {
+        initInfoOverlay();
         if (mPresentation == null) {
             UiTools.setViewVisibility(mVerticalBar, View.GONE);
             UiTools.setViewVisibility(mOverlayInfo, View.VISIBLE);
@@ -1512,7 +1507,20 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         mHandler.sendEmptyMessageDelayed(FADE_OUT_INFO, duration);
     }
 
+    private void initInfoOverlay() {
+        ViewStubCompat vsc = (ViewStubCompat) findViewById(R.id.player_info_stub);
+        if (vsc != null) {
+            vsc.inflate();
+            // the info textView is not on the overlay
+            mInfo = (TextView) findViewById(R.id.player_overlay_textinfo);
+            mOverlayInfo = findViewById(R.id.player_overlay_info);
+            mVerticalBar = findViewById(R.id.verticalbar);
+            mVerticalBarProgress = findViewById(R.id.verticalbar_progress);
+        }
+    }
+
     private void showInfo(int textid, int duration) {
+        initInfoOverlay();
         if (mPresentation == null) {
             UiTools.setViewVisibility(mVerticalBar, View.GONE);
             UiTools.setViewVisibility(mOverlayInfo, View.VISIBLE);
@@ -1545,7 +1553,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                         VideoPlayerActivity.this, android.R.anim.fade_out));
                 UiTools.setViewVisibility(mOverlayInfo, View.INVISIBLE);
             }
-        } else if (mInfo.getVisibility() == View.VISIBLE) {
+        } else if (mInfo != null && mInfo.getVisibility() == View.VISIBLE) {
             mInfo.startAnimation(AnimationUtils.loadAnimation(
                     VideoPlayerActivity.this, android.R.anim.fade_out));
             mInfo.setVisibility(View.INVISIBLE);



More information about the Android mailing list