package com.gyf.barlibrary;

import android.app.Activity;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import com.bytedance.covode.number.Covode;

public class FitsKeyboard implements ViewTreeObserver.OnGlobalLayoutListener {
    public final int mActionBarHeight;
    public Activity mActivity;
    public View mChildView;
    public View mContentView;
    public View mDecorView;
    public ImmersionBar mImmersionBar;
    public boolean mIsAddListener;
    public int mPaddingBottom;
    public int mPaddingLeft;
    public int mPaddingRight;
    public int mPaddingTop;
    public final int mStatusBarHeight;
    public int mTempKeyboardHeight;
    public Window mWindow;

    static {
        Covode.recordClassIndex(45593);
    }

    public void cancel() {
        if (this.mIsAddListener) {
            this.mDecorView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            this.mIsAddListener = false;
        }
    }

    public void disable() {
        if (!this.mIsAddListener) {
            return;
        }
        if (this.mChildView != null) {
            this.mContentView.setPadding(this.mPaddingLeft, this.mPaddingTop, this.mPaddingRight, this.mPaddingBottom);
        } else {
            this.mContentView.setPadding(this.mImmersionBar.getPaddingLeft(), this.mImmersionBar.getPaddingTop(), this.mImmersionBar.getPaddingRight(), this.mImmersionBar.getPaddingBottom());
        }
    }

    public void onGlobalLayout() {
        int i;
        ImmersionBar immersionBar = this.mImmersionBar;
        if (immersionBar != null && immersionBar.getBarParams() != null && this.mImmersionBar.getBarParams().keyboardEnable) {
            int navigationBarHeight = ImmersionBar.getNavigationBarHeight(this.mActivity);
            Rect rect = new Rect();
            this.mDecorView.getWindowVisibleDisplayFrame(rect);
            int height = this.mContentView.getHeight() - rect.bottom;
            if (height != this.mTempKeyboardHeight) {
                this.mTempKeyboardHeight = height;
                boolean z = true;
                int i2 = 0;
                if (ImmersionBar.checkFitsSystemWindows(this.mWindow.getDecorView().findViewById(16908290))) {
                    height -= navigationBarHeight;
                    if (height <= navigationBarHeight) {
                        z = false;
                    }
                } else if (this.mChildView != null) {
                    if (this.mImmersionBar.getBarParams().isSupportActionBar) {
                        height += this.mActionBarHeight + this.mStatusBarHeight;
                    }
                    if (this.mImmersionBar.getBarParams().fits) {
                        height += this.mStatusBarHeight;
                    }
                    if (height > navigationBarHeight) {
                        i = this.mPaddingBottom + height;
                    } else {
                        i = 0;
                        z = false;
                    }
                    this.mContentView.setPadding(this.mPaddingLeft, this.mPaddingTop, this.mPaddingRight, i);
                } else {
                    int paddingBottom = this.mImmersionBar.getPaddingBottom();
                    height -= navigationBarHeight;
                    if (height > navigationBarHeight) {
                        paddingBottom = height + navigationBarHeight;
                    } else {
                        z = false;
                    }
                    this.mContentView.setPadding(this.mImmersionBar.getPaddingLeft(), this.mImmersionBar.getPaddingTop(), this.mImmersionBar.getPaddingRight(), paddingBottom);
                }
                if (height >= 0) {
                    i2 = height;
                }
                if (this.mImmersionBar.getBarParams().onKeyboardListener != null) {
                    this.mImmersionBar.getBarParams().onKeyboardListener.onKeyboardChange(z, i2);
                }
            }
        }
    }

    public void enable(int i) {
        this.mWindow.setSoftInputMode(i);
        if (!this.mIsAddListener) {
            this.mDecorView.getViewTreeObserver().addOnGlobalLayoutListener(this);
            this.mIsAddListener = true;
        }
    }

    /* JADX WARNING: type inference failed for: r0v1, types: [android.view.View] */
    /* JADX WARNING: Multi-variable type inference failed */
    /* JADX WARNING: Unknown variable types count: 1 */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public FitsKeyboard(com.gyf.barlibrary.ImmersionBar r5, android.app.Activity r6, android.view.Window r7) {
        /*
            r4 = this;
            r4.<init>()
            r4.mImmersionBar = r5
            r4.mActivity = r6
            r4.mWindow = r7
            android.view.View r1 = r7.getDecorView()
            r4.mDecorView = r1
            r0 = 16908290(0x1020002, float:2.3877235E-38)
            android.view.View r3 = r1.findViewById(r0)
            android.widget.FrameLayout r3 = (android.widget.FrameLayout) r3
            r2 = 0
            android.view.View r1 = r3.getChildAt(r2)
            r4.mChildView = r1
            if (r1 == 0) goto L_0x004f
            boolean r0 = r1 instanceof X.094
            if (r0 == 0) goto L_0x002d
            X.094 r1 = (X.094) r1
            android.view.View r0 = r1.getChildAt(r2)
            r4.mChildView = r0
        L_0x002d:
            android.view.View r0 = r4.mChildView
            if (r0 == 0) goto L_0x004f
            int r0 = r0.getPaddingLeft()
            r4.mPaddingLeft = r0
            android.view.View r0 = r4.mChildView
            int r0 = r0.getPaddingTop()
            r4.mPaddingTop = r0
            android.view.View r0 = r4.mChildView
            int r0 = r0.getPaddingRight()
            r4.mPaddingRight = r0
            android.view.View r0 = r4.mChildView
            int r0 = r0.getPaddingBottom()
            r4.mPaddingBottom = r0
        L_0x004f:
            android.view.View r0 = r4.mChildView
            if (r0 == 0) goto L_0x0054
            r3 = r0
        L_0x0054:
            r4.mContentView = r3
            com.gyf.barlibrary.BarConfig r1 = new com.gyf.barlibrary.BarConfig
            android.app.Activity r0 = r4.mActivity
            r1.<init>(r0)
            int r0 = r1.getStatusBarHeight()
            r4.mStatusBarHeight = r0
            int r0 = r1.getActionBarHeight()
            r4.mActionBarHeight = r0
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.gyf.barlibrary.FitsKeyboard.<init>(com.gyf.barlibrary.ImmersionBar, android.app.Activity, android.view.Window):void");
    }
}
