Skip to content

Commit

Permalink
Add filter switching, intensity setting and other logic to the Filter…
Browse files Browse the repository at this point in the history
…View Demo controlled by the matrix
  • Loading branch information
phcbest committed Oct 6, 2024
1 parent e1a7952 commit 2a53f2d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package org.wysaid.cgeDemo

import android.graphics.BitmapFactory
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.SeekBar
import android.widget.Spinner
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.doOnLayout
import org.wysaid.cgeDemo.view.MatrixMutualViewGroup

private const val TAG = "ImageDemoWithMatrixActi"

/**
* @author PengHaiChen
* @date 2024/9/30 21:32:29
Expand All @@ -16,12 +24,55 @@ class ImageDemoWithMatrixActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image_demo_with_matrix)

initView()
initEvent()

}

private fun initEvent() {
val demoView: MatrixMutualViewGroup = findViewById(R.id.demo_view)
val intensity: SeekBar = findViewById(R.id.intensity)
val spinner: Spinner = findViewById(R.id.filter_item)
intensity.progress = intensity.max
intensity.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(p0: SeekBar, p1: Int, p2: Boolean) {
val progress = (p1.toFloat() / p0.max).coerceIn(0F, 1F)
Log.i(TAG, "onProgressChanged: $progress")
demoView.setIntensity(progress)
}

override fun onStartTrackingTouch(p0: SeekBar?) {
}

override fun onStopTrackingTouch(p0: SeekBar?) {
}

})
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(p0: AdapterView<*>?, p1: View?, p2: Int, p3: Long) {
demoView.setFilter(MainActivity.EFFECT_CONFIGS[p2])
}

override fun onNothingSelected(p0: AdapterView<*>?) {

}

}
}

private fun initView() {
val spinner: Spinner = findViewById(R.id.filter_item)
val demoView: MatrixMutualViewGroup = findViewById(R.id.demo_view)
val mBitmap = BitmapFactory.decodeResource(resources, R.mipmap.test_image)
demoView.doOnLayout {
demoView.initBitmap(mBitmap)
demoView.setFilter(MainActivity.EFFECT_CONFIGS[4])
}
val effectConfigs: List<String> = MainActivity.EFFECT_CONFIGS.toList().map {
it.ifBlank { "Select A Filter Apply To Image" }
}
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, effectConfigs)
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class MatrixMutualViewGroup : FrameLayout {


fun setFilter(filterData: String?) = matrixMutualImageView.applyFilter(filterData)
fun setIntensity(intensity: Float) {
matrixMutualImageView.filterAdjust = intensity
}

private fun syncMatrix2Child() {
matrixMutualImageView.syncMatrix = syncTotalMatrix
Expand Down
29 changes: 25 additions & 4 deletions cgeDemo/src/main/res/layout/activity_image_demo_with_matrix.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">

<Spinner
android:id="@+id/filter_item"
android:layout_width="match_parent"
android:layout_height="80dp" />

<SeekBar
android:id="@+id/intensity"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="center_horizontal|top" />


<org.wysaid.cgeDemo.view.MatrixMutualViewGroup
android:id="@+id/demo_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="0dp"
android:layout_weight="1" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="You can try using two hands to zoom and one hand drag" />

</FrameLayout>
</LinearLayout>

0 comments on commit 2a53f2d

Please sign in to comment.