Search in sources :

Example 36 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method setCustomViewNotification.

/**
	 * Custom View Notification
	 * 
	 * @return Notification
	 * @see CreateNotification
	 */
private Notification setCustomViewNotification(String content) {
    // Creates an explicit intent for an ResultActivity to receive.
    Intent resultIntent = new Intent(this, ResultActivity.class);
    // This ensures that the back button follows the recommended convention
    // for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ResultActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    // Create remote view and set bigContentView.
    RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_custom_remote);
    expandedView.setTextViewText(R.id.text_view, "Neat logo!");
    Notification notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentIntent(resultPendingIntent).setContentTitle("Custom View").build();
    return notification;
}
Also used : RemoteViews(android.widget.RemoteViews) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Notification(android.app.Notification)

Example 37 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method setBigPictureStyleNotification.

/**
	 * Big Picture Style Notification
	 * 
	 * @return Notification
	 * @see CreateNotification
	 */
private Notification setBigPictureStyleNotification(String content) {
    Bitmap remote_picture = null;
    // Create the style object with BigPictureStyle subclass.
    NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
    notiStyle.setBigContentTitle("Big Picture Expanded");
    notiStyle.setSummaryText("Nice big picture.");
    try {
        remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Add the big picture to the style.
    notiStyle.bigPicture(remote_picture);
    // Creates an explicit intent for an ResultActivity to receive.
    Intent resultIntent = new Intent(this, ResultActivity.class);
    // This ensures that the back button follows the recommended convention
    // for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself).
    stackBuilder.addParentStack(ResultActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setLargeIcon(remote_picture).setContentIntent(resultPendingIntent).addAction(R.drawable.ic_launcher, "One", resultPendingIntent).addAction(R.drawable.ic_launcher, "Two", resultPendingIntent).addAction(R.drawable.ic_launcher, "Three", resultPendingIntent).setContentTitle("Big Picture Normal").setContentText(content).setStyle(notiStyle).build();
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) URL(java.net.URL)

Example 38 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method setNormalNotification.

/**
	 * Normal Notification
	 * 
	 * @return Notification
	 * @see CreateNotification
	 */
private Notification setNormalNotification(String content) {
    Bitmap remote_picture = null;
    try {
        remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Setup an explicit intent for an ResultActivity to receive.
    Intent resultIntent = new Intent(this, ResultActivity.class);
    // TaskStackBuilder ensures that the back button follows the recommended
    // convention for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself).
    stackBuilder.addParentStack(ResultActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    return new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setLargeIcon(remote_picture).setContentIntent(resultPendingIntent).setContentTitle("Normal Notification").setContentText(content).build();
}
Also used : Bitmap(android.graphics.Bitmap) InputStream(java.io.InputStream) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) URL(java.net.URL)

Example 39 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project AprilBeacon-Android-SDK by AprilBrother.

the class NotifyService method setCustomViewNotification.

/**
	 * Custom View Notification
	 * 
	 * @return Notification
	 * @see CreateNotification
	 */
private Notification setCustomViewNotification(String content) {
    // Creates an explicit intent for an ResultActivity to receive.
    Intent resultIntent = new Intent(this, ResultActivity.class);
    // This ensures that the back button follows the recommended convention
    // for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ResultActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack.
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    // Create remote view and set bigContentView.
    RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_custom_remote);
    expandedView.setTextViewText(R.id.text_view, "Neat logo!");
    Notification notification = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentIntent(resultPendingIntent).setContentTitle("Custom View").build();
    return notification;
}
Also used : RemoteViews(android.widget.RemoteViews) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Notification(android.app.Notification)

Example 40 with TaskStackBuilder

use of android.support.v4.app.TaskStackBuilder in project Remindy by abicelis.

the class NotificationUtil method displayNotification.

public static void displayNotification(Context context, Task task, String contentTitle, String contentText) {
    //Intent for "DONE" button on BigView style
    Intent setTaskDoneIntent = new Intent(context, TaskActionsIntentService.class);
    setTaskDoneIntent.setAction(TaskActionsIntentService.ACTION_SET_TASK_DONE);
    setTaskDoneIntent.putExtra(TaskActionsIntentService.PARAM_TASK_ID, task.getId());
    PendingIntent setTaskDonePendingIntent = PendingIntent.getService(context, task.getId(), setTaskDoneIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    //Intent for "POSTPONE" button on BigView style
    Intent postponeTaskIntent = new Intent(context, TaskActionsIntentService.class);
    postponeTaskIntent.setAction(TaskActionsIntentService.ACTION_POSTPONE_TASK);
    postponeTaskIntent.putExtra(TaskActionsIntentService.PARAM_TASK_ID, task.getId());
    PendingIntent postponeTaskPendingIntent = PendingIntent.getService(context, task.getId(), postponeTaskIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    //Intent for clicking notification
    Intent openTaskIntent = new Intent(context, TaskDetailActivity.class);
    openTaskIntent.putExtra(TASK_ID_TO_DISPLAY, task.getId());
    //openTaskIntent.setAction(String.valueOf(task.getId()));
    //openTaskIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //openTaskIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack
    stackBuilder.addParentStack(TaskDetailActivity.class);
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(openTaskIntent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent openTaskPendingIntent = stackBuilder.getPendingIntent(task.getId(), PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder;
    mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.icon_remindy_notification_small).setColor(ContextCompat.getColor(context, R.color.primary)).setVibrate(new long[] { 50, 50, 200, 50 }).setLights(ContextCompat.getColor(context, R.color.primary), 3000, 3000).setSound(Settings.System.DEFAULT_NOTIFICATION_URI).setContentTitle(contentTitle).setContentText(contentText).setContentIntent(openTaskPendingIntent).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH).setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).addAction(R.drawable.icon_notification_done, context.getResources().getString(R.string.notification_big_view_set_done), setTaskDonePendingIntent).addAction(R.drawable.icon_notification_postpone, context.getResources().getString(R.string.notification_big_view_postpone), postponeTaskPendingIntent);
    // Get an instance of the NotificationManager service
    NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
    mNotifyMgr.notify(task.getId(), mBuilder.build());
}
Also used : NotificationManager(android.app.NotificationManager) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder)

Aggregations

Intent (android.content.Intent)39 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)38 PendingIntent (android.app.PendingIntent)34 NotificationCompat (android.support.v4.app.NotificationCompat)20 NotificationManager (android.app.NotificationManager)14 Bitmap (android.graphics.Bitmap)13 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 URL (java.net.URL)8 Notification (android.app.Notification)7 Context (android.content.Context)5 Uri (android.net.Uri)5 SharedPreferences (android.content.SharedPreferences)3 Resources (android.content.res.Resources)3 Cursor (android.database.Cursor)3 RemoteViews (android.widget.RemoteViews)3 TaskStackBuilder (android.app.TaskStackBuilder)2 ContentResolver (android.content.ContentResolver)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2