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.mattprecious.notisync.service.SecondaryService.java

private void handleTextMessage(TextMessage message) {
    if (!Preferences.getSecondaryTextMessageEnabled(this)) {
        return;//from  w  w w  .j av  a  2 s . c om
    }

    if (textMessages.containsKey(message.number)) {
        List<TextMessage> messages = textMessages.remove(message.number);
        messages.add(message);
        textMessages.put(message.number, messages);
    } else {
        List<TextMessage> list = Lists.newArrayList();
        list.add(message);

        textMessages.put(message.number, list);
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_stat_sms);
    builder.setSound(getRingtoneUri(Preferences.getSecondaryTextMessageRingtone(this)));
    builder.setAutoCancel(true);

    int defaults = 0;
    if (Preferences.getSecondaryTextMessageVibrate(this)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    if (Preferences.getSecondaryTextMessageLights(this)) {
        defaults |= Notification.DEFAULT_LIGHTS;
    }

    builder.setDefaults(defaults);

    PendingIntent deleteIntent = PendingIntent.getBroadcast(this, 0,
            new Intent(ACTION_TEXT_NOTIFICATION_DELETED), 0);
    builder.setContentIntent(deleteIntent);
    builder.setDeleteIntent(deleteIntent);

    List<List<NotificationData>> threadList = Lists.newArrayList();
    List<Entry<String, List<TextMessage>>> entryList = Lists
            .reverse(Lists.newArrayList(textMessages.entrySet()));
    for (Entry<String, List<TextMessage>> entry : entryList) {
        List<TextMessage> messages = entry.getValue();
        TextMessage last = messages.get(messages.size() - 1);

        String sender;
        if (last.name != null) {
            sender = last.name;
        } else {
            sender = PhoneNumberUtils.formatNumber(last.number);
        }

        List<NotificationData> data = Lists.newArrayList();
        for (TextMessage msg : messages) {
            data.add(new NotificationData(sender, msg.message));
        }

        threadList.add(data);
    }

    Bitmap photo = ContactHelper.getContactPhoto(this, message.number);
    notificationManager.notify(NOTIFICATION_ID_TEXT, buildRichNotification(builder, threadList, photo));

    String sender;
    if (message.name != null) {
        sender = message.name;
    } else {
        sender = PhoneNumberUtils.formatNumber(message.number);
    }

    openNotificationDatabaseWrite();
    notificationsDbAdapter.insertNotification("text.message", "smsmms", "SMS/MMS", sender,
            PhoneNumberUtils.formatNumber(message.number), System.currentTimeMillis() + "");
    notificationsDbAdapter.close();
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  w ww.j  av a 2s .c o m*/
 */
private void sendNotification(Context context, String from, String message) {
    /*
    Intent intent = new Intent(context, DevToolActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
        PendingIntent.FLAG_ONE_SHOT);
    */

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.shortcut_pkg).setContentTitle("Uninstalled").setContentText(message)
            .setAutoCancel(true);
    //       .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
    //       .setLights(Color.RED, 3000, 3000)
    //       .setSound(defaultSoundUri)
    //       .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
    //       .setContentIntent(pendingIntent);

    // <uses-permission android:name="android.permission.VIBRATE" />

    Notification note = notificationBuilder.build();
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.defaults |= Notification.DEFAULT_SOUND;
    note.defaults |= Notification.DEFAULT_LIGHTS;

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, note);
}

From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java

Notification buildHeadsUp(Context context, List<Timer> expired) {
    final Timer timer = expired.get(0);

    // First action intent is to reset all timers.
    @DrawableRes/*from   ww w.  j a  v  a 2  s .  c o  m*/
    final int icon1 = com.androidinspain.deskclock.R.drawable.ic_stop_24dp;
    final Intent reset = TimerService.createResetExpiredTimersIntent(context);
    final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);

    // Generate some descriptive text, a title, and an action name based on the timer count.
    final CharSequence stateText;
    final int count = expired.size();
    final List<Action> actions = new ArrayList<>(2);
    if (count == 1) {
        final String label = timer.getLabel();
        if (TextUtils.isEmpty(label)) {
            stateText = context.getString(com.androidinspain.deskclock.R.string.timer_times_up);
        } else {
            stateText = label;
        }

        // Left button: Reset single timer
        final CharSequence title1 = context.getString(com.androidinspain.deskclock.R.string.timer_stop);
        actions.add(new Action.Builder(icon1, title1, intent1).build());

        // Right button: Add minute
        final Intent addTime = TimerService.createAddMinuteTimerIntent(context, timer.getId());
        final PendingIntent intent2 = Utils.pendingServiceIntent(context, addTime);
        @DrawableRes
        final int icon2 = com.androidinspain.deskclock.R.drawable.ic_add_24dp;
        final CharSequence title2 = context.getString(com.androidinspain.deskclock.R.string.timer_plus_1_min);
        actions.add(new Action.Builder(icon2, title2, intent2).build());
    } else {
        stateText = context.getString(com.androidinspain.deskclock.R.string.timer_multi_times_up, count);

        // Left button: Reset all timers
        final CharSequence title1 = context.getString(com.androidinspain.deskclock.R.string.timer_stop_all);
        actions.add(new Action.Builder(icon1, title1, intent1).build());
    }

    final long base = getChronometerBase(timer);

    final String pname = context.getPackageName();

    // Content intent shows the timer full screen when clicked.
    final Intent content = new Intent(context, ExpiredTimersActivity.class);
    final PendingIntent contentIntent = Utils.pendingActivityIntent(context, content);

    // Full screen intent has flags so it is different than the content intent.
    final Intent fullScreen = new Intent(context, ExpiredTimersActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
    final PendingIntent pendingFullScreen = Utils.pendingActivityIntent(context, fullScreen);

    final Builder notification = new NotificationCompat.Builder(context).setOngoing(true).setLocalOnly(true)
            .setShowWhen(false).setAutoCancel(false).setContentIntent(contentIntent)
            .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_LIGHTS)
            .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer)
            .setFullScreenIntent(pendingFullScreen, true)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
            .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background));

    for (Action action : actions) {
        notification.addAction(action);
    }

    if (Utils.isNOrLater()) {
        notification.setCustomContentView(buildChronometer(pname, base, true, stateText));
    } else {
        final CharSequence contentTextPreN = count == 1
                ? context.getString(com.androidinspain.deskclock.R.string.timer_times_up)
                : context.getString(com.androidinspain.deskclock.R.string.timer_multi_times_up, count);

        notification.setContentTitle(stateText).setContentText(contentTextPreN);
    }

    return notification.build();
}

From source file:edu.sage.spark.service.XmppConnectionAdapter.java

/**
 * Update the notification for the Beem status.
 * @param status the status to display./*from  w  w  w  .  j  av  a 2s.c o m*/
 * @param text the text to display.
 */
@SuppressWarnings("deprecation")
private void updateNotification(int status, String text) {
    String mNotificationText = "Spark Status"; //almyz125 added this

    Notification mStatusNotification;
    mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text,
            System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    mStatusNotification.setLatestEventInfo(mService, mNotificationText, text, //almyz125 added mNotificationText variable
            PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}

From source file:com.beem.project.beem.service.XmppConnectionAdapter.java

/**
 * Update the notification for the Beem status.
 * @param status the status to display.//  w ww.ja v  a2 s. c om
 * @param text the text to display.
 */
private void updateNotification(int status, String text) {
    Notification mStatusNotification;
    mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text,
            System.currentTimeMillis());
    mStatusNotification.defaults = Notification.DEFAULT_LIGHTS;
    mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    mStatusNotification.setLatestEventInfo(mService, "Beem Status", text,
            PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0));
    // bypass the preferences for notification
    mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}

From source file:com.elixsr.portforwarder.forwarding.ForwardingService.java

/**
 * Construct a notification//from w  w w.j  a  v a  2 s .  c o m
 */
private void showForwardingEnabledNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_fwd_24dp).setContentTitle("Port Forwarding Active")
            .setContentText("Touch to disable");

    mBuilder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.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);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT
            | Notification.DEFAULT_LIGHTS;

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static Notification makePinNotification(Context context, Builder builder, ContentSet task,
        boolean withSound, boolean withTickerText, boolean withHeadsUpNotification) {
    Resources resources = context.getResources();

    // reset actions
    builder.mActions = new ArrayList<Action>(2);

    // content//ww  w. ja  v a2 s .com
    builder.setSmallIcon(R.drawable.ic_pin_white_24dp).setContentTitle(TaskFieldAdapters.TITLE.get(task))
            .setOngoing(true).setShowWhen(false);

    // set priority for HeadsUpNotification
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        if (withHeadsUpNotification) {
            builder.setPriority(Notification.PRIORITY_HIGH);
        } else {
            builder.setPriority(Notification.PRIORITY_DEFAULT);
        }
    }

    // color is based on the priority of the task. If the task has no priority we use the primary color.
    Integer priority = TaskFieldAdapters.PRIORITY.get(task);
    if (priority != null && priority > 0) {
        if (priority < 5) {
            builder.setColor(resources.getColor(R.color.priority_red));
        }
        if (priority == 5) {
            builder.setColor(resources.getColor(R.color.priority_yellow));
        }
        if (priority > 5 && priority <= 9) {
            builder.setColor(resources.getColor(R.color.priority_green));
        }
    } else {
        builder.setColor(resources.getColor(R.color.colorPrimary));
    }

    // description
    String contentText = makePinNotificationContentText(context, task);
    if (contentText != null) {
        builder.setContentText(contentText);
    }

    // ticker text
    if (withTickerText) {
        builder.setTicker(
                context.getString(R.string.notification_task_pin_ticker, (TaskFieldAdapters.TITLE.get(task))));
    }

    // click action
    Intent resultIntent = new Intent(Intent.ACTION_VIEW);
    resultIntent.setData(task.getUri());
    resultIntent.setPackage(context.getPackageName());

    PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    // complete action
    Boolean closed = TaskFieldAdapters.IS_CLOSED.get(task);
    if (closed == null || !closed) {
        Time dueTime = TaskFieldAdapters.DUE.get(task);
        long dueTimestamp = dueTime == null ? 0 : dueTime.toMillis(true);

        NotificationAction completeAction = new NotificationAction(NotificationUpdaterService.ACTION_COMPLETE,
                R.string.notification_action_completed, TaskFieldAdapters.TASK_ID.get(task), task.getUri(),
                dueTimestamp);
        builder.addAction(NotificationUpdaterService.getCompleteAction(context,
                NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction)));
    }

    // unpin action
    builder.addAction(NotificationUpdaterService.getUnpinAction(context, TaskFieldAdapters.TASK_ID.get(task),
            task.getUri()));

    // sound
    if (withSound) {
        builder.setDefaults(Notification.DEFAULT_ALL);
    } else {
        builder.setDefaults(Notification.DEFAULT_LIGHTS);
    }

    return builder.build();
}

From source file:com.mattprecious.notisync.service.SecondaryService.java

private void handlePhoneCallMessage(PhoneCallMessage message) {
    if (!Preferences.getSecondaryPhoneCallEnabled(this)) {
        return;/*from  w  ww.  j  av  a  2  s. c  om*/
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSound(getRingtoneUri(Preferences.getSecondaryPhoneCallRingtone(this)));
    builder.setAutoCancel(true);

    int defaults = 0;
    if (Preferences.getSecondaryPhoneCallVibrate(this)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    if (Preferences.getSecondaryPhoneCallLights(this)) {
        defaults |= Notification.DEFAULT_LIGHTS;
    }

    builder.setDefaults(defaults);

    PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    builder.setContentIntent(intent);

    int notificationId;
    if (message.type == PhoneCallMessage.Type.INCOMING) {
        incomingCallMessage = message;

        notificationId = NOTIFICATION_ID_PHONE_INCOMING;
        builder.setContentTitle(getString(R.string.noti_title_incoming_call));
        builder.setSmallIcon(R.drawable.ic_stat_incoming);
    } else if (message.type == PhoneCallMessage.Type.MISSED) {
        notificationId = NOTIFICATION_ID_PHONE_MISSED;
        builder.setContentTitle(getString(R.string.noti_title_missed_call));
        builder.setSmallIcon(R.drawable.ic_stat_missed_call);

        if (incomingCallMessage != null && message.number != null
                && message.number.equals(incomingCallMessage.number)) {
            notificationManager.cancel(NOTIFICATION_ID_PHONE_INCOMING);
            incomingCallMessage = null;
        }
    } else {
        return;
    }

    String text;
    if (message.name != null) {
        text = message.name;
    } else {
        text = PhoneNumberUtils.formatNumber(message.number);
    }

    builder.setContentText(text);

    Notification notification = builder.build();
    notificationManager.notify(notificationId, notification);

    openNotificationDatabaseWrite();
    notificationsDbAdapter.insertNotification("phone.call", "phone", "Phone call", text,
            PhoneNumberUtils.formatNumber(message.number), System.currentTimeMillis() + "");
    notificationsDbAdapter.close();
}

From source file:com.chen.email.NotificationController.java

/** Sets up the notification's sound and vibration based upon account details. */
private void setupSoundAndVibration(NotificationCompat.Builder builder, Account account) {
    String ringtoneUri = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
    boolean vibrate = false;

    // Use the Inbox notification preferences
    final Cursor accountCursor = mContext.getContentResolver().query(
            EmailProvider.uiUri("uiaccount", account.mId), UIProvider.ACCOUNTS_PROJECTION, null, null, null);

    com.chen.mail.providers.Account uiAccount = null;
    try {/*from  w  ww  . j a va 2 s  .  co  m*/
        if (accountCursor.moveToFirst()) {
            uiAccount = new com.chen.mail.providers.Account(accountCursor);
        }
    } finally {
        accountCursor.close();
    }

    if (uiAccount != null) {
        final Cursor folderCursor = mContext.getContentResolver().query(uiAccount.settings.defaultInbox,
                UIProvider.FOLDERS_PROJECTION, null, null, null);

        if (folderCursor == null) {
            // This can happen when the notification is for the security policy notification
            // that happens before the account is setup
            LogUtils.w(LOG_TAG, "Null folder cursor for mailbox %s", uiAccount.settings.defaultInbox);
        } else {
            Folder folder = null;
            try {
                if (folderCursor.moveToFirst()) {
                    folder = new Folder(folderCursor);
                }
            } finally {
                folderCursor.close();
            }

            if (folder != null) {
                final FolderPreferences folderPreferences = new FolderPreferences(mContext,
                        uiAccount.getEmailAddress(), folder, true /* inbox */);

                ringtoneUri = folderPreferences.getNotificationRingtoneUri();
                vibrate = folderPreferences.isNotificationVibrateEnabled();
            } else {
                LogUtils.e(LOG_TAG, "Null folder for mailbox %s", uiAccount.settings.defaultInbox);
            }
        }
    } else {
        LogUtils.e(LOG_TAG, "Null uiAccount for account id %d", account.mId);
    }

    int defaults = Notification.DEFAULT_LIGHTS;
    if (vibrate) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    builder.setSound(TextUtils.isEmpty(ringtoneUri) ? null : Uri.parse(ringtoneUri)).setDefaults(defaults);
}

From source file:at.jclehner.rxdroid.NotificationReceiver.java

public void updateNotification(Date date, int doseTime, boolean isActiveDoseTime, int mode) {
    final List<Drug> drugsWithLowSupplies = new ArrayList<Drug>();
    final int lowSupplyDrugCount = getDrugsWithLowSupplies(date, doseTime, drugsWithLowSupplies);
    final int missedDoseCount = getDrugsWithMissedDoses(date, doseTime, isActiveDoseTime, null);
    final int dueDoseCount = isActiveDoseTime ? getDrugsWithDueDoses(date, doseTime, null) : 0;

    int titleResId = R.string._title_notification_doses;
    int icon = R.drawable.ic_stat_normal;

    final StringBuilder sb = new StringBuilder();
    final String[] lines = new String[2];

    int lineCount = 0;

    if (missedDoseCount != 0 || dueDoseCount != 0) {
        if (dueDoseCount != 0)
            sb.append(RxDroid.getQuantityString(R.plurals._qmsg_due, dueDoseCount));

        if (missedDoseCount != 0) {
            if (sb.length() != 0)
                sb.append(", ");

            sb.append(RxDroid.getQuantityString(R.plurals._qmsg_missed, missedDoseCount));
        }/*w  w  w .  j  a v a  2  s  . co  m*/

        lines[1] = "<b>" + getString(R.string._title_notification_doses) + "</b> "
                + Util.escapeHtml(sb.toString());
    }

    final boolean isShowingLowSupplyNotification;

    if (lowSupplyDrugCount != 0) {
        final String msg;
        final String first = drugsWithLowSupplies.get(0).getName();

        icon = R.drawable.ic_stat_exclamation;
        isShowingLowSupplyNotification = sb.length() == 0;
        //titleResId = R.string._title_notification_low_supplies;

        if (lowSupplyDrugCount == 1)
            msg = getString(R.string._qmsg_low_supply_single, first);
        else {
            final String second = drugsWithLowSupplies.get(1).getName();
            msg = RxDroid.getQuantityString(R.plurals._qmsg_low_supply_multiple, lowSupplyDrugCount - 1, first,
                    second);
        }

        if (isShowingLowSupplyNotification) {
            sb.append(msg);
            titleResId = R.string._title_notification_low_supplies;
        }

        lines[0] = "<b>" + getString(R.string._title_notification_low_supplies) + "</b> "
                + Util.escapeHtml(msg);
    } else
        isShowingLowSupplyNotification = false;

    final int priority;
    if (isShowingLowSupplyNotification)
        priority = NotificationCompat.PRIORITY_DEFAULT;
    else
        priority = NotificationCompat.PRIORITY_HIGH;

    final String message = sb.toString();
    final int currentHash = message.hashCode();
    final int lastHash = Settings.getInt(Settings.Keys.LAST_MSG_HASH);

    if (message.length() == 0) {
        getNotificationManager().cancel(R.id.notification);
        return;
    }

    final StringBuilder source = new StringBuilder();

    //      final InboxStyle inboxStyle = new InboxStyle();
    //      inboxStyle.setBigContentTitle(getString(R.string.app_name) +
    //            " (" + (dueDoseCount + missedDoseCount + lowSupplyDrugCount) + ")");

    for (String line : lines) {
        if (line != null) {
            if (lineCount != 0)
                source.append("\n<br/>\n");

            source.append(line);
            //            inboxStyle.addLine(Html.fromHtml(line));
            ++lineCount;
        }
    }

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    builder.setContentTitle(getString(titleResId));
    builder.setContentIntent(createDrugListIntent(date));
    builder.setContentText(message);
    builder.setTicker(getString(R.string._msg_new_notification));
    builder.setSmallIcon(icon);
    builder.setOngoing(true);
    builder.setUsesChronometer(false);
    builder.setWhen(0);
    builder.setPriority(priority);

    if (lineCount > 1) {
        final BigTextStyle style = new BigTextStyle();
        style.setBigContentTitle(getString(R.string.app_name));
        style.bigText(Html.fromHtml(source.toString()));
        builder.setStyle(style);
    }

    //      final long offset;
    //
    //      if(isActiveDoseTime)
    //         offset = Settings.getDoseTimeBeginOffset(doseTime);
    //      else
    //         offset = Settings.getTrueDoseTimeEndOffset(doseTime);
    //
    //      builder.setWhen(date.getTime() + offset);

    if (mode == NOTIFICATION_FORCE_UPDATE || currentHash != lastHash) {
        builder.setOnlyAlertOnce(false);
        Settings.putInt(Settings.Keys.LAST_MSG_HASH, currentHash);
    } else
        builder.setOnlyAlertOnce(true);

    // Prevents low supplies from constantly annoying the user with
    // notification's sound and/or vibration if alarms are repeated.
    if (isShowingLowSupplyNotification)
        mode = NOTIFICATION_FORCE_SILENT;

    int defaults = 0;

    final String lightColor = Settings.getString(Settings.Keys.NOTIFICATION_LIGHT_COLOR, "");
    if (lightColor.length() == 0)
        defaults |= Notification.DEFAULT_LIGHTS;
    else {
        try {
            int ledARGB = Integer.parseInt(lightColor, 16);
            if (ledARGB != 0) {
                ledARGB |= 0xff000000; // set alpha to ff
                builder.setLights(ledARGB, LED_ON_MS, LED_OFF_MS);
            }
        } catch (NumberFormatException e) {
            Log.e(TAG, "Failed to parse light color; using default", e);
            defaults |= Notification.DEFAULT_LIGHTS;
        }
    }

    if (mode != NOTIFICATION_FORCE_SILENT) {
        boolean isNowWithinQuietHours = false;

        do {
            if (!Settings.isChecked(Settings.Keys.QUIET_HOURS, false))
                break;

            final String quietHoursStr = Settings.getString(Settings.Keys.QUIET_HOURS);
            if (quietHoursStr == null)
                break;

            final TimePeriod quietHours = TimePeriod.fromString(quietHoursStr);
            if (quietHours.contains(DumbTime.now()))
                isNowWithinQuietHours = true;

        } while (false);

        if (!isNowWithinQuietHours) {
            final String ringtone = Settings.getString(Settings.Keys.NOTIFICATION_SOUND);
            if (ringtone != null)
                builder.setSound(Uri.parse(ringtone));
            else
                defaults |= Notification.DEFAULT_SOUND;

            if (LOGV)
                Log.i(TAG, "Sound: " + (ringtone != null ? ringtone.toString() : "(default)"));
        } else
            Log.i(TAG, "Currently within quiet hours; muting sound...");
    }

    if (mode != NOTIFICATION_FORCE_SILENT && Settings.getBoolean(Settings.Keys.USE_VIBRATOR, true))
        defaults |= Notification.DEFAULT_VIBRATE;

    builder.setDefaults(defaults);

    getNotificationManager().notify(R.id.notification, builder.build());
}