Search in sources :

Example 6 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project Talon-for-Twitter by klinker24.

the class NotificationUtils method sendTestNotification.

public static void sendTestNotification(Context context) {
    if (!TEST_NOTIFICATION) {
        return;
    }
    AppSettings settings = AppSettings.getInstance(context);
    SharedPreferences sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    Intent markRead = new Intent(context, MarkReadService.class);
    PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0);
    String shortText = "Test Talon";
    String longText = "Here is a test for Talon's notifications";
    Intent resultIntent = new Intent(context, RedirectToMentions.class);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0);
    NotificationCompat.Builder mBuilder;
    Intent deleteIntent = new Intent(context, NotificationDeleteReceiverOne.class);
    mBuilder = new NotificationCompat.Builder(context).setContentTitle(shortText).setContentText(longText).setSmallIcon(R.drawable.ic_stat_icon).setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)).setContentIntent(resultPendingIntent).setAutoCancel(true).setTicker(shortText).setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)).setPriority(NotificationCompat.PRIORITY_HIGH);
    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        sendAlertToPebble(context, shortText, shortText);
    }
    // Light Flow notification
    sendToLightFlow(context, shortText, shortText);
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            e.printStackTrace();
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (settings.led)
        mBuilder.setLights(0xFFFFFF, 1000, 1000);
    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    Intent reply = new Intent(context, NotificationCompose.class);
    MentionsDataSource data = MentionsDataSource.getInstance(context);
    PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + "lukeklinker" + " ").build();
    // Create the notification action
    NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput).build();
    NotificationCompat.Action.Builder action = new NotificationCompat.Action.Builder(R.drawable.ic_action_read_dark, context.getResources().getString(R.string.mark_read), readPending);
    mBuilder.addAction(replyAction);
    mBuilder.addAction(action.build());
    // Build the notification and issues it with notification manager.
    notificationManager.notify(1, mBuilder.build());
    // if we want to wake the screen on a new message
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) AppSettings(com.klinker.android.twitter.settings.AppSettings) SharedPreferences(android.content.SharedPreferences) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 7 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project Talon-for-Twitter by klinker24.

the class ActivityUtils method postNotification.

public void postNotification(int id) {
    if (notificationItems.size() == 0) {
        return;
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setContentTitle(notificationTitle);
    mBuilder.setSmallIcon(R.drawable.ic_stat_icon);
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_notification_dark));
    if (notificationItems.size() > 1) {
        // inbox style
        NotificationCompat.InboxStyle inbox = new NotificationCompat.InboxStyle();
        try {
            inbox.setBigContentTitle(notificationTitle);
        } catch (Exception e) {
        }
        if (notificationItems.size() <= 5) {
            for (String s : notificationItems) {
                inbox.addLine(Html.fromHtml(s));
            }
        } else {
            for (int i = 0; i < 5; i++) {
                inbox.addLine(Html.fromHtml(notificationItems.get(i)));
            }
            int extra = notificationItems.size() - 5;
            if (extra > 1) {
                inbox.setSummaryText("+" + extra + " " + context.getString(R.string.items));
            } else {
                inbox.setSummaryText("+" + extra + " " + context.getString(R.string.item));
            }
        }
        mBuilder.setStyle(inbox);
        mBuilder.setContentText(notificationItems.size() + " " + context.getString(R.string.items));
    } else {
        // big text style
        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        bigText.bigText(Html.fromHtml(notificationItems.get(0)));
        bigText.setBigContentTitle(notificationTitle);
        mBuilder.setStyle(bigText);
        mBuilder.setContentText(Html.fromHtml(notificationItems.get(0)));
    }
    if (useSecondAccount) {
        mBuilder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, SwitchAccountsToActivity.class), 0));
    } else {
        mBuilder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, RedirectToActivity.class), 0));
    }
    if (settings.vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (settings.sound) {
        try {
            mBuilder.setSound(Uri.parse(settings.ringtone));
        } catch (Exception e) {
            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (settings.led) {
        mBuilder.setLights(0xFFFFFF, 1000, 1000);
    }
    if (settings.wakeScreen) {
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
        wakeLock.acquire(5000);
    }
    // Pebble notification
    if (sharedPrefs.getBoolean("pebble_notification", false)) {
        NotificationUtils.sendAlertToPebble(context, notificationTitle, notificationItems.get(0));
    }
    // Light Flow notification
    NotificationUtils.sendToLightFlow(context, notificationTitle, notificationItems.get(0));
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
    notificationManager.notify(id, mBuilder.build());
}
Also used : NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PowerManager(android.os.PowerManager) NotificationCompat(android.support.v4.app.NotificationCompat)

Example 8 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project k-9 by k9mail.

the class NotificationController method newInstance.

public static NotificationController newInstance(Context context) {
    Context appContext = context.getApplicationContext();
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(appContext);
    return new NotificationController(appContext, notificationManager);
}
Also used : Context(android.content.Context) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat)

Example 9 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project muzei by romannurik.

the class NewWallpaperNotificationReceiver method markNotificationRead.

public static void markNotificationRead(Context context) {
    Cursor lastArtwork = context.getContentResolver().query(MuzeiContract.Artwork.CONTENT_URI, new String[] { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, MuzeiContract.Artwork.COLUMN_NAME_TOKEN }, null, null, null);
    if (lastArtwork != null && lastArtwork.moveToFirst()) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        sp.edit().putLong(PREF_LAST_READ_NOTIFICATION_ARTWORK_ID, lastArtwork.getLong(0)).putString(PREF_LAST_READ_NOTIFICATION_ARTWORK_IMAGE_URI, lastArtwork.getString(1)).putString(PREF_LAST_READ_NOTIFICATION_ARTWORK_TOKEN, lastArtwork.getString(2)).apply();
    }
    if (lastArtwork != null) {
        lastArtwork.close();
    }
    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.cancel(NOTIFICATION_ID);
}
Also used : SharedPreferences(android.content.SharedPreferences) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) Cursor(android.database.Cursor)

Example 10 with NotificationManagerCompat

use of android.support.v4.app.NotificationManagerCompat in project Conversations by siacs.

the class NotificationService method updateErrorNotification.

public void updateErrorNotification() {
    final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
    final List<Account> errors = new ArrayList<>();
    for (final Account account : mXmppConnectionService.getAccounts()) {
        if (account.hasErrorStatus() && account.showErrorNotification()) {
            errors.add(account);
        }
    }
    if (mXmppConnectionService.getPreferences().getBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE, false)) {
        notificationManager.notify(FOREGROUND_NOTIFICATION_ID, createForegroundNotification());
    }
    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
    if (errors.size() == 0) {
        notificationManager.cancel(ERROR_NOTIFICATION_ID);
        return;
    } else if (errors.size() == 1) {
        mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_account));
        mBuilder.setContentText(errors.get(0).getJid().toBareJid().toString());
    } else {
        mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.problem_connecting_to_accounts));
        mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_fix));
    }
    mBuilder.addAction(R.drawable.ic_autorenew_white_24dp, mXmppConnectionService.getString(R.string.try_again), createTryAgainIntent());
    mBuilder.setDeleteIntent(createDismissErrorIntent());
    mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setSmallIcon(R.drawable.ic_warning_white_24dp);
    } else {
        mBuilder.setSmallIcon(R.drawable.ic_stat_alert_warning);
    }
    mBuilder.setContentIntent(PendingIntent.getActivity(mXmppConnectionService, 145, new Intent(mXmppConnectionService, ManageAccountActivity.class), PendingIntent.FLAG_UPDATE_CURRENT));
    notificationManager.notify(ERROR_NOTIFICATION_ID, mBuilder.build());
}
Also used : Account(eu.siacs.conversations.entities.Account) Builder(android.support.v4.app.NotificationCompat.Builder) NotificationManagerCompat(android.support.v4.app.NotificationManagerCompat) ArrayList(java.util.ArrayList) Builder(android.support.v4.app.NotificationCompat.Builder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationManagerCompat (android.support.v4.app.NotificationManagerCompat)38 NotificationCompat (android.support.v4.app.NotificationCompat)17 PendingIntent (android.app.PendingIntent)15 Intent (android.content.Intent)15 SharedPreferences (android.content.SharedPreferences)7 PowerManager (android.os.PowerManager)7 Bitmap (android.graphics.Bitmap)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)6 Notification (android.app.Notification)5 Context (android.content.Context)4 Cursor (android.database.Cursor)4 RemoteInput (android.support.v4.app.RemoteInput)4 Bundle (android.os.Bundle)3 ComponentName (android.content.ComponentName)2 ContentResolver (android.content.ContentResolver)2 ContentValues (android.content.ContentValues)2 Uri (android.net.Uri)2 Builder (android.support.v4.app.NotificationCompat.Builder)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 ArrayList (java.util.ArrayList)2