/** Gets all relevant transfers from the Transfer Service for populating the UI */
  private void initData() {
    transferRecordMaps.clear();
    // Use TransferUtility to get all upload transfers.
    observers = transferUtility.getTransfersWithType(TransferType.UPLOAD);
    TransferListener listener = new UploadListener();
    for (TransferObserver observer : observers) {

      // For each transfer we will will create an entry in
      // transferRecordMaps which will display
      // as a single row in the UI
      HashMap<String, Object> map = new HashMap<String, Object>();
      Util.fillMap(map, observer, false);
      transferRecordMaps.add(map);

      // Sets listeners to in progress transfers
      if (TransferState.WAITING.equals(observer.getState())
          || TransferState.WAITING_FOR_NETWORK.equals(observer.getState())
          || TransferState.IN_PROGRESS.equals(observer.getState())) {
        observer.setTransferListener(listener);
      }
    }
    simpleAdapter.notifyDataSetChanged();
  }
예제 #2
0
 /*
  * Fills in the map with information in the observer so that it can be used
  * with a SimpleAdapter to populate the UI
  */
 public static void fillMap(
     Map<String, Object> map, TransferObserver observer, boolean isChecked) {
   int progress = (int) ((double) observer.getBytesTransferred() * 100 / observer.getBytesTotal());
   map.put("id", observer.getId());
   map.put("checked", isChecked);
   map.put("fileName", observer.getAbsoluteFilePath());
   map.put("progress", progress);
   map.put(
       "bytes",
       getBytesString(observer.getBytesTransferred())
           + "/"
           + getBytesString(observer.getBytesTotal()));
   map.put("state", observer.getState());
   map.put("percentage", progress + "%");
 }