package com.seewo.libvui.signage.dialog;

import D0.b;
import D0.c;
import D0.d;
import D0.e;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

/* JADX INFO: loaded from: classes.dex */
public abstract class SignageBaseDialog extends Dialog {
    private static final String TAG = "SignageBaseDialog";
    private boolean mForbidKeyEvent;

    public static abstract class Builder {
        protected View mBaseLayout;
        protected Dialog mDialog;
        protected Context mDialogContext;
        CharSequence mDialogTitle;
        boolean mForbidKeyEvent;
        boolean mIsNeedScroll;
        protected Button mNegativeButton;
        DialogInterface.OnClickListener mNegativeButtonClickListener;
        String mNegativeButtonText;
        protected Button mNeutralButton;
        DialogInterface.OnClickListener mNeutralButtonClickListener;
        String mNeutralButtonText;
        DialogInterface.OnCancelListener mOnCancelListener;
        DialogInterface.OnDismissListener mOnDismissListener;
        protected Button mPositiveButton;
        DialogInterface.OnClickListener mPositiveButtonClickListener;
        String mPositiveButtonText;
        int mPaddingLeft = -1;
        int mPaddingRight = -1;
        int mPaddingTop = -1;
        int mPaddingBottom = -1;
        int mDialogWidth = -1;

        public Builder(Context context) {
            this.mDialogContext = context;
        }

        private void checkBottomView() {
            if (this.mPositiveButtonText == null && this.mNegativeButtonText == null && this.mNeutralButtonText == null) {
                this.mBaseLayout.findViewById(c.f473a).setVisibility(8);
            }
        }

        private <T extends SignageBaseDialog> T createInstance(Class<T> cls, Context context, int i2) {
            try {
                return cls.getConstructor(Context.class, Integer.TYPE).newInstance(context, Integer.valueOf(i2));
            } catch (Exception e2) {
                Log.e(SignageBaseDialog.TAG, e2.getMessage(), e2);
                throw new IllegalArgumentException("Base dialog newInstance error!");
            }
        }

        private void init(View view, Dialog dialog) {
            this.mDialog = dialog;
            beforeInitView();
            initContentView(view);
            initDialogTitle(view);
            initPositiveButton(dialog);
            initNeutralButton(dialog, view);
            initNegativeButton(dialog);
            initCancelListener(dialog);
            initDismissListener(dialog);
            afterInitView();
            checkBottomView();
            dialog.setContentView(view, new ViewGroup.LayoutParams(-1, -2));
            initDialogWindow(dialog);
        }

        protected void afterInitView() {
        }

        protected void beforeInitView() {
        }

        public <T extends SignageBaseDialog> T create(Class<T> cls) {
            LayoutInflater layoutInflater = (LayoutInflater) this.mDialogContext.getSystemService("layout_inflater");
            T t2 = (T) createInstance(cls, this.mDialogContext, e.f498a);
            View viewInflate = layoutInflater.inflate(d.f491a, (ViewGroup) null);
            this.mBaseLayout = viewInflate;
            this.mPositiveButton = (Button) viewInflate.findViewById(c.f489q);
            this.mNegativeButton = (Button) this.mBaseLayout.findViewById(c.f487o);
            this.mNeutralButton = (Button) this.mBaseLayout.findViewById(c.f488p);
            init(this.mBaseLayout, t2);
            ((SignageBaseDialog) t2).mForbidKeyEvent = this.mForbidKeyEvent;
            return t2;
        }

        public abstract View getContentView();

        public String getPositiveButtonText() {
            return this.mPositiveButtonText;
        }

        protected void initCancelListener(Dialog dialog) {
            DialogInterface.OnCancelListener onCancelListener = this.mOnCancelListener;
            if (onCancelListener != null) {
                dialog.setOnCancelListener(onCancelListener);
            }
        }

        protected void initContentView(View view) {
            View contentView = getContentView();
            ScrollView scrollView = (ScrollView) view.findViewById(c.f480h);
            scrollView.removeAllViews();
            if (this.mIsNeedScroll) {
                ViewGroup.LayoutParams layoutParams = scrollView.getLayoutParams();
                layoutParams.height = this.mDialogContext.getResources().getDimensionPixelSize(b.f468a);
                scrollView.setLayoutParams(layoutParams);
            }
            if (this.mPaddingLeft == -1) {
                this.mPaddingLeft = scrollView.getPaddingLeft();
            }
            if (this.mPaddingRight == -1) {
                this.mPaddingRight = scrollView.getPaddingRight();
            }
            if (this.mPaddingTop == -1) {
                this.mPaddingTop = scrollView.getPaddingTop();
            }
            if (this.mPaddingBottom == -1) {
                this.mPaddingBottom = scrollView.getPaddingBottom();
            }
            scrollView.setPadding(this.mPaddingLeft, this.mPaddingTop, this.mPaddingRight, this.mPaddingBottom);
            scrollView.addView(contentView, new ViewGroup.LayoutParams(-1, -2));
        }

        protected void initDialogTitle(View view) {
            ((TextView) view.findViewById(c.f490r)).setText(this.mDialogTitle);
        }

        protected void initDialogWindow(Dialog dialog) {
            WindowManager.LayoutParams attributes = dialog.getWindow().getAttributes();
            int i2 = this.mDialogWidth;
            if (i2 == -1) {
                attributes.width = dialog.getContext().getResources().getDimensionPixelSize(b.f471d);
            } else {
                attributes.width = i2;
            }
        }

        protected void initDismissListener(Dialog dialog) {
            DialogInterface.OnDismissListener onDismissListener = this.mOnDismissListener;
            if (onDismissListener != null) {
                dialog.setOnDismissListener(onDismissListener);
            }
        }

        protected void initNegativeButton(final Dialog dialog) {
            if (this.mNegativeButtonText == null) {
                this.mNegativeButton.setVisibility(8);
                return;
            }
            this.mNegativeButton.setVisibility(0);
            this.mNegativeButton.setText(this.mNegativeButtonText);
            this.mNegativeButton.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.libvui.signage.dialog.SignageBaseDialog.Builder.3
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    DialogInterface.OnClickListener onClickListener = Builder.this.mNegativeButtonClickListener;
                    if (onClickListener != null) {
                        onClickListener.onClick(dialog, -2);
                    }
                    dialog.dismiss();
                }
            });
        }

        protected void initNeutralButton(final Dialog dialog, View view) {
            if (this.mNeutralButtonText == null) {
                view.findViewById(c.f488p).setVisibility(8);
                return;
            }
            int i2 = c.f488p;
            view.findViewById(i2).setVisibility(0);
            ((TextView) view.findViewById(i2)).setText(this.mNeutralButtonText);
            if (this.mNeutralButtonClickListener != null) {
                view.findViewById(i2).setOnClickListener(new View.OnClickListener() { // from class: com.seewo.libvui.signage.dialog.SignageBaseDialog.Builder.2
                    @Override // android.view.View.OnClickListener
                    public void onClick(View view2) {
                        Builder.this.mNeutralButtonClickListener.onClick(dialog, -3);
                    }
                });
            }
        }

        protected void initPositiveButton(final Dialog dialog) {
            if (this.mPositiveButtonText == null) {
                this.mPositiveButton.setVisibility(8);
                return;
            }
            this.mPositiveButton.setVisibility(0);
            this.mPositiveButton.setText(this.mPositiveButtonText);
            if (this.mPositiveButtonClickListener != null) {
                this.mPositiveButton.setOnClickListener(new View.OnClickListener() { // from class: com.seewo.libvui.signage.dialog.SignageBaseDialog.Builder.1
                    @Override // android.view.View.OnClickListener
                    public void onClick(View view) {
                        Builder.this.mPositiveButtonClickListener.onClick(dialog, -1);
                    }
                });
            }
        }

        public Builder setDialogWidth(int i2) {
            this.mDialogWidth = i2;
            return this;
        }

        public Builder setForbidKeyEvent(boolean z2) {
            this.mForbidKeyEvent = z2;
            return this;
        }

        public void setListViewHeightBasedOnChildren(ListView listView) {
            ListAdapter adapter = listView.getAdapter();
            if (adapter == null) {
                return;
            }
            int count = adapter.getCount();
            int measuredHeight = 0;
            for (int i2 = 0; i2 < count; i2++) {
                View view = adapter.getView(i2, null, listView);
                view.measure(0, 0);
                measuredHeight += view.getMeasuredHeight();
            }
            ViewGroup.LayoutParams layoutParams = listView.getLayoutParams();
            layoutParams.height = measuredHeight + (listView.getDividerHeight() * (count - 1));
            listView.setLayoutParams(layoutParams);
        }

        public Builder setNeedScroll(boolean z2) {
            this.mIsNeedScroll = z2;
            return this;
        }

        public Builder setNegativeButton(int i2, DialogInterface.OnClickListener onClickListener) {
            setNegativeButton((String) this.mDialogContext.getText(i2), onClickListener);
            return this;
        }

        public Builder setNeutralButton(int i2, DialogInterface.OnClickListener onClickListener) {
            setNeutralButton((String) this.mDialogContext.getText(i2), onClickListener);
            return this;
        }

        public Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
            this.mOnCancelListener = onCancelListener;
            return this;
        }

        public Builder setOnDissmissListener(DialogInterface.OnDismissListener onDismissListener) {
            this.mOnDismissListener = onDismissListener;
            return this;
        }

        public Builder setPaddingBottom(int i2) {
            this.mPaddingBottom = i2;
            return this;
        }

        public Builder setPaddingLeft(int i2) {
            this.mPaddingLeft = i2;
            return this;
        }

        public Builder setPaddingRight(int i2) {
            this.mPaddingRight = i2;
            return this;
        }

        public Builder setPaddingTop(int i2) {
            this.mPaddingTop = i2;
            return this;
        }

        public Builder setPositiveButton(int i2, DialogInterface.OnClickListener onClickListener) {
            setPositiveButton((String) this.mDialogContext.getText(i2), onClickListener);
            return this;
        }

        public Builder setTitle(int i2) {
            this.mDialogTitle = (String) this.mDialogContext.getText(i2);
            return this;
        }

        public Builder setNegativeButton(String str, DialogInterface.OnClickListener onClickListener) {
            this.mNegativeButtonText = str;
            this.mNegativeButtonClickListener = onClickListener;
            return this;
        }

        public Builder setNeutralButton(String str, DialogInterface.OnClickListener onClickListener) {
            this.mNeutralButtonText = str;
            this.mNeutralButtonClickListener = onClickListener;
            return this;
        }

        public Builder setPositiveButton(String str, DialogInterface.OnClickListener onClickListener) {
            this.mPositiveButtonText = str;
            this.mPositiveButtonClickListener = onClickListener;
            return this;
        }

        public Builder setTitle(CharSequence charSequence) {
            this.mDialogTitle = charSequence;
            return this;
        }
    }

    protected SignageBaseDialog(Context context, int i2) {
        super(context, i2);
    }

    public Button getButton(int i2) {
        if (i2 == -1) {
            return (Button) findViewById(c.f489q);
        }
        if (i2 == -2) {
            return (Button) findViewById(c.f487o);
        }
        return null;
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i2, KeyEvent keyEvent) {
        return this.mForbidKeyEvent || super.onKeyDown(i2, keyEvent);
    }

    protected SignageBaseDialog(Context context) {
        super(context);
    }
}
