package com.ys.bdtp.android.base.utils

import android.content.Context.INPUT_METHOD_SERVICE
import android.app.Activity
import android.view.inputmethod.InputMethodManager


/**
 * Android软键盘工具类
 *
 * @author  庞利祥(sybotan@126.com)
 */
object SKeyboardUtil {
    /**
     * 隐藏键盘
     *
     * @param   activity     当前activity对象
     */
    fun dismissSoftKeyboard(activity: Activity): Boolean {
        try {
            val inputMethodManage = activity.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
            return if (activity.currentFocus == null) {
                inputMethodManage.hideSoftInputFromWindow(activity.window.decorView.windowToken, 0)
            } else {
                inputMethodManage.hideSoftInputFromWindow(activity.currentFocus!!.windowToken, 0)
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }

        return false
    } // Function dismissSoftKeyboard()
} // Object SKeyboardUtil