@Override
 public Notification build(Builder b) {
   postJellyBeanBuilder = new Notification.Builder(b.mContext);
   postJellyBeanBuilder
       .setContentTitle(b.mContentTitle)
       .setContentText(b.mContentText)
       .setTicker(b.mNotification.tickerText)
       .setSmallIcon(b.mNotification.icon, b.mNotification.iconLevel)
       .setContentIntent(b.mContentIntent)
       .setDeleteIntent(b.mNotification.deleteIntent)
       .setAutoCancel((b.mNotification.flags & Notification.FLAG_AUTO_CANCEL) != 0)
       .setLargeIcon(b.mLargeIcon)
       .setDefaults(b.mNotification.defaults);
   if (b.mStyle != null) {
     if (b.mStyle instanceof Builder.BigTextStyle) {
       Builder.BigTextStyle staticStyle = (Builder.BigTextStyle) b.mStyle;
       Notification.BigTextStyle style =
           new Notification.BigTextStyle(postJellyBeanBuilder)
               .setBigContentTitle(staticStyle.mBigContentTitle)
               .bigText(staticStyle.mBigText);
       if (staticStyle.mSummaryTextSet) {
         style.setSummaryText(staticStyle.mSummaryText);
       }
     }
   }
   return postJellyBeanBuilder.build();
 }
  /**
   * 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;
  }
 public void a(CharSequence paramCharSequence1, boolean paramBoolean, CharSequence paramCharSequence2, CharSequence paramCharSequence3)
 {
   Notification.BigTextStyle localBigTextStyle = new Notification.BigTextStyle(this.a).setBigContentTitle(paramCharSequence1).bigText(paramCharSequence3);
   if (paramBoolean)
     localBigTextStyle.setSummaryText(paramCharSequence2);
 }
  private void buildNotification() {

    int count =
        (data.getSize() >= Integer.valueOf(SettingUtility.getMsgCount())
            ? unreadBean.getMention_status()
            : data.getSize());

    Notification.Builder builder =
        new Notification.Builder(getBaseContext())
            .setTicker(ticker)
            .setContentText(accountBean.getUsernick())
            .setSmallIcon(R.drawable.ic_notification)
            .setAutoCancel(true)
            .setContentIntent(getPendingIntent())
            .setOnlyAlertOnce(true);

    builder.setContentTitle(
        String.format(
            GlobalContext.getInstance().getString(R.string.new_mentions_weibo),
            String.valueOf(count)));

    if (data.getSize() > 1) {
      builder.setNumber(count);
    }

    if (clearNotificationEventReceiver != null) {
      Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
          GlobalContext.getInstance(), clearNotificationEventReceiver);
      JBMentionsWeiboNotificationServiceHelper.clearNotificationEventReceiver = null;
    }

    clearNotificationEventReceiver =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        try {
                          new ClearUnreadDao(accountBean.getAccess_token())
                              .clearMentionStatusUnread(unreadBean, accountBean.getUid());

                        } catch (WeiboException ignored) {

                        } finally {
                          Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
                              GlobalContext.getInstance(), clearNotificationEventReceiver);
                          JBMentionsWeiboNotificationServiceHelper.clearNotificationEventReceiver =
                              null;
                        }
                      }
                    })
                .start();
          }
        };

    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);

    Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    PendingIntent deletedPendingIntent =
        PendingIntent.getBroadcast(
            GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);

    Intent intent = new Intent(getApplicationContext(), WriteCommentActivity.class);
    intent.putExtra("token", accountBean.getAccess_token());
    intent.putExtra("msg", data.getItem(0));

    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(
        R.drawable.comment_light,
        getApplicationContext().getString(R.string.comments),
        pendingIntent);

    if (data.getSize() > 1) {
      Intent nextIntent =
          new Intent(
              JBMentionsWeiboNotificationServiceHelper.this,
              JBMentionsWeiboNotificationServiceHelper.class);
      nextIntent.putExtra(NotificationServiceHelper.ACCOUNT_ARG, accountBean);
      nextIntent.putExtra(NotificationServiceHelper.MENTIONS_WEIBO_ARG, data);
      nextIntent.putExtra(NotificationServiceHelper.UNREAD_ARG, unreadBean);
      nextIntent.putExtra(
          NotificationServiceHelper.PENDING_INTENT_INNER_ARG, clickToOpenAppPendingIntentInner);
      nextIntent.putExtra(NotificationServiceHelper.TICKER, ticker);

      String actionName;
      int nextIndex;
      int actionDrawable;
      if (currentIndex < data.getSize() - 1) {
        nextIndex = currentIndex + 1;
        actionName = getString(R.string.next_message);
        actionDrawable = R.drawable.notification_action_next;
      } else {
        nextIndex = 0;
        actionName = getString(R.string.first_message);
        actionDrawable = R.drawable.notification_action_previous;
      }
      nextIntent.putExtra(NotificationServiceHelper.CURRENT_INDEX_ARG, nextIndex);
      PendingIntent retrySendIntent =
          PendingIntent.getService(
              JBMentionsWeiboNotificationServiceHelper.this,
              0,
              nextIntent,
              PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(actionDrawable, actionName, retrySendIntent);
    }

    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
    if (data.getItem(currentIndex).getText().contains(accountBean.getUsernick())) {
      // mentioned you
      bigTextStyle.setBigContentTitle(
          "@"
              + data.getItem(currentIndex).getUser().getScreen_name()
              + getString(R.string.weibo_at_to_you));
    } else {
      // retweeted your weibo
      bigTextStyle.setBigContentTitle(
          "@"
              + data.getItem(currentIndex).getUser().getScreen_name()
              + getString(R.string.retweeted_your_weibo));
    }
    bigTextStyle.bigText(data.getItem(currentIndex).getText());
    String summaryText;
    if (data.getSize() > 1) {
      summaryText =
          accountBean.getUsernick() + "(" + (currentIndex + 1) + "/" + data.getSize() + ")";
    } else {
      summaryText = accountBean.getUsernick();
    }
    bigTextStyle.setSummaryText(summaryText);

    builder.setStyle(bigTextStyle);
    Utility.configVibrateLedRingTone(builder);

    NotificationManager notificationManager =
        (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
  }
  private void buildNotification(String uid) {

    final ValueWrapper valueWrapper = valueBagHashMap.get(uid);

    if (valueWrapper == null) {
      return;
    }

    final AccountBean accountBean = valueWrapper.accountBean;

    final MessageListBean mentionsWeibo = valueWrapper.mentionsWeibo;

    final CommentListBean mentionsComment = valueWrapper.mentionsComment;

    final CommentListBean commentsToMe = valueWrapper.commentsToMe;

    final UnreadBean unreadBean = valueWrapper.unreadBean;

    int currentIndex = valueWrapper.currentIndex;

    Intent clickToOpenAppPendingIntentInner = valueWrapper.clickToOpenAppPendingIntentInner;

    String ticker = valueWrapper.ticker;

    ArrayList<Parcelable> notificationItems = valueWrapper.notificationItems;

    //        int count = Math.min(unreadBean.getMention_status(), data.getSize());

    int count = notificationItems.size();

    if (count == 0) {
      return;
    }

    Parcelable itemBean = notificationItems.get(currentIndex);

    Notification.Builder builder =
        new Notification.Builder(getBaseContext())
            .setTicker(ticker)
            .setContentText(ticker)
            .setSubText(accountBean.getUsernick())
            .setSmallIcon(R.drawable.ic_notification)
            .setAutoCancel(true)
            .setContentIntent(
                getPendingIntent(clickToOpenAppPendingIntentInner, itemBean, accountBean))
            .setOnlyAlertOnce(true);

    builder.setContentTitle(getString(R.string.app_name));

    if (count > 1) {
      builder.setNumber(count);
    }

    Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
        GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver);

    valueWrapper.clearNotificationEventReceiver =
        new RecordOperationAppBroadcastReceiver() {

          // mark these messages as read, write to database
          @Override
          public void onReceive(Context context, Intent intent) {
            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        try {
                          ArrayList<String> ids = new ArrayList<String>();

                          if (mentionsWeibo != null) {
                            for (MessageBean msg : mentionsWeibo.getItemList()) {
                              ids.add(msg.getId());
                            }

                            NotificationDBTask.addUnreadNotification(
                                accountBean.getUid(),
                                ids,
                                NotificationDBTask.UnreadDBType.mentionsWeibo);
                          }

                          ids.clear();

                          if (commentsToMe != null) {

                            for (CommentBean msg : commentsToMe.getItemList()) {
                              ids.add(msg.getId());
                            }

                            NotificationDBTask.addUnreadNotification(
                                accountBean.getUid(),
                                ids,
                                NotificationDBTask.UnreadDBType.commentsToMe);
                          }
                          ids.clear();
                          if (mentionsComment != null) {
                            for (CommentBean msg : mentionsComment.getItemList()) {
                              ids.add(msg.getId());
                            }

                            NotificationDBTask.addUnreadNotification(
                                accountBean.getUid(),
                                ids,
                                NotificationDBTask.UnreadDBType.mentionsComment);
                          }
                        } finally {
                          Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
                              GlobalContext.getInstance(),
                              valueWrapper.clearNotificationEventReceiver);
                          if (Utility.isDebugMode()) {

                            new Handler(Looper.getMainLooper())
                                .post(
                                    new Runnable() {
                                      @Override
                                      public void run() {
                                        Toast.makeText(
                                                getApplicationContext(),
                                                "weiciyuan:remove notification items"
                                                    + System.currentTimeMillis(),
                                                Toast.LENGTH_SHORT)
                                            .show();
                                      }
                                    });
                          }
                        }
                      }
                    })
                .start();
          }
        };

    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    Utility.registerReceiverIgnoredReceiverHasRegisteredHereException(
        GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver, intentFilter);

    Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    PendingIntent deletedPendingIntent =
        PendingIntent.getBroadcast(
            GlobalContext.getInstance(),
            accountBean.getUid().hashCode(),
            broadcastIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);

    if (itemBean instanceof MessageBean) {
      MessageBean msg = (MessageBean) itemBean;
      Intent intent =
          WriteCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, msg);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(
          R.drawable.comment_light,
          getApplicationContext().getString(R.string.comments),
          pendingIntent);
    } else if (itemBean instanceof CommentBean) {
      CommentBean commentBean = (CommentBean) itemBean;
      Intent intent =
          WriteReplyToCommentActivity.newIntentFromNotification(
              getApplicationContext(), accountBean, commentBean);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(
          R.drawable.reply_to_comment_light,
          getApplicationContext().getString(R.string.reply_to_comment),
          pendingIntent);
    }

    String avatar = ((ItemBean) itemBean).getUser().getAvatar_large();
    String avatarPath = FileManager.getFilePathFromUrl(avatar, FileLocationMethod.avatar_large);
    if (ImageUtility.isThisBitmapCanRead(avatarPath) && TaskCache.isThisUrlTaskFinished(avatar)) {
      Bitmap bitmap = BitmapFactory.decodeFile(avatarPath, new BitmapFactory.Options());
      if (bitmap != null) {
        builder.setLargeIcon(bitmap);
      }
    }

    if (count > 1) {

      String actionName;
      int nextIndex;
      int actionDrawable;
      if (currentIndex < count - 1) {
        nextIndex = currentIndex + 1;
        actionName = getString(R.string.next_message);
        actionDrawable = R.drawable.notification_action_next;
      } else {
        nextIndex = 0;
        actionName = getString(R.string.first_message);
        actionDrawable = R.drawable.notification_action_previous;
      }
      Intent nextIntent =
          BigTextNotificationService.newIntent(
              accountBean,
              mentionsWeibo,
              commentsToMe,
              mentionsComment,
              unreadBean,
              clickToOpenAppPendingIntentInner,
              ticker,
              nextIndex);
      PendingIntent retrySendIntent =
          PendingIntent.getService(
              BigTextNotificationService.this,
              accountBean.getUid().hashCode(),
              nextIntent,
              PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(actionDrawable, actionName, retrySendIntent);
    }

    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
    bigTextStyle.setBigContentTitle(
        getItemBigContentTitle(accountBean, notificationItems, currentIndex));
    bigTextStyle.bigText(getItemBigText(notificationItems, currentIndex));
    String summaryText;
    if (count > 1) {
      summaryText = accountBean.getUsernick() + "(" + (currentIndex + 1) + "/" + count + ")";
    } else {
      summaryText = accountBean.getUsernick();
    }
    bigTextStyle.setSummaryText(summaryText);

    builder.setStyle(bigTextStyle);
    Utility.configVibrateLedRingTone(builder);

    NotificationManager notificationManager =
        (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
  }