예제 #1
0
 public static File createTessDataFolder() {
   String folderParentName = "stpdata";
   String folderTessDataName = "tessdata";
   File storageDir = mContext.getFilesDir();
   Log.i("createTessDataFolder", storageDir.getAbsolutePath());
   // File folderTess = new File(mContext.getFilesDir() + "/" + folderName);
   File folderTessPar = new File(mContext.getFilesDir(), folderParentName);
   if (!folderTessPar.exists()) {
     folderTessPar.mkdirs();
   }
   File folderTess = new File(folderTessPar, folderTessDataName);
   if (!folderTess.exists()) {
     folderTess.mkdirs();
   }
   return folderTess;
 }
예제 #2
0
  @Override
  protected void onPostExecute(File result) {
    super.onPostExecute(result);

    SharedPreferences sharePref =
        mContext.getSharedPreferences(Constant.PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
    Editor edit = sharePref.edit();
    edit.putBoolean(Constant.KEY_IS_DATA_COPIED, true);
    edit.putString(Constant.KEY_PATH_TESS_DATA, result.getParent());
    edit.putString(Constant.KEY_LANG_TESS, "vie");
    edit.commit();
  }
예제 #3
0
  public static void createTessDataNotAsync() {
    InputStream in = mContext.getResources().openRawResource(R.raw.vie);
    OutputStream out = null;
    File folder = null;
    folder = createTessDataFolder();
    if (folder == null) {
      throw new NullPointerException("Not able to create tessData");
    }

    File fileCP = new File(folder, "/vie.traineddata");
    try {
      out = new FileOutputStream(fileCP);
      byte[] buffer = new byte[1024];
      int countRead = 0;
      while ((countRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, countRead);
      }
    } catch (FileNotFoundException fnfE) {
      fnfE.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        in.close();
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    File tessdataFolder = fileCP.getParentFile();
    SharedPreferences sharePref =
        mContext.getSharedPreferences(Constant.PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
    Editor edit = sharePref.edit();
    edit.putBoolean(Constant.KEY_IS_DATA_COPIED, true);
    edit.putString(Constant.KEY_PATH_TESS_DATA, tessdataFolder.getParent());
    edit.putString(Constant.KEY_LANG_TESS, "vie");
    edit.commit();
  }