Android Open Source - XKCD-Reader Comic Pager Adapter






From Project

Back to project page XKCD-Reader.

License

The source code is released under:

Apache License

If you think the Android project XKCD-Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.davidtpate.xkcd.adapter;
/*  w ww .  ja  v a  2s .com*/
import android.support.v4.app.FixedFragmentStatePagerAdapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import com.davidtpate.xkcd.model.Constants;
import com.davidtpate.xkcd.ui.ComicFragment;
import com.davidtpate.xkcd.util.Ln;

/**
 * The main adapter that backs the ViewPager. A subclass of FragmentStatePagerAdapter as there
 * could be a large number of items in the ViewPager and we don't want to retain them all in
 * memory at once but create/destroy them on the fly.
 */
public class ComicPagerAdapter extends FixedFragmentStatePagerAdapter {
    protected int mMaxComicNumber;
    public ComicPagerAdapter(FragmentManager fm, int mMaxComicNumber) {
        super(fm);
        this.mMaxComicNumber = mMaxComicNumber;
    }

    /**
     * Return the Fragment associated with a specified position.
     */
    @Override public Fragment getItem(int position) {
        // Arrays are 0 based, but the comic is 1 based, so always add 1.
        position++;

        Ln.d("Creating Fragment %d", position);
        // We want this to start from the most recent, so
        return ComicFragment.newInstance(position);
    }

    /**
     * Return the number of views available.
     */
    @Override public int getCount() {
        // If we don't know the maximum value yet, or had a bad value passed limit this to only the current comic until it is updated.
        if (mMaxComicNumber == Constants.LATEST_COMIC_NUMBER || mMaxComicNumber <= 0) {
            return 1;
        }
        return mMaxComicNumber;
    }

    public void updateMaxComicNumber(int mMaxComicNumber) {
        Ln.d("Got New Max Comic Number %d, Updating Adapter", mMaxComicNumber);
        this.mMaxComicNumber = mMaxComicNumber;
        notifyDataSetChanged();
    }
}




Java Source Code List

android.support.v4.app.FixedFragmentStatePagerAdapter.java
com.android.debug.hv.ViewServer.java
com.davidtpate.xkcd.BaseApplication.java
com.davidtpate.xkcd.adapter.ComicPagerAdapter.java
com.davidtpate.xkcd.model.Comic.java
com.davidtpate.xkcd.model.Constants.java
com.davidtpate.xkcd.preferences.SharedPreferencesHelper.java
com.davidtpate.xkcd.provider.SystemUiStateProvider.java
com.davidtpate.xkcd.ui.About.java
com.davidtpate.xkcd.ui.ComicFragmentActivity.java
com.davidtpate.xkcd.ui.ComicFragment.java
com.davidtpate.xkcd.ui.CurrentComic.java
com.davidtpate.xkcd.ui.base.BaseActivity.java
com.davidtpate.xkcd.ui.base.BaseFragmentActivity.java
com.davidtpate.xkcd.ui.base.BaseFragment.java
com.davidtpate.xkcd.ui.base.BaseListActivity.java
com.davidtpate.xkcd.ui.base.BaseListFragment.java
com.davidtpate.xkcd.ui.dialog.JumpToDialogFragment.java
com.davidtpate.xkcd.util.AndroidUtil.java
com.davidtpate.xkcd.util.ComicUtil.java
com.davidtpate.xkcd.util.Ln.java
com.davidtpate.xkcd.util.MathUtil.java
com.davidtpate.xkcd.util.Strings.java