本文整理匯總了Java中android.support.v4.app.Fragment.getParentFragment方法的典型用法代碼示例。如果您正苦於以下問題:Java Fragment.getParentFragment方法的具體用法?Java Fragment.getParentFragment怎麽用?Java Fragment.getParentFragment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.app.Fragment
的用法示例。
在下文中一共展示了Fragment.getParentFragment方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFragmentManager
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* get fragment manager
*
* @param fragmentActivity
* @return
*/
private FragmentManager getFragmentManager(FragmentActivity fragmentActivity) {
Fragment fragment = null;
if (fragmentActivity != null && fragmentActivity.getSupportFragmentManager() != null && fragmentActivity.getSupportFragmentManager().getFragments() != null && fragmentActivity.getSupportFragmentManager().getFragments().size() > 0) {
fragment = fragmentActivity.getSupportFragmentManager().getFragments().get(0);
}
if (fragment != null && fragment.getParentFragment() != null) {//必須fragment嵌套fragment才取ChildFragment
return fragment.getChildFragmentManager();
}
return fragmentActivity != null ? fragmentActivity.getSupportFragmentManager() : null;
}
示例2: findContainerById
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private ViewGroup findContainerById(Fragment fragment, int containerId) {
if (fragment.getView() == null) return null;
View container;
Fragment parentFragment = fragment.getParentFragment();
if (parentFragment != null) {
if (parentFragment.getView() != null) {
container = parentFragment.getView().findViewById(containerId);
} else {
container = findContainerById(parentFragment, containerId);
}
} else {
container = mActivity.findViewById(containerId);
}
if (container instanceof ViewGroup) {
return (ViewGroup) container;
}
return null;
}
示例3: getCallbacksOrThrow
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* Return the callbacks for a fragment or throw an exception.
* <p/>
* Inspired by: https://gist.github.com/keyboardr/5455206
*/
@SuppressWarnings("unchecked")
public static <T> T getCallbacksOrThrow(Fragment frag, Class<T> callbacks) {
Fragment parent = frag.getParentFragment();
if (parent != null && callbacks.isInstance(parent)) {
return (T) parent;
} else {
FragmentActivity activity = frag.getActivity();
if (activity != null && callbacks.isInstance(activity)) {
return (T) activity;
}
}
// We haven't actually failed a class cast thanks to the checks above, but that's the
// idiomatic approach for this pattern with fragments.
throw new ClassCastException("This fragment's activity or parent fragment must implement "
+ callbacks.getCanonicalName());
}
示例4: onDestroy
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onDestroy() {
super.onDestroy();
if (mIsStateSaved) {
mIsStateSaved = false;
return;
}
boolean anyParentIsRemoving = false;
Fragment parent = getParentFragment();
while (!anyParentIsRemoving && parent != null) {
anyParentIsRemoving = parent.isRemoving();
parent = parent.getParentFragment();
}
if (isRemoving() || anyParentIsRemoving || getActivity().isFinishing()) {
getMvpDelegate().onDestroy();
if (presenterCallback != null) {
presenterCallback.onDestroyPresenter();
}
}
}
示例5: isDescendant
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* Returns true if the fragment is a descendant of our parent.
*/
private boolean isDescendant(Fragment fragment) {
Fragment root = this.getParentFragmentUsingHint();
while (fragment.getParentFragment() != null) {
if (fragment.getParentFragment() == root) {
return true;
}
fragment = fragment.getParentFragment();
}
return false;
}
示例6: onDestroy
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onDestroy() {
super.onDestroy();
//We leave the screen and respectively all fragments will be destroyed
if (getActivity().isFinishing()) {
getMvpDelegate().onDestroy();
return;
}
// When we rotate device isRemoving() return true for fragment placed in backstack
// http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving
if (mIsStateSaved) {
mIsStateSaved = false;
return;
}
// See https://github.com/Arello-Mobile/Moxy/issues/24
boolean anyParentIsRemoving = false;
Fragment parent = getParentFragment();
while (!anyParentIsRemoving && parent != null) {
anyParentIsRemoving = parent.isRemoving();
parent = parent.getParentFragment();
}
if (isRemoving() || anyParentIsRemoving) {
getMvpDelegate().onDestroy();
}
}
示例7: compatChildFragmentExitAnim
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Nullable
public Animation compatChildFragmentExitAnim(Fragment fragment) {
if ((fragment.getTag() != null && fragment.getTag().startsWith("android:switcher:") && fragment.getUserVisibleHint()) ||
(fragment.getParentFragment() != null && fragment.getParentFragment().isRemoving() && !fragment.isHidden())) {
Animation animation = new Animation() {
};
animation.setDuration(exitAnim.getDuration());
return animation;
}
return null;
}
示例8: onDestroy
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void onDestroy() {
super.onDestroy();
//We leave the screen and respectively all fragments will be destroyed
if (getActivity().isFinishing()) {
getMvpDelegate().onDestroy();
return;
}
// When we rotate device isRemoving() return true for fragment placed in backstack
// http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving
if (mIsStateSaved) {
mIsStateSaved = false;
return;
}
// See https://github.com/Arello-Mobile/Moxy/issues/24
boolean anyParentIsRemoving = false;
if (Build.VERSION.SDK_INT >= 17) {
Fragment parent = getParentFragment();
while (!anyParentIsRemoving && parent != null) {
anyParentIsRemoving = parent.isRemoving();
parent = parent.getParentFragment();
}
}
if (isRemoving() || anyParentIsRemoving) {
getMvpDelegate().onDestroy();
}
}
示例9: getContainerHost
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
/**
* Returns the container host.
*/
private Object getContainerHost() {
Fragment parent = mFragment.getParentFragment();
while (true) {
if (parent == null) break;
int containerViewId = Rigger.getRigger(parent).getContainerViewId();
if (containerViewId > 0) break;
parent = parent.getParentFragment();
}
if (parent == null) {
return mActivity;
}
return parent;
}
示例10: setResult
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public void setResult(int resultCode, Bundle bundle) {
if (mForResultTarget == null) {
throwException(new UnSupportException("class " + this + " is not started by startFragmentForResult() method"));
}
//get the host object.
Object host = mForResultTarget.obj;
if (host == null) {
Fragment startPuppet = mFragment.getParentFragment();
while (true) {
if (startPuppet == null) break;
int containerViewId = Rigger.getRigger(startPuppet).getContainerViewId();
if (containerViewId > 0) break;
startPuppet = startPuppet.getParentFragment();
}
host = startPuppet == null ? mActivity : startPuppet;
}
//invoke the host#onFragmentResult method.
Class<?> clazz = host.getClass();
try {
Method method = clazz.getMethod(RiggerConsts.METHOD_ON_FRAGMENT_RESULT, int.class, int.class, Bundle.class);
method.invoke(host, mForResultTarget.arg1, resultCode, bundle);
} catch (NoSuchMethodException ignored) {
Logger
.w(this, "Not found method " + RiggerConsts.METHOD_ON_FRAGMENT_RESULT + " in class " + clazz.getSimpleName());
} catch (Exception e) {
e.printStackTrace();
}
}
示例11: isAnyParentOfFragmentRemoving
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
private boolean isAnyParentOfFragmentRemoving() {
boolean isAnyParentRemoving = false;
Fragment parent = fragment.getParentFragment();
while (!isAnyParentRemoving && parent != null) {
isAnyParentRemoving = parent.isRemoving();
parent = parent.getParentFragment();
}
return isAnyParentRemoving;
}
示例12: getCustomSettingsObject
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
@Override
public Object getCustomSettingsObject() {
if (globalSetting) {
return null;
}
ISettingsFragmentParent parent = null;
Fragment p = getParentFragment();
while (p != null && parent == null) {
if (p instanceof ISettingsFragmentParent) {
parent = (ISettingsFragmentParent) p;
} else {
p = p.getParentFragment();
}
}
if (parent == null && getActivity() instanceof ISettingsFragmentParent) {
parent = (ISettingsFragmentParent) getActivity();
}
if (parent == null) {
throw new RuntimeException(
"You need to implement ISettingsFragmentParent in any of the SettingsFragment's parents (either parent fragment or parent activity), if you want to use custom settings and not "
+ "global settings only!");
}
if (parent.getCustomSettingsObject() == null) {
throw new RuntimeException("You need to provide a custom settings object in your ISettingsFragmentParent, if you want to use custom settings and not global settings only!");
}
return parent.getCustomSettingsObject();
}
示例13: holderFragmentCreated
import android.support.v4.app.Fragment; //導入方法依賴的package包/類
void holderFragmentCreated(Fragment holderFragment) {
Fragment parentFragment = holderFragment.getParentFragment();
if (parentFragment != null) {
mNotCommittedFragmentHolders.remove(parentFragment);
parentFragment.getFragmentManager().unregisterFragmentLifecycleCallbacks(
mParentDestroyedCallback);
} else {
mNotCommittedActivityHolders.remove(holderFragment.getActivity());
}
}