Search in sources :

Example 1 with InboxStyle

use of android.support.v4.app.NotificationCompat.InboxStyle in project Klyph by jonathangerbaud.

the class KlyphNotification method setInboxStyle.

public static void setInboxStyle(Builder builder, String title, List<String> lines) {
    builder.setNumber(lines.size());
    InboxStyle inboxStyle = new InboxStyle();
    inboxStyle.setBigContentTitle(title);
    for (String line : lines) {
        inboxStyle.addLine(line);
    }
    builder.setStyle(inboxStyle);
}
Also used : InboxStyle(android.support.v4.app.NotificationCompat.InboxStyle)

Example 2 with InboxStyle

use of android.support.v4.app.NotificationCompat.InboxStyle in project Pokemap by omkarmoghe.

the class PokemonNotificationService method onEvent.

@Subscribe
public void onEvent(CatchablePokemonEvent event) {
    List<CatchablePokemon> catchablePokemon = event.getCatchablePokemon();
    LatLng location = locationManager.getLocation();
    Location myLoc = new Location("");
    myLoc.setLatitude(location.latitude);
    myLoc.setLongitude(location.longitude);
    builder.setContentText(getString(R.string.notification_service_pokemon_near, catchablePokemon.size()));
    builder.setStyle(null);
    if (!catchablePokemon.isEmpty()) {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(getString(R.string.notification_service_pokemon_in_area, catchablePokemon.size()));
        Set<PokemonIdOuterClass.PokemonId> showablePokemonIDs = preffs.getShowablePokemonIDs();
        for (CatchablePokemon cp : catchablePokemon) {
            //Only show the notification if the Pokemon is in the preference list
            if (showablePokemonIDs.contains(cp.getPokemonId())) {
                Location pokeLocation = new Location("");
                pokeLocation.setLatitude(cp.getLatitude());
                pokeLocation.setLongitude(cp.getLongitude());
                long remainingTime = cp.getExpirationTimestampMs() - System.currentTimeMillis();
                String pokeName = PokemonIdUtils.getLocalePokemonName(getApplicationContext(), cp.getPokemonId().name());
                long remTime = TimeUnit.MILLISECONDS.toMinutes(remainingTime);
                int dist = (int) Math.ceil(pokeLocation.distanceTo(myLoc));
                inboxStyle.addLine(getString(R.string.notification_service_inbox_line, pokeName, remTime, dist));
            }
        }
        builder.setStyle(inboxStyle);
    }
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(notificationId, builder.build());
}
Also used : NotificationManager(android.app.NotificationManager) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) NotificationCompat(android.support.v4.app.NotificationCompat) LatLng(com.google.android.gms.maps.model.LatLng) Location(android.location.Location) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 3 with InboxStyle

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

the class NotifyService method setInboxStyleNotification.

/**
	 * Inbox Style Notification
	 * 
	 * @return Notification
	 * @see CreateNotification
	 */
private Notification setInboxStyleNotification(String content) {
    Bitmap remote_picture = null;
    // Create the style object with InboxStyle subclass.
    NotificationCompat.InboxStyle notiStyle = new NotificationCompat.InboxStyle();
    notiStyle.setBigContentTitle("Inbox Style Expanded");
    // This is strictly for providing an example of multiple lines.
    for (int i = 0; i < 5; i++) {
        notiStyle.addLine("(" + i + " of 6) Line one here.");
    }
    notiStyle.setSummaryText("+2 more Line Samples");
    try {
        remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 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("Inbox Style 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 4 with InboxStyle

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

the class NotifyService method setInboxStyleNotification.

/**
	 * Inbox Style Notification
	 * 
	 * @return Notification
	 * @see CreateNotification
	 */
private Notification setInboxStyleNotification(String content) {
    Bitmap remote_picture = null;
    // Create the style object with InboxStyle subclass.
    NotificationCompat.InboxStyle notiStyle = new NotificationCompat.InboxStyle();
    notiStyle.setBigContentTitle("Inbox Style Expanded");
    // This is strictly for providing an example of multiple lines.
    for (int i = 0; i < 5; i++) {
        notiStyle.addLine("(" + i + " of 6) Line one here.");
    }
    notiStyle.setSummaryText("+2 more Line Samples");
    try {
        remote_picture = BitmapFactory.decodeStream((InputStream) new URL(sample_url).getContent());
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 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("Inbox Style 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 5 with InboxStyle

use of android.support.v4.app.NotificationCompat.InboxStyle in project ETSMobile-Android2 by ApplETS.

the class ETSGcmListenerService method sendNotification.

/**
     * Create and show a simple notification containing the received GCM message.
     *
     * @param data GCM message received.
     */
private void sendNotification(Bundle data) {
    SecurePreferences securePreferences = new SecurePreferences(this);
    Gson gson = new Gson();
    String receivedNotifString = securePreferences.getString(Constants.RECEIVED_NOTIF, "");
    ArrayList<MonETSNotification> receivedNotif = gson.fromJson(receivedNotifString, new TypeToken<ArrayList<MonETSNotification>>() {
    }.getType());
    if (receivedNotif == null) {
        receivedNotif = new ArrayList<>();
    }
    MonETSNotification nouvelleNotification = getMonETSNotificationFromBundle(data);
    receivedNotif.add(nouvelleNotification);
    int numberOfNotifications = receivedNotif.size();
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_ets);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.school_48).setColor(getResources().getColor(R.color.red)).setContentTitle(getString(R.string.ets)).setContentText(getString(R.string.new_notifications)).setContentIntent(pendingIntent).setLargeIcon(icon).setAutoCancel(true).setNumber(numberOfNotifications);
    NotificationCompat.InboxStyle inBoxStyle = new NotificationCompat.InboxStyle();
    // Sets a title for the Inbox in expanded layout
    String bigContentTitle = getString(R.string.notification_content_title, numberOfNotifications + "", (numberOfNotifications == 1 ? "" : "s"), (numberOfNotifications == 1 ? "" : "s"));
    inBoxStyle.setBigContentTitle(bigContentTitle);
    String username = ApplicationManager.userCredentials.getUsername();
    Spannable sb = new SpannableString(username);
    sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, username.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    inBoxStyle.setSummaryText(sb);
    securePreferences.edit().putString(Constants.RECEIVED_NOTIF, gson.toJson(receivedNotif)).commit();
    int minimumIndex = receivedNotif.size() - NUMBER_OF_NOTIF_TO_DISPLAY;
    minimumIndex = minimumIndex < 0 ? 0 : minimumIndex;
    for (int i = receivedNotif.size() - 1; i >= minimumIndex; i--) {
        inBoxStyle.addLine(receivedNotif.get(i).getNotificationTexte());
    }
    if (numberOfNotifications > NUMBER_OF_NOTIF_TO_DISPLAY) {
        int plusOthers = (numberOfNotifications - NUMBER_OF_NOTIF_TO_DISPLAY);
        String plusOthersString = getString(R.string.others_notifications, plusOthers + "", (plusOthers == 1 ? "" : "s"));
        Spannable others = new SpannableString(plusOthersString);
        others.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, others.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        inBoxStyle.addLine(others);
    }
    mBuilder.setStyle(inBoxStyle);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());
}
Also used : MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) NotificationManager(android.app.NotificationManager) Gson(com.google.gson.Gson) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SecurePreferences(ca.etsmtl.applets.etsmobile.util.SecurePreferences) SpannableString(android.text.SpannableString) SpannableString(android.text.SpannableString) Bitmap(android.graphics.Bitmap) TypeToken(com.google.gson.reflect.TypeToken) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Spannable(android.text.Spannable)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)13 PendingIntent (android.app.PendingIntent)11 Intent (android.content.Intent)8 NotificationManager (android.app.NotificationManager)6 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)5 Bitmap (android.graphics.Bitmap)3 StyleSpan (android.text.style.StyleSpan)3 Notification (android.app.Notification)2 Cursor (android.database.Cursor)2 SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Resources (android.content.res.Resources)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Drawable (android.graphics.drawable.Drawable)1 Location (android.location.Location)1