Java Code Examples for android.support.v4.app.Fragment#getChildFragmentManager()

The following examples show how to use android.support.v4.app.Fragment#getChildFragmentManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RequestManagerRetriever.java    From giffun with Apache License 2.0 5 votes vote down vote up
public RequestManager get(Fragment fragment) {
    if (fragment.getActivity() == null) {
        throw new IllegalArgumentException("You cannot start a load on a fragment before it is attached");
    }
    if (Util.isOnBackgroundThread()) {
        return get(fragment.getActivity().getApplicationContext());
    } else {
        FragmentManager fm = fragment.getChildFragmentManager();
        return supportFragmentGet(fragment.getActivity(), fm);
    }
}
 
Example 2
Source File: FragmentListTreeDialog.java    From UETool with MIT License 5 votes vote down vote up
private TreeNode createTreeNode(TreeNode rootNode, FragmentManager fragmentManager, boolean showPackageName) {
    for (Fragment fragment : fragmentManager.getFragments()) {
        TreeNode node = new TreeNode(new TreeItem(fragment, showPackageName)).setViewHolder(new TreeItemVH(getContext(), this));
        FragmentManager childManager = fragment.getChildFragmentManager();
        rootNode.addChild(createTreeNode(node, childManager, showPackageName));
    }
    return rootNode;
}
 
Example 3
Source File: FragmentUtil.java    From DeviceInfo with Apache License 2.0 5 votes vote down vote up
public void addTabClildFragment(Fragment fragmentParent, Fragment fragmentChild)
{
    if (fragmentParent != null && fragmentChild != null)
    {
        FragmentManager fragmentManager = fragmentParent.getChildFragmentManager();
        clearBackStackFragmets(fragmentManager);
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.fragment_container, fragmentChild, fragmentChild.getClass().getCanonicalName());
        fragmentTransaction.commit();
    }
}
 
Example 4
Source File: RxPermissionsResult.java    From RxPermissionsResult with Apache License 2.0 5 votes vote down vote up
@Nullable private Fragment getTargetFragment(List<Fragment> fragments) {
  if (fragments == null) return null;

  for (Fragment fragment : fragments) {
    if(fragment != null && fragment.isVisible() && fragment.getClass() == clazz) {
      return fragment;
    } else if (fragment != null && fragment.getChildFragmentManager() != null) {
      List<Fragment> childFragments = fragment.getChildFragmentManager().getFragments();
      Fragment candidate = getTargetFragment(childFragments);
      if (candidate != null) return candidate;
    }
  }

  return null;
}
 
Example 5
Source File: RxPermissionsResult.java    From RxPermissionsResult with Apache License 2.0 5 votes vote down vote up
@Nullable private Fragment getTargetFragment(List<Fragment> fragments) {
  if (fragments == null) return null;

  for (Fragment fragment : fragments) {
    if(fragment != null && fragment.isVisible() && fragment.getClass() == clazz) {
      return fragment;
    } else if (fragment != null && fragment.getChildFragmentManager() != null) {
      List<Fragment> childFragments = fragment.getChildFragmentManager().getFragments();
      Fragment candidate = getTargetFragment(childFragments);
      if (candidate != null) return candidate;
    }
  }

  return null;
}
 
Example 6
Source File: PullToNextFragmentAdapter.java    From Android-PullToNextLayout with Apache License 2.0 5 votes vote down vote up
public PullToNextFragmentAdapter(Fragment fragment, List<Fragment> allList) {
    super(allList);
    if(null  == allList){
        list=new ArrayList<>();
    }
    fm = fragment.getChildFragmentManager();
}
 
Example 7
Source File: FragmentHack.java    From android-task with Apache License 2.0 5 votes vote down vote up
public static FragmentManager getChildFragmentManager(final Fragment fragment) {
  if (Looper.myLooper() == Looper.getMainLooper()) {
    try {
      return fragment.getChildFragmentManager();
    } catch (Exception e) {
      return null;
    }
  } else {

    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<FragmentManager> reference = new AtomicReference<>();

    HANDLER.post(new Runnable() {
      @Override
      public void run() {
        reference.set(getChildFragmentManager(fragment));
        latch.countDown();
      }
    });

    try {
      latch.await(3, TimeUnit.SECONDS);
    } catch (InterruptedException ignored) {
    }

    return reference.get();
  }
}
 
Example 8
Source File: FragmentTransactionUriRequest.java    From WMRouter with Apache License 2.0 4 votes vote down vote up
/**
 * @param fragment 父fragment
 * @param uri      地址
 */
public FragmentTransactionUriRequest(@NonNull Fragment fragment, String uri) {
    super(fragment.getContext(), uri);
    mFragmentManager = fragment.getChildFragmentManager();
}
 
Example 9
Source File: FragmentUtil.java    From DeviceInfo with Apache License 2.0 4 votes vote down vote up
private void pushFragment(final Fragment fragment, final Fragment parentFragment, final int containerId, boolean isAddToBackStack, boolean isJustAdd, final boolean shouldAnimate, final boolean ignorIfCurrent)
    {
        if (fragment == null)
            return;
        // Add the fragment to the 'fragment_container' FrameLayout
        final FragmentManager fragmentManager;// = getSupportFragmentManager();

        if (parentFragment != null)
        {
            fragmentManager = parentFragment.getChildFragmentManager();
        }
        else {
            fragmentManager = mActivity.getSupportFragmentManager();
        }


        // Find current visible fragment
        Fragment fragmentCurrent = fragmentManager.findFragmentById(R.id.fragment_container);

        if (ignorIfCurrent && fragmentCurrent!=null) {
            if (fragment.getClass().getCanonicalName().equalsIgnoreCase(fragmentCurrent.getTag())) {
                return;
            }
        }


        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        if (shouldAnimate) {
//            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, android.R.anim.fade_in, android.R.anim.fade_out);
        } else {
            fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        }

        if (fragmentCurrent != null)
        {
            fragmentTransaction.hide(fragmentCurrent);
        }

        if (isAddToBackStack) {
            fragmentTransaction.addToBackStack(fragment.getClass().getCanonicalName());
        }
        else {

           /* List<Fragment> fragmentList = fragmentManager.getFragments();
            if (fragmentList != null && !fragmentList.isEmpty())
            {
//                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                for (Fragment fragmentM : fragmentList)
                {
                    if (fragmentM != null)
                    {
                        fragmentTransaction.remove(fragmentM);
                    }
                }
//                fragmentTransaction.commit();
            }*/
        }

        if (isJustAdd) {
            fragmentTransaction.add(containerId, fragment, fragment.getClass().getCanonicalName());
        }
        else {
            fragmentTransaction.replace(containerId, fragment, fragment.getClass().getCanonicalName());
        }


        try {
//            fragmentTransaction.commit();
            fragmentTransaction.commitAllowingStateLoss();

            if (!isAddToBackStack) {
//                fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

            }

            Methods.hideKeyboard(mActivity);

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }
 
Example 10
Source File: MainActivity.java    From Sparkplug with Eclipse Public License 1.0 4 votes vote down vote up
public boolean updateFragmentViews(Connection connection) {
    boolean updateOccurred = false;

    FragmentManager fragmentManager = getSupportFragmentManager();
    List<Fragment> fragments = fragmentManager.getFragments();
    if(fragments != null){
        for(Fragment fragment : fragments){
            //Log.d(TAG, "Found Fragment: " + fragment.toString());
            if (fragment instanceof ConnectionFragment) {
                if (fragment.getChildFragmentManager() != null && fragment.getChildFragmentManager().getFragments() != null) {
                    for (Fragment childFragment : fragment.getChildFragmentManager().getFragments()) {
                        //Log.d(TAG, "Found Child Fragment: " + childFragment.toString());
                        if (childFragment instanceof PublishFragment) {

                            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

                            if ((Double) connection.getSparkplugMetrics().get("Analog 1").getValue() != ((PublishFragment) childFragment).getAnalogOne()) {
                                Log.d(TAG, "Setting Analog 1: " + (Double) connection.getSparkplugMetrics().get("Analog 1").getValue());
                                ((PublishFragment) childFragment).setAnalogOne((Double) connection.getSparkplugMetrics().get("Analog 1").getValue());
                                updateOccurred = true;
                            }
                            if ((Double) connection.getSparkplugMetrics().get("Analog 2").getValue() != ((PublishFragment) childFragment).getAnalogTwo()) {
                                Log.d(TAG, "Setting Analog 2: " + (Double) connection.getSparkplugMetrics().get("Analog 2").getValue());
                                ((PublishFragment) childFragment).setAnalogTwo((Double) connection.getSparkplugMetrics().get("Analog 2").getValue());
                                updateOccurred = true;
                            }
                            if ((Double) connection.getSparkplugMetrics().get("Analog 3").getValue() != ((PublishFragment) childFragment).getAnalogThree()) {
                                Log.d(TAG, "Setting Analog 3: " + (Double) connection.getSparkplugMetrics().get("Analog 3").getValue());
                                ((PublishFragment) childFragment).setAnalogThree((Double) connection.getSparkplugMetrics().get("Analog 3").getValue());
                                updateOccurred = true;
                            }
                            if ((Double) connection.getSparkplugMetrics().get("Analog 4").getValue() != ((PublishFragment) childFragment).getAnalogFour()) {
                                Log.d(TAG, "Setting Analog 4: " + (Double) connection.getSparkplugMetrics().get("Analog 4").getValue());
                                ((PublishFragment) childFragment).setAnalogFour((Double) connection.getSparkplugMetrics().get("Analog 4").getValue());
                                updateOccurred = true;
                            }
                            if ((Boolean)connection.getSparkplugMetrics().get("Boolean 1").getValue() != ((PublishFragment) childFragment).getBooleanOne()) {
                                Log.d(TAG, "Setting Boolean 1: " + (Boolean) connection.getSparkplugMetrics().get("Boolean 1").getValue());
                                ((PublishFragment) childFragment).setBooleanOne((Boolean) connection.getSparkplugMetrics().get("Boolean 1").getValue());
                                updateOccurred = true;
                            }
                            if ((Boolean)connection.getSparkplugMetrics().get("Boolean 2").getValue() != ((PublishFragment) childFragment).getBooleanTwo()) {
                                Log.d(TAG, "Setting Boolean 2: " + (Boolean) connection.getSparkplugMetrics().get("Boolean 2").getValue());
                                ((PublishFragment) childFragment).setBooleanTwo((Boolean) connection.getSparkplugMetrics().get("Boolean 2").getValue());
                                updateOccurred = true;
                            }
                            if ((Boolean)connection.getSparkplugMetrics().get("Boolean 3").getValue() != ((PublishFragment) childFragment).getBooleanThree()) {
                                Log.d(TAG, "Setting Boolean 3: " + (Boolean) connection.getSparkplugMetrics().get("Boolean 3").getValue());
                                ((PublishFragment) childFragment).setBooleanThree((Boolean) connection.getSparkplugMetrics().get("Boolean 3").getValue());
                                updateOccurred = true;
                            }
                            if ((Boolean)connection.getSparkplugMetrics().get("Boolean 4").getValue() != ((PublishFragment) childFragment).getBooleanFour()) {
                                Log.d(TAG, "Setting Boolean 4: " + (Boolean) connection.getSparkplugMetrics().get("Boolean 4").getValue());
                                ((PublishFragment) childFragment).setBooleanFour((Boolean) connection.getSparkplugMetrics().get("Boolean 4").getValue());
                                updateOccurred = true;
                            }
                        }
                    }
                }
            }
        }
    }

    return updateOccurred;
}
 
Example 11
Source File: FragmentCompatSupportLib.java    From weex with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public FragmentManager getChildFragmentManager(Fragment fragment) {
  return fragment.getChildFragmentManager();
}
 
Example 12
Source File: FragmentCompatSupportLib.java    From stetho with MIT License 4 votes vote down vote up
@Nullable
@Override
public FragmentManager getChildFragmentManager(Fragment fragment) {
  return fragment.getChildFragmentManager();
}
 
Example 13
Source File: FragmentUtils.java    From MvpRoute with Apache License 2.0 2 votes vote down vote up
/**
 * 对应的fragment  用于开启管理者
 *
 * @param fragment
 * @return
 */
public static FragmentUtils getInstance(Fragment fragment) {
	newInstance();
	fragmentManager = fragment.getChildFragmentManager();
	return instance;
}
 
Example 14
Source File: PagerAdapter.java    From android with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor for <code>PagerAdapter</code>
 *
 * @param fragment The {@link android.support.v4.app.Fragment} to use
 */
public PagerAdapter(Fragment fragment, int titles) {
    super(fragment.getChildFragmentManager());
    mTitles = fragment.getResources().getStringArray(titles);
}
 
Example 15
Source File: PagerAdapter.java    From android with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor for <code>PagerAdapter</code>
 *
 * @param fragment The {@link android.support.v4.app.Fragment} to use
 */
public PagerAdapter(Fragment fragment, String[] titles) {
    super(fragment.getChildFragmentManager());
    mTitles = titles;
}