Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin initialzation #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,31 @@ import android.util.TypedValue
/**
* Created by @iamBedant on 05/01/18.
*/
class OutlineTextView : AppCompatTextView {

private val defaultStrokeWidth = 0F
private var isDrawing: Boolean = false

private var strokeColor: Int = 0
private var strokeWidth: Float = 0.toFloat()

constructor(context: Context?) : super(context) {
initResources(context, null)

}

constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
initResources(context, attrs)
class OutlineTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) {

/**
* Constant default values for Outline TextView
*/
companion object {
private const val DEFAULT_STROKE_WIDTH = 0F
}

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
initResources(context, attrs)

}
private var isDrawing: Boolean = false

private fun initResources(context: Context?, attrs: AttributeSet?) {
if (attrs != null) {
val a = context?.obtainStyledAttributes(attrs, R.styleable.outlineAttrs)
strokeColor = a!!.getColor(R.styleable.outlineAttrs_outlineColor,
currentTextColor)
strokeWidth = a.getFloat(R.styleable.outlineAttrs_outlineWidth,
defaultStrokeWidth)
private var strokeColor: Int = currentTextColor
private var strokeWidth: Float = DEFAULT_STROKE_WIDTH

a.recycle()
} else {
strokeColor = currentTextColor
strokeWidth = defaultStrokeWidth
init {
attrs?.let {
context.obtainStyledAttributes(it, R.styleable.outlineAttrs).apply {
strokeColor = getColor(R.styleable.outlineAttrs_outlineColor, currentTextColor)
strokeWidth = getFloat(R.styleable.outlineAttrs_outlineWidth, DEFAULT_STROKE_WIDTH)
recycle()
}
}
setStrokeWidth(strokeWidth)
}
Expand All @@ -74,7 +64,6 @@ class OutlineTextView : AppCompatTextView {
super.invalidate()
}


override fun onDraw(canvas: Canvas) {
if (strokeWidth > 0) {
isDrawing = true
Expand Down