Example usage for android.widget FrameLayout onApplyWindowInsets

List of usage examples for android.widget FrameLayout onApplyWindowInsets

Introduction

In this page you can find the example usage for android.widget FrameLayout 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.example.android.xyztouristattractions.ui.AttractionsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.topFrameLayout);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mGridViewPager = (GridViewPager) findViewById(R.id.gridViewPager);
    mDotsPageIndicator = (DotsPageIndicator) findViewById(R.id.dotsPageIndicator);
    mAdapter = new AttractionsGridPagerAdapter(this, mAttractions);
    mAdapter.setOnChromeFadeListener(this);
    mGridViewPager.setAdapter(mAdapter);

    topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override/*w  w w . j  av  a 2s.c om*/
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // Call through to super implementation
            insets = topFrameLayout.onApplyWindowInsets(insets);

            boolean round = insets.isRound();

            // Store system window insets regardless of screen shape
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());

            if (round) {
                // On a round screen calculate the square inset to use.
                // Alternatively could use BoxInsetLayout, although calculating
                // the inset ourselves lets us position views outside the center
                // box. For example, slightly lower on the round screen (by giving
                // up some horizontal space).
                mInsets = Utils.calculateBottomInsetsOnRoundDevice(getWindowManager().getDefaultDisplay(),
                        mInsets);

                // Boost the dots indicator up by the bottom inset
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mDotsPageIndicator
                        .getLayoutParams();
                params.bottomMargin = mInsets.bottom;
                mDotsPageIndicator.setLayoutParams(params);
            }

            mAdapter.setInsets(mInsets);
            return insets;
        }
    });

    // Set up the DismissOverlayView
    mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
    mDismissOverlayView.setIntroText(getString(R.string.exit_intro_text));
    mDismissOverlayView.showIntroIfNecessary();
    mGestureDetector = new GestureDetectorCompat(this, new LongPressListener());

    Uri attractionsUri = getIntent().getParcelableExtra(Constants.EXTRA_ATTRACTIONS_URI);
    if (attractionsUri != null) {
        new FetchDataAsyncTask(this).execute(attractionsUri);
        UtilityService.clearNotification(this);
        UtilityService.clearRemoteNotifications(this);
    } else {
        finish();
    }
}

From source file:com.example.android.xyztouristattractions.ui.ShopsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.topFrameLayout);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mGridViewPager = (GridViewPager) findViewById(R.id.gridViewPager);
    mDotsPageIndicator = (DotsPageIndicator) findViewById(R.id.dotsPageIndicator);
    mAdapter = new ShopsGridPagerAdapter(this, mShops);
    mAdapter.setOnChromeFadeListener(this);
    mGridViewPager.setAdapter(mAdapter);
    mDotsPageIndicator.setPager(mGridViewPager);
    mDotsPageIndicator.setOnPageChangeListener(mAdapter);

    topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override// ww w  .  jav a2  s.c  o  m
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // Call through to super implementation
            insets = topFrameLayout.onApplyWindowInsets(insets);

            boolean round = insets.isRound();

            // Store system window insets regardless of screen shape
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());

            if (round) {
                // On a round screen calculate the square inset to use.
                // Alternatively could use BoxInsetLayout, although calculating
                // the inset ourselves lets us position views outside the center
                // box. For example, slightly lower on the round screen (by giving
                // up some horizontal space).
                mInsets = Utils.calculateBottomInsetsOnRoundDevice(getWindowManager().getDefaultDisplay(),
                        mInsets);

                // Boost the dots indicator up by the bottom inset
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mDotsPageIndicator
                        .getLayoutParams();
                params.bottomMargin = mInsets.bottom;
                mDotsPageIndicator.setLayoutParams(params);
            }

            mAdapter.setInsets(mInsets);
            return insets;
        }
    });

    // Set up the DismissOverlayView
    mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
    mDismissOverlayView.setIntroText(getString(R.string.exit_intro_text));
    mDismissOverlayView.showIntroIfNecessary();
    mGestureDetector = new GestureDetectorCompat(this, new LongPressListener());

    Uri shopsUri = getIntent().getParcelableExtra(Constants.EXTRA_SHOPS_URI);
    if (shopsUri != null) {
        new FetchDataAsyncTask(this).execute(shopsUri);
        UtilityService.clearNotification(this);
        UtilityService.clearRemoteNotifications(this);
    } else {
        finish();
    }
}

From source file:com.asburymotors.android.disneysocal.ui.AttractionsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    final FrameLayout topFrameLayout = (FrameLayout) findViewById(R.id.topFrameLayout);
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mGridViewPager = (GridViewPager) findViewById(R.id.gridViewPager);
    mDotsPageIndicator = (DotsPageIndicator) findViewById(R.id.dotsPageIndicator);
    mAdapter = new AttractionsGridPagerAdapter(this, mAttractions);
    mAdapter.setOnChromeFadeListener(this);
    mGridViewPager.setAdapter(mAdapter);
    mDotsPageIndicator.setPager(mGridViewPager);
    mDotsPageIndicator.setOnPageChangeListener(mAdapter);

    topFrameLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override/*  ww w  .j  a va  2 s  .c o  m*/
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            // Call through to super implementation
            insets = topFrameLayout.onApplyWindowInsets(insets);

            boolean round = insets.isRound();

            // Store system window insets regardless of screen shape
            mInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                    insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());

            if (round) {
                // On a round screen calculate the square inset to use.
                // Alternatively could use BoxInsetLayout, although calculating
                // the inset ourselves lets us position views outside the center
                // box. For example, slightly lower on the round screen (by giving
                // up some horizontal space).
                mInsets = Utils.calculateBottomInsetsOnRoundDevice(getWindowManager().getDefaultDisplay(),
                        mInsets);

                // Boost the dots indicator up by the bottom inset
                FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mDotsPageIndicator
                        .getLayoutParams();
                params.bottomMargin = mInsets.bottom;
                mDotsPageIndicator.setLayoutParams(params);
            }

            mAdapter.setInsets(mInsets);
            return insets;
        }
    });

    // Set up the DismissOverlayView
    mDismissOverlayView = (DismissOverlayView) findViewById(R.id.dismiss_overlay);
    mDismissOverlayView.setIntroText(getString(R.string.exit_intro_text));
    mDismissOverlayView.showIntroIfNecessary();
    mGestureDetector = new GestureDetectorCompat(this, new LongPressListener());

    Uri attractionsUri = getIntent().getParcelableExtra(Constants.EXTRA_ATTRACTIONS_URI);
    if (attractionsUri != null) {
        new FetchDataAsyncTask(this).execute(attractionsUri);
        UtilityService.clearNotification(this);
        UtilityService.clearRemoteNotifications(this);
    } else {
        finish();
    }
}