Search in sources :

Example 1 with WindowInsets

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

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 2 with WindowInsets

use of android.view.WindowInsets in project u2020 by JakeWharton.

the class DrawerLayoutCompatApi21 method applyMarginInsets.

public static void applyMarginInsets(ViewGroup.MarginLayoutParams lp, Object insets, int gravity) {
    WindowInsets wi = (WindowInsets) insets;
    if (gravity == Gravity.LEFT) {
        wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
    } else if (gravity == Gravity.RIGHT) {
        wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
    }
    lp.leftMargin = wi.getSystemWindowInsetLeft();
    lp.topMargin = wi.getSystemWindowInsetTop();
    lp.rightMargin = wi.getSystemWindowInsetRight();
    lp.bottomMargin = wi.getSystemWindowInsetBottom();
}
Also used : WindowInsets(android.view.WindowInsets)

Example 3 with WindowInsets

use of android.view.WindowInsets in project u2020 by JakeWharton.

the class DrawerLayoutCompatApi21 method dispatchChildInsets.

public static void dispatchChildInsets(View child, Object insets, int gravity) {
    WindowInsets wi = (WindowInsets) insets;
    if (gravity == Gravity.LEFT) {
        wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
    } else if (gravity == Gravity.RIGHT) {
        wi = wi.replaceSystemWindowInsets(0, wi.getSystemWindowInsetTop(), wi.getSystemWindowInsetRight(), wi.getSystemWindowInsetBottom());
    }
    child.dispatchApplyWindowInsets(wi);
}
Also used : WindowInsets(android.view.WindowInsets)

Example 4 with WindowInsets

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

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 5 with WindowInsets

use of android.view.WindowInsets in project plaid by nickbutcher.

the class HomeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    ButterKnife.bind(this);
    drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    setActionBar(toolbar);
    if (savedInstanceState == null) {
        animateToolbar();
    }
    setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
    dribbblePrefs = DribbblePrefs.get(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() {

        @Override
        public void requestDribbbleAuthorisation(View sharedElement, Source forSource) {
            Intent login = new Intent(HomeActivity.this, DribbbleLogin.class);
            MorphTransform.addExtras(login, ContextCompat.getColor(HomeActivity.this, R.color.background_dark), sharedElement.getHeight() / 2);
            ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElement, getString(R.string.transition_dribbble_login));
            startActivityForResult(login, getAuthSourceRequestCode(forSource), options.toBundle());
        }
    });
    dataManager = new DataManager(this, filtersAdapter) {

        @Override
        public void onDataLoaded(List<? extends PlaidItem> data) {
            adapter.addAndResort(data);
            checkEmptyState();
        }
    };
    adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
    grid.setAdapter(adapter);
    layoutManager = new GridLayoutManager(this, columns);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            return adapter.getItemColumnSpan(position);
        }
    });
    grid.setLayoutManager(layoutManager);
    grid.addOnScrollListener(toolbarElevation);
    grid.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {

        @Override
        public void onLoadMore() {
            dataManager.loadAllDataSources();
        }
    });
    grid.setHasFixedSize(true);
    grid.addItemDecoration(new GridItemDividerDecoration(adapter.getDividedViewHolderClasses(), this, R.dimen.divider_height, R.color.divider));
    grid.setItemAnimator(new HomeGridItemAnimator());
    // drawer layout treats fitsSystemWindows specially so we have to handle insets ourselves
    drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // inset the toolbar down by the status bar height
            ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
            lpToolbar.topMargin += insets.getSystemWindowInsetTop();
            lpToolbar.leftMargin += insets.getSystemWindowInsetLeft();
            lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
            toolbar.setLayoutParams(lpToolbar);
            // inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
            grid.setPadding(// landscape
            grid.getPaddingLeft() + insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), // landscape
            grid.getPaddingRight() + insets.getSystemWindowInsetRight(), grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());
            // inset the fab for the navbar
            ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
            // portrait
            lpFab.bottomMargin += insets.getSystemWindowInsetBottom();
            // landscape
            lpFab.rightMargin += insets.getSystemWindowInsetRight();
            fab.setLayoutParams(lpFab);
            View postingStub = findViewById(R.id.stub_posting_progress);
            ViewGroup.MarginLayoutParams lpPosting = (ViewGroup.MarginLayoutParams) postingStub.getLayoutParams();
            // portrait
            lpPosting.bottomMargin += insets.getSystemWindowInsetBottom();
            // landscape
            lpPosting.rightMargin += insets.getSystemWindowInsetRight();
            postingStub.setLayoutParams(lpPosting);
            // we place a background behind the status bar to combine with it's semi-transparent
            // color to get the desired appearance.  Set it's height to the status bar height
            View statusBarBackground = findViewById(R.id.status_bar_background);
            FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
            lpStatus.height = insets.getSystemWindowInsetTop();
            statusBarBackground.setLayoutParams(lpStatus);
            // inset the filters list for the status bar / navbar
            // need to set the padding end for landscape case
            final boolean ltr = filtersList.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
            filtersList.setPaddingRelative(filtersList.getPaddingStart(), filtersList.getPaddingTop() + insets.getSystemWindowInsetTop(), filtersList.getPaddingEnd() + (ltr ? insets.getSystemWindowInsetRight() : 0), filtersList.getPaddingBottom() + insets.getSystemWindowInsetBottom());
            // clear this listener so insets aren't re-applied
            drawer.setOnApplyWindowInsetsListener(null);
            return insets.consumeSystemWindowInsets();
        }
    });
    setupTaskDescription();
    filtersList.setAdapter(filtersAdapter);
    filtersList.setItemAnimator(new FilterAdapter.FilterAnimator());
    filtersAdapter.registerFilterChangedCallback(filtersChangedCallbacks);
    dataManager.loadAllDataSources();
    ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(filtersList);
    checkEmptyState();
}
Also used : FilterTouchHelperCallback(io.plaidapp.ui.recyclerview.FilterTouchHelperCallback) Source(io.plaidapp.data.Source) GridItemDividerDecoration(io.plaidapp.ui.recyclerview.GridItemDividerDecoration) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) WindowInsets(android.view.WindowInsets) ActivityOptions(android.app.ActivityOptions) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) DataManager(io.plaidapp.data.DataManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) FrameLayout(android.widget.FrameLayout) InfiniteScrollListener(io.plaidapp.ui.recyclerview.InfiniteScrollListener)

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