Commit a8084723 authored by Geoffrey Métais's avatar Geoffrey Métais

Nicer touch behaviour for volume and brightness

parent 1862583d
...@@ -215,7 +215,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -215,7 +215,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
private int mAudioMax; private int mAudioMax;
private OnAudioFocusChangeListener mAudioFocusListener; private OnAudioFocusChangeListener mAudioFocusListener;
private boolean mMute = false; private boolean mMute = false;
private int mVol, mVolSave; private int mVolSave;
private float mVol;
//Touch Events //Touch Events
private static final int TOUCH_NONE = 0; private static final int TOUCH_NONE = 0;
...@@ -1383,6 +1384,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -1383,6 +1384,8 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
// No volume/brightness action if coef < 2 or a secondary display is connected // No volume/brightness action if coef < 2 or a secondary display is connected
//TODO : Volume action when a secondary display is connected //TODO : Volume action when a secondary display is connected
if (coef > 2 && mPresentation == null) { if (coef > 2 && mPresentation == null) {
mTouchY = event.getRawY();
mTouchX = event.getRawX();
// Volume (Up or Down - Right side) // Volume (Up or Down - Right side)
if (!mEnableBrightnessGesture || (int)mTouchX > (screen.widthPixels / 2)){ if (!mEnableBrightnessGesture || (int)mTouchX > (screen.widthPixels / 2)){
doVolumeTouch(y_changed); doVolumeTouch(y_changed);
...@@ -1397,9 +1400,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -1397,9 +1400,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
// Nexus), gestures can't be made without activating the UI. // Nexus), gestures can't be made without activating the UI.
if(AndroidDevices.hasNavBar()) if(AndroidDevices.hasNavBar())
showOverlay(); showOverlay();
} else {
// Seek (Right or Left move)
doSeekTouch(coef, xgesturesize, false);
} }
// Seek (Right or Left move)
doSeekTouch(coef, xgesturesize, false);
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
...@@ -1462,9 +1466,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -1462,9 +1466,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
private void doVolumeTouch(float y_changed) { private void doVolumeTouch(float y_changed) {
if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_VOLUME) if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_VOLUME)
return; return;
int delta = -(int) ((y_changed / mSurfaceYDisplayRange) * mAudioMax); float delta = - ((y_changed * 2f / mSurfaceYDisplayRange) * mAudioMax);
int vol = (int) Math.min(Math.max(mVol + delta, 0), mAudioMax); mVol += delta;
if (delta != 0) { int vol = (int) Math.min(Math.max(mVol, 0), mAudioMax);
if (delta != 0f) {
setAudioVolume(vol); setAudioVolume(vol);
} }
} }
...@@ -1477,14 +1482,14 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -1477,14 +1482,14 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
private void updateMute () { private void updateMute () {
if (!mMute) { if (!mMute) {
mVolSave = mVol; mVolSave = Float.floatToIntBits(mVol);
mMute = true; mMute = true;
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
showInfo(R.string.sound_off,1000); showInfo(R.string.sound_off,1000);
} else { } else {
mVol = mVolSave; mVol = mVolSave;
mMute = false; mMute = false;
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mVol, 0); mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, Float.floatToIntBits(mVol), 0);
showInfo(R.string.sound_on,1000); showInfo(R.string.sound_on,1000);
} }
} }
...@@ -1509,10 +1514,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer { ...@@ -1509,10 +1514,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_BRIGHTNESS) if (mTouchAction != TOUCH_NONE && mTouchAction != TOUCH_BRIGHTNESS)
return; return;
if (mIsFirstBrightnessGesture) initBrightnessTouch(); if (mIsFirstBrightnessGesture) initBrightnessTouch();
mTouchAction = TOUCH_BRIGHTNESS; mTouchAction = TOUCH_BRIGHTNESS;
// Set delta : 0.07f is arbitrary for now, it possibly will change in the future // Set delta : 2f is arbitrary for now, it possibly will change in the future
float delta = - y_changed / mSurfaceYDisplayRange * 0.07f; float delta = - y_changed / mSurfaceYDisplayRange * 2f;
changeBrightness(delta); changeBrightness(delta);
} }
......
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