Java Code Examples for androidx.fragment.app.Fragment#getView()

The following examples show how to use androidx.fragment.app.Fragment#getView() . 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: FragmentController.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
public boolean popAllFloatingFragments() {
    Fragment f = getCurrentFragment();
    boolean success = false;
    while (fragmentManager.getBackStackEntryCount() > 0 &&
            f.getView() != null &&
            f.getView().getParent() != null &&
            (R.id.floating == ((ViewGroup) f.getView().getParent()).getId()))
    {
        try {
            fragmentManager.popBackStackImmediate();
            f = getCurrentFragment();
            success = true;
        } catch (Exception e) {
            logger.error("An error occurred popping all floating fragments.", e);
            return false;
        }
    }

    return success;
}
 
Example 2
Source File: YouTubePlayerView.java    From android-inline-youtube-view with Apache License 2.0 6 votes vote down vote up
private YouTubeBaseFragment removeCurrentYouTubeFragment() {
    FragmentManager fragmentManager = fragment.getChildFragmentManager();
    Fragment youTubeFragment = fragmentManager.findFragmentByTag(TAG);
    YouTubeBaseFragment youTubeBaseFragment = null;
    if (youTubeFragment instanceof YouTubeBaseFragment) {
        youTubeBaseFragment = (YouTubeBaseFragment) youTubeFragment;
        View fragmentView = youTubeFragment.getView();
        ViewParent parentView = null != fragmentView ? fragmentView.getParent() : null;
        youTubeBaseFragment.release();
        fragmentManager.beginTransaction().remove(youTubeFragment).commitAllowingStateLoss();
        fragmentManager.executePendingTransactions();
        if (parentView instanceof View && ((View) parentView).getId() == R.id.youtubeFragmentContainer) {
            ((View) parentView).setId(0);
        }
    }
    return youTubeBaseFragment;
}
 
Example 3
Source File: ViewPagerTabFragmentParentFragment.java    From UltimateRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(final ObservableScrollState scrollState) {
    if (!mScrolled) {
        // This event can be used only when TouchInterceptionFrameLayout
        // doesn't handle the consecutive events.
        // toolbarAdjustment(scrollState);
        mBaseTranslationY = 0;

        final Fragment fragment = getCurrentFragment();
        if (fragment == null) {
            return;
        }
        View view = fragment.getView();
        if (view == null) {
            return;
        }
        //    toolbarAdjustment(mLastScrollState, view);
    }
}
 
Example 4
Source File: SimpleTask.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
public void execute(final Fragment fragment, @NonNull Bundle args, @NonNull String name) {
    try {
        if (fragment.getView() != null || fragment instanceof FragmentDialogBase)
            run(fragment.getContext(), fragment.getViewLifecycleOwner(), args, name);
    } catch (IllegalStateException ex) {
        Log.e(ex);
    }
}
 
Example 5
Source File: SupportFragmentRefWatcher.java    From DoraemonKit with Apache License 2.0 5 votes vote down vote up
@Override
public void onFragmentViewDestroyed(FragmentManager fm, Fragment fragment) {
  View view = fragment.getView();
  if (view != null) {
    refWatcher.watch(view);
  }
}
 
Example 6
Source File: TaskHelper.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
static boolean isFragmentDestroyed(Fragment fragment) {
  return fragment.isRemoving()
      || fragment.getActivity() == null
      || fragment.isDetached()
      || !fragment.isAdded()
      || fragment.getView() == null;
}
 
Example 7
Source File: ViewPagerTabFragmentParentFragment.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
private Scrollable getCurrentScrollable() {
    Fragment fragment = getCurrentFragment();
    if (fragment == null) {
        return null;
    }
    View view = fragment.getView();
    if (view == null) {
        return null;
    }
    return viewscrollable(view);
}
 
Example 8
Source File: ViewPagerTabFragmentParentFragment.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
private void propagateToolbarState(boolean isShown) {
    final int toolbarHeight = headerBanner.getHeight();
    // Set scrollY for the fragments that are not created yet
    mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight);

    // Set scrollY for the active fragments
    for (int i = 0; i < mPagerAdapter.getCount(); i++) {
        // Skip current item
        if (i == mPager.getCurrentItem()) {
            continue;
        }
        // Skip destroyed or not created item
        Fragment f = mPagerAdapter.getItemAt(i);
        if (f == null) {
            continue;
        }
        View view = f.getView();
        if (view == null) {
            continue;
        }

        if (view.findViewById(R.id.scroll) instanceof UltimateRecyclerView) {
            UltimateRecyclerView listView = (UltimateRecyclerView) viewscrollable(view);
            if (isShown) {
                // Scroll up
                if (0 < listView.getCurrentScrollY()) {
                    // listView.setSelection(0);
                    Log.d(FRAGMENT_TAG, "up");
                }
            } else {
                // Scroll down (to hide padding)
                if (listView.getCurrentScrollY() < toolbarHeight) {
                    //listView.setSelection(1);
                    Log.d(FRAGMENT_TAG, "down");
                }
            }
        }

    }
}
 
Example 9
Source File: CommonUtils.java    From CommonUtils with Apache License 2.0 4 votes vote down vote up
public static boolean isVisible(@NonNull Fragment fragment) {
    View root = fragment.getView();
    return root != null && root.getGlobalVisibleRect(new Rect());
}
 
Example 10
Source File: ViewUtil.java    From AndroidGodEye with Apache License 2.0 4 votes vote down vote up
public static void measureFragmentV4DidDraw(final Fragment fragment, final OnDrawCallback onDrawCallback) {
    View view = fragment.getView();
    if (view != null) {
        measurePageDidDraw(view, onDrawCallback);
    }
}
 
Example 11
Source File: SnackbarUtils.java    From DevUtils with Apache License 2.0 2 votes vote down vote up
/**
 * 获取 SnackbarUtils 对象
 * @param fragment {@link Fragment}
 * @return {@link SnackbarUtils}
 */
public static SnackbarUtils with(final Fragment fragment) {
    return new SnackbarUtils((fragment != null) ? fragment.getView() : null);
}