Example usage for android.support.v4.view WindowInsetsCompat getSystemWindowInsetRight

List of usage examples for android.support.v4.view WindowInsetsCompat getSystemWindowInsetRight

Introduction

In this page you can find the example usage for android.support.v4.view WindowInsetsCompat getSystemWindowInsetRight.

Prototype

public int getSystemWindowInsetRight() 

Source Link

Usage

From source file:android.support.design.internal.ScrimInsetsFrameLayout.java

public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsFrameLayout, defStyleAttr,
            R.style.Widget_Design_ScrimInsetsFrameLayout);
    mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground);
    a.recycle();//from  w w  w  . jav a 2s. c  o m
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == mInsets) {
                mInsets = new Rect();
            }
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            onInsetsChanged(insets);
            setWillNotDraw(!insets.hasSystemWindowInsets() || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:com.ericyl.utils.ui.widget.translucent.ScrimInsetsFrameLayout.java

public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MineScrimInsetsFrameLayout,
            defStyleAttr, R.style.defaultStyle_ScrimInsetsFrameLayout);
    mInsetForeground = a.getDrawable(R.styleable.MineScrimInsetsFrameLayout_insetForeground);
    a.recycle();//from  www.  ja  v  a 2  s  .  c  o  m
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == mInsets) {
                mInsets = new Rect();
            }
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            onInsetsChanged(insets);
            setWillNotDraw(!insets.hasSystemWindowInsets() || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:net.xpece.android.widget.ScrimInsetsNonConsumingSelfPaddingNestedScrollView.java

public ScrimInsetsNonConsumingSelfPaddingNestedScrollView(Context context, AttributeSet attrs,
        int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.ScrimInsetsFrameLayout, defStyleAttr,
            android.support.design.R.style.Widget_Design_ScrimInsetsFrameLayout);
    mInsetForeground = a.getDrawable(android.support.design.R.styleable.ScrimInsetsFrameLayout_insetForeground);
    a.recycle();/* w  ww  .j  a va2  s .c  o m*/
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == mInsets) {
                mInsets = new Rect();
            }
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            onInsetsChanged(insets);
            setWillNotDraw(XpRect.isZero(mInsets) || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsNonConsumingSelfPaddingNestedScrollView.this);
            return insets;
        }
    });
}

From source file:net.xpece.android.widget.ScrimInsetsLinearLayout.java

private void init(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrimInsetsFrameLayout, defStyleAttr,
            R.style.Widget_Design_ScrimInsetsFrameLayout);
    mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsFrameLayout_insetForeground);
    a.recycle();//from  w  ww .j  a  v a  2 s  .  c o m
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == mInsets) {
                mInsets = new Rect();
            }
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            onInsetsChanged(mInsets);
            setWillNotDraw(XpRect.isZero(mInsets) || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsLinearLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:net.xpece.android.widget.ScrimInsetsNonConsumingChildPaddingFrameLayout.java

public ScrimInsetsNonConsumingChildPaddingFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.ScrimInsetsFrameLayout, defStyleAttr,
            android.support.design.R.style.Widget_Design_ScrimInsetsFrameLayout);
    mInsetForeground = a.getDrawable(android.support.design.R.styleable.ScrimInsetsFrameLayout_insetForeground);
    a.recycle();/*from  ww w. ja va  2 s.co m*/
    setWillNotDraw(true); // No need to draw until the insets are adjusted

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == mInsets) {
                mInsets = new Rect();
            }
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
            onInsetsChanged(insets);
            setWillNotDraw(XpRect.isZero(mInsets) || mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsNonConsumingChildPaddingFrameLayout.this);
            return insets;
        }
    });
}

From source file:com.appeaser.sublimenavigationviewlibrary.ScrimInsetsFrameLayout.java

public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mTempRect = new Rect();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnvScrimInsetsFrameLayout, defStyleAttr,
            R.style.SnvScrimInsetsFrameLayout);
    this.mInsetForeground = a.getDrawable(R.styleable.SnvScrimInsetsFrameLayout_snvInsetForeground);
    a.recycle();/*from  w  w w.java2  s. c  om*/
    this.setWillNotDraw(true);
    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (null == ScrimInsetsFrameLayout.this.mInsets) {
                ScrimInsetsFrameLayout.this.mInsets = new Rect();
            }

            ScrimInsetsFrameLayout.this.mInsets.set(insets.getSystemWindowInsetLeft(),
                    insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(),
                    insets.getSystemWindowInsetBottom());
            ScrimInsetsFrameLayout.this.setWillNotDraw(ScrimInsetsFrameLayout.this.mInsets.isEmpty()
                    || ScrimInsetsFrameLayout.this.mInsetForeground == null);
            ViewCompat.postInvalidateOnAnimation(ScrimInsetsFrameLayout.this);
            return insets.consumeSystemWindowInsets();
        }
    });
}

From source file:ooo.oxo.apps.earth.widget.WindowInsetsFrameLayout.java

@TargetApi(21)
private boolean applySystemWindowInsets21(WindowInsetsCompat insets) {
    boolean consumed = false;

    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);

        if (!child.getFitsSystemWindows()) {
            continue;
        }/*  w w  w . j  av  a 2s  .c  om*/

        Rect childInsets = new Rect(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());

        computeInsetsWithGravity(child, childInsets);

        ViewCompat.dispatchApplyWindowInsets(child, insets.replaceSystemWindowInsets(childInsets));

        consumed = true;
    }

    return consumed;
}

From source file:com.google.android.apps.muzei.MainFragment.java

@Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
    // Set up the action bar
    final View actionBarContainer = view.findViewById(R.id.action_bar_container);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        actionBarContainer.setBackground(ScrimUtil.makeCubicGradientScrimDrawable(0x44000000, 8, Gravity.TOP));
    }//from  w w w.j  ava 2  s.com
    final Toolbar toolbar = view.findViewById(R.id.toolbar);
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        activity.setSupportActionBar(toolbar);
        activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
    }

    // Set up the container for the child fragments
    final View container = view.findViewById(R.id.container);
    if (savedInstanceState == null) {
        FirebaseAnalytics.getInstance(getActivity()).setCurrentScreen(getActivity(), "ArtDetail",
                ArtDetailFragment.class.getSimpleName());
        getChildFragmentManager().beginTransaction().replace(R.id.container, new ArtDetailFragment()).commit();
    }

    // Set up the bottom nav
    final BottomNavigationView bottomNavigationView = view.findViewById(R.id.bottom_nav);
    bottomNavigationView
            .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
                    if (getChildFragmentManager().isStateSaved()) {
                        // Can't navigate after the state is saved
                        return false;
                    }
                    switch (item.getItemId()) {
                    case R.id.main_art_details:
                        FirebaseAnalytics.getInstance(getContext()).setCurrentScreen(getActivity(), "ArtDetail",
                                ArtDetailFragment.class.getSimpleName());
                        getChildFragmentManager().beginTransaction()
                                .replace(R.id.container, new ArtDetailFragment())
                                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
                        return true;
                    case R.id.main_choose_source:
                        FirebaseAnalytics.getInstance(getContext()).setCurrentScreen(getActivity(),
                                "ChooseSource", ChooseSourceFragment.class.getSimpleName());
                        getChildFragmentManager().popBackStack("main",
                                FragmentManager.POP_BACK_STACK_INCLUSIVE);
                        getChildFragmentManager().beginTransaction()
                                .replace(R.id.container, new ChooseSourceFragment()).addToBackStack("main")
                                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
                        return true;
                    case R.id.main_effects:
                        FirebaseAnalytics.getInstance(getContext()).setCurrentScreen(getActivity(), "Effects",
                                EffectsFragment.class.getSimpleName());
                        getChildFragmentManager().popBackStack("main",
                                FragmentManager.POP_BACK_STACK_INCLUSIVE);
                        getChildFragmentManager().beginTransaction()
                                .replace(R.id.container, new EffectsFragment()).addToBackStack("main")
                                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
                        return true;
                    default:
                        return false;
                    }
                }
            });
    bottomNavigationView.setOnNavigationItemReselectedListener(
            new BottomNavigationView.OnNavigationItemReselectedListener() {
                @Override
                public void onNavigationItemReselected(@NonNull final MenuItem item) {
                    if (item.getItemId() == R.id.main_art_details) {
                        getActivity().getWindow().getDecorView()
                                .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
                                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN
                                        | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                    }
                }
            });

    // Send the correct window insets to each view
    ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat insets) {
            // Ensure the action bar container gets the appropriate insets
            ViewCompat.dispatchApplyWindowInsets(actionBarContainer,
                    insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(),
                            insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0));
            ViewCompat.dispatchApplyWindowInsets(container, insets.replaceSystemWindowInsets(
                    insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(), 0));
            ViewCompat.dispatchApplyWindowInsets(bottomNavigationView,
                    insets.replaceSystemWindowInsets(insets.getSystemWindowInsetLeft(), 0,
                            insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()));
            return insets;
        }
    });

    // Listen for visibility changes to know when to hide our views
    view.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
        @Override
        public void onSystemUiVisibilityChange(int vis) {
            final boolean visible = (vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) == 0;

            actionBarContainer.setVisibility(View.VISIBLE);
            actionBarContainer.animate().alpha(visible ? 1f : 0f).setDuration(200)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            if (!visible) {
                                actionBarContainer.setVisibility(View.GONE);
                            }
                        }
                    });

            bottomNavigationView.setVisibility(View.VISIBLE);
            bottomNavigationView.animate().alpha(visible ? 1f : 0f).setDuration(200)
                    .withEndAction(new Runnable() {
                        @Override
                        public void run() {
                            if (!visible) {
                                bottomNavigationView.setVisibility(View.GONE);
                            }
                        }
                    });
        }
    });

}

From source file:android.support.design.widget.HeaderScrollingViewBehavior.java

@Override
protected void layoutChild(final CoordinatorLayout parent, 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 = mTempRect1;
        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();
        }//from   w ww.ja  v  a  2 s.co m

        final Rect out = mTempRect2;
        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);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}

From source file:com.huyn.demogroup.bahavior.widget.HeaderScrollingViewBehavior.java

@Override
protected void layoutChild(final CoordinatorLayout parent, 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 = mTempRect1;
        SysoutUtil.sysout("HeaderScrollingViewBehavior", "layoutChild", "header.bottom:" + header.getBottom());
        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();
        }//from   w w  w .jav  a 2  s.co  m

        final Rect out = mTempRect2;
        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);
        mVerticalLayoutGap = out.top - header.getBottom();
    } else {
        // If we don't have a dependency, let super handle it
        super.layoutChild(parent, child, layoutDirection);
        mVerticalLayoutGap = 0;
    }
}