Add tap to pause to video trimming editor.
This commit is contained in:
parent
28bbfd88b2
commit
5038210d78
5 changed files with 69 additions and 19 deletions
|
@ -34,12 +34,12 @@ public class MediaSendVideoFragment extends Fragment implements VideoEditorHud.E
|
|||
private final Throttler videoScanThrottle = new Throttler(150);
|
||||
private final Handler handler = new Handler();
|
||||
|
||||
private Controller controller;
|
||||
private Data data = new Data();
|
||||
private Uri uri;
|
||||
private VideoPlayer player;
|
||||
private VideoEditorHud hud;
|
||||
private Runnable updatePosition;
|
||||
private Controller controller;
|
||||
private Data data = new Data();
|
||||
private Uri uri;
|
||||
private VideoPlayer player;
|
||||
@Nullable private VideoEditorHud hud;
|
||||
private Runnable updatePosition;
|
||||
|
||||
public static MediaSendVideoFragment newInstance(@NonNull Uri uri) {
|
||||
Bundle args = new Bundle();
|
||||
|
@ -92,16 +92,21 @@ public class MediaSendVideoFragment extends Fragment implements VideoEditorHud.E
|
|||
Log.w(TAG, e);
|
||||
}
|
||||
|
||||
player.setOnClickListener(v -> {
|
||||
player.pause();
|
||||
hud.showPlayButton();
|
||||
});
|
||||
|
||||
player.setPlayerCallback(new VideoPlayer.PlayerCallback() {
|
||||
|
||||
@Override
|
||||
public void onPlaying() {
|
||||
hud.playing();
|
||||
hud.fadePlayButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopped() {
|
||||
hud.stopped();
|
||||
hud.showPlayButton();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -200,6 +205,9 @@ public class MediaSendVideoFragment extends Fragment implements VideoEditorHud.E
|
|||
public void notifyHidden() {
|
||||
if (player != null) {
|
||||
player.pause();
|
||||
if (hud != null) {
|
||||
hud.showPlayButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,6 +215,10 @@ public class MediaSendVideoFragment extends Fragment implements VideoEditorHud.E
|
|||
public void onEditVideoDuration(long totalDurationUs, long startTimeUs, long endTimeUs, boolean fromEdited, boolean editingComplete) {
|
||||
controller.onTouchEventsNeeded(!editingComplete);
|
||||
|
||||
if (hud != null) {
|
||||
hud.hidePlayButton();
|
||||
}
|
||||
|
||||
boolean wasEdited = data.durationEdited;
|
||||
boolean durationEdited = startTimeUs > 0 || endTimeUs < totalDurationUs;
|
||||
|
||||
|
@ -241,7 +253,7 @@ public class MediaSendVideoFragment extends Fragment implements VideoEditorHud.E
|
|||
|
||||
@Override
|
||||
public void onPlay() {
|
||||
player.playFromStart();
|
||||
player.play();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package org.thoughtcrime.securesms.scribbles;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -50,7 +52,7 @@ public final class VideoEditorHud extends LinearLayout {
|
|||
setOrientation(VERTICAL);
|
||||
|
||||
videoTimeLine = root.findViewById(R.id.video_timeline);
|
||||
playOverlay = root.findViewById(R.id.play_overlay);
|
||||
playOverlay = root.findViewById(R.id.play_overlay);
|
||||
|
||||
playOverlay.setOnClickListener(v -> eventListener.onPlay());
|
||||
}
|
||||
|
@ -101,12 +103,43 @@ public final class VideoEditorHud extends LinearLayout {
|
|||
});
|
||||
}
|
||||
|
||||
public void playing() {
|
||||
playOverlay.setVisibility(INVISIBLE);
|
||||
public void showPlayButton() {
|
||||
playOverlay.setVisibility(VISIBLE);
|
||||
playOverlay.animate()
|
||||
.setListener(null)
|
||||
.alpha(1)
|
||||
.scaleX(1).scaleY(1)
|
||||
.setInterpolator(new OvershootInterpolator())
|
||||
.start();
|
||||
}
|
||||
|
||||
public void stopped() {
|
||||
playOverlay.setVisibility(VISIBLE);
|
||||
public void fadePlayButton() {
|
||||
playOverlay.animate()
|
||||
.setListener(new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
playOverlay.setVisibility(GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {}
|
||||
})
|
||||
.alpha(0)
|
||||
.scaleX(0.8f).scaleY(0.8f)
|
||||
.start();
|
||||
}
|
||||
|
||||
public void hidePlayButton() {
|
||||
playOverlay.setVisibility(GONE);
|
||||
playOverlay.setAlpha(0);
|
||||
playOverlay.setScaleX(0.8f);
|
||||
playOverlay.setScaleY(0.8f);
|
||||
}
|
||||
|
||||
@RequiresApi(api = 23)
|
||||
|
|
|
@ -52,7 +52,7 @@ public final class FeatureFlags {
|
|||
private static final String PINS_FOR_ALL = "android.pinsForAll";
|
||||
private static final String PINS_MEGAPHONE_KILL_SWITCH = "android.pinsMegaphoneKillSwitch";
|
||||
private static final String PROFILE_NAMES_MEGAPHONE = "android.profileNamesMegaphone";
|
||||
private static final String VIDEO_TRIMMING = "android.videoTrimming";
|
||||
private static final String VIDEO_TRIMMING = "android.videoTrimming.2";
|
||||
private static final String STORAGE_SERVICE = "android.storageService.2";
|
||||
|
||||
/**
|
||||
|
|
|
@ -216,10 +216,15 @@ public class VideoPlayer extends FrameLayout {
|
|||
this.playerCallback = playerCallback;
|
||||
}
|
||||
|
||||
public void playFromStart() {
|
||||
/**
|
||||
* Resumes a paused video, or restarts if at end of video.
|
||||
*/
|
||||
public void play() {
|
||||
if (exoPlayer != null) {
|
||||
exoPlayer.setPlayWhenReady(true);
|
||||
exoPlayer.seekTo(0);
|
||||
if (exoPlayer.getCurrentPosition() >= exoPlayer.getDuration()) {
|
||||
exoPlayer.seekTo(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,14 +33,14 @@
|
|||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center"
|
||||
android:alpha="0"
|
||||
android:background="@drawable/circle_white"
|
||||
android:longClickable="false"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible">
|
||||
tools:alpha="1">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="19dp"
|
||||
|
|
Loading…
Add table
Reference in a new issue