Ejemplo n.º 1
0
 /**
  * µÃµ½¸ùFragment
  *
  * @return
  */
 public Fragment getRootFragment() {
   Fragment fragment = getParentFragment();
   while (fragment.getParentFragment() != null) {
     fragment = fragment.getParentFragment();
   }
   return fragment;
 }
Ejemplo n.º 2
0
  /**
   * 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());
  }
Ejemplo n.º 3
0
 public zzc zzrp() {
   return zza(zzadh.getParentFragment());
 }