コード例 #1
0
ファイル: Settings.java プロジェクト: ZaubererHaft/Hangman
  /**
   * Loads a user local.
   *
   * @return user.
   */
  public static User loadCurrentUser(Activity a) {
    try {
      File file = new File(Settings.getPath(a) + "/curUser.ini");

      // if the file doesn't exits, abort.
      if (!file.exists()) {
        return null;
      }

      FileReader fr;
      fr = new FileReader(Settings.getPath(a) + "/curUser.ini");
      BufferedReader br = new BufferedReader(fr, 8192);

      User u = new User(br.readLine(), "", "", -1);

      Logger.logOnly("User loaded!");
      fr.close();
      br.close();

      return u;
    } catch (IOException ex) {
      Logger.logOnly(ex.getMessage());
    } catch (NumberFormatException ex) {
      Logger.logOnlyError(ex.getMessage());
    }

    return null;
  }
コード例 #2
0
ファイル: Settings.java プロジェクト: ZaubererHaft/Hangman
  /**
   * Delets the file with the last word.
   *
   * @param a Context.
   */
  public static void deleteLastWord(Activity a) {
    try {
      File file = new File(Settings.getPath(a) + "/lastWord.txt");

      if (file.exists()) {
        file.delete();
      }
    } catch (Exception e) {
      Logger.logOnlyError(e.getMessage());
    }
  }
コード例 #3
0
ファイル: Settings.java プロジェクト: ZaubererHaft/Hangman
  /**
   * Loads the settings if they were already saved.
   *
   * @param a Context to load the file.
   * @since 0.3
   */
  public static void load(Activity a) {
    try {
      File file = new File(Settings.getPath(a) + "/settings.ini");
      Settings.categories = new ArrayList<>();

      // if the file doesn't exits, just create one.
      if (!file.exists()) {
        Settings.save(a);
        return;
      }

      FileReader fr;
      fr = new FileReader(Settings.getPath(a) + "/settings.ini");
      BufferedReader br = new BufferedReader(fr, 8192);

      // Gets the color theme
      String color = br.readLine();
      Settings.indexToColor(Integer.valueOf(color));

      // Gets the last logged in user
      Settings.lastUsername = br.readLine();
      Settings.lastPassword = br.readLine();

      String cat;

      while (true) {
        cat = br.readLine();

        if (cat == null) {
          break;
        }
        Settings.categories.add(cat);
      }

      Logger.logOnly("Settings loaded!");
      fr.close();
      br.close();

      // sort list
      Collections.sort(Settings.categories);

    } catch (IOException ex) {
      Logger.logOnly(ex.getMessage());
    } catch (NumberFormatException ex) {
      Logger.logOnlyError(ex.getMessage());
    }
  }
コード例 #4
0
ファイル: Settings.java プロジェクト: ZaubererHaft/Hangman
  /**
   * Loads a word an its guessed letters.<br>
   * Position 1: Word<br>
   * Position 2: Category<br>
   * Position 3: Description <br>
   * Position 4 - end: Letters already guessed.<br>
   *
   * @param a Context.
   * @return ArrayList
   */
  public static ArrayList<String> loadLastWord(Activity a) {
    try {
      File file = new File(Settings.getPath(a) + "/lastWord.txt");

      // if the file doesn't exits, abort.
      if (!file.exists()) {
        Logger.logOnlyWarning("Tried loading last word but there is none!");
        return null;
      }

      FileReader fr;
      fr = new FileReader(Settings.getPath(a) + "/lastWord.txt");
      BufferedReader br = new BufferedReader(fr, 8192);

      ArrayList<String> ret = new ArrayList<>();

      ret.add(br.readLine());
      ret.add(br.readLine());
      ret.add(br.readLine());

      while (true) {
        String cat = br.readLine();
        ;

        if (cat == null) {
          break;
        } else {
          ret.add(cat);
        }
      }

      Logger.logOnly("Last word loaded! " + ret.get(0));

      fr.close();
      br.close();

      return ret;
    } catch (IOException ex) {
      Logger.logOnly(ex.getMessage());
    } catch (NumberFormatException ex) {
      Logger.logOnlyError(ex.getMessage());
    }

    return null;
  }