occlusion processing keyboard input box webView

package com.hconline.iso.uicore.utils

import android.app.Activity
import android.graphics.Rect
import android.os.Build
import android.provider.Settings
import android.util.Log
import android.view.View
import android.view.WindowManager
import android.widget.FrameLayout

/**
 * The webView processing keyboard input box shutter 
* Full-page / non-full screen / navigation with a bottom bar / no bottom navigation bar */ class WebViewKeyBoardListener( private val activity: Activity ) { private var mChildOfContent: View? = null private var usableHeightPrevious: Int = 0 private var frameLayoutParams: FrameLayout.LayoutParams? = null fun init() { val content = activity .findViewById<View>(android.R.id.content) as FrameLayout mChildOfContent = content.getChildAt(0) mChildOfContent!!.viewTreeObserver.addOnGlobalLayoutListener { possiblyResizeChildOfContent() } frameLayoutParams = mChildOfContent!! .layoutParams as FrameLayout.LayoutParams } private fun possiblyResizeChildOfContent() { val usableHeightNow = computeUsableHeight() if (usableHeightNow != usableHeightPrevious) { val usableHeightSansKeyboard = mChildOfContent!!.rootView .height - getNavHeight() val heightDifference = usableHeightSansKeyboard - usableHeightNow if (heightDifference > usableHeightSansKeyboard / 4) { // keyboard probably just became visible frameLayoutParams!!.height = usableHeightSansKeyboard - heightDifference } else { // keyboard probably just became hidden frameLayoutParams!!.height = usableHeightSansKeyboard } mChildOfContent!!.requestLayout() usableHeightPrevious = usableHeightNow } } private fun computeUsableHeight(): Int { val r = Rect() mChildOfContent!!.getWindowVisibleDisplayFrame(r) return r.bottom - r.top } private fun getNavHeight(): Int { val resources = activity.resources val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { // determine whether the navigation bar at the bottom to display status val navigationBarShowing = isNavigationBarShowing() if (navigationBarShowing) { val height = resources.getDimensionPixelSize(resourceId) return height } } return 0 } private fun isNavigationBarShowing(): Boolean { // bottom of the phone to determine whether to support navigation bar val haveNavigationBar = checkDeviceHasNavigationBar() if (haveNavigationBar) { if (Build.VERSION.SDK_INT >= 17) { val brand = Build.BRAND val mDeviceInfo = when { brand.toUpperCase() == "HUAWEI" -> "navigationbar_is_min" brand.toUpperCase() == "XIAOMI" -> "force_fsg_nav_bar" brand.toUpperCase() == "VIVO" -> "navigation_gesture_on" brand.toUpperCase() == "OPPO" -> "navigation_gesture_on" else -> "navigationbar_is_min" } // whether full screen val isFullScree = (activity.window.attributes.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN) == WindowManager.LayoutParams.FLAG_FULLSCREEN if (Settings.Global.getInt( activity.contentResolver, mDeviceInfo, 0 ) == 0 && !isFullScree ) { return true } } } return false } private fun checkDeviceHasNavigationBar(): Boolean { was hasNavigationBar = false val rs = activity.resources val id = rs.getIdentifier("config_showNavigationBar", "bool", "android") if (id > 0) { hasNavigationBar = rs.getBoolean(id) } try { val systemPropertiesClass = Class.forName("android.os.SystemProperties"); val m = systemPropertiesClass.getMethod("get", String::class.java) val navBarOverride = m.invoke(systemPropertiesClass, "qemu.hw.mainkeys") as String if ("1" == navBarOverride) { hasNavigationBar = false } else if ("0" == navBarOverride) { hasNavigationBar = true } } catch (e: Exception) { e.printStackTrace () } return hasNavigationBar } companion object { fun getInstance(activity: Activity): WebViewKeyBoardListener { val keyBoardListener = WebViewKeyBoardListener(activity) return keyBoardListener } } }

  

Guess you like

Origin www.cnblogs.com/ggband/p/12205028.html