Search in sources :

Example 46 with Builder

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());
    }
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 47 with Builder

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);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Message(eu.siacs.conversations.entities.Message) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) BigPictureStyle(android.support.v4.app.NotificationCompat.BigPictureStyle)

Example 48 with Builder

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());
            }
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Builder(android.support.v4.app.NotificationCompat.Builder) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 49 with Builder

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;
}
Also used : SpannableString(android.text.SpannableString) Message(eu.siacs.conversations.entities.Message) Builder(android.support.v4.app.NotificationCompat.Builder) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString)

Example 50 with Builder

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();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Dialog(android.app.Dialog) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) ArrayList(java.util.ArrayList) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) Subscription(rx.Subscription) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)105 PendingIntent (android.app.PendingIntent)86 Intent (android.content.Intent)76 NotificationManager (android.app.NotificationManager)35 Notification (android.app.Notification)29 Builder (android.support.v4.app.NotificationCompat.Builder)19 Context (android.content.Context)16 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)14 Uri (android.net.Uri)11 Bundle (android.os.Bundle)10 Bitmap (android.graphics.Bitmap)9 View (android.view.View)9 RemoteViews (android.widget.RemoteViews)9 IOException (java.io.IOException)9 AlertDialog (android.app.AlertDialog)7 DialogInterface (android.content.DialogInterface)7 Paint (android.graphics.Paint)6 SpannableString (android.text.SpannableString)6 TypedValue (android.util.TypedValue)6 TextView (android.widget.TextView)6