Android Open Source - rpg-droid Pager Adapter_ Charsheet






From Project

Back to project page rpg-droid.

License

The source code is released under:

Apache License

If you think the Android project rpg-droid 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.thing.rpg_droid.app;
/*  w ww.j a v a 2s.  c  om*/
import android.app.Fragment;
import android.app.FragmentManager;
import android.support.v13.app.FragmentPagerAdapter;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by jon on 3/08/14.
 */
public class PagerAdapter_Charsheet  extends FragmentPagerAdapter {

    Activity_Charsheet mActivity;

    public PagerAdapter_Charsheet(FragmentManager fm, Activity_Charsheet pActivity) {
        super(fm);

        mActivity = pActivity;
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).

        ICharacter lChar = mActivity.getCharacter();

        if (lChar != null)
        {
            Class<? extends Fragment> pClass = lChar.getPageFragmentClass(position);

            try
            {
                Constructor<? extends Fragment> lConstructor = pClass.getConstructor(new Class[] { });

                return lConstructor.newInstance();
            }
            catch (NoSuchMethodException e)
            {
                e.printStackTrace();
            }
            catch (InvocationTargetException e)
            {
                e.printStackTrace();
            }
            catch (InstantiationException e)
            {
                e.printStackTrace();
            }
            catch (IllegalAccessException e)
            {
                e.printStackTrace();
            }
        }

        return null;
    }

    @Override
    public int getCount() {

        ICharacter lChar = mActivity.getCharacter();

        if (lChar != null)
        {
            return lChar.getPageCount();
        }

        return 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {

        ICharacter lChar = mActivity.getCharacter();

        if (lChar != null)
        {
            Class<? extends Fragment> pClass = lChar.getPageFragmentClass(position);

            if (pClass.isAnnotationPresent(CharSheet_PageInfo.class))
            {
                CharSheet_PageInfo lTitleInfo = pClass.getAnnotation(CharSheet_PageInfo.class);
                return lTitleInfo.title();
            }
            else
            {
                return pClass.getSimpleName();
            }
        }

        return null;
    }
}




Java Source Code List

com.thing.rpg_droid.Utils.DieRoller.java
com.thing.rpg_droid.Utils.DieType.java
com.thing.rpg_droid.app.Activity_CharacterList.java
com.thing.rpg_droid.app.Activity_Charsheet.java
com.thing.rpg_droid.app.CharSheet_PageInfo.java
com.thing.rpg_droid.app.Fragment_CharacterList.java
com.thing.rpg_droid.app.ICharacter.java
com.thing.rpg_droid.app.PagerAdapter_Charsheet.java
com.thing.rpg_droid.app.ViewBinder.java
com.thing.rpg_droid.app.View_CharacterSheet_Field.java
com.thing.rpg_droid.app.dummy.DummyContent.java
com.thing.rpg_droid.pathfinder.Ability.java
com.thing.rpg_droid.pathfinder.Adapters.java
com.thing.rpg_droid.pathfinder.Appearance.java
com.thing.rpg_droid.pathfinder.ArmorClass.java
com.thing.rpg_droid.pathfinder.BodySlot.java
com.thing.rpg_droid.pathfinder.Character.java
com.thing.rpg_droid.pathfinder.Fragment_Basic.java
com.thing.rpg_droid.pathfinder.Fragment_Gear.java
com.thing.rpg_droid.pathfinder.Fragment_Skills.java
com.thing.rpg_droid.pathfinder.Fragment_Spells_Abilities.java
com.thing.rpg_droid.pathfinder.Fragment_Status.java
com.thing.rpg_droid.pathfinder.IInventoryLocation.java
com.thing.rpg_droid.pathfinder.Initiative.java
com.thing.rpg_droid.pathfinder.SavingThrow.java
com.thing.rpg_droid.pathfinder.SizeModifier.java
com.thing.rpg_droid.pathfinder.Skill.java
com.thing.rpg_droid.pathfinder.Spell.java
com.thing.rpg_droid.pathfinder.Status.java