private static List<OCRLanguage> getAllOCRLanguages(Context context) {
    List<OCRLanguage> languages = new ArrayList<OCRLanguage>();
    // actual values uses by tesseract
    final String[] languageValues = context.getResources().getStringArray(R.array.ocr_languages);
    // values shown to the user
    final String[] languageDisplayValues = new String[languageValues.length];
    for (int i = 0; i < languageValues.length; i++) {
      final String val = languageValues[i];
      final int firstSpace = val.indexOf(' ');
      languageDisplayValues[i] =
          languageValues[i].substring(firstSpace + 1, languageValues[i].length());
      languageValues[i] = languageValues[i].substring(0, firstSpace);
    }
    final List<Pair<String, Long>> installedLanguages = getInstalledLanguages(context);
    for (int i = 0; i < languageValues.length; i++) {
      boolean downloaded = false;
      long size = 0;
      for (Pair<String, Long> installedLang : installedLanguages) {
        if (installedLang.first.equalsIgnoreCase(languageValues[i])) {
          downloaded = true;
          size = installedLang.second;
          break;
        }
      }
      OCRLanguage language =
          new OCRLanguage(languageValues[i], languageDisplayValues[i], downloaded, size);
      if (language.needsCubeData && getCubeFilesForLanguage(language.mValue, context).length == 0) {
        language.mDownloaded = false;
      }

      languages.add(language);
    }
    return languages;
  }
 protected void updateLanguageList(String lang, int status) {
   for (int i = 0; i < mAdapter.getCount(); i++) {
     final OCRLanguage language = (OCRLanguage) mAdapter.getItem(i);
     if (language.getValue().equalsIgnoreCase(lang)) {
       updateLanguage(language, status);
       return;
     }
   }
 }
 protected void updateLanguageListByDisplayValue(String displayValue, int status) {
   for (int i = 0; i < mAdapter.getCount(); i++) {
     final OCRLanguage language = (OCRLanguage) mAdapter.getItem(i);
     if (language.getDisplayText().equalsIgnoreCase(displayValue)) {
       updateLanguage(language, status);
       return;
     }
   }
 }
  private void updateLanguage(final OCRLanguage language, int status) {
    language.mDownloading = false;
    if (status == DownloadManager.STATUS_SUCCESSFUL) {
      language.mDownloaded = true;
    } else {
      language.mDownloaded = false;
      runOnUiThread(
          new Runnable() {

            @Override
            public void run() {
              String msg = getString(R.string.download_failed);
              msg = String.format(msg, language.mDisplayText);
              Toast.makeText(OCRLanguageActivity.this, msg, Toast.LENGTH_LONG).show();
            }
          });
    }
    mAdapter.notifyDataSetChanged();
  }