Ejemplo n.º 1
0
  /**
   * Updates the contents of the service's notifications. Should be called before
   * setupNotificationBuilders.
   */
  @SuppressLint("NewApi")
  private Notification updateNotifications() {
    String contentTitle = getString(R.string.download_notification_title);
    int numDownloads = requester.getNumberOfDownloads();
    String downloadsLeft;
    if (numDownloads > 0) {
      downloadsLeft = requester.getNumberOfDownloads() + getString(R.string.downloads_left);
    } else {
      downloadsLeft = getString(R.string.downloads_processing);
    }
    if (android.os.Build.VERSION.SDK_INT >= 16) {

      if (notificationBuilder != null) {

        StringBuilder bigText = new StringBuilder("");
        for (int i = 0; i < downloads.size(); i++) {
          Downloader downloader = downloads.get(i);
          final DownloadRequest request = downloader.getDownloadRequest();
          if (request.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
            if (request.getTitle() != null) {
              if (i > 0) {
                bigText.append("\n");
              }
              bigText.append("\u2022 " + request.getTitle());
            }
          } else if (request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
            if (request.getTitle() != null) {
              if (i > 0) {
                bigText.append("\n");
              }
              bigText.append(
                  "\u2022 " + request.getTitle() + " (" + request.getProgressPercent() + "%)");
            }
          }
        }
        notificationBuilder.setSummaryText(downloadsLeft);
        notificationBuilder.setBigContentTitle(contentTitle);
        if (bigText != null) {
          notificationBuilder.bigText(bigText.toString());
        }
        return notificationBuilder.build();
      }
    } else {
      if (notificationCompatBuilder != null) {
        notificationCompatBuilder.setContentTitle(contentTitle);
        notificationCompatBuilder.setContentText(downloadsLeft);
        return notificationCompatBuilder.build();
      }
    }
    return null;
  }