Android Open Source - ScienceQuiz Config Reader






From Project

Back to project page ScienceQuiz.

License

The source code is released under:

GNU General Public License

If you think the Android project ScienceQuiz 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.finger.sciencequiz;
/*from w w  w .  ja  v  a2  s .  c o  m*/
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import android.content.Context;
import android.util.Log;

public class ConfigReader
{
    public static String LOG_TAG = "ConfigReader";

    public ConfigReader (String path, Context context)
    {
  this.Path = path;
    }

    public String     Path;

    protected Context context;

    public HashMap<String, String> Read ()
    {
  return Read (Path, context);
    }

    public static HashMap<String, String> Read (String path, Context context)
    {
  HashMap<String, String> cfg = new HashMap<String, String> ();
  try
  {
      InputStreamReader is = new InputStreamReader (context.getAssets ()
                                                     .open (path));
      BufferedReader br = new BufferedReader (is);
      int lnNum = 1;
      String ln, key, val;
      while ((ln = br.readLine ()) != null)
      {
    ln = ln.trim ();
    if (!(ln.length () < 1 || ln.charAt (0) == 35))
    {
        int idx = ln.indexOf ("=");
        try
        {
      key = ln.substring (0, idx);
      val = ln.substring (idx + 1, ln.length ());
      cfg.put (key, val);
        }
        catch (IndexOutOfBoundsException e)
        {
      Log.w (LOG_TAG, path + ": Invalid option in line "
                      + lnNum);
        }
    }
    lnNum++;
      }
      br.close ();
  }
  catch (FileNotFoundException e)
  {
      Log.e (LOG_TAG, "Config file not found: " + path);
  }
  catch (IOException e)
  {
      e.printStackTrace ();
  }

  return cfg;
    }
}




Java Source Code List

com.finger.sciencequiz.AboutActivity.java
com.finger.sciencequiz.ConfigReader.java
com.finger.sciencequiz.FriendsHomeFragment.java
com.finger.sciencequiz.GalleryViewPager.java
com.finger.sciencequiz.GameActivity.java
com.finger.sciencequiz.GameTypeSelectActivity.java
com.finger.sciencequiz.HistoryActivity.java
com.finger.sciencequiz.HomePagerAdapter.java
com.finger.sciencequiz.ImageAdapter.java
com.finger.sciencequiz.LobbyActivity.java
com.finger.sciencequiz.MainActivity.java
com.finger.sciencequiz.NavigationDrawerFragment.java
com.finger.sciencequiz.NewGameActivity.java
com.finger.sciencequiz.ProfileHomeFragment.java
com.finger.sciencequiz.RotationTextView.java
com.finger.sciencequiz.RunningGamesHomeFragment.java
com.finger.sciencequiz.SettingsActivity.java
com.finger.sciencequiz.StartHomeFragment.java