Merge pull request #4000 from ByteHamster/double-tap-to-skip
Double-tap video to skip
This commit is contained in:
commit
454cbc7327
@ -6,6 +6,11 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.Gravity;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.widget.ImageView;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import android.text.TextUtils;
|
||||
@ -48,6 +53,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
||||
private boolean videoControlsShowing = true;
|
||||
private boolean videoSurfaceCreated = false;
|
||||
private boolean destroyingDueToReload = false;
|
||||
private long lastScreenTap = 0;
|
||||
|
||||
private VideoControlsHider videoControlsHider = new VideoControlsHider(this);
|
||||
|
||||
@ -58,6 +64,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
||||
private AspectRatioVideoView videoview;
|
||||
private ProgressBar progressIndicator;
|
||||
private FrameLayout videoframe;
|
||||
private ImageView skipAnimationView;
|
||||
|
||||
@Override
|
||||
protected void chooseTheme() {
|
||||
@ -148,6 +155,7 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
||||
videoview = findViewById(R.id.videoview);
|
||||
videoframe = findViewById(R.id.videoframe);
|
||||
progressIndicator = findViewById(R.id.progressIndicator);
|
||||
skipAnimationView = findViewById(R.id.skip_animation);
|
||||
videoview.getHolder().addCallback(surfaceHolderCallback);
|
||||
videoframe.setOnTouchListener(onVideoviewTouched);
|
||||
videoOverlay.setOnTouchListener((view, motionEvent) -> true); // To suppress touches directly below the slider
|
||||
@ -177,16 +185,72 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
||||
return true;
|
||||
}
|
||||
videoControlsHider.stop();
|
||||
|
||||
if (System.currentTimeMillis() - lastScreenTap < 300) {
|
||||
if (event.getX() > v.getMeasuredWidth() / 2) {
|
||||
onFastForward();
|
||||
showSkipAnimation(true);
|
||||
} else {
|
||||
onRewind();
|
||||
showSkipAnimation(false);
|
||||
}
|
||||
if (videoControlsShowing) {
|
||||
getSupportActionBar().hide();
|
||||
hideVideoControls(false);
|
||||
videoControlsShowing = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
toggleVideoControlsVisibility();
|
||||
if (videoControlsShowing) {
|
||||
setupVideoControlsToggler();
|
||||
}
|
||||
|
||||
lastScreenTap = System.currentTimeMillis();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private void showSkipAnimation(boolean isForward) {
|
||||
AnimationSet skipAnimation = new AnimationSet(true);
|
||||
skipAnimation.addAnimation(new ScaleAnimation(1f, 2f, 1f, 2f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
|
||||
skipAnimation.addAnimation(new AlphaAnimation(1f, 0f));
|
||||
skipAnimation.setFillAfter(false);
|
||||
skipAnimation.setDuration(800);
|
||||
|
||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) skipAnimationView.getLayoutParams();
|
||||
if (isForward) {
|
||||
skipAnimationView.setImageResource(R.drawable.ic_av_fast_forward_white_80dp);
|
||||
params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
|
||||
} else {
|
||||
skipAnimationView.setImageResource(R.drawable.ic_av_fast_rewind_white_80dp);
|
||||
params.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
|
||||
}
|
||||
|
||||
skipAnimationView.setVisibility(View.VISIBLE);
|
||||
skipAnimationView.setLayoutParams(params);
|
||||
skipAnimationView.startAnimation(skipAnimation);
|
||||
skipAnimation.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
skipAnimationView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void setupVideoControlsToggler() {
|
||||
videoControlsHider.stop();
|
||||
|
@ -60,6 +60,14 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/skip_animation"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
android:padding="64dp"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/overlay"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user