[Android] Handle auto mode for brightness
Geoffrey Métais
git at videolan.org
Mon Nov 3 16:53:19 CET 2014
vlc-ports/android | branch: 1.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Nov 3 14:49:19 2014 +0100| [f30444eef9cc7a73c8ef3db0f464dd1cf7bf0ba7] | committer: Jean-Baptiste Kempf
Handle auto mode for brightness
Prevents for device on auto brightness mode to get a brutal brightness change
There is no proper solution to get the correct value in this case, so I set the starting level at mid range
(cherry picked from commit 451104294ccefe5713177d1e5d66d8c91c732955)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=f30444eef9cc7a73c8ef3db0f464dd1cf7bf0ba7
---
.../vlc/gui/video/VideoPlayerActivity.java | 31 ++++++++++++++++++--
1 file changed, 28 insertions(+), 3 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 6e317ca..0a37f85 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.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
+import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
@@ -231,6 +232,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
// Brightness
private boolean mIsFirstBrightnessGesture = true;
+ private float mRestoreAutoBrightness = -1f;
// Tracks & Subtitles
private Map<Integer,String> mAudioTracksList;
@@ -537,6 +539,20 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
mPresentation.dismiss();
mPresentation = null;
}
+ restoreBrightness();
+ }
+
+ @TargetApi(android.os.Build.VERSION_CODES.FROYO)
+ private void restoreBrightness() {
+ if (mRestoreAutoBrightness != -1f) {
+ int brightness = (int) (mRestoreAutoBrightness*255f);
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.SCREEN_BRIGHTNESS,
+ brightness);
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.SCREEN_BRIGHTNESS_MODE,
+ Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC);
+ }
}
@Override
@@ -1443,14 +1459,23 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
}
}
+ @TargetApi(android.os.Build.VERSION_CODES.FROYO)
private void initBrightnessTouch() {
- float brightnesstemp = 0.01f;
+ float brightnesstemp = 0.6f;
// Initialize the layoutParams screen brightness
try {
- brightnesstemp = android.provider.Settings.System.getInt(getContentResolver(),
+ if (LibVlcUtil.isFroyoOrLater() &&
+ 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);
+ mRestoreAutoBrightness = android.provider.Settings.System.getInt(getContentResolver(),
+ android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
+ } else {
+ brightnesstemp = android.provider.Settings.System.getInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
+ }
} catch (SettingNotFoundException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
WindowManager.LayoutParams lp = getWindow().getAttributes();
More information about the Android
mailing list