Java Code Examples for androidx.core.view.ViewCompat#getFitsSystemWindows()
The following examples show how to use
androidx.core.view.ViewCompat#getFitsSystemWindows() .
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: SubtitleCollapsingToolbarLayout.java From collapsingtoolbarlayout-subtitle with Apache License 2.0 | 6 votes |
WindowInsetsCompat onWindowInsetChanged(@NonNull final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; if (ViewCompat.getFitsSystemWindows(this)) { // If we're set to fit system windows, keep the insets newInsets = insets; } // If our insets have changed, keep them and invalidate the scroll ranges... if (!ObjectsCompat.equals(lastInsets, newInsets)) { lastInsets = newInsets; requestLayout(); } // Consume the insets. This is done so that child views with fitSystemWindows=true do not // get the default padding functionality from View return insets.consumeSystemWindowInsets(); }
Example 2
Source File: CollapsingTitleBarLayout.java From UIWidget with Apache License 2.0 | 6 votes |
WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; if (ViewCompat.getFitsSystemWindows(this)) { // If we're set to fit system windows, keep the insets newInsets = insets; } // If our insets have changed, keep them and invalidate the scroll ranges... if (!objectEquals(mLastInsets, newInsets)) { mLastInsets = newInsets; requestLayout(); } // Consume the insets. This is done so that child views with fitSystemWindows=true do not // get the default padding functionality from View return insets.consumeSystemWindowInsets(); }
Example 3
Source File: CollapsingToolbarLayout.java From material-components-android with Apache License 2.0 | 6 votes |
WindowInsetsCompat onWindowInsetChanged(@NonNull final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; if (ViewCompat.getFitsSystemWindows(this)) { // If we're set to fit system windows, keep the insets newInsets = insets; } // If our insets have changed, keep them and invalidate the scroll ranges... if (!ObjectsCompat.equals(lastInsets, newInsets)) { lastInsets = newInsets; requestLayout(); } // Consume the insets. This is done so that child views with fitSystemWindows=true do not // get the default padding functionality from View return insets.consumeSystemWindowInsets(); }
Example 4
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 6 votes |
WindowInsetsCompat onWindowInsetChanged(final WindowInsetsCompat insets) { WindowInsetsCompat newInsets = null; if (ViewCompat.getFitsSystemWindows(this)) { // If we're set to fit system windows, keep the insets newInsets = insets; } // If our insets have changed, keep them and trigger a layout... if (!ObjectsCompat.equals(lastInsets, newInsets)) { lastInsets = newInsets; updateWillNotDraw(); requestLayout(); } return insets; }
Example 5
Source File: CustomScrollView.java From Paginize with MIT License | 5 votes |
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); if (!mPaddingSet && ViewCompat.getFitsSystemWindows(this)) { ViewCompat.requestApplyInsets(this); setWillNotDraw(false); mPaddingSet = true; } }
Example 6
Source File: CustomLinearLayout.java From Paginize with MIT License | 5 votes |
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); if (!mPaddingSet && ViewCompat.getFitsSystemWindows(this)) { ViewCompat.requestApplyInsets(this); setWillNotDraw(false); mPaddingSet = true; } }
Example 7
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Whether the first child needs to be offset because it does not want to handle the top window * inset */ private boolean shouldOffsetFirstChild() { if (getChildCount() > 0) { final View firstChild = getChildAt(0); return firstChild.getVisibility() != GONE && !ViewCompat.getFitsSystemWindows(firstChild); } return false; }
Example 8
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Returns the scroll range of all children. * * @return the scroll range in px */ public final int getTotalScrollRange() { if (totalScrollRange != INVALID_SCROLL_RANGE) { return totalScrollRange; } int range = 0; for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int childHeight = child.getMeasuredHeight(); final int flags = lp.scrollFlags; if ((flags & LayoutParams.SCROLL_FLAG_SCROLL) != 0) { // We're set to scroll so add the child's height range += childHeight + lp.topMargin + lp.bottomMargin; if (i == 0 && ViewCompat.getFitsSystemWindows(child)) { // If this is the first child and it wants to handle system windows, we need to make // sure we don't scroll it past the inset range -= getTopInset(); } if ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) != 0) { // For a collapsing scroll, we to take the collapsed height into account. // We also break straight away since later views can't scroll beneath // us range -= ViewCompat.getMinimumHeight(child); break; } } else { // As soon as a view doesn't have the scroll flag, we end the range calculation. // This is because views below can not scroll under a fixed view. break; } } return totalScrollRange = Math.max(0, range); }
Example 9
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 5 votes |
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { // If we need to offset the first child, we need to offset all of them to make space final int topInset = getTopInset(); for (int z = getChildCount() - 1; z >= 0; z--) { ViewCompat.offsetTopAndBottom(getChildAt(z), topInset); } } invalidateScrollRanges(); haveChildWithInterpolator = false; for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); final LayoutParams childLp = (LayoutParams) child.getLayoutParams(); final Interpolator interpolator = childLp.getScrollInterpolator(); if (interpolator != null) { haveChildWithInterpolator = true; break; } } if (statusBarForeground != null) { statusBarForeground.setBounds(0, 0, getWidth(), getTopInset()); } // If the user has set liftable manually, don't set liftable state automatically. if (!liftableOverride) { setLiftableState(liftOnScroll || hasCollapsibleChild()); } }
Example 10
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 5 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); // If we're set to handle system windows but our first child is not, we need to add some // height to ourselves to pad the first child down below the status bar final int heightMode = MeasureSpec.getMode(heightMeasureSpec); if (heightMode != MeasureSpec.EXACTLY && ViewCompat.getFitsSystemWindows(this) && shouldOffsetFirstChild()) { int newHeight = getMeasuredHeight(); switch (heightMode) { case MeasureSpec.AT_MOST: // For AT_MOST, we need to clamp our desired height with the max height newHeight = MathUtils.clamp( getMeasuredHeight() + getTopInset(), 0, MeasureSpec.getSize(heightMeasureSpec)); break; case MeasureSpec.UNSPECIFIED: // For UNSPECIFIED we can use any height so just add the top inset newHeight += getTopInset(); break; default: // fall out } setMeasuredDimension(getMeasuredWidth(), newHeight); } invalidateScrollRanges(); }
Example 11
Source File: BottomSheetBehavior.java From bottomsheetrecycler with Apache License 2.0 | 4 votes |
@Override public boolean onLayoutChild(CoordinatorLayout parent, V child, int layoutDirection) { if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { child.setFitsSystemWindows(true); } // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (shapeThemingEnabled && materialShapeDrawable != null) { ViewCompat.setBackground(child, materialShapeDrawable); } // Set elevation on MaterialShapeDrawable if (materialShapeDrawable != null) { // Use elevation attr if set on bottomsheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); } if (viewRef == null) { // First layout with this behavior. peekHeightMin = parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min); viewRef = new WeakReference<>(child); } if (viewDragHelper == null) { viewDragHelper = ViewDragHelper.create(parent, dragCallback); } int savedTop = child.getTop(); // First let the parent lay it out parent.onLayoutChild(child, layoutDirection); // Offset the bottom sheet parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); fitToContentsOffset = Math.max(0, parentHeight - child.getHeight()); calculateHalfExpandedOffset(); calculateCollapsedOffset(); if (state == STATE_EXPANDED) { ViewCompat.offsetTopAndBottom(child, getExpandedOffset()); } else if (state == STATE_HALF_EXPANDED) { ViewCompat.offsetTopAndBottom(child, halfExpandedOffset); } else if (hideable && state == STATE_HIDDEN) { ViewCompat.offsetTopAndBottom(child, parentHeight); } else if (state == STATE_COLLAPSED) { ViewCompat.offsetTopAndBottom(child, collapsedOffset); } else if (state == STATE_DRAGGING || state == STATE_SETTLING) { ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop()); } //nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child)); return true; }
Example 12
Source File: HeaderScrollingViewBehavior.java From material-components-android with Apache License 2.0 | 4 votes |
@Override protected void layoutChild( @NonNull final CoordinatorLayout parent, @NonNull final View child, final int layoutDirection) { final List<View> dependencies = parent.getDependencies(child); final View header = findFirstDependency(dependencies); if (header != null) { final CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams(); final Rect available = tempRect1; available.set( parent.getPaddingLeft() + lp.leftMargin, header.getBottom() + lp.topMargin, parent.getWidth() - parent.getPaddingRight() - lp.rightMargin, parent.getHeight() + header.getBottom() - parent.getPaddingBottom() - lp.bottomMargin); final WindowInsetsCompat parentInsets = parent.getLastWindowInsets(); if (parentInsets != null && ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { // If we're set to handle insets but this child isn't, then it has been measured as // if there are no insets. We need to lay it out to match horizontally. // Top and bottom and already handled in the logic above available.left += parentInsets.getSystemWindowInsetLeft(); available.right -= parentInsets.getSystemWindowInsetRight(); } final Rect out = tempRect2; GravityCompat.apply( resolveGravity(lp.gravity), child.getMeasuredWidth(), child.getMeasuredHeight(), available, out, layoutDirection); final int overlap = getOverlapPixelsForOffset(header); child.layout(out.left, out.top - overlap, out.right, out.bottom - overlap); verticalLayoutGap = out.top - header.getBottom(); } else { // If we don't have a dependency, let super handle it super.layoutChild(parent, child, layoutDirection); verticalLayoutGap = 0; } }
Example 13
Source File: BottomSheetBehavior.java From material-components-android with Apache License 2.0 | 4 votes |
@Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull V child, int layoutDirection) { if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { child.setFitsSystemWindows(true); } if (viewRef == null) { // First layout with this behavior. peekHeightMin = parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min); setSystemGestureInsets(parent); viewRef = new WeakReference<>(child); // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (shapeThemingEnabled && materialShapeDrawable != null) { ViewCompat.setBackground(child, materialShapeDrawable); } // Set elevation on MaterialShapeDrawable if (materialShapeDrawable != null) { // Use elevation attr if set on bottomsheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); // Update the material shape based on initial state. isShapeExpanded = state == STATE_EXPANDED; materialShapeDrawable.setInterpolation(isShapeExpanded ? 0f : 1f); } updateAccessibilityActions(); if (ViewCompat.getImportantForAccessibility(child) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } } if (viewDragHelper == null) { viewDragHelper = ViewDragHelper.create(parent, dragCallback); } int savedTop = child.getTop(); // First let the parent lay it out parent.onLayoutChild(child, layoutDirection); // Offset the bottom sheet parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); fitToContentsOffset = Math.max(0, parentHeight - child.getHeight()); calculateHalfExpandedOffset(); calculateCollapsedOffset(); if (state == STATE_EXPANDED) { ViewCompat.offsetTopAndBottom(child, getExpandedOffset()); } else if (state == STATE_HALF_EXPANDED) { ViewCompat.offsetTopAndBottom(child, halfExpandedOffset); } else if (hideable && state == STATE_HIDDEN) { ViewCompat.offsetTopAndBottom(child, parentHeight); } else if (state == STATE_COLLAPSED) { ViewCompat.offsetTopAndBottom(child, collapsedOffset); } else if (state == STATE_DRAGGING || state == STATE_SETTLING) { ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop()); } nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child)); return true; }
Example 14
Source File: AppBarLayout.java From material-components-android with Apache License 2.0 | 4 votes |
private int interpolateOffset(@NonNull T layout, final int offset) { final int absOffset = Math.abs(offset); for (int i = 0, z = layout.getChildCount(); i < z; i++) { final View child = layout.getChildAt(i); final AppBarLayout.LayoutParams childLp = (LayoutParams) child.getLayoutParams(); final Interpolator interpolator = childLp.getScrollInterpolator(); if (absOffset >= child.getTop() && absOffset <= child.getBottom()) { if (interpolator != null) { int childScrollableHeight = 0; final int flags = childLp.getScrollFlags(); if ((flags & LayoutParams.SCROLL_FLAG_SCROLL) != 0) { // We're set to scroll so add the child's height plus margin childScrollableHeight += child.getHeight() + childLp.topMargin + childLp.bottomMargin; if ((flags & LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED) != 0) { // For a collapsing scroll, we to take the collapsed height // into account. childScrollableHeight -= ViewCompat.getMinimumHeight(child); } } if (ViewCompat.getFitsSystemWindows(child)) { childScrollableHeight -= layout.getTopInset(); } if (childScrollableHeight > 0) { final int offsetForView = absOffset - child.getTop(); final int interpolatedDiff = Math.round( childScrollableHeight * interpolator.getInterpolation( offsetForView / (float) childScrollableHeight)); return Integer.signum(offset) * (child.getTop() + interpolatedDiff); } } // If we get to here then the view on the offset isn't suitable for interpolated // scrolling. So break out of the loop break; } } return offset; }
Example 15
Source File: CollapsingTitleBarLayout.java From UIWidget with Apache License 2.0 | 4 votes |
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); int topBarInsetAdjustTop = 0; if (mLastInsets != null) { // Shift down any views which are not set to fit system windows final int insetTop = mLastInsets.getSystemWindowInsetTop(); for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); if (ViewCompat.getFitsSystemWindows(child)) { if (child.getTop() < insetTop) { // If the child isn't set to fit system windows but is drawing within // the inset offset it down ViewCompat.offsetTopAndBottom(child, insetTop); } } } View adjustView = mTitleBarDirectChild != null ? mTitleBarDirectChild : mTitleBar; if (ViewCompat.getFitsSystemWindows(adjustView)) { topBarInsetAdjustTop = insetTop; } } // Update the collapsed bounds by getting it's transformed bounds if (mCollapsingTitleEnabled) { // Update the collapsed bounds final int maxOffset = getMaxOffsetForPinChild( mTitleBarDirectChild != null ? mTitleBarDirectChild : mTitleBar); ViewGroupUtils.getDescendantRect(this, mTitleBar, mTmpRect); mTmpRect.top = mTmpRect.top - topBarInsetAdjustTop; Rect rect = mTitleBar.getTitleContainerRect(); int horStart = mTmpRect.top + maxOffset; mCollapsingTextHelper.setCollapsedBounds( mTmpRect.left + rect.left, horStart + rect.top, mTmpRect.left + rect.right, horStart + rect.bottom); // Update the expanded bounds mCollapsingTextHelper.setExpandedBounds( mExpandedMarginStart, mTmpRect.top + mExpandedMarginTop, right - left - mExpandedMarginEnd, bottom - top - mExpandedMarginBottom); // Now recalculate using the new bounds mCollapsingTextHelper.recalculate(); } // Update our child view offset helpers. This needs to be done after the title has been // setup, so that any Toolbars are in their original position for (int i = 0, z = getChildCount(); i < z; i++) { getViewOffsetHelper(getChildAt(i)).onViewLayout(); } // Finally, set our minimum height to enable proper AppBarLayout collapsing if (mTitleBar != null) { if (mCollapsingTitleEnabled && TextUtils.isEmpty(mCollapsingTextHelper.getText())) { // If we do not currently have a title, try and grab it from the Toolbar mCollapsingTextHelper.setText(mTitleBar.getTextView(Gravity.CENTER | Gravity.TOP).getText()); } if (mTitleBarDirectChild == null || mTitleBarDirectChild == this) { setMinimumHeight(getHeightWithMargins(mTitleBar)); } else { setMinimumHeight(getHeightWithMargins(mTitleBarDirectChild)); } mTitleBar.setCenterGravityLeft(getCollapsedTitleGravity() == Gravity.LEFT); } updateScrimVisibility(); }
Example 16
Source File: CollapsingToolbarLayout.java From material-components-android with Apache License 2.0 | 4 votes |
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (lastInsets != null) { // Shift down any views which are not set to fit system windows final int insetTop = lastInsets.getSystemWindowInsetTop(); for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); if (!ViewCompat.getFitsSystemWindows(child)) { if (child.getTop() < insetTop) { // If the child isn't set to fit system windows but is drawing within // the inset offset it down ViewCompat.offsetTopAndBottom(child, insetTop); } } } } // Update our child view offset helpers so that they track the correct layout coordinates for (int i = 0, z = getChildCount(); i < z; i++) { getViewOffsetHelper(getChildAt(i)).onViewLayout(); } // Update the collapsed bounds by getting its transformed bounds if (collapsingTitleEnabled && dummyView != null) { // We only draw the title if the dummy view is being displayed (Toolbar removes // views if there is no space) drawCollapsingTitle = ViewCompat.isAttachedToWindow(dummyView) && dummyView.getVisibility() == VISIBLE; if (drawCollapsingTitle) { final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; // Update the collapsed bounds final int maxOffset = getMaxOffsetForPinChild(toolbarDirectChild != null ? toolbarDirectChild : toolbar); DescendantOffsetUtils.getDescendantRect(this, dummyView, tmpRect); collapsingTextHelper.setCollapsedBounds( tmpRect.left + (isRtl ? toolbar.getTitleMarginEnd() : toolbar.getTitleMarginStart()), tmpRect.top + maxOffset + toolbar.getTitleMarginTop(), tmpRect.right + (isRtl ? toolbar.getTitleMarginStart() : toolbar.getTitleMarginEnd()), tmpRect.bottom + maxOffset - toolbar.getTitleMarginBottom()); // Update the expanded bounds collapsingTextHelper.setExpandedBounds( isRtl ? expandedMarginEnd : expandedMarginStart, tmpRect.top + expandedMarginTop, right - left - (isRtl ? expandedMarginStart : expandedMarginEnd), bottom - top - expandedMarginBottom); // Now recalculate using the new bounds collapsingTextHelper.recalculate(); } } // Set our minimum height to enable proper AppBarLayout collapsing if (toolbar != null) { if (collapsingTitleEnabled && TextUtils.isEmpty(collapsingTextHelper.getText())) { // If we do not currently have a title, try and grab it from the Toolbar setTitle(toolbar.getTitle()); } if (toolbarDirectChild == null || toolbarDirectChild == this) { setMinimumHeight(getHeightWithMargins(toolbar)); } else { setMinimumHeight(getHeightWithMargins(toolbarDirectChild)); } } updateScrimVisibility(); // Apply any view offsets, this should be done at the very end of layout for (int i = 0, z = getChildCount(); i < z; i++) { getViewOffsetHelper(getChildAt(i)).applyOffsets(); } }
Example 17
Source File: BottomSheetBehavior.java From Mysplash with GNU Lesser General Public License v3.0 | 4 votes |
@Override public boolean onLayoutChild( @NonNull CoordinatorLayout parent, @NonNull V child, int layoutDirection) { if (ViewCompat.getFitsSystemWindows(parent) && !ViewCompat.getFitsSystemWindows(child)) { child.setFitsSystemWindows(true); } if (viewRef == null) { // First layout with this behavior. peekHeightMin = parent.getResources().getDimensionPixelSize(R.dimen.design_bottom_sheet_peek_height_min); viewRef = new WeakReference<>(child); // Only set MaterialShapeDrawable as background if shapeTheming is enabled, otherwise will // default to android:background declared in styles or layout. if (shapeThemingEnabled && materialShapeDrawable != null) { ViewCompat.setBackground(child, materialShapeDrawable); } // Set elevation on MaterialShapeDrawable if (materialShapeDrawable != null) { // Use elevation attr if set on bottomsheet; otherwise, use elevation of child view. materialShapeDrawable.setElevation( elevation == -1 ? ViewCompat.getElevation(child) : elevation); // Update the material shape based on initial state. isShapeExpanded = state == STATE_EXPANDED; materialShapeDrawable.setInterpolation(isShapeExpanded ? 0f : 1f); } updateAccessibilityActions(); if (ViewCompat.getImportantForAccessibility(child) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } } if (viewDragHelper == null) { viewDragHelper = ViewDragHelper.create(parent, dragCallback); } int savedTop = child.getTop(); // First let the parent lay it out parent.onLayoutChild(child, layoutDirection); // Offset the bottom sheet parentWidth = parent.getWidth(); parentHeight = parent.getHeight(); fitToContentsOffset = Math.max(0, parentHeight - child.getHeight()); calculateHalfExpandedOffset(); calculateCollapsedOffset(); if (state == STATE_EXPANDED) { ViewCompat.offsetTopAndBottom(child, getExpandedOffset()); } else if (state == STATE_HALF_EXPANDED) { ViewCompat.offsetTopAndBottom(child, halfExpandedOffset); } else if (hideable && state == STATE_HIDDEN) { ViewCompat.offsetTopAndBottom(child, parentHeight); } else if (state == STATE_COLLAPSED) { ViewCompat.offsetTopAndBottom(child, collapsedOffset); } else if (state == STATE_DRAGGING || state == STATE_SETTLING) { ViewCompat.offsetTopAndBottom(child, savedTop - child.getTop()); } nestedScrollingChildRef = new WeakReference<>(findScrollingChild(child)); return true; }
Example 18
Source File: CustomLinearLayout.java From Paginize with MIT License | 4 votes |
private void applyFitsSystemWindowIfNeeded() { if (Build.VERSION.SDK_INT >= 20 && ViewCompat.getFitsSystemWindows(this)) { setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } }
Example 19
Source File: SubtitleCollapsingToolbarLayout.java From collapsingtoolbarlayout-subtitle with Apache License 2.0 | 4 votes |
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (lastInsets != null) { // Shift down any views which are not set to fit system windows final int insetTop = lastInsets.getSystemWindowInsetTop(); for (int i = 0, z = getChildCount(); i < z; i++) { final View child = getChildAt(i); if (!ViewCompat.getFitsSystemWindows(child)) { if (child.getTop() < insetTop) { // If the child isn't set to fit system windows but is drawing within // the inset offset it down ViewCompat.offsetTopAndBottom(child, insetTop); } } } } // Update our child view offset helpers so that they track the correct layout coordinates for (int i = 0, z = getChildCount(); i < z; i++) { getViewOffsetHelper(getChildAt(i)).onViewLayout(); } // Update the collapsed bounds by getting its transformed bounds if (collapsingTitleEnabled && dummyView != null) { // We only draw the title if the dummy view is being displayed (Toolbar removes // views if there is no space) drawCollapsingTitle = ViewCompat.isAttachedToWindow(dummyView) && dummyView.getVisibility() == VISIBLE; if (drawCollapsingTitle) { final boolean isRtl = ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; // Update the collapsed bounds final int maxOffset = getMaxOffsetForPinChild(toolbarDirectChild != null ? toolbarDirectChild : toolbar); DescendantOffsetUtils.getDescendantRect(this, dummyView, tmpRect); collapsingTextHelper.setCollapsedBounds( tmpRect.left + (isRtl ? toolbar.getTitleMarginEnd() : toolbar.getTitleMarginStart()), tmpRect.top + maxOffset + toolbar.getTitleMarginTop(), tmpRect.right + (isRtl ? toolbar.getTitleMarginStart() : toolbar.getTitleMarginEnd()), tmpRect.bottom + maxOffset - toolbar.getTitleMarginBottom()); // Update the expanded bounds collapsingTextHelper.setExpandedBounds( isRtl ? expandedMarginEnd : expandedMarginStart, tmpRect.top + expandedMarginTop, right - left - (isRtl ? expandedMarginStart : expandedMarginEnd), bottom - top - expandedMarginBottom); // Now recalculate using the new bounds collapsingTextHelper.recalculate(); } } // Set our minimum height to enable proper AppBarLayout collapsing if (toolbar != null) { if (collapsingTitleEnabled && TextUtils.isEmpty(collapsingTextHelper.getTitle())) { // If we do not currently have a title, try and grab it from the Toolbar setTitle(toolbar.getTitle()); setSubtitle(toolbar.getSubtitle()); } if (toolbarDirectChild == null || toolbarDirectChild == this) { setMinimumHeight(getHeightWithMargins(toolbar)); } else { setMinimumHeight(getHeightWithMargins(toolbarDirectChild)); } } updateScrimVisibility(); // Apply any view offsets, this should be done at the very end of layout for (int i = 0, z = getChildCount(); i < z; i++) { getViewOffsetHelper(getChildAt(i)).applyOffsets(); } }
Example 20
Source File: CustomScrollView.java From Paginize with MIT License | 4 votes |
private void applyFitsSystemWindowIfNeeded() { if (Build.VERSION.SDK_INT >= 20 && ViewCompat.getFitsSystemWindows(this)) { setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } }