wjc
2025-04-09 87cd5df70918e6ba1af849c5f026d3719bfdb1ac
app/src/main/java/com/hdl/photovoltaic/utils/KeyboardStateObserverUtils.java
@@ -17,7 +17,7 @@
    }
    private View mChildOfContent;
    private final View mChildOfContent;
    private int usableHeightPrevious;//使用高度
@@ -52,20 +52,20 @@
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevious) {
            //可用高度无键盘
            //获取整个屏幕的高度
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard / 4)) {
                if (listener != null) {
                    listener.onKeyboardShow();
                    listener.onKeyboardShow(heightDifference);
                }
            } else {
                if (listener != null) {
                    listener.onKeyboardHide();
                    listener.onKeyboardHide(heightDifference);
                }
@@ -87,19 +87,18 @@
    private int computeUsableHeight() {
        Rect r = new Rect();
        //获取可见窗口
        //获取可以显示的区域
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        //Log.d(TAG,"rec bottom>" + r.bottom + " | rec top>" + r.top);
        return (r.bottom - r.top);// 全屏模式下: return r.bottom
    }
    public interface OnKeyboardVisibilityListener {
        void onKeyboardShow();
        void onKeyboardShow(int h);
        void onKeyboardHide();
        void onKeyboardHide(int h);
    }