use of android.app.PendingIntent in project weiciyuan by qii.
the class JBInboxNotification method getPendingIntent.
private PendingIntent getPendingIntent() {
Intent i = new Intent(context, MainTimeLineActivity.class);
i.putExtra("account", accountBean);
i.putExtra("comment", comment);
i.putExtra("repost", repost);
i.putExtra("mentionsComment", mentionCommentsResult);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, Long.valueOf(accountBean.getUid()).intValue(), i, PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}
use of android.app.PendingIntent in project weiciyuan by qii.
the class JBInboxNotification method get.
public Notification get() {
Notification.Builder builder = new Notification.Builder(context).setTicker(NotificationUtility.getTicker(unreadBean, null, null, null)).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent()).setOnlyAlertOnce(true);
builder.setContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
if (NotificationUtility.getCount(unreadBean) > 1) {
builder.setNumber(NotificationUtility.getCount(unreadBean));
}
if (clearNotificationEventReceiver != null) {
GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
JBInboxNotification.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());
new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
} catch (WeiboException ignored) {
} finally {
GlobalContext.getInstance().unregisterReceiver(clearNotificationEventReceiver);
JBInboxNotification.clearNotificationEventReceiver = null;
}
}
}).start();
}
};
IntentFilter intentFilter = new IntentFilter("org.qii.weiciyuan.Notification.unread");
GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver, intentFilter);
Intent broadcastIntent = new Intent("org.qii.weiciyuan.Notification.unread");
PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setDeleteIntent(deletedPendingIntent);
Notification.InboxStyle inboxStyle = new Notification.InboxStyle(builder);
inboxStyle.setBigContentTitle(NotificationUtility.getTicker(unreadBean, null, null, null));
if (comment != null) {
for (CommentBean c : comment.getItemList()) {
inboxStyle.addLine(c.getUser().getScreen_name() + ":" + c.getText());
}
}
if (repost != null) {
for (MessageBean m : repost.getItemList()) {
inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
}
}
if (mentionCommentsResult != null) {
for (CommentBean m : mentionCommentsResult.getItemList()) {
inboxStyle.addLine(m.getUser().getScreen_name() + ":" + m.getText());
}
}
inboxStyle.setSummaryText(accountBean.getUsernick());
builder.setStyle(inboxStyle);
Utility.configVibrateLedRingTone(builder);
return builder.build();
}
use of android.app.PendingIntent in project weiciyuan by qii.
the class JBMentionsCommentNotificationServiceHelper method getPendingIntent.
private PendingIntent getPendingIntent() {
clickToOpenAppPendingIntentInner.setExtrasClassLoader(getClass().getClassLoader());
clickToOpenAppPendingIntentInner.putExtra(BundleArgsConstants.OPEN_NAVIGATION_INDEX_EXTRA, UnreadTabIndex.MENTION_COMMENT);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, clickToOpenAppPendingIntentInner, PendingIntent.FLAG_UPDATE_CURRENT);
return pendingIntent;
}
use of android.app.PendingIntent in project weiciyuan by qii.
the class JBMentionsCommentNotificationServiceHelper method buildNotification.
private void buildNotification() {
// int count = (data.getSize() >= Integer.valueOf(SettingUtility.getMsgCount()) ? unreadBean
// .getMention_cmt() : data.getSize());
int count = Math.min(unreadBean.getMention_cmt(), data.getSize());
if (count == 0) {
return;
}
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_comment), String.valueOf(count)));
if (count > 1) {
builder.setNumber(count);
}
if (clearNotificationEventReceiver.get(accountBean.getUid()) != null) {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver.get(accountBean.getUid()));
JBMentionsCommentNotificationServiceHelper.clearNotificationEventReceiver.put(accountBean.getUid(), null);
}
RecordOperationAppBroadcastReceiver receiver = new RecordOperationAppBroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// new ClearUnreadDao(accountBean.getAccess_token())
// .clearMentionCommentUnread(unreadBean, accountBean.getUid());
// } catch (WeiboException ignored) {
ArrayList<String> ids = new ArrayList<String>();
for (CommentBean msg : data.getItemList()) {
ids.add(msg.getId());
}
NotificationDBTask.addUnreadNotification(accountBean.getUid(), ids, NotificationDBTask.UnreadDBType.mentionsComment);
} finally {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver.get(accountBean.getUid()));
JBMentionsCommentNotificationServiceHelper.clearNotificationEventReceiver.put(accountBean.getUid(), null);
}
}
}).start();
}
};
clearNotificationEventReceiver.put(accountBean.getUid(), receiver);
IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_COMMENT_ACTION);
GlobalContext.getInstance().registerReceiver(receiver, intentFilter);
Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_COMMENT_ACTION);
PendingIntent deletedPendingIntent = PendingIntent.getBroadcast(GlobalContext.getInstance(), 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setDeleteIntent(deletedPendingIntent);
Intent intent = WriteReplyToCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, data.getItem(currentIndex));
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);
if (count > 1) {
Intent nextIntent = new Intent(JBMentionsCommentNotificationServiceHelper.this, JBMentionsCommentNotificationServiceHelper.class);
nextIntent.putExtra(NotificationServiceHelper.ACCOUNT_ARG, accountBean);
nextIntent.putExtra(NotificationServiceHelper.MENTIONS_COMMENT_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 < 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;
}
nextIntent.putExtra(NotificationServiceHelper.CURRENT_INDEX_ARG, nextIndex);
PendingIntent retrySendIntent = PendingIntent.getService(JBMentionsCommentNotificationServiceHelper.this, 0, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(actionDrawable, actionName, retrySendIntent);
}
Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
bigTextStyle.setBigContentTitle("@" + data.getItem(currentIndex).getUser().getScreen_name() + getString(R.string.comment_at_to_you));
bigTextStyle.bigText(data.getItem(currentIndex).getText());
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(getMentionsCommentNotificationId(accountBean), builder.build());
}
use of android.app.PendingIntent in project weiciyuan by qii.
the class JBMentionsWeiboNotificationServiceHelper method buildNotification.
private void buildNotification() {
// int count = (data.getSize() >= Integer.valueOf(SettingUtility.getMsgCount()) ? unreadBean
// .getMention_status() : data.getSize());
int count = Math.min(unreadBean.getMention_status(), data.getSize());
if (count == 0) {
return;
}
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 (count > 1) {
builder.setNumber(count);
}
if (clearNotificationEventReceiver.get(accountBean.getUid()) != null) {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver.get(accountBean.getUid()));
JBMentionsWeiboNotificationServiceHelper.clearNotificationEventReceiver.put(accountBean.getUid(), null);
}
RecordOperationAppBroadcastReceiver receiver = new RecordOperationAppBroadcastReceiver() {
@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());
ArrayList<String> ids = new ArrayList<String>();
for (MessageBean msg : data.getItemList()) {
ids.add(msg.getId());
}
NotificationDBTask.addUnreadNotification(accountBean.getUid(), ids, NotificationDBTask.UnreadDBType.mentionsWeibo);
// } catch (WeiboException ignored) {
} finally {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver.get(accountBean.getUid()));
JBMentionsWeiboNotificationServiceHelper.clearNotificationEventReceiver.put(accountBean.getUid(), null);
}
}
}).start();
}
};
clearNotificationEventReceiver.put(accountBean.getUid(), receiver);
IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
GlobalContext.getInstance().registerReceiver(clearNotificationEventReceiver.get(accountBean.getUid()), 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 = WriteCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, data.getItem(currentIndex));
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.comment_light, getApplicationContext().getString(R.string.comments), pendingIntent);
if (count > 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 < 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;
}
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 (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());
}
Aggregations