Example usage for android.view View onApplyWindowInsets

List of usage examples for android.view View onApplyWindowInsets

Introduction

In this page you can find the example usage for android.view View onApplyWindowInsets.

Prototype

public WindowInsets onApplyWindowInsets(WindowInsets insets) 

Source Link

Document

Called when the view should apply WindowInsets according to its internal policy.

Usage

From source file:com.facebook.react.modules.statusbar.StatusBarModule.java

@ReactMethod
public void setTranslucent(final boolean translucent, final Promise res) {
    final Activity activity = getCurrentActivity();
    if (activity == null) {
        res.reject(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
        return;//from www.  j a v  a 2 s  .  c o  m
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        UiThreadUtil.runOnUiThread(new Runnable() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void run() {
                // If the status bar is translucent hook into the window insets calculations
                // and consume all the top insets so no padding will be added under the status bar.
                View decorView = activity.getWindow().getDecorView();
                if (translucent) {
                    decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                        @Override
                        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                            WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                            return defaultInsets.replaceSystemWindowInsets(
                                    defaultInsets.getSystemWindowInsetLeft(), 0,
                                    defaultInsets.getSystemWindowInsetRight(),
                                    defaultInsets.getSystemWindowInsetBottom());
                        }
                    });
                } else {
                    decorView.setOnApplyWindowInsetsListener(null);
                }

                ViewCompat.requestApplyInsets(decorView);
                res.resolve(null);
            }
        });
    }
}

From source file:com.jpventura.xyzreader.ui.ArticleDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }// w  ww.j  a v  a2s.  c om
    setContentView(R.layout.activity_article_detail);

    getLoaderManager().initLoader(0, null, this);

    mPagerAdapter = new MyPagerAdapter(getFragmentManager());
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mPagerAdapter);
    mPager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
            getResources().getDisplayMetrics()));
    mPager.setPageMarginDrawable(new ColorDrawable(0x22000000));

    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrollStateChanged(int state) {
            super.onPageScrollStateChanged(state);

            if (null == mUpButton)
                return;

            mUpButton.animate().alpha((state == ViewPager.SCROLL_STATE_IDLE) ? 1f : 0f).setDuration(300);
        }

        @Override
        public void onPageSelected(int position) {
            if (mCursor != null) {
                mCursor.moveToPosition(position);
            }
            mSelectedItemId = mCursor.getLong(ArticleLoader.Query._ID);
            updateUpButtonPosition();
        }
    });

    mUpButtonContainer = findViewById(R.id.up_container);

    mUpButton = findViewById(R.id.action_up);
    if (null != mUpButton) {
        mUpButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onSupportNavigateUp();
            }
        });
    }

    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && (null != mUpButtonContainer)) {
        mUpButtonContainer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
            public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                view.onApplyWindowInsets(windowInsets);
                mTopInset = windowInsets.getSystemWindowInsetTop();
                mUpButtonContainer.setTranslationY(mTopInset);
                updateUpButtonPosition();
                return windowInsets;
            }
        });
    }

    if (savedInstanceState == null) {
        if (getIntent() != null && getIntent().getData() != null) {
            mStartId = ItemsContract.Items.getItemId(getIntent().getData());
            mSelectedItemId = mStartId;
        }
    }
}