Example usage for android.view WindowInsets getSystemWindowInsetLeft

List of usage examples for android.view WindowInsets getSystemWindowInsetLeft

Introduction

In this page you can find the example usage for android.view WindowInsets getSystemWindowInsetLeft.

Prototype

public int getSystemWindowInsetLeft() 

Source Link

Document

Returns the left system window inset in pixels.

Usage

From source file:com.nightlynexus.dire.widget.ScrimInsetsFrameLayout.java

@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Override//  ww w  .  java 2  s  . co  m
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    mInsets = new Rect(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
            insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
    setWillNotDraw(mInsetForeground == null);
    ViewCompat.postInvalidateOnAnimation(this);
    if (mOnInsetsCallback != null) {
        mOnInsetsCallback.onInsetsChanged(mInsets);
    }
    return insets;
}

From source file:com.github.shareme.gwsmaterialdrawer.library.widget.ScrimInsetsScrollView.java

@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Override//  w  ww.  j  av a  2  s  .co  m
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
    insets = super.onApplyWindowInsets(insets);
    handleWindowInsets(new Rect(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
            insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom()));
    return insets;
}

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;/*  w  w  w .  j a  va 2 s  .c  om*/
    }

    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.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/* w  w  w.  j av  a  2s . 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.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/*from w w  w .  jav  a  2s .com*/
        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.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/* w ww.j a v  a  2 s . 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:io.plaidapp.ui.PlayerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dribbble_player);
    ButterKnife.bind(this);
    circleTransform = new CircleTransform(this);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_PLAYER)) {
        player = intent.getParcelableExtra(EXTRA_PLAYER);
        bindPlayer();/* w  ww . ja  va2 s.  c o  m*/
    } else if (intent.hasExtra(EXTRA_PLAYER_NAME)) {
        String name = intent.getStringExtra(EXTRA_PLAYER_NAME);
        playerName.setText(name);
        if (intent.hasExtra(EXTRA_PLAYER_ID)) {
            long userId = intent.getLongExtra(EXTRA_PLAYER_ID, 0L);
            loadPlayer(userId);
        } else if (intent.hasExtra(EXTRA_PLAYER_USERNAME)) {
            String username = intent.getStringExtra(EXTRA_PLAYER_USERNAME);
            loadPlayer(username);
        }
    } else if (intent.getData() != null) {
        // todo support url intents
    }

    // setup immersive mode i.e. draw behind the system chrome & adjust insets
    draggableFrame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    draggableFrame.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            final ViewGroup.MarginLayoutParams lpFrame = (ViewGroup.MarginLayoutParams) draggableFrame
                    .getLayoutParams();
            lpFrame.leftMargin += insets.getSystemWindowInsetLeft(); // landscape
            lpFrame.rightMargin += insets.getSystemWindowInsetRight(); // landscape
            ((ViewGroup.MarginLayoutParams) avatar.getLayoutParams()).topMargin += insets
                    .getSystemWindowInsetTop();
            ViewUtils.setPaddingTop(container, insets.getSystemWindowInsetTop());
            ViewUtils.setPaddingBottom(shots, insets.getSystemWindowInsetBottom());
            // clear this listener so insets aren't re-applied
            draggableFrame.setOnApplyWindowInsetsListener(null);
            return insets;
        }
    });
    setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
}

From source file:org.androidwhite.icons.ui.MainActivity.java

private void setupNavDrawer() {
    assert mNavView != null;
    assert mDrawer != null;
    mNavView.getMenu().clear();//from  www. ja va  2  s  .com
    for (PagesBuilder.Page page : mPages)
        page.addToMenu(mNavView.getMenu());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.TRANSPARENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                //TODO: Check if NavigationView needs bottom padding
                WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets(
                        insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                        insets.getSystemWindowInsetRight(), 0);
                mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop();
                ((DrawerLayout) v).setChildInsets(drawerLayoutInsets,
                        drawerLayoutInsets.getSystemWindowInsetTop() > 0);
                return insets;
            }
        });
    }

    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Drawable menuIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_menu);
    menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color));
    getSupportActionBar().setHomeAsUpIndicator(menuIcon);

    mDrawer.addDrawerListener(
            new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close));
    mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark));
    mNavView.setNavigationItemSelectedListener(this);

    final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground();
    final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent);
    int iconColor;
    int titleColor;
    int selectedBg;
    if (TintUtils.isColorLight(navBg.getColor())) {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light);
    } else {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark);
    }

    final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText });
    final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText });
    mNavView.setItemTextColor(textSl);
    mNavView.setItemIconTintList(iconSl);

    StateListDrawable bgDrawable = new StateListDrawable();
    bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg));
    mNavView.setItemBackground(bgDrawable);

    mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            dispatchFragmentUpdateTitle(false);
            invalidateNavViewSelection(position);
        }
    });

    mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0);
}

From source file:com.afollestad.polar.ui.MainActivity.java

private void setupNavDrawer() {
    assert mNavView != null;
    assert mDrawer != null;
    mNavView.getMenu().clear();//from   w  w w .  j a  v a 2 s .  co  m
    for (PagesBuilder.Page page : mPages)
        page.addToMenu(mNavView.getMenu());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(Color.TRANSPARENT);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                //TODO: Check if NavigationView needs bottom padding
                WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets(
                        insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(),
                        insets.getSystemWindowInsetRight(), 0);
                mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop();
                ((DrawerLayout) v).setChildInsets(drawerLayoutInsets,
                        drawerLayoutInsets.getSystemWindowInsetTop() > 0);
                return insets;
            }
        });
    }

    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    Drawable menuIcon = VC.get(R.drawable.ic_action_menu);
    menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color));
    getSupportActionBar().setHomeAsUpIndicator(menuIcon);

    mDrawer.addDrawerListener(
            new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close));
    mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark));
    mNavView.setNavigationItemSelectedListener(this);

    final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground();
    final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent);
    int iconColor;
    int titleColor;
    int selectedBg;
    if (TintUtils.isColorLight(navBg.getColor())) {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light);
    } else {
        iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark);
        titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark);
        selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark);
    }

    final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText });
    final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked },
            new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText });
    mNavView.setItemTextColor(textSl);
    mNavView.setItemIconTintList(iconSl);

    StateListDrawable bgDrawable = new StateListDrawable();
    bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg));
    mNavView.setItemBackground(bgDrawable);

    mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            dispatchFragmentUpdateTitle(false);
            invalidateNavViewSelection(position);
        }
    });

    mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0);
}

From source file:io.plaidapp.ui.HomeActivity.java

@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);//from   w  w w .j  av  a  2 s  .co m
    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(grid.getPaddingLeft() + insets.getSystemWindowInsetLeft(), // landscape
                    insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this),
                    grid.getPaddingRight() + insets.getSystemWindowInsetRight(), // landscape
                    grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());

            // inset the fab for the navbar
            ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
            lpFab.bottomMargin += insets.getSystemWindowInsetBottom(); // portrait
            lpFab.rightMargin += insets.getSystemWindowInsetRight(); // landscape
            fab.setLayoutParams(lpFab);

            View postingStub = findViewById(R.id.stub_posting_progress);
            ViewGroup.MarginLayoutParams lpPosting = (ViewGroup.MarginLayoutParams) postingStub
                    .getLayoutParams();
            lpPosting.bottomMargin += insets.getSystemWindowInsetBottom(); // portrait
            lpPosting.rightMargin += insets.getSystemWindowInsetRight(); // landscape
            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();
}