Android Open Source - Game-of-thrones-trivia Strings X M L File Data






From Project

Back to project page Game-of-thrones-trivia.

License

The source code is released under:

MIT License

If you think the Android project Game-of-thrones-trivia 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.GameOfThrones.Trivia.data;
//from   w w w.  ja  v a  2  s .c  om
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.content.res.Resources;
import android.os.AsyncTask;

import com.GameOfThrones.Trivia.R;
import com.GameOfThrones.Trivia.core.GameCharacter;
import com.GameOfThrones.Trivia.core.Question;
import com.GameOfThrones.Trivia.core.QuestionCollection;
import com.GameOfThrones.Trivia.util.GeneralAlgorithms;

/**
 * Used to parse the character data in the strings.xml file
 * 
 * @author andre
 * 
 */
public class StringsXMLFileData {
  /**
   * Returns a string[][] that obtains character data from the array in the
   * string.xml file.
   * 
   * @param res
   * @return
   */
  private StringsXMLFileData() {
  }

  public ArrayList<GameCharacter> getCharacters(Resources res) {
    String[][] charactersData = null;
    String[] data = res.getStringArray(R.array.characters);
    charactersData = new String[data.length][];
    for (int i = 0; i < data.length; i++) {
      charactersData[i] = data[i].split("_");
    }

    ArrayList<GameCharacter> characters = new ArrayList<GameCharacter>();
    for (String[] characterInfo : charactersData) {
      ArrayList<String> aliases = new ArrayList<String>();
      for (int i = 1; i < characterInfo.length; i++) {
        aliases.add(characterInfo[i]);
      }
      characters.add(new GameCharacter(characterInfo[0], aliases));
    }
    return characters;
  }

  public static QuestionCollection getQuestionList(Resources res) {
    String[] questionData = res.getStringArray(R.array.questions);
    ArrayList<Question> questions = new ArrayList<Question>();
    for (int i = 0; i < questionData.length; i = i + 6) {
      questions.add(new Question(questionData[i], GeneralAlgorithms
          .converToStrArray(GeneralAlgorithms.sliceArray(
              questionData, i + 1, i + 4)), Integer
          .parseInt(questionData[i + 5])));
    }
    return new QuestionCollection(questions);
  }
}




Java Source Code List

com.GameOfThrones.Trivia.core.CharacterToQuestionsMap.java
com.GameOfThrones.Trivia.core.GameCharacter.java
com.GameOfThrones.Trivia.core.HighScore.java
com.GameOfThrones.Trivia.core.OutOfQuestionsException.java
com.GameOfThrones.Trivia.core.QuestionCollection.java
com.GameOfThrones.Trivia.core.Question.java
com.GameOfThrones.Trivia.core.Session.java
com.GameOfThrones.Trivia.core.SimpleIterator.java
com.GameOfThrones.Trivia.core.TriviaGame.java
com.GameOfThrones.Trivia.data.HighScorePrefs.java
com.GameOfThrones.Trivia.data.RequestWebService.java
com.GameOfThrones.Trivia.data.StringsXMLFileData.java
com.GameOfThrones.Trivia.ui.AboutActivity.java
com.GameOfThrones.Trivia.ui.DynamicBackgroundActivity.java
com.GameOfThrones.Trivia.ui.GameActivity.java
com.GameOfThrones.Trivia.ui.HighScoreActivity.java
com.GameOfThrones.Trivia.ui.MainMenuActivity.java
com.GameOfThrones.Trivia.ui.ResultsActivity.java
com.GameOfThrones.Trivia.ui.TriviaSelectionActivity.java
com.GameOfThrones.Trivia.ui.music.MusicService.java
com.GameOfThrones.Trivia.util.GeneralAlgorithms.java
com.Spartacus.TriviaTest.TriviaMenuActivityTest.java
com.Spartacus.Trivia.utilTest.GeneralAlgorithmsTest.java