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

Factorize code for vertical touch actions

parent 7db5f0e9
...@@ -2142,25 +2142,18 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C ...@@ -2142,25 +2142,18 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
(mDetector != null && mDetector.onTouchEvent(event))) (mDetector != null && mDetector.onTouchEvent(event)))
return true; return true;
float x_changed, y_changed; final float x_changed = mTouchX != -1f && mTouchY != -1f ? event.getRawX() - mTouchX : 0f;
if (mTouchX != -1f && mTouchY != -1f) { final float y_changed = x_changed != 0f ? event.getRawY() - mTouchY : 0f;
y_changed = event.getRawY() - mTouchY;
x_changed = event.getRawX() - mTouchX;
} else {
x_changed = 0f;
y_changed = 0f;
}
// coef is the gradient's move to determine a neutral zone // coef is the gradient's move to determine a neutral zone
float coef = Math.abs (y_changed / x_changed); final float coef = Math.abs (y_changed / x_changed);
float xgesturesize = ((x_changed / mScreen.xdpi) * 2.54f); final float xgesturesize = ((x_changed / mScreen.xdpi) * 2.54f);
float delta_y = Math.max(1f, (Math.abs(mInitTouchY - event.getRawY()) / mScreen.xdpi + 0.5f) * 2f); final float delta_y = Math.max(1f, (Math.abs(mInitTouchY - event.getRawY()) / mScreen.xdpi + 0.5f) * 2f);
int xTouch = Math.round(event.getRawX()); final int xTouch = Math.round(event.getRawX());
int yTouch = Math.round(event.getRawY()); final int yTouch = Math.round(event.getRawY());
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
// Audio // Audio
mTouchY = mInitTouchY = event.getRawY(); mTouchY = mInitTouchY = event.getRawY();
...@@ -2177,7 +2170,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C ...@@ -2177,7 +2170,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
// Mouse events for the core // Mouse events for the core
sendMouseEvent(MotionEvent.ACTION_DOWN, 0, xTouch, yTouch); sendMouseEvent(MotionEvent.ACTION_DOWN, 0, xTouch, yTouch);
break; break;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
// Mouse events for the core // Mouse events for the core
sendMouseEvent(MotionEvent.ACTION_MOVE, 0, xTouch, yTouch); sendMouseEvent(MotionEvent.ACTION_MOVE, 0, xTouch, yTouch);
...@@ -2190,22 +2182,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C ...@@ -2190,22 +2182,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
return false; return false;
mTouchY = event.getRawY(); mTouchY = event.getRawY();
mTouchX = event.getRawX(); mTouchX = event.getRawX();
// (Up or Down - Right side) LTR: Volume RTL: Brightness doVerticalTouchAction(y_changed);
if ((mTouchControls & (!mIsRtl ? TOUCH_FLAG_AUDIO_VOLUME : TOUCH_FLAG_BRIGHTNESS)) != 0 && (int)mTouchX > (4 * mScreen.widthPixels / 7f)){
if (!mIsRtl)
doVolumeTouch(y_changed);
else
doBrightnessTouch(y_changed);
hideOverlay(true);
}
// (Up or Down - Left side) LTR: Brightness RTL: Volume
if ((mTouchControls & (!mIsRtl ? TOUCH_FLAG_BRIGHTNESS : TOUCH_FLAG_AUDIO_VOLUME)) != 0 && (int)mTouchX < (3 * mScreen.widthPixels / 7f)){
if(!mIsRtl)
doBrightnessTouch(y_changed);
else
doVolumeTouch(y_changed);
hideOverlay(true);
}
} else { } else {
// Seek (Right or Left move) // Seek (Right or Left move)
doSeekTouch(Math.round(delta_y), mIsRtl ? -xgesturesize : xgesturesize , false); doSeekTouch(Math.round(delta_y), mIsRtl ? -xgesturesize : xgesturesize , false);
...@@ -2214,12 +2191,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C ...@@ -2214,12 +2191,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mTouchY = event.getRawY(); mTouchY = event.getRawY();
mTouchX = event.getRawX(); mTouchX = event.getRawX();
mTouchAction = TOUCH_MOVE; mTouchAction = TOUCH_MOVE;
float yaw = mFov * -x_changed/(float)mSurfaceXDisplayRange; final float yaw = mFov * -x_changed/(float)mSurfaceXDisplayRange;
float pitch = mFov * -y_changed/(float)mSurfaceXDisplayRange; final float pitch = mFov * -y_changed/(float)mSurfaceXDisplayRange;
mService.updateViewpoint(yaw, pitch, 0, 0, false); mService.updateViewpoint(yaw, pitch, 0, 0, false);
} }
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
// Mouse events for the core // Mouse events for the core
sendMouseEvent(MotionEvent.ACTION_UP, 0, xTouch, yTouch); sendMouseEvent(MotionEvent.ACTION_UP, 0, xTouch, yTouch);
...@@ -2233,6 +2209,29 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C ...@@ -2233,6 +2209,29 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
return mTouchAction != TOUCH_NONE; return mTouchAction != TOUCH_NONE;
} }
private void doVerticalTouchAction(float y_changed) {
final boolean rightAction = (int) mTouchX > (4 * mScreen.widthPixels / 7f);
final boolean leftAction = !rightAction && (int) mTouchX < (3 * mScreen.widthPixels / 7f);
if (!leftAction && !rightAction)
return;
final boolean audio = (mTouchControls & TOUCH_FLAG_AUDIO_VOLUME) != 0;
final boolean brightness = (mTouchControls & TOUCH_FLAG_BRIGHTNESS) != 0;
if (!audio && !brightness)
return;
if (rightAction ^ mIsRtl) {
if (audio)
doVolumeTouch(y_changed);
else
doBrightnessTouch(y_changed);
} else {
if (brightness)
doBrightnessTouch(y_changed);
else
doVolumeTouch(y_changed);
}
hideOverlay(true);
}
private void doSeekTouch(int coef, float gesturesize, boolean seek) { private void doSeekTouch(int coef, float gesturesize, boolean seek) {
if (coef == 0) if (coef == 0)
coef = 1; coef = 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