Finish video crop :)

This commit is contained in:
Matthieu 2022-10-21 00:03:08 +02:00
parent 896c9634eb
commit 75deac0e5b
5 changed files with 91 additions and 21 deletions

View File

@ -578,6 +578,7 @@ class ImageCarousel(
null, null, null)
}
} else {
binding.encodeInfoText.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
binding.encodeProgress.visibility = VISIBLE
binding.encodeInfoCard.visibility = VISIBLE
binding.encodeProgress.progress = progress

View File

@ -3,6 +3,7 @@ package org.pixeldroid.app.postCreation.photoEdit
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.graphics.Color
import android.graphics.Rect
import android.media.AudioManager
import android.net.Uri
@ -11,6 +12,7 @@ import android.os.Handler
import android.os.Looper
import android.text.format.DateUtils
import android.util.Log
import android.util.TypedValue
import android.view.Menu
import android.view.MenuItem
import android.view.View
@ -18,6 +20,7 @@ import android.widget.FrameLayout
import android.widget.ImageView
import androidx.core.net.toUri
import androidx.core.os.HandlerCompat
import androidx.core.view.isVisible
import androidx.media.AudioAttributesCompat
import androidx.media2.common.MediaMetadata
import androidx.media2.common.UriMediaItem
@ -43,23 +46,27 @@ import kotlin.math.absoluteValue
class VideoEditActivity : BaseThemedWithBarActivity() {
data class RelativeCropPosition(
val relativeWidth: Float,
val relativeHeight: Float,
val relativeX: Float,
val relativeY: Float,
// Width of the selected part of the video, relative to the width of the video
val relativeWidth: Float = 1f,
// Height of the selected part of the video, relative to the height of the video
val relativeHeight: Float = 1f,
// Distance of left corner of selected part, relative to the width of the video
val relativeX: Float = 0f,
// Distance of top of selected part, relative to the height of the video
val relativeY: Float = 0f,
): Serializable {
fun notCropped(): Boolean =
(relativeX - 1f).absoluteValue < 0.001f
&& (relativeY - 1f).absoluteValue < 0.001f
(relativeWidth - 1f).absoluteValue < 0.001f
&& (relativeHeight - 1f).absoluteValue < 0.001f
&& relativeX.absoluteValue < 0.001f
&& relativeWidth.absoluteValue < 0.001f
&& relativeY.absoluteValue < 0.001f
}
private lateinit var mediaPlayer: MediaPlayer
private var videoPosition: Int = -1
private var cropRelativeDimensions: RelativeCropPosition = RelativeCropPosition(1f,1f,0f,0f)
private var cropRelativeDimensions: RelativeCropPosition = RelativeCropPosition()
private var speed: Int = 1
set(value) {
@ -139,7 +146,6 @@ class VideoEditActivity : BaseThemedWithBarActivity() {
}
binding.cropper.setOnClickListener {
//TODO set crop from saved value
showCropInterface(show = true, uri = uri)
}
@ -167,6 +173,21 @@ class VideoEditActivity : BaseThemedWithBarActivity() {
relativeY = y/fullImageRect.height()
)
binding.cropSavedCard.isVisible = !cropRelativeDimensions.notCropped()
// If a crop was saved, change the color of the crop button to give a visual indication
if(!cropRelativeDimensions.notCropped()){
val typedValue = TypedValue()
val color: Int = if (binding.checkMarkCropped.context.theme
.resolveAttribute(R.attr.colorOnPrimaryContainer, typedValue, true)
) typedValue.data else Color.TRANSPARENT
binding.cropper.drawable.setTint(color)
} else {
// Else reset the tint
binding.cropper.drawable.setTintList(null)
}
showCropInterface(show = false)
}
@ -283,6 +304,9 @@ class VideoEditActivity : BaseThemedWithBarActivity() {
if(show) mediaPlayer.pause()
// Only hide: showing happens on save only if necessary
if(show) binding.cropSavedCard.visibility = View.GONE
binding.muter.visibility = visibilityOfOthers
binding.speeder.visibility = visibilityOfOthers
binding.cropper.visibility = visibilityOfOthers
@ -296,6 +320,7 @@ class VideoEditActivity : BaseThemedWithBarActivity() {
binding.thumbnail6.visibility = visibilityOfOthers
binding.thumbnail7.visibility = visibilityOfOthers
binding.cropImageView.visibility = visibilityOfCrop
binding.saveCropButton.visibility = visibilityOfCrop
@ -322,7 +347,11 @@ class VideoEditActivity : BaseThemedWithBarActivity() {
private fun resetControls() {
binding.videoRangeSeekBar.values = listOf(0f, binding.videoRangeSeekBar.valueTo/2, binding.videoRangeSeekBar.valueTo)
binding.muter.isSelected = false
binding.cropImageView.resetCropRect()
cropRelativeDimensions = RelativeCropPosition()
binding.cropper.drawable.setTintList(null)
binding.cropSavedCard.visibility = View.GONE
}
override fun onDestroy() {

View File

@ -119,16 +119,16 @@ public class CropOverlayView extends View {
}
public void setRecordedCropWindowRect(@NonNull VideoEditActivity.RelativeCropPosition relativeCropPosition) {
Rect rect = new Rect(
(int) (mInitialCropWindowRect.left + relativeCropPosition.getRelativeX() * mInitialCropWindowRect.width()),
(int) (mInitialCropWindowRect.top + relativeCropPosition.getRelativeY() * mInitialCropWindowRect.height()),
(int) (relativeCropPosition.getRelativeWidth() * mInitialCropWindowRect.width()
+ mInitialCropWindowRect.left + relativeCropPosition.getRelativeX() * mInitialCropWindowRect.width()),
(int) (relativeCropPosition.getRelativeHeight() * mInitialCropWindowRect.height()
+ mInitialCropWindowRect.top + relativeCropPosition.getRelativeY() * mInitialCropWindowRect.width())
RectF rect = new RectF(
mInitialCropWindowRect.left + relativeCropPosition.getRelativeX() * mInitialCropWindowRect.width(),
mInitialCropWindowRect.top + relativeCropPosition.getRelativeY() * mInitialCropWindowRect.height(),
relativeCropPosition.getRelativeWidth() * mInitialCropWindowRect.width()
+ mInitialCropWindowRect.left + relativeCropPosition.getRelativeX() * mInitialCropWindowRect.width(),
relativeCropPosition.getRelativeHeight() * mInitialCropWindowRect.height()
+ mInitialCropWindowRect.top + relativeCropPosition.getRelativeY() * mInitialCropWindowRect.height()
);
//TODO call correct thing instead of initial (which sets the limits...)
setInitialCropWindowRect(rect);
mCropWindowHandler.setRect(rect);
}
/** Set crop window initial rectangle to be used instead of default. */
@ -169,7 +169,7 @@ public class CropOverlayView extends View {
/**
* Set the initial crop window size and position. This is dependent on the size and position of
* the image being notCropped.
* the image being cropped.
*/
private void initCropWindow() {

View File

@ -69,7 +69,7 @@
app:layout_constraintBottom_toTopOf="@+id/thumbnail1"
app:layout_constraintStart_toEndOf="@+id/muter" />
<ImageView
<ImageButton
android:id="@+id/cropper"
android:layout_width="60dp"
android:layout_height="40dp"
@ -83,6 +83,45 @@
app:layout_constraintBottom_toTopOf="@+id/thumbnail1"
app:layout_constraintStart_toEndOf="@+id/speeder" />
<com.google.android.material.card.MaterialCardView
android:visibility="invisible"
tools:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@+id/cropper"
app:layout_constraintEnd_toEndOf="@+id/cropper"
app:layout_constraintBottom_toTopOf="@+id/cropper"
android:id="@+id/cropSavedCard"
android:layout_marginBottom="8dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp">
<ImageView
android:id="@+id/checkMarkCropped"
android:importantForAccessibility="no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/check_circle_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/encodeInfoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/checkMarkCropped"
app:layout_constraintTop_toTopOf="@id/checkMarkCropped"
app:layout_constraintStart_toEndOf="@id/checkMarkCropped"
android:layout_marginEnd="8dp"
android:text="@string/crop_saved" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.slider.RangeSlider
android:id="@+id/videoRangeSeekBar"
android:layout_width="match_parent"

View File

@ -272,6 +272,8 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="mute_video">Mute video</string>
<string name="video_speed">Change video speed</string>
<string name="video_crop">Crop video</string>
<string name="save_crop">Save crop</string>
<string name="crop_saved">Crop saved</string>
<string name="still_encoding">One or more videos are still encoding. Wait for them to finish before uploading</string>
<string name="new_post_shortcut_long">Create new post</string>
<string name="new_post_shortcut_short">New post</string>
@ -294,7 +296,6 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
<string name="add_images_error">Error while adding images</string>
<string name="notification_thumbnail">"Thumbnail of image in this notification's post"</string>
<string name="post_preview">Preview of a post</string>
<string name="save_crop">Save crop</string>
<plurals name="replies_count">
<item quantity="one">%d reply</item>
<item quantity="other">%d replies</item>