[Android] Option: remember brightness level in video player

Geoffrey Métais git at videolan.org
Thu Nov 12 16:40:48 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 12 16:39:41 2015 +0100| [5779fc2da8523a4133285b2438f93dc152d225d0] | committer: Geoffrey Métais

Option: remember brightness level in video player

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

 vlc-android/res/values/strings.xml                 |    2 ++
 vlc-android/res/xml/preferences_ui.xml             |    5 +++
 .../vlc/gui/video/VideoPlayerActivity.java         |   34 +++++++++++++++-----
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index d2ef565..e6fbb93 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -344,6 +344,8 @@
     <string name="confirm_resume_title">Ask confirmation to resume</string>
     <string name="confirm_resume_summary">if activated you will be asked to confirm when a video can be resumed from last position</string>
     <string name="directory_empty">Directory is empty</string>
+    <string name="save_brightness_summary">Remember brightness level in video player</string>
+    <string name="save_brightness_title">Save brightness level for video</string>
 
     <!--Accessibility-->
     <string name="more_actions">More Actions</string>
diff --git a/vlc-android/res/xml/preferences_ui.xml b/vlc-android/res/xml/preferences_ui.xml
index 0303b0c..75b6905 100644
--- a/vlc-android/res/xml/preferences_ui.xml
+++ b/vlc-android/res/xml/preferences_ui.xml
@@ -15,6 +15,11 @@
     <PreferenceCategory android:title="@string/interface_other_category" >
         <CheckBoxPreference
             android:defaultValue="false"
+            android:key="save_brightness"
+            android:summary="@string/save_brightness_summary"
+            android:title="@string/save_brightness_title" />
+        <CheckBoxPreference
+            android:defaultValue="false"
             android:key="dialog_confirm_resume"
             android:summary="@string/confirm_resume_summary"
             android:title="@string/confirm_resume_title" />
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 87ee7f4..560d9b9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -596,6 +596,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     protected void onStart() {
         super.onStart();
         mHelper.onStart();
+        if (mSettings.getBoolean("save_brightness", false)) {
+            float brightness = mSettings.getFloat("brightness_value", -1f);
+            if (brightness != -1f)
+                setWindowBrightness(brightness);
+        }
     }
 
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@@ -629,6 +634,15 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                     Settings.System.SCREEN_BRIGHTNESS_MODE,
                     Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
         }
+        // Save brightness if user wants to
+        if (mSettings.getBoolean("save_brightness", false)) {
+            float brightness = getWindow().getAttributes().screenBrightness;
+            if (brightness != -1f) {
+                SharedPreferences.Editor editor = mSettings.edit();
+                editor.putFloat("brightness_value", brightness);
+                Util.commitPreferences(editor);
+            }
+        }
     }
 
     @Override
@@ -1904,13 +1918,12 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         showInfo(mMute ? R.string.sound_off : R.string.sound_on,1000);
     }
 
-    @TargetApi(android.os.Build.VERSION_CODES.FROYO)
     private void initBrightnessTouch() {
-        float brightnesstemp = 0.6f;
+        WindowManager.LayoutParams lp = getWindow().getAttributes();
+        float brightnesstemp = lp.screenBrightness != -1f ? lp.screenBrightness : 0.6f;
         // Initialize the layoutParams screen brightness
         try {
-            if (AndroidUtil.isFroyoOrLater() &&
-                    Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
+            if (Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
                 Settings.System.putInt(getContentResolver(),
                         Settings.System.SCREEN_BRIGHTNESS_MODE,
                         Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
@@ -1923,7 +1936,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         } catch (SettingNotFoundException e) {
             e.printStackTrace();
         }
-        WindowManager.LayoutParams lp = getWindow().getAttributes();
         lp.screenBrightness = brightnesstemp;
         getWindow().setAttributes(lp);
         mIsFirstBrightnessGesture = false;
@@ -1944,11 +1956,17 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     private void changeBrightness(float delta) {
         // Estimate and adjust Brightness
         WindowManager.LayoutParams lp = getWindow().getAttributes();
-        lp.screenBrightness =  Math.min(Math.max(lp.screenBrightness + delta, 0.01f), 1);
+        float brightness =  Math.min(Math.max(lp.screenBrightness + delta, 0.01f), 1f);
+        setWindowBrightness(brightness);
+        brightness = Math.round(brightness * 100);
+        showInfoWithVerticalBar(getString(R.string.brightness) + "\n" + brightness + '%', 1000, (int) brightness);
+    }
+
+    private void setWindowBrightness(float brightness) {
+        WindowManager.LayoutParams lp = getWindow().getAttributes();
+        lp.screenBrightness =  brightness;
         // Set Brightness
         getWindow().setAttributes(lp);
-        int brightness = Math.round(lp.screenBrightness * 100);
-        showInfoWithVerticalBar(getString(R.string.brightness) + "\n" + brightness + '%', 1000, brightness);
     }
 
     /**



More information about the Android mailing list