[Android] [PATCH] Vertical volume/brightness bar

Vladimír Pokorný vlada.pokorny at seznam.cz
Mon Apr 6 22:13:06 CEST 2015


---
 vlc-android/res/drawable/verticalbar_border.xml    |  6 ++++
 vlc-android/res/layout/player.xml                  | 27 ++++++++++++++++++
 .../vlc/gui/video/VideoPlayerActivity.java         | 32 ++++++++++++++++++++--
 3 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 vlc-android/res/drawable/verticalbar_border.xml

diff --git a/vlc-android/res/drawable/verticalbar_border.xml b/vlc-android/res/drawable/verticalbar_border.xml
new file mode 100644
index 0000000..276679e
--- /dev/null
+++ b/vlc-android/res/drawable/verticalbar_border.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
+    <solid android:color="#00000000" />
+    <stroke android:width="1dp"
+            android:color="#77ffffff" />
+</shape>
\ No newline at end of file
diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index a4906a6..6dfdc15 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -77,6 +77,33 @@
             android:textColor="#ffffff"
             android:textSize="36sp"
             android:visibility="invisible" />
+
+        <FrameLayout android:id="@+id/verticalbar"
+                     android:layout_width="28dp"
+                     android:layout_height="100dp"
+                     android:layout_above="@+id/progress_overlay"
+                     android:layout_toLeftOf="@+id/player_overlay_info"
+                     android:layout_marginRight="8dp"
+                     android:layout_marginBottom="-16dp"
+                     android:background="@drawable/video_list_length_bg"
+                     android:visibility="invisible">
+
+            <LinearLayout android:layout_width="match_parent"
+                          android:layout_height="match_parent"
+                          android:layout_margin="7dp"
+                          android:background="@drawable/verticalbar_border"
+                          android:orientation="vertical"
+                          android:weightSum="15"
+                          android:gravity="bottom">
+
+                <View android:id="@+id/verticalbar_progress"
+                      android:layout_width="match_parent"
+                      android:layout_height="0dp"
+                      android:layout_margin="2dp"
+                      android:background="@color/orange500transparent" />
+            </LinearLayout>
+        </FrameLayout>
+
         <ImageView
             android:id="@+id/player_delay_minus"
             android:layout_width="wrap_content"
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 a0ddf2c..06b43aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -86,6 +86,7 @@ import android.view.animation.DecelerateInterpolator;
 import android.view.animation.RotateAnimation;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
 import android.widget.SeekBar;
 import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -196,6 +197,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     private TextView mTime;
     private TextView mLength;
     private TextView mInfo;
+    private View mVerticalBar;
+    private View mVerticalBarProgress;
     private ImageView mLoading;
     private TextView mLoadingText;
     private ImageView mTipsBackground;
@@ -397,6 +400,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
 
         // the info textView is not on the overlay
         mInfo = (TextView) findViewById(R.id.player_overlay_info);
+        mVerticalBar = findViewById(R.id.verticalbar);
+        mVerticalBarProgress = findViewById(R.id.verticalbar_progress);
 
         mEnableBrightnessGesture = mSettings.getBoolean("enable_brightness_gesture", true);
         mScreenOrientation = Integer.valueOf(
@@ -1194,11 +1199,26 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     }
 
     /**
+     * Show text in the info view and vertical progress bar for "duration" milliseconds
+     * @param text
+     * @param duration
+     * @param barNewValue new volume/brightness value (range: 0 - 15)
+     */
+    private void showInfoWithVerticalBar(String text, int duration, int barNewValue) {
+        showInfo(text, duration);
+        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mVerticalBarProgress.getLayoutParams();
+        layoutParams.weight = barNewValue;
+        mVerticalBarProgress.setLayoutParams(layoutParams);
+        mVerticalBar.setVisibility(View.VISIBLE);
+    }
+
+    /**
      * Show text in the info view for "duration" milliseconds
      * @param text
      * @param duration
      */
     private void showInfo(String text, int duration) {
+        mVerticalBar.setVisibility(View.INVISIBLE);
         mInfo.setVisibility(View.VISIBLE);
         mInfo.setText(text);
         mHandler.removeMessages(FADE_OUT_INFO);
@@ -1206,6 +1226,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
     }
 
     private void showInfo(int textid, int duration) {
+        mVerticalBar.setVisibility(View.INVISIBLE);
         mInfo.setVisibility(View.VISIBLE);
         mInfo.setText(textid);
         mHandler.removeMessages(FADE_OUT_INFO);
@@ -1217,6 +1238,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
      * @param text
      */
     private void showInfo(String text) {
+        mVerticalBar.setVisibility(View.INVISIBLE);
         mHandler.removeMessages(FADE_OUT_INFO);
         mInfo.setVisibility(View.VISIBLE);
         mInfo.setText(text);
@@ -1243,6 +1265,11 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
             mInfo.startAnimation(AnimationUtils.loadAnimation(
                     VideoPlayerActivity.this, android.R.anim.fade_out));
         mInfo.setVisibility(View.INVISIBLE);
+
+        if (mVerticalBar.getVisibility() == View.VISIBLE)
+            mVerticalBar.startAnimation(AnimationUtils.loadAnimation(
+                    VideoPlayerActivity.this, android.R.anim.fade_out));
+        mVerticalBar.setVisibility(View.INVISIBLE);
     }
 
     private OnAudioFocusChangeListener mAudioFocusListener = !LibVlcUtil.isFroyoOrLater() ? null :
@@ -1835,7 +1862,7 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
             mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, AudioManager.FLAG_SHOW_UI);
 
         mTouchAction = TOUCH_VOLUME;
-        showInfo(getString(R.string.volume) + '\u00A0' + Integer.toString(vol),1000);
+        showInfoWithVerticalBar(getString(R.string.volume) + '\u00A0' + Integer.toString(vol), 1000, vol);
     }
 
     private void mute(boolean mute) {
@@ -1893,7 +1920,8 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
         lp.screenBrightness =  Math.min(Math.max(lp.screenBrightness + delta, 0.01f), 1);
         // Set Brightness
         getWindow().setAttributes(lp);
-        showInfo(getString(R.string.brightness) + '\u00A0' + Math.round(lp.screenBrightness * 15),1000);
+        int brightness = Math.round(lp.screenBrightness * 15);
+        showInfoWithVerticalBar(getString(R.string.brightness) + '\u00A0' + brightness, 1000, brightness);
     }
 
     /**
-- 
1.9.1



More information about the Android mailing list