我正在使用 Exoplayer 开发视频播放器应用程序并应用滑动手势来调节音量和亮度。顶部、底部、右侧、左侧的滑动手势运行良好。 但我想将宽度分为音量和亮度功能的两部分,建议我做额外的代码。 这是我的 OnSwipeTouchListner.java 代码
struct ContainerView: UIViewRepresentable {
func makeUIView(context: Context) -> DonationCell {
DonationCell()
}
func updateUIView(_ uiView: DonationCell,context: Context) {
}
}
}
下面的代码是在Main activity中的实现
public class OnSwipeTouchListener implements View.OnTouchListener {
private final GestureDetector gestureDetector;
public OnSwipeTouchListener(Context ctx) {
gestureDetector = new GestureDetector(ctx,new GestureListener());
}
@Override
public boolean onTouch(View v,MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
private final class GestureListener extends GestureDetector.SimpleonGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
///below first one is downEvent second is moveEvent
@Override
public boolean onfling(MotionEvent e1,MotionEvent e2,float velocityX,float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeleft();
}
result = true;
}
} else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom();
} else {
onSwipeTop();
}
result = true;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeRight() {
}
public void onSwipeleft() {
}
public void onSwipeTop() {
}
public void onSwipeBottom() {
}}