Java Code Examples for android.support.v4.app.fragment#getView()
The following examples show how to use
android.support.v4.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: WrappingFragmentStatePagerAdapter.java From wrapping-viewpager with Apache License 2.0 | 6 votes |
/** * @param container View container (instanceof {@link WrappingViewPager})) * @param position Item position * @param object {@link Fragment} */ @Override public void setPrimaryItem(ViewGroup container, int position, Object object) { super.setPrimaryItem(container, position, object); if (!(container instanceof WrappingViewPager)) { throw new UnsupportedOperationException("ViewPager is not a WrappingViewPager"); } Fragment fragment = (Fragment) object; WrappingViewPager pager = (WrappingViewPager) container; if (fragment != null && fragment.getView() != null) { if (position != mCurrentPosition) { mCurrentPosition = position; } pager.onPageChanged(fragment.getView()); } }
Example 2
Source File: Depth.java From Depth with MIT License | 6 votes |
public void onFragmentReady(Fragment fragment) { DepthLogger.log("onFragmentReady "+fragment); if (fragment != null) { final View view = fragment.getView(); if (view != null) { view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { view.getViewTreeObserver().removeOnPreDrawListener(this); if (depthAnimator != null) { depthAnimator.reloadFragmentsState(); } return false; } }); } } }
Example 3
Source File: NavHostFragment.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Find a {@link NavController} given a local {@link Fragment}. * * <p>This method will locate the {@link NavController} associated with this Fragment, * looking first for a {@link NavHostFragment} along the given Fragment's parent chain. * If a {@link NavController} is not found, this method will look for one along this * Fragment's {@link Fragment#getView() view hierarchy} as specified by * {@link Navigation#findNavController(View)}.</p> * * @param fragment the locally scoped Fragment for navigation * @return the locally scoped {@link NavController} for navigating from this {@link Fragment} * @throws IllegalStateException if the given Fragment does not correspond with a * {@link NavHost} or is not within a NavHost. */ @NonNull public static NavController findNavController(@NonNull Fragment fragment) { Fragment findFragment = fragment; while (findFragment != null) { if (findFragment instanceof NavHostFragment) { return ((NavHostFragment) findFragment).getNavController(); } Fragment primaryNavFragment = findFragment.requireFragmentManager() .getPrimaryNavigationFragment(); if (primaryNavFragment instanceof NavHostFragment) { return ((NavHostFragment) primaryNavFragment).getNavController(); } findFragment = findFragment.getParentFragment(); } // Try looking for one associated with the view instead, if applicable View view = fragment.getView(); if (view != null) { return Navigation.findNavController(view); } throw new IllegalStateException("Fragment " + fragment + " does not have a NavController set"); }
Example 4
Source File: ViewClickedEventListener.java From Tracker with MIT License | 5 votes |
/** * 设置Fragment页面中View的事件监听 * @param fragment */ public void setFragmentTracker(Fragment fragment) { View contentView = fragment.getView(); if (contentView != null) { setViewClickedTracker(contentView, fragment); } }
Example 5
Source File: ViewPagerTabFragmentParentFragment.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
private Scrollable getCurrentScrollable() { Fragment fragment = getCurrentFragment(); if (fragment == null) { return null; } View view = fragment.getView(); if (view == null) { return null; } return (Scrollable) view.findViewById(R.id.scroll); }
Example 6
Source File: ViewPagerTabScrollViewActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { mBaseTranslationY = 0; Fragment fragment = getCurrentFragment(); if (fragment == null) { return; } View view = fragment.getView(); if (view == null) { return; } int toolbarHeight = mToolbarView.getHeight(); final ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll); if (scrollState == ScrollState.UP) { if (toolbarHeight < scrollView.getCurrentScrollY()) { hideToolbar(); } else if (scrollView.getCurrentScrollY() < toolbarHeight) { showToolbar(); } } else if (scrollState == ScrollState.DOWN) { if (toolbarHeight < scrollView.getCurrentScrollY()) { showToolbar(); } } }
Example 7
Source File: DepthAnimator.java From Depth with MIT License | 5 votes |
private void afterAnimationEnd(int index) { final Fragment fragmentAnimated = fragmentsState.get(index).getFragment(); final DepthAnimation finishedAnimation = animations.get(index); depth.notifyListenersEnd(finishedAnimation, fragmentAnimated); this.currentIndex = index + 1; DepthLogger.log("afterAnimationEnd "+finishedAnimation.getClass().getCanonicalName()); if(finishedAnimation instanceof ExitAnimation){ if (fragmentAnimated != null) { final View fragmentView = fragmentAnimated.getView(); if (fragmentView != null) { fragmentView.postDelayed(new Runnable() { @Override public void run() { depth.removeFragment(fragmentAnimated); } }, 100); } } } if (currentIndex < animations.size()) { startAnimation(currentIndex); } else { DepthLogger.log("clear"); for (DepthFragmentState depthFragmentState : fragmentsState) { depthFragmentState.clear(); } fragmentsState.clear(); for (DepthAnimation animation : animations) { animation.clear(); } animations.clear(); System.gc(); depth.onAnimationFinished(); } }
Example 8
Source File: FragmentUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 设置背景 * * @param fragment fragment * @param background 背景 */ public static void setBackground(@NonNull Fragment fragment, Drawable background) { View view = fragment.getView(); if (view != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.setBackground(background); } else { view.setBackgroundDrawable(background); } } }
Example 9
Source File: ArrayFragmentPagerAdapter.java From ArrayPagerAdapter with Apache License 2.0 | 5 votes |
@Override public boolean isViewFromObject(View view, Object object) { for (Fragment fragment : fragmentManager.getFragments()) { if (fragment != null) { View v = fragment.getView(); if (v != null && v == view && makeFragmentName(((IdentifiedItem) object).id).equals(fragment.getTag())) { return true; } } } return false; }
Example 10
Source File: SwipeBackFragmentImpl.java From SwipeBackLibrary with Apache License 2.0 | 5 votes |
@Override public void onHiddenChanged(boolean hidden) { super.onHiddenChanged(hidden); if (hidden) { Fragment preFragment = (Fragment) getPreFragment(); if (preFragment != null && preFragment.getView() != null){ preFragment.getView().setVisibility(View.GONE); } } }
Example 11
Source File: StatusView.java From StatusView with Apache License 2.0 | 5 votes |
/** * 在Fragment中的初始化方法 * * @param fragment * @param viewId 使用多状态布局的 ViewId * @return */ public static StatusView init(Fragment fragment, @IdRes int viewId) { View rootView = fragment.getView(); View contentView = null; if (rootView != null) { contentView = rootView.findViewById(viewId); } return init(contentView); }
Example 12
Source File: ViewPagerTabActivity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public Scrollable getCurrentScrollable() { Fragment fragment = getCurrentFragment(); if (fragment == null) { return null; } View view = fragment.getView(); if (view == null) { return null; } return (Scrollable) view.findViewById(R.id.scroll); }
Example 13
Source File: FragmentUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * Set background color for fragment. * * @param fragment The fragment. * @param color The background color. */ public static void setBackgroundColor(@NonNull final Fragment fragment, @ColorInt final int color) { View view = fragment.getView(); if (view != null) { view.setBackgroundColor(color); } }
Example 14
Source File: FragmentUtils.java From TikTok with Apache License 2.0 | 5 votes |
/** * 设置背景资源 * * @param fragment fragment * @param resId 资源Id */ public static void setBackgroundResource(@NonNull Fragment fragment, @DrawableRes int resId) { View view = fragment.getView(); if (view != null) { view.setBackgroundResource(resId); } }
Example 15
Source File: SwipeBackLayout.java From SwipeBackFragment with Apache License 2.0 | 5 votes |
@Override public boolean tryCaptureView(View child, int pointerId) { boolean dragEnable = mHelper.isEdgeTouched(mEdgeFlag, pointerId); if (dragEnable) { if (mHelper.isEdgeTouched(EDGE_LEFT, pointerId)) { mCurrentSwipeOrientation = EDGE_LEFT; } else if (mHelper.isEdgeTouched(EDGE_RIGHT, pointerId)) { mCurrentSwipeOrientation = EDGE_RIGHT; } if (mListeners != null && !mListeners.isEmpty()) { for (OnSwipeListener listener : mListeners) { listener.onEdgeTouch(mCurrentSwipeOrientation); } } if (mPreFragment == null) { if (mFragment != null) { List<Fragment> fragmentList = mFragment.getFragmentManager().getFragments(); if (fragmentList != null && fragmentList.size() > 1) { int index = fragmentList.indexOf(mFragment); for (int i = index - 1; i >= 0; i--) { Fragment fragment = fragmentList.get(i); if (fragment != null && fragment.getView() != null) { fragment.getView().setVisibility(VISIBLE); mPreFragment = fragment; break; } } } } } else { View preView = mPreFragment.getView(); if (preView != null && preView.getVisibility() != VISIBLE) { preView.setVisibility(VISIBLE); } } } return dragEnable; }
Example 16
Source File: ViewPagerTab2Activity.java From Android-ObservableScrollView with Apache License 2.0 | 5 votes |
public Scrollable getCurrentScrollable() { Fragment fragment = getCurrentFragment(); if (fragment == null) { return null; } View view = fragment.getView(); if (view == null) { return null; } return (Scrollable) view.findViewById(R.id.scroll); }
Example 17
Source File: SwipeLayout.java From FragmentRigger with MIT License | 5 votes |
private void computeScrollPreView() { Fragment preFragment = getPreFragment(); if (preFragment == null) { if (mPuppetHost instanceof Activity) { computeScrollActivityView(); } return; } View view = preFragment.getView(); computeScroll(view); }
Example 18
Source File: OpenPagerAdapter.java From OpenPagerAdapter with Apache License 2.0 | 4 votes |
@Override public boolean isViewFromObject(View view, Object object) { Fragment fragment = ((ItemInfo) object).fragment; return fragment.getView() == view; }
Example 19
Source File: ViewDirector.java From hawkular-android-client with Apache License 2.0 | 4 votes |
@NonNull public static ViewDirector of(@NonNull Fragment fragment) { return new ViewDirector(fragment.getView()); }
Example 20
Source File: CanRefreshLayout.java From CanRefresh with Apache License 2.0 | 2 votes |
/** * 是否能上拉 * * @return boolean */ protected boolean canChildScrollDown() { if (mIsCoo) { if (mIsViewPager) { int current = mViewPager.getCurrentItem(); if (current < mViewPager.getChildCount()) { PagerAdapter adapter = mViewPager.getAdapter(); if (adapter instanceof FragmentPagerAdapter) { FragmentPagerAdapter fragmentPagerAdapter = (FragmentPagerAdapter) adapter; Fragment fragment = fragmentPagerAdapter.getItem(current); if (fragment != null) { mScrollView = fragment.getView(); } } else { mScrollView = mViewPager.getChildAt(current); } } } if (mScrollView == null) { return false; } return isDependentOpen || canScrollDown(mScrollView); } return canScrollDown(mContentView); }