Example usage for android.app Notification DEFAULT_LIGHTS

List of usage examples for android.app Notification DEFAULT_LIGHTS

Introduction

In this page you can find the example usage for android.app Notification DEFAULT_LIGHTS.

Prototype

int DEFAULT_LIGHTS

To view the source code for android.app Notification DEFAULT_LIGHTS.

Click Source Link

Document

Use the default notification lights.

Usage

From source file:com.juick.android.XMPPMessageReceiver.java

public static void updateInfo(final Context context, int nMessages, boolean silent) {
    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    String tickerText = "juick: new message";
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);

    // public Notification(int icon, java.lang.CharSequence tickerText, long when) { /* compiled code */ }
    // Notification notif = new Notification(R.drawable.juick_message_icon, null,System.currentTimeMillis());

    int iconIndex;
    if (nMessages < 1) {
        iconIndex = 0; // to prevent out of bounds
    } else if (nMessages > NOTIFICATION_ICONS.length - 1) {
        iconIndex = NOTIFICATION_ICONS.length - 1; // to prevent out of bounds
    } else {/*from  www.  j ava  2s  . com*/
        iconIndex = nMessages;
    }
    boolean showNumberUnread = sp.getBoolean("show_number_unread", true);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(
                    showNumberUnread ? NOTIFICATION_ICONS[iconIndex] : R.drawable.juick_message_icon_plain)
            .setWhen(System.currentTimeMillis());

    //context.getResources().getDrawable(smallIcon)
    // public Notification(int icon, java.lang.CharSequence tickerText, long when) { /* compiled code */ }

    int notification = 0;
    if (!silent) {
        if (sp.getBoolean("led_enabled", true))
            notification |= Notification.DEFAULT_LIGHTS;
        if (System.currentTimeMillis() - lastVibrate > 5000) {
            // add some sound
            if (sp.getBoolean("vibration_enabled", true))
                notification |= Notification.DEFAULT_VIBRATE;
            if (sp.getBoolean("ringtone_enabled", true)) {
                String ringtone_uri = sp.getString("ringtone_uri", "");
                if (ringtone_uri.length() > 0) {
                    notificationBuilder.setSound(Uri.parse(ringtone_uri));
                } else
                    notification |= Notification.DEFAULT_SOUND;
            }
            lastVibrate = System.currentTimeMillis();
        }
    }
    notificationBuilder.setDefaults(silent ? 0 : notification);
    Intent intent = new Intent(context, XMPPService.class);
    intent.setAction(XMPPService.ACTION_LAUNCH_MESSAGELIST);
    PendingIntent pendingIntent = PendingIntent.getService(context, 1000, intent, 0);
    //PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, nintent, 0);
    notificationBuilder.setContentTitle("Juick: " + nMessages + " new message" + (nMessages > 1 ? "s" : ""))
            .setContentText(tickerText).setContentIntent(pendingIntent).setNumber(nMessages);
    nm.notify("", 2, notificationBuilder.getNotification());
}

From source file:com.nobledesignlabs.lookupaddress.GcmIntentService.java

private void displayNotification(Context context, Bundle extras) {
    // ---PendingIntent to launch activity if the user selects
    // this notification---
    // NotificationView context = new NotificationView();
    try {/*from w  w  w.  j a va 2 s .c  om*/

        Intent i = null;
        Random rand = new Random();
        int timenow = rand.nextInt();
        String title = extras.getString("title");
        String message = extras.getString("message");
        String picture = extras.getString("imgurl");
        String sinfotype = extras.getString("infotype");
        boolean cancelonclick = true;
        int infotype = Integer.parseInt(sinfotype);
        if (infotype == CommonStuff.ADDRESS_NOTIFICATION) {
            i = new Intent(context, NotificationView.class);
            i.putExtra("notificationID", timenow);
            i.putExtra("message", message);
            i.putExtra("title", title);
            i.putExtra("picture", picture);
            cancelonclick = true;
            // i.putExtra("infotype", picture);
        } else if (infotype == CommonStuff.ADDRESS_AUTHORIZATION_REQUEST) {
            i = new Intent(context, AuthorizationRequestActivity.class);
            String token = extras.getString("token");
            i.putExtra("notificationID", timenow);
            i.putExtra("message", message);
            i.putExtra("title", title);
            i.putExtra("picture", picture);
            i.putExtra("token", token);
            String address = extras.getString("address");
            i.putExtra("address", address);
            cancelonclick = true;
            // i.putExtra("infotype", picture);
        } else if (infotype == CommonStuff.ADDRESS_SHARING_REQUEST) {
            i = new Intent(context, AuthorizedActivity.class);
            i.putExtra("notificationID", timenow);
            i.putExtra("message", message);
            i.putExtra("title", title);
            String token = extras.getString("token");
            String address = extras.getString("address");
            i.putExtra("address", address);
            i.putExtra("token", token);
            cancelonclick = false;
            // i.putExtra("infotype", picture);
        }
        if (i != null) {
            i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, timenow, i, 0);
            /*
             * NotificationManager nm = (NotificationManager) context
             * .getSystemService(Context.NOTIFICATION_SERVICE); Notification
             * notif = new Notification( R.drawable.direction_uturn,
             * message, timenow); // String title =
             * context.getString(R.string.app_name);
             * 
             * i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
             * Intent.FLAG_ACTIVITY_SINGLE_TOP);
             * 
             * notif.setLatestEventInfo(context, title, message,
             * pendingIntent); // notif.flags |=
             * Notification.FLAG_AUTO_CANCEL; notif.flags =
             * Notification.FLAG_AUTO_CANCEL; notif.defaults |=
             * Notification.DEFAULT_SOUND; notif.defaults |=
             * Notification.DEFAULT_VIBRATE; notif.vibrate = new long[] {
             * 100, 250, 100, 500 }; nm.notify(timenow, notif);
             */

            NotificationCompat.Builder b = new NotificationCompat.Builder(context);

            if (cancelonclick) {
                b.setAutoCancel(true).setOngoing(false).setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.drawable.direction_uturn).setTicker(title).setContentTitle(title)
                        .setContentText(message).setVibrate(new long[] { 100, 250, 100, 500 })
                        .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE
                                | Notification.DEFAULT_SOUND)
                        .setContentIntent(pendingIntent).setLights(0xFFF7BF05, 250, 500)
                        .setContentInfo("me@address");

            } else {
                b.setAutoCancel(false).setOngoing(true).setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.drawable.direction_uturn).setTicker(title).setContentTitle(title)
                        .setContentText(message).setLights(0xFF308036, 250, 500)
                        .setVibrate(new long[] { 100, 250, 100, 500 })
                        .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE
                                | Notification.DEFAULT_SOUND)
                        .setContentIntent(pendingIntent).setContentInfo("me@address");
            }

            NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            manager.notify(timenow, b.build());
        }
    } catch (Exception d) {
    }
}

From source file:se.erichansander.retrotimer.TimerKlaxon.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    TinyTracelog.trace("4");

    // No intent, tell the system not to restart us.
    if (intent == null) {
        TinyTracelog.trace("4.e");
        stopSelf();/* ww w .  ja  va  2  s. c  o  m*/
        return START_NOT_STICKY;
    }

    boolean ring = mPrefs.getBoolean(RetroTimer.PREF_RING_ON_ALARM, true);
    boolean vibrate = mPrefs.getBoolean(RetroTimer.PREF_VIBRATE_ON_ALARM, true);
    long timeoutMillis = mPrefs.getLong(RetroTimer.PREF_ALARM_TIMEOUT_MILLIS, 10 * 1000);
    mAlarmTime = intent.getLongExtra(RetroTimer.ALARM_TIME_EXTRA, 0);

    // Close dialogs and window shade
    sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));

    // Trigger a notification that, when clicked, will dismiss the alarm.
    Intent notify = new Intent(RetroTimer.ALARM_DISMISS_ACTION);
    PendingIntent pendingNotify = PendingIntent.getBroadcast(this, 0, notify, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentIntent(pendingNotify)
            .setDefaults(Notification.DEFAULT_LIGHTS).setOngoing(true)
            .setSmallIcon(R.drawable.ic_stat_alarm_triggered)
            .setContentTitle(getString(R.string.notify_triggered_label))
            .setContentText(getString(R.string.notify_triggered_text));

    /*
     * Send the notification using the alarm id to easily identify the
     * correct notification.
     */
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(RetroTimer.NOTIF_SET_ID);
    nm.notify(RetroTimer.NOTIF_TRIGGERED_ID, mBuilder.build());

    /*
     * launch UI, explicitly stating that this is not due to user action so
     * that the current app's notification management is not disturbed
     */
    Intent timerAlert = new Intent(this, TimerAlert.class);
    timerAlert.putExtra(RetroTimer.ALARM_TIME_EXTRA, mAlarmTime);
    timerAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    startActivity(timerAlert);

    play(ring, vibrate);
    startTimeoutCountdown(timeoutMillis);

    // Record the initial call state here so that the new alarm has the
    // newest state.
    mInitialCallState = mTelephonyManager.getCallState();

    // Update the shared state
    RetroTimer.clearAlarm(this);

    return START_STICKY;
}

From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java

private static void issueNotification(Context context, Set<String> addedMilestones,
        Set<String> removedMilestones, Map<String, int[]> changedProgresses) {
    String title = context.getString(R.string.notification_title);
    StringBuilder message = new StringBuilder();

    // Changed progresses
    for (String milestoneTitle : changedProgresses.keySet()) {
        int oldProgress = changedProgresses.get(milestoneTitle)[0];
        int newProgress = changedProgresses.get(milestoneTitle)[1];
        message.append("\n").append(String.format(context.getString(R.string.notific_msg_text_format),
                milestoneTitle, oldProgress, newProgress));
    }//from w  w w  .  j  a  va 2s .  c om

    // Added milestones
    for (String milestoneTitle : addedMilestones) {
        message.append("\n").append(context.getString(R.string.milestone_added_notification, milestoneTitle));
    }

    // Removed milestones
    for (String milestoneTitle : removedMilestones) {
        message.append("\n").append(context.getString(R.string.milestone_removed_notification, milestoneTitle));
    }

    // Remove first newline
    message.delete(0, 1);

    // Create PendingIntent
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    boolean sound = pref.getBoolean(Constants.NOTIFICATION_SOUND_PREF, true);
    boolean vibrate = pref.getBoolean(Constants.NOTIFICATION_VIBRATE_PREF, true);
    boolean light = pref.getBoolean(Constants.NOTIFICATION_LIGHT_PREF, true);
    int defaults = 0;
    if (sound)
        defaults = defaults | Notification.DEFAULT_SOUND;
    if (vibrate)
        defaults = defaults | Notification.DEFAULT_VIBRATE;
    if (light)
        defaults = defaults | Notification.DEFAULT_LIGHTS;

    // Build the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .setSmallIcon(R.mipmap.notification_small_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setDefaults(defaults).setAutoCancel(true);

    // Issue the notification
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(PROGRESS_NOTIFICATION_ID, builder.build());
}

From source file:com.mobileman.moments.android.frontend.activity.IncomingCallActivity.java

public static void sendGeneralNotificationOfMissedCall(Context context, String userName, String title) {
    Intent intent = new Intent(context, MainActivity.class);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder b = new NotificationCompat.Builder(context);
    String notificationTitle = userName + " " + context.getResources().getString(R.string.isLiveSuffix);
    String notificationText = title;
    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    b.setAutoCancel(true).setSmallIcon(R.drawable.ic_launcher).setDefaults(Notification.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis()).setTicker("X").setContentTitle(notificationTitle)
            .setContentText(notificationText)
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(++NOTIFICATION_COUNTER, b.build());
}

From source file:com.better.alarm.presenter.alert.AlarmAlertReceiver.java

private void onSnoozed(int id) {

    // What to do, when a user clicks on the notification bar
    Intent cancelSnooze = new Intent(mContext, AlarmAlertReceiver.class);
    cancelSnooze.setAction(ACTION_CANCEL_NOTIFICATION);
    cancelSnooze.putExtra(Intents.EXTRA_ID, id);
    PendingIntent pCancelSnooze = PendingIntent.getBroadcast(mContext, id, cancelSnooze, 0);

    // When button Reschedule is clicked, the TransparentActivity with
    // TimePickerFragment to set new alarm time is launched
    Intent reschedule = new Intent(mContext, TransparentActivity.class);
    reschedule.putExtra(Intents.EXTRA_ID, id);
    PendingIntent pendingReschedule = PendingIntent.getActivity(mContext, id, reschedule, 0);

    PendingIntent pendingDismiss = PresentationToModelIntents.createPendingIntent(mContext,
            PresentationToModelIntents.ACTION_REQUEST_DISMISS, id);

    String label = alarm.getLabelOrDefault(mContext);

    //@formatter:off
    Notification status = new NotificationCompat.Builder(mContext)
            // Get the display time for the snooze and update the notification.
            .setContentTitle(mContext.getString(R.string.alarm_notify_snooze_label, label))
            .setContentText(mContext.getString(R.string.alarm_notify_snooze_text, formatTimeString()))
            .setSmallIcon(R.drawable.stat_notify_alarm).setContentIntent(pCancelSnooze).setOngoing(true)
            .addAction(R.drawable.ic_action_reschedule_snooze,
                    mContext.getString(R.string.alarm_alert_reschedule_text), pendingReschedule)
            .addAction(R.drawable.ic_action_dismiss, mContext.getString(R.string.alarm_alert_dismiss_text),
                    pendingDismiss)/*from   w w  w  .j  a va2s  .c om*/
            .setDefaults(Notification.DEFAULT_LIGHTS).build();
    //@formatter:on

    // Send the notification using the alarm id to easily identify the
    // correct notification.
    nm.notify(id + NOTIFICATION_OFFSET, status);
}

From source file:ru.appsm.inapphelp.IAHHelpDesk.java

/**
 *
 * Handle push notification. Cordova./*from ww  w  .  j  a va2  s  .c o m*/
 *
 * @param data
 * @param context
 */
public static void BuildNotificationForDataWithContext(JSONObject data, Context context) {
    Log.i(TAG, "Create notifications");
    if (data != null && data.has("secretkey") && data.has("userid") && data.has("appkey") && data.has("appid")
            && data.has("email") && data.has("message") && data.has("title") && data.has("notId")
            && data.has("msgId")) {
        try {
            int notId = 1;
            try {
                notId = data.getInt("notId");
            } catch (JSONException e) {
                notId = 1;
            }

            mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Intent notificationIntent = new Intent(context, IssueDetailActivity.class);
            notificationIntent.putExtra("fromPush", true);
            notificationIntent.putExtra("userid", data.getString("userid"));
            notificationIntent.putExtra("appid", data.getString("appid"));
            notificationIntent.putExtra("appkey", data.getString("appkey"));
            notificationIntent.putExtra("secretkey", data.getString("secretkey"));
            notificationIntent.putExtra("email", data.getString("email"));

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                    .setSmallIcon(getApplicationIcon(context)).setContentTitle(data.getString("title"))
                    .setContentText(data.getString("message")).setAutoCancel(true)
                    .setContentIntent(contentIntent);

            if (data.getString("sound").equals("default")) {
                mBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE
                        | Notification.DEFAULT_LIGHTS);
            }

            mNotificationManager.notify(notId, mBuilder.build());
        } catch (JSONException e) {
            Log.i(TAG, "Fail to parse push data");
        }
    } else {
        Log.i(TAG, "Empty or wrong push data");
    }
}

From source file:com.tws.soul.soulbrown.gcm.GcmIntentService.java

private void sendNotification(String msg) {

    WakeupMgr wakeupMgr;//from  w  w  w .  j  a  v a2  s . c  o  m
    wakeupMgr = new WakeupMgr(this);

    wakeupMgr.setPowerWakeUp(4);

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.push_logo_s).setContentTitle(getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    wakeupMgr.releaseWifiManager();
}

From source file:uk.org.rivernile.edinburghbustracker.android.alerts.TimeAlertService.java

/**
 * {@inheritDoc}// ww w. j  a v a  2s  . c om
 */
@Override
protected void onHandleIntent(final Intent intent) {
    final String stopCode = intent.getStringExtra(ARG_STOPCODE);
    final String[] services = intent.getStringArrayExtra(ARG_SERVICES);
    final int timeTrigger = intent.getIntExtra(ARG_TIME_TRIGGER, 5);
    final BusParser parser = new EdinburghParser();

    HashMap<String, BusStop> result;
    try {
        // Get the bus times. Only get 1 bus per service.
        result = parser.getBusStopData(new String[] { stopCode }, 1);
    } catch (BusParserException e) {
        // There was an error. No point continuing. Reschedule.
        reschedule(intent);
        return;
    }

    // Get the bus stop we are interested in. It should be the only one in
    // the HashMap anyway.
    final BusStop busStop = result.get(stopCode);
    int time;
    EdinburghBus edinBs;

    // Loop through all the bus services at this stop.
    for (BusService bs : busStop.getBusServices()) {
        // We are only interested in the next departure. Also get the time.
        edinBs = (EdinburghBus) bs.getFirstBus();
        if (edinBs == null) {
            continue;
        }

        time = edinBs.getArrivalMinutes();

        // Loop through all of the services we are interested in.
        for (String service : services) {
            // The service matches and meets the time criteria.
            if (service.equals(bs.getServiceName()) && time <= timeTrigger) {
                // The alert may have been cancelled by the user recently,
                // check it's still active to stay relevant. Cancel the
                // alert if we're continuing.
                if (!sd.isActiveTimeAlert(stopCode))
                    return;
                alertMan.removeTimeAlert();

                // Create the intent that's fired when the notification is
                // tapped. It shows the bus times view for that stop.
                final Intent launchIntent = new Intent(this, DisplayStopDataActivity.class);
                launchIntent.setAction(DisplayStopDataActivity.ACTION_VIEW_STOP_DATA);
                launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                launchIntent.putExtra(DisplayStopDataActivity.ARG_STOPCODE, stopCode);
                launchIntent.putExtra(DisplayStopDataActivity.ARG_FORCELOAD, true);

                final String stopName = bsd.getNameForBusStop(stopCode);

                final String title = getString(R.string.timeservice_notification_title);

                final String summary = getResources().getQuantityString(
                        R.plurals.timeservice_notification_summary, time == 0 ? 1 : time, service, time,
                        stopName);

                // Build the notification.
                final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
                notifBuilder.setAutoCancel(true);
                notifBuilder.setSmallIcon(R.drawable.ic_status_bus);
                notifBuilder.setTicker(summary);
                notifBuilder.setContentTitle(title);
                notifBuilder.setContentText(summary);
                // Support for Jelly Bean notifications.
                notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(summary));
                notifBuilder.setContentIntent(
                        PendingIntent.getActivity(this, 0, launchIntent, PendingIntent.FLAG_ONE_SHOT));

                final Notification n = notifBuilder.build();
                if (sp.getBoolean(PreferencesActivity.PREF_ALERT_SOUND, true))
                    n.defaults |= Notification.DEFAULT_SOUND;

                if (sp.getBoolean(PreferencesActivity.PREF_ALERT_VIBRATE, true))
                    n.defaults |= Notification.DEFAULT_VIBRATE;

                if (sp.getBoolean(PreferencesActivity.PREF_ALERT_LED, true)) {
                    n.defaults |= Notification.DEFAULT_LIGHTS;
                    n.flags |= Notification.FLAG_SHOW_LIGHTS;
                }

                // Send the notification.
                notifMan.notify(ALERT_ID, n);
                return;
            }
        }
    }

    // All the services have been looped through and the criteria didn't
    // match. This means a reschedule should be attempted.
    reschedule(intent);
}

From source file:fr.neamar.notiflow.GcmIntentService.java

private void sendNotification(String flow, String msg, Bundle extras) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Boolean notifyOwnMessages = prefs.getBoolean("prefNotifyOwnMessages", false);
    Boolean isOwnMessage = extras.getString("own", "false").equals("true");

    String notifyType = prefs.getString("prefNotifyType", "all"); // all | mentions | private
    Boolean isMentioned = extras.getString("mentioned", "false").equals("true");
    Boolean isPrivate = extras.getString("private", "false").equals("true");

    Log.d(TAG, "New message, type " + notifyType + ", mentioned: " + isMentioned + ", private: " + isPrivate);

    if (isOwnMessage && !notifyOwnMessages) {
        Log.i(TAG, "Canceling notification (user sent): " + extras.toString());
        mNotificationManager.cancel(extras.getString("flow"), 0);
        NotificationHelper.cleanNotifications(getApplicationContext(), extras.getString("flow"));
        return;//from  www .j a  v  a  2s.  c  o m

    } else if (notifyType.equals("mentions") && !isMentioned && !isPrivate) {
        Log.i(TAG, "Skipping message (not mentioned): " + extras.toString());
        return;

    } else if (notifyType.equals("private") && !isPrivate) {
        Log.i(TAG, "Skipping message (not private): " + extras.toString());
        return;
    }

    Date lastNotification = NotificationHelper.getLastNotificationDate(getApplicationContext(), flow);
    NotificationHelper.addNotification(getApplicationContext(), flow, msg);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();

    Boolean silentMode = prefs.getBoolean("prefNotifySilent", false);

    if (!silentMode) {
        Date now = new Date();
        Long timeSinceLastNotification = now.getTime() - lastNotification.getTime();

        Integer frequency = Integer.parseInt(prefs.getString("prefNotifyVibrationFrequency", "15")) * 1000;
        Boolean notifyWhenActive = prefs.getBoolean("prefNotifyWhenActive", false);
        Boolean isActive = extras.getString("active", "false").equals("true");

        if (timeSinceLastNotification < frequency) {
            Log.i(TAG, "Skipping vibration -- cooldown in effect");

        } else if (isActive && !notifyWhenActive) {
            Log.i(TAG, "Skipping vibration -- user already active");

        } else {
            mBuilder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
        }
    }

    ArrayList<String> prevMessages = NotificationHelper.getNotifications(getApplicationContext(), flow);
    Integer pendingCount = prevMessages.size();

    if (pendingCount == 1) {
        // Only one notification : display using BigTextStyle for multiline.
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle()
                .bigText(Html.fromHtml(msg));

        mBuilder.setStyle(style);
    } else {
        // More than one notification: use inbox style, displaying up to 5 messages
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        for (int i = 0; i < Math.min(pendingCount, 5); i++) {
            style.addLine(Html.fromHtml(prevMessages.get(i)));
        }

        mBuilder.setStyle(style).setContentInfo(Integer.toString(pendingCount)).setNumber(pendingCount);

        NotificationCompat.BigTextStyle pageStyle = new NotificationCompat.BigTextStyle();
        StringBuilder pageText = new StringBuilder();

        // And then add a second page for Wearables, displaying the whole pending conversation
        for (int i = pendingCount - 1; i >= 0; i--) {
            if (i < pendingCount - 1) {
                pageText.append("<br /><br />");
            }
            pageText.append(prevMessages.get(i));
        }

        pageStyle.bigText(Html.fromHtml(pageText.toString()));

        Notification secondPage = new NotificationCompat.Builder(this).setStyle(pageStyle)
                .extend(new NotificationCompat.WearableExtender().setStartScrollBottom(true)).build();

        wearableExtender.addPage(secondPage);

    }

    // Set large icon, which gets used for wearable background as well
    String avatar = extras.getString("avatar", "");
    if (!avatar.equals("")) {

        String sizeExpr = "(/\\d+/?)$";
        Boolean isCloudFront = avatar.contains("cloudfront");
        Boolean hasSize = avatar.matches(".*" + sizeExpr);

        if (isCloudFront) {
            if (!hasSize) {
                avatar += "/400";
            } else {
                avatar.replaceFirst(sizeExpr, "/400");
            }
        }

        ImageLoader imageLoader = ImageLoader.getInstance();
        Bitmap image = imageLoader.loadImageSync(avatar);

        // scale for notification tray
        int height = (int) getResources().getDimension(android.R.dimen.notification_large_icon_height);
        int width = (int) getResources().getDimension(android.R.dimen.notification_large_icon_width);
        Bitmap scaledImage = Bitmap.createScaledBitmap(image, width, height, false);

        mBuilder.setLargeIcon(scaledImage);
        wearableExtender.setBackground(image);
    }

    // Increase priority only for mentions and 1-1 conversations
    if (isMentioned || isPrivate) {
        mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
    }

    // Retrieve color
    // Default to 0x7BD3FB
    int color = Integer.parseInt(extras.getString("color", "8115195"));

    Notification notification = mBuilder.setSmallIcon(R.drawable.notification).setColor(color)
            .setContentTitle(flow).setContentText(Html.fromHtml(msg)).setAutoCancel(true)
            .setContentIntent(createClickedIntent(flow, extras)).setDeleteIntent(createDismissedIntent(flow))
            .setTicker(Html.fromHtml(msg)).setCategory(Notification.CATEGORY_SOCIAL).extend(wearableExtender)
            .build();

    mNotificationManager.notify(flow, 0, notification);
    Log.i(TAG, "Displaying message: " + extras.toString());
}