Exemplo n.º 1
0
  private static final List<Pair<String, Long>> getInstalledLanguages(Context appContext) {
    final List<Pair<String, Long>> result = new ArrayList<Pair<String, Long>>();
    final File tessDir = Util.getTrainingDataDir(appContext);
    if (!tessDir.exists()) {
      return result;
    }
    final String[] languageFiles =
        tessDir.list(
            new FilenameFilter() {

              @Override
              public boolean accept(File dir, String filename) {
                if (filename.endsWith(".traineddata")) {
                  return true;
                }
                return false;
              }
            });

    for (final String val : languageFiles) {
      final int dotIndex = val.indexOf('.');
      if (dotIndex > -1) {
        File f = new File(tessDir, val);
        result.add(Pair.create(val.substring(0, dotIndex), f.length()));
      }
    }
    return result;
  }
  /** @return if the language assets are installed or not */
  public static boolean IsInstalled(Context appContext) {

    // check directories
    File tessDir = Util.getTrainingDataDir(appContext);

    if (!tessDir.exists()) {
      return false;
    }

    return true;
  }
Exemplo n.º 3
0
    private boolean deleteLanguage(final OCRLanguage language) {
      File tessDir = Util.getTrainingDataDir(OCRLanguageActivity.this);
      if (!tessDir.exists()) {
        return false;
      }

      File lang = new File(tessDir, language.mValue + ".traineddata");
      final String[] list = getCubeFilesForLanguage(language.mValue, OCRLanguageActivity.this);
      for (String fileName : list) {
        File f = new File(tessDir, fileName);
        f.delete();
      }
      if (lang.delete()) {
        return true;
      }
      return false;
    }
Exemplo n.º 4
0
 private static String[] getCubeFilesForLanguage(String language, final Context context) {
   final String prefix = language + ".cube";
   File tessDir = Util.getTrainingDataDir(context);
   if (!tessDir.exists()) {
     return new String[0];
   }
   final String[] list =
       tessDir.list(
           new FilenameFilter() {
             @Override
             public boolean accept(File dir, String filename) {
               if (filename != null && filename.startsWith(prefix)) {
                 return true;
               }
               return false;
             }
           });
   if (list == null) {
     return new String[0];
   } else {
     return list;
   }
 }