Commit 4c9edffd authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Ignore Brightness automatic setting

Brightness seems to be applied for application only anyway
see #189
parent 5bdafb46
......@@ -52,7 +52,6 @@ import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager;
......@@ -71,7 +70,6 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Rational;
import android.view.Display;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
......@@ -177,7 +175,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private FrameLayout mSurfaceFrame;
private Uri mUri;
private boolean mAskResume = true;
private boolean mIsRtl;
private ImageView mPlaylistToggle;
private RecyclerView mPlaylist;
......@@ -242,7 +239,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private String KEY_BLUETOOTH_DELAY = "key_bluetooth_delay";
private long mSpuDelay = 0L;
private long mAudioDelay = 0L;
private boolean mRateHasChanged = false;
private int mCurrentAudioTrack = -2, mCurrentSpuTrack = -2;
private boolean mIsLocked = false;
......@@ -255,8 +251,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private long mSavedTime = -1;
private float mSavedRate = 1.f;
private float mSavedBrightness = -1f;
/**
* For uninterrupted switching between audio and video mode
*/
......@@ -439,7 +433,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mCurrentSize = mSettings.getInt(PreferencesActivity.VIDEO_RATIO, SURFACE_BEST_FIT);
}
mMedialibrary = VLCApplication.getMLInstance();
mIsRtl = AndroidUtil.isJellyBeanMR1OrLater && TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
final int touch;
if (!VLCApplication.showTvUi()) {
touch = (mSettings.getBoolean("enable_volume_gesture", true) ? VideoTouchDelegateKt.TOUCH_FLAG_AUDIO_VOLUME : 0)
......@@ -448,12 +441,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
} else touch = 0;
mCurrentScreenOrientation = getResources().getConfiguration().orientation;
if (touch != 0) {
boolean isRtl = AndroidUtil.isJellyBeanMR1OrLater && TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL;
final DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int yRange = Math.min(dm.widthPixels, dm.heightPixels);
int xRange = Math.max(dm.widthPixels, dm.heightPixels);
final ScreenConfig sc = new ScreenConfig(dm, xRange, yRange, mCurrentScreenOrientation);
mTouchDelegate = new VideoTouchDelegate(this, touch, sc, mIsRtl);
mTouchDelegate = new VideoTouchDelegate(this, touch, sc, isRtl);
}
}
......@@ -467,8 +461,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
*/
setListeners(true);
if (mIsLocked && mScreenOrientation == 99)
setRequestedOrientation(mScreenOrientationLock);
if (mIsLocked && mScreenOrientation == 99) setRequestedOrientation(mScreenOrientationLock);
}
private void setListeners(boolean enabled) {
......@@ -619,11 +612,7 @@ 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);
}
restoreBrightness();
final IntentFilter filter = new IntentFilter(Constants.PLAY_FROM_SERVICE);
filter.addAction(Constants.EXIT_PLAYER);
LocalBroadcastManager.getInstance(this).registerReceiver(
......@@ -670,7 +659,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, subtitleList_serialized);
editor.apply();
restoreBrightness();
saveBrightness();
if (mSubtitlesGetTask != null)
mSubtitlesGetTask.cancel(true);
......@@ -681,17 +670,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
setIntent(new Intent());
}
private void restoreBrightness() {
if (mSavedBrightness != -1f) {
int brightness = (int) (mSavedBrightness *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);
mSavedBrightness = -1f;
}
private void saveBrightness() {
// Save brightness if user wants to
if (mSettings.getBoolean("save_brightness", false)) {
float brightness = getWindow().getAttributes().screenBrightness;
......@@ -703,6 +682,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
}
}
private void restoreBrightness() {
if (mSettings.getBoolean("save_brightness", false)) {
float brightness = mSettings.getFloat("brightness_value", -1f);
if (brightness != -1f) setWindowBrightness(brightness);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
......@@ -2070,7 +2056,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
void changeBrightness(float delta) {
// Estimate and adjust Brightness
WindowManager.LayoutParams lp = getWindow().getAttributes();
final WindowManager.LayoutParams lp = getWindow().getAttributes();
float brightness = Math.min(Math.max(lp.screenBrightness + delta, 0.01f), 1f);
setWindowBrightness(brightness);
brightness = Math.round(brightness * 100);
......@@ -2078,8 +2064,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
}
void setWindowBrightness(float brightness) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
final WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
// Set Brightness
getWindow().setAttributes(lp);
}
......
......@@ -2,7 +2,6 @@ package org.videolan.vlc.gui.video
import android.content.res.Configuration
import android.media.AudioManager
import android.provider.Settings
import android.support.v4.view.GestureDetectorCompat
import android.support.v4.view.ScaleGestureDetectorCompat
import android.util.DisplayMetrics
......@@ -11,7 +10,6 @@ import org.videolan.medialibrary.Tools
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.util.AndroidDevices
import org.videolan.vlc.util.Permissions
const val TOUCH_FLAG_AUDIO_VOLUME = 1
const val TOUCH_FLAG_BRIGHTNESS = 1 shl 1
......@@ -259,38 +257,19 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
private fun initBrightnessTouch() {
val lp = player.window.attributes
var brightnesstemp = if (lp.screenBrightness != -1f) lp.screenBrightness else 0.6f
// Initialize the layoutParams screen brightness
try {
val cr = player.contentResolver
if (Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
if (!Permissions.canWriteSettings(player)) {
Permissions.checkWriteSettingsPermission(player, Permissions.PERMISSION_SYSTEM_BRIGHTNESS)
return
}
Settings.System.putInt(cr,
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL)
player.setSavedBrightness(android.provider.Settings.System.getInt(cr,
android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f)
} else if (brightnesstemp == 0.6f) {
brightnesstemp = android.provider.Settings.System.getInt(cr,
android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f
}
} catch (e: Settings.SettingNotFoundException) {}
val brightnesstemp = if (lp.screenBrightness != -1f) lp.screenBrightness else 0.6f
lp.screenBrightness = brightnesstemp
player.window.attributes = lp
mIsFirstBrightnessGesture = false
}
private fun doBrightnessTouch(y_changed: Float) {
private fun doBrightnessTouch(ychanged: Float) {
if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_BRIGHTNESS) return
if (mIsFirstBrightnessGesture) initBrightnessTouch()
mTouchAction = TOUCH_BRIGHTNESS
// Set delta : 2f is arbitrary for now, it possibly will change in the future
val delta = -y_changed / screenConfig.yRange
val delta = -ychanged / screenConfig.yRange
player.changeBrightness(delta)
}
......@@ -314,13 +293,15 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
}
override fun onScaleEnd(detector: ScaleGestureDetector) {
val grow = detector.scaleFactor > 1.0f
if (grow && player.currentSize != VideoPlayerActivity.SURFACE_FIT_SCREEN) {
savedSize = player.currentSize
player.setVideoSurfacesize(VideoPlayerActivity.SURFACE_FIT_SCREEN)
} else if (!grow && savedSize != -1) {
player.setVideoSurfacesize(savedSize)
savedSize = -1
if (player.fov == 0f) {
val grow = detector.scaleFactor > 1.0f
if (grow && player.currentSize != VideoPlayerActivity.SURFACE_FIT_SCREEN) {
savedSize = player.currentSize
player.setVideoSurfacesize(VideoPlayerActivity.SURFACE_FIT_SCREEN)
} else if (!grow && savedSize != -1) {
player.setVideoSurfacesize(savedSize)
savedSize = -1
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment