@Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.random:
        final int page = RANDOM.nextInt(mAdapter.getCount());
        Toast.makeText(this, "Changing to page " + page, Toast.LENGTH_SHORT);
        mPager.setCurrentItem(page);
        return true;

      case R.id.add_page:
        if (mAdapter.getCount() < 10) {
          mAdapter.setCount(mAdapter.getCount() + 1);
          mIndicator.notifyDataSetChanged();
        }
        return true;

      case R.id.remove_page:
        if (mAdapter.getCount() > 1) {
          mAdapter.setCount(mAdapter.getCount() - 1);
          mIndicator.notifyDataSetChanged();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_underline_page_indicator);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(
        new FragmentStatePagerAdapter(getSupportFragmentManager()) {
          @Override
          public int getCount() {
            return 5;
          }

          @Override
          public Fragment getItem(int position) {
            Fragment f = new SampleFragment();
            Bundle args = new Bundle();
            args.putInt(SampleFragment.PAGE_NUMBER, position + 1);
            f.setArguments(args);
            return f;
          }

          @Override
          public CharSequence getPageTitle(int position) {
            return "Page" + (position + 1);
          }
        });
    PageIndicator titleIndicator = (PageIndicator) findViewById(R.id.indicator);
    titleIndicator.setViewPager(viewPager);
  }
Пример #3
0
  private void setupRadioChannelPager() {
    if (mRadioChannelItems.size() >= 0) {
      ArrayList<RadioGridFragment> viewPagerFragments = new ArrayList<>();

      int pages = mRadioChannelItems.size() / Constants.RADIO_CHANNEL_GRIDVIEW_SIZE;
      int remains = mRadioChannelItems.size() % Constants.RADIO_CHANNEL_GRIDVIEW_SIZE;

      if (remains > 0) {
        pages++;
      }

      if (pages == 0) {
        pages = 1;
      }

      // create fragment
      for (int i = 0; i < pages; i++) {
        int start = i * Constants.RADIO_CHANNEL_GRIDVIEW_SIZE;
        int end = start + Constants.RADIO_CHANNEL_GRIDVIEW_SIZE;
        if (end > mRadioChannelItems.size()) {
          end = mRadioChannelItems.size();
        }

        ArrayList<RadioChannelInfo.RadioChannel> subList = new ArrayList<>();
        if (end > 0) {
          subList = new ArrayList<>(mRadioChannelItems.subList(start, end));
        }

        viewPagerFragments.add(RadioGridFragment.newInstance(i, subList));
      }

      mRadioPagerAdapter =
          new RadioPagerAdapter(this, getSupportFragmentManager(), viewPagerFragments);
      mViewPager.setAdapter(mRadioPagerAdapter);
      mViewPager.setSwipeable(true);
      mIndicator.setViewPager(mViewPager);
      mIndicator.setOnPageChangeListener(
          new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(
                int position, float positionOffset, int positionOffsetPixels) {}

            @Override
            public void onPageSelected(int position) {}

            @Override
            public void onPageScrollStateChanged(int state) {}
          });
    } else {
      // show relaod or close
      Log.e(TAG, ">> Radio channel list update failed. show error message !!!");
    }
  }
Пример #4
0
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    pagerAdapter = new ImageViewPagerAdapter(getActivity(), MainController.getPhotos(), listener);

    /* set adapter */
    mViewPager.setAdapter(pagerAdapter);

    /* Set Initial Item Position */
    mViewPager.setCurrentItem(MainController.getClickedItemPosition());

    /* Set Page indicator to View Pager */
    indicator.setViewPager(mViewPager);

    /* Set Current Item of Page Indicator */
    indicator.setCurrentItem(MainController.getClickedItemPosition());
  }
Пример #5
0
  // TODO make this less sloppy. Create a custom fragment activity.
  private void populate() {
    setContentView(R.layout.generic_pager);

    setActionBarTitle("Top 10");

    adapter = new Adapater(getSupportFragmentManager());

    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);

    indicator = (TabPageIndicator) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.acitivity_intro);

    ViewPager pager = (ViewPager) findViewById(R.id.fullscreen_pager);

    IntroPagerAdapter introPagerAdapter = new IntroPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(introPagerAdapter);
    pager.setPageTransformer(true, new ColorFadingPageTransformer());
    mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
    mIndicator.setViewPager(pager);
  }
Пример #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_main);

    mAdapter = new FragmentAdapter(getSupportFragmentManager());

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    mIndicator = (TitlePageIndicator) findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
  }