1.组合使用调节(以三组为例)
//三组滤镜
private var currentFilter1: Filter = NoFilter()
private var currentFilter2: Filter = NoFilter()
private var currentFilter3: Filter = NoFilter()
//点击切换
private var count1 = 0
private var count2 = 0
private var count3 = 0
//所有滤镜类型
private var filters = Filters.values()
.toMutableList()
//初始化
override fun initData(savedInstanceState: Bundle?) {
//设置的越大滑动时值越精确
test1Seek.max = 3600
test2Seek.max = 3600
test3Seek.max = 3600
//默认隐藏三个滑动条
test1Seek.gone()
test2Seek.gone()
test3Seek.gone()
//监听滑动条
test1Seek.userChange {
val temp = currentFilter1
if (temp is OneParameterFilter) temp.parameter1 = it / 3600f
showFilter()
}
test2Seek.userChange {
val temp = currentFilter2
if (temp is OneParameterFilter) temp.parameter1 = it / 3600f
showFilter()
}
test3Seek.userChange {
val temp = currentFilter3
if (temp is OneParameterFilter) temp.parameter1 = it / 3600f
showFilter()
}
//监听切换滤镜类型
test1btn.setOnClickListener {
count1++
currentFilter1 = filters[count1 % filters.size].newInstance()
test1Seek.visibleGone(currentFilter1 is OneParameterFilter)
showFilter()
try {
videoRecorderView.filter = MultiFilter(currentFilter1, currentFilter2, currentFilter3)
} catch (e: Exception) {
e.printStackTrace()
}
}
test2btn.setOnClickListener {
count2++
currentFilter2 = filters[count2 % filters.size].newInstance()
test2Seek.visibleGone(currentFilter2 is OneParameterFilter)
showFilter()
try {
videoRecorderView.filter = MultiFilter(currentFilter1, currentFilter2, currentFilter3)
} catch (e: Exception) {
e.printStackTrace()
}
}
test3btn.setOnClickListener {
count3++
currentFilter3 = filters[count3 % filters.size].newInstance()
test3Seek.visibleGone(currentFilter3 is OneParameterFilter)
showFilter()
try {
videoRecorderView.filter = MultiFilter(currentFilter1, currentFilter2, currentFilter3)
} catch (e: Exception) {
e.printStackTrace()
}
}
showFilter()
}
//刷新当前的组合滤镜信息
private fun showFilter() {
testResult.text =
currentFilter1::class.java.simpleName + ":" + getFilterValue(currentFilter1) + "\n" +
currentFilter2::class.java.simpleName + ":" + getFilterValue(currentFilter2) + "\n" +
currentFilter3::class.java.simpleName + ":" + getFilterValue(currentFilter3)
}
//SeekBar的扩展方法
@SuppressLint("CheckResult")
inline fun SeekBar.userChange(crossinline function: (progress: Int) -> Unit) {
this.userChanges()
.skipInitialValue()
.subscribe({
function(it)
}, {
Timber.e("CASE-userChange-error")
})
}
2.XML代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:background="@color/black_35"
>
<com.otaliastudios.cameraview.CameraView
android:id="@+id/videoRecorderView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
app:cameraAutoFocusResetDelay="60000"
app:cameraEngine="camera1"
app:cameraExperimental="true"
app:cameraGesturePinch="zoom"
app:cameraGestureTap="autoFocus"
app:cameraMode="video"
app:cameraPreview="glSurface"
>
</com.otaliastudios.cameraview.CameraView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
>
<Button
android:id="@+id/test1btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="切换"
/>
<SeekBar
android:id="@+id/test1Seek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:maxHeight="2dp"
android:minHeight="2dp"
android:progress="56"
android:progressDrawable="@drawable/layer_list_live_seek"
android:thumb="@drawable/shape_circle_ff6060_8dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
>
<Button
android:id="@+id/test2btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="切换"
/>
<SeekBar
android:id="@+id/test2Seek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:maxHeight="2dp"
android:minHeight="2dp"
android:progress="56"
android:progressDrawable="@drawable/layer_list_live_seek"
android:thumb="@drawable/shape_circle_ff6060_8dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center_vertical"
android:orientation="horizontal"
>
<Button
android:id="@+id/test3btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="切换"
/>
<SeekBar
android:id="@+id/test3Seek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginStart="12dp"
android:maxHeight="2dp"
android:minHeight="2dp"
android:progress="56"
android:progressDrawable="@drawable/layer_list_live_seek"
android:thumb="@drawable/shape_circle_ff6060_8dp"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/testResult"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:gravity="end"
android:maxLines="3"
android:minLines="3"
android:shadowColor="@color/black_35"
android:shadowDx="2"
android:shadowDy="2"
android:shadowRadius="4"
android:textColor="@color/white_90"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</android.support.constraint.ConstraintLayout>
网友评论