List of usage examples for android.view WindowInsets getSystemWindowInsetTop
public int getSystemWindowInsetTop()
From source file:com.google.android.gcm.demo.ui.MainActivity.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); setContentView(R.layout.activity_main); mLogger = new Logger(this); mLogsUI = (TextView) findViewById(R.id.logs); mLoggerCallback = new BroadcastReceiver() { @Override// w w w .ja v a 2 s.com public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case LoggingService.ACTION_CLEAR_LOGS: mLogsUI.setText(""); break; case LoggingService.ACTION_LOG: StringBuilder stringBuilder = new StringBuilder(); String newLog = intent.getStringExtra(LoggingService.EXTRA_LOG_MESSAGE); String oldLogs = Html.toHtml(new SpannableString(mLogsUI.getText())); appendFormattedLogLine(newLog, stringBuilder); stringBuilder.append(oldLogs); mLogsUI.setText(Html.fromHtml(stringBuilder.toString())); List<Fragment> fragments = getSupportFragmentManager().getFragments(); for (Fragment fragment : fragments) { if (fragment instanceof RefreshableFragment && fragment.isVisible()) { ((RefreshableFragment) fragment).refresh(); } } break; } } }; Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerView = (FrameLayout) findViewById(R.id.navigation_drawer); mDrawerMenu = (ListView) findViewById(R.id.navigation_drawer_menu); mDrawerScrim = findViewById(R.id.navigation_drawer_scrim); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); TypedArray colorPrimaryDark = getTheme().obtainStyledAttributes(new int[] { R.attr.colorPrimaryDark }); mDrawerLayout.setStatusBarBackgroundColor(colorPrimaryDark.getColor(0, 0xFF000000)); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); colorPrimaryDark.recycle(); ImageView drawerHeader = new ImageView(this); drawerHeader.setImageResource(R.drawable.drawer_gcm_logo); mDrawerMenu.addHeaderView(drawerHeader); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Set the drawer width accordingly with the guidelines: window_width - toolbar_height. toolbar.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View view, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { if (left == 0 && top == 0 && right == 0 && bottom == 0) { return; } DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); float logicalDensity = metrics.density; int maxWidth = (int) Math.ceil(320 * logicalDensity); DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawerView.getLayoutParams(); int newWidth = view.getWidth() - view.getHeight(); params.width = (newWidth > maxWidth ? maxWidth : newWidth); mDrawerView.setLayoutParams(params); } }); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { mDrawerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // Set scrim height to match status bar height. mDrawerScrim.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, insets.getSystemWindowInsetTop())); return insets; } }); } int activeItemIndicator = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) ? android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_checked; mMainMenu = new MainMenu(this); mDrawerMenu.setOnItemClickListener(this); mDrawerMenu.setAdapter(new ArrayAdapter<>(getSupportActionBar().getThemedContext(), activeItemIndicator, android.R.id.text1, mMainMenu.getEntries())); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { // The user learned how to open the drawer. Do not open it for him anymore. getAppPreferences().edit().putBoolean(PREF_OPEN_DRAWER_AT_STARTUP, false).apply(); super.onDrawerOpened(drawerView); } }; boolean activityResumed = (savedState != null); boolean openDrawer = getAppPreferences().getBoolean(PREF_OPEN_DRAWER_AT_STARTUP, true); int lastScreenId = getAppPreferences().getInt(PREF_LAST_SCREEN_ID, 0); selectItem(lastScreenId); if (!activityResumed && openDrawer) { mDrawerLayout.openDrawer(mDrawerView); } mDrawerLayout.setDrawerListener(mDrawerToggle); /* * Here we check if the Activity was created by the user clicking on one of our GCM * notifications: * 1. Check if the action of the intent used to launch the Activity. * 2. Print out any additional data sent with the notification. This is included as extras * on the intent. */ Intent launchIntent = getIntent(); if ("gcm_test_app_notification_click_action".equals(launchIntent.getAction())) { Bundle data = launchIntent.getExtras(); data.isEmpty(); // Force the bundle to unparcel so that toString() works String format = getResources().getString(R.string.notification_intent_received); mLogger.log(Log.INFO, String.format(format, data)); } }
From source file:org.androidwhite.icons.ui.MainActivity.java
private void setupNavDrawer() { assert mNavView != null; assert mDrawer != null; mNavView.getMenu().clear();/* w w w .j ava 2 s .c o 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 = 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();// w w w. j a v a 2 s.c o 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.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();//from w ww . j av a2 s. com } 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:com.hannesdorfmann.home.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);//from w w w .ja v a2 s .c om setContentView(R.layout.activity_home2); ButterKnife.bind(this); drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); //toolbar.inflateMenu(R.menu.main); setActionBar(toolbar); if (savedInstanceState == null) { animateToolbar(); } adapter = new FeedAdapter(this, columns, false); 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(gridScroll); grid.addOnScrollListener(new com.hannesdorfmann.InfiniteScrollListener(layoutManager) { @Override public void onLoadMore() { presenter.loadMore(); } }); 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.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.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), grid.getPaddingRight() + insets.getSystemWindowInsetRight(), // landscape grid.getPaddingBottom()); // 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); // 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); // clear this listener so insets aren't re-applied drawer.setOnApplyWindowInsetsListener(null); return insets.consumeSystemWindowInsets(); } }); setupTaskDescription(); }
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); //toolbar.inflateMenu(R.menu.main); setActionBar(toolbar);/* w ww. j a va2s. c o m*/ if (savedInstanceState == null) { animateToolbar(); } dribbblePrefs = DribbblePrefs.get(this); designerNewsPrefs = DesignerNewsPrefs.get(this); filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() { @Override public void requestDribbbleAuthorisation(View sharedElemeent, Source forSource) { Intent login = new Intent(HomeActivity.this, DribbbleLogin.class); login.putExtra(FabDialogMorphSetup.EXTRA_SHARED_ELEMENT_START_COLOR, ContextCompat.getColor(HomeActivity.this, R.color.background_dark)); ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElemeent, 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(gridScroll); 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.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.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), grid.getPaddingRight() + insets.getSystemWindowInsetRight(), // landscape grid.getPaddingBottom()); // 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); // 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); filtersAdapter.addFilterChangedListener(filtersChangedListener); filtersAdapter.addFilterChangedListener(dataManager); dataManager.loadAllDataSources(); ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); itemTouchHelper.attachToRecyclerView(filtersList); checkEmptyState(); checkConnectivity(); }
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 ww 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(); }