Skip to content

Commit fdaae4e

Browse files
fixed layout params issues.
1 parent e23a5fa commit fdaae4e

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

app/src/main/res/layout/video_trimmer.xml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@
2626
app:layout_constraintBottom_toTopOf="@id/timeTextContainer" app:layout_constraintEnd_toEndOf="parent"
2727
app:srcCompat="@android:drawable/ic_menu_crop" tools:ignore="RtlCompat"/>
2828

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

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

37-
<com.lb.video_trimmer_library.view.RangeSeekBarView
38-
app:layout_constraintTop_toTopOf="@id/timeLineView" android:id="@+id/rangeSeekBarView"
39-
android:layout_width="match_parent" android:layout_height="0px"
40-
app:layout_constraintBottom_toBottomOf="@id/timeLineView"
41-
tools:background="#3300ffff"/>
34+
<FrameLayout android:layout_width="match_parent" android:layout_height="40dp" android:id="@+id/trimmingContainer"
35+
app:layout_constraintBottom_toBottomOf="parent">
36+
<com.lb.video_trimmer_library.view.TimeLineView
37+
android:id="@+id/timeLineView" android:layout_width="match_parent"
38+
android:layout_height="match_parent"/>
39+
40+
<com.lb.video_trimmer_library.view.RangeSeekBarView
41+
app:layout_constraintTop_toTopOf="@id/timeLineView" android:id="@+id/rangeSeekBarView"
42+
android:layout_width="match_parent" android:layout_height="match_parent"
43+
tools:background="#3300ffff"/>
44+
</FrameLayout>
4245

4346
<FrameLayout
4447
android:id="@+id/timeTextContainer" android:layout_width="match_parent" android:layout_height="wrap_content"
45-
android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/timeLineView"
48+
android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/trimmingContainer"
4649
tools:visibility="visible">
4750

4851
<TextView

video_trimmer_library/src/main/java/com/lb/video_trimmer_library/BaseVideoTrimmerView.kt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ import com.lb.video_trimmer_library.view.TimeLineView
5151
import java.io.File
5252
import java.lang.ref.WeakReference
5353

54-
abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int = 0) : FrameLayout(context, attrs, defStyleAttr) {
54+
abstract class BaseVideoTrimmerView @JvmOverloads constructor(
55+
context: Context,
56+
attrs: AttributeSet,
57+
defStyleAttr: Int = 0
58+
) : FrameLayout(context, attrs, defStyleAttr) {
5559
private val rangeSeekBarView: RangeSeekBarView
5660
private val videoViewContainer: View
5761
private val timeInfoContainer: View
@@ -112,12 +116,12 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
112116
}
113117
})
114118
val gestureDetector = GestureDetector(context,
115-
object : GestureDetector.SimpleOnGestureListener() {
116-
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
117-
onClickVideoPlayPause()
118-
return true
119-
}
119+
object : GestureDetector.SimpleOnGestureListener() {
120+
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
121+
onClickVideoPlayPause()
122+
return true
120123
}
124+
}
121125
)
122126
videoView.setOnErrorListener { _, what, extra ->
123127
if (videoTrimmingListener != null)
@@ -154,7 +158,7 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
154158
private fun setUpMargins() {
155159
val marge = rangeSeekBarView.thumbWidth
156160
val lp: MarginLayoutParams = timeLineView.layoutParams as MarginLayoutParams
157-
lp.setMargins(marge, 0, marge, 0)
161+
lp.setMargins(marge, lp.topMargin, marge, lp.bottomMargin)
158162
timeLineView.layoutParams = lp
159163
}
160164

@@ -164,7 +168,8 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
164168
pauseVideo()
165169
val mediaMetadataRetriever = MediaMetadataRetriever()
166170
mediaMetadataRetriever.setDataSource(context, src)
167-
val metadataKeyDuration = java.lang.Long.parseLong(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))
171+
val metadataKeyDuration =
172+
java.lang.Long.parseLong(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))
168173
if (timeVideo < MIN_TIME_FRAME) {
169174
if (metadataKeyDuration - endPosition > MIN_TIME_FRAME - timeVideo) {
170175
endPosition += MIN_TIME_FRAME - timeVideo
@@ -176,15 +181,23 @@ abstract class BaseVideoTrimmerView @JvmOverloads constructor(context: Context,
176181
if (videoTrimmingListener != null)
177182
videoTrimmingListener!!.onTrimStarted()
178183
BackgroundExecutor.execute(
179-
object : BackgroundExecutor.Task(null, 0L, null) {
180-
override fun execute() {
181-
try {
182-
TrimVideoUtils.startTrim(context, src!!, dstFile!!, startPosition.toLong(), endPosition.toLong(), duration.toLong(), videoTrimmingListener!!)
183-
} catch (e: Throwable) {
184-
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e)
185-
}
184+
object : BackgroundExecutor.Task(null, 0L, null) {
185+
override fun execute() {
186+
try {
187+
TrimVideoUtils.startTrim(
188+
context,
189+
src!!,
190+
dstFile!!,
191+
startPosition.toLong(),
192+
endPosition.toLong(),
193+
duration.toLong(),
194+
videoTrimmingListener!!
195+
)
196+
} catch (e: Throwable) {
197+
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e)
186198
}
187199
}
200+
}
188201
)
189202
}
190203

0 commit comments

Comments
 (0)