use of android.app.Notification 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.Notification in project weiciyuan by qii.
the class SimpleTextNotificationService method buildNotification.
private void buildNotification(String uid) {
ValueWrapper valueWrapper = valueBagHashMap.get(uid);
if (valueWrapper == null) {
return;
}
final AccountBean accountBean = valueWrapper.accountBean;
final UnreadBean unreadBean = valueWrapper.unreadBean;
Intent clickToOpenAppPendingIntentInner = valueWrapper.clickToOpenAppPendingIntentInner;
String ticker = valueWrapper.ticker;
final RecordOperationAppBroadcastReceiver clearNotificationEventReceiver = valueWrapper.clearNotificationEventReceiver;
Notification.Builder builder = new Notification.Builder(getBaseContext()).setTicker(ticker).setContentText(accountBean.getUsernick()).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(getPendingIntent(clickToOpenAppPendingIntentInner)).setOnlyAlertOnce(true);
builder.setContentTitle(ticker);
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver);
valueWrapper.clearNotificationEventReceiver = 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());
new ClearUnreadDao(accountBean.getAccess_token()).clearMentionCommentUnread(unreadBean, accountBean.getUid());
new ClearUnreadDao(accountBean.getAccess_token()).clearCommentUnread(unreadBean, accountBean.getUid());
} catch (WeiboException ignored) {
} finally {
Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(GlobalContext.getInstance(), clearNotificationEventReceiver);
if (Utility.isDebugMode()) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "weiciyuan:remove notification items", Toast.LENGTH_SHORT).show();
}
});
}
}
}
}).start();
}
};
IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);
GlobalContext.getInstance().registerReceiver(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);
Utility.configVibrateLedRingTone(builder);
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
}
use of android.app.Notification in project weiciyuan by qii.
the class BigTextNotificationService method buildNotification.
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());
}
use of android.app.Notification in project howabout-android by recomio.
the class MusicPlayerService method play.
@SuppressWarnings("deprecation")
private void play(final String trackTitle, final String artistName, String thumbnailUrl) {
Notification notification = new Notification(R.drawable.ic_launcher, trackTitle + " - " + artistName, System.currentTimeMillis());
Intent intent = new Intent(this, MusicPlaylistActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, trackTitle, artistName, pendingIntent);
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(NOTIFICATION_ID, notification);
playlistAdapter.setCurrentLyrics("");
isLoaded = false;
isLoading = true;
mediaPlayer.stop();
mediaPlayer.reset();
if (playInfoRequest != null) {
contentManager.cancel(playInfoRequest);
playInfoRequest = null;
}
playInfoRequest = new PlayInfoRequest(trackTitle, artistName);
contentManager.execute(playInfoRequest, new RequestListener<PlayInfo>() {
@Override
public void onRequestFailure(SpiceException e) {
if (groovesharkStreamUrlGetter != null) {
groovesharkStreamUrlGetter.isStopped(true);
}
if (e instanceof RequestCancelledException) {
return;
}
isLoading = false;
playlistAdapter.playNext();
playlistAdapter.notifyDataSetChanged();
Toast.makeText(MusicPlayerService.this, trackTitle + "(" + artistName + ")" + "\n 무료 스트리밍 음원을 찾지 못했습니다.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestSuccess(final PlayInfo playInfo) {
playlistAdapter.setCurrentLyrics(playInfo.getLyrics());
Log.i("grooveshark", playInfo.getTrackTitle());
final String groovesharkSongId = playInfo.getTinysongId();
if (groovesharkSongId != null) {
HowaboutApplication application = (HowaboutApplication) getApplicationContext();
try {
groovesharkStreamUrlGetter = new GroovesharkStreamUrlGetter(application, groovesharkSongId, new OnGetGroovesharkStreamKey() {
@Override
public void sucess(String streamUrl) {
playInfo.setGroovesharkSongID(groovesharkSongId);
playInfo.setGroovesharkStreamUrl(streamUrl);
playStream(playInfo);
}
@Override
public void error(Exception e) {
playStream(playInfo);
}
});
groovesharkStreamUrlGetter.getGroovesharkStreamUrlAsync();
} catch (Exception e) {
playStream(playInfo);
}
} else {
playStream(playInfo);
}
}
});
}
use of android.app.Notification in project robolectric by robolectric.
the class ShadowNotificationBuilderTest method build_addsActionToNotification.
@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void build_addsActionToNotification() throws Exception {
PendingIntent action = PendingIntent.getBroadcast(RuntimeEnvironment.application, 0, null, 0);
Notification notification = builder.addAction(0, "Action", action).build();
assertThat(notification.actions[0].actionIntent).isEqualToComparingFieldByField(action);
}
Aggregations