use of androidx.activity.OnBackPressedDispatcherOwner in project sesl by OneUIProject.
the class FragmentManager method attachController.
@SuppressWarnings("deprecation")
@SuppressLint("SyntheticAccessor")
void attachController(@NonNull FragmentHostCallback<?> host, @NonNull FragmentContainer container, @Nullable final Fragment parent) {
if (mHost != null)
throw new IllegalStateException("Already attached");
mHost = host;
mContainer = container;
mParent = parent;
// backward compatibility with the deprecated onAttachFragment() APIs
if (mParent != null) {
addFragmentOnAttachListener(new FragmentOnAttachListener() {
@SuppressWarnings("deprecation")
@Override
public void onAttachFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
parent.onAttachFragment(fragment);
}
});
} else if (host instanceof FragmentOnAttachListener) {
addFragmentOnAttachListener((FragmentOnAttachListener) host);
}
if (mParent != null) {
// Since the callback depends on us being the primary navigation fragment,
// update our callback now that we have a parent so that we have the correct
// state by default
updateOnBackPressedCallbackEnabled();
}
// Set up the OnBackPressedCallback
if (host instanceof OnBackPressedDispatcherOwner) {
OnBackPressedDispatcherOwner dispatcherOwner = ((OnBackPressedDispatcherOwner) host);
mOnBackPressedDispatcher = dispatcherOwner.getOnBackPressedDispatcher();
LifecycleOwner owner = parent != null ? parent : dispatcherOwner;
mOnBackPressedDispatcher.addCallback(owner, mOnBackPressedCallback);
}
// Get the FragmentManagerViewModel
if (parent != null) {
mNonConfig = parent.mFragmentManager.getChildNonConfig(parent);
} else if (host instanceof ViewModelStoreOwner) {
ViewModelStore viewModelStore = ((ViewModelStoreOwner) host).getViewModelStore();
mNonConfig = FragmentManagerViewModel.getInstance(viewModelStore);
} else {
mNonConfig = new FragmentManagerViewModel(false);
}
// Ensure that the state is in sync with FragmentManager
mNonConfig.setIsStateSaved(isStateSaved());
mFragmentStore.setNonConfig(mNonConfig);
if (mHost instanceof ActivityResultRegistryOwner) {
ActivityResultRegistry registry = ((ActivityResultRegistryOwner) mHost).getActivityResultRegistry();
String parentId = parent != null ? parent.mWho + ":" : "";
String keyPrefix = "FragmentManager:" + parentId;
mStartActivityForResult = registry.register(keyPrefix + "StartActivityForResult", new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No Activities were started for result for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// result call
if (fragment == null) {
Log.w(TAG, "Activity result delivered for unknown Fragment " + fragmentWho);
return;
}
fragment.onActivityResult(requestCode, result.getResultCode(), result.getData());
}
});
mStartIntentSenderForResult = registry.register(keyPrefix + "StartIntentSenderForResult", new FragmentManager.FragmentIntentSenderContract(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No IntentSenders were started for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// result call
if (fragment == null) {
Log.w(TAG, "Intent Sender result delivered for unknown Fragment " + fragmentWho);
return;
}
fragment.onActivityResult(requestCode, result.getResultCode(), result.getData());
}
});
mRequestPermissions = registry.register(keyPrefix + "RequestPermissions", new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@SuppressLint("SyntheticAccessor")
@Override
public void onActivityResult(Map<String, Boolean> result) {
String[] permissions = result.keySet().toArray(new String[0]);
ArrayList<Boolean> resultValues = new ArrayList<>(result.values());
int[] grantResults = new int[resultValues.size()];
for (int i = 0; i < resultValues.size(); i++) {
grantResults[i] = resultValues.get(i) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED;
}
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No permissions were requested for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// permissions call
if (fragment == null) {
Log.w(TAG, "Permission request result delivered for unknown " + "Fragment " + fragmentWho);
return;
}
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
});
}
}
use of androidx.activity.OnBackPressedDispatcherOwner in project GreenHouse by utsanjan.
the class FragmentManagerImpl method attachController.
/* JADX WARN: Multi-variable type inference failed */
public void attachController(FragmentHostCallback host, FragmentContainer container, Fragment parent) {
if (this.mHost == null) {
this.mHost = host;
this.mContainer = container;
this.mParent = parent;
if (parent != null) {
updateOnBackPressedCallbackEnabled();
}
if (host instanceof OnBackPressedDispatcherOwner) {
OnBackPressedDispatcherOwner dispatcherOwner = (OnBackPressedDispatcherOwner) host;
this.mOnBackPressedDispatcher = dispatcherOwner.getOnBackPressedDispatcher();
LifecycleOwner owner = parent != null ? parent : dispatcherOwner;
this.mOnBackPressedDispatcher.addCallback(owner, this.mOnBackPressedCallback);
}
if (parent != null) {
this.mNonConfig = parent.mFragmentManager.getChildNonConfig(parent);
} else if (host instanceof ViewModelStoreOwner) {
ViewModelStore viewModelStore = ((ViewModelStoreOwner) host).getViewModelStore();
this.mNonConfig = FragmentManagerViewModel.getInstance(viewModelStore);
} else {
this.mNonConfig = new FragmentManagerViewModel(false);
}
} else {
throw new IllegalStateException("Already attached");
}
}
use of androidx.activity.OnBackPressedDispatcherOwner in project sesl-appcompat by OneUIProject.
the class FragmentManager method attachController.
@SuppressWarnings("deprecation")
@SuppressLint("SyntheticAccessor")
void attachController(@NonNull FragmentHostCallback<?> host, @NonNull FragmentContainer container, @Nullable final Fragment parent) {
if (mHost != null)
throw new IllegalStateException("Already attached");
mHost = host;
mContainer = container;
mParent = parent;
// backward compatibility with the deprecated onAttachFragment() APIs
if (mParent != null) {
addFragmentOnAttachListener(new FragmentOnAttachListener() {
@SuppressWarnings("deprecation")
@Override
public void onAttachFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment) {
parent.onAttachFragment(fragment);
}
});
} else if (host instanceof FragmentOnAttachListener) {
addFragmentOnAttachListener((FragmentOnAttachListener) host);
}
if (mParent != null) {
// Since the callback depends on us being the primary navigation fragment,
// update our callback now that we have a parent so that we have the correct
// state by default
updateOnBackPressedCallbackEnabled();
}
// Set up the OnBackPressedCallback
if (host instanceof OnBackPressedDispatcherOwner) {
OnBackPressedDispatcherOwner dispatcherOwner = ((OnBackPressedDispatcherOwner) host);
mOnBackPressedDispatcher = dispatcherOwner.getOnBackPressedDispatcher();
LifecycleOwner owner = parent != null ? parent : dispatcherOwner;
mOnBackPressedDispatcher.addCallback(owner, mOnBackPressedCallback);
}
// Get the FragmentManagerViewModel
if (parent != null) {
mNonConfig = parent.mFragmentManager.getChildNonConfig(parent);
} else if (host instanceof ViewModelStoreOwner) {
ViewModelStore viewModelStore = ((ViewModelStoreOwner) host).getViewModelStore();
mNonConfig = FragmentManagerViewModel.getInstance(viewModelStore);
} else {
mNonConfig = new FragmentManagerViewModel(false);
}
// Ensure that the state is in sync with FragmentManager
mNonConfig.setIsStateSaved(isStateSaved());
mFragmentStore.setNonConfig(mNonConfig);
if (mHost instanceof ActivityResultRegistryOwner) {
ActivityResultRegistry registry = ((ActivityResultRegistryOwner) mHost).getActivityResultRegistry();
String parentId = parent != null ? parent.mWho + ":" : "";
String keyPrefix = "FragmentManager:" + parentId;
mStartActivityForResult = registry.register(keyPrefix + "StartActivityForResult", new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No Activities were started for result for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// result call
if (fragment == null) {
Log.w(TAG, "Activity result delivered for unknown Fragment " + fragmentWho);
return;
}
fragment.onActivityResult(requestCode, result.getResultCode(), result.getData());
}
});
mStartIntentSenderForResult = registry.register(keyPrefix + "StartIntentSenderForResult", new FragmentManager.FragmentIntentSenderContract(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No IntentSenders were started for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// result call
if (fragment == null) {
Log.w(TAG, "Intent Sender result delivered for unknown Fragment " + fragmentWho);
return;
}
fragment.onActivityResult(requestCode, result.getResultCode(), result.getData());
}
});
mRequestPermissions = registry.register(keyPrefix + "RequestPermissions", new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@SuppressLint("SyntheticAccessor")
@Override
public void onActivityResult(Map<String, Boolean> result) {
String[] permissions = result.keySet().toArray(new String[0]);
ArrayList<Boolean> resultValues = new ArrayList<>(result.values());
int[] grantResults = new int[resultValues.size()];
for (int i = 0; i < resultValues.size(); i++) {
grantResults[i] = resultValues.get(i) ? PackageManager.PERMISSION_GRANTED : PackageManager.PERMISSION_DENIED;
}
LaunchedFragmentInfo requestInfo = mLaunchedFragments.pollFirst();
if (requestInfo == null) {
Log.w(TAG, "No permissions were requested for " + this);
return;
}
String fragmentWho = requestInfo.mWho;
int requestCode = requestInfo.mRequestCode;
Fragment fragment = mFragmentStore.findFragmentByWho(fragmentWho);
// permissions call
if (fragment == null) {
Log.w(TAG, "Permission request result delivered for unknown " + "Fragment " + fragmentWho);
return;
}
fragment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
});
}
}
Aggregations