Kotlin 이미지(Image) : 엠보싱(embossing) 앱바(App Bar)
------------------------------------------------------------------------------------
MainActivity.kt
------------------------------------------------------------------------------------
class MainActivity : AppCompatActivity() {
private lateinit var mgv: MyGraphicView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mgv = MyGraphicView(this)
setContentView(mgv)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
super.onCreateOptionsMenu(menu)
menu?.add(0, 1, 0, "빛 방향{3,3,3}")
menu?.add(0, 2, 0, "빛 방향{10,3,3}")
menu?.add(0, 3, 0, "빛 방향{3,10,3}")
menu?.add(0, 4, 0, "빛 방향{3,3,10}")
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
1 -> {
choice = 1
mgv.invalidate()
return true
}
2 -> {
choice = 2
mgv.invalidate()
return true
}
3 -> {
choice = 3
mgv.invalidate()
return true
}
4 -> {
choice = 4
mgv.invalidate()
return true
}
}
return false
}
}
------------------------------------------------------------------------------------
***** MyGraphicView.kt
------------------------------------------------------------------------------------
class MyGraphicView(context: Context?) : View(context) {
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
var cenX = this.width / 2f
var cenY = this.height / 2f
var paint = Paint()
paint.color = Color.GRAY
var eMask: EmbossMaskFilter
when (choice) {
1 -> {
eMask = EmbossMaskFilter(floatArrayOf(3f, 3f, 3f), 0.5f, 5f, 30f)
paint.maskFilter = eMask
canvas.drawCircle(cenX, cenY, 300f, paint)
}
2 -> {
eMask = EmbossMaskFilter(floatArrayOf(10f, 3f, 3f), 0.5f, 5f, 30f)
paint.maskFilter = eMask
canvas.drawCircle(cenX, cenY, 300f, paint)
}
3 -> {
eMask = EmbossMaskFilter(floatArrayOf(3f, 10f, 3f), 0.5f, 5f, 30f)
paint.maskFilter = eMask
canvas.drawCircle(cenX, cenY, 300f, paint)
}
4 -> {
eMask = EmbossMaskFilter(floatArrayOf(3f, 3f, 10f), 0.5f, 5f, 30f)
paint.maskFilter = eMask
canvas.drawCircle(cenX, cenY, 300f, paint)
}
}
}
companion object {
internal var choice = 0
//
}
}
------------------------------------------------------------------------------------
strings.xml
------------------------------------------------------------------------------------
<resources>
<string name="app_name">이미지 엠보싱</string>
</resources>
------------------------------------------------------------------------------------
themes.xml
------------------------------------------------------------------------------------
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.ImageEmbossingAppBar" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">#00ACC1</item>
<item name="colorPrimaryDark">#FFB300</item>
</style>
<style name="Theme.ImageEmbossingAppBar" parent="Base.Theme.ImageEmbossingAppBar" />
</resources>