예제 #1
0
 /**
  * 5.search all
  *
  * @return
  */
 public List<DownloadBean> getAllCompletedTask() {
   List<DownloadBean> list = new ArrayList<DownloadBean>();
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   String sql =
       "select url, file_name, file_size, "
           + "done_time, icon_url, file_version, "
           + "file_version_code, package_name, "
           + "file_path, soft_id, download_id, version_code "
           + "from end_download_info order by done_time asc";
   Cursor cursor = null;
   try {
     cursor = database.rawQuery(sql, null);
     while (cursor.moveToNext()) {
       DownloadBean info = new DownloadBean();
       info.url = cursor.getString(0);
       info.fileName = cursor.getString(1);
       info.fileSize = cursor.getLong(2);
       info.doneTime = cursor.getLong(3);
       info.iconUrl = cursor.getString(4);
       info.fileVersion = cursor.getString(5);
       info.fileVersionCode = cursor.getInt(6);
       info.packageName = cursor.getString(7);
       info.savePath = cursor.getString(8);
       info.fileId = cursor.getString(9);
       info.downloadId = cursor.getString(10);
       info.versionCode = cursor.getInt(11);
       list.add(info);
     }
   } catch (Exception e) {
     Log.e(TAG, "getAllComplieteTask Error:" + e);
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return list;
 }
예제 #2
0
  /**
   * 5.search all results <url,bean>
   *
   * @return
   */
  public HashMap<String, ArrayList<DownloadBean>> getAllTasks() {
    HashMap<String, ArrayList<DownloadBean>> map = new HashMap<String, ArrayList<DownloadBean>>();
    SQLiteDatabase database = dbHelper.getReadableDatabase();
    String sql =
        "select url, file_name, "
            + "total_size, start_pos, end_pos, "
            + "compelete_size, thread_id, file_version, "
            + "file_version_code, package_name, "
            + "icon_url, soft_id, download_id, version_code "
            + "from download_info";
    Cursor cursor = null;
    try {
      cursor = database.rawQuery(sql, null);
      while (cursor.moveToNext()) {
        DownloadBean info = new DownloadBean();
        info.url = cursor.getString(0);
        info.fileName = cursor.getString(1);
        info.fileSize = cursor.getLong(2);
        info.startPosition = cursor.getLong(3);
        info.endPosition = cursor.getLong(4);
        info.currentPosition = cursor.getLong(5);
        info.threadId = cursor.getInt(6);
        info.fileVersion = cursor.getString(7);
        info.fileVersionCode = cursor.getInt(8);
        info.packageName = cursor.getString(9);
        info.iconUrl = cursor.getString(10);
        info.fileId = cursor.getString(11);
        info.downloadId = cursor.getString(12);
        info.versionCode = cursor.getInt(13);

        // update the list, contains by Map
        String mapKey = info.url + "_" + info.downloadId;
        if (map.containsKey(mapKey)) {
          map.get(mapKey).add(info);
        } else { // not exist in the map, create a new one
          ArrayList<DownloadBean> list = new ArrayList<DownloadBean>();
          list.add(info);
          map.put(mapKey, list);
        }
      }
    } catch (Exception e) {
      Log.e(TAG, "getAllTasks Error:" + e);
    } finally {
      if (cursor != null) {
        cursor.close();
      }
    }
    return map;
  }
예제 #3
0
 /**
  * 4.search by url
  *
  * @param urlstr
  * @return
  */
 public DownloadBean getCompleteTaskInfoByUrl(String urlstr, String downloadId) {
   DownloadBean info = new DownloadBean();
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   String sql =
       "select url, file_name, file_size, "
           + "done_time, icon_url, file_version, "
           + "file_version_code, package_name, "
           + "file_path, soft_id, download_id, version_code "
           + "from end_download_info "
           + "where url=? and download_id=?";
   Cursor cursor = null;
   try {
     cursor = database.rawQuery(sql, new String[] {urlstr, downloadId});
     while (cursor.moveToNext()) {
       info.url = cursor.getString(0);
       info.fileName = cursor.getString(1);
       info.fileSize = cursor.getLong(2);
       info.doneTime = cursor.getLong(3);
       info.iconUrl = cursor.getString(4);
       info.fileVersion = cursor.getString(5);
       info.fileVersionCode = cursor.getInt(6);
       info.packageName = cursor.getString(7);
       info.savePath = cursor.getString(8);
       info.fileId = cursor.getString(9);
       info.downloadId = cursor.getString(10);
       info.versionCode = cursor.getInt(11);
     }
   } catch (Exception e) {
     Log.e(TAG, "getCompleteTaskInfoByUrl Error:" + e);
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return info;
 }
예제 #4
0
 /**
  * 4.searching by url
  *
  * @param urlstr
  * @return
  */
 public ArrayList<DownloadBean> getDownloadTaskByUrl(String urlstr, String downloadId) {
   ArrayList<DownloadBean> list = new ArrayList<DownloadBean>();
   SQLiteDatabase database = dbHelper.getReadableDatabase();
   String sql =
       "select url, file_name, total_size, "
           + "start_pos, end_pos, compelete_size, "
           + "thread_id, file_version, file_version_code, "
           + "package_name, icon_url, soft_id, download_id, version_code "
           + "from download_info "
           + "where url=? and download_id=?";
   Cursor cursor = null;
   try {
     cursor = database.rawQuery(sql, new String[] {urlstr, downloadId});
     while (cursor.moveToNext()) {
       DownloadBean info = new DownloadBean();
       info.url = cursor.getString(0);
       info.fileName = cursor.getString(1);
       info.fileSize = cursor.getLong(2);
       info.startPosition = cursor.getLong(3);
       info.endPosition = cursor.getLong(4);
       info.currentPosition = cursor.getLong(5);
       info.threadId = cursor.getInt(6);
       info.fileVersion = cursor.getString(7);
       info.fileVersionCode = cursor.getInt(8);
       info.packageName = cursor.getString(9);
       info.iconUrl = cursor.getString(10);
       info.fileId = cursor.getString(11);
       info.downloadId = cursor.getString(12);
       info.versionCode = cursor.getInt(13);
       list.add(info);
     }
   } catch (Exception e) {
     Log.e(TAG, "getDownloadTaskByUrl Error:" + e);
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
   }
   return list;
 }