List of usage examples for android.view WindowInsets getSystemWindowInsetTop
public int getSystemWindowInsetTop()
From source file:com.google.samples.apps.ourstreets.view.ViewUtils.java
/** * Applies top window insets for a view. * * @param view The view to apply insets for. */// w ww . j av a2 s . co m public static void applyTopWindowInsetsForView(@NonNull final View view) { view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { v.setPadding(v.getPaddingLeft(), insets.getSystemWindowInsetTop() + v.getPaddingTop(), v.getPaddingRight(), v.getPaddingBottom()); return insets; } }); view.requestApplyInsets(); }
From source file:android.support.v7.custom.CustomDrawerLayout.java
public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) { mSystemWindowInsetTop = insets.getSystemWindowInsetTop(); return super.dispatchApplyWindowInsets(insets); }
From source file:com.nightlynexus.dire.widget.ScrimInsetsFrameLayout.java
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH) @Override/*from w ww. j a v a2 s.c o 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/* ww w . ja va 2s . 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.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); }//from w ww. j a va2 s . c o m 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; } } }
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//from www. 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 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 ww w. j a v a 2 s.co 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(); } }
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/*from w w w . j a v a 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(); } }
From source file:liam.franco.selene.activities.AboutActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_about); ButterKnife.bind(this); App.BUS.register(this); setSupportActionBar(toolbar);// ww w. j av a 2 s . com if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_white_24dp); } UIUtils.setTranslucentNavigationFlag(this, true); UIUtils.setTranslucentStatusFlag(this, true); parentLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); parentLayout.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { int navBarHeight = UIUtils.getNavigationBarHeight(App.CONTEXT); // 1 = portrait, 2 = landscape int orientation = App.RESOURCES.getConfiguration().orientation; ViewGroup.MarginLayoutParams bar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); bar.topMargin += insets.getSystemWindowInsetTop(); bar.rightMargin += insets.getSystemWindowInsetRight(); toolbar.setLayoutParams(bar); // making sure it's all inside bounds because of our transparent status and nav bars scrollableLayout.setPadding(scrollableLayout.getPaddingLeft(), scrollableLayout.getPaddingTop(), scrollableLayout.getPaddingRight() + (orientation == 1 ? insets.getSystemWindowInsetRight() : navBarHeight), scrollableLayout.getPaddingBottom() + (orientation == 1 ? navBarHeight : insets.getSystemWindowInsetBottom())); parentLayout.setOnApplyWindowInsetsListener(null); return insets.consumeSystemWindowInsets(); } }); liamList.addItemDecoration(new SimpleDividerItemDecoration(this)); liamAdapter = new FastItemAdapter<>(); liamList.setLayoutManager(new UnscrollableLinearLayoutManager(this)); liamList.setAdapter(liamAdapter); franciscoList.addItemDecoration(new SimpleDividerItemDecoration(this)); franciscoAdapter = new FastItemAdapter<>(); franciscoList.setLayoutManager(new UnscrollableLinearLayoutManager(this)); franciscoList.setAdapter(franciscoAdapter); libsList.addItemDecoration(new SimpleDividerItemDecoration(this)); libsAdapter = new FastItemAdapter<>(); libsList.setLayoutManager(new UnscrollableLinearLayoutManager(this)); libsList.setAdapter(libsAdapter); mutateMoreList.addItemDecoration(new SimpleDividerItemDecoration(this)); mutateMoreAdapter = new FastItemAdapter<>(); mutateMoreList.setLayoutManager(new UnscrollableLinearLayoutManager(this)); mutateMoreList.setAdapter(mutateMoreAdapter); initAboutEntries(); }
From source file:us.phyxsi.gameshelf.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);// w w w . j a v a2s .co m if (savedInstanceState == null) { animateToolbar(); } bggPrefs = BGGPrefs.get(this); dataManager = new DataManager(this) { @Override public void onDataLoaded(List<? extends Boardgame> data) { adapter.addAndResort(data); checkEmptyState(); } }; adapter = new FeedAdapter(this, HomeActivity.this, dataManager, columns); 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) { // @Override // public void onLoadMore() { // // TODO: Load more items // } // }); grid.setHasFixedSize(true); // 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(); dataManager.loadFromDatabase(); checkEmptyState(); checkConnectivity(); }