Ejemplo n.º 1
0
 private OCRLanguageAdapter initLanguageList() {
   OCRLanguageAdapter adapter = new OCRLanguageAdapter(getApplicationContext(), false);
   List<OCRLanguage> languages = getAllOCRLanguages(this);
   adapter.addAll(languages);
   updateLanguageListWithDownloadManagerStatus(adapter);
   return adapter;
 }
Ejemplo n.º 2
0
 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;
     }
   }
 }
Ejemplo n.º 3
0
 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;
     }
   }
 }
Ejemplo n.º 4
0
 private void updateLanguageListWithDownloadManagerStatus(OCRLanguageAdapter adapter) {
   if (adapter != null) {
     // find languages that are currently beeing downloaded
     Query query = new Query();
     query.setFilterByStatus(
         DownloadManager.STATUS_RUNNING
             | DownloadManager.STATUS_PENDING
             | DownloadManager.STATUS_PAUSED);
     final DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
     Cursor c = dm.query(query);
     int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_TITLE);
     while (c.moveToNext()) {
       final String title = c.getString(columnIndex);
       adapter.setDownloading(title, true);
     }
     adapter.notifyDataSetChanged();
     c.close();
   }
 }
Ejemplo n.º 5
0
  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();
  }