Java Code Examples for androidx.core.view.ViewCompat#isLaidOut()
The following examples show how to use
androidx.core.view.ViewCompat#isLaidOut() .
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: PhoneTabSwitcherLayout.java From ChromeLikeTabSwitcher with Apache License 2.0 | 6 votes |
/** * Shows the tab switcher in an animated manner. * * @param referenceTabIndex * The index of the tab, which is used as a reference, when restoring the positions of * tabs, as an {@link Integer} value or -1, if the positions of tabs should not be * restored * @param referenceTabPosition * The position of tab, which is used as a reference, when restoring the positions of * tabs, in relation to the available space as a {@link Float} value or -1, if the * positions of tabs should not be restored */ private void animateShowSwitcher(final int referenceTabIndex, final float referenceTabPosition) { AbstractItem[] items = calculateInitialItems(referenceTabIndex, referenceTabPosition); AbstractItemIterator iterator = new InitialItemIteratorBuilder(items).create(); AbstractItem item; while ((item = iterator.next()) != null) { if (((TabItem) item).getTab() == getModel().getSelectedTab() || item.isVisible()) { tabViewRecycler.inflate(item); View view = item.getView(); if (!ViewCompat.isLaidOut(view)) { view.getViewTreeObserver().addOnGlobalLayoutListener( new LayoutListenerWrapper(view, createShowSwitcherLayoutListener(item))); } else { animateShowSwitcher(item, createUpdateViewAnimationListener(item)); } } } animateToolbarVisibility(getModel().areToolbarsShown(), toolbarVisibilityAnimationDelay); }
Example 2
Source File: TabLayout.java From a with GNU General Public License v3.0 | 6 votes |
private void animateToTab(int newPosition) { if (newPosition == Tab.INVALID_POSITION) { return; } if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f, true); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); if (startScrollX != targetScrollX) { ensureScrollAnimator(); mScrollAnimator.setIntValues(startScrollX, targetScrollX); mScrollAnimator.start(); } // Now animate the indicator mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION); }
Example 3
Source File: TabLayoutHelper.java From android-tablayouthelper with Apache License 2.0 | 6 votes |
protected void adjustTabMode(int prevScrollX) { if (mAdjustTabModeRunnable != null) { return; } if (prevScrollX < 0) { prevScrollX = mTabLayout.getScrollX(); } if (ViewCompat.isLaidOut(mTabLayout)) { adjustTabModeInternal(mTabLayout, prevScrollX); } else { final int prevScrollX1 = prevScrollX; mAdjustTabModeRunnable = new Runnable() { @Override public void run() { mAdjustTabModeRunnable = null; adjustTabModeInternal(mTabLayout, prevScrollX1); } }; mTabLayout.post(mAdjustTabModeRunnable); } }
Example 4
Source File: HideViewOnScrollAnimation.java From AndroidPreferenceActivity with Apache License 2.0 | 6 votes |
@Override public final void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) { if (ViewCompat.isLaidOut(animatedView)) { boolean isScrollingUp = dy < 0; if (this.scrollingUp == null || this.scrollingUp != isScrollingUp) { this.scrollingUp = isScrollingUp; if (scrollingUp) { onScrollingUp(); notifyOnScrollingUp(animatedView, dy); } else { onScrollingDown(); notifyOnScrollingDown(animatedView, dy); } } } }
Example 5
Source File: Bulletin.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void hide(boolean animated) { if (showing) { showing = false; if (visibleBulletin == this) { visibleBulletin = null; } if (ViewCompat.isLaidOut(layout)) { if (exitRunnable != null) { layout.removeCallbacks(exitRunnable); exitRunnable = null; } if (animated) { final OffsetProvider offsetProvider = offsetProviders.get(containerLayout); layoutTransition.animateExit(layout, layout::onExitTransitionStart, () -> { layout.onExitTransitionEnd(); layout.onHide(); if (containerLayout != null) { containerLayout.removeView(layout); } layout.onDetach(); }, offsetProvider != null ? offsetProvider.getBottomOffset() : 0); return; } } layout.onExitTransitionStart(); layout.onExitTransitionEnd(); layout.onHide(); if (containerLayout != null) { containerLayout.removeView(layout); } layout.onDetach(); } }
Example 6
Source File: AppBarRelativeLayout.java From cathode with Apache License 2.0 | 5 votes |
private void hideScrims() { if (scrimsVisible) { if (ViewCompat.isLaidOut(this) && !isInEditMode()) { animateScrim(0); } else { setScrimAlpha(0); } scrimsVisible = false; } }
Example 7
Source File: AppBarRelativeLayout.java From cathode with Apache License 2.0 | 5 votes |
private void showScrims() { if (!scrimsVisible) { if (ViewCompat.isLaidOut(this) && !isInEditMode()) { animateScrim(255); } else { setScrimAlpha(255); } scrimsVisible = true; } }
Example 8
Source File: Bulletin.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void hide(boolean animated) { if (showing) { showing = false; if (visibleBulletin == this) { visibleBulletin = null; } if (ViewCompat.isLaidOut(layout)) { if (exitRunnable != null) { layout.removeCallbacks(exitRunnable); exitRunnable = null; } if (animated) { final OffsetProvider offsetProvider = offsetProviders.get(containerLayout); layoutTransition.animateExit(layout, layout::onExitTransitionStart, () -> { layout.onExitTransitionEnd(); layout.onHide(); if (containerLayout != null) { containerLayout.removeView(layout); } layout.onDetach(); }, offsetProvider != null ? offsetProvider.getBottomOffset() : 0); return; } } layout.onExitTransitionStart(); layout.onExitTransitionEnd(); layout.onHide(); if (containerLayout != null) { containerLayout.removeView(layout); } layout.onDetach(); } }
Example 9
Source File: Flipper.java From RecyclerViewExtensions with MIT License | 5 votes |
protected void replaceInternal(View outView, View inView, boolean animate) { if (animate && mFlipperAnimator != null && ViewCompat.isLaidOut(outView)) { mFlipperAnimator.animateFlip(outView, inView); } else { if (mFlipperAnimator != null && mFlipperAnimator.isAnimating()) { outView.animate().cancel(); inView.animate().cancel(); } outView.setVisibility(View.GONE); inView.setVisibility(View.VISIBLE); } }
Example 10
Source File: ViewUtils.java From Jockey with Apache License 2.0 | 5 votes |
public static void whenLaidOut(View view, Runnable action) { if (ViewCompat.isLaidOut(view)) { action.run(); } else { view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { view.getViewTreeObserver().removeOnGlobalLayoutListener(this); action.run(); } }); } }
Example 11
Source File: ExpandableBehavior.java From material-components-android with Apache License 2.0 | 5 votes |
@CallSuper @Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull final View child, int layoutDirection) { if (!ViewCompat.isLaidOut(child)) { final ExpandableWidget dep = findExpandableWidget(parent, child); if (dep != null && didStateChange(dep.isExpanded())) { currentState = dep.isExpanded() ? STATE_EXPANDED : STATE_COLLAPSED; @State final int expectedState = currentState; child .getViewTreeObserver() .addOnPreDrawListener( new OnPreDrawListener() { @Override public boolean onPreDraw() { child.getViewTreeObserver().removeOnPreDrawListener(this); // Proceed only if the state did not change while we're waiting for pre-draw. if (currentState == expectedState) { onExpandedStateChange((View) dep, child, dep.isExpanded(), false); } return false; } }); } } return false; }
Example 12
Source File: IndicatorViewController.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Check if the caption view should animate. Only animate the caption view if we're enabled, laid * out, and have a different caption message. * * @param captionView The view that contains text for the caption underneath the text input area * @param captionText The text for the caption view * @return Whether the view should animate when setting the caption */ private boolean shouldAnimateCaptionView( @Nullable TextView captionView, @Nullable final CharSequence captionText) { return ViewCompat.isLaidOut(textInputView) && textInputView.isEnabled() && (captionToShow != captionDisplayed || captionView == null || !TextUtils.equals(captionView.getText(), captionText)); }
Example 13
Source File: TabLayout.java From material-components-android with Apache License 2.0 | 5 votes |
private void animateToTab(int newPosition) { if (newPosition == Tab.INVALID_POSITION) { return; } if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || slidingTabIndicator.childrenNeedLayout()) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f, true); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); if (startScrollX != targetScrollX) { ensureScrollAnimator(); scrollAnimator.setIntValues(startScrollX, targetScrollX); scrollAnimator.start(); } // Now animate the indicator slidingTabIndicator.animateIndicatorToPosition(newPosition, tabIndicatorAnimationDuration); }
Example 14
Source File: BottomAppBar.java From material-components-android with Apache License 2.0 | 5 votes |
@Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull BottomAppBar child, int layoutDirection) { viewRef = new WeakReference<>(child); View dependentView = child.findDependentView(); if (dependentView != null && !ViewCompat.isLaidOut(dependentView)) { // Set the initial position of the FloatingActionButton with the BottomAppBar vertical // offset. CoordinatorLayout.LayoutParams fabLayoutParams = (CoordinatorLayout.LayoutParams) dependentView.getLayoutParams(); fabLayoutParams.anchorGravity = Gravity.CENTER | Gravity.TOP; // Keep track of the original bottom margin for the fab. We will manage the margin if // nothing was set. originalBottomMargin = fabLayoutParams.bottomMargin; if (dependentView instanceof FloatingActionButton) { FloatingActionButton fab = ((FloatingActionButton) dependentView); // Always update the BAB if the fab is laid out. fab.addOnLayoutChangeListener(fabLayoutListener); // Ensure the FAB is correctly linked to this BAB so the animations can run correctly child.addFabAnimationListeners(fab); } // Move the fab to the correct position child.setCutoutState(); } // Now let the CoordinatorLayout lay out the BAB parent.onLayoutChild(child, layoutDirection); return super.onLayoutChild(parent, child, layoutDirection); }
Example 15
Source File: FloatingActionButton.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Return in {@code rect} the bounds of the actual floating action button content in view-local * coordinates. This is defined as anything within any visible shadow. * * @return true if this view actually has been laid out and has a content rect, else false. * @deprecated prefer {@link FloatingActionButton#getMeasuredContentRect} instead, so you don't * need to handle the case where the view isn't laid out. */ @Deprecated public boolean getContentRect(@NonNull Rect rect) { if (ViewCompat.isLaidOut(this)) { rect.set(0, 0, getWidth(), getHeight()); offsetRectWithShadow(rect); return true; } else { return false; } }
Example 16
Source File: ViewUtil.java From TapTargetView with Apache License 2.0 | 4 votes |
/** Returns whether or not the view has been laid out **/ private static boolean isLaidOut(View view) { return ViewCompat.isLaidOut(view) && view.getWidth() > 0 && view.getHeight() > 0; }
Example 17
Source File: FloatingActionButtonImpl.java From material-components-android with Apache License 2.0 | 4 votes |
private boolean shouldAnimateVisibilityChange() { return ViewCompat.isLaidOut(view) && !view.isInEditMode(); }
Example 18
Source File: ExtendedFloatingActionButton.java From material-components-android with Apache License 2.0 | 4 votes |
private boolean shouldAnimateVisibilityChange() { return ViewCompat.isLaidOut(this) && !isInEditMode(); }