|
|
|
|
@ -15,6 +15,9 @@ import com.fongmi.android.tv.utils.Util; |
|
|
|
|
|
|
|
|
|
public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
|
|
|
|
|
private static final int DISTANCE = 100; |
|
|
|
|
private static final int VELOCITY = 10; |
|
|
|
|
|
|
|
|
|
private final GestureDetector detector; |
|
|
|
|
private final AudioManager manager; |
|
|
|
|
private final Listener listener; |
|
|
|
|
@ -24,6 +27,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
private boolean changeVolume; |
|
|
|
|
private boolean changeSpeed; |
|
|
|
|
private boolean changeTime; |
|
|
|
|
private boolean center; |
|
|
|
|
private boolean touch; |
|
|
|
|
private boolean lock; |
|
|
|
|
private float bright; |
|
|
|
|
@ -67,6 +71,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
changeVolume = false; |
|
|
|
|
changeSpeed = false; |
|
|
|
|
changeTime = false; |
|
|
|
|
center = false; |
|
|
|
|
touch = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
@ -79,12 +84,12 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { |
|
|
|
|
public boolean onScroll(MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) { |
|
|
|
|
if (isEdge(e1) || lock || e1.getPointerCount() > 1) return true; |
|
|
|
|
float deltaX = e2.getX() - e1.getX(); |
|
|
|
|
float deltaY = e1.getY() - e2.getY(); |
|
|
|
|
if (touch) checkFunc(distanceX, distanceY, e2); |
|
|
|
|
if (changeTime) listener.onSeek(time = (long) deltaX * 50); |
|
|
|
|
if (changeTime) listener.onSeek(time = (long) (deltaX * 50)); |
|
|
|
|
if (changeBright) setBright(deltaY); |
|
|
|
|
if (changeVolume) setVolume(deltaY); |
|
|
|
|
return true; |
|
|
|
|
@ -102,6 +107,13 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onFling(MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { |
|
|
|
|
if (isEdge(e1) || !center) return true; |
|
|
|
|
checkFunc(e1, e2, velocityY); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void onSeekEnd() { |
|
|
|
|
listener.onSeekEnd(time); |
|
|
|
|
changeTime = false; |
|
|
|
|
@ -109,11 +121,21 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkFunc(float distanceX, float distanceY, MotionEvent e2) { |
|
|
|
|
changeTime = Math.abs(distanceX) >= Math.abs(distanceY); |
|
|
|
|
if (!changeTime) checkSide(e2); |
|
|
|
|
int four = ResUtil.getScreenWidth(activity) / 4; |
|
|
|
|
if (e2.getX() > four && e2.getX() < four * 3) center = true; |
|
|
|
|
else if (Math.abs(distanceX) < Math.abs(distanceY)) checkSide(e2); |
|
|
|
|
if (Math.abs(distanceX) >= Math.abs(distanceY)) changeTime = true; |
|
|
|
|
touch = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkFunc(MotionEvent e1, MotionEvent e2, float velocityY) { |
|
|
|
|
if (e1.getY() - e2.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { |
|
|
|
|
listener.onFlingUp(); |
|
|
|
|
} else if (e2.getY() - e1.getY() > DISTANCE && Math.abs(velocityY) > VELOCITY) { |
|
|
|
|
listener.onFlingDown(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkSide(MotionEvent e2) { |
|
|
|
|
int half = ResUtil.getScreenWidth(activity) / 2; |
|
|
|
|
if (e2.getX() > half) changeVolume = true; |
|
|
|
|
@ -121,6 +143,7 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setBright(float deltaY) { |
|
|
|
|
if (bright == -1.0f) bright = 0.5f; |
|
|
|
|
int height = videoView.getMeasuredHeight(); |
|
|
|
|
float brightness = deltaY * 2 / height + bright; |
|
|
|
|
if (brightness < 0) brightness = 0f; |
|
|
|
|
@ -156,6 +179,10 @@ public class CustomKeyDownVod extends GestureDetector.SimpleOnGestureListener { |
|
|
|
|
|
|
|
|
|
void onVolumeEnd(); |
|
|
|
|
|
|
|
|
|
void onFlingUp(); |
|
|
|
|
|
|
|
|
|
void onFlingDown(); |
|
|
|
|
|
|
|
|
|
void onSeek(long time); |
|
|
|
|
|
|
|
|
|
void onSeekEnd(long time); |
|
|
|
|
|