package androidx.preference;

import a3.b;
import a3.t;
import android.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ComponentCallbacks2;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
@Deprecated
public abstract class PreferenceDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public DialogPreference f3593a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public CharSequence f3594b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public CharSequence f3595c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public CharSequence f3596d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public CharSequence f3597e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f3598f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public BitmapDrawable f3599g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f3600h;

    @Deprecated
    public PreferenceDialogFragment() {
    }

    public final DialogPreference a() {
        if (this.f3593a == null) {
            this.f3593a = (DialogPreference) ((b) getTargetFragment()).findPreference(getArguments().getString("key"));
        }
        return this.f3593a;
    }

    public void b(View view) {
        int i10;
        View viewFindViewById = view.findViewById(R.id.message);
        if (viewFindViewById != null) {
            CharSequence charSequence = this.f3597e;
            if (TextUtils.isEmpty(charSequence)) {
                i10 = 8;
            } else {
                if (viewFindViewById instanceof TextView) {
                    ((TextView) viewFindViewById).setText(charSequence);
                }
                i10 = 0;
            }
            if (viewFindViewById.getVisibility() != i10) {
                viewFindViewById.setVisibility(i10);
            }
        }
    }

    public abstract void c(boolean z10);

    public void d(AlertDialog.Builder builder) {
    }

    @Override // android.content.DialogInterface.OnClickListener
    public final void onClick(DialogInterface dialogInterface, int i10) {
        this.f3600h = i10;
    }

    @Override // android.app.DialogFragment, android.app.Fragment
    public void onCreate(@Nullable Bundle bundle) {
        super.onCreate(bundle);
        ComponentCallbacks2 targetFragment = getTargetFragment();
        if (!(targetFragment instanceof b)) {
            throw new IllegalStateException("Target fragment must implement TargetFragment interface");
        }
        b bVar = (b) targetFragment;
        String string = getArguments().getString("key");
        if (bundle != null) {
            this.f3594b = bundle.getCharSequence("PreferenceDialogFragment.title");
            this.f3595c = bundle.getCharSequence("PreferenceDialogFragment.positiveText");
            this.f3596d = bundle.getCharSequence("PreferenceDialogFragment.negativeText");
            this.f3597e = bundle.getCharSequence("PreferenceDialogFragment.message");
            this.f3598f = bundle.getInt("PreferenceDialogFragment.layout", 0);
            Bitmap bitmap = (Bitmap) bundle.getParcelable("PreferenceDialogFragment.icon");
            if (bitmap != null) {
                this.f3599g = new BitmapDrawable(getResources(), bitmap);
                return;
            }
            return;
        }
        DialogPreference dialogPreference = (DialogPreference) bVar.findPreference(string);
        this.f3593a = dialogPreference;
        this.f3594b = dialogPreference.getDialogTitle();
        this.f3595c = this.f3593a.getPositiveButtonText();
        this.f3596d = this.f3593a.getNegativeButtonText();
        this.f3597e = this.f3593a.getDialogMessage();
        DialogPreference dialogPreference2 = this.f3593a;
        this.f3598f = dialogPreference2.f3547t0;
        Drawable dialogIcon = dialogPreference2.getDialogIcon();
        if (dialogIcon == null || (dialogIcon instanceof BitmapDrawable)) {
            this.f3599g = (BitmapDrawable) dialogIcon;
            return;
        }
        Bitmap bitmapCreateBitmap = Bitmap.createBitmap(dialogIcon.getIntrinsicWidth(), dialogIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmapCreateBitmap);
        dialogIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        dialogIcon.draw(canvas);
        this.f3599g = new BitmapDrawable(getResources(), bitmapCreateBitmap);
    }

    @Override // android.app.DialogFragment
    @NonNull
    public Dialog onCreateDialog(@Nullable Bundle bundle) {
        Activity activity = getActivity();
        this.f3600h = -2;
        AlertDialog.Builder negativeButton = new AlertDialog.Builder(activity).setTitle(this.f3594b).setIcon(this.f3599g).setPositiveButton(this.f3595c, this).setNegativeButton(this.f3596d, this);
        View viewOnCreateDialogView = onCreateDialogView(activity);
        if (viewOnCreateDialogView != null) {
            b(viewOnCreateDialogView);
            negativeButton.setView(viewOnCreateDialogView);
        } else {
            negativeButton.setMessage(this.f3597e);
        }
        d(negativeButton);
        AlertDialog alertDialogCreate = negativeButton.create();
        if (this instanceof EditTextPreferenceDialogFragment) {
            Window window = alertDialogCreate.getWindow();
            if (Build.VERSION.SDK_INT >= 30) {
                t.a(window);
            } else {
                window.setSoftInputMode(5);
            }
        }
        return alertDialogCreate;
    }

    @Nullable
    @Deprecated
    public View onCreateDialogView(@NonNull Context context) {
        int i10 = this.f3598f;
        if (i10 == 0) {
            return null;
        }
        return LayoutInflater.from(context).inflate(i10, (ViewGroup) null);
    }

    @Override // android.app.DialogFragment, android.content.DialogInterface.OnDismissListener
    public final void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
        c(this.f3600h == -1);
    }

    @Override // android.app.DialogFragment, android.app.Fragment
    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putCharSequence("PreferenceDialogFragment.title", this.f3594b);
        bundle.putCharSequence("PreferenceDialogFragment.positiveText", this.f3595c);
        bundle.putCharSequence("PreferenceDialogFragment.negativeText", this.f3596d);
        bundle.putCharSequence("PreferenceDialogFragment.message", this.f3597e);
        bundle.putInt("PreferenceDialogFragment.layout", this.f3598f);
        BitmapDrawable bitmapDrawable = this.f3599g;
        if (bitmapDrawable != null) {
            bundle.putParcelable("PreferenceDialogFragment.icon", bitmapDrawable.getBitmap());
        }
    }
}
