package com.develop.food.base.widgets

import android.content.Context
import android.graphics.Rect
import android.util.AttributeSet
import android.widget.EditText


/**
 * EditText获取焦点时,hint值消失
 *
 * @author admin2016-9-5 下午4:32:36
 */
class YEditText : EditText {
    private var hint: String? = null

    constructor(context: Context?) : super(context!!) {
        init()

    }

    constructor(context: Context, attrs: AttributeSet) : super(
        context, attrs
    ) {
        init()
    }

    /**
     * 获得hint值
     *
     * @author admin 2016-9-5 下午4:32:19
     */
    private fun init() {
        hint = if (getHint() != null) {
            getHint().toString()
        } else {
            ""
        }

    }

    override fun onFocusChanged(
        focused: Boolean, direction: Int,
        previouslyFocusedRect: Rect?
    ) {
        if (focused) {
            setHint("")
        } else {
            setHint(hint)
        }
        super.onFocusChanged(focused, direction, previouslyFocusedRect)
    }


}