예제 #1
0
  /**
   * 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
  /**
   * Saves a word to a txt.
   *
   * @param word Word to save.
   * @param letters Letters to save.
   * @param a Context.
   */
  public static void saveWord(Word word, String[] letters, Activity a) {
    File file = new File(Settings.getPath(a) + "/lastWord.txt");
    PrintWriter pWriter = null;

    try {
      pWriter = new PrintWriter(new BufferedWriter(new FileWriter(file), 8192));
      pWriter.println(word.getWord());
      pWriter.println(word.getCategory());
      pWriter.println(word.getDescription());

      for (int i = 0; i < letters.length; i++) {
        pWriter.println(letters[i]);
      }

      Logger.logOnly("Word saved!: " + word.getWord());

    } catch (IOException ex) {
      Logger.logOnly(ex.getMessage());
    } finally {
      if (pWriter != null) {
        pWriter.flush();
        pWriter.close();
      }
    }
  }
예제 #3
0
  /**
   * 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
  /**
   * 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;
  }
예제 #5
0
  /**
   * 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());
    }
  }
예제 #6
0
  /**
   * Saves the settings to a file.
   *
   * @param a Context to ave the file.
   * @since 0.3
   */
  public static void save(Activity a) {
    File file = new File(Settings.getPath(a) + "/settings.ini");
    PrintWriter pWriter = null;
    try {
      pWriter = new PrintWriter(new BufferedWriter(new FileWriter(file), 8192));
      pWriter.println(Settings.theme.ordinal());
      pWriter.println(Settings.getCurrentUser().getName());
      pWriter.println(Settings.getCurrentUser().getPassword());

      for (int i = 0; i < Settings.categories.size(); i++) {
        pWriter.println(Settings.categories.get(i));
      }

      Logger.logOnly("Settings saved!");
    } catch (IOException ex) {
      Logger.logOnly(ex.getMessage());
    } finally {
      if (pWriter != null) {
        pWriter.flush();
        pWriter.close();
      }
    }
  }
예제 #7
0
  /**
   * Saves a user local.
   *
   * @param a Context.
   * @param u User.
   */
  public static void saveCurrentUser(Activity a, User u) {
    File file = new File(Settings.getPath(a) + "/curUser.ini");
    PrintWriter pWriter = null;

    try {
      pWriter = new PrintWriter(new BufferedWriter(new FileWriter(file), 8192));
      pWriter.print(u.getName());
    } catch (IOException ex) {
      Logger.logOnly(ex.getMessage());
    } finally {
      if (pWriter != null) {
        pWriter.flush();
        pWriter.close();
      }
    }
  }