android.view.View.OnApplyWindowInsetsListener Java Examples
The following examples show how to use
android.view.View.OnApplyWindowInsetsListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WindowUtils.java From ticdesign with Apache License 2.0 | 6 votes |
/** * Clip given window to round. * * This method should be called before window is show. * * @param window window needs to be clipped. * @return If clip succeed. */ public static boolean clipToScreenShape(final Window window) { if (window == null || window.getDecorView() == null) { return false; } // Record original drawable & set window to transparent to avoid window has solid color. final Drawable original = window.getDecorView().getBackground(); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.getDecorView().setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // Delay setting window background when shape is defined. Drawable background = getBackgroundDrawable(original, insets.isRound()); window.setBackgroundDrawable(background); if (insets.isRound()) { clipToRound(v); } return insets; } }); window.getDecorView().requestApplyInsets(); return true; }
Example #2
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Resources res = getResources(); final GridViewPager pager = (GridViewPager) findViewById(R.id.pager); pager.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // Adjust page margins: // A little extra horizontal spacing between pages looks a bit // less crowded on a round display. final boolean round = insets.isRound(); int rowMargin = res.getDimensionPixelOffset(R.dimen.page_row_margin); int colMargin = res.getDimensionPixelOffset(round ? R.dimen.page_column_margin_round : R.dimen.page_column_margin); pager.setPageMargins(rowMargin, colMargin); return insets; } }); pager.setAdapter(new SampleGridPagerAdapter(this, getFragmentManager())); }
Example #3
Source File: MainActivity.java From android-GridViewPager with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Resources res = getResources(); final GridViewPager pager = (GridViewPager) findViewById(R.id.pager); pager.setOnApplyWindowInsetsListener(new OnApplyWindowInsetsListener() { @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { // Adjust page margins: // A little extra horizontal spacing between pages looks a bit // less crowded on a round display. final boolean round = insets.isRound(); int rowMargin = res.getDimensionPixelOffset(R.dimen.page_row_margin); int colMargin = res.getDimensionPixelOffset(round ? R.dimen.page_column_margin_round : R.dimen.page_column_margin); pager.setPageMargins(rowMargin, colMargin); // GridViewPager relies on insets to properly handle // layout for round displays. They must be explicitly // applied since this listener has taken them over. pager.onApplyWindowInsets(insets); return insets; } }); pager.setAdapter(new SampleGridPagerAdapter(this, getFragmentManager())); DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator); dotsPageIndicator.setPager(pager); }