コード例 #1
0
 public static void start() {
   // ChumbyLog.i("NotificationEvents.start()");
   final Handler handler =
       new Handler() {
         public void handleMessage(Message message) {
           switch (message.what) {
             case POLL_NOTIFICATIONS:
               NotificationEvents.getInstance().fetch();
               break;
             default:
               super.handleMessage(message);
           }
           this.sendMessageDelayed(Message.obtain(this, POLL_NOTIFICATIONS), POLL_INTERVAL);
         }
       };
   handler.sendMessageDelayed(Message.obtain(handler, POLL_NOTIFICATIONS), POLL_INTERVAL);
 }
コード例 #2
0
ファイル: D4.java プロジェクト: sarekautowerke/D4
  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);
        }
      }
    }
  }