Java 类android.support.v4.app.FixedFragmentStatePagerAdapter 实例源码

项目:RSSFeedReader-App    文件:ArticleView.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
       BrightnessControl.toggleBrightness(getApplicationContext(), this);
    if (savedInstanceState == null) {
        rssData = HeadlinesFragment.getInstance().getRssData();
    }
    else {
        rssData = savedInstanceState.getParcelableArrayList(RSS_DATA_KEY);
    }
    setContentView(R.layout.article_view);
       viewPager = (ViewPager) findViewById(R.id.viewPager);

    viewPager
            .setOnPageChangeListener(viewPagerPageChangeListener = new ArticleViewPagerChangeListener());
    FragmentManager fragMan = getSupportFragmentManager();
    viewPager
            .setAdapter(viewPagerAdapter = new FixedFragmentStatePagerAdapter(
                   fragMan) {

                   @Override
                   public Fragment getItem (int arg0) {
                       return ArticleViewFragment.newArticleViewFragment(rssData.get(arg0));
                   }

                   @Override
                   public int getCount () {
                       return rssData.size();
                   }

               });
       viewPager.setPageTransformer(true, new DepthPageTransformer());
    String uuid = getIntent().getStringExtra(HeadlinesFragment.ARTICLE_ID);

    for (int i = 0; i < rssData.size(); i++) {
        RSSDataBundle rdBundle = rssData.get(i);
        if (rdBundle.getId().equals(uuid)) {
            viewPager.setCurrentItem(i);
            // Explicitly call the page change listener to set
            // the action bar title appropriately
            viewPagerPageChangeListener.onPageSelected(i);
            break;
        }
    }

       ActionBar actionBar = getActionBar();
       if (actionBar != null) {
           actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                                     | ActionBar.DISPLAY_USE_LOGO
                                     | ActionBar.DISPLAY_SHOW_TITLE
                                     | ActionBar.DISPLAY_HOME_AS_UP);
       }
       title = Utils.getTitleTextView(this);

    if (title != null) {
        title.setEllipsize(TruncateAt.MARQUEE);
        title.setMarqueeRepeatLimit(-1);
        title.setHorizontallyScrolling(true);
        title.setFocusable(true);
        title.setFocusableInTouchMode(true);
        title.requestFocus();
        title.setTransformationMethod(SingleLineTransformationMethod
                .getInstance());
        title.setTextColor(getResources().getColor((R.color.AppPrimaryTextColor)));
    }

       action_openInBrowser = (LinearLayout) findViewById(R.id.action_open_in_browser);
       action_openInBrowser
           .setOnClickListener(new ArticleViewOpenInBrowserActionClickListener());
       action_next_unread = (LinearLayout) findViewById(R.id.action_next_unread);
       action_next_unread
           .setOnClickListener(new ArticleViewNextUnreadActionClickListener());
       action_previous_unread = (LinearLayout) findViewById(R.id.action_previous_unread);
       action_previous_unread
           .setOnClickListener(new ArticleViewPreviousUnreadActionClickListener());
}