Skip to content

Commit

Permalink
fixed layout params issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
AndroidDeveloperLB committed Feb 11, 2019
1 parent e23a5fa commit fdaae4e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
27 changes: 15 additions & 12 deletions app/src/main/res/layout/video_trimmer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@
app:layout_constraintBottom_toTopOf="@id/timeTextContainer" app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_menu_crop" tools:ignore="RtlCompat"/>

<View app:layout_constraintTop_toTopOf="@id/timeTextContainer"
android:id="@+id/trimmingContainer" android:layout_width="match_parent" android:layout_height="0px"
android:background="#33ffffff" app:layout_constraintBottom_toBottomOf="parent"/>
<View app:layout_constraintTop_toTopOf="@id/timeTextContainer" android:background="#33ffffff"
android:id="@+id/backgroundView" android:layout_width="match_parent" android:layout_height="0px"
app:layout_constraintBottom_toBottomOf="parent"/>

<com.lb.video_trimmer_library.view.TimeLineView
android:id="@+id/timeLineView" android:layout_width="match_parent" android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"/>

<com.lb.video_trimmer_library.view.RangeSeekBarView
app:layout_constraintTop_toTopOf="@id/timeLineView" android:id="@+id/rangeSeekBarView"
android:layout_width="match_parent" android:layout_height="0px"
app:layout_constraintBottom_toBottomOf="@id/timeLineView"
tools:background="#3300ffff"/>
<FrameLayout android:layout_width="match_parent" android:layout_height="40dp" android:id="@+id/trimmingContainer"
app:layout_constraintBottom_toBottomOf="parent">
<com.lb.video_trimmer_library.view.TimeLineView
android:id="@+id/timeLineView" android:layout_width="match_parent"
android:layout_height="match_parent"/>

<com.lb.video_trimmer_library.view.RangeSeekBarView
app:layout_constraintTop_toTopOf="@id/timeLineView" android:id="@+id/rangeSeekBarView"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:background="#3300ffff"/>
</FrameLayout>

<FrameLayout
android:id="@+id/timeTextContainer" android:layout_width="match_parent" android:layout_height="wrap_content"
android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/timeLineView"
android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/trimmingContainer"
tools:visibility="visible">

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ import com.lb.video_trimmer_library.view.TimeLineView
import java.io.File
import java.lang.ref.WeakReference

abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
abstract class BaseVideoTrimmerView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
private val rangeSeekBarView: RangeSeekBarView
private val videoViewContainer: View
private val timeInfoContainer: View
Expand Down Expand Up @@ -112,12 +116,12 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
}
})
val gestureDetector = GestureDetector(context,
object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
onClickVideoPlayPause()
return true
}
object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
onClickVideoPlayPause()
return true
}
}
)
videoView.setOnErrorListener { _, what, extra ->
if (videoTrimmingListener != null)
Expand Down Expand Up @@ -154,7 +158,7 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
private fun setUpMargins() {
val marge = rangeSeekBarView.thumbWidth
val lp: MarginLayoutParams = timeLineView.layoutParams as MarginLayoutParams
lp.setMargins(marge, 0, marge, 0)
lp.setMargins(marge, lp.topMargin, marge, lp.bottomMargin)
timeLineView.layoutParams = lp
}

Expand All @@ -164,7 +168,8 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
pauseVideo()
val mediaMetadataRetriever = MediaMetadataRetriever()
mediaMetadataRetriever.setDataSource(context, src)
val metadataKeyDuration = java.lang.Long.parseLong(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))
val metadataKeyDuration =
java.lang.Long.parseLong(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))
if (timeVideo < MIN_TIME_FRAME) {
if (metadataKeyDuration - endPosition > MIN_TIME_FRAME - timeVideo) {
endPosition += MIN_TIME_FRAME - timeVideo
Expand All @@ -176,15 +181,23 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
if (videoTrimmingListener != null)
videoTrimmingListener!!.onTrimStarted()
BackgroundExecutor.execute(
object : BackgroundExecutor.Task(null, 0L, null) {
override fun execute() {
try {
TrimVideoUtils.startTrim(context, src!!, dstFile!!, startPosition.toLong(), endPosition.toLong(), duration.toLong(), videoTrimmingListener!!)
} catch (e: Throwable) {
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e)
}
object : BackgroundExecutor.Task(null, 0L, null) {
override fun execute() {
try {
TrimVideoUtils.startTrim(
context,
src!!,
dstFile!!,
startPosition.toLong(),
endPosition.toLong(),
duration.toLong(),
videoTrimmingListener!!
)
} catch (e: Throwable) {
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e)
}
}
}
)
}

Expand Down

0 comments on commit fdaae4e

Please sign in to comment.