Android Open Source - eve-datapad Account






From Project

Back to project page eve-datapad.

License

The source code is released under:

GNU General Public License

If you think the Android project eve-datapad 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.pocketcircuit.evedatapad;
//from w  w w  .  j a  v  a2  s  .co m
import android.content.Context;
import android.content.res.XmlResourceParser;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;


/**
 * List of Objects that comprise an Account via the API
 */
public class Account {
    private static Account sAccount;
    private Context mAccountContext;

    /**
     * TODO: Remove these hard coded data for truly populated data from API
     */
    private ArrayList<Integer> characterIds = new ArrayList<Integer>();
    private ArrayList<Character> accountCharacters = new ArrayList<Character>();

    private Account(Context appContext) {
        mAccountContext = appContext;
        updateAccount(mAccountContext);
    }

    public static Account get(Context c) {
        if (sAccount == null) {
            sAccount = new Account(c. getApplicationContext());
            sAccount.characterIds.add(964872367);
            sAccount.characterIds.add(240028545);
            sAccount.characterIds.add(373367497);
        }
        return sAccount;
    }

    public boolean updateAccount(Context passedContext){
            Character currentCharacter = new Character();
            // Hardcoded Avatar for now
            currentCharacter.setAvatarResource("@drawable/test_avatar");

            // Parse Characters XML File
            if(accountCharacters.size() <= 0 ) {
                XmlResourceParser xrp = passedContext.getResources().getXml(R.xml.charactersheetapi964872367);
                try{
                    xrp.next();
                    boolean done = false;
                    int eventType = xrp.getEventType();
                    while (eventType != XmlPullParser.END_DOCUMENT && !done)   {

                        switch (eventType) {
                            case XmlPullParser.START_DOCUMENT:
                                break;
                            case XmlPullParser.START_TAG:
                                String name = xrp.getName();
                                if(name.equalsIgnoreCase("characterID")) {
                                    currentCharacter.setId(Integer.parseInt(xrp.nextText()));
                                } else if(name.equalsIgnoreCase("name")) {
                                    currentCharacter.setName(xrp.nextText());
                                } else if(name.equalsIgnoreCase("DoB")) {
                                    currentCharacter.setDoB(xrp.nextText());
                                } else if(name.equalsIgnoreCase("race")){
                                    currentCharacter.setRace(xrp.nextText());
                                } else if(name.equalsIgnoreCase("bloodline")){
                                    currentCharacter.setBloodline(xrp.nextText());
                                } else if(name.equalsIgnoreCase("ancestry")){
                                    currentCharacter.setAncestry(xrp.nextText());
                                } else if(name.equalsIgnoreCase("gender")){
                                    currentCharacter.setGender(xrp.nextText());
                                } else if(name.equalsIgnoreCase("corporationName")){
                                    currentCharacter.setCorpName(xrp.nextText());
                                } else if(name.equalsIgnoreCase("corporationId")){
                                    currentCharacter.setCorpId(Integer.parseInt(xrp.nextText()));
                                } else if(name.equalsIgnoreCase("allianceName")){
                                    currentCharacter.setAllianceName(xrp.nextText());
                                } else if(name.equalsIgnoreCase("allianceId")){
                                    currentCharacter.setAllianceId(Integer.parseInt(xrp.nextText()));
                                } else if(name.equalsIgnoreCase("cloneName")){
                                    currentCharacter.setCloneName(xrp.nextText());
                                } else if(name.equalsIgnoreCase("cloneSkillPoints")){
                                    currentCharacter.setCloneSkillPoints(Long.parseLong(xrp.nextText()));
                                } else if(name.equalsIgnoreCase("balance")){
                                    currentCharacter.setWalletBalance(Double.parseDouble(xrp.nextText()));
                                } else if(name.equalsIgnoreCase("rowset")){
                                    // TODO: Build in Skill Queue and Skill List Parser.
                                }
                                break;

                            case XmlPullParser.END_TAG:
                                break;
                            case XmlPullParser.TEXT:
                                break;

                        }
                        eventType = xrp.next();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    e.printStackTrace();
                }
                // Hardcoded skill queue for now
                Skill AstrometricPinpointing = new Skill(1001, "Astrometric Pinpointing", "Greater accuracy in hunting down targets found through scanning. Reduces maximum scan deviation by 10% per level.", "Science", "Astrometrics III", 3, 46212, 7072, 5, "Intelligence", "Memory");
                Skill Logistics = new Skill(1002, "Logistics", "Skill at operating Support Cruisers. Can not be trained on Trial Accounts.", "Spaceship Command", "Ship Command V, Signature Analysis III, Long Range Targeting III", 4, 271530, 37190, 6, "Willpower", "Perception");

                ArrayList<Skill> returnSkillQueue = new ArrayList<Skill>();
                returnSkillQueue.add(AstrometricPinpointing);
                returnSkillQueue.add(Logistics);
                currentCharacter.setSkillQueue(returnSkillQueue);
            }
            // Add XML data that has been parsed into the Account ArrayList<Characters>
            accountCharacters.add(currentCharacter);
        //}
        return true;
    }
    public ArrayList<Character> getCharacters() {
        return accountCharacters;
    }

    public Character getCharacter(int id) {
        for(Character c : accountCharacters) {
            if (c.getId() == id)
                return c;
        }
        return null;
    }

}




Java Source Code List

com.pocketcircuit.evedatapad.Account.java
com.pocketcircuit.evedatapad.BuildConfig.java
com.pocketcircuit.evedatapad.CharacterDetail.java
com.pocketcircuit.evedatapad.CharacterList.java
com.pocketcircuit.evedatapad.Character.java
com.pocketcircuit.evedatapad.Skill.java