aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/EmbeddedMenuLayout.kt
blob: 76990ff41ec5f57a14cd8159890d9f7502bbb59a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package net.lacolaco.smileessence.view

import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.support.v7.widget.AppCompatTextView
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import net.lacolaco.smileessence.R

class EmbeddedMenuLayout : LinearLayout {
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) :
            super(context, attrs, defStyleAttr, defStyleRes)

    @JvmOverloads
    constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
            super(context, attrs, defStyleAttr)

    init {
        orientation = VERTICAL
    }

    fun add(name: String, cb: (View) -> Unit) {
        val layoutInflater = LayoutInflater.from(context)
        val textView = layoutInflater.inflate(R.layout.menu_item_simple_text, this, false) as AppCompatTextView
        textView.text = name
        textView.setOnClickListener { cb(it) }
        addView(textView)
    }
}