Exemplo n.º 1
0
 private void sendExceptionMsg(int what, Exception e) {
   e.printStackTrace();
   Message msg = Message.obtain();
   msg.obj = e;
   msg.what = what;
   queryHandler.sendMessage(msg);
 }
Exemplo n.º 2
0
  public void getFilesFromFolder(List filesAndFolders, String savePath) {
    // create a File object for the parent directory
    File downloadsDirectory = new File(savePath);
    // create the folder if needed.
    downloadsDirectory.mkdir();

    for (int i = 0; i < filesAndFolders.size(); i++) {
      Object links = filesAndFolders.get(i);
      List linksArray = (ArrayList) links;
      if (i == 0) {
        for (int j = 0; j < linksArray.size(); j += 2) {
          // We've got an array of file urls so download each one to a directory with the folder
          // name
          String fileURL = linksArray.get(j).toString();
          String fileName = linksArray.get(j + 1).toString();
          downloadFile(fileURL, savePath, fileName);
          progress++;
          Message msg = mHandler.obtainMessage();
          msg.arg1 = progress;
          mHandler.sendMessage(msg);
        }
      } else if (i == 1) {
        // we've got an array of folders so recurse down the levels, extracting subfolders and files
        // until we've downloaded everything.
        for (int j = 0; j < linksArray.size(); j += 2) {
          String folderURL = linksArray.get(j).toString();
          String folderName = linksArray.get(j + 1).toString();

          String page = getData(folderURL);
          List newFilesAndFolders = parsePage(page);
          String dlDirPath = savePath + folderName + "/";

          getFilesFromFolder(newFilesAndFolders, dlDirPath);
        }
      }
    }
  }
Exemplo n.º 3
0
  public void run() {
    OfxRequest req = session.newRequest();
    AccountInfoMsgReq acctReq = new AccountInfoMsgReq();
    acctReq.acctListAge = session.profile.acctListAge;
    req.addRequest(acctReq);

    List<OfxMessageResp> response;
    try {
      response = req.submit(this);

      for (OfxMessageResp resp : response) {
        if (resp instanceof AccountInfoMsgResp) {
          AccountInfoMsgResp acctResp = (AccountInfoMsgResp) resp;
          session.profile.acctListAge = acctResp.acctListAge;
          accountList = acctResp.accounts;
        }
      }
    } catch (HttpResponseException e) {
      sendExceptionMsg(QH_ERR_STATUS, e);
    } catch (OfxError e) {
      sendExceptionMsg(QH_ERR_OFX, e);
    } catch (XmlPullParserException e) {
      sendExceptionMsg(QH_ERR_PARSE, e);
    } catch (SSLPeerUnverifiedException e) {
      sendExceptionMsg(QH_ERR_SSL_VERIFY, e);
    } catch (ClientProtocolException e) {
      sendExceptionMsg(QH_ERR_HTTP, e);
    } catch (ConnectException e) {
      sendExceptionMsg(QH_ERR_TIMEOUT, e);
    } catch (SocketException e) {
      sendExceptionMsg(QH_ERR_CONN, e);
    } catch (SSLException e) {
      sendExceptionMsg(QH_ERR_SSL, e);
    } catch (Exception e) {
      sendExceptionMsg(QH_ERR, e);
    }

    ProfileTable db = new ProfileTable(this);
    try {
      db.openWritable();
      db.syncAccounts(session, accountList);
    } catch (SQLiteException e) {
      sendExceptionMsg(QH_ERR, e);
    } finally {
      db.close();
    }

    queryHandler.sendEmptyMessage(QH_OK);
  }
  @Override
  public void handleDownloadThreadUpdate() {
    handler.post(
        new Runnable() {

          @Override
          public void run() {
            // total_files_to_download = downloadThread.getTotalQueued();
            total_files_to_download = links.size();
            if (downloadThread != null) {
              completed_downloads = downloadThread.getTotalCompleted() + initial_value;
            } else {
              completed_downloads = readProgress()[0];
            }

            progress_download.setMax(links.size());
            // progress_download.incrementProgressBy(1);
            progress_download.setProgress(0); // need to do it due to a ProgressBar bug
            progress_download.setProgress(completed_downloads);

            progress_text.setText(
                "Downloading "
                    + Integer.toString(completed_downloads + 1)
                    + " of "
                    + Integer.toString(links.size())
                    + ".");

            // writeProgress(completed_downloads,total_files_to_download);

            if (completed_downloads == total_files_to_download) {
              completed = true;
              writeProgress(completed_downloads, total_files_to_download);
              if (resume_pause.VISIBLE != View.GONE) resume_pause.setVisibility(View.GONE);
              downloadThread.requestStop();
              progress_text.setText("Completed.");
            }
          }
        });
  }