Search in sources :

Example 1 with MailReceivedEvent

use of com.hannesdorfmann.mosby3.sample.mail.model.event.MailReceivedEvent in project mosby by sockeqwe.

the class GcmFakeIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    Mail mail = intent.getParcelableExtra(KEY_MAIL);
    // simulate network / receiving delay
    try {
        Thread.sleep(3000);
    } catch (Exception e) {
    }
    mail.label(Label.INBOX);
    mailProvider.addMail(mail).subscribe();
    eventBus.post(new MailReceivedEvent(mail));
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    Intent startIntent = intentStarter.getShowMailInNewActivityIntent(getApplicationContext(), mail);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, startIntent, 0);
    builder.setContentIntent(pendingIntent);
    builder.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), mail.getSender().getImageRes()));
    builder.setSmallIcon(R.mipmap.ic_launcher).setLights(getResources().getColor(R.color.primary), 1800, 3500).setAutoCancel(true).setContentTitle(mail.getSubject()).setContentText(mail.getText()).setWhen(mail.getDate().getTime()).setVibrate(new long[] { 1000, 1000 });
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(mail.getId(), builder.build());
}
Also used : Mail(com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) MailReceivedEvent(com.hannesdorfmann.mosby3.sample.mail.model.event.MailReceivedEvent)

Aggregations

NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 MailReceivedEvent (com.hannesdorfmann.mosby3.sample.mail.model.event.MailReceivedEvent)1 Mail (com.hannesdorfmann.mosby3.sample.mail.model.mail.Mail)1