512 lines
18 KiB
Java
512 lines
18 KiB
Java
package androidx.fragment.app;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.app.Activity;
|
|
import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.Window;
|
|
import androidx.annotation.LayoutRes;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.annotation.StyleRes;
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
import androidx.lifecycle.Observer;
|
|
public class DialogFragment extends Fragment implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener {
|
|
private static final String SAVED_BACK_STACK_ID = "android:backStackId";
|
|
private static final String SAVED_CANCELABLE = "android:cancelable";
|
|
private static final String SAVED_DIALOG_STATE_TAG = "android:savedDialogState";
|
|
private static final String SAVED_INTERNAL_DIALOG_SHOWING = "android:dialogShowing";
|
|
private static final String SAVED_SHOWS_DIALOG = "android:showsDialog";
|
|
private static final String SAVED_STYLE = "android:style";
|
|
private static final String SAVED_THEME = "android:theme";
|
|
public static final int STYLE_NORMAL = 0;
|
|
public static final int STYLE_NO_FRAME = 2;
|
|
public static final int STYLE_NO_INPUT = 3;
|
|
public static final int STYLE_NO_TITLE = 1;
|
|
private int mBackStackId = -1;
|
|
private boolean mCancelable = true;
|
|
private boolean mCreatingDialog;
|
|
@Nullable
|
|
private Dialog mDialog;
|
|
private boolean mDialogCreated = false;
|
|
private Runnable mDismissRunnable = new AnonymousClass1();
|
|
private boolean mDismissed;
|
|
private Handler mHandler;
|
|
private Observer<LifecycleOwner> mObserver = new AnonymousClass4();
|
|
private DialogInterface.OnCancelListener mOnCancelListener = new AnonymousClass2();
|
|
private DialogInterface.OnDismissListener mOnDismissListener = new AnonymousClass3();
|
|
private boolean mShownByMe;
|
|
private boolean mShowsDialog = true;
|
|
private int mStyle = 0;
|
|
private int mTheme = 0;
|
|
private boolean mViewDestroyed;
|
|
|
|
/* renamed from: androidx.fragment.app.DialogFragment$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements Runnable {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public void run() {
|
|
DialogFragment.access$100(DialogFragment.this).onDismiss(DialogFragment.access$000(DialogFragment.this));
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.DialogFragment$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements DialogInterface.OnCancelListener {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
@Override // android.content.DialogInterface.OnCancelListener
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public void onCancel(@Nullable DialogInterface dialogInterface) {
|
|
if (DialogFragment.access$000(DialogFragment.this) != null) {
|
|
DialogFragment dialogFragment = DialogFragment.this;
|
|
dialogFragment.onCancel(DialogFragment.access$000(dialogFragment));
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.DialogFragment$3 reason: invalid class name */
|
|
public class AnonymousClass3 implements DialogInterface.OnDismissListener {
|
|
public AnonymousClass3() {
|
|
}
|
|
|
|
@Override // android.content.DialogInterface.OnDismissListener
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public void onDismiss(@Nullable DialogInterface dialogInterface) {
|
|
if (DialogFragment.access$000(DialogFragment.this) != null) {
|
|
DialogFragment dialogFragment = DialogFragment.this;
|
|
dialogFragment.onDismiss(DialogFragment.access$000(dialogFragment));
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.DialogFragment$4 reason: invalid class name */
|
|
public class AnonymousClass4 implements Observer<LifecycleOwner> {
|
|
public AnonymousClass4() {
|
|
}
|
|
|
|
@SuppressLint({"SyntheticAccessor"})
|
|
public void onChanged(LifecycleOwner lifecycleOwner) {
|
|
if (lifecycleOwner != null && DialogFragment.access$200(DialogFragment.this)) {
|
|
View requireView = DialogFragment.this.requireView();
|
|
if (requireView.getParent() != null) {
|
|
throw new IllegalStateException("DialogFragment can not be attached to a container view");
|
|
} else if (DialogFragment.access$000(DialogFragment.this) != null) {
|
|
if (FragmentManager.isLoggingEnabled(3)) {
|
|
Log.d("FragmentManager", "DialogFragment " + this + " setting the content view on " + DialogFragment.access$000(DialogFragment.this));
|
|
}
|
|
DialogFragment.access$000(DialogFragment.this).setContentView(requireView);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.DialogFragment$5 reason: invalid class name */
|
|
public class AnonymousClass5 extends FragmentContainer {
|
|
public final /* synthetic */ FragmentContainer val$fragmentContainer;
|
|
|
|
public AnonymousClass5(FragmentContainer fragmentContainer) {
|
|
this.val$fragmentContainer = fragmentContainer;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentContainer
|
|
@Nullable
|
|
public View onFindViewById(int i) {
|
|
View onFindViewById = DialogFragment.this.onFindViewById(i);
|
|
if (onFindViewById != null) {
|
|
return onFindViewById;
|
|
}
|
|
if (this.val$fragmentContainer.onHasView()) {
|
|
return this.val$fragmentContainer.onFindViewById(i);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentContainer
|
|
public boolean onHasView() {
|
|
return DialogFragment.this.onHasView() || this.val$fragmentContainer.onHasView();
|
|
}
|
|
}
|
|
|
|
public DialogFragment() {
|
|
}
|
|
|
|
public DialogFragment(@LayoutRes int i) {
|
|
super(i);
|
|
}
|
|
|
|
public static /* synthetic */ Dialog access$000(DialogFragment dialogFragment) {
|
|
return dialogFragment.mDialog;
|
|
}
|
|
|
|
public static /* synthetic */ DialogInterface.OnDismissListener access$100(DialogFragment dialogFragment) {
|
|
return dialogFragment.mOnDismissListener;
|
|
}
|
|
|
|
public static /* synthetic */ boolean access$200(DialogFragment dialogFragment) {
|
|
return dialogFragment.mShowsDialog;
|
|
}
|
|
|
|
private void dismissInternal(boolean z2, boolean z3) {
|
|
if (!this.mDismissed) {
|
|
this.mDismissed = true;
|
|
this.mShownByMe = false;
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
dialog.setOnDismissListener(null);
|
|
this.mDialog.dismiss();
|
|
if (!z3) {
|
|
if (Looper.myLooper() == this.mHandler.getLooper()) {
|
|
onDismiss(this.mDialog);
|
|
} else {
|
|
this.mHandler.post(this.mDismissRunnable);
|
|
}
|
|
}
|
|
}
|
|
this.mViewDestroyed = true;
|
|
if (this.mBackStackId >= 0) {
|
|
getParentFragmentManager().popBackStack(this.mBackStackId, 1);
|
|
this.mBackStackId = -1;
|
|
return;
|
|
}
|
|
FragmentTransaction beginTransaction = getParentFragmentManager().beginTransaction();
|
|
beginTransaction.remove(this);
|
|
if (z2) {
|
|
beginTransaction.commitAllowingStateLoss();
|
|
} else {
|
|
beginTransaction.commit();
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: finally extract failed */
|
|
private void prepareDialog(@Nullable Bundle bundle) {
|
|
if (this.mShowsDialog && !this.mDialogCreated) {
|
|
try {
|
|
this.mCreatingDialog = true;
|
|
Dialog onCreateDialog = onCreateDialog(bundle);
|
|
this.mDialog = onCreateDialog;
|
|
if (this.mShowsDialog) {
|
|
setupDialog(onCreateDialog, this.mStyle);
|
|
Context context = getContext();
|
|
if (context instanceof Activity) {
|
|
this.mDialog.setOwnerActivity((Activity) context);
|
|
}
|
|
this.mDialog.setCancelable(this.mCancelable);
|
|
this.mDialog.setOnCancelListener(this.mOnCancelListener);
|
|
this.mDialog.setOnDismissListener(this.mOnDismissListener);
|
|
this.mDialogCreated = true;
|
|
} else {
|
|
this.mDialog = null;
|
|
}
|
|
this.mCreatingDialog = false;
|
|
} catch (Throwable th) {
|
|
this.mCreatingDialog = false;
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@NonNull
|
|
public FragmentContainer createFragmentContainer() {
|
|
return new AnonymousClass5(super.createFragmentContainer());
|
|
}
|
|
|
|
public void dismiss() {
|
|
dismissInternal(false, false);
|
|
}
|
|
|
|
public void dismissAllowingStateLoss() {
|
|
dismissInternal(true, false);
|
|
}
|
|
|
|
@Nullable
|
|
public Dialog getDialog() {
|
|
return this.mDialog;
|
|
}
|
|
|
|
public boolean getShowsDialog() {
|
|
return this.mShowsDialog;
|
|
}
|
|
|
|
@StyleRes
|
|
public int getTheme() {
|
|
return this.mTheme;
|
|
}
|
|
|
|
public boolean isCancelable() {
|
|
return this.mCancelable;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onAttach(@NonNull Context context) {
|
|
super.onAttach(context);
|
|
getViewLifecycleOwnerLiveData().observeForever(this.mObserver);
|
|
if (!this.mShownByMe) {
|
|
this.mDismissed = false;
|
|
}
|
|
}
|
|
|
|
@Override // android.content.DialogInterface.OnCancelListener
|
|
public void onCancel(@NonNull DialogInterface dialogInterface) {
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onCreate(@Nullable Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
this.mHandler = new Handler();
|
|
this.mShowsDialog = this.mContainerId == 0;
|
|
if (bundle != null) {
|
|
this.mStyle = bundle.getInt("android:style", 0);
|
|
this.mTheme = bundle.getInt("android:theme", 0);
|
|
this.mCancelable = bundle.getBoolean("android:cancelable", true);
|
|
this.mShowsDialog = bundle.getBoolean("android:showsDialog", this.mShowsDialog);
|
|
this.mBackStackId = bundle.getInt("android:backStackId", -1);
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
@MainThread
|
|
public Dialog onCreateDialog(@Nullable Bundle bundle) {
|
|
if (FragmentManager.isLoggingEnabled(3)) {
|
|
Log.d("FragmentManager", "onCreateDialog called for DialogFragment " + this);
|
|
}
|
|
return new Dialog(requireContext(), getTheme());
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onDestroyView() {
|
|
super.onDestroyView();
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
this.mViewDestroyed = true;
|
|
dialog.setOnDismissListener(null);
|
|
this.mDialog.dismiss();
|
|
if (!this.mDismissed) {
|
|
onDismiss(this.mDialog);
|
|
}
|
|
this.mDialog = null;
|
|
this.mDialogCreated = false;
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onDetach() {
|
|
super.onDetach();
|
|
if (!this.mShownByMe && !this.mDismissed) {
|
|
this.mDismissed = true;
|
|
}
|
|
getViewLifecycleOwnerLiveData().removeObserver(this.mObserver);
|
|
}
|
|
|
|
@Override // android.content.DialogInterface.OnDismissListener
|
|
public void onDismiss(@NonNull DialogInterface dialogInterface) {
|
|
if (!this.mViewDestroyed) {
|
|
if (FragmentManager.isLoggingEnabled(3)) {
|
|
Log.d("FragmentManager", "onDismiss called for DialogFragment " + this);
|
|
}
|
|
dismissInternal(true, true);
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
public View onFindViewById(int i) {
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
return dialog.findViewById(i);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@NonNull
|
|
public LayoutInflater onGetLayoutInflater(@Nullable Bundle bundle) {
|
|
LayoutInflater onGetLayoutInflater = super.onGetLayoutInflater(bundle);
|
|
if (!this.mShowsDialog || this.mCreatingDialog) {
|
|
if (FragmentManager.isLoggingEnabled(2)) {
|
|
String str = "getting layout inflater for DialogFragment " + this;
|
|
if (!this.mShowsDialog) {
|
|
Log.d("FragmentManager", "mShowsDialog = false: " + str);
|
|
} else {
|
|
Log.d("FragmentManager", "mCreatingDialog = true: " + str);
|
|
}
|
|
}
|
|
return onGetLayoutInflater;
|
|
}
|
|
prepareDialog(bundle);
|
|
if (FragmentManager.isLoggingEnabled(2)) {
|
|
Log.d("FragmentManager", "get layout inflater for DialogFragment " + this + " from dialog context");
|
|
}
|
|
Dialog dialog = this.mDialog;
|
|
return dialog != null ? onGetLayoutInflater.cloneInContext(dialog.getContext()) : onGetLayoutInflater;
|
|
}
|
|
|
|
public boolean onHasView() {
|
|
return this.mDialogCreated;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onSaveInstanceState(@NonNull Bundle bundle) {
|
|
super.onSaveInstanceState(bundle);
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
Bundle onSaveInstanceState = dialog.onSaveInstanceState();
|
|
onSaveInstanceState.putBoolean("android:dialogShowing", false);
|
|
bundle.putBundle("android:savedDialogState", onSaveInstanceState);
|
|
}
|
|
int i = this.mStyle;
|
|
if (i != 0) {
|
|
bundle.putInt("android:style", i);
|
|
}
|
|
int i2 = this.mTheme;
|
|
if (i2 != 0) {
|
|
bundle.putInt("android:theme", i2);
|
|
}
|
|
boolean z2 = this.mCancelable;
|
|
if (!z2) {
|
|
bundle.putBoolean("android:cancelable", z2);
|
|
}
|
|
boolean z3 = this.mShowsDialog;
|
|
if (!z3) {
|
|
bundle.putBoolean("android:showsDialog", z3);
|
|
}
|
|
int i3 = this.mBackStackId;
|
|
if (i3 != -1) {
|
|
bundle.putInt("android:backStackId", i3);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onStart() {
|
|
super.onStart();
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
this.mViewDestroyed = false;
|
|
dialog.show();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onStop() {
|
|
super.onStop();
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
dialog.hide();
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
@MainThread
|
|
public void onViewStateRestored(@Nullable Bundle bundle) {
|
|
Bundle bundle2;
|
|
super.onViewStateRestored(bundle);
|
|
if (this.mDialog != null && bundle != null && (bundle2 = bundle.getBundle("android:savedDialogState")) != null) {
|
|
this.mDialog.onRestoreInstanceState(bundle2);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.fragment.app.Fragment
|
|
public void performCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
|
|
Bundle bundle2;
|
|
super.performCreateView(layoutInflater, viewGroup, bundle);
|
|
if (this.mView == null && this.mDialog != null && bundle != null && (bundle2 = bundle.getBundle("android:savedDialogState")) != null) {
|
|
this.mDialog.onRestoreInstanceState(bundle2);
|
|
}
|
|
}
|
|
|
|
@NonNull
|
|
public final Dialog requireDialog() {
|
|
Dialog dialog = getDialog();
|
|
if (dialog != null) {
|
|
return dialog;
|
|
}
|
|
throw new IllegalStateException("DialogFragment " + this + " does not have a Dialog.");
|
|
}
|
|
|
|
public void setCancelable(boolean z2) {
|
|
this.mCancelable = z2;
|
|
Dialog dialog = this.mDialog;
|
|
if (dialog != null) {
|
|
dialog.setCancelable(z2);
|
|
}
|
|
}
|
|
|
|
public void setShowsDialog(boolean z2) {
|
|
this.mShowsDialog = z2;
|
|
}
|
|
|
|
public void setStyle(int i, @StyleRes int i2) {
|
|
if (FragmentManager.isLoggingEnabled(2)) {
|
|
Log.d("FragmentManager", "Setting style and theme for DialogFragment " + this + " to " + i + ", " + i2);
|
|
}
|
|
this.mStyle = i;
|
|
if (i == 2 || i == 3) {
|
|
this.mTheme = 16973913;
|
|
}
|
|
if (i2 != 0) {
|
|
this.mTheme = i2;
|
|
}
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
public void setupDialog(@NonNull Dialog dialog, int i) {
|
|
if (!(i == 1 || i == 2)) {
|
|
if (i == 3) {
|
|
Window window = dialog.getWindow();
|
|
if (window != null) {
|
|
window.addFlags(24);
|
|
}
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
dialog.requestWindowFeature(1);
|
|
}
|
|
|
|
public int show(@NonNull FragmentTransaction fragmentTransaction, @Nullable String str) {
|
|
this.mDismissed = false;
|
|
this.mShownByMe = true;
|
|
fragmentTransaction.add(this, str);
|
|
this.mViewDestroyed = false;
|
|
int commit = fragmentTransaction.commit();
|
|
this.mBackStackId = commit;
|
|
return commit;
|
|
}
|
|
|
|
public void show(@NonNull FragmentManager fragmentManager, @Nullable String str) {
|
|
this.mDismissed = false;
|
|
this.mShownByMe = true;
|
|
FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
|
|
beginTransaction.add(this, str);
|
|
beginTransaction.commit();
|
|
}
|
|
|
|
public void showNow(@NonNull FragmentManager fragmentManager, @Nullable String str) {
|
|
this.mDismissed = false;
|
|
this.mShownByMe = true;
|
|
FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
|
|
beginTransaction.add(this, str);
|
|
beginTransaction.commitNow();
|
|
}
|
|
}
|