474 lines
19 KiB
Java
474 lines
19 KiB
Java
package androidx.fragment.app;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentSender;
|
|
import android.content.res.Configuration;
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.Window;
|
|
import androidx.activity.ComponentActivity;
|
|
import androidx.activity.OnBackPressedDispatcher;
|
|
import androidx.activity.OnBackPressedDispatcherOwner;
|
|
import androidx.activity.contextaware.OnContextAvailableListener;
|
|
import androidx.activity.result.ActivityResultRegistry;
|
|
import androidx.activity.result.ActivityResultRegistryOwner;
|
|
import androidx.annotation.CallSuper;
|
|
import androidx.annotation.ContentView;
|
|
import androidx.annotation.LayoutRes;
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.core.app.ActivityCompat;
|
|
import androidx.core.app.SharedElementCallback;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import androidx.lifecycle.LifecycleRegistry;
|
|
import androidx.lifecycle.ViewModelStore;
|
|
import androidx.lifecycle.ViewModelStoreOwner;
|
|
import androidx.loader.app.LoaderManager;
|
|
import androidx.savedstate.SavedStateRegistry;
|
|
import java.io.FileDescriptor;
|
|
import java.io.PrintWriter;
|
|
public class FragmentActivity extends ComponentActivity implements ActivityCompat.OnRequestPermissionsResultCallback, ActivityCompat.RequestPermissionsRequestCodeValidator {
|
|
public static final String FRAGMENTS_TAG = "android:support:fragments";
|
|
public boolean mCreated;
|
|
public final LifecycleRegistry mFragmentLifecycleRegistry = new LifecycleRegistry(this);
|
|
public final FragmentController mFragments = FragmentController.createController(new HostCallbacks());
|
|
public boolean mResumed;
|
|
public boolean mStopped = true;
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentActivity$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements SavedStateRegistry.SavedStateProvider {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
@Override // androidx.savedstate.SavedStateRegistry.SavedStateProvider
|
|
@NonNull
|
|
public Bundle saveState() {
|
|
Bundle bundle = new Bundle();
|
|
FragmentActivity.this.markFragmentsCreated();
|
|
FragmentActivity.this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
|
Parcelable saveAllState = FragmentActivity.this.mFragments.saveAllState();
|
|
if (saveAllState != null) {
|
|
bundle.putParcelable("android:support:fragments", saveAllState);
|
|
}
|
|
return bundle;
|
|
}
|
|
}
|
|
|
|
/* renamed from: androidx.fragment.app.FragmentActivity$2 reason: invalid class name */
|
|
public class AnonymousClass2 implements OnContextAvailableListener {
|
|
public AnonymousClass2() {
|
|
}
|
|
|
|
@Override // androidx.activity.contextaware.OnContextAvailableListener
|
|
public void onContextAvailable(@NonNull Context context) {
|
|
FragmentActivity.this.mFragments.attachHost(null);
|
|
Bundle consumeRestoredStateForKey = FragmentActivity.this.getSavedStateRegistry().consumeRestoredStateForKey("android:support:fragments");
|
|
if (consumeRestoredStateForKey != null) {
|
|
FragmentActivity.this.mFragments.restoreSaveState(consumeRestoredStateForKey.getParcelable("android:support:fragments"));
|
|
}
|
|
}
|
|
}
|
|
|
|
public class HostCallbacks extends FragmentHostCallback<FragmentActivity> implements ViewModelStoreOwner, OnBackPressedDispatcherOwner, ActivityResultRegistryOwner, FragmentOnAttachListener {
|
|
public HostCallbacks() {
|
|
super(FragmentActivity.this);
|
|
}
|
|
|
|
@Override // androidx.activity.result.ActivityResultRegistryOwner
|
|
@NonNull
|
|
public ActivityResultRegistry getActivityResultRegistry() {
|
|
return FragmentActivity.this.getActivityResultRegistry();
|
|
}
|
|
|
|
@Override // androidx.lifecycle.LifecycleOwner
|
|
@NonNull
|
|
public Lifecycle getLifecycle() {
|
|
return FragmentActivity.this.mFragmentLifecycleRegistry;
|
|
}
|
|
|
|
@Override // androidx.activity.OnBackPressedDispatcherOwner
|
|
@NonNull
|
|
public OnBackPressedDispatcher getOnBackPressedDispatcher() {
|
|
return FragmentActivity.this.getOnBackPressedDispatcher();
|
|
}
|
|
|
|
@Override // androidx.lifecycle.ViewModelStoreOwner
|
|
@NonNull
|
|
public ViewModelStore getViewModelStore() {
|
|
return FragmentActivity.this.getViewModelStore();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentOnAttachListener
|
|
public void onAttachFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
|
|
FragmentActivity.this.onAttachFragment(fragment);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public void onDump(@NonNull String str, @Nullable FileDescriptor fileDescriptor, @NonNull PrintWriter printWriter, @Nullable String[] strArr) {
|
|
FragmentActivity.this.dump(str, fileDescriptor, printWriter, strArr);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback, androidx.fragment.app.FragmentContainer
|
|
@Nullable
|
|
public View onFindViewById(int i) {
|
|
return FragmentActivity.this.findViewById(i);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public FragmentActivity onGetHost() {
|
|
return FragmentActivity.this;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
@NonNull
|
|
public LayoutInflater onGetLayoutInflater() {
|
|
return FragmentActivity.this.getLayoutInflater().cloneInContext(FragmentActivity.this);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public int onGetWindowAnimations() {
|
|
Window window = FragmentActivity.this.getWindow();
|
|
if (window == null) {
|
|
return 0;
|
|
}
|
|
return window.getAttributes().windowAnimations;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback, androidx.fragment.app.FragmentContainer
|
|
public boolean onHasView() {
|
|
Window window = FragmentActivity.this.getWindow();
|
|
return (window == null || window.peekDecorView() == null) ? false : true;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public boolean onHasWindowAnimations() {
|
|
return FragmentActivity.this.getWindow() != null;
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public boolean onShouldSaveFragmentState(@NonNull Fragment fragment) {
|
|
return !FragmentActivity.this.isFinishing();
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public boolean onShouldShowRequestPermissionRationale(@NonNull String str) {
|
|
return ActivityCompat.shouldShowRequestPermissionRationale(FragmentActivity.this, str);
|
|
}
|
|
|
|
@Override // androidx.fragment.app.FragmentHostCallback
|
|
public void onSupportInvalidateOptionsMenu() {
|
|
FragmentActivity.this.supportInvalidateOptionsMenu();
|
|
}
|
|
}
|
|
|
|
public FragmentActivity() {
|
|
init();
|
|
}
|
|
|
|
@ContentView
|
|
public FragmentActivity(@LayoutRes int i) {
|
|
super(i);
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
getSavedStateRegistry().registerSavedStateProvider("android:support:fragments", new AnonymousClass1());
|
|
addOnContextAvailableListener(new AnonymousClass2());
|
|
}
|
|
|
|
private static boolean markState(FragmentManager fragmentManager, Lifecycle.State state) {
|
|
boolean z2 = false;
|
|
for (Fragment fragment : fragmentManager.getFragments()) {
|
|
if (fragment != null) {
|
|
if (fragment.getHost() != null) {
|
|
z2 |= markState(fragment.getChildFragmentManager(), state);
|
|
}
|
|
FragmentViewLifecycleOwner fragmentViewLifecycleOwner = fragment.mViewLifecycleOwner;
|
|
if (fragmentViewLifecycleOwner != null && fragmentViewLifecycleOwner.getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
|
|
fragment.mViewLifecycleOwner.setCurrentState(state);
|
|
z2 = true;
|
|
}
|
|
if (fragment.mLifecycleRegistry.getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
|
|
fragment.mLifecycleRegistry.setCurrentState(state);
|
|
z2 = true;
|
|
}
|
|
}
|
|
}
|
|
return z2;
|
|
}
|
|
|
|
@Nullable
|
|
public final View dispatchFragmentsOnCreateView(@Nullable View view, @NonNull String str, @NonNull Context context, @NonNull AttributeSet attributeSet) {
|
|
return this.mFragments.onCreateView(view, str, context, attributeSet);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void dump(@NonNull String str, @Nullable FileDescriptor fileDescriptor, @NonNull PrintWriter printWriter, @Nullable String[] strArr) {
|
|
super.dump(str, fileDescriptor, printWriter, strArr);
|
|
printWriter.print(str);
|
|
printWriter.print("Local FragmentActivity ");
|
|
printWriter.print(Integer.toHexString(System.identityHashCode(this)));
|
|
printWriter.println(" State:");
|
|
String str2 = str + " ";
|
|
printWriter.print(str2);
|
|
printWriter.print("mCreated=");
|
|
printWriter.print(this.mCreated);
|
|
printWriter.print(" mResumed=");
|
|
printWriter.print(this.mResumed);
|
|
printWriter.print(" mStopped=");
|
|
printWriter.print(this.mStopped);
|
|
if (getApplication() != null) {
|
|
LoaderManager.getInstance(this).dump(str2, fileDescriptor, printWriter, strArr);
|
|
}
|
|
this.mFragments.getSupportFragmentManager().dump(str, fileDescriptor, printWriter, strArr);
|
|
}
|
|
|
|
@NonNull
|
|
public FragmentManager getSupportFragmentManager() {
|
|
return this.mFragments.getSupportFragmentManager();
|
|
}
|
|
|
|
@NonNull
|
|
@Deprecated
|
|
public LoaderManager getSupportLoaderManager() {
|
|
return LoaderManager.getInstance(this);
|
|
}
|
|
|
|
public void markFragmentsCreated() {
|
|
do {
|
|
} while (markState(getSupportFragmentManager(), Lifecycle.State.CREATED));
|
|
}
|
|
|
|
@Override // androidx.activity.ComponentActivity, android.app.Activity
|
|
@CallSuper
|
|
public void onActivityResult(int i, int i2, @Nullable Intent intent) {
|
|
this.mFragments.noteStateNotSaved();
|
|
super.onActivityResult(i, i2, intent);
|
|
}
|
|
|
|
@MainThread
|
|
@Deprecated
|
|
public void onAttachFragment(@NonNull Fragment fragment) {
|
|
}
|
|
|
|
@Override // android.app.Activity, android.content.ComponentCallbacks
|
|
public void onConfigurationChanged(@NonNull Configuration configuration) {
|
|
super.onConfigurationChanged(configuration);
|
|
this.mFragments.noteStateNotSaved();
|
|
this.mFragments.dispatchConfigurationChanged(configuration);
|
|
}
|
|
|
|
@Override // androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
|
|
public void onCreate(@Nullable Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_CREATE);
|
|
this.mFragments.dispatchCreate();
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.Window.Callback
|
|
public boolean onCreatePanelMenu(int i, @NonNull Menu menu) {
|
|
return i == 0 ? super.onCreatePanelMenu(i, menu) | this.mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()) : super.onCreatePanelMenu(i, menu);
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.LayoutInflater.Factory2
|
|
@Nullable
|
|
public View onCreateView(@Nullable View view, @NonNull String str, @NonNull Context context, @NonNull AttributeSet attributeSet) {
|
|
View dispatchFragmentsOnCreateView = dispatchFragmentsOnCreateView(view, str, context, attributeSet);
|
|
return dispatchFragmentsOnCreateView == null ? super.onCreateView(view, str, context, attributeSet) : dispatchFragmentsOnCreateView;
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.LayoutInflater.Factory
|
|
@Nullable
|
|
public View onCreateView(@NonNull String str, @NonNull Context context, @NonNull AttributeSet attributeSet) {
|
|
View dispatchFragmentsOnCreateView = dispatchFragmentsOnCreateView(null, str, context, attributeSet);
|
|
return dispatchFragmentsOnCreateView == null ? super.onCreateView(str, context, attributeSet) : dispatchFragmentsOnCreateView;
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
this.mFragments.dispatchDestroy();
|
|
this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
|
|
}
|
|
|
|
@Override // android.app.Activity, android.content.ComponentCallbacks
|
|
public void onLowMemory() {
|
|
super.onLowMemory();
|
|
this.mFragments.dispatchLowMemory();
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.Window.Callback
|
|
public boolean onMenuItemSelected(int i, @NonNull MenuItem menuItem) {
|
|
if (super.onMenuItemSelected(i, menuItem)) {
|
|
return true;
|
|
}
|
|
if (i == 0) {
|
|
return this.mFragments.dispatchOptionsItemSelected(menuItem);
|
|
}
|
|
if (i != 6) {
|
|
return false;
|
|
}
|
|
return this.mFragments.dispatchContextItemSelected(menuItem);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
@CallSuper
|
|
public void onMultiWindowModeChanged(boolean z2) {
|
|
this.mFragments.dispatchMultiWindowModeChanged(z2);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
@CallSuper
|
|
public void onNewIntent(@SuppressLint({"UnknownNullness"}) Intent intent) {
|
|
super.onNewIntent(intent);
|
|
this.mFragments.noteStateNotSaved();
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.Window.Callback
|
|
public void onPanelClosed(int i, @NonNull Menu menu) {
|
|
if (i == 0) {
|
|
this.mFragments.dispatchOptionsMenuClosed(menu);
|
|
}
|
|
super.onPanelClosed(i, menu);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onPause() {
|
|
super.onPause();
|
|
this.mResumed = false;
|
|
this.mFragments.dispatchPause();
|
|
this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
@CallSuper
|
|
public void onPictureInPictureModeChanged(boolean z2) {
|
|
this.mFragments.dispatchPictureInPictureModeChanged(z2);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onPostResume() {
|
|
super.onPostResume();
|
|
onResumeFragments();
|
|
}
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
@Deprecated
|
|
public boolean onPrepareOptionsPanel(@Nullable View view, @NonNull Menu menu) {
|
|
return super.onPreparePanel(0, view, menu);
|
|
}
|
|
|
|
@Override // android.app.Activity, android.view.Window.Callback
|
|
public boolean onPreparePanel(int i, @Nullable View view, @NonNull Menu menu) {
|
|
return i == 0 ? onPrepareOptionsPanel(view, menu) | this.mFragments.dispatchPrepareOptionsMenu(menu) : super.onPreparePanel(i, view, menu);
|
|
}
|
|
|
|
@Override // androidx.activity.ComponentActivity, android.app.Activity
|
|
@CallSuper
|
|
public void onRequestPermissionsResult(int i, @NonNull String[] strArr, @NonNull int[] iArr) {
|
|
this.mFragments.noteStateNotSaved();
|
|
super.onRequestPermissionsResult(i, strArr, iArr);
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onResume() {
|
|
super.onResume();
|
|
this.mResumed = true;
|
|
this.mFragments.noteStateNotSaved();
|
|
this.mFragments.execPendingActions();
|
|
}
|
|
|
|
public void onResumeFragments() {
|
|
this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_RESUME);
|
|
this.mFragments.dispatchResume();
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onStart() {
|
|
super.onStart();
|
|
this.mStopped = false;
|
|
if (!this.mCreated) {
|
|
this.mCreated = true;
|
|
this.mFragments.dispatchActivityCreated();
|
|
}
|
|
this.mFragments.noteStateNotSaved();
|
|
this.mFragments.execPendingActions();
|
|
this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
|
this.mFragments.dispatchStart();
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onStateNotSaved() {
|
|
this.mFragments.noteStateNotSaved();
|
|
}
|
|
|
|
@Override // android.app.Activity
|
|
public void onStop() {
|
|
super.onStop();
|
|
this.mStopped = true;
|
|
markFragmentsCreated();
|
|
this.mFragments.dispatchStop();
|
|
this.mFragmentLifecycleRegistry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
|
}
|
|
|
|
public void setEnterSharedElementCallback(@Nullable SharedElementCallback sharedElementCallback) {
|
|
ActivityCompat.setEnterSharedElementCallback(this, sharedElementCallback);
|
|
}
|
|
|
|
public void setExitSharedElementCallback(@Nullable SharedElementCallback sharedElementCallback) {
|
|
ActivityCompat.setExitSharedElementCallback(this, sharedElementCallback);
|
|
}
|
|
|
|
public void startActivityFromFragment(@NonNull Fragment fragment, @SuppressLint({"UnknownNullness"}) Intent intent, int i) {
|
|
startActivityFromFragment(fragment, intent, i, (Bundle) null);
|
|
}
|
|
|
|
public void startActivityFromFragment(@NonNull Fragment fragment, @SuppressLint({"UnknownNullness"}) Intent intent, int i, @Nullable Bundle bundle) {
|
|
if (i == -1) {
|
|
ActivityCompat.startActivityForResult(this, intent, -1, bundle);
|
|
} else {
|
|
fragment.startActivityForResult(intent, i, bundle);
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public void startIntentSenderFromFragment(@NonNull Fragment fragment, @SuppressLint({"UnknownNullness"}) IntentSender intentSender, int i, @Nullable Intent intent, int i2, int i3, int i4, @Nullable Bundle bundle) throws IntentSender.SendIntentException {
|
|
if (i == -1) {
|
|
ActivityCompat.startIntentSenderForResult(this, intentSender, i, intent, i2, i3, i4, bundle);
|
|
} else {
|
|
fragment.startIntentSenderForResult(intentSender, i, intent, i2, i3, i4, bundle);
|
|
}
|
|
}
|
|
|
|
public void supportFinishAfterTransition() {
|
|
ActivityCompat.finishAfterTransition(this);
|
|
}
|
|
|
|
@Deprecated
|
|
public void supportInvalidateOptionsMenu() {
|
|
invalidateOptionsMenu();
|
|
}
|
|
|
|
public void supportPostponeEnterTransition() {
|
|
ActivityCompat.postponeEnterTransition(this);
|
|
}
|
|
|
|
public void supportStartPostponedEnterTransition() {
|
|
ActivityCompat.startPostponedEnterTransition(this);
|
|
}
|
|
|
|
@Override // androidx.core.app.ActivityCompat.RequestPermissionsRequestCodeValidator
|
|
@Deprecated
|
|
public final void validateRequestPermissionsRequestCode(int i) {
|
|
}
|
|
}
|