use of android.support.v4.app.NotificationCompat.Builder in project routerkeygenAndroid by routerkeygen.
the class UpdateCheckerService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
final LastVersion lastVersion = getLatestVersion();
if (lastVersion == null)
return;
if (!Preferences.VERSION.equals(lastVersion.version)) {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_notification).setTicker(getString(R.string.update_title)).setContentTitle(getString(R.string.update_title)).setContentText(getString(R.string.update_notification, lastVersion.version)).setOnlyAlertOnce(true).setAutoCancel(true).setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(Intent.ACTION_VIEW).setData(Uri.parse(lastVersion.url)), PendingIntent.FLAG_ONE_SHOT));
mNotificationManager.notify(UNIQUE_ID, builder.build());
}
}
use of android.support.v4.app.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method modifyForImage.
private void modifyForImage(final Builder builder, final Message message, final ArrayList<Message> messages) {
try {
final Bitmap bitmap = mXmppConnectionService.getFileBackend().getThumbnail(message, getPixel(288), false);
final ArrayList<Message> tmp = new ArrayList<>();
for (final Message msg : messages) {
if (msg.getType() == Message.TYPE_TEXT && msg.getTransferable() == null) {
tmp.add(msg);
}
}
final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
bigPictureStyle.bigPicture(bitmap);
if (tmp.size() > 0) {
CharSequence text = getMergedBodies(tmp);
bigPictureStyle.setSummaryText(text);
builder.setContentText(text);
} else {
builder.setContentText(mXmppConnectionService.getString(R.string.received_x_file, UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
}
builder.setStyle(bigPictureStyle);
} catch (final FileNotFoundException e) {
modifyForTextOnly(builder, messages);
}
}
use of android.support.v4.app.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method updateNotification.
public void updateNotification(final boolean notify) {
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final SharedPreferences preferences = mXmppConnectionService.getPreferences();
if (notifications.size() == 0) {
notificationManager.cancel(NOTIFICATION_ID);
} else {
if (notify) {
this.markLastNotification();
}
final Builder mBuilder;
if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
mBuilder = buildSingleConversations(notifications.values().iterator().next());
modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
} else {
mBuilder = buildMultipleConversation();
modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
Builder singleBuilder = buildSingleConversations(entry.getValue());
singleBuilder.setGroup(CONVERSATIONS_GROUP);
modifyForSoundVibrationAndLight(singleBuilder, notify, preferences);
notificationManager.notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
}
}
}
}
use of android.support.v4.app.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method buildMultipleConversation.
private Builder buildMultipleConversation() {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(notifications.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations));
final StringBuilder names = new StringBuilder();
Conversation conversation = null;
for (final ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
conversation = messages.get(0).getConversation();
final String name = conversation.getName();
SpannableString styledString;
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
int count = messages.size();
styledString = new SpannableString(name + ": " + mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
} else {
styledString = new SpannableString(name + ": " + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
}
names.append(name);
names.append(", ");
}
}
if (names.length() >= 2) {
names.delete(names.length() - 2, names.length());
}
mBuilder.setContentTitle(notifications.size() + " " + mXmppConnectionService.getString(R.string.unread_conversations));
mBuilder.setContentText(names.toString());
mBuilder.setStyle(style);
if (conversation != null) {
mBuilder.setContentIntent(createContentIntent(conversation));
}
mBuilder.setGroupSummary(true);
mBuilder.setGroup(CONVERSATIONS_GROUP);
mBuilder.setDeleteIntent(createDeleteIntent(null));
mBuilder.setSmallIcon(R.drawable.ic_notification);
return mBuilder;
}
use of android.support.v4.app.NotificationCompat.Builder in project Shuttle by timusus.
the class DialogUtils method showBlacklistDialog.
public static void showBlacklistDialog(final Context context) {
View view = LayoutInflater.from(context).inflate(R.layout.dialog_blacklist, null);
final MaterialDialog.Builder builder = getBuilder(context).title(R.string.blacklist_title).customView(view, false).positiveText(R.string.close).negativeText(R.string.pref_title_clear_blacklist).onNegative((materialDialog, dialogAction) -> {
BlacklistHelper.deleteAllSongs();
Toast.makeText(context, R.string.blacklist_deleted, Toast.LENGTH_SHORT).show();
});
final Dialog dialog = builder.build();
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
final BlacklistAdapter blacklistAdapter = new BlacklistAdapter();
blacklistAdapter.setBlackListListener((v, position, song) -> {
BlacklistHelper.deleteSong(song.id);
if (blacklistAdapter.items.size() == 0) {
dialog.dismiss();
}
});
recyclerView.setAdapter(blacklistAdapter);
Observable<List<Song>> songsObservable = SqlBriteUtils.createContinuousQuery(ShuttleApplication.getInstance(), Song::new, Song.getQuery()).first();
Observable<List<BlacklistedSong>> blacklistObservable = BlacklistHelper.getBlacklistSongsObservable();
Subscription subscription = Observable.combineLatest(songsObservable, blacklistObservable, (songs, blacklistedSongs) -> Stream.of(songs).filter(song -> Stream.of(blacklistedSongs).anyMatch(blacklistedSong -> blacklistedSong.songId == song.id)).sorted((a, b) -> ComparisonUtils.compare(a.albumArtistName, b.albumArtistName)).sorted((a, b) -> ComparisonUtils.compareInt(b.year, a.year)).sorted((a, b) -> ComparisonUtils.compareInt(a.track, b.track)).sorted((a, b) -> ComparisonUtils.compareInt(a.discNumber, b.discNumber)).sorted((a, b) -> ComparisonUtils.compare(a.albumName, b.albumName)).map(song -> (AdaptableItem) new BlacklistView(song)).collect(Collectors.toList())).observeOn(AndroidSchedulers.mainThread()).subscribe(blacklistViews -> {
if (blacklistViews.size() == 0) {
blacklistAdapter.addItem(0, new EmptyView(R.string.blacklist_empty));
} else {
blacklistAdapter.setItems(blacklistViews);
}
});
dialog.setOnDismissListener(dialogInterface -> subscription.unsubscribe());
dialog.show();
}
Aggregations