Java Code Examples for android.support.wearable.view.GridViewPager#setOnApplyWindowInsetsListener()

The following examples show how to use android.support.wearable.view.GridViewPager#setOnApplyWindowInsetsListener() . 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: MainActivity.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: MainActivity.java    From android-GridViewPager with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 3
Source File: CommentsActivity.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_comments);

    final String stringComments = getIntent().getStringExtra(Constants.KEY_REDDIT_POSTS);
    final ArrayList<Comment> comments = mGson.fromJson(stringComments,
            new TypeToken<List<Comment>>() {
            }.getType());
    if (comments == null || comments.isEmpty()) {
        Toast.makeText(this, R.string.thread_has_no_comments_yet, Toast.LENGTH_SHORT).show();
        finish();
    } else {
        mGridViewPager = (GridViewPager) findViewById(R.id.pager);
        mGridViewPager.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                // A little extra horizontal spacing between pages looks a bit less crowded on a round display
                int rowMargin = getResources().getDimensionPixelOffset(R.dimen.page_row_margin);
                int colMargin = getResources().getDimensionPixelOffset(insets.isRound() ? R.dimen.page_column_margin_round : R.dimen.page_column_margin);
                mGridViewPager.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
                mGridViewPager.onApplyWindowInsets(insets);
                return insets;
            }
        });
        mGridViewPager.setAdapter(new CommentsGridPagerAdapter(CommentsActivity.this,
                getFragmentManager(),
                comments));

        DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
        dotsPageIndicator.setPager(mGridViewPager);
    }
}