Search in sources :

Example 11 with WindowInsets

use of android.view.WindowInsets in project android_frameworks_base by ResurrectionRemix.

the class ActionBarOverlayLayout method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    pullChildren();
    int maxHeight = 0;
    int maxWidth = 0;
    int childState = 0;
    int topInset = 0;
    int bottomInset = 0;
    measureChildWithMargins(mActionBarTop, widthMeasureSpec, 0, heightMeasureSpec, 0);
    LayoutParams lp = (LayoutParams) mActionBarTop.getLayoutParams();
    maxWidth = Math.max(maxWidth, mActionBarTop.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
    maxHeight = Math.max(maxHeight, mActionBarTop.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
    childState = combineMeasuredStates(childState, mActionBarTop.getMeasuredState());
    // xlarge screen layout doesn't have bottom action bar.
    if (mActionBarBottom != null) {
        measureChildWithMargins(mActionBarBottom, widthMeasureSpec, 0, heightMeasureSpec, 0);
        lp = (LayoutParams) mActionBarBottom.getLayoutParams();
        maxWidth = Math.max(maxWidth, mActionBarBottom.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
        maxHeight = Math.max(maxHeight, mActionBarBottom.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
        childState = combineMeasuredStates(childState, mActionBarBottom.getMeasuredState());
    }
    final int vis = getWindowSystemUiVisibility();
    final boolean stable = (vis & SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0;
    if (stable) {
        // This is the standard space needed for the action bar.  For stable measurement,
        // we can't depend on the size currently reported by it -- this must remain constant.
        topInset = mActionBarHeight;
        if (mHasNonEmbeddedTabs) {
            final View tabs = mActionBarTop.getTabContainer();
            if (tabs != null) {
                // If tabs are not embedded, increase space on top to account for them.
                topInset += mActionBarHeight;
            }
        }
    } else if (mActionBarTop.getVisibility() != GONE) {
        // This is the space needed on top of the window for all of the action bar
        // and tabs.
        topInset = mActionBarTop.getMeasuredHeight();
    }
    if (mDecorToolbar.isSplit()) {
        // If action bar is split, adjust bottom insets for it.
        if (mActionBarBottom != null) {
            if (stable) {
                bottomInset = mActionBarHeight;
            } else {
                bottomInset = mActionBarBottom.getMeasuredHeight();
            }
        }
    }
    // If the window has not requested system UI layout flags, we need to
    // make sure its content is not being covered by system UI...  though it
    // will still be covered by the action bar if they have requested it to
    // overlay.
    mContentInsets.set(mBaseContentInsets);
    mInnerInsets.set(mBaseInnerInsets);
    if (!mOverlayMode && !stable) {
        mContentInsets.top += topInset;
        mContentInsets.bottom += bottomInset;
    } else {
        mInnerInsets.top += topInset;
        mInnerInsets.bottom += bottomInset;
    }
    applyInsets(mContent, mContentInsets, true, true, true, true);
    if (!mLastInnerInsets.equals(mInnerInsets)) {
        // If the inner insets have changed, we need to dispatch this down to
        // the app's fitSystemWindows().  We do this before measuring the content
        // view to keep the same semantics as the normal fitSystemWindows() call.
        mLastInnerInsets.set(mInnerInsets);
        mContent.dispatchApplyWindowInsets(new WindowInsets(mInnerInsets));
    }
    measureChildWithMargins(mContent, widthMeasureSpec, 0, heightMeasureSpec, 0);
    lp = (LayoutParams) mContent.getLayoutParams();
    maxWidth = Math.max(maxWidth, mContent.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
    maxHeight = Math.max(maxHeight, mContent.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
    childState = combineMeasuredStates(childState, mContent.getMeasuredState());
    // Account for padding too
    maxWidth += getPaddingLeft() + getPaddingRight();
    maxHeight += getPaddingTop() + getPaddingBottom();
    // Check against our minimum height and width
    maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
    maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
    setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
}
Also used : WindowInsets(android.view.WindowInsets) View(android.view.View)

Example 12 with WindowInsets

use of android.view.WindowInsets in project android_frameworks_base by DirtyUnicorns.

the class ActionBarOverlayLayout method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    pullChildren();
    int maxHeight = 0;
    int maxWidth = 0;
    int childState = 0;
    int topInset = 0;
    int bottomInset = 0;
    measureChildWithMargins(mActionBarTop, widthMeasureSpec, 0, heightMeasureSpec, 0);
    LayoutParams lp = (LayoutParams) mActionBarTop.getLayoutParams();
    maxWidth = Math.max(maxWidth, mActionBarTop.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
    maxHeight = Math.max(maxHeight, mActionBarTop.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
    childState = combineMeasuredStates(childState, mActionBarTop.getMeasuredState());
    // xlarge screen layout doesn't have bottom action bar.
    if (mActionBarBottom != null) {
        measureChildWithMargins(mActionBarBottom, widthMeasureSpec, 0, heightMeasureSpec, 0);
        lp = (LayoutParams) mActionBarBottom.getLayoutParams();
        maxWidth = Math.max(maxWidth, mActionBarBottom.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
        maxHeight = Math.max(maxHeight, mActionBarBottom.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
        childState = combineMeasuredStates(childState, mActionBarBottom.getMeasuredState());
    }
    final int vis = getWindowSystemUiVisibility();
    final boolean stable = (vis & SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0;
    if (stable) {
        // This is the standard space needed for the action bar.  For stable measurement,
        // we can't depend on the size currently reported by it -- this must remain constant.
        topInset = mActionBarHeight;
        if (mHasNonEmbeddedTabs) {
            final View tabs = mActionBarTop.getTabContainer();
            if (tabs != null) {
                // If tabs are not embedded, increase space on top to account for them.
                topInset += mActionBarHeight;
            }
        }
    } else if (mActionBarTop.getVisibility() != GONE) {
        // This is the space needed on top of the window for all of the action bar
        // and tabs.
        topInset = mActionBarTop.getMeasuredHeight();
    }
    if (mDecorToolbar.isSplit()) {
        // If action bar is split, adjust bottom insets for it.
        if (mActionBarBottom != null) {
            if (stable) {
                bottomInset = mActionBarHeight;
            } else {
                bottomInset = mActionBarBottom.getMeasuredHeight();
            }
        }
    }
    // If the window has not requested system UI layout flags, we need to
    // make sure its content is not being covered by system UI...  though it
    // will still be covered by the action bar if they have requested it to
    // overlay.
    mContentInsets.set(mBaseContentInsets);
    mInnerInsets.set(mBaseInnerInsets);
    if (!mOverlayMode && !stable) {
        mContentInsets.top += topInset;
        mContentInsets.bottom += bottomInset;
    } else {
        mInnerInsets.top += topInset;
        mInnerInsets.bottom += bottomInset;
    }
    applyInsets(mContent, mContentInsets, true, true, true, true);
    if (!mLastInnerInsets.equals(mInnerInsets)) {
        // If the inner insets have changed, we need to dispatch this down to
        // the app's fitSystemWindows().  We do this before measuring the content
        // view to keep the same semantics as the normal fitSystemWindows() call.
        mLastInnerInsets.set(mInnerInsets);
        mContent.dispatchApplyWindowInsets(new WindowInsets(mInnerInsets));
    }
    measureChildWithMargins(mContent, widthMeasureSpec, 0, heightMeasureSpec, 0);
    lp = (LayoutParams) mContent.getLayoutParams();
    maxWidth = Math.max(maxWidth, mContent.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
    maxHeight = Math.max(maxHeight, mContent.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
    childState = combineMeasuredStates(childState, mContent.getMeasuredState());
    // Account for padding too
    maxWidth += getPaddingLeft() + getPaddingRight();
    maxHeight += getPaddingTop() + getPaddingBottom();
    // Check against our minimum height and width
    maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
    maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
    setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
}
Also used : WindowInsets(android.view.WindowInsets) View(android.view.View)

Aggregations

WindowInsets (android.view.WindowInsets)12 View (android.view.View)9 TextView (android.widget.TextView)4 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 BindView (butterknife.BindView)3 Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 FrameLayout (android.widget.FrameLayout)2 TargetApi (android.annotation.TargetApi)1 ActivityOptions (android.app.ActivityOptions)1 ColorStateList (android.content.res.ColorStateList)1 NavigationView (android.support.design.widget.NavigationView)1 Fragment (android.support.v4.app.Fragment)1 ActionMenuView (android.support.v7.widget.ActionMenuView)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 DisplayMetrics (android.util.DisplayMetrics)1 MenuItem (android.view.MenuItem)1 CompoundButton (android.widget.CompoundButton)1